raft

package
v0.0.0-...-1a6bc1e Latest Latest
Warning

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

Go to latest
Published: Jul 27, 2017 License: MPL-2.0 Imports: 24 Imported by: 0

Documentation

Overview

This file stores functions used to interface in or out of raft

Index

Constants

View Source
const (
	PersistentConfigurationFileName string = "persistentConfigFile"
	OriginalConfigurationFileName   string = "originalConfigFile"
)
View Source
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
)
View Source
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
)
View Source
const (
	FOLLOWER int = iota
	CANDIDATE
	LEADER
	INACTIVE
)
View Source
const (
	PersistentStateFileName string = "persistentStateFile"
	LogDirectory            string = "raft_logs"
)
View Source
const (
	SnapshotDirectory        string = "snapshots"
	CurrentSnapshotDirectory string = "currentsnapshot"
	SnapshotMetaFileName     string = "snapshotmeta"
	TarFileName              string = "snapshot.tar"
)
View Source
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
)
View Source
const (
	MAX_APPEND_ENTRIES uint64 = 100 //How many entries can be sent in one append entries request
)

Variables

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) GetNode

func (c *Configuration) GetNode(nodeID string) (Node, error)

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 Node

type Node struct {
	IP         string
	Port       string
	CommonName string
	NodeID     string
}

func (Node) String

func (n Node) String() string

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 (*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 (*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 (s *RaftState) GetCommitIndex() uint64

func (*RaftState) GetCurrentState

func (s *RaftState) GetCurrentState() int

func (*RaftState) GetCurrentTerm

func (s *RaftState) GetCurrentTerm() uint64

func (*RaftState) GetLastApplied

func (s *RaftState) GetLastApplied() uint64

func (*RaftState) GetLeaderId

func (s *RaftState) GetLeaderId() string

func (*RaftState) GetPerformingSnapshot

func (s *RaftState) GetPerformingSnapshot() bool

func (*RaftState) GetSnapshotCounterValue

func (s *RaftState) GetSnapshotCounterValue() int

func (*RaftState) GetSpecialNumber

func (s *RaftState) GetSpecialNumber() uint64

func (*RaftState) GetVotedFor

func (s *RaftState) GetVotedFor() string

func (*RaftState) GetWaitingForApplied

func (s *RaftState) GetWaitingForApplied() bool

func (*RaftState) IncrementSnapshotCounter

func (s *RaftState) IncrementSnapshotCounter()

func (*RaftState) SetCommitIndex

func (s *RaftState) SetCommitIndex(x uint64)

func (*RaftState) SetCurrentState

func (s *RaftState) SetCurrentState(x int)

func (*RaftState) SetCurrentTerm

func (s *RaftState) SetCurrentTerm(x uint64)

func (*RaftState) SetLastApplied

func (s *RaftState) SetLastApplied(x uint64)

func (*RaftState) SetLeaderId

func (s *RaftState) SetLeaderId(x string)

func (*RaftState) SetPerformingSnapshot

func (s *RaftState) SetPerformingSnapshot(x bool)

func (*RaftState) SetSpecialNumber

func (s *RaftState) SetSpecialNumber(x uint64)

func (*RaftState) SetVotedFor

func (s *RaftState) SetVotedFor(x string)

func (*RaftState) SetWaitingForApplied

func (s *RaftState) SetWaitingForApplied(x bool)

type SnapShotInfo

type SnapShotInfo struct {
	LastIncludedIndex uint64 `json:"lastincludedindex"`
	LastIncludedTerm  uint64 `json:"lastincludedterm"`
	SelfCreated       bool   `json:"selfcreated"`
}

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

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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