Documentation ¶
Overview ¶
Package raft stores function used to interface in and out of raft.
Index ¶
- Constants
- type ActionType
- type Configuration
- func (c *Configuration) CalculateNewCommitIndex(lastCommitIndex, term uint64, rlog *raftlog.RaftLog) uint64
- func (c *Configuration) ChangeNodeLocation(nodeID, IP, Port string)
- func (c *Configuration) GetFutureConfigurationActive() bool
- func (c *Configuration) GetMatchIndex(nodeID string) uint64
- func (c *Configuration) GetNextIndex(nodeID string) uint64
- func (c *Configuration) GetNode(nodeID string) (Node, error)
- func (c *Configuration) GetNodesList() []Node
- func (c *Configuration) GetPeersList() []Node
- func (c *Configuration) GetSendingSnapshot(nodeID string) bool
- func (c *Configuration) GetTotalPossibleVotes() int
- func (c *Configuration) HasConfiguration() bool
- func (c *Configuration) HasMajority(votesRecieved []string) bool
- func (c *Configuration) InConfiguration(nodeID string) bool
- func (c *Configuration) MyConfigurationGood() bool
- func (c *Configuration) NewFutureConfiguration(nodes []Node, lastLogIndex uint64)
- func (c *Configuration) ResetNodeIndices(lastLogIndex uint64)
- func (c *Configuration) SetMatchIndex(nodeID string, x uint64)
- func (c *Configuration) SetNextIndex(nodeID string, x uint64)
- func (c *Configuration) SetSendingSnapshot(nodeID string, x bool)
- func (c *Configuration) UpdateCurrentConfiguration(nodes []Node, lastLogIndex uint64)
- func (c *Configuration) UpdateFromConfigurationFile(configurationFilePath string, lastLogIndex uint64) error
- type EntryAppliedInfo
- type NetworkServer
- func (s *NetworkServer) AppendEntries(ctx context.Context, req *pb.AppendEntriesRequest) (*pb.AppendEntriesResponse, error)
- func (s *NetworkServer) ChangeNodeLocation(UUID, IP, Port string)
- func (s *NetworkServer) ClientToLeader(ctx context.Context, req *pb.ClientToLeaderRequest) (*pb.ClientToLeaderResponse, error)
- func (s *NetworkServer) CreateSnapshot(lastIncludedIndex uint64) (err error)
- func (s *NetworkServer) Dial(node *Node, timeoutMiliseconds time.Duration) (*grpc.ClientConn, error)
- func (s *NetworkServer) InstallSnapshot(ctx context.Context, req *pb.SnapshotRequest) (*pb.SnapshotResponse, error)
- func (s *NetworkServer) RequestAddLogEntry(entry *pb.Entry) (*StateMachineResult, error)
- func (s *NetworkServer) RequestAddNodeToConfiguration(node Node) error
- func (s *NetworkServer) RequestChangeConfiguration(nodes []Node) error
- func (s *NetworkServer) RequestChmodCommand(filePath string, mode uint32) (returnCode returncodes.Code, returnError error)
- func (s *NetworkServer) RequestCreatCommand(filePath string, mode uint32) (returnCode returncodes.Code, returnError error)
- func (s *NetworkServer) RequestKeyStateUpdate(owner, holder *pb.Node, generation int64) error
- func (s *NetworkServer) RequestLinkCommand(oldPath, newPath string) (returnCode returncodes.Code, returnError error)
- func (s *NetworkServer) RequestMkdirCommand(filePath string, mode uint32) (returnCode returncodes.Code, returnError error)
- func (s *NetworkServer) RequestNewGeneration(newNode string) (int, []string, error)
- func (s *NetworkServer) RequestOwnerComplete(nodeID string, generation int64) error
- func (s *NetworkServer) RequestRenameCommand(oldPath, newPath string) (returnCode returncodes.Code, returnError error)
- func (s *NetworkServer) RequestRmdirCommand(filePath string) (returnCode returncodes.Code, returnError error)
- func (s *NetworkServer) RequestSymlinkCommand(oldPath, newPath string) (returnCode returncodes.Code, returnError error)
- func (s *NetworkServer) RequestTruncateCommand(filePath string, length int64) (returnCode returncodes.Code, returnError error)
- func (s *NetworkServer) RequestUnlinkCommand(filePath string) (returnCode returncodes.Code, returnError error)
- func (s *NetworkServer) RequestUtimesCommand(filePath string, atime, mtime *time.Time) (returnCode returncodes.Code, returnError error)
- func (s *NetworkServer) RequestVote(ctx context.Context, req *pb.RequestVoteRequest) (*pb.RequestVoteResponse, error)
- func (s *NetworkServer) RequestWriteCommand(filePath string, offset, length int64, data []byte) (returnCode returncodes.Code, bytesWrote int, returnError error)
- func (s *NetworkServer) RevertToSnapshot(snapshotPath string) error
- type Node
- type NodeType
- type SnapShotInfo
- type StartConfiguration
- type State
- func (s *State) ApplyLogEntries()
- func (s *State) DecrementSnapshotCounter()
- func (s *State) GetCommitIndex() uint64
- func (s *State) GetCurrentState() NodeType
- func (s *State) GetCurrentTerm() uint64
- func (s *State) GetLastApplied() uint64
- func (s *State) GetLeaderID() string
- func (s *State) GetPerformingSnapshot() bool
- func (s *State) GetSnapshotCounterValue() int
- func (s *State) GetSpecialNumber() uint64
- func (s *State) GetVotedFor() string
- func (s *State) GetWaitingForApplied() bool
- func (s *State) IncrementSnapshotCounter()
- func (s *State) SetCommitIndex(x uint64)
- func (s *State) SetCurrentState(x NodeType)
- func (s *State) SetCurrentTerm(x uint64)
- func (s *State) SetLastApplied(x uint64)
- func (s *State) SetLeaderID(x string)
- func (s *State) SetPerformingSnapshot(x bool)
- func (s *State) SetSpecialNumber(x uint64)
- func (s *State) SetVotedFor(x string)
- func (s *State) SetWaitingForApplied(x bool)
- type StateMachineResult
Constants ¶
const ( PersistentConfigurationFileName = "persistentConfigFile" OriginalConfigurationFileName = "originalConfigFile" )
Different constants
const ( ElectionTimeout time.Duration = 3000 * time.Millisecond Heartbeat = 1000 * time.Millisecond RequestVoteTimeout = 5500 * time.Millisecond HeartbeatTimeout = 3000 * time.Millisecond SendEntryTimeout = 7500 * time.Millisecond EntryAppliedTimeout = 20000 * time.Millisecond )
Raft constants
const ( PersistentStateFileName string = "persistentStateFile" LogDirectory string = "raft_logs" )
Constants used by State
const ( SnapshotDirectory = "snapshots" CurrentSnapshotDirectory = "currentsnapshot" SnapshotMetaFileName = "snapshotmeta" TarFileName = "snapshot.tar" )
String constants
const ( SnapshortInteval time.Duration = 1 * time.Minute SnapshotLogsize uint64 = 2 * 1024 * 1024 //2 MegaBytes SnapshotChunkSize int64 = 1024 MaxInstallSnapshotFails int = 10 )
Snapshot constants
const MaxAppendEntries uint64 = 100
MaxAppendEntries that can be send it one append request
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type ActionType ¶
type ActionType uint32
ActionType is the base type of the different action
const ( TypeWrite ActionType = iota TypeCreat TypeChmod TypeTruncate TypeUtimes TypeRename TypeLink TypeSymlink TypeUnlink TypeMkdir TypeRmdir )
List of the ActionTypes
type Configuration ¶
type Configuration struct {
// contains filtered or unexported fields
}
Configuration manages configuration information of a raft server
func (*Configuration) CalculateNewCommitIndex ¶
func (c *Configuration) CalculateNewCommitIndex( lastCommitIndex, term uint64, rlog *raftlog.RaftLog, ) uint64
CalculateNewCommitIndex calculates a new commit index in the manner described in the Raft paper
func (*Configuration) ChangeNodeLocation ¶
func (c *Configuration) ChangeNodeLocation(nodeID, IP, Port string)
ChangeNodeLocation changes the IP and Port of a given nodeID
func (*Configuration) GetFutureConfigurationActive ¶
func (c *Configuration) GetFutureConfigurationActive() bool
GetFutureConfigurationActive returns true if the future configuration is active
func (*Configuration) GetMatchIndex ¶
func (c *Configuration) GetMatchIndex(nodeID string) uint64
GetMatchIndex returns the index matched by the node.
func (*Configuration) GetNextIndex ¶
func (c *Configuration) GetNextIndex(nodeID string) uint64
GetNextIndex gets the index of the configuration that he node is in.
func (*Configuration) GetNode ¶
func (c *Configuration) GetNode(nodeID string) (Node, error)
GetNode based on the node ID. If the node is not found, an error is returned
func (*Configuration) GetNodesList ¶
func (c *Configuration) GetNodesList() []Node
GetNodesList returns a list of all the nodes in the cluster including the current nodes information.
func (*Configuration) GetPeersList ¶
func (c *Configuration) GetPeersList() []Node
GetPeersList returns a list of all the nodes that must be queried to decide on state changes or leader election.
func (*Configuration) GetSendingSnapshot ¶
func (c *Configuration) GetSendingSnapshot(nodeID string) bool
GetSendingSnapshot gets the snapshot of the node sending it TODO: Verify this
func (*Configuration) GetTotalPossibleVotes ¶
func (c *Configuration) GetTotalPossibleVotes() int
GetTotalPossibleVotes returns the number of nodes in the current configuration plus the number in the future configuration not also in the current configuration.
func (*Configuration) HasConfiguration ¶
func (c *Configuration) HasConfiguration() bool
HasConfiguration checks if the local node is in the configuration
func (*Configuration) HasMajority ¶
func (c *Configuration) HasMajority(votesRecieved []string) bool
HasMajority checks if the majority of votes have been received given a list of NodeIDs. A majority is needed in both the current and future configurations
func (*Configuration) InConfiguration ¶
func (c *Configuration) InConfiguration(nodeID string) bool
InConfiguration checks is the node ID in the current or future configuration
func (*Configuration) MyConfigurationGood ¶
func (c *Configuration) MyConfigurationGood() bool
MyConfigurationGood checks if the configuration contains the current node and has more than one member.
func (*Configuration) NewFutureConfiguration ¶
func (c *Configuration) NewFutureConfiguration(nodes []Node, lastLogIndex uint64)
NewFutureConfiguration creates a future configuration and sets the next index of those nodes to lastLogIndex + 1
func (*Configuration) ResetNodeIndices ¶
func (c *Configuration) ResetNodeIndices(lastLogIndex uint64)
ResetNodeIndices is used to reset the currentIndex and matchindex of each peer when elected as a leader.
func (*Configuration) SetMatchIndex ¶
func (c *Configuration) SetMatchIndex(nodeID string, x uint64)
SetMatchIndex sets the matched index for the node.
func (*Configuration) SetNextIndex ¶
func (c *Configuration) SetNextIndex(nodeID string, x uint64)
SetNextIndex sets the next index for the node.
func (*Configuration) SetSendingSnapshot ¶
func (c *Configuration) SetSendingSnapshot(nodeID string, x bool)
SetSendingSnapshot of the node
func (*Configuration) UpdateCurrentConfiguration ¶
func (c *Configuration) UpdateCurrentConfiguration(nodes []Node, lastLogIndex uint64)
UpdateCurrentConfiguration updates the current configuration given a set of nodes. If all the nodes are in the future configuration, the future configuration is changed to the current configuration.
func (*Configuration) UpdateFromConfigurationFile ¶
func (c *Configuration) UpdateFromConfigurationFile( configurationFilePath string, lastLogIndex uint64, ) error
UpdateFromConfigurationFile updates the configuration based on the provided file path and the last log index. If the configuration cannot be updated, an error is returned
type EntryAppliedInfo ¶
type EntryAppliedInfo struct { Index uint64 Result *StateMachineResult }
EntryAppliedInfo stores the information with the state machine results
type NetworkServer ¶
type NetworkServer struct { pb.UnimplementedRaftNetworkServiceServer State *State Wait sync.WaitGroup TLSEnabled bool Encrypted bool TLSSkipVerify bool QuitChannelClosed bool Quit chan bool ElectionTimeoutReset chan bool // contains filtered or unexported fields }
NetworkServer implements the raft protobuf server interface
func NewNetworkServer ¶
func NewNetworkServer( nodeDetails Node, pfsDirectory, raftInfoDirectory string, testConfiguration *StartConfiguration, TLSEnabled, TLSSkipVerify, encrypted bool, ) *NetworkServer
NewNetworkServer creates a new instance of the raft server
func StartRaft ¶
func StartRaft(lis *net.Listener, nodeDetails Node, pfsDirectory, raftInfoDirectory string, startConfiguration *StartConfiguration) (*NetworkServer, *grpc.Server)
StartRaft server given a listener, node information a directory to store information Only used for testing purposes
func (*NetworkServer) AppendEntries ¶
func (s *NetworkServer) AppendEntries(ctx context.Context, req *pb.AppendEntriesRequest) (*pb.AppendEntriesResponse, error)
AppendEntries implementation
func (*NetworkServer) ChangeNodeLocation ¶
func (s *NetworkServer) ChangeNodeLocation(UUID, IP, Port string)
ChangeNodeLocation changes the IP and Port of a given node
func (*NetworkServer) ClientToLeader ¶
func (s *NetworkServer) ClientToLeader(ctx context.Context, req *pb.ClientToLeaderRequest) (*pb.ClientToLeaderResponse, error)
ClientToLeaderRequest implementation
func (*NetworkServer) CreateSnapshot ¶
func (s *NetworkServer) CreateSnapshot(lastIncludedIndex uint64) (err error)
CreateSnapshot creates a new snapshot up to the last included index
func (*NetworkServer) Dial ¶
func (s *NetworkServer) Dial(node *Node, timeoutMiliseconds time.Duration) (*grpc.ClientConn, error)
Dial a node
func (*NetworkServer) InstallSnapshot ¶
func (s *NetworkServer) InstallSnapshot(ctx context.Context, req *pb.SnapshotRequest) (*pb.SnapshotResponse, error)
InstallSnapshot performs snapshot installation
func (*NetworkServer) RequestAddLogEntry ¶
func (s *NetworkServer) RequestAddLogEntry(entry *pb.Entry) (*StateMachineResult, error)
RequestAddLogEntry from a client. If the mode is not the leader, it must follow the request to the leader. Only returns once the request has been committed to the State machine
func (*NetworkServer) RequestAddNodeToConfiguration ¶
func (s *NetworkServer) RequestAddNodeToConfiguration(node Node) error
RequestAddNodeToConfiguration adds a node to configuration
func (*NetworkServer) RequestChangeConfiguration ¶
func (s *NetworkServer) RequestChangeConfiguration(nodes []Node) error
RequestChangeConfiguration performs a change in Configuration
func (*NetworkServer) RequestChmodCommand ¶
func (s *NetworkServer) RequestChmodCommand(filePath string, mode uint32) (returnCode returncodes.Code, returnError error)
RequestChmodCommand performs the Chmod command
func (*NetworkServer) RequestCreatCommand ¶
func (s *NetworkServer) RequestCreatCommand(filePath string, mode uint32) (returnCode returncodes.Code, returnError error)
RequestCreatCommand performs the Creat command
func (*NetworkServer) RequestKeyStateUpdate ¶
func (s *NetworkServer) RequestKeyStateUpdate(owner, holder *pb.Node, generation int64) error
RequestKeyStateUpdate requests and update
func (*NetworkServer) RequestLinkCommand ¶
func (s *NetworkServer) RequestLinkCommand(oldPath, newPath string) (returnCode returncodes.Code, returnError error)
RequestLinkCommand performs the link command
func (*NetworkServer) RequestMkdirCommand ¶
func (s *NetworkServer) RequestMkdirCommand(filePath string, mode uint32) (returnCode returncodes.Code, returnError error)
RequestMkdirCommand performs the mkdir command
func (*NetworkServer) RequestNewGeneration ¶
func (s *NetworkServer) RequestNewGeneration(newNode string) (int, []string, error)
RequestNewGeneration retrns a number, a list of peer nodes, and an error.
func (*NetworkServer) RequestOwnerComplete ¶
func (s *NetworkServer) RequestOwnerComplete(nodeID string, generation int64) error
RequestOwnerComplete of the node
func (*NetworkServer) RequestRenameCommand ¶
func (s *NetworkServer) RequestRenameCommand(oldPath, newPath string) (returnCode returncodes.Code, returnError error)
RequestRenameCommand performs the rename command
func (*NetworkServer) RequestRmdirCommand ¶
func (s *NetworkServer) RequestRmdirCommand(filePath string) (returnCode returncodes.Code, returnError error)
RequestRmdirCommand performs the rmdir command
func (*NetworkServer) RequestSymlinkCommand ¶
func (s *NetworkServer) RequestSymlinkCommand(oldPath, newPath string) (returnCode returncodes.Code, returnError error)
RequestSymlinkCommand performs the symlink command
func (*NetworkServer) RequestTruncateCommand ¶
func (s *NetworkServer) RequestTruncateCommand(filePath string, length int64) (returnCode returncodes.Code, returnError error)
RequestTruncateCommand performs the Truncate command
func (*NetworkServer) RequestUnlinkCommand ¶
func (s *NetworkServer) RequestUnlinkCommand(filePath string) (returnCode returncodes.Code, returnError error)
RequestUnlinkCommand performs the unlink command
func (*NetworkServer) RequestUtimesCommand ¶
func (s *NetworkServer) RequestUtimesCommand(filePath string, atime, mtime *time.Time) (returnCode returncodes.Code, returnError error)
RequestUtimesCommand performs the Utimes command
func (*NetworkServer) RequestVote ¶
func (s *NetworkServer) RequestVote(ctx context.Context, req *pb.RequestVoteRequest) (*pb.RequestVoteResponse, error)
RequestVote implementation
func (*NetworkServer) RequestWriteCommand ¶
func (s *NetworkServer) RequestWriteCommand(filePath string, offset, length int64, data []byte) (returnCode returncodes.Code, bytesWrote int, returnError error)
RequestWriteCommand performs a write
func (*NetworkServer) RevertToSnapshot ¶
func (s *NetworkServer) RevertToSnapshot(snapshotPath string) error
RevertToSnapshot revets the statemachine to the snapshot state and removes all log entries.
type SnapShotInfo ¶
type SnapShotInfo struct { LastIncludedIndex uint64 `json:"lastincludedindex"` LastIncludedTerm uint64 `json:"lastincludedterm"` SelfCreated bool `json:"selfcreated"` }
SnapShotInfo contains the information about the snapshot
type StartConfiguration ¶
type StartConfiguration struct {
Peers []Node
}
StartConfiguration is used to start a raft node with a specific congiuration for testing purposes or if the node is the first node to join a cluster
type State ¶
type State struct { NodeID string Log *raftlog.RaftLog Configuration *Configuration StartElection chan bool StartLeading chan bool StopLeading chan bool SendAppendEntries chan bool ApplyEntries chan bool LeaderElected chan bool SendSnapshot chan Node NewSnapshotCreated chan bool SnapshotCounterAtZero chan bool EntryApplied chan *EntryAppliedInfo ConfigurationApplied chan *pb.Configuration ApplyEntryLock sync.Mutex // contains filtered or unexported fields }
State information
func (*State) ApplyLogEntries ¶
func (s *State) ApplyLogEntries()
ApplyLogEntries applys all log entries that have been committed but not yet applied
func (*State) DecrementSnapshotCounter ¶
func (s *State) DecrementSnapshotCounter()
DecrementSnapshotCounter reduces the snapshot counter. If the snapshotCounter reaches 0, SnapshotCounterAtZero is notified
func (*State) GetCommitIndex ¶
GetCommitIndex returns the current commit index
func (*State) GetCurrentState ¶
GetCurrentState of the State
func (*State) GetCurrentTerm ¶
GetCurrentTerm returns the current term
func (*State) GetLastApplied ¶
GetLastApplied returns the last applied
func (*State) GetLeaderID ¶
GetLeaderID returns the ID of the leader
func (*State) GetPerformingSnapshot ¶
GetPerformingSnapshot from the State
func (*State) GetSnapshotCounterValue ¶
GetSnapshotCounterValue returns the current snapshot counter
func (*State) GetSpecialNumber ¶
GetSpecialNumber from the raft state
func (*State) GetWaitingForApplied ¶
GetWaitingForApplied sets the value
func (*State) IncrementSnapshotCounter ¶
func (s *State) IncrementSnapshotCounter()
IncrementSnapshotCounter updates the counter
func (*State) SetCommitIndex ¶
SetCommitIndex sets the current commit index to a given value
func (*State) SetCurrentState ¶
SetCurrentState of the State
func (*State) SetCurrentTerm ¶
SetCurrentTerm sets the current term
func (*State) SetLastApplied ¶
SetLastApplied sets the last applied and saves the state
func (*State) SetLeaderID ¶
SetLeaderID sets the ID of the leader
func (*State) SetPerformingSnapshot ¶
SetPerformingSnapshot of the State
func (*State) SetSpecialNumber ¶
SetSpecialNumber sets the number and saves the state
func (*State) SetWaitingForApplied ¶
SetWaitingForApplied set the value
type StateMachineResult ¶
type StateMachineResult struct { Code returncodes.Code Err error BytesWritten int KSMResult *ksmResult }
StateMachineResult containing the data of the state machine
func PerformKSMCommand ¶
func PerformKSMCommand(sateMachine *keyman.KeyStateMachine, keyCommand *pb.KeyStateCommand) *StateMachineResult
PerformKSMCommand updates the keys
func PerformLibPfsCommand ¶
func PerformLibPfsCommand(directory string, command *pb.StateMachineCommand) *StateMachineResult
PerformLibPfsCommand performs a libpfs command