2016-05-13 06:49:28 +03:00
|
|
|
// Copyright 2015 The etcd Authors
|
2015-01-25 06:19:16 +03:00
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
// you may not use this file except in compliance with the License.
|
|
|
|
// You may obtain a copy of the License at
|
|
|
|
//
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
//
|
|
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
// See the License for the specific language governing permissions and
|
|
|
|
// limitations under the License.
|
|
|
|
|
2014-11-26 08:38:57 +03:00
|
|
|
package rafthttp
|
|
|
|
|
|
|
|
import (
|
|
|
|
"net/http"
|
2014-12-29 04:44:26 +03:00
|
|
|
"sync"
|
2015-08-26 01:14:41 +03:00
|
|
|
"time"
|
2014-11-26 08:38:57 +03:00
|
|
|
|
|
|
|
"github.com/coreos/etcd/etcdserver/stats"
|
2015-11-04 18:17:48 +03:00
|
|
|
"github.com/coreos/etcd/pkg/logutil"
|
2015-10-11 09:04:10 +03:00
|
|
|
"github.com/coreos/etcd/pkg/transport"
|
2014-11-26 08:38:57 +03:00
|
|
|
"github.com/coreos/etcd/pkg/types"
|
2015-03-01 19:17:14 +03:00
|
|
|
"github.com/coreos/etcd/raft"
|
2014-11-26 08:38:57 +03:00
|
|
|
"github.com/coreos/etcd/raft/raftpb"
|
2015-12-08 18:52:54 +03:00
|
|
|
"github.com/coreos/etcd/snap"
|
2016-03-23 03:10:28 +03:00
|
|
|
"github.com/coreos/pkg/capnslog"
|
|
|
|
"github.com/xiang90/probing"
|
|
|
|
"golang.org/x/net/context"
|
2014-11-26 08:38:57 +03:00
|
|
|
)
|
|
|
|
|
2015-11-04 18:17:48 +03:00
|
|
|
var plog = logutil.NewMergeLogger(capnslog.NewPackageLogger("github.com/coreos/etcd", "rafthttp"))
|
2015-06-03 01:33:58 +03:00
|
|
|
|
2014-12-29 04:44:26 +03:00
|
|
|
type Raft interface {
|
2014-11-26 08:38:57 +03:00
|
|
|
Process(ctx context.Context, m raftpb.Message) error
|
2015-04-26 09:24:59 +03:00
|
|
|
IsIDRemoved(id uint64) bool
|
2015-03-01 18:02:24 +03:00
|
|
|
ReportUnreachable(id uint64)
|
2015-03-01 19:17:14 +03:00
|
|
|
ReportSnapshot(id uint64, status raft.SnapshotStatus)
|
2014-11-26 08:38:57 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
type Transporter interface {
|
2015-10-11 01:58:02 +03:00
|
|
|
// Start starts the given Transporter.
|
|
|
|
// Start MUST be called before calling other functions in the interface.
|
2015-10-11 09:04:10 +03:00
|
|
|
Start() error
|
2015-03-03 21:22:41 +03:00
|
|
|
// Handler returns the HTTP handler of the transporter.
|
|
|
|
// A transporter HTTP handler handles the HTTP requests
|
|
|
|
// from remote peers.
|
|
|
|
// The handler MUST be used to handle RaftPrefix(/raft)
|
|
|
|
// endpoint.
|
2014-11-26 08:38:57 +03:00
|
|
|
Handler() http.Handler
|
2015-03-03 21:22:41 +03:00
|
|
|
// Send sends out the given messages to the remote peers.
|
|
|
|
// Each message has a To field, which is an id that maps
|
|
|
|
// to an existing peer in the transport.
|
|
|
|
// If the id cannot be found in the transport, the message
|
|
|
|
// will be ignored.
|
2014-11-26 08:38:57 +03:00
|
|
|
Send(m []raftpb.Message)
|
2015-12-08 18:52:54 +03:00
|
|
|
// SendSnapshot sends out the given snapshot message to a remote peer.
|
|
|
|
// The behavior of SendSnapshot is similar to Send.
|
|
|
|
SendSnapshot(m snap.Message)
|
2015-04-21 09:48:36 +03:00
|
|
|
// AddRemote adds a remote with given peer urls into the transport.
|
|
|
|
// A remote helps newly joined member to catch up the progress of cluster,
|
|
|
|
// and will not be used after that.
|
2015-08-07 20:57:11 +03:00
|
|
|
// It is the caller's responsibility to ensure the urls are all valid,
|
2015-04-21 09:48:36 +03:00
|
|
|
// or it panics.
|
|
|
|
AddRemote(id types.ID, urls []string)
|
2015-03-03 21:22:41 +03:00
|
|
|
// AddPeer adds a peer with given peer urls into the transport.
|
2015-08-07 20:57:11 +03:00
|
|
|
// It is the caller's responsibility to ensure the urls are all valid,
|
2015-03-03 21:22:41 +03:00
|
|
|
// or it panics.
|
|
|
|
// Peer urls are used to connect to the remote peer.
|
2014-11-26 08:38:57 +03:00
|
|
|
AddPeer(id types.ID, urls []string)
|
2015-03-03 21:22:41 +03:00
|
|
|
// RemovePeer removes the peer with given id.
|
2014-11-26 08:38:57 +03:00
|
|
|
RemovePeer(id types.ID)
|
2015-03-03 21:22:41 +03:00
|
|
|
// RemoveAllPeers removes all the existing peers in the transport.
|
2015-02-12 21:48:06 +03:00
|
|
|
RemoveAllPeers()
|
2015-03-03 21:22:41 +03:00
|
|
|
// UpdatePeer updates the peer urls of the peer with the given id.
|
2015-08-07 20:57:11 +03:00
|
|
|
// It is the caller's responsibility to ensure the urls are all valid,
|
2015-03-03 21:22:41 +03:00
|
|
|
// or it panics.
|
2014-11-26 08:38:57 +03:00
|
|
|
UpdatePeer(id types.ID, urls []string)
|
2015-08-26 01:14:41 +03:00
|
|
|
// ActiveSince returns the time that the connection with the peer
|
|
|
|
// of the given id becomes active.
|
|
|
|
// If the connection is active since peer was added, it returns the adding time.
|
|
|
|
// If the connection is currently inactive, it returns zero time.
|
|
|
|
ActiveSince(id types.ID) time.Time
|
2015-03-03 21:22:41 +03:00
|
|
|
// Stop closes the connections and stops the transporter.
|
2014-11-26 08:38:57 +03:00
|
|
|
Stop()
|
|
|
|
}
|
|
|
|
|
2015-10-11 01:58:02 +03:00
|
|
|
// Transport implements Transporter interface. It provides the functionality
|
|
|
|
// to send raft messages to peers, and receive raft messages from peers.
|
|
|
|
// User should call Handler method to get a handler to serve requests
|
|
|
|
// received from peerURLs.
|
|
|
|
// User needs to call Start before calling other functions, and call
|
|
|
|
// Stop when the Transport is no longer used.
|
|
|
|
type Transport struct {
|
2015-10-11 09:04:10 +03:00
|
|
|
DialTimeout time.Duration // maximum duration before timing out dial of the request
|
|
|
|
TLSInfo transport.TLSInfo // TLS information used when creating connection
|
|
|
|
|
2016-02-05 09:05:59 +03:00
|
|
|
ID types.ID // local member ID
|
|
|
|
URLs types.URLs // local peer URLs
|
|
|
|
ClusterID types.ID // raft cluster ID for request validation
|
|
|
|
Raft Raft // raft state machine, to which the Transport forwards received messages and reports status
|
2015-12-08 18:52:54 +03:00
|
|
|
Snapshotter *snap.Snapshotter
|
2015-10-11 09:04:10 +03:00
|
|
|
ServerStats *stats.ServerStats // used to record general transportation statistics
|
2015-10-11 01:58:02 +03:00
|
|
|
// used to record transportation statistics with followers when
|
|
|
|
// performing as leader in raft protocol
|
|
|
|
LeaderStats *stats.LeaderStats
|
2016-02-24 11:45:40 +03:00
|
|
|
// ErrorC is used to report detected critical errors, e.g.,
|
2015-10-11 01:58:02 +03:00
|
|
|
// the member has been permanently removed from the cluster
|
|
|
|
// When an error is received from ErrorC, user should stop raft state
|
|
|
|
// machine and thus stop the Transport.
|
|
|
|
ErrorC chan error
|
2014-11-26 08:38:57 +03:00
|
|
|
|
2015-10-11 09:04:10 +03:00
|
|
|
streamRt http.RoundTripper // roundTripper used by streams
|
|
|
|
pipelineRt http.RoundTripper // roundTripper used by pipelines
|
|
|
|
|
2015-10-20 09:41:01 +03:00
|
|
|
mu sync.RWMutex // protect the remote and peer map
|
2015-04-21 09:48:36 +03:00
|
|
|
remotes map[types.ID]*remote // remotes map that helps newly joined member to catch up
|
|
|
|
peers map[types.ID]Peer // peers map
|
2015-08-03 04:07:16 +03:00
|
|
|
|
|
|
|
prober probing.Prober
|
2014-11-26 08:38:57 +03:00
|
|
|
}
|
|
|
|
|
2015-10-11 09:04:10 +03:00
|
|
|
func (t *Transport) Start() error {
|
|
|
|
var err error
|
2015-11-04 02:13:50 +03:00
|
|
|
t.streamRt, err = newStreamRoundTripper(t.TLSInfo, t.DialTimeout)
|
2015-10-11 09:04:10 +03:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2015-11-04 02:13:50 +03:00
|
|
|
t.pipelineRt, err = NewRoundTripper(t.TLSInfo, t.DialTimeout)
|
2015-10-11 09:04:10 +03:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2015-10-11 01:58:02 +03:00
|
|
|
t.remotes = make(map[types.ID]*remote)
|
|
|
|
t.peers = make(map[types.ID]Peer)
|
2015-10-11 09:04:10 +03:00
|
|
|
t.prober = probing.NewProber(t.pipelineRt)
|
|
|
|
return nil
|
2014-12-29 04:44:26 +03:00
|
|
|
}
|
|
|
|
|
2015-10-11 01:58:02 +03:00
|
|
|
func (t *Transport) Handler() http.Handler {
|
2016-02-05 09:05:59 +03:00
|
|
|
pipelineHandler := newPipelineHandler(t, t.Raft, t.ClusterID)
|
2016-02-03 08:00:15 +03:00
|
|
|
streamHandler := newStreamHandler(t, t, t.Raft, t.ID, t.ClusterID)
|
2016-02-05 09:05:59 +03:00
|
|
|
snapHandler := newSnapshotHandler(t, t.Raft, t.Snapshotter, t.ClusterID)
|
2014-11-26 08:38:57 +03:00
|
|
|
mux := http.NewServeMux()
|
2015-02-15 19:44:34 +03:00
|
|
|
mux.Handle(RaftPrefix, pipelineHandler)
|
|
|
|
mux.Handle(RaftStreamPrefix+"/", streamHandler)
|
2015-10-11 21:49:52 +03:00
|
|
|
mux.Handle(RaftSnapshotPrefix, snapHandler)
|
2015-08-03 04:07:16 +03:00
|
|
|
mux.Handle(ProbingPrefix, probing.NewHandler())
|
2014-12-29 04:44:26 +03:00
|
|
|
return mux
|
|
|
|
}
|
|
|
|
|
2015-10-11 01:58:02 +03:00
|
|
|
func (t *Transport) Get(id types.ID) Peer {
|
2014-12-29 04:44:26 +03:00
|
|
|
t.mu.RLock()
|
|
|
|
defer t.mu.RUnlock()
|
|
|
|
return t.peers[id]
|
|
|
|
}
|
|
|
|
|
2015-10-11 01:58:02 +03:00
|
|
|
func (t *Transport) Send(msgs []raftpb.Message) {
|
2014-12-29 04:44:26 +03:00
|
|
|
for _, m := range msgs {
|
|
|
|
if m.To == 0 {
|
2015-10-18 09:30:30 +03:00
|
|
|
// ignore intentionally dropped message
|
2014-12-29 04:44:26 +03:00
|
|
|
continue
|
|
|
|
}
|
|
|
|
to := types.ID(m.To)
|
2015-04-21 09:48:36 +03:00
|
|
|
|
2015-10-27 06:26:43 +03:00
|
|
|
t.mu.RLock()
|
2016-03-27 13:07:33 +03:00
|
|
|
p, pok := t.peers[to]
|
|
|
|
g, rok := t.remotes[to]
|
2015-10-27 06:26:43 +03:00
|
|
|
t.mu.RUnlock()
|
|
|
|
|
2016-03-27 13:07:33 +03:00
|
|
|
if pok {
|
2015-04-21 09:48:36 +03:00
|
|
|
if m.Type == raftpb.MsgApp {
|
2015-10-11 01:58:02 +03:00
|
|
|
t.ServerStats.SendAppendReq(m.Size())
|
2015-04-21 09:48:36 +03:00
|
|
|
}
|
2015-10-18 09:30:30 +03:00
|
|
|
p.send(m)
|
2014-12-29 04:44:26 +03:00
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
2016-03-27 13:07:33 +03:00
|
|
|
if rok {
|
2015-10-18 09:30:30 +03:00
|
|
|
g.send(m)
|
2015-04-21 09:48:36 +03:00
|
|
|
continue
|
2014-12-29 04:44:26 +03:00
|
|
|
}
|
|
|
|
|
2015-06-03 01:33:58 +03:00
|
|
|
plog.Debugf("ignored message %s (sent to unknown peer %s)", m.Type, to)
|
2014-12-29 04:44:26 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-10-11 01:58:02 +03:00
|
|
|
func (t *Transport) Stop() {
|
2016-02-06 00:53:43 +03:00
|
|
|
t.mu.Lock()
|
|
|
|
defer t.mu.Unlock()
|
2015-04-21 09:48:36 +03:00
|
|
|
for _, r := range t.remotes {
|
2015-10-18 09:30:30 +03:00
|
|
|
r.stop()
|
2015-04-21 09:48:36 +03:00
|
|
|
}
|
2014-12-29 04:44:26 +03:00
|
|
|
for _, p := range t.peers {
|
2015-10-18 09:30:30 +03:00
|
|
|
p.stop()
|
2014-12-29 04:44:26 +03:00
|
|
|
}
|
2015-08-04 12:42:51 +03:00
|
|
|
t.prober.RemoveAll()
|
2015-10-11 09:04:10 +03:00
|
|
|
if tr, ok := t.streamRt.(*http.Transport); ok {
|
|
|
|
tr.CloseIdleConnections()
|
|
|
|
}
|
|
|
|
if tr, ok := t.pipelineRt.(*http.Transport); ok {
|
2014-12-29 04:44:26 +03:00
|
|
|
tr.CloseIdleConnections()
|
|
|
|
}
|
2016-04-28 08:05:59 +03:00
|
|
|
t.peers = nil
|
|
|
|
t.remotes = nil
|
2014-11-26 08:38:57 +03:00
|
|
|
}
|
|
|
|
|
2015-10-11 01:58:02 +03:00
|
|
|
func (t *Transport) AddRemote(id types.ID, us []string) {
|
2015-04-21 09:48:36 +03:00
|
|
|
t.mu.Lock()
|
|
|
|
defer t.mu.Unlock()
|
2016-04-28 08:05:59 +03:00
|
|
|
if t.remotes == nil {
|
|
|
|
// there's no clean way to shutdown the golang http server
|
|
|
|
// (see: https://github.com/golang/go/issues/4674) before
|
|
|
|
// stopping the transport; ignore any new connections.
|
|
|
|
return
|
|
|
|
}
|
2016-02-05 09:05:59 +03:00
|
|
|
if _, ok := t.peers[id]; ok {
|
|
|
|
return
|
|
|
|
}
|
2015-04-21 09:48:36 +03:00
|
|
|
if _, ok := t.remotes[id]; ok {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
urls, err := types.NewURLs(us)
|
|
|
|
if err != nil {
|
2015-06-03 01:33:58 +03:00
|
|
|
plog.Panicf("newURLs %+v should never fail: %+v", us, err)
|
2015-04-21 09:48:36 +03:00
|
|
|
}
|
2016-06-02 07:47:46 +03:00
|
|
|
t.remotes[id] = startRemote(t, urls, id)
|
2015-04-21 09:48:36 +03:00
|
|
|
}
|
|
|
|
|
2015-10-11 01:58:02 +03:00
|
|
|
func (t *Transport) AddPeer(id types.ID, us []string) {
|
2014-12-29 04:44:26 +03:00
|
|
|
t.mu.Lock()
|
|
|
|
defer t.mu.Unlock()
|
2016-06-01 07:12:41 +03:00
|
|
|
|
2016-04-28 08:05:59 +03:00
|
|
|
if t.peers == nil {
|
|
|
|
panic("transport stopped")
|
|
|
|
}
|
2014-12-29 04:44:26 +03:00
|
|
|
if _, ok := t.peers[id]; ok {
|
|
|
|
return
|
|
|
|
}
|
2015-02-27 18:54:06 +03:00
|
|
|
urls, err := types.NewURLs(us)
|
2014-12-29 04:44:26 +03:00
|
|
|
if err != nil {
|
2015-06-03 01:33:58 +03:00
|
|
|
plog.Panicf("newURLs %+v should never fail: %+v", us, err)
|
2014-12-29 04:44:26 +03:00
|
|
|
}
|
2015-10-11 01:58:02 +03:00
|
|
|
fs := t.LeaderStats.Follower(id.String())
|
2016-06-02 07:47:46 +03:00
|
|
|
t.peers[id] = startPeer(t, urls, id, fs)
|
2015-08-03 04:07:16 +03:00
|
|
|
addPeerToProber(t.prober, id.String(), us)
|
2016-06-01 07:12:41 +03:00
|
|
|
|
|
|
|
plog.Infof("added peer %s", id)
|
2014-12-29 04:44:26 +03:00
|
|
|
}
|
|
|
|
|
2015-10-11 01:58:02 +03:00
|
|
|
func (t *Transport) RemovePeer(id types.ID) {
|
2014-12-29 04:44:26 +03:00
|
|
|
t.mu.Lock()
|
|
|
|
defer t.mu.Unlock()
|
2015-02-12 21:48:06 +03:00
|
|
|
t.removePeer(id)
|
|
|
|
}
|
|
|
|
|
2015-10-11 01:58:02 +03:00
|
|
|
func (t *Transport) RemoveAllPeers() {
|
2015-02-12 21:48:06 +03:00
|
|
|
t.mu.Lock()
|
|
|
|
defer t.mu.Unlock()
|
2015-08-22 04:52:16 +03:00
|
|
|
for id := range t.peers {
|
2015-02-12 21:48:06 +03:00
|
|
|
t.removePeer(id)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// the caller of this function must have the peers mutex.
|
2015-10-11 01:58:02 +03:00
|
|
|
func (t *Transport) removePeer(id types.ID) {
|
2015-02-12 05:37:02 +03:00
|
|
|
if peer, ok := t.peers[id]; ok {
|
2015-10-18 09:30:30 +03:00
|
|
|
peer.stop()
|
2015-02-12 05:37:02 +03:00
|
|
|
} else {
|
2015-06-03 01:33:58 +03:00
|
|
|
plog.Panicf("unexpected removal of unknown peer '%d'", id)
|
2015-02-12 05:37:02 +03:00
|
|
|
}
|
2014-12-29 04:44:26 +03:00
|
|
|
delete(t.peers, id)
|
2015-10-11 01:58:02 +03:00
|
|
|
delete(t.LeaderStats.Followers, id.String())
|
2015-08-03 04:07:16 +03:00
|
|
|
t.prober.Remove(id.String())
|
2016-06-01 07:12:41 +03:00
|
|
|
plog.Infof("removed peer %s", id)
|
2014-12-29 04:44:26 +03:00
|
|
|
}
|
|
|
|
|
2015-10-11 01:58:02 +03:00
|
|
|
func (t *Transport) UpdatePeer(id types.ID, us []string) {
|
2014-12-29 04:44:26 +03:00
|
|
|
t.mu.Lock()
|
|
|
|
defer t.mu.Unlock()
|
|
|
|
// TODO: return error or just panic?
|
|
|
|
if _, ok := t.peers[id]; !ok {
|
|
|
|
return
|
|
|
|
}
|
2015-02-27 18:54:06 +03:00
|
|
|
urls, err := types.NewURLs(us)
|
2014-12-29 04:44:26 +03:00
|
|
|
if err != nil {
|
2015-06-03 01:33:58 +03:00
|
|
|
plog.Panicf("newURLs %+v should never fail: %+v", us, err)
|
2014-12-29 04:44:26 +03:00
|
|
|
}
|
2015-10-18 09:30:30 +03:00
|
|
|
t.peers[id].update(urls)
|
2015-08-03 04:07:16 +03:00
|
|
|
|
|
|
|
t.prober.Remove(id.String())
|
|
|
|
addPeerToProber(t.prober, id.String(), us)
|
2016-06-01 07:12:41 +03:00
|
|
|
plog.Infof("updated peer %s", id)
|
2014-12-29 04:44:26 +03:00
|
|
|
}
|
|
|
|
|
2015-10-11 01:58:02 +03:00
|
|
|
func (t *Transport) ActiveSince(id types.ID) time.Time {
|
2015-08-26 01:14:41 +03:00
|
|
|
t.mu.Lock()
|
|
|
|
defer t.mu.Unlock()
|
|
|
|
if p, ok := t.peers[id]; ok {
|
|
|
|
return p.activeSince()
|
|
|
|
}
|
|
|
|
return time.Time{}
|
|
|
|
}
|
|
|
|
|
2015-12-08 18:52:54 +03:00
|
|
|
func (t *Transport) SendSnapshot(m snap.Message) {
|
2016-02-17 06:18:05 +03:00
|
|
|
t.mu.Lock()
|
|
|
|
defer t.mu.Unlock()
|
2015-12-08 18:52:54 +03:00
|
|
|
p := t.peers[types.ID(m.To)]
|
|
|
|
if p == nil {
|
2015-12-24 03:03:23 +03:00
|
|
|
m.CloseWithError(errMemberNotFound)
|
2015-12-08 18:52:54 +03:00
|
|
|
return
|
|
|
|
}
|
|
|
|
p.sendSnap(m)
|
2015-10-11 21:49:52 +03:00
|
|
|
}
|
|
|
|
|
2016-02-21 16:05:03 +03:00
|
|
|
// Pausable is a testing interface for pausing transport traffic.
|
2014-12-29 23:20:52 +03:00
|
|
|
type Pausable interface {
|
|
|
|
Pause()
|
|
|
|
Resume()
|
|
|
|
}
|
|
|
|
|
2015-10-11 01:58:02 +03:00
|
|
|
func (t *Transport) Pause() {
|
2014-12-29 04:44:26 +03:00
|
|
|
for _, p := range t.peers {
|
2015-02-26 11:13:35 +03:00
|
|
|
p.(Pausable).Pause()
|
2014-12-29 04:44:26 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-10-11 01:58:02 +03:00
|
|
|
func (t *Transport) Resume() {
|
2014-12-29 04:44:26 +03:00
|
|
|
for _, p := range t.peers {
|
2015-02-26 11:13:35 +03:00
|
|
|
p.(Pausable).Resume()
|
2014-12-29 04:44:26 +03:00
|
|
|
}
|
|
|
|
}
|
2016-01-04 22:24:49 +03:00
|
|
|
|
|
|
|
type nopTransporter struct{}
|
|
|
|
|
|
|
|
func NewNopTransporter() Transporter {
|
|
|
|
return &nopTransporter{}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *nopTransporter) Start() error { return nil }
|
|
|
|
func (s *nopTransporter) Handler() http.Handler { return nil }
|
|
|
|
func (s *nopTransporter) Send(m []raftpb.Message) {}
|
|
|
|
func (s *nopTransporter) SendSnapshot(m snap.Message) {}
|
|
|
|
func (s *nopTransporter) AddRemote(id types.ID, us []string) {}
|
|
|
|
func (s *nopTransporter) AddPeer(id types.ID, us []string) {}
|
|
|
|
func (s *nopTransporter) RemovePeer(id types.ID) {}
|
|
|
|
func (s *nopTransporter) RemoveAllPeers() {}
|
|
|
|
func (s *nopTransporter) UpdatePeer(id types.ID, us []string) {}
|
|
|
|
func (s *nopTransporter) ActiveSince(id types.ID) time.Time { return time.Time{} }
|
|
|
|
func (s *nopTransporter) Stop() {}
|
|
|
|
func (s *nopTransporter) Pause() {}
|
|
|
|
func (s *nopTransporter) Resume() {}
|
|
|
|
|
|
|
|
type snapTransporter struct {
|
|
|
|
nopTransporter
|
|
|
|
snapDoneC chan snap.Message
|
|
|
|
snapDir string
|
|
|
|
}
|
|
|
|
|
|
|
|
func NewSnapTransporter(snapDir string) (Transporter, <-chan snap.Message) {
|
|
|
|
ch := make(chan snap.Message, 1)
|
|
|
|
tr := &snapTransporter{snapDoneC: ch, snapDir: snapDir}
|
|
|
|
return tr, ch
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *snapTransporter) SendSnapshot(m snap.Message) {
|
|
|
|
ss := snap.New(s.snapDir)
|
|
|
|
ss.SaveDBFrom(m.ReadCloser, m.Snapshot.Metadata.Index+1)
|
|
|
|
m.CloseWithError(nil)
|
|
|
|
s.snapDoneC <- m
|
|
|
|
}
|