rpc

package
v0.0.0-...-f2131c8 Latest Latest
Warning

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

Go to latest
Published: Sep 17, 2019 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ConvertEntryToProtobuf

func ConvertEntryToProtobuf(entry log.Entry) *raftpb.OpEntry

ConvertEntryToProtobuf converts the entry from in-memory format to the format as defined in protocol-buffer

func ConvertProtobufToEntry

func ConvertProtobufToEntry(entry *raftpb.OpEntry) log.Entry

ConvertProtobufToEntry converts from protobuf wire format to the in-memory format.

Types

type RaftProtobufClient

type RaftProtobufClient interface {
	// RequestVote requests the vote from the node specified by nodeID for the
	// term "curTermID". It also sends some log metadata to the remote node to
	// help the other node decide on voting
	RequestVote(curTermID uint64, nodeID string, lastLogEntryID log.EntryID) (voteGranted bool, votingErr error)

	// Heartbeat sends heartbeat to the remote node. It should return true if
	// the remote node accepts authority of this not or false otherwise.
	Heartbeat(curTermID uint64, nodeID string, maxCommittedIndex uint64) (acceptedAsLeader bool, heartbeatErr error)

	// AppendEntry tries to append the given entry to the log of the remote node.
	// If replication is successful, then true is returned or false otherwise.
	AppendEntry(curTermID uint64, nodeID string, prevEntryID log.EntryID, index uint64, entry log.Entry) (appended bool, appendErr error)

	// InstallSnapshot installs the snapshot to the remote node and the remote node
	// replies with its current index ID. If there is any error then it is returned
	InstallSnapshot(curTermID uint64, nodeID string) (committedIndex uint64, err error)

	// ComponentLifecycle indicates that this is a component and
	// has lifecycle events - start and destroy
	common.ComponentLifecycle
}

RaftProtobufClient represents the component which is responsible for handling all outgoing protocol related communications

type RealRaftProtobufClient

type RealRaftProtobufClient struct {

	// MembershipManager is used to look up the address of the
	// remote node specified. It must be provided.
	cluster.MembershipManager

	// CurrentNodeID is the identifier of the current node
	// in the Raft cluster
	CurrentNodeID string

	// MaxConnectionRetryAttempts specify the maximum number of
	// times the client tries to connect to the remote node before
	// giving up.
	MaxConnectionRetryAttempts uint32

	// RPCTimeoutInMillis specifies RPC-timeout in milliseconds
	RPCTimeoutInMillis uint64

	// SnapshotHandler is required for handling snapshot transfers
	log.SnapshotHandler
	// contains filtered or unexported fields
}

RealRaftProtobufClient is responsible for handling all protocol related outgoing messages.

func NewRealRaftProtobufClient

func NewRealRaftProtobufClient(
	membershipManager cluster.MembershipManager,
	currentNodeID string,
	maxConnRetryAttempts uint32,
	rpcTimeoutInMillis uint64,
	snapshotHandler log.SnapshotHandler,
) *RealRaftProtobufClient

NewRealRaftProtobufClient creates a new instance of real raft protocol client. This component is responsible for handling all outgoing communication.

func (*RealRaftProtobufClient) AppendEntry

func (rpcc *RealRaftProtobufClient) AppendEntry(curTermID uint64, nodeID string, prevEntryID log.EntryID, index uint64, entry log.Entry) (bool, error)

AppendEntry tries to append the given entry to the log. The function returns true if the given entry is successfully appended to the log or false otherwise. If there is an error during operation then it is returned.

func (*RealRaftProtobufClient) Destroy

func (rpcc *RealRaftProtobufClient) Destroy() error

Destroy makes the component non-operational. No operation can be invoked on this component after it is destroyed.

func (*RealRaftProtobufClient) Heartbeat

func (rpcc *RealRaftProtobufClient) Heartbeat(curTermID uint64, nodeID string, maxCommittedIndex uint64) (bool, error)

Heartbeat sends heartbeat to the given node in the cluster. The function returns true if the remote node accepts the authority of this node in the cluster (as leader), false otherwise. If there is an error during this operation, it is returned

func (*RealRaftProtobufClient) InstallSnapshot

func (rpcc *RealRaftProtobufClient) InstallSnapshot(curTermID uint64, nodeID string) (uint64, error)

InstallSnapshot is a streaming RPC call which transfers the snapshot from this node to the destination. Once the transfer is complete the remote node returns the committed index if successful or an error if there was any.

func (*RealRaftProtobufClient) RequestVote

func (rpcc *RealRaftProtobufClient) RequestVote(curTermID uint64, nodeID string, lastLogEntryID log.EntryID) (bool, error)

RequestVote requests the remote node. The function returns true if the remote node grants vote, false otherwise. If there is an error then it is returned.

func (*RealRaftProtobufClient) Start

func (rpcc *RealRaftProtobufClient) Start() error

Start starts the operation of the component unless it is already destroyed. This operation is idempotent. If there is any error during start-up this fails and returns error

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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