server

package
v3.2.5 Latest Latest
Warning

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

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

Documentation

Index

Constants

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")
	// 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")
)
View Source
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

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.

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

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

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, fs vfs.IFS) (*Context, error)

NewContext creates and returns a new server Context object.

func (*Context) CheckLogDBType

func (sc *Context) CheckLogDBType(did uint64, dbType string) error

CheckLogDBType checks whether LogDB type is compatible.

func (*Context) CheckNodeHostDir

func (sc *Context) CheckNodeHostDir(did uint64,
	addr string, binVer uint32, dbType string) error

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

func (*Context) CreateNodeHostDir

func (sc *Context) CreateNodeHostDir(did uint64) ([]string, []string, error)

CreateNodeHostDir creates the top level dirs used by nodehost.

func (*Context) CreateSnapshotDir

func (sc *Context) CreateSnapshotDir(did uint64,
	clusterID uint64, nodeID uint64) error

CreateSnapshotDir creates the snapshot directory for the specified node.

func (*Context) GetLogDBDirs

func (sc *Context) GetLogDBDirs(did uint64) ([]string, []string)

GetLogDBDirs returns the directory names for LogDB

func (*Context) GetRandomSource

func (sc *Context) GetRandomSource() random.Source

GetRandomSource returns the random source associated with the Nodehost.

func (*Context) GetSnapshotDir

func (sc *Context) GetSnapshotDir(did uint64, clusterID uint64,
	nodeID uint64) string

GetSnapshotDir returns the snapshot directory name.

func (*Context) LockNodeHostDir

func (sc *Context) LockNodeHostDir() error

LockNodeHostDir tries to lock the NodeHost data directories.

func (*Context) RemoveSnapshotDir

func (sc *Context) RemoveSnapshotDir(did uint64,
	clusterID uint64, nodeID uint64) error

RemoveSnapshotDir marks the node snapshot directory as removed and have all existing snapshots deleted.

func (*Context) Stop

func (sc *Context) Stop()

Stop stops the context.

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

type GetSnapshotDirFunc func(clusterID uint64, nodeID uint64) string

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

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

type Mode uint64

Mode is the snapshot env mode.

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

type ProposalInfo

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

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

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

func (se *SSEnv) CreateTempDir() error

CreateTempDir creates the temp snapshot directory.

func (*SSEnv) FinalizeSnapshot

func (se *SSEnv) FinalizeSnapshot(msg fileutil.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 fileutil.Marshaler) error

SaveSSMetadata saves the metadata of the snapshot file.

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 {
	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

type TickerFunc func(usec uint64) 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.

Jump to

Keyboard shortcuts

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