Documentation ¶
Index ¶
- Constants
- Variables
- func GetSnapshotDirName(index uint64) string
- func GetSnapshotFilename(index uint64) string
- type CampaignInfo
- type DoubleFixedPartitioner
- type Env
- func (env *Env) CheckLogDBType(cfg config.NodeHostConfig, dbType string) error
- func (env *Env) CheckNodeHostDir(cfg config.NodeHostConfig, binVer uint32, dbType string) error
- func (env *Env) CreateNodeHostDir(did uint64) (string, string, error)
- func (env *Env) CreateSnapshotDir(did uint64, clusterID uint64, nodeID uint64) error
- func (env *Env) GetLogDBDirs(did uint64) (string, string)
- func (env *Env) GetRandomSource() random.Source
- func (env *Env) GetSnapshotDir(did uint64, clusterID uint64, nodeID uint64) string
- func (env *Env) LoadNodeHostID() (*id.NodeHostID, error)
- func (env *Env) LockNodeHostDir() error
- func (env *Env) NodeHostID() string
- func (env *Env) RemoveSnapshotDir(did uint64, clusterID uint64, nodeID uint64) error
- func (env *Env) SetNodeHostID(nhid *id.NodeHostID)
- func (env *Env) Stop()
- type FixedPartitioner
- type IPartitioner
- type IRaftEventListener
- type InMemRateLimiter
- func (r *InMemRateLimiter) Decrease(sz uint64)
- func (r *InMemRateLimiter) Enabled() bool
- func (r *InMemRateLimiter) Get() uint64
- func (r *InMemRateLimiter) GetTick() uint64
- func (r *InMemRateLimiter) Increase(sz uint64)
- func (r *InMemRateLimiter) RateLimited() bool
- func (r *InMemRateLimiter) Reset()
- func (r *InMemRateLimiter) Set(sz uint64)
- func (r *InMemRateLimiter) SetFollowerState(nodeID uint64, sz uint64)
- func (r *InMemRateLimiter) Tick()
- type LeaderInfo
- type MessageQueue
- type Mode
- type ProposalInfo
- type RateLimiter
- 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 SnapshotDirFunc
- type SnapshotInfo
- type SystemEvent
- type SystemEventType
Constants ¶
const ( // ChangeTickThreashold is the minimum number of ticks required to update // the state of the rate limiter. ChangeTickThreashold uint64 = 10 )
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") // ErrAddressByNodeHostIDChanged is the error used to indicate that the // AddressByNodeHostID setting has changed. ErrAddressByNodeHostIDChanged = errors.New("AddressByNodeHostID 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("internal/settings/hard.go settings changed") // ErrIncompatibleData indicates that the specified data directory contains // incompatible data. ErrIncompatibleData = errors.New("incompatible LogDB data format") // ErrLogDBBrokenChange indicates that your NodeHost failed to be created as // your code is hit by the LogDB breaking change introduced in v3.0. Set your // NodeHostConfig.LogDBFactory to rocksdb.OpenBatchedLogDB to continue. ErrLogDBBrokenChange = errors.New("using new LogDB on existing Raft Log") )
var ( // ErrSnapshotOutOfDate is the error to indicate that snapshot is out of date. ErrSnapshotOutOfDate = errors.New("snapshot out of date") // MetadataFilename is the filename of a snapshot's metadata file. MetadataFilename = "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.
Types ¶
type CampaignInfo ¶
CampaignInfo contains campaign info.
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 Env ¶
type Env struct {
// contains filtered or unexported fields
}
Env is the server environment for NodeHost.
func (*Env) CheckLogDBType ¶
func (env *Env) CheckLogDBType(cfg config.NodeHostConfig, dbType string) error
CheckLogDBType checks whether LogDB type is compatible.
func (*Env) CheckNodeHostDir ¶
CheckNodeHostDir checks whether NodeHost dir is owned by the current nodehost.
func (*Env) CreateNodeHostDir ¶
CreateNodeHostDir creates the top level dirs used by nodehost.
func (*Env) CreateSnapshotDir ¶
CreateSnapshotDir creates the snapshot directory for the specified node.
func (*Env) GetLogDBDirs ¶
GetLogDBDirs returns the directory names for LogDB
func (*Env) GetRandomSource ¶
GetRandomSource returns the random source associated with the Nodehost.
func (*Env) GetSnapshotDir ¶
GetSnapshotDir returns the snapshot directory name.
func (*Env) LoadNodeHostID ¶
func (env *Env) LoadNodeHostID() (*id.NodeHostID, error)
LoadNodeHostID loads the NodeHost ID value from the ID file. A new ID file will be created with a randomly assigned NodeHostID when running for the first time.
func (*Env) LockNodeHostDir ¶
LockNodeHostDir tries to lock the NodeHost data directories.
func (*Env) NodeHostID ¶
NodeHostID returns the string representation of the NodeHost ID value.
func (*Env) RemoveSnapshotDir ¶
RemoveSnapshotDir marks the node snapshot directory as removed and have all existing snapshots deleted.
func (*Env) SetNodeHostID ¶
func (env *Env) SetNodeHostID(nhid *id.NodeHostID)
SetNodeHostID sets the NodeHostID value recorded in Env. This is typically invoked by tests.
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 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 InMemRateLimiter ¶
type InMemRateLimiter struct {
// contains filtered or unexported fields
}
InMemRateLimiter is the struct used to keep tracking the in memory rate log size.
func NewInMemRateLimiter ¶
func NewInMemRateLimiter(maxSize uint64) *InMemRateLimiter
NewInMemRateLimiter creates and returns a rate limiter instance.
func (*InMemRateLimiter) Decrease ¶
func (r *InMemRateLimiter) Decrease(sz uint64)
Decrease decreases the recorded in memory log size by sz bytes.
func (*InMemRateLimiter) Enabled ¶
func (r *InMemRateLimiter) Enabled() bool
Enabled returns a boolean flag indicating whether the rate limiter is enabled.
func (*InMemRateLimiter) Get ¶
func (r *InMemRateLimiter) Get() uint64
Get returns the recorded in memory log size.
func (*InMemRateLimiter) GetTick ¶
func (r *InMemRateLimiter) GetTick() uint64
GetTick returns the internal logical clock value.
func (*InMemRateLimiter) Increase ¶
func (r *InMemRateLimiter) Increase(sz uint64)
Increase increases the recorded in memory log size by sz bytes.
func (*InMemRateLimiter) RateLimited ¶
func (r *InMemRateLimiter) RateLimited() bool
RateLimited returns a boolean flag indicating whether the node is rate limited.
func (*InMemRateLimiter) Reset ¶
func (r *InMemRateLimiter) Reset()
Reset clears all recorded follower states.
func (*InMemRateLimiter) Set ¶
func (r *InMemRateLimiter) Set(sz uint64)
Set sets the recorded in memory log size to sz bytes.
func (*InMemRateLimiter) SetFollowerState ¶
func (r *InMemRateLimiter) SetFollowerState(nodeID uint64, sz uint64)
SetFollowerState sets the follower rate identiified by nodeID to sz bytes.
func (*InMemRateLimiter) Tick ¶
func (r *InMemRateLimiter) Tick()
Tick advances the internal logical clock.
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 consumed memory size.
func NewRateLimiter ¶
func NewRateLimiter(max 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) 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) Set ¶
func (r *RateLimiter) Set(sz uint64)
Set sets the recorded in memory log size 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 SnapshotDirFunc, 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 SnapshotDirFunc ¶
SnapshotDirFunc is the function type that returns the snapshot dir for the specified raft node.
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 )