|
|
@@ -21,7 +21,6 @@ import (
|
|
|
"net"
|
|
|
"net/http"
|
|
|
"path"
|
|
|
- "strconv"
|
|
|
"strings"
|
|
|
"sync"
|
|
|
"time"
|
|
|
@@ -37,7 +36,6 @@ import (
|
|
|
const (
|
|
|
streamTypeMessage streamType = "message"
|
|
|
streamTypeMsgAppV2 streamType = "msgappv2"
|
|
|
- streamTypeMsgApp streamType = "msgapp"
|
|
|
|
|
|
streamBufSize = 4096
|
|
|
)
|
|
|
@@ -47,9 +45,9 @@ var (
|
|
|
|
|
|
// the key is in string format "major.minor.patch"
|
|
|
supportedStream = map[string][]streamType{
|
|
|
- "2.0.0": {streamTypeMsgApp},
|
|
|
- "2.1.0": {streamTypeMsgApp, streamTypeMsgAppV2, streamTypeMessage},
|
|
|
- "2.2.0": {streamTypeMsgApp, streamTypeMsgAppV2, streamTypeMessage},
|
|
|
+ "2.0.0": {},
|
|
|
+ "2.1.0": {streamTypeMsgAppV2, streamTypeMessage},
|
|
|
+ "2.2.0": {streamTypeMsgAppV2, streamTypeMessage},
|
|
|
}
|
|
|
)
|
|
|
|
|
|
@@ -57,8 +55,6 @@ type streamType string
|
|
|
|
|
|
func (t streamType) endpoint() string {
|
|
|
switch t {
|
|
|
- case streamTypeMsgApp: // for backward compatibility of v2.0
|
|
|
- return RaftStreamPrefix
|
|
|
case streamTypeMsgAppV2:
|
|
|
return path.Join(RaftStreamPrefix, "msgapp")
|
|
|
case streamTypeMessage:
|
|
|
@@ -71,8 +67,6 @@ func (t streamType) endpoint() string {
|
|
|
|
|
|
func (t streamType) String() string {
|
|
|
switch t {
|
|
|
- case streamTypeMsgApp:
|
|
|
- return "stream MsgApp"
|
|
|
case streamTypeMsgAppV2:
|
|
|
return "stream MsgApp v2"
|
|
|
case streamTypeMessage:
|
|
|
@@ -94,8 +88,7 @@ func isLinkHeartbeatMessage(m raftpb.Message) bool {
|
|
|
}
|
|
|
|
|
|
type outgoingConn struct {
|
|
|
- t streamType
|
|
|
- termStr string
|
|
|
+ t streamType
|
|
|
io.Writer
|
|
|
http.Flusher
|
|
|
io.Closer
|
|
|
@@ -138,7 +131,6 @@ func (cw *streamWriter) run() {
|
|
|
var msgc chan raftpb.Message
|
|
|
var heartbeatc <-chan time.Time
|
|
|
var t streamType
|
|
|
- var msgAppTerm uint64
|
|
|
var enc encoder
|
|
|
var flusher http.Flusher
|
|
|
tickc := time.Tick(ConnReadTimeout / 3)
|
|
|
@@ -158,16 +150,6 @@ func (cw *streamWriter) run() {
|
|
|
flusher.Flush()
|
|
|
reportSentDuration(string(t), linkHeartbeatMessage, time.Since(start))
|
|
|
case m := <-msgc:
|
|
|
- if t == streamTypeMsgApp && m.Term != msgAppTerm {
|
|
|
- // TODO: reasonable retry logic
|
|
|
- if m.Term > msgAppTerm {
|
|
|
- cw.close()
|
|
|
- heartbeatc, msgc = nil, nil
|
|
|
- // TODO: report to raft at peer level
|
|
|
- cw.r.ReportUnreachable(m.To)
|
|
|
- }
|
|
|
- continue
|
|
|
- }
|
|
|
start := time.Now()
|
|
|
if err := enc.encode(m); err != nil {
|
|
|
reportSentFailure(string(t), m)
|
|
|
@@ -184,13 +166,6 @@ func (cw *streamWriter) run() {
|
|
|
cw.close()
|
|
|
t = conn.t
|
|
|
switch conn.t {
|
|
|
- case streamTypeMsgApp:
|
|
|
- var err error
|
|
|
- msgAppTerm, err = strconv.ParseUint(conn.termStr, 10, 64)
|
|
|
- if err != nil {
|
|
|
- plog.Panicf("could not parse term %s to uint (%v)", conn.termStr, err)
|
|
|
- }
|
|
|
- enc = &msgAppEncoder{w: conn.Writer, fs: cw.fs}
|
|
|
case streamTypeMsgAppV2:
|
|
|
enc = newMsgAppV2Encoder(conn.Writer, cw.fs)
|
|
|
case streamTypeMessage:
|
|
|
@@ -260,29 +235,27 @@ type streamReader struct {
|
|
|
propc chan<- raftpb.Message
|
|
|
errorc chan<- error
|
|
|
|
|
|
- mu sync.Mutex
|
|
|
- msgAppTerm uint64
|
|
|
- cancel func()
|
|
|
- closer io.Closer
|
|
|
- stopc chan struct{}
|
|
|
- done chan struct{}
|
|
|
+ mu sync.Mutex
|
|
|
+ cancel func()
|
|
|
+ closer io.Closer
|
|
|
+ stopc chan struct{}
|
|
|
+ done chan struct{}
|
|
|
}
|
|
|
|
|
|
-func startStreamReader(tr http.RoundTripper, picker *urlPicker, t streamType, local, remote, cid types.ID, status *peerStatus, recvc chan<- raftpb.Message, propc chan<- raftpb.Message, errorc chan<- error, term uint64) *streamReader {
|
|
|
+func startStreamReader(tr http.RoundTripper, picker *urlPicker, t streamType, local, remote, cid types.ID, status *peerStatus, recvc chan<- raftpb.Message, propc chan<- raftpb.Message, errorc chan<- error) *streamReader {
|
|
|
r := &streamReader{
|
|
|
- tr: tr,
|
|
|
- picker: picker,
|
|
|
- t: t,
|
|
|
- local: local,
|
|
|
- remote: remote,
|
|
|
- cid: cid,
|
|
|
- status: status,
|
|
|
- recvc: recvc,
|
|
|
- propc: propc,
|
|
|
- errorc: errorc,
|
|
|
- msgAppTerm: term,
|
|
|
- stopc: make(chan struct{}),
|
|
|
- done: make(chan struct{}),
|
|
|
+ tr: tr,
|
|
|
+ picker: picker,
|
|
|
+ t: t,
|
|
|
+ local: local,
|
|
|
+ remote: remote,
|
|
|
+ cid: cid,
|
|
|
+ status: status,
|
|
|
+ recvc: recvc,
|
|
|
+ propc: propc,
|
|
|
+ errorc: errorc,
|
|
|
+ stopc: make(chan struct{}),
|
|
|
+ done: make(chan struct{}),
|
|
|
}
|
|
|
go r.run()
|
|
|
return r
|
|
|
@@ -292,12 +265,6 @@ func (cr *streamReader) run() {
|
|
|
for {
|
|
|
t := cr.t
|
|
|
rc, err := cr.dial(t)
|
|
|
- // downgrade to streamTypeMsgApp if the remote doesn't support
|
|
|
- // streamTypeMsgAppV2
|
|
|
- if t == streamTypeMsgAppV2 && err == errUnsupportedStreamType {
|
|
|
- t = streamTypeMsgApp
|
|
|
- rc, err = cr.dial(t)
|
|
|
- }
|
|
|
if err != nil {
|
|
|
if err != errUnsupportedStreamType {
|
|
|
cr.status.deactivate(failureType{source: t.String(), action: "dial"}, err.Error())
|
|
|
@@ -310,9 +277,6 @@ func (cr *streamReader) run() {
|
|
|
case err == io.EOF:
|
|
|
// connection is closed by the remote
|
|
|
case isClosedConnectionError(err):
|
|
|
- // stream msgapp is only used for etcd 2.0, and etcd 2.0 doesn't
|
|
|
- // heartbeat on the idle stream, so it is expected to time out.
|
|
|
- case t == streamTypeMsgApp && isNetworkTimeoutError(err):
|
|
|
default:
|
|
|
cr.status.deactivate(failureType{source: t.String(), action: "read"}, err.Error())
|
|
|
}
|
|
|
@@ -332,8 +296,6 @@ func (cr *streamReader) decodeLoop(rc io.ReadCloser, t streamType) error {
|
|
|
var dec decoder
|
|
|
cr.mu.Lock()
|
|
|
switch t {
|
|
|
- case streamTypeMsgApp:
|
|
|
- dec = &msgAppDecoder{r: rc, local: cr.local, remote: cr.remote, term: cr.msgAppTerm}
|
|
|
case streamTypeMsgAppV2:
|
|
|
dec = newMsgAppV2Decoder(rc, cr.local, cr.remote)
|
|
|
case streamTypeMessage:
|
|
|
@@ -377,20 +339,6 @@ func (cr *streamReader) decodeLoop(rc io.ReadCloser, t streamType) error {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-// updateMsgAppTerm updates the term for MsgApp stream, and closes
|
|
|
-// the existing MsgApp stream if term is updated.
|
|
|
-func (cr *streamReader) updateMsgAppTerm(term uint64) {
|
|
|
- cr.mu.Lock()
|
|
|
- defer cr.mu.Unlock()
|
|
|
- if cr.msgAppTerm >= term {
|
|
|
- return
|
|
|
- }
|
|
|
- cr.msgAppTerm = term
|
|
|
- if cr.t == streamTypeMsgApp {
|
|
|
- cr.close()
|
|
|
- }
|
|
|
-}
|
|
|
-
|
|
|
func (cr *streamReader) stop() {
|
|
|
close(cr.stopc)
|
|
|
cr.mu.Lock()
|
|
|
@@ -410,10 +358,6 @@ func (cr *streamReader) isWorking() bool {
|
|
|
|
|
|
func (cr *streamReader) dial(t streamType) (io.ReadCloser, error) {
|
|
|
u := cr.picker.pick()
|
|
|
- cr.mu.Lock()
|
|
|
- term := cr.msgAppTerm
|
|
|
- cr.mu.Unlock()
|
|
|
-
|
|
|
uu := u
|
|
|
uu.Path = path.Join(t.endpoint(), cr.local.String())
|
|
|
|
|
|
@@ -427,9 +371,6 @@ func (cr *streamReader) dial(t streamType) (io.ReadCloser, error) {
|
|
|
req.Header.Set("X-Min-Cluster-Version", version.MinClusterVersion)
|
|
|
req.Header.Set("X-Etcd-Cluster-ID", cr.cid.String())
|
|
|
req.Header.Set("X-Raft-To", cr.remote.String())
|
|
|
- if t == streamTypeMsgApp {
|
|
|
- req.Header.Set("X-Raft-Term", strconv.FormatUint(term, 10))
|
|
|
- }
|
|
|
|
|
|
cr.mu.Lock()
|
|
|
select {
|