Documentation ¶
Overview ¶
This file stores functions used to interface in or out of raft
Index ¶
- Constants
- Variables
- type Configuration
- func (c *Configuration) CalculateNewCommitIndex(lastCommitIndex, term uint64, log *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 Node
- type RaftNetworkServer
- func (s *RaftNetworkServer) AppendEntries(ctx context.Context, req *pb.AppendEntriesRequest) (*pb.AppendEntriesResponse, error)
- func (s *RaftNetworkServer) ChangeNodeLocation(UUID, IP, Port string)
- func (s *RaftNetworkServer) ClientToLeaderRequest(ctx context.Context, req *pb.EntryRequest) (*pb.EmptyMessage, error)
- func (s *RaftNetworkServer) CreateSnapshot(lastIncludedIndex uint64) (err error)
- func (s *RaftNetworkServer) Dial(node *Node, timeoutMiliseconds time.Duration) (*grpc.ClientConn, error)
- func (s *RaftNetworkServer) InstallSnapshot(ctx context.Context, req *pb.SnapshotRequest) (*pb.SnapshotResponse, error)
- func (s *RaftNetworkServer) RequestAddLogEntry(entry *pb.Entry) (*StateMachineResult, error)
- func (s *RaftNetworkServer) RequestAddNodeToConfiguration(node Node) error
- func (s *RaftNetworkServer) RequestChangeConfiguration(nodes []Node) error
- func (s *RaftNetworkServer) RequestChmodCommand(filePath string, mode uint32) (returnCode returncodes.Code, returnError error)
- func (s *RaftNetworkServer) RequestCreatCommand(filePath string, mode uint32) (returnCode returncodes.Code, returnError error)
- func (s *RaftNetworkServer) RequestKeyStateUpdate(owner, holder *pb.Node, generation int64) error
- func (s *RaftNetworkServer) RequestLinkCommand(oldPath, newPath string) (returnCode returncodes.Code, returnError error)
- func (s *RaftNetworkServer) RequestMkdirCommand(filePath string, mode uint32) (returnCode returncodes.Code, returnError error)
- func (s *RaftNetworkServer) RequestNewGeneration(newNode string) (int, []string, error)
- func (s *RaftNetworkServer) RequestOwnerComplete(nodeId string, generation int64) error
- func (s *RaftNetworkServer) RequestRenameCommand(oldPath, newPath string) (returnCode returncodes.Code, returnError error)
- func (s *RaftNetworkServer) RequestRmdirCommand(filePath string) (returnCode returncodes.Code, returnError error)
- func (s *RaftNetworkServer) RequestSymlinkCommand(oldPath, newPath string) (returnCode returncodes.Code, returnError error)
- func (s *RaftNetworkServer) RequestTruncateCommand(filePath string, length int64) (returnCode returncodes.Code, returnError error)
- func (s *RaftNetworkServer) RequestUnlinkCommand(filePath string) (returnCode returncodes.Code, returnError error)
- func (s *RaftNetworkServer) RequestUtimesCommand(filePath string, atime, mtime *time.Time) (returnCode returncodes.Code, returnError error)
- func (s *RaftNetworkServer) RequestVote(ctx context.Context, req *pb.RequestVoteRequest) (*pb.RequestVoteResponse, error)
- func (s *RaftNetworkServer) RequestWriteCommand(filePath string, offset, length int64, data []byte) (returnCode returncodes.Code, returnError error, bytesWrote int)
- func (s *RaftNetworkServer) RevertToSnapshot(snapshotPath string) error
- type RaftState
- func (s *RaftState) ApplyLogEntries()
- func (s *RaftState) DecrementSnapshotCounter()
- func (s *RaftState) GetCommitIndex() uint64
- func (s *RaftState) GetCurrentState() int
- func (s *RaftState) GetCurrentTerm() uint64
- func (s *RaftState) GetLastApplied() uint64
- func (s *RaftState) GetLeaderId() string
- func (s *RaftState) GetPerformingSnapshot() bool
- func (s *RaftState) GetSnapshotCounterValue() int
- func (s *RaftState) GetSpecialNumber() uint64
- func (s *RaftState) GetVotedFor() string
- func (s *RaftState) GetWaitingForApplied() bool
- func (s *RaftState) IncrementSnapshotCounter()
- func (s *RaftState) SetCommitIndex(x uint64)
- func (s *RaftState) SetCurrentState(x int)
- func (s *RaftState) SetCurrentTerm(x uint64)
- func (s *RaftState) SetLastApplied(x uint64)
- func (s *RaftState) SetLeaderId(x string)
- func (s *RaftState) SetPerformingSnapshot(x bool)
- func (s *RaftState) SetSpecialNumber(x uint64)
- func (s *RaftState) SetVotedFor(x string)
- func (s *RaftState) SetWaitingForApplied(x bool)
- type SnapShotInfo
- type StartConfiguration
- type StateMachineResult
Constants ¶
const ( PersistentConfigurationFileName string = "persistentConfigFile" OriginalConfigurationFileName string = "originalConfigFile" )
const ( TYPE_WRITE uint32 = iota TYPE_CREAT TYPE_CHMOD TYPE_TRUNCATE TYPE_UTIMES TYPE_RENAME TYPE_LINK TYPE_SYMLINK TYPE_UNLINK TYPE_MKDIR TYPE_RMDIR )
const ( ELECTION_TIMEOUT time.Duration = 3000 * time.Millisecond HEARTBEAT time.Duration = 1000 * time.Millisecond REQUEST_VOTE_TIMEOUT time.Duration = 5500 * time.Millisecond HEARTBEAT_TIMEOUT time.Duration = 3000 * time.Millisecond SEND_ENTRY_TIMEOUT time.Duration = 7500 * time.Millisecond ENTRY_APPLIED_TIMEOUT time.Duration = 20000 * time.Millisecond LEADER_REQUEST_TIMEOUT time.Duration = 10000 * time.Millisecond )
const ( FOLLOWER int = iota CANDIDATE LEADER INACTIVE )
const ( PersistentStateFileName string = "persistentStateFile" LogDirectory string = "raft_logs" )
const ( SnapshotDirectory string = "snapshots" CurrentSnapshotDirectory string = "currentsnapshot" SnapshotMetaFileName string = "snapshotmeta" TarFileName string = "snapshot.tar" )
const ( SNAPSHOT_INTERVAL time.Duration = 1 * time.Minute SNAPSHOT_LOGSIZE uint64 = 2 * 1024 * 1024 //2 MegaBytes SNAPSHOT_CHUNK_SIZE int64 = 1024 MAX_INSTALLSNAPSHOT_FAILS int = 10 )
const (
MAX_APPEND_ENTRIES uint64 = 100 //How many entries can be sent in one append entries request
)
Variables ¶
var (
Log *logger.ParanoidLogger
)
Functions ¶
This section is empty.
Types ¶
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, log *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
func (*Configuration) GetMatchIndex ¶
func (c *Configuration) GetMatchIndex(nodeID string) uint64
func (*Configuration) GetNextIndex ¶
func (c *Configuration) GetNextIndex(nodeID string) uint64
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
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
func (*Configuration) HasMajority ¶
func (c *Configuration) HasMajority(votesRecieved []string) bool
Check has a 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
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)
func (*Configuration) SetNextIndex ¶
func (c *Configuration) SetNextIndex(nodeID string, x uint64)
func (*Configuration) SetSendingSnapshot ¶
func (c *Configuration) SetSendingSnapshot(nodeID string, x bool)
func (*Configuration) UpdateCurrentConfiguration ¶
func (c *Configuration) UpdateCurrentConfiguration(nodes []Node, lastLogIndex uint64)
UpdateCurrentConfiguration updates the current configuraiton 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
type EntryAppliedInfo ¶
type EntryAppliedInfo struct { Index uint64 Result *StateMachineResult }
type RaftNetworkServer ¶
type RaftNetworkServer struct { State *RaftState Wait sync.WaitGroup TLSEnabled bool Encrypted bool TLSSkipVerify bool QuitChannelClosed bool Quit chan bool ElectionTimeoutReset chan bool // contains filtered or unexported fields }
func NewRaftNetworkServer ¶
func NewRaftNetworkServer(nodeDetails Node, pfsDirectory, raftInfoDirectory string, testConfiguration *StartConfiguration, TLSEnabled, TLSSkipVerify, encrypted bool) *RaftNetworkServer
func StartRaft ¶
func StartRaft(lis *net.Listener, nodeDetails Node, pfsDirectory, raftInfoDirectory string, startConfiguration *StartConfiguration) (*RaftNetworkServer, *grpc.Server)
Starts a raft server given a listener, node information a directory to store information Only used for testing purposes
func (*RaftNetworkServer) AppendEntries ¶
func (s *RaftNetworkServer) AppendEntries(ctx context.Context, req *pb.AppendEntriesRequest) (*pb.AppendEntriesResponse, error)
func (*RaftNetworkServer) ChangeNodeLocation ¶
func (s *RaftNetworkServer) ChangeNodeLocation(UUID, IP, Port string)
ChangeNodeLocation changes the IP and Port of a given node
func (*RaftNetworkServer) ClientToLeaderRequest ¶
func (s *RaftNetworkServer) ClientToLeaderRequest(ctx context.Context, req *pb.EntryRequest) (*pb.EmptyMessage, error)
func (*RaftNetworkServer) CreateSnapshot ¶
func (s *RaftNetworkServer) CreateSnapshot(lastIncludedIndex uint64) (err error)
func (*RaftNetworkServer) Dial ¶
func (s *RaftNetworkServer) Dial(node *Node, timeoutMiliseconds time.Duration) (*grpc.ClientConn, error)
func (*RaftNetworkServer) InstallSnapshot ¶
func (s *RaftNetworkServer) InstallSnapshot(ctx context.Context, req *pb.SnapshotRequest) (*pb.SnapshotResponse, error)
func (*RaftNetworkServer) RequestAddLogEntry ¶
func (s *RaftNetworkServer) RequestAddLogEntry(entry *pb.Entry) (*StateMachineResult, error)
A request to add a Log entry from a client. If the node is not the leader, it must forward the request to the leader. Only returns once the request has been commited to the State machine
func (*RaftNetworkServer) RequestAddNodeToConfiguration ¶
func (s *RaftNetworkServer) RequestAddNodeToConfiguration(node Node) error
func (*RaftNetworkServer) RequestChangeConfiguration ¶
func (s *RaftNetworkServer) RequestChangeConfiguration(nodes []Node) error
func (*RaftNetworkServer) RequestChmodCommand ¶
func (s *RaftNetworkServer) RequestChmodCommand(filePath string, mode uint32) (returnCode returncodes.Code, returnError error)
func (*RaftNetworkServer) RequestCreatCommand ¶
func (s *RaftNetworkServer) RequestCreatCommand(filePath string, mode uint32) (returnCode returncodes.Code, returnError error)
func (*RaftNetworkServer) RequestKeyStateUpdate ¶
func (s *RaftNetworkServer) RequestKeyStateUpdate(owner, holder *pb.Node, generation int64) error
func (*RaftNetworkServer) RequestLinkCommand ¶
func (s *RaftNetworkServer) RequestLinkCommand(oldPath, newPath string) (returnCode returncodes.Code, returnError error)
func (*RaftNetworkServer) RequestMkdirCommand ¶
func (s *RaftNetworkServer) RequestMkdirCommand(filePath string, mode uint32) (returnCode returncodes.Code, returnError error)
func (*RaftNetworkServer) RequestNewGeneration ¶
func (s *RaftNetworkServer) RequestNewGeneration(newNode string) (int, []string, error)
Returns the new generation number, a list of peer nodes, and an error.
func (*RaftNetworkServer) RequestOwnerComplete ¶
func (s *RaftNetworkServer) RequestOwnerComplete(nodeId string, generation int64) error
func (*RaftNetworkServer) RequestRenameCommand ¶
func (s *RaftNetworkServer) RequestRenameCommand(oldPath, newPath string) (returnCode returncodes.Code, returnError error)
func (*RaftNetworkServer) RequestRmdirCommand ¶
func (s *RaftNetworkServer) RequestRmdirCommand(filePath string) (returnCode returncodes.Code, returnError error)
func (*RaftNetworkServer) RequestSymlinkCommand ¶
func (s *RaftNetworkServer) RequestSymlinkCommand(oldPath, newPath string) (returnCode returncodes.Code, returnError error)
func (*RaftNetworkServer) RequestTruncateCommand ¶
func (s *RaftNetworkServer) RequestTruncateCommand(filePath string, length int64) (returnCode returncodes.Code, returnError error)
func (*RaftNetworkServer) RequestUnlinkCommand ¶
func (s *RaftNetworkServer) RequestUnlinkCommand(filePath string) (returnCode returncodes.Code, returnError error)
func (*RaftNetworkServer) RequestUtimesCommand ¶
func (s *RaftNetworkServer) RequestUtimesCommand(filePath string, atime, mtime *time.Time) (returnCode returncodes.Code, returnError error)
func (*RaftNetworkServer) RequestVote ¶
func (s *RaftNetworkServer) RequestVote(ctx context.Context, req *pb.RequestVoteRequest) (*pb.RequestVoteResponse, error)
func (*RaftNetworkServer) RequestWriteCommand ¶
func (s *RaftNetworkServer) RequestWriteCommand(filePath string, offset, length int64, data []byte) (returnCode returncodes.Code, returnError error, bytesWrote int)
func (*RaftNetworkServer) RevertToSnapshot ¶
func (s *RaftNetworkServer) RevertToSnapshot(snapshotPath string) error
Revert the statemachine state to the snapshot state. Remove all log entries
type RaftState ¶
type RaftState 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 }
func (*RaftState) ApplyLogEntries ¶
func (s *RaftState) ApplyLogEntries()
ApplyLogEntries applys all log entries that have been commited but not yet applied
func (*RaftState) DecrementSnapshotCounter ¶
func (s *RaftState) DecrementSnapshotCounter()
func (*RaftState) GetCommitIndex ¶
func (*RaftState) GetCurrentState ¶
func (*RaftState) GetCurrentTerm ¶
func (*RaftState) GetLastApplied ¶
func (*RaftState) GetLeaderId ¶
func (*RaftState) GetPerformingSnapshot ¶
func (*RaftState) GetSnapshotCounterValue ¶
func (*RaftState) GetSpecialNumber ¶
func (*RaftState) GetVotedFor ¶
func (*RaftState) GetWaitingForApplied ¶
func (*RaftState) IncrementSnapshotCounter ¶
func (s *RaftState) IncrementSnapshotCounter()
func (*RaftState) SetCommitIndex ¶
func (*RaftState) SetCurrentState ¶
func (*RaftState) SetCurrentTerm ¶
func (*RaftState) SetLastApplied ¶
func (*RaftState) SetLeaderId ¶
func (*RaftState) SetPerformingSnapshot ¶
func (*RaftState) SetSpecialNumber ¶
func (*RaftState) SetVotedFor ¶
func (*RaftState) SetWaitingForApplied ¶
type SnapShotInfo ¶
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 StateMachineResult ¶
type StateMachineResult struct { Code returncodes.Code Err error BytesWritten int KSMResult *ksmResult }
func PerformKSMCommand ¶
func PerformKSMCommand(sateMachine *keyman.KeyStateMachine, keyCommand *pb.KeyStateCommand) *StateMachineResult
func PerformLibPfsCommand ¶
func PerformLibPfsCommand(directory string, command *pb.StateMachineCommand) *StateMachineResult