Documentation
¶
Index ¶
- Constants
- Variables
- func GetSnapshotDirName(index uint64) string
- func GetSnapshotFilename(index uint64) string
- func RunTicker(td time.Duration, tf TickerFunc, stopc1 <-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 SnapshotEnv
- func (se *SnapshotEnv) CreateTempDir() error
- func (se *SnapshotEnv) FinalizeSnapshot(msg proto.Message) error
- func (se *SnapshotEnv) GetFilename() string
- func (se *SnapshotEnv) GetFilepath() string
- func (se *SnapshotEnv) GetFinalDir() string
- func (se *SnapshotEnv) GetRootDir() string
- func (se *SnapshotEnv) GetShrinkedFilepath() string
- func (se *SnapshotEnv) GetTempDir() string
- func (se *SnapshotEnv) GetTempFilepath() string
- func (se *SnapshotEnv) HasFlagFile() bool
- func (se *SnapshotEnv) MustRemoveTempDir()
- func (se *SnapshotEnv) RemoveFinalDir() error
- func (se *SnapshotEnv) RemoveFlagFile() error
- func (se *SnapshotEnv) RemoveTempDir() error
- func (se *SnapshotEnv) SaveSnapshotMetadata(msg proto.Message) error
- type SnapshotInfo
- 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 RunTicker ¶
func RunTicker(td time.Duration, tf TickerFunc, stopc1 <-chan struct{}, stopc2 <-chan struct{})
RunTicker 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 ¶ added in v3.1.0
CampaignInfo contains campaign info.
type Context ¶
type Context struct {
// contains filtered or unexported fields
}
Context is the server context for NodeHost.
func NewContext ¶
func NewContext(nhConfig config.NodeHostConfig) (*Context, error)
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 ¶ added in v3.1.0
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 ¶ added in v3.1.0
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 raftpb.Message) (bool, bool)
Add adds the specified message to the queue.
func (*MessageQueue) AddSnapshot ¶
func (q *MessageQueue) AddSnapshot(msg raftpb.Message) bool
AddSnapshot adds the specified snapshot 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() []raftpb.Message
Get returns everything current in 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 ¶ added in v3.1.0
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 ¶ added in v3.1.0
ReadIndexInfo contains info on read index requests.
type ReplicationInfo ¶ added in v3.1.0
ReplicationInfo contains info of a replication message.
type SnapshotEnv ¶
type SnapshotEnv struct {
// contains filtered or unexported fields
}
SnapshotEnv is the struct used to manage involved directories for taking or receiving snapshots.
func NewSnapshotEnv ¶
func NewSnapshotEnv(f GetSnapshotDirFunc, clusterID uint64, nodeID uint64, index uint64, from uint64, mode Mode) *SnapshotEnv
NewSnapshotEnv creates and returns a new SnapshotEnv instance.
func (*SnapshotEnv) CreateTempDir ¶
func (se *SnapshotEnv) CreateTempDir() error
CreateTempDir creates the temp snapshot directory.
func (*SnapshotEnv) FinalizeSnapshot ¶
func (se *SnapshotEnv) FinalizeSnapshot(msg proto.Message) error
FinalizeSnapshot finalizes the snapshot.
func (*SnapshotEnv) GetFilename ¶
func (se *SnapshotEnv) GetFilename() string
GetFilename returns the snapshot filename.
func (*SnapshotEnv) GetFilepath ¶
func (se *SnapshotEnv) GetFilepath() string
GetFilepath returns the snapshot file path.
func (*SnapshotEnv) GetFinalDir ¶
func (se *SnapshotEnv) GetFinalDir() string
GetFinalDir returns the final snapshot directory.
func (*SnapshotEnv) GetRootDir ¶
func (se *SnapshotEnv) GetRootDir() string
GetRootDir returns the root directory. The temp and final snapshot directories are children of the root directory.
func (*SnapshotEnv) GetShrinkedFilepath ¶
func (se *SnapshotEnv) GetShrinkedFilepath() string
GetShrinkedFilepath returns the file path of the shrunk snapshot.
func (*SnapshotEnv) GetTempDir ¶
func (se *SnapshotEnv) GetTempDir() string
GetTempDir returns the temp snapshot directory.
func (*SnapshotEnv) GetTempFilepath ¶
func (se *SnapshotEnv) GetTempFilepath() string
GetTempFilepath returns the temp snapshot file path.
func (*SnapshotEnv) HasFlagFile ¶
func (se *SnapshotEnv) HasFlagFile() bool
HasFlagFile returns a boolean flag indicating whether the flag file is available in the final directory.
func (*SnapshotEnv) MustRemoveTempDir ¶
func (se *SnapshotEnv) MustRemoveTempDir()
MustRemoveTempDir removes the temp snapshot directory and panic if there is any error.
func (*SnapshotEnv) RemoveFinalDir ¶
func (se *SnapshotEnv) RemoveFinalDir() error
RemoveFinalDir removes the final snapshot directory.
func (*SnapshotEnv) RemoveFlagFile ¶
func (se *SnapshotEnv) RemoveFlagFile() error
RemoveFlagFile removes the flag file from the final directory.
func (*SnapshotEnv) RemoveTempDir ¶
func (se *SnapshotEnv) RemoveTempDir() error
RemoveTempDir removes the temp snapshot directory.
func (*SnapshotEnv) SaveSnapshotMetadata ¶
func (se *SnapshotEnv) SaveSnapshotMetadata(msg proto.Message) error
SaveSnapshotMetadata saves the metadata of the snapshot file.
type SnapshotInfo ¶ added in v3.1.0
SnapshotInfo contains info of a snapshot.
type TickerFunc ¶
type TickerFunc func() bool
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.