transport

package
v0.3.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 9, 2022 License: Apache-2.0 Imports: 24 Imported by: 1

Documentation

Index

Constants

View Source
const (
	SnapshotChunkSize = 1024 * 1024 * 4
)
View Source
const (
	// TCPTransportName is the name of the tcp transport module.
	TCPTransportName = "go-tcp-transport"
)

Variables

View Source
var (
	// ErrBadMessage is the error returned to indicate the incoming message is
	// corrupted.
	ErrBadMessage = errors.New("invalid message")
)
View Source
var (
	// ErrSnapshotOutOfDate is returned when the snapshot being received is
	// considered as out of date.
	ErrSnapshotOutOfDate = errors.New("snapshot is out of date")
)
View Source
var (
	// ErrStopped is the error returned to indicate that the connection has
	// already been stopped.
	ErrStopped = errors.New("connection stopped")
)

Functions

This section is empty.

Types

type Chunk added in v0.2.0

type Chunk struct {
	// contains filtered or unexported fields
}

Chunk managed on the receiving side

func NewChunk added in v0.2.0

func NewChunk(logger *zap.Logger,
	onReceive func(meta.RaftMessageBatch),
	dir snapshot.SnapshotDirFunc, fs vfs.FS) *Chunk

NewChunk creates and returns a new snapshot chunks instance.

func (*Chunk) Add added in v0.2.0

func (c *Chunk) Add(chunk meta.SnapshotChunk) bool

Add adds a received trunk to chunks.

func (*Chunk) Close added in v0.2.0

func (c *Chunk) Close()

Close closes the chunks instance.

func (*Chunk) Tick added in v0.2.0

func (c *Chunk) Tick()

Tick moves the internal logical clock forward.

type Connection added in v0.2.0

type Connection interface {
	// Close closes the Connection instance.
	Close()
	// SendMessageBatch sends the specified message batch to the target. It is
	// recommended to deliver the message batch to the target in order to enjoy
	// best possible performance, but out of order delivery is allowed at the
	// cost of reduced performance.
	SendMessageBatch(batch meta.RaftMessageBatch) error
}

Connection is the interface used by the transport module for sending Raft messages. Each Connection works for a specified target store instance, it is possible for a target to have multiple concurrent Connection instances in use.

type ContainerResolver

type ContainerResolver func(storeID uint64) (string, error)

type MessageHandler

type MessageHandler func(meta.RaftMessageBatch)

type SnapshotChunkHandler added in v0.2.0

type SnapshotChunkHandler func(meta.SnapshotChunk) bool

type SnapshotConnection added in v0.2.0

type SnapshotConnection interface {
	// Close closes the SnapshotConnection instance.
	Close()
	// SendChunk sends the snapshot chunk to the target. It is
	// recommended to have the snapshot chunk delivered in order for the best
	// performance, but out of order delivery is allowed at the cost of reduced
	// performance.
	SendChunk(chunk meta.SnapshotChunk) error
}

SnapshotConnection is the interface used by the transport module for sending snapshot chunks. Each SnapshotConnection works for a specified target store instance.

type SnapshotStatusHandler added in v0.2.0

type SnapshotStatusHandler func(uint64, uint64, raftpb.Snapshot, bool)

type TCP added in v0.2.0

type TCP struct {
	// contains filtered or unexported fields
}

TCP is a TCP based transport module for exchanging raft messages and snapshots between NodeHost instances.

func (*TCP) Close added in v0.2.0

func (t *TCP) Close() error

Close closes the TCP transport module.

func (*TCP) GetConnection added in v0.2.0

func (t *TCP) GetConnection(ctx context.Context, target string) (Connection, error)

GetConnection returns a new raftio.IConnection for sending raft messages.

func (*TCP) GetSnapshotConnection added in v0.2.0

func (t *TCP) GetSnapshotConnection(ctx context.Context,
	target string) (SnapshotConnection, error)

GetSnapshotConnection returns a new raftio.IConnection for sending raft snapshots.

func (*TCP) Name added in v0.2.0

func (t *TCP) Name() string

Name returns a human readable name of the TCP transport module.

func (*TCP) Start added in v0.2.0

func (t *TCP) Start() error

Start starts the TCP transport module.

type TCPConnection added in v0.2.0

type TCPConnection struct {
	// contains filtered or unexported fields
}

TCPConnection is the connection used for sending raft messages to remote nodes.

func NewTCPConnection added in v0.2.0

func NewTCPConnection(logger *zap.Logger,
	conn net.Conn, encrypted bool) *TCPConnection

NewTCPConnection creates and returns a new TCPConnection instance.

func (*TCPConnection) Close added in v0.2.0

func (c *TCPConnection) Close()

Close closes the TCPConnection instance.

func (*TCPConnection) SendMessageBatch added in v0.2.0

func (c *TCPConnection) SendMessageBatch(batch meta.RaftMessageBatch) error

SendMessageBatch sends a raft message batch to remote node.

type TCPSnapshotConnection added in v0.2.0

type TCPSnapshotConnection struct {
	// contains filtered or unexported fields
}

TCPSnapshotConnection is the connection for sending raft snapshot chunks to remote nodes.

func NewTCPSnapshotConnection added in v0.2.0

func NewTCPSnapshotConnection(logger *zap.Logger,
	conn net.Conn, encrypted bool) *TCPSnapshotConnection

NewTCPSnapshotConnection creates and returns a new snapshot connection.

func (*TCPSnapshotConnection) Close added in v0.2.0

func (c *TCPSnapshotConnection) Close()

Close closes the snapshot connection.

func (*TCPSnapshotConnection) SendChunk added in v0.2.0

func (c *TCPSnapshotConnection) SendChunk(chunk meta.SnapshotChunk) error

SendChunk sends the specified snapshot chunk to remote node.

type Trans added in v0.2.0

type Trans interface {
	Send(meta.RaftMessage) bool
	SendSnapshot(meta.RaftMessage) bool
	SetFilter(func(meta.RaftMessage) bool)
	SendingSnapshotCount() uint64
	Start() error
	Close() error
}

type TransImpl added in v0.2.0

type TransImpl interface {
	// Name returns the type name of the TransImpl instance.
	Name() string
	// Start launches the transport module and make it ready to start sending and
	// receiving Raft messages. If necessary, TransImpl may take this opportunity
	// to start listening for incoming data.
	Start() error
	// Close closes the transport module.
	Close() error
	// GetConnection returns an Connection instance used for sending messages
	// to the specified target store instance.
	GetConnection(ctx context.Context, target string) (Connection, error)
	// GetSnapshotConnection returns an Connection instance used for transporting
	// snapshots to the specified store instance.
	GetSnapshotConnection(ctx context.Context,
		target string) (SnapshotConnection, error)
}

TransImpl is the interface to be implemented by a customized transport module. A transport module is responsible for exchanging Raft messages, snapshots and other metadata between store instances.

func NewTCPTransport added in v0.2.0

func NewTCPTransport(logger *zap.Logger, addr string,
	requestHandler MessageHandler, chunkHandler SnapshotChunkHandler) TransImpl

NewTCPTransport creates and returns a new TCP transport module.

type Transport

type Transport struct {
	// contains filtered or unexported fields
}

Transport is the transport layer for delivering raft messages and snapshots.

func NewTransport added in v0.2.0

func NewTransport(logger *zap.Logger, addr string,
	storeID uint64, handler MessageHandler,
	unreachable UnreachableHandler, snapshotStatus SnapshotStatusHandler,
	dir snapshot.SnapshotDirFunc,
	resolver ContainerResolver, fs vfs.FS) *Transport

func (*Transport) Close added in v0.2.0

func (t *Transport) Close() error

Close closes the Transport object.

func (*Transport) Name added in v0.2.0

func (t *Transport) Name() string

Name returns the type name of the transport module

func (*Transport) Send

func (t *Transport) Send(m meta.RaftMessage) bool

func (*Transport) SendSnapshot added in v0.2.0

func (t *Transport) SendSnapshot(m meta.RaftMessage) bool

SendSnapshot asynchronously sends raft snapshot message to its target.

func (*Transport) SendingSnapshotCount

func (t *Transport) SendingSnapshotCount() uint64

func (*Transport) SetFilter added in v0.2.0

func (t *Transport) SetFilter(f func(meta.RaftMessage) bool)

func (*Transport) Start

func (t *Transport) Start() error

type UnreachableHandler added in v0.2.0

type UnreachableHandler func(uint64, uint64)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL