Documentation
¶
Overview ¶
Package transport implements the transport component used for exchanging Raft messages between NodeHosts.
This package is internally used by Dragonboat, applications are not expected to import this package.
Index ¶
- Constants
- Variables
- func NewNOOPTransport(nhConfig config.NodeHostConfig, requestHandler raftio.MessageHandler, ...) raftio.ITransport
- func NewUDPTransport(nhConfig config.NodeHostConfig, requestHandler raftio.MessageHandler, ...) raftio.ITransport
- type Chunk
- type DefaultTransportFactory
- type IMessageHandler
- type ITransport
- type ITransportEvent
- type NOOPConnection
- type NOOPSnapshotConnection
- type NOOPTransport
- func (g *NOOPTransport) Close() error
- func (g *NOOPTransport) GetConnection(ctx context.Context, target string) (raftio.IConnection, error)
- func (g *NOOPTransport) GetSnapshotConnection(ctx context.Context, target string) (raftio.ISnapshotConnection, error)
- func (g *NOOPTransport) Name() string
- func (g *NOOPTransport) Start() error
- type NOOPTransportFactory
- type SendMessageBatchFunc
- type Sink
- type StreamChunkSendFunc
- type Transport
- func (t *Transport) Close() error
- func (t *Transport) GetCircuitBreaker(key string) *circuit.Breaker
- func (t *Transport) GetStreamSink(shardID uint64, replicaID uint64) *Sink
- func (t *Transport) GetTrans() raftio.ITransport
- func (t *Transport) Name() string
- func (t *Transport) Send(req pb.Message) bool
- func (t *Transport) SendSnapshot(m pb.Message) bool
- func (t *Transport) SetPreSendBatchHook(h SendMessageBatchFunc)
- func (t *Transport) SetPreStreamChunkSendHook(h StreamChunkSendFunc)
- type UDP
- type UDPConnection
- type UDPSnapshotConnection
Constants ¶
const (
// UDPTransportName is the name of the tcp transport module.
UDPTransportName = "go-udp-transport"
)
Variables ¶
var ( // ErrStopped is the error returned to indicate that the connection has // already been stopped. ErrStopped = errors.New("connection stopped") // ErrStreamSnapshot is the error returned to indicate that snapshot // streaming failed. ErrStreamSnapshot = errors.New("stream snapshot failed") )
var ( // NOOPRaftName is the module name for the NOOP transport module. NOOPRaftName = "noop-test-transport" // ErrRequestedToFail is the error used to indicate that the error is // requested. ErrRequestedToFail = errors.New("requested to returned error") )
var ( // ErrBadMessage is the error returned to indicate the incoming message is // corrupted. ErrBadMessage = errors.New("invalid message") )
var ( // ErrSnapshotOutOfDate is returned when the snapshot being received is // considered as out of date. ErrSnapshotOutOfDate = errors.New("snapshot is out of date") )
Functions ¶
func NewNOOPTransport ¶
func NewNOOPTransport(nhConfig config.NodeHostConfig, requestHandler raftio.MessageHandler, chunkHandler raftio.ChunkHandler) raftio.ITransport
NewNOOPTransport creates a new NOOPTransport instance.
func NewUDPTransport ¶
func NewUDPTransport(nhConfig config.NodeHostConfig, requestHandler raftio.MessageHandler, chunkHandler raftio.ChunkHandler) raftio.ITransport
Types ¶
type Chunk ¶
type Chunk struct {
// contains filtered or unexported fields
}
Chunk managed on the receiving side
type DefaultTransportFactory ¶
type DefaultTransportFactory struct{}
DefaultTransportFactory is the default transport module used.
func (*DefaultTransportFactory) Create ¶
func (dtm *DefaultTransportFactory) Create(nhConfig config.NodeHostConfig, handler raftio.MessageHandler, chunkHandler raftio.ChunkHandler) raftio.ITransport
Create creates a default transport instance.
func (*DefaultTransportFactory) Validate ¶
func (dtm *DefaultTransportFactory) Validate(addr string) bool
Validate returns a boolean value indicating whether the specified address is valid.
type IMessageHandler ¶
type IMessageHandler interface {
HandleMessageBatch(batch pb.MessageBatch) (uint64, uint64)
HandleUnreachable(shardID uint64, replicaID uint64)
HandleSnapshotStatus(shardID uint64, replicaID uint64, rejected bool)
HandleSnapshot(shardID uint64, replicaID uint64, from uint64)
}
IMessageHandler is the interface required to handle incoming raft requests.
type ITransport ¶
type ITransport interface {
Name() string
Send(pb.Message) bool
SendSnapshot(pb.Message) bool
GetStreamSink(shardID uint64, replicaID uint64) *Sink
Close() error
}
ITransport is the interface of the transport layer used for exchanging Raft messages.
type ITransportEvent ¶
type ITransportEvent interface {
ConnectionEstablished(string, bool)
ConnectionFailed(string, bool)
}
ITransportEvent is the interface for notifying connection status changes.
type NOOPConnection ¶
type NOOPConnection struct {
// contains filtered or unexported fields
}
NOOPConnection is the connection used to exchange messages between node hosts.
func (*NOOPConnection) Close ¶
func (c *NOOPConnection) Close()
Close closes the NOOPConnection instance.
func (*NOOPConnection) SendMessageBatch ¶
func (c *NOOPConnection) SendMessageBatch(batch raftpb.MessageBatch) error
SendMessageBatch return ErrRequestedToFail when requested.
type NOOPSnapshotConnection ¶
type NOOPSnapshotConnection struct {
// contains filtered or unexported fields
}
NOOPSnapshotConnection is the connection used to send snapshots.
func (*NOOPSnapshotConnection) Close ¶
func (c *NOOPSnapshotConnection) Close()
Close closes the NOOPSnapshotConnection.
type NOOPTransport ¶
type NOOPTransport struct {
// contains filtered or unexported fields
}
NOOPTransport is a transport module for testing purposes. It does not actually has the ability to exchange messages or snapshots between nodehosts.
func (*NOOPTransport) Close ¶
func (g *NOOPTransport) Close() error
Close closes the NOOPTransport instance.
func (*NOOPTransport) GetConnection ¶
func (g *NOOPTransport) GetConnection(ctx context.Context, target string) (raftio.IConnection, error)
GetConnection returns a connection.
func (*NOOPTransport) GetSnapshotConnection ¶
func (g *NOOPTransport) GetSnapshotConnection(ctx context.Context, target string) (raftio.ISnapshotConnection, error)
GetSnapshotConnection returns a snapshot connection.
func (*NOOPTransport) Start ¶
func (g *NOOPTransport) Start() error
Start starts the NOOPTransport instance.
type NOOPTransportFactory ¶
type NOOPTransportFactory struct{}
NOOPTransportFactory is a NOOP transport module used in testing
func (*NOOPTransportFactory) Create ¶
func (n *NOOPTransportFactory) Create(nhConfig config.NodeHostConfig, handler raftio.MessageHandler, chunkHandler raftio.ChunkHandler) raftio.ITransport
Create creates a noop transport instance.
func (*NOOPTransportFactory) Validate ¶
func (n *NOOPTransportFactory) Validate(addr string) bool
Validate returns a boolean value indicating whether the input address is valid.
type SendMessageBatchFunc ¶
type SendMessageBatchFunc func(pb.MessageBatch) (pb.MessageBatch, bool)
SendMessageBatchFunc is a func type that is used to determine whether the specified message batch should be sent. This func is used in test only.
type Sink ¶
type Sink struct {
// contains filtered or unexported fields
}
Sink is the chunk sink for receiving generated snapshot chunk.
func (*Sink) ToReplicaID ¶
ToReplicaID returns the node ID of the node intended to get and handle the received snapshot chunk.
type StreamChunkSendFunc ¶
StreamChunkSendFunc is a func type that is used to determine whether a snapshot chunk should indeed be sent. This func is used in test only.
type Transport ¶
type Transport struct {
// contains filtered or unexported fields
}
Transport is the transport layer for delivering raft messages and snapshots.
func NewTransport ¶
func NewTransport(nhConfig config.NodeHostConfig, handler IMessageHandler, env *server.Env, resolver registry.IResolver, dir server.SnapshotDirFunc, sysEvents ITransportEvent, fs vfs.IFS) (*Transport, error)
NewTransport creates a new Transport object.
func (*Transport) GetCircuitBreaker ¶
GetCircuitBreaker returns the circuit breaker used for the specified target node.
func (*Transport) GetStreamSink ¶
GetStreamSink returns a connection used for streaming snapshot.
func (*Transport) GetTrans ¶
func (t *Transport) GetTrans() raftio.ITransport
GetTrans returns the transport instance.
func (*Transport) Send ¶
Send asynchronously sends raft messages to their target nodes.
The generic async send Go pattern used in Send() is found in CockroachDB's codebase.
func (*Transport) SendSnapshot ¶
SendSnapshot asynchronously sends raft snapshot message to its target.
func (*Transport) SetPreSendBatchHook ¶
func (t *Transport) SetPreSendBatchHook(h SendMessageBatchFunc)
SetPreSendBatchHook set the SendMessageBatch hook. This function is only expected to be used in monkey testing.
func (*Transport) SetPreStreamChunkSendHook ¶
func (t *Transport) SetPreStreamChunkSendHook(h StreamChunkSendFunc)
SetPreStreamChunkSendHook sets the StreamChunkSend hook function that will be called before each snapshot chunk is sent.
type UDP ¶
type UDP struct {
// contains filtered or unexported fields
}
func (*UDP) GetConnection ¶
func (*UDP) GetSnapshotConnection ¶
type UDPConnection ¶
type UDPConnection struct {
// contains filtered or unexported fields
}
func NewUDPConnection ¶
func NewUDPConnection(UDPconn *net.UDPConn, encrypted bool) *UDPConnection
NewTCPConnection creates and returns a new UDPConnection instance.
func (*UDPConnection) Close ¶
func (c *UDPConnection) Close()
Close closes the TCPConnection instance.
func (*UDPConnection) SendMessageBatch ¶
func (c *UDPConnection) SendMessageBatch(batch pb.MessageBatch) error
SendMessageBatch sends a raft message batch to remote node.
type UDPSnapshotConnection ¶
type UDPSnapshotConnection struct {
// contains filtered or unexported fields
}
TCPSnapshotConnection is the connection for sending raft snapshot chunks to remote nodes.
func NewUDPSnapshotConnection ¶
func NewUDPSnapshotConnection(conn *net.UDPConn, encrypted bool) *UDPSnapshotConnection
NewTCPSnapshotConnection creates and returns a new snapshot connection.
func (*UDPSnapshotConnection) Close ¶
func (c *UDPSnapshotConnection) Close()
Close closes the snapshot connection.