node

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: 15 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// StaticFileJoinMode is the default mode and is useful
	// running cluster locally. It looks for a cluster
	// configuration file containing the list of nodes
	// in the cluster. It expects JSON format
	StaticFileJoinMode = "static"

	// KubernetesJoinMode is enabled when this is run
	// in Kubernetes.
	KubernetesJoinMode = "k8s"
)

Variables

This section is empty.

Functions

func Validate

func Validate(config *Config) []error

Validate goes through the configuration and returns a list of validation errors found or an empty list otherwise

Types

type Config

type Config struct {
	NodeID  string `json:"node_id"`
	APIPort uint32 `json:"api_port"`
	RPCPort uint32 `json:"rpc_port"`

	WriteAheadLogEntryPath    string `json:"write_ahead_log_entry_path"`
	WriteAheadLogMetadataPath string `json:"write_ahead_log_metadata_path"`
	RaftStatePath             string `json:"raft_state_path"`

	JoinMode          string `json:"cluster_mode"`
	ClusterConfigPath string `json:"cluster_config_path"`

	ElectionTimeoutInMillis   int64 `json:"election_timeout_in_millis"`
	HeartbeatIntervalInMillis int64 `json:"heartbeat_interval_in_millis"`
	RPCTimeoutInMillis        int64 `json:"rpc_timeout_in_millis"`
	APITimeoutInMillis        int64 `json:"api_timeout_in_millis"`
	APIFwdTimeoutInMillis     int64 `json:"api_fwd_timeout_in_millis"`

	MaxConnectionRetryAttempts uint32 `json:"max_conn_retry_attempts"`

	SnapshotPath string `json:"snapshot_path"`
}

Config represents the configuration passed to the raft node like NodeID, API and RPC ports

type Context

type Context struct {
	// RealRaftProbufServer is an implementation of RaftProtocolServer
	// It is responsible for receiving all incoming protocol-related
	// messages from other nodes and taking appropriate action
	*server.RealRaftProtobufServer

	// RealRaftProtobufClient is responsible for handling all outgoing
	// communication from this node
	rpc.RaftProtobufClient

	// MembershipManager is responsible for managing cluster membership
	// and keeping track of information about other nodes in the cluster
	cluster.MembershipManager

	// EntryPersistence is responsible for persisting and retrieving
	// entries written to write-ahead log
	log.EntryPersistence

	// MetadataPersistence is responsible for persisting and retrieving
	// metadata of write-ahead log
	log.MetadataPersistence

	// WriteAheadLogManager is responsible for managing write-ahead log
	// entries, metadata and persisting them to disk
	log.WriteAheadLogManager

	// RaftStateManager is responsible for managing state related to
	// raft node safely in concurrent environments. It is also responsible
	// for recovery of state across restarts/crashes
	state.RaftStateManager

	// RaftStatePersistence is responsible for persisting and retrieving
	// raft-related state data.
	state.RaftStatePersistence

	// Voter is responsible for deciding whether to grant or reject vote
	*state.Voter

	// LeaderElectionAlgorithm is responsible for actually executing the
	// leader election algorithm. In case of raft it would be becoming
	// candidate, requesting votes and upgrading to leader if necessary
	election.LeaderElectionAlgorithm

	// LeaderElectionManager is responsible for running election timeout,
	// starting and declaring results of leader election
	election.LeaderElectionManager

	// LeaderHeartbeatController is responsible for controlling the sending
	// of heartbeat to remote nodes to establish authority as leader
	heartbeat.LeaderHeartbeatController

	// APIServer receives key-value store operation requests from the user.
	// If the current node is the leader then it is appended to the log and
	// it tries to replicate it to other nodes. If it is not a leader then
	// it forwards to the leader node if it is known. Otherwise error is
	// returned informing the same.
	*rest.APIServer

	// DataStore represents the API through which the distributed key-value
	// store is accessed. All the complexities of distributing are hidden
	// beneath this component.
	datastore.DataStore

	// EntryReplicationController is responsible for handling replication of
	// entries across the cluster when the node is elected as leader
	replication.EntryReplicationController

	// SnapshotPersistence is responsible for handling persistence of key-value
	// pairs as part of the snapshot
	log.SnapshotPersistence

	// SnapshotMetadataPersistence is responsible for handling persistence of
	// snapshot related metadata like snapshot index, epoch etc
	log.SnapshotMetadataPersistence

	// SnapshotHandler is responsible for handling snapshot
	log.SnapshotHandler

	// GarbageCollector is responsible for cleaning up entries
	// once their snapshot is taken and also cleaning up snapshot
	// with stale epoch
	log.GarbageCollector
}

Context represents the holder for all the components running as part of this Raft node.

func NewContext

func NewContext(config *Config) *Context

NewContext creates a new node context and returns it It wires up all the components before returning.

func (*Context) Destroy

func (ctx *Context) Destroy() error

Destroy destroys all components so that they become non-operational and the resources can be cleaned up This allows for graceful shutdown of each of the component in the node.

func (*Context) Start

func (ctx *Context) Start() error

Start starts various node context components. If the operation is not successful then it returns error

type ContextLifecycleError

type ContextLifecycleError struct {
	Errors []error
}

ContextLifecycleError represents the errors that occur during lifecycle events of the node context. This can be thought of as the consolidated error message derived from errors in various components

func (*ContextLifecycleError) Error

func (e *ContextLifecycleError) Error() string

Directories

Path Synopsis
k8s
rpc

Jump to

Keyboard shortcuts

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