etcd: Index | Files

package rafthttp

import ""

Package rafthttp implements HTTP transportation layer for etcd/raft pkg.


Package Files

coder.go doc.go http.go metrics.go msg_codec.go msgappv2_codec.go peer.go peer_status.go pipeline.go probing_status.go remote.go snapshot_sender.go stream.go transport.go urlpick.go util.go


const (
    // ConnReadTimeout and ConnWriteTimeout are the i/o timeout set on each connection rafthttp pkg creates.
    // A 5 seconds timeout is good enough for recycling bad connections. Or we have to wait for
    // tcp keepalive failing to detect a bad connection, which is at minutes level.
    // For long term streaming connections, rafthttp pkg sends application level linkHeartbeatMessage
    // to keep the connection alive.
    // For short term pipeline connections, the connection MUST be killed to avoid it being
    // put back to http pkg connection pool.
    ConnReadTimeout  = 5 * time.Second
    ConnWriteTimeout = 5 * time.Second
const (
    // RoundTripperNameRaftMessage is the name of round-tripper that sends
    // all other Raft messages, other than "snap.Message".
    RoundTripperNameRaftMessage = "ROUND_TRIPPER_RAFT_MESSAGE"
    // RoundTripperNameSnapshot is the name of round-tripper that sends merged snapshot message.
    RoundTripperNameSnapshot = "ROUND_TRIPPER_SNAPSHOT"


var (
    RaftPrefix         = "/raft"
    ProbingPrefix      = path.Join(RaftPrefix, "probing")
    RaftStreamPrefix   = path.Join(RaftPrefix, "stream")
    RaftSnapshotPrefix = path.Join(RaftPrefix, "snapshot")
var (
    ErrExceedSizeLimit = errors.New("rafthttp: error limit exceeded")

func NewListener Uses

func NewListener(u url.URL, tlsinfo *transport.TLSInfo) (net.Listener, error)

NewListener returns a listener for raft message transfer between peers. It uses timeout listener to identify broken streams promptly.

func NewRoundTripper Uses

func NewRoundTripper(tlsInfo transport.TLSInfo, dialTimeout time.Duration) (http.RoundTripper, error)

NewRoundTripper returns a roundTripper used to send requests to rafthttp listener of remote peers.

type Pausable Uses

type Pausable interface {

Pausable is a testing interface for pausing transport traffic.

type Peer Uses

type Peer interface {
    // contains filtered or unexported methods

type Raft Uses

type Raft interface {
    Process(ctx context.Context, m raftpb.Message) error
    IsIDRemoved(id uint64) bool
    ReportUnreachable(id uint64)
    ReportSnapshot(id uint64, status raft.SnapshotStatus)

type Transport Uses

type Transport struct {
    Logger *zap.Logger

    DialTimeout time.Duration // maximum duration before timing out dial of the request
    // DialRetryFrequency defines the frequency of streamReader dial retrial attempts;
    // a distinct rate limiter is created per every peer (default value: 10 events/sec)
    DialRetryFrequency rate.Limit

    TLSInfo transport.TLSInfo // TLS information used when creating connection

    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
    Snapshotter *snap.Snapshotter
    ServerStats *stats.ServerStats // used to record general transportation statistics
    // used to record transportation statistics with followers when
    // performing as leader in raft protocol
    LeaderStats *stats.LeaderStats
    // ErrorC is used to report detected critical errors, e.g.,
    // 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
    // contains filtered or unexported fields

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.

func (*Transport) ActivePeers Uses

func (t *Transport) ActivePeers() (cnt int)

ActivePeers returns a channel that closes when an initial peer connection has been established. Use this to wait until the first peer connection becomes active.

func (*Transport) ActiveSince Uses

func (t *Transport) ActiveSince(id types.ID) time.Time

func (*Transport) AddPeer Uses

func (t *Transport) AddPeer(id types.ID, us []string)

func (*Transport) AddRemote Uses

func (t *Transport) AddRemote(id types.ID, us []string)

func (*Transport) CutPeer Uses

func (t *Transport) CutPeer(id types.ID)

CutPeer drops messages to the specified peer.

func (*Transport) Get Uses

func (t *Transport) Get(id types.ID) Peer

func (*Transport) Handler Uses

func (t *Transport) Handler() http.Handler

func (*Transport) MendPeer Uses

func (t *Transport) MendPeer(id types.ID)

MendPeer recovers the message dropping behavior of the given peer.

func (*Transport) Pause Uses

func (t *Transport) Pause()

func (*Transport) RemoveAllPeers Uses

func (t *Transport) RemoveAllPeers()

func (*Transport) RemovePeer Uses

func (t *Transport) RemovePeer(id types.ID)

func (*Transport) Resume Uses

func (t *Transport) Resume()

func (*Transport) Send Uses

func (t *Transport) Send(msgs []raftpb.Message)

func (*Transport) SendSnapshot Uses

func (t *Transport) SendSnapshot(m snap.Message)

func (*Transport) Start Uses

func (t *Transport) Start() error

func (*Transport) Stop Uses

func (t *Transport) Stop()

func (*Transport) UpdatePeer Uses

func (t *Transport) UpdatePeer(id types.ID, us []string)

type Transporter Uses

type Transporter interface {
    // Start starts the given Transporter.
    // Start MUST be called before calling other functions in the interface.
    Start() error
    // 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.
    Handler() http.Handler
    // 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.
    Send(m []raftpb.Message)
    // SendSnapshot sends out the given snapshot message to a remote peer.
    // The behavior of SendSnapshot is similar to Send.
    SendSnapshot(m snap.Message)
    // 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.
    // It is the caller's responsibility to ensure the urls are all valid,
    // or it panics.
    AddRemote(id types.ID, urls []string)
    // AddPeer adds a peer with given peer urls into the transport.
    // It is the caller's responsibility to ensure the urls are all valid,
    // or it panics.
    // Peer urls are used to connect to the remote peer.
    AddPeer(id types.ID, urls []string)
    // RemovePeer removes the peer with given id.
    RemovePeer(id types.ID)
    // RemoveAllPeers removes all the existing peers in the transport.
    // UpdatePeer updates the peer urls of the peer with the given id.
    // It is the caller's responsibility to ensure the urls are all valid,
    // or it panics.
    UpdatePeer(id types.ID, urls []string)
    // 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
    // ActivePeers returns the number of active peers.
    ActivePeers() int
    // Stop closes the connections and stops the transporter.

Package rafthttp imports 32 packages (graph). Updated 2019-08-10. Refresh now. Tools for package owners.