Commit Graph

253 Commits (c8cc87c3f5527c386bba2ad4a27da757f812664c)

Author SHA1 Message Date
Shawn Smith 96d82b40fb rafthttp: fix typo in test comment 2016-01-29 15:59:36 +09:00
Gyu-Ho Lee b6077f9d57 *: fix minor typos 2016-01-14 01:28:29 -08:00
siddontang 54a45ba2f5 *: fix typo 2016-01-06 16:17:02 +08:00
Anthony Romano e1bf726bc1 *: split out etcdserver's test mockup objects to live in interfaces' packages 2016-01-05 09:39:13 -08:00
Xiang Li d07a9cd893 Merge pull request #4059 from xiang90/snap_log
rafthttp: better snapshot sending logging
2015-12-28 10:05:35 -08:00
Xiang Li 4be152bb4f rework 2015-12-23 16:21:16 -08:00
Xiang Li ab31ba0d29 *: fix snapshot sending cycle 2015-12-23 13:58:57 -08:00
Xiang Li 74dba2d4cf rafthttp: better snapshot sending logging
snapshot sending is an important event. We should always log it explicitly.
2015-12-23 12:36:07 -08:00
Xiang Li 94da4b9ee5 rafthttp: log before receiving snapshot
Database snapshot can be as large as 5GB. It is reasonable
to log before receiving it. Or the user might not know what
is happening and why etcd starts to use IO intensively.
2015-12-23 08:45:36 -08:00
Xiang Li 80541d74d0 rafhttp: make TestStreamWriterAttachOutgoingConn more robust 2015-12-14 17:06:38 -08:00
Xiang Li 7d78e0c85e rafthttp: remove the unncessary TODO
The issue is not caused by this code, but by reading snapshot
from disk. etcd assumes the snapshot of v3 kv should live in
memory. If not, etcd does not work well anyway.
2015-12-11 09:37:41 -08:00
Xiang Li 95c29838e3 rafthttp: move ReadCloser to ioutil 2015-12-11 09:37:41 -08:00
Xiang Li 2fc3320e59 rafthttp: kill the receiving body timeout TODO in snapshot sender 2015-12-10 22:42:17 -08:00
Xiang Li 23bd60ccce *: rewrite snapshot sending 2015-12-08 18:21:21 -08:00
Gyu-Ho Lee 6aa559f93d rafthttp: more detailed logs when filled-up buffer
This adds more detailed explanation about why some messages got dropped to help
users debug. This is for https://github.com/coreos/etcd/issues/3806.
2015-11-18 14:17:43 -08:00
Gyu-Ho Lee 81229dbea9 *: add missing package descriptions
This adds and updates package descriptions in etcd projects.
And also deletes some duplicate LICENSE statements.
2015-11-17 20:54:10 -08:00
Xiang Li ff36b9d9bc Merge pull request #3700 from xiang90/metrics_hi
Replace Summary with Histogram for all metrics
2015-11-10 10:06:45 -08:00
Xiang Li 964f6050ee raft: use HistogramVec for message_sent_latency 2015-11-10 10:05:32 -08:00
Yicheng Qin ec3c2d23a3 *: update feature maps to adopt v2.3.0 2015-11-04 14:30:35 -08:00
Yicheng Qin 3d15526c35 Merge pull request #3796 from yichengq/fix-get-version
etcdserver: not reuse connections for peer transport
2015-11-04 11:39:14 -08:00
Yicheng Qin 4ccbcb91c8 rafthttp: add functions to create listener and roundTripper
This moves the code to create listener and roundTripper for raft communication
to the same place, and use explicit functions to build them. This prevents
possible development errors in the future.
2015-11-04 11:12:46 -08:00
Yicheng Qin 65d153db73 Merge pull request #3783 from yichengq/merge-logger
rafthttp: use MergeLogger for rafthttp logging
2015-11-04 09:48:43 -08:00
Yicheng Qin 6040d57106 rafthttp: use MergeLogger to merge message-drop log
rafthttp logs repeated messages when amounts of message-drop logs
happen, and it becomes log spamming.
Use MergeLogger to merge log lines in this case.
2015-11-04 07:26:58 -08:00
Yicheng Qin 5329159b5e rafthttp: remove failureMap from peerStatus
The logging mechanism is verbose, so it is removed from peerStatus.

We would like to see the status change
of connection with peers, and one error that leads to deactivation.
There is no need to print out all non-repeated errors.
2015-11-04 07:26:33 -08:00
Yicheng Qin 0eee88a3d9 etcdserver: use timeout transport as peer transport
This pairs with remote timeout listeners.

etcd uses timeout listener, and times out the accepted connections
if there is no activity. So the idle connections may time out easily.
Becaus timeout transport doesn't reuse connections, it prevents using
timeouted connection.

This fixes the problem that etcd fail to get version of peers.
2015-11-03 07:58:03 -08:00
Yicheng Qin 1b3d9130c9 Merge pull request #3759 from yichengq/rafthttp-unreachable
rafthttp: mark unreachable on unexpected response
2015-10-29 15:12:23 -07:00
Yicheng Qin 84d7825a77 rafthttp: stop masking errMemberRemoved in pipeline
It makes logic more straightforward and readable. Also, it makes the
handle method consistent with stream and snapshot sender.
2015-10-28 21:40:48 -07:00
Yicheng Qin 908a011604 rafthttp: mark unreachable on unexpected response
In rafthttp, when making request to some endpoint, it may receive
response with unexpected status code and header. This indicates the endpoint
doesn't function correctly. It should mark the endpoint unreachable.
2015-10-28 21:40:11 -07:00
Xiang Li a8e6e71bf9 *: fix various data races detected by race detector 2015-10-26 20:49:37 -07:00
Xiang Li 336d177c82 rafthttp: fix data races detected by go race detector 2015-10-26 15:29:08 -07:00
Yicheng Qin 4076dda101 rafthttp: fix wrong return in pipeline.handle
pipeline.handle is a long-living one, and should continue to receive
next message to send out when current message fails to send. So it
should `continue` instead of `return` here.
2015-10-26 14:05:19 -07:00
Yicheng Qin 9635d8d94c Merge pull request #3720 from yichengq/clean-streamAppV1
rafthttp: deprecate streamTypeMsgApp and remove msgApp stream sent restriction due to streamTypeMsgApp
2015-10-20 10:37:51 -07:00
Yicheng Qin de669be6d6 Merge pull request #3683 from yichengq/raft-block
etcdserver: fix raft state machine may block
2015-10-20 09:44:34 -07:00
Yicheng Qin ab5df57ecf etcdserver: fix raft state machine may block
When snapshot store requests raft snapshot from etcdserver apply loop,
it may block on the channel for some time, or wait some time for KV to
snapshot. This is unexpected because raft state machine should be unblocked.

Even worse, this block may lead to deadlock:
1. raft state machine waits on getting snapshot from raft memory storage
2. raft memory storage waits snapshot store to get snapshot
3. snapshot store requests raft snapshot from apply loop
4. apply loop is applying entries, and waits raftNode loop to finish
messages sending
5. raftNode loop waits peer loop in Transport to send out messages
6. peer loop in Transport waits for raft state machine to process message

Fix it by changing the logic of getSnap to be asynchronously creation.
2015-10-20 09:19:34 -07:00
Yicheng Qin b61eaf3335 rafthttp: msgApp{Reader/Writer} -> msgAppV2{Reader/Writer}
To make what it serves more clear.
2015-10-20 08:28:06 -07:00
Yicheng Qin 5060b2f322 rafthttp: send all MsgApp on stream msgAppV2
For stream msgAppV2, as long as the message is MsgApp type, it should be sent
through stream msgAppV2.
2015-10-20 08:23:36 -07:00
Yicheng Qin 33231fccdd rafthttp: fix wrong stream name returned by pick
msgAppWriter uses streamAppV2 type, and it should return the correct name.
2015-10-20 08:17:06 -07:00
Yicheng Qin f725f6a552 rafthttp: deprecate streamTypeMsgApp
streamTypeMsgApp is only used in etcd 2.0. etcd 2.3 should not talk to
etcd 2.0, either send or receive requests. So I deprecate streamTypeMsgApp
and its related stuffs from rafthttp package.

updating term is only used from streamTypeMsgApp, so it is removed too.
2015-10-20 08:15:54 -07:00
Xiang Li 427a154aae rafthttp: various clean up 2015-10-18 09:49:18 -07:00
Xiang Li 7d3af5e15f rafthttp: rename message.go -> message_codec.go 2015-10-18 09:49:11 -07:00
Xiang Li e87cd0c17b rafthttp: move new funcs to right place 2015-10-18 09:48:59 -07:00
Xiang Li 478fab6aca rafthttp: rename NewHandler to newPipelineHandler 2015-10-17 22:33:28 -07:00
Xiang Li 080c11d14e rafthttp: make ConnReadLimitByte private and add comment 2015-10-17 22:20:36 -07:00
Yicheng Qin 1f21ccf166 rafthttp: support sending v3 snapshot message
Use snapshotSender to send v3 snapshot message. It puts raft snapshot
message and v3 snapshot into request body, then sends it to the target peer.
When it receives http.StatusNoContent, it knows the message has been
received and processed successfully.

As receiver, snapHandler saves v3 snapshot and then processes the raft snapshot
message, then respond with http.StatusNoContent.
2015-10-13 23:11:28 -07:00
Yicheng Qin 207c92b627 rafthttp: build transport inside pkg instead of passed-in
rafthttp has different requirements for connections created by the
transport for different usage, and this is hard to achieve when giving
one http.RoundTripper. Pass into pkg the data needed to build transport
now, and let rafthttp build its own transports.
2015-10-11 21:42:37 -07:00
Yicheng Qin 233e717e2f rafthttp: expose struct to set configuration
transport takes too many arguments and the new function is unable to
read. Change the way to set fields in transport struct directly.
2015-10-11 09:02:16 -07:00
Jonathan Boulle 7848ac3979 *: add missing license headers 2015-09-15 14:09:01 -07:00
Dmitry Smirnov b2f4a5f587 *: fix spelling issues (codespell).
Signed-off-by: Dmitry Smirnov <onlyjob@member.fsf.org>
2015-09-11 10:22:29 +10:00
Yicheng Qin 8f6bf029f8 etcdserver: specify request timeout error due to connection lost
It specifies request timeout error possibly caused by connection lost,
and print out better log for user to understand.

It handles two cases:
1. the leader cannot connect to majority of cluster.
2. the connection between follower and leader is down for a while,
and it losts proposals.

log format:
```
20:04:19 etcd3 | 2015-08-25 20:04:19.368126 E | etcdhttp: etcdserver:
request timed out, possibly due to connection lost
20:04:19 etcd3 | 2015-08-25 20:04:19.368227 E | etcdhttp: etcdserver:
request timed out, possibly due to connection lost
```
2015-08-26 12:38:37 -07:00
Yicheng Qin 61a75b3d48 rafthttp: always cancel in-flight request when pipeline.send
This fits the way for go1.5 to cancel request.
2015-08-25 09:07:49 -07:00
Yicheng Qin 6fc638673c rafthttp: return err if stopped before setting cancel in dial()
The original workflow may fail to cancel if stop() cancels the finished
request just before dial() assigning a new cancel. This commit checks
streamReader status before setting cancel to avoid this problem.

It is tested at travis for 300 times. go 1.5 always works well, while
go 1.4 fails to stop once.
2015-08-25 08:59:12 -07:00
Yicheng Qin fc95ec0cc6 rafthttp: always cancel in-flight request when stop streamReader
This problem is totally fixed at 1.5.

go1.5 adds a Request.Cancel channel, which allows for "race free"
cancellation
(8b4278ffb7).
Our implementation relies on it to always cancel in-flight request.
2015-08-25 08:54:13 -07:00
Xiang Li 6b23a8131f *: test gofmt with -s and fix reported issues 2015-08-21 18:52:16 -07:00
Yicheng Qin ffae601af5 etcdmain: calculate dial timeout for peer transport
This helps peer communication in globally-deployed cluster.
2015-08-17 16:52:53 -07:00
Yicheng Qin c9cca6a93b *: update MinClusterVersion and supportedStream map 2015-08-13 13:05:14 -07:00
Xiang Li 845c51fedd *: fix typos vaild->valid 2015-08-07 10:57:11 -07:00
Xiang Li b6580a9591 rafthttp: use customized transport for probing
We need to support TLS verification when probing.
2015-08-06 16:20:44 -07:00
Xiang Li 1e048b5c24 rafthttp: cleanup prober when stopping the transport 2015-08-04 17:42:51 +08:00
Xiang Li 0fc764200d rafthttp: monitor connection 2015-08-04 17:39:40 +08:00
Yicheng Qin bd84e678e6 Merge pull request #3061 from yichengq/fix-stream-test
rafthttp: fix TestStream uses outdated stream
2015-06-29 11:15:29 -07:00
Yicheng Qin f421eaeff7 Merge pull request #3071 from yichengq/rename-rafthttp-metrics
rafthttp: message_sent_latency metrics: channel -> sendingType
2015-06-29 10:58:36 -07:00
Yicheng Qin 28342ae097 rafthttp: avoid TestStream to use outdated stream
The original test code before fb4b0b5cf0
doesn't work because reader side may update the
stream, while writer side writes message to the old stream and fails.

This PR removes unnecessary call to set term, and avoids this problem to
happen on term > 1 in the future.
2015-06-29 10:46:54 -07:00
Yicheng Qin 606876154d rafthttp: message_sent_latency metrics: channel -> sendingType
Better naming.
2015-06-29 10:44:40 -07:00
Yicheng Qin fb4b0b5cf0 rafthttp: support to init term when adding peer
So it doesn't need to build term-0 stream with the remote first, then update it.
2015-06-29 10:20:48 -07:00
Yicheng Qin 2d426b518a Merge pull request #3035 from yichengq/update-term
rafthttp: update term when AddPeer
2015-06-23 14:05:37 -07:00
Yicheng Qin e25e368321 rafthttp: update term when AddPeer
Update term when AddPeer, or the term in peer will not be updated until
the term is changed. This fixes the log flood happended when the v2.1
follower applies the snapshot from v2.0 leader:

```
rafthttp: cannot attach out of data stream server [0 / 17]
```
or
```
rafthttp: server streaming to 6e3bd23ae5f1eae0 at term 0 has been
stopped
```
2015-06-23 13:42:21 -07:00
Brandon Philips 740187f199 *: docs and code %s%maximal%maximum%g
maximum is a more common word, use it instead
2015-06-22 16:06:57 -07:00
Yicheng Qin 219d304291 Merge pull request #2968 from yichengq/fix-stream-reader-init
rafthttp: always init streamReader before return from newPeer
2015-06-12 14:51:05 -07:00
Yicheng Qin 7ff1fa36f2 rafthttp: always init streamReader before return from newPeer
Or etcd will panic if someone calls `setTerm()`, which uses streamReader
internally, before streamReader is inited.
2015-06-12 14:38:14 -07:00
Xiang Li 684c721307 Merge pull request #2970 from yichengq/fix-stream-test
rafthttp: use buffered channel as recv/prop chan
2015-06-12 14:34:52 -07:00
Yicheng Qin 36f75cf062 rafthttp: use buffered channel as recv/prop chan
So it ensures that the message will not be discarded because the receive
side has not been ready, which happens easily in multiple core test.

Use log.fatal instead of log.error. The test exits when there is
something wrong because the error may affect following test cases.
2015-06-12 14:25:11 -07:00
Yicheng Qin 2f05b24d6d rafthttp: {from, to} -> {local, remote} in stream
{from, to} nameings are confused when it both dials and receives
messages from the remote. Change it to {local, remote} for better
clarity.
2015-06-12 14:17:30 -07:00
Yicheng Qin bcc1aadea9 rafthttp: fix the misformat logging line
before:
```
2015/06/12 20:06:19 rafthttp: dropped MsgApp from %!s(uint64=2) since
receiving buffer is full
```

after:
```
2015/06/12 13:51:38 rafthttp: dropped MsgProp from 2 since receiving
buffer is full
```
2015-06-12 14:12:49 -07:00
Yicheng Qin ea3c7d1d31 Merge pull request #2960 from yichengq/fix-drop-flood
rafthttp: pretty print message drop info
2015-06-12 09:23:23 -07:00
Yicheng Qin 0de0e4b77c rafthttp: pretty print message drop info 2015-06-12 09:14:53 -07:00
Yicheng Qin c21cc5b39b rafthttp: fix TestStopBlockedPipeline
Refactor the fake cancel implementation.

The old one may cancel other in-flight message in random, which leaves
the original target message blocked forever.
2015-06-12 07:55:12 -07:00
Yicheng Qin 29dca49cb5 rafthttp: wait 1ms before enabling cancel
CancelRequest only effects on in-flight request, so we need to wait
for Do(request) called before enabling cancel.
2015-06-12 07:55:06 -07:00
Yicheng Qin 0a3a2720a1 Merge pull request #2923 from yichengq/rafthttp-status
rafthttp: pretty print connection error
2015-06-10 16:17:07 -07:00
Yicheng Qin d92c89516b rafthttp: fix capnslog package name 2015-06-10 15:43:54 -07:00
Yicheng Qin 1dbe72bb74 rafthttp: pretty print connection error
1. print out the status change of connection with peer
2. only print the first error for repeated ones
2015-06-10 15:43:49 -07:00
Yicheng Qin 4e79abcfeb Merge pull request #2944 from yichengq/fix-2procs
pkg/testutil: ForceGosched -> WaitSchedule
2015-06-10 14:44:32 -07:00
Yicheng Qin 018fb8e6d9 pkg/testutil: ForceGosched -> WaitSchedule
ForceGosched() performs bad when GOMAXPROCS>1. When GOMAXPROCS=1, it
could promise that other goroutines run long enough
because it always yield the processor to other goroutines. But it cannot
yield processor to goroutine running on other processors. So when
GOMAXPROCS>1, the yield may finish when goroutine on the other
processor just runs for little time.

Here is a test to confirm the case:

```
package main

import (
	"fmt"
	"runtime"
	"testing"
)

func ForceGosched() {
	// possibility enough to sched up to 10 go routines.
	for i := 0; i < 10000; i++ {
		runtime.Gosched()
	}
}

var d int

func loop(c chan struct{}) {
	for {
		select {
		case <-c:
			for i := 0; i < 1000; i++ {
				fmt.Sprintf("come to time %d", i)
			}
			d++
		}
	}
}

func TestLoop(t *testing.T) {
	c := make(chan struct{}, 1)
	go loop(c)
	c <- struct{}{}
	ForceGosched()
	if d != 1 {
		t.Fatal("d is not incremented")
	}
}
```

`go test -v -race` runs well, but `GOMAXPROCS=2 go test -v -race` fails.

Change the functionality to waiting for schedule to happen.
2015-06-10 14:37:41 -07:00
Yicheng Qin 1403783326 Merge pull request #2911 from yichengq/rafthttp-plog
rafthttp: use leveled logger
2015-06-09 16:16:33 -07:00
Yicheng Qin f1e995b070 rafthttp: use leveled logger 2015-06-09 16:15:02 -07:00
Yicheng Qin 7f8925e172 rafthttp: fix pipeline.stop may block
This PR makes pipeline.stop stop quickly. It cancels inflight requests,
and stops sending messages in the buffer.
2015-06-02 17:15:44 -07:00
Xiang Li 28878e34ff Merge pull request #2903 from xiang90/chord_rafthttp
rafhttp: clean up logging messages
2015-06-02 14:44:40 -07:00
Yicheng Qin b74082c06c Merge pull request #2889 from yichengq/version-runtime-enforce
rafthttp: version enforcement on rafthttp messages
2015-06-02 14:37:38 -07:00
Yicheng Qin c371d8c65c rafthttp: version enforcement on rafthttp messages
This PR sets etcd version and min cluster version in request header,
and let server check version compatibility. rafthttp server
will reject any message from peer with incompatible version(too low
version or too high version), and print out warning logs.
2015-06-02 13:33:18 -07:00
Xiang Li a7a4233f0b rafhttp: clean up logging messages 2015-06-01 17:18:37 -07:00
Xiang Li b660ee408f rafthttp: move mu to the top in urlPicker struct
mutex protects all the fields.
2015-06-01 16:40:18 -07:00
Xiang Li 0d3d4c5b01 rafthttp: print out log when clusterID mismatch instead of exiting
We have heard from several users that they do not expect a clusterID
mismatch to kill the cluster.
2015-05-26 16:05:58 -07:00
Yicheng Qin 19fc1a7137 rafthttp: update streamReader term in time
Because etcd 2.1 will build stream to any existing peers and etcd 2.0
requires the remote to provide most updated term, it is
necessary for streamReader to know the latest term.
2015-05-26 14:52:42 -07:00
Yicheng Qin fad2c09fa8 rafthttp: not log expected timeout as error
The network timeout from stream with etcd 2.0 is expected because etcd
2.0 doesn't heartbeat on idle connections.
2015-05-26 14:52:41 -07:00
Yicheng Qin 38b8e848ac rafthttp: try stream msgappV1 handler if msgappV2 is unsupported
This helps etcd 2.1 connect to msgappV1 handler when the remote member
doesn't support msgappV2. And it doesn't print out unsupported handler
error to make log clean.
2015-05-26 14:52:41 -07:00
Xiang Li 42fe370b35 Merge pull request #2848 from xiang90/metrics
*: use namespace and subsystem in metrics
2015-05-26 14:44:54 -07:00
Xiang Li 34ac145b38 *: use namespace and subsystem in metrics
Fix #2841.

From Prometheus developer:
```
the recommended way for etcd as an open source project and under
consideration of its size would be etcd_<subsystem>_<name>.
```

We made the naming change accordingly.
2015-05-26 14:39:04 -07:00
Yicheng Qin 2e43ac8463 rafthttp: add test for streamReader.updateMsgAppTerm 2015-05-15 11:21:54 -07:00
Yicheng Qin 8637a4bf69 rafthttp: only close streamMsgApp when updating term
In all stream types, streamMsgApp needs to be closed when
updating term because its stream connection can only be used under
a certain term. But there is no need to close other streams, which
may waste time and reduce performance.
2015-05-15 11:21:54 -07:00
Yicheng Qin 8e0992a28b rafthttp: resetCloser -> close
name 'close' is shorter and more straightforward.
2015-05-14 22:24:05 -07:00
Yicheng Qin fc4543a3fd Merge pull request #2628 from yichengq/improve-msgappv2
rafthttp: reduce allocs in msgappv2
2015-05-14 21:18:16 -07:00