Documentation ¶
Index ¶
- Constants
- Variables
- func GetSnapshotDirName(index uint64) string
- func GetSnapshotFilename(index uint64) string
- func StartTicker(td time.Duration, tf TickerFunc, stopc <-chan struct{})
- type CampaignInfo
- type Context
- func (sc *Context) CheckLogDBType(did uint64, dbType string) error
- func (sc *Context) CheckNodeHostDir(did uint64, addr string, binVer uint32, dbType string) error
- func (sc *Context) CreateNodeHostDir(did uint64) ([]string, []string, error)
- func (sc *Context) CreateSnapshotDir(did uint64, clusterID uint64, nodeID uint64) error
- func (sc *Context) GetLogDBDirs(did uint64) ([]string, []string)
- func (sc *Context) GetRandomSource() random.Source
- func (sc *Context) GetSnapshotDir(did uint64, clusterID uint64, nodeID uint64) string
- func (sc *Context) LockNodeHostDir() error
- func (sc *Context) RemoveSnapshotDir(did uint64, clusterID uint64, nodeID uint64) error
- func (sc *Context) Stop()
- type DoubleFixedPartitioner
- type FixedPartitioner
- type GetSnapshotDirFunc
- type IPartitioner
- type IRaftEventListener
- type LeaderInfo
- type MessageQueue
- type Mode
- type ProposalInfo
- type RateLimiter
- func (r *RateLimiter) Decrease(sz uint64)
- func (r *RateLimiter) Enabled() bool
- func (r *RateLimiter) Get() uint64
- func (r *RateLimiter) GetHeartbeatTick() uint64
- func (r *RateLimiter) HeartbeatTick()
- func (r *RateLimiter) Increase(sz uint64)
- func (r *RateLimiter) RateLimited() bool
- func (r *RateLimiter) ResetFollowerState()
- func (r *RateLimiter) Set(sz uint64)
- func (r *RateLimiter) SetFollowerState(nodeID uint64, sz uint64)
- type ReadIndexInfo
- type ReplicationInfo
- type SSEnv
- func (se *SSEnv) CreateTempDir() error
- func (se *SSEnv) FinalizeSnapshot(msg fileutil.Marshaler) error
- func (se *SSEnv) GetFilename() string
- func (se *SSEnv) GetFilepath() string
- func (se *SSEnv) GetFinalDir() string
- func (se *SSEnv) GetRootDir() string
- func (se *SSEnv) GetShrinkedFilepath() string
- func (se *SSEnv) GetTempDir() string
- func (se *SSEnv) GetTempFilepath() string
- func (se *SSEnv) HasFlagFile() bool
- func (se *SSEnv) MustRemoveTempDir()
- func (se *SSEnv) RemoveFinalDir() error
- func (se *SSEnv) RemoveFlagFile() error
- func (se *SSEnv) RemoveTempDir() error
- func (se *SSEnv) SaveSSMetadata(msg fileutil.Marshaler) error
- type SnapshotInfo
- type SystemEvent
- type SystemEventType
- type TickerFunc
Constants ¶
const ( // NoLeader is the flag used to indcate that there is no leader or the leader // is unknown. NoLeader uint64 = 0 )
Variables ¶
var ( // ErrHardSettingChanged indicates that one or more of the hard settings // changed. ErrHardSettingChanged = errors.New("hard setting changed") // ErrDirMarkedAsDeleted is the error used to indicate that the directory has // been marked as deleted and can not be used again. ErrDirMarkedAsDeleted = errors.New("trying to use a dir marked as deleted") // ErrHostnameChanged is the error used to indicate that the hostname changed. ErrHostnameChanged = errors.New("hostname changed") // ErrDeploymentIDChanged is the error used to indicate that the deployment // ID changed. ErrDeploymentIDChanged = errors.New("Deployment ID changed") // ErrLogDBType is the error used to indicate that the LogDB type changed. ErrLogDBType = errors.New("logdb type changed") // ErrNotOwner indicates that the data directory belong to another NodeHost // instance. ErrNotOwner = errors.New("not the owner of the data directory") // ErrLockDirectory indicates that obtaining exclusive lock to the data // directory failed. ErrLockDirectory = errors.New("failed to lock data directory") // ErrHardSettingsChanged indicates that hard settings changed. ErrHardSettingsChanged = errors.New("settings in internal/settings/hard.go changed") // ErrIncompatibleData indicates that the configured data directory contains // incompatible data. ErrIncompatibleData = errors.New("Incompatible LogDB data format") // ErrLogDBBrokenChange indicates that you NodeHost failed to be created as // your code is hit by the LogDB broken change introduced in v3.0. Set your // NodeHostConfig.LogDBFactory to rocksdb.OpenBatchedLogDB to continue. ErrLogDBBrokenChange = errors.New("Using new LogDB implementation on existing Raft Log") )
var ( // ErrSnapshotOutOfDate is the error to indicate that snapshot is out of date. ErrSnapshotOutOfDate = errors.New("snapshot out of date") // SnapshotMetadataFilename is the filename of a snapshot's metadata file. SnapshotMetadataFilename = "snapshot.metadata" // SnapshotFileSuffix is the filename suffix of a snapshot file. SnapshotFileSuffix = "gbsnap" // SnapshotDirNameRe is the regex of snapshot names. SnapshotDirNameRe = regexp.MustCompile(`^snapshot-[0-9A-F]+$`) // GenSnapshotDirNameRe is the regex of temp snapshot directory name used when // generating snapshots. GenSnapshotDirNameRe = regexp.MustCompile(`^snapshot-[0-9A-F]+-[0-9A-F]+\.generating$`) // RecvSnapshotDirNameRe is the regex of temp snapshot directory name used when // receiving snapshots from remote NodeHosts. RecvSnapshotDirNameRe = regexp.MustCompile(`^snapshot-[0-9A-F]+-[0-9A-F]+\.receiving$`) )
Functions ¶
func GetSnapshotDirName ¶
GetSnapshotDirName returns the snapshot dir name for the snapshot captured at the specified index.
func GetSnapshotFilename ¶
GetSnapshotFilename returns the filename of the snapshot file.
func StartTicker ¶
func StartTicker(td time.Duration, tf TickerFunc, stopc <-chan struct{})
StartTicker runs a ticker at the specified interval, the provided TickerFunc will be called after each tick. The ticker will be stopped when the TickerFunc return a true value or when any of the two specified stop channels is signalled.
Types ¶
type CampaignInfo ¶
CampaignInfo contains campaign info.
type Context ¶
type Context struct {
// contains filtered or unexported fields
}
Context is the server context for NodeHost.
func NewContext ¶
NewContext creates and returns a new server Context object.
func (*Context) CheckLogDBType ¶
CheckLogDBType checks whether LogDB type is compatible.
func (*Context) CheckNodeHostDir ¶
CheckNodeHostDir checks whether NodeHost dir is owned by the current nodehost.
func (*Context) CreateNodeHostDir ¶
CreateNodeHostDir creates the top level dirs used by nodehost.
func (*Context) CreateSnapshotDir ¶
CreateSnapshotDir creates the snapshot directory for the specified node.
func (*Context) GetLogDBDirs ¶
GetLogDBDirs returns the directory names for LogDB
func (*Context) GetRandomSource ¶
GetRandomSource returns the random source associated with the Nodehost.
func (*Context) GetSnapshotDir ¶
GetSnapshotDir returns the snapshot directory name.
func (*Context) LockNodeHostDir ¶
LockNodeHostDir tries to lock the NodeHost data directories.
func (*Context) RemoveSnapshotDir ¶
RemoveSnapshotDir marks the node snapshot directory as removed and have all existing snapshots deleted.
type DoubleFixedPartitioner ¶
type DoubleFixedPartitioner struct {
// contains filtered or unexported fields
}
DoubleFixedPartitioner is the IPartitioner with two fixed capacity and naive partitioning strategy.
func NewDoubleFixedPartitioner ¶
func NewDoubleFixedPartitioner(capacity uint64, workerCount uint64) *DoubleFixedPartitioner
NewDoubleFixedPartitioner creates a new DoubleFixedPartitioner instance.
func (*DoubleFixedPartitioner) GetPartitionID ¶
func (p *DoubleFixedPartitioner) GetPartitionID(clusterID uint64) uint64
GetPartitionID returns the partition ID for the specified raft cluster.
type FixedPartitioner ¶
type FixedPartitioner struct {
// contains filtered or unexported fields
}
FixedPartitioner is the IPartitioner with fixed capacity and naive partitioning strategy.
func NewFixedPartitioner ¶
func NewFixedPartitioner(capacity uint64) *FixedPartitioner
NewFixedPartitioner creates a new FixedPartitioner instance.
func (*FixedPartitioner) GetPartitionID ¶
func (p *FixedPartitioner) GetPartitionID(clusterID uint64) uint64
GetPartitionID returns the partition ID for the specified raft cluster.
type GetSnapshotDirFunc ¶
GetSnapshotDirFunc is the function type that returns the snapshot dir for the specified raft node.
type IPartitioner ¶
IPartitioner is the interface for partitioning clusters.
type IRaftEventListener ¶
type IRaftEventListener interface { LeaderUpdated(info LeaderInfo) CampaignLaunched(info CampaignInfo) CampaignSkipped(info CampaignInfo) SnapshotRejected(info SnapshotInfo) ReplicationRejected(info ReplicationInfo) ProposalDropped(info ProposalInfo) ReadIndexDropped(info ReadIndexInfo) }
IRaftEventListener is the event listener used by the Raft implementation.
type LeaderInfo ¶
LeaderInfo contains leader info.
type MessageQueue ¶
type MessageQueue struct {
// contains filtered or unexported fields
}
MessageQueue is the queue used to hold Raft messages.
func NewMessageQueue ¶
func NewMessageQueue(size uint64, ch bool, lazyFreeCycle uint64, maxMemorySize uint64) *MessageQueue
NewMessageQueue creates a new MessageQueue instance.
func (*MessageQueue) Add ¶
func (q *MessageQueue) Add(msg pb.Message) (bool, bool)
Add adds the specified message to the queue.
func (*MessageQueue) Ch ¶
func (q *MessageQueue) Ch() <-chan struct{}
Ch returns the notification channel.
func (*MessageQueue) Close ¶
func (q *MessageQueue) Close()
Close closes the queue so no further messages can be added.
func (*MessageQueue) Get ¶
func (q *MessageQueue) Get() []pb.Message
Get returns everything current in the queue.
func (*MessageQueue) MustAdd ¶
func (q *MessageQueue) MustAdd(msg pb.Message) bool
MustAdd adds the specified message to the queue.
func (*MessageQueue) Notify ¶
func (q *MessageQueue) Notify()
Notify notifies the notification channel listener that a new message is now available in the queue.
type ProposalInfo ¶
ProposalInfo contains info on proposals.
type RateLimiter ¶
type RateLimiter struct {
// contains filtered or unexported fields
}
RateLimiter is the struct used to keep tracking the in memory rate log size.
func NewRateLimiter ¶
func NewRateLimiter(maxSize uint64) *RateLimiter
NewRateLimiter creates and returns a rate limiter instance.
func (*RateLimiter) Decrease ¶
func (r *RateLimiter) Decrease(sz uint64)
Decrease decreases the recorded in memory log size by sz bytes.
func (*RateLimiter) Enabled ¶
func (r *RateLimiter) Enabled() bool
Enabled returns a boolean flag indicating whether the rate limiter is enabled.
func (*RateLimiter) Get ¶
func (r *RateLimiter) Get() uint64
Get returns the recorded in memory log size.
func (*RateLimiter) GetHeartbeatTick ¶
func (r *RateLimiter) GetHeartbeatTick() uint64
GetHeartbeatTick returns the internal logical clock value.
func (*RateLimiter) HeartbeatTick ¶
func (r *RateLimiter) HeartbeatTick()
HeartbeatTick advances the internal logical clock.
func (*RateLimiter) Increase ¶
func (r *RateLimiter) Increase(sz uint64)
Increase increases the recorded in memory log size by sz bytes.
func (*RateLimiter) RateLimited ¶
func (r *RateLimiter) RateLimited() bool
RateLimited returns a boolean flag indicating whether the node is rate limited.
func (*RateLimiter) ResetFollowerState ¶
func (r *RateLimiter) ResetFollowerState()
ResetFollowerState clears all recorded follower states.
func (*RateLimiter) Set ¶
func (r *RateLimiter) Set(sz uint64)
Set sets the recorded in memory log size to sz bytes.
func (*RateLimiter) SetFollowerState ¶
func (r *RateLimiter) SetFollowerState(nodeID uint64, sz uint64)
SetFollowerState sets the follower rate identiified by nodeID to sz bytes.
type ReadIndexInfo ¶
ReadIndexInfo contains info on read index requests.
type ReplicationInfo ¶
ReplicationInfo contains info of a replication message.
type SSEnv ¶
type SSEnv struct {
// contains filtered or unexported fields
}
SSEnv is the struct used to manage involved directories for taking or receiving snapshots.
func NewSSEnv ¶
func NewSSEnv(f GetSnapshotDirFunc, clusterID uint64, nodeID uint64, index uint64, from uint64, mode Mode, fs vfs.IFS) *SSEnv
NewSSEnv creates and returns a new SSEnv instance.
func (*SSEnv) CreateTempDir ¶
CreateTempDir creates the temp snapshot directory.
func (*SSEnv) FinalizeSnapshot ¶
FinalizeSnapshot finalizes the snapshot.
func (*SSEnv) GetFilename ¶
GetFilename returns the snapshot filename.
func (*SSEnv) GetFilepath ¶
GetFilepath returns the snapshot file path.
func (*SSEnv) GetFinalDir ¶
GetFinalDir returns the final snapshot directory.
func (*SSEnv) GetRootDir ¶
GetRootDir returns the root directory. The temp and final snapshot directories are children of the root directory.
func (*SSEnv) GetShrinkedFilepath ¶
GetShrinkedFilepath returns the file path of the shrunk snapshot.
func (*SSEnv) GetTempDir ¶
GetTempDir returns the temp snapshot directory.
func (*SSEnv) GetTempFilepath ¶
GetTempFilepath returns the temp snapshot file path.
func (*SSEnv) HasFlagFile ¶
HasFlagFile returns a boolean flag indicating whether the flag file is available in the final directory.
func (*SSEnv) MustRemoveTempDir ¶
func (se *SSEnv) MustRemoveTempDir()
MustRemoveTempDir removes the temp snapshot directory and panic if there is any error.
func (*SSEnv) RemoveFinalDir ¶
RemoveFinalDir removes the final snapshot directory.
func (*SSEnv) RemoveFlagFile ¶
RemoveFlagFile removes the flag file from the final directory.
func (*SSEnv) RemoveTempDir ¶
RemoveTempDir removes the temp snapshot directory.
type SnapshotInfo ¶
SnapshotInfo contains info of a snapshot.
type SystemEvent ¶
type SystemEvent struct { Type SystemEventType ClusterID uint64 NodeID uint64 Address string SnapshotConnection bool From uint64 Index uint64 }
SystemEvent is an system event record published by the system that can be handled by a raftio.ISystemEventListener.
type SystemEventType ¶
type SystemEventType uint64
SystemEventType is the type of system events.
const ( // NodeHostShuttingDown ... NodeHostShuttingDown SystemEventType = iota // NodeReady ... NodeReady // NodeUnloaded ... NodeUnloaded // MembershipChanged ... MembershipChanged // ConnectionEstablished ... ConnectionEstablished // ConnectionFailed ... ConnectionFailed // SendSnapshotStarted ... SendSnapshotStarted // SendSnapshotCompleted ... SendSnapshotCompleted // SendSnapshotAborted ... SendSnapshotAborted // SnapshotReceived ... SnapshotReceived // SnapshotRecovered ... SnapshotRecovered // SnapshotCreated ... SnapshotCreated // SnapshotCompacted ... SnapshotCompacted // LogCompacted ... LogCompacted // LogDBCompacted ... LogDBCompacted )
type TickerFunc ¶
TickerFunc is type of the function that will be called by the RunTicker function after each tick. The returned boolean value indicates whether the ticker should stop.