rpc

package
v1.26.8 Latest Latest
Warning

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

Go to latest
Published: Oct 30, 2024 License: BSD-3-Clause Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

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

Client is used for communication with remote nodes in a RAFT cluster It wraps the gRPC client to our gRPC server that is running on the raft port on each node

func NewClient

func NewClient(r rpcAddressResolver, rpcMessageMaxSize int, sentryEnabled bool, logger *logrus.Logger) *Client

NewClient returns a Client using the rpcAddressResolver to resolve raft nodes and configured with rpcMessageMaxSize

func (*Client) Apply

func (cl *Client) Apply(ctx context.Context, leaderRaftAddr string, req *cmd.ApplyRequest) (*cmd.ApplyResponse, error)

Apply will contact the node at leaderRaftAddr and send req to be applied in the RAFT store Returns the server response to the apply request Returns an error if an RPC connection to leaderRaftAddr can't be established Returns an error if the apply command fails

func (*Client) Close

func (cl *Client) Close()

Close the client and allocated resources

func (*Client) Join

func (cl *Client) Join(ctx context.Context, leaderRaftAddr string, req *cmd.JoinPeerRequest) (*cmd.JoinPeerResponse, error)

Join will contact the node at leaderRaftAddr and try to join this node to the cluster leaded by leaderRaftAddress using req Returns the server response to the join request Returns an error if an RPC connection to leaderRaftAddr can't be established Returns an error if joining the node fails

func (*Client) Notify

func (cl *Client) Notify(ctx context.Context, remoteAddr string, req *cmd.NotifyPeerRequest) (*cmd.NotifyPeerResponse, error)

Notify will contact the node at remoteAddr using the configured resolver and notify it of it's readiness to join a cluster using req Returns the server response to the notify request Returns an error if remoteAddr is not resolvable Returns an error if remoteAddr after resolve is not dial-able Returns an error if notifying the node fails. Note that Notify will not return an error if the node has notified itself already or if the remote node is already bootstrapped If the remote node is already bootstrapped/running a cluster, nodes should call Join instead Once a remote node has reached the sufficient amount of ready nodes (bootstrap_expect) it will initiate a cluster bootstrap process

func (*Client) Query

func (cl *Client) Query(ctx context.Context, leaderRaftAddr string, req *cmd.QueryRequest) (*cmd.QueryResponse, error)

Query will contact the node at leaderRaftAddr and send req to read data in the RAFT store Returns the server response to the query request Returns an error if an RPC connection to leaderRaftAddr can't be established Returns an error if the query command fails

func (*Client) Remove

func (cl *Client) Remove(ctx context.Context, leaderRaftAddr string, req *cmd.RemovePeerRequest) (*cmd.RemovePeerResponse, error)

Remove will contact the node at leaderRaftAddr and remove the client node from the RAFT cluster using req Returns the server response to the remove request Returns an error if an RPC connection to leaderRaftAddr can't be established

type Server

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

func NewServer

func NewServer(raftPeers raftPeers, raftFSM raftFSM, listenAddress string, log *logrus.Logger, grpcMessageMaxSize int, sentryEnabled bool) *Server

NewServer returns the Server implementing the RPC interface for RAFT peers management and execute/query commands. The server must subsequently be started with Open(). The server will be configure the gRPC service with grpcMessageMaxSize.

func (*Server) Apply

func (s *Server) Apply(ctx context.Context, req *cmd.ApplyRequest) (*cmd.ApplyResponse, error)

Apply will update the RAFT FSM representation to apply req. Returns the FSM version of that change. Returns an error and the current raft leader if applying fails.

func (*Server) Close

func (s *Server) Close()

Close closes the server and free any used ressources.

func (*Server) JoinPeer

JoinPeer will notify the RAFT cluster that a new peer is joining the cluster. Returns an error and the current raft leader if joining fails.

func (*Server) Leader

func (s *Server) Leader() string

Leader returns the current leader of the RAFT cluster.

func (*Server) NotifyPeer

NotifyPeer will notify the RAFT cluster that a peer has notified that it is ready to be joined. Returns an error if notifying fails.

func (*Server) Open

func (s *Server) Open() error

Open starts the server and registers it as the cluster service server. Returns asynchronously once the server has started. Returns an error if the configured listenAddress is invalid. Returns an error if the configured listenAddress is un-usable to listen on.

func (*Server) Query

func (s *Server) Query(ctx context.Context, req *cmd.QueryRequest) (*cmd.QueryResponse, error)

Query will read the RAFT FSM schema representation using req. Returns the result of the query. Returns an error if querying fails.

func (*Server) RemovePeer

RemovePeer will notify the RAFT cluster that a peer is removed from the cluster. Returns an error and the current raft leader if removal fails.

Jump to

Keyboard shortcuts

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