server

package
v0.0.0-...-a582c34 Latest Latest
Warning

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

Go to latest
Published: May 16, 2021 License: Apache-2.0 Imports: 20 Imported by: 0

Documentation

Index

Constants

View Source
const (

	// ChangeTickThreashold is the minimum number of ticks required to update
	// the state of the rate limiter.
	ChangeTickThreashold uint64 = 10
)
View Source
const (
	// NoLeader is the flag used to indcate that there is no leader or the leader
	// is unknown.
	NoLeader uint64 = 0
)

Variables

View Source
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")
)
View Source
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]+$`)
	// SnapshotDirNamePartsRe is used to find the index value from snapshot folder name.
	SnapshotDirNamePartsRe = 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

func GetSnapshotDirName(index uint64) string

GetSnapshotDirName returns the snapshot dir name for the snapshot captured at the specified index.

func GetSnapshotFilename

func GetSnapshotFilename(index uint64) string

GetSnapshotFilename returns the filename of the snapshot file.

Types

type CampaignInfo

type CampaignInfo struct {
	ClusterID uint64
	NodeID    uint64
	PreVote   bool
	Term      uint64
}

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 NewEnv

func NewEnv(nhConfig config.NodeHostConfig, fs vfs.IFS) (*Env, error)

NewEnv creates and returns a new server Env object.

func (*Env) CheckLogDBType

func (env *Env) CheckLogDBType(cfg config.NodeHostConfig,
	dbType string) error

CheckLogDBType checks whether LogDB type is compatible.

func (*Env) CheckNodeHostDir

func (env *Env) CheckNodeHostDir(cfg config.NodeHostConfig,
	binVer uint32, dbType string) error

CheckNodeHostDir checks whether NodeHost dir is owned by the current nodehost.

func (*Env) Close

func (env *Env) Close() (err error)

Close closes the environment.

func (*Env) CreateNodeHostDir

func (env *Env) CreateNodeHostDir(did uint64) (string, string, error)

CreateNodeHostDir creates the top level dirs used by nodehost.

func (*Env) CreateSnapshotDir

func (env *Env) CreateSnapshotDir(did uint64,
	clusterID uint64, nodeID uint64) error

CreateSnapshotDir creates the snapshot directory for the specified node.

func (*Env) GetLogDBDirs

func (env *Env) GetLogDBDirs(did uint64) (string, string)

GetLogDBDirs returns the directory names for LogDB

func (*Env) GetRandomSource

func (env *Env) GetRandomSource() random.Source

GetRandomSource returns the random source associated with the Nodehost.

func (*Env) GetSnapshotDir

func (env *Env) GetSnapshotDir(did uint64, clusterID uint64,
	nodeID uint64) string

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

func (env *Env) LockNodeHostDir() error

LockNodeHostDir tries to lock the NodeHost data directories.

func (*Env) NodeHostID

func (env *Env) NodeHostID() string

NodeHostID returns the string representation of the NodeHost ID value.

func (*Env) RemoveSnapshotDir

func (env *Env) RemoveSnapshotDir(did uint64,
	clusterID uint64, nodeID uint64) error

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

type IPartitioner interface {
	GetPartitionID(clusterID uint64) uint64
}

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

type LeaderInfo struct {
	ClusterID uint64
	NodeID    uint64
	Term      uint64
	LeaderID  uint64
}

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

func (q *MessageQueue) AddDelayed(msg pb.Message, delay uint64) bool

AddDelayed adds the specified message to the queue and makes sure that the message will stay in the queue for at least delay ticks.

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.

func (*MessageQueue) Tick

func (q *MessageQueue) Tick()

Tick increases the internal tick value.

type Mode

type Mode uint64

Mode is the snapshot env mode.

const (
	// SnapshotMode is the mode used when taking snapshotting.
	SnapshotMode Mode = iota
	// ReceivingMode is the mode used when receiving snapshots from remote nodes.
	ReceivingMode
)

type ProposalInfo

type ProposalInfo struct {
	Entries   []pb.Entry
	ClusterID uint64
	NodeID    uint64
}

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

type ReadIndexInfo struct {
	ClusterID uint64
	NodeID    uint64
}

ReadIndexInfo contains info on read index requests.

type ReplicationInfo

type ReplicationInfo struct {
	ClusterID uint64
	NodeID    uint64
	From      uint64
	Index     uint64
	Term      uint64
}

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

func (se *SSEnv) CreateTempDir() error

CreateTempDir creates the temp snapshot directory.

func (*SSEnv) FinalizeSnapshot

func (se *SSEnv) FinalizeSnapshot(msg pb.Marshaler) error

FinalizeSnapshot finalizes the snapshot.

func (*SSEnv) GetFilename

func (se *SSEnv) GetFilename() string

GetFilename returns the snapshot filename.

func (*SSEnv) GetFilepath

func (se *SSEnv) GetFilepath() string

GetFilepath returns the snapshot file path.

func (*SSEnv) GetFinalDir

func (se *SSEnv) GetFinalDir() string

GetFinalDir returns the final snapshot directory.

func (*SSEnv) GetRootDir

func (se *SSEnv) GetRootDir() string

GetRootDir returns the root directory. The temp and final snapshot directories are children of the root directory.

func (*SSEnv) GetShrinkedFilepath

func (se *SSEnv) GetShrinkedFilepath() string

GetShrinkedFilepath returns the file path of the shrunk snapshot.

func (*SSEnv) GetTempDir

func (se *SSEnv) GetTempDir() string

GetTempDir returns the temp snapshot directory.

func (*SSEnv) GetTempFilepath

func (se *SSEnv) GetTempFilepath() string

GetTempFilepath returns the temp snapshot file path.

func (*SSEnv) HasFlagFile

func (se *SSEnv) HasFlagFile() bool

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

func (se *SSEnv) RemoveFinalDir() error

RemoveFinalDir removes the final snapshot directory.

func (*SSEnv) RemoveFlagFile

func (se *SSEnv) RemoveFlagFile() error

RemoveFlagFile removes the flag file from the final directory.

func (*SSEnv) RemoveTempDir

func (se *SSEnv) RemoveTempDir() error

RemoveTempDir removes the temp snapshot directory.

func (*SSEnv) SaveSSMetadata

func (se *SSEnv) SaveSSMetadata(msg pb.Marshaler) error

SaveSSMetadata saves the metadata of the snapshot file.

type SnapshotDirFunc

type SnapshotDirFunc func(clusterID uint64, nodeID uint64) string

SnapshotDirFunc is the function type that returns the snapshot dir for the specified raft node.

type SnapshotInfo

type SnapshotInfo struct {
	ClusterID uint64
	NodeID    uint64
	From      uint64
	Index     uint64
	Term      uint64
}

SnapshotInfo contains info of a snapshot.

type SystemEvent

type SystemEvent struct {
	Address            string
	Type               SystemEventType
	ClusterID          uint64
	NodeID             uint64
	From               uint64
	Index              uint64
	SnapshotConnection bool
}

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
)

Jump to

Keyboard shortcuts

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