raft

package
v0.0.0-...-51f4fca Latest Latest
Warning

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

Go to latest
Published: Apr 17, 2024 License: BSD-2-Clause-Patent Imports: 35 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// CurrentSchemaVersion indicates the current db schema version.
	CurrentSchemaVersion = 0
)

Variables

View Source
var (
	// ErrNoRaftLogEntries is returned when there are no raft log entries.
	ErrNoRaftLogEntries = errors.New("no raft log entries")
	// ErrNoRaftSnapshots is returned when there are no raft snapshots.
	ErrNoRaftSnapshots = errors.New("no raft snapshots")
)

Functions

func AddContextLock

func AddContextLock(parent context.Context, lock *PoolLock) (context.Context, error)

AddContextLock adds a pool lock to the supplied context.

func DatabaseExists

func DatabaseExists(cfg *DatabaseConfig) (bool, error)

DatabaseExists returns true if the system database file exists.

func ErrFindingNotFound

func ErrFindingNotFound(seq uint64) error

ErrFindingNotFound creates an error that indicates a specified finding wasn't found in the database.

func GetLogEntries

func GetLogEntries(log logging.Logger, cfg *DatabaseConfig, maxEntries ...uint64) (<-chan *LogEntryDetails, error)

GetLogEntries returns the log entries from the raft log via a channel which is closed when there are no more entries to be read.

func GetRaftConfiguration

func GetRaftConfiguration(log logging.Logger, cfg *DatabaseConfig) (raft.Configuration, error)

GetRaftConfiguration returns the current raft configuration.

func IsFindingNotFound

func IsFindingNotFound(err error) bool

IsFindingNotFound checks whether an error is an ErrFindingNotFound.

func IsRaftLeadershipError

func IsRaftLeadershipError(err error) bool

IsRaftLeadershipError returns true if the given error is a known leadership error returned by the raft library.

func RecoverLocalReplica

func RecoverLocalReplica(log logging.Logger, cfg *DatabaseConfig) error

RecoverLocalReplica recovers the MS from the local on-disk replica state.

func RestoreLocalReplica

func RestoreLocalReplica(log logging.Logger, cfg *DatabaseConfig, snapPath string) error

RestoreLocalReplica restores the MS from the snapshot at the supplied path.

Types

type CheckerDatabase

type CheckerDatabase struct {
	Findings CheckerFindingMap
}

CheckerDatabase is the database containing all checker Findings.

type CheckerFindingMap

type CheckerFindingMap map[uint64]*checker.Finding

CheckerFindingMap allows the lookup of a Finding by its sequence number.

type Database

type Database struct {
	sync.Mutex
	// contains filtered or unexported fields
}

Database provides high-level access methods for the system data as well as structure for managing the raft service that replicates the system data.

func MockDatabase

func MockDatabase(t *testing.T, log logging.Logger) *Database

MockDatabase returns a lightweight implementation of the system database that does not support raft replication and does all operations in memory.

func MockDatabaseWithAddr

func MockDatabaseWithAddr(t *testing.T, log logging.Logger, addr *net.TCPAddr) *Database

MockDatabaseWithAddr is similar to MockDatabase but allows a custom replica address to be supplied.

func MockDatabaseWithCfg

func MockDatabaseWithCfg(t *testing.T, log logging.Logger, dbCfg *DatabaseConfig) *Database

MockDatabaseWithCfg is similar to MockDatabase but allows a custom DatabaseConfig to be supplied.

func MockDatabaseWithFaultDomainTree

func MockDatabaseWithFaultDomainTree(t *testing.T, log logging.Logger, tree *system.FaultDomainTree) *Database

MockDatabaseWithFaultDomainTree creates a MockDatabase and sets the fault domain tree.

func NewDatabase

func NewDatabase(log logging.Logger, cfg *DatabaseConfig) (*Database, error)

NewDatabase returns a configured and initialized Database instance.

func TestDatabase

func TestDatabase(t *testing.T, log logging.Logger, replicas ...*net.TCPAddr) (*Database, func())

TestDatabase returns a database that is backed by temporary storage and can be started. Uses an in-memory transport. Much heavier-weight implementation and should only be used by tests that require it.

func (*Database) AddCheckerFinding

func (db *Database) AddCheckerFinding(finding *checker.Finding) error

AddCheckerFinding adds a finding to the database.

func (*Database) AddMember

func (db *Database) AddMember(newMember *system.Member) error

AddMember adds a member to the system.

func (*Database) AddOrUpdateCheckerFinding

func (db *Database) AddOrUpdateCheckerFinding(finding *checker.Finding) error

AddOrUpdateCheckerFinding updates a finding in the database if it is already stored, or stores it if not.

func (*Database) AddPoolService

func (db *Database) AddPoolService(ctx context.Context, ps *system.PoolService) error

AddPoolService creates an entry for a new pool service in the pool database.

func (*Database) AllMembers

func (db *Database) AllMembers() ([]*system.Member, error)

AllMembers returns a copy of the system membership.

func (*Database) Barrier

func (db *Database) Barrier() error

Barrier blocks until the raft implementation has persisted all outstanding log entries.

func (*Database) CheckLeader

func (db *Database) CheckLeader() error

CheckLeader returns an error if the node is not a replica or is not the current system leader. The error can be inspected for hints about where to find the current leader.

func (*Database) CheckReplica

func (db *Database) CheckReplica() error

CheckReplica returns an error if the node is not configured as a replica or the service is not running.

func (*Database) ConfigureTransport

func (db *Database) ConfigureTransport(srv *grpc.Server, dialOpts ...grpc.DialOption) error

ConfigureTransport configures the raft transport for the database.

func (*Database) CurMapVersion

func (db *Database) CurMapVersion() (uint32, error)

CurMapVersion returns the current system map version.

func (*Database) DataVersion

func (db *Database) DataVersion() (uint64, error)

DataVersion returns the current version of the system database.

func (*Database) FaultDomainTree

func (db *Database) FaultDomainTree() *system.FaultDomainTree

FaultDomainTree returns the tree of fault domains of joined members.

func (*Database) FindMemberByRank

func (db *Database) FindMemberByRank(rank ranklist.Rank) (*system.Member, error)

FindMemberByRank searches the member database by rank. If no member is found, an error is returned.

func (*Database) FindMemberByUUID

func (db *Database) FindMemberByUUID(uuid uuid.UUID) (*system.Member, error)

FindMemberByUUID searches the member database by UUID. If no member is found, an error is returned.

func (*Database) FindMembersByAddr

func (db *Database) FindMembersByAddr(addr *net.TCPAddr) ([]*system.Member, error)

FindMembersByAddr searches the member database by control address. If no members are found, an error is returned. This search may return multiple members, as a given address may be associated with more than one rank.

func (*Database) FindPoolServiceByLabel

func (db *Database) FindPoolServiceByLabel(label string) (*system.PoolService, error)

FindPoolServiceByLabel searches the pool database by Label. If no pool service is found, an error is returned.

func (*Database) FindPoolServiceByUUID

func (db *Database) FindPoolServiceByUUID(uuid uuid.UUID) (*system.PoolService, error)

FindPoolServiceByUUID searches the pool database by UUID. If no pool service is found, an error is returned.

func (*Database) GetCheckerFinding

func (db *Database) GetCheckerFinding(seq uint64) (*checker.Finding, error)

GetCheckerFinding looks up a finding by sequence number.

func (*Database) GetCheckerFindings

func (db *Database) GetCheckerFindings(searchList ...uint64) ([]*checker.Finding, error)

GetCheckerFindings fetches findings from the database by sequence number, or fetches all of them if no list is provided.

func (*Database) GetSystemAttrs

func (db *Database) GetSystemAttrs(keys []string, filterFn func(string) bool) (map[string]string, error)

GetSystemAttrs returns a copy of the system properties map.

func (*Database) GroupMap

func (db *Database) GroupMap() (*GroupMap, error)

GroupMap returns the latest system group map.

func (*Database) IncMapVer

func (db *Database) IncMapVer() error

IncMapVer forces the system database to increment the map version.

func (*Database) IsBootstrap

func (db *Database) IsBootstrap() bool

IsBootstrap returns true if the system is a replica and meets the criteria for bootstrapping (starting without configured peers) the system database as part of initial wireup.

func (*Database) IsLeader

func (db *Database) IsLeader() bool

IsLeader returns a boolean indicating whether or not this system thinks that is a) a replica and b) the current leader.

func (*Database) IsReplica

func (db *Database) IsReplica() bool

IsReplica returns true if the system is configured as a replica.

func (*Database) LeaderQuery

func (db *Database) LeaderQuery() (leader string, replicas []string, err error)

LeaderQuery returns the system leader, if known.

func (*Database) MemberCount

func (db *Database) MemberCount(desiredStates ...system.MemberState) (int, error)

MemberCount returns the number of members in the system.

func (*Database) MemberRanks

func (db *Database) MemberRanks(desiredStates ...system.MemberState) ([]ranklist.Rank, error)

MemberRanks returns a slice of all the ranks in the membership.

func (*Database) OnEvent

func (db *Database) OnEvent(_ context.Context, evt *events.RASEvent)

OnEvent handles events and updates system database accordingly.

func (*Database) OnLeadershipGained

func (db *Database) OnLeadershipGained(fns ...onLeadershipGainedFn)

OnLeadershipGained registers callbacks to be run when this instance gains the leadership role.

func (*Database) OnLeadershipLost

func (db *Database) OnLeadershipLost(fns ...onLeadershipLostFn)

OnLeadershipLost registers callbacks to be run when this instance loses the leadership role.

func (*Database) OnRaftShutdown

func (db *Database) OnRaftShutdown(fns ...onRaftShutdownFn)

OnRaftShutdown registers callbacks to be run when this instance shuts down.

func (*Database) PeerAddrs

func (db *Database) PeerAddrs() ([]*net.TCPAddr, error)

PeerAddrs returns the addresses of this system's replication peers.

func (*Database) PoolServiceList

func (db *Database) PoolServiceList(all bool) ([]*system.PoolService, error)

PoolServiceList returns a list of pool services registered with the system. If the all parameter is not true, only pool services in the "Ready" state are returned.

func (*Database) RemoveCheckerFinding

func (db *Database) RemoveCheckerFinding(finding *checker.Finding) error

RemoveCheckerFinding removes a given finding from the checker database.

func (*Database) RemoveCheckerFindingsForPools

func (db *Database) RemoveCheckerFindingsForPools(poolIDs ...string) error

RemoveCheckerFindingsForPools removes any findings in the database associated with one or more pool IDs.

func (*Database) RemoveFiles

func (db *Database) RemoveFiles() error

RemoveFiles destructively removes files associated with the system database.

func (*Database) RemoveMember

func (db *Database) RemoveMember(m *system.Member) error

RemoveMember removes a member from the system.

func (*Database) RemovePoolService

func (db *Database) RemovePoolService(ctx context.Context, poolUUID uuid.UUID) error

RemovePoolService removes a pool database entry.

func (*Database) ReplicaAddr

func (db *Database) ReplicaAddr() (*net.TCPAddr, error)

ReplicaAddr returns the system's replica address if the system is configured as a MS replica.

func (*Database) ResetCheckerData

func (db *Database) ResetCheckerData() error

ResetCheckerData clears all findings in the database.

func (*Database) ResignLeadership

func (db *Database) ResignLeadership(cause error) error

ResignLeadership causes this instance to give up its raft leadership state. No-op if there is only one replica configured or the cause is a raft leadership error.

func (*Database) SetCheckerFindingAction

func (db *Database) SetCheckerFindingAction(seq uint64, action int32) error

SetCheckerFindingAction sets the action chosen for a giving finding.

func (*Database) SetSystemAttrs

func (db *Database) SetSystemAttrs(props map[string]string) error

SetSystemAttrs submits an update to the system properties map.

func (*Database) ShutdownRaft

func (db *Database) ShutdownRaft() error

ShutdownRaft signals that the raft implementation should shut down and release any resources it is holding. Blocks until the shutdown is complete.

func (*Database) Start

func (db *Database) Start(parent context.Context) error

Start checks to see if the system is configured as a MS replica. If not, it returns early without an error. If it is, the persistent storage is initialized if necessary, and the replica is started to begin the process of choosing a MS leader.

func (*Database) Stop

func (db *Database) Stop() error

Stop signals to the database that it should shutdown all background tasks and release any resources.

func (*Database) SystemName

func (db *Database) SystemName() string

SystemName returns the system name set in the configuration.

func (*Database) TakePoolLock

func (db *Database) TakePoolLock(ctx context.Context, poolUUID uuid.UUID) (*PoolLock, error)

TakePoolLock attempts to take a lock on the pool with the given UUID, if the supplied context does not already contain a valid lock for that pool.

func (*Database) UpdateCheckerFinding

func (db *Database) UpdateCheckerFinding(finding *checker.Finding) error

UpdateCheckerFinding updates a finding that is already in the database.

func (*Database) UpdateMember

func (db *Database) UpdateMember(m *system.Member) error

UpdateMember updates an existing member.

func (*Database) UpdatePoolService

func (db *Database) UpdatePoolService(ctx context.Context, ps *system.PoolService) error

UpdatePoolService updates an existing pool database entry.

type DatabaseConfig

type DatabaseConfig struct {
	Replicas              []*net.TCPAddr
	RaftDir               string
	RaftSnapshotThreshold uint64
	RaftSnapshotInterval  time.Duration
	SystemName            string
	ReadOnly              bool
}

DatabaseConfig defines the configuration for the system database.

func (*DatabaseConfig) DBFilePath

func (cfg *DatabaseConfig) DBFilePath() string

DBFilePath returns the path to the system database file.

func (*DatabaseConfig) LocalReplicaAddr

func (cfg *DatabaseConfig) LocalReplicaAddr() (addr *net.TCPAddr, err error)

LocalReplicaAddr returns the address corresponding to the local MS replica, or an error indicating that this node is not a configured replica.

func (*DatabaseConfig) PeerReplicaAddrs

func (cfg *DatabaseConfig) PeerReplicaAddrs() (peers []*net.TCPAddr)

type GroupMap

type GroupMap struct {
	Version     uint32
	RankEntries map[ranklist.Rank]RankEntry
	MSRanks     []ranklist.Rank
}

GroupMap represents a version of the system membership map.

type LogEntryDetails

type LogEntryDetails struct {
	Log       raft.Log
	Time      time.Time
	Operation string
	Data      json.RawMessage
}

LogEntryDetails contains details of a raft log entry.

func GetLastLogEntry

func GetLastLogEntry(log logging.Logger, cfg *DatabaseConfig) (*LogEntryDetails, error)

GetLastLogEntry returns the last (highest index) log entry from the raft log.

func (*LogEntryDetails) DecodeLog

func (led *LogEntryDetails) DecodeLog() error

DecodeLog decodes the log entry data into the LogEntryDetails.

type MemberAddrMap

type MemberAddrMap map[string][]*system.Member

MemberAddrMap provides a map of string->[]*system.Member.

func (MemberAddrMap) MarshalJSON

func (mam MemberAddrMap) MarshalJSON() ([]byte, error)

MarshalJSON creates a serialized representation of the MemberAddrMap. The member's UUID is used to represent the member in order to avoid duplicating member details in the serialized format.

type MemberDatabase

type MemberDatabase struct {
	Ranks        MemberRankMap
	Uuids        MemberUuidMap
	Addrs        MemberAddrMap
	FaultDomains *system.FaultDomainTree
}

MemberDatabase contains a set of maps for looking up members and provides methods for managing the membership.

func (*MemberDatabase) UnmarshalJSON

func (mdb *MemberDatabase) UnmarshalJSON(data []byte) error

UnmarshalJSON "inflates" the MemberDatabase from a compressed and serialized representation. The MemberUuidMap contains a full representation of each Member, whereas the other serialized maps simply use the Member UUID as a placeholder for the mapping.

type MemberRankMap

type MemberRankMap map[ranklist.Rank]*system.Member

MemberRankMap provides a map of Rank->*system.Member.

func (MemberRankMap) MarshalJSON

func (mrm MemberRankMap) MarshalJSON() ([]byte, error)

MarshalJSON creates a serialized representation of the MemberRankMap. The member's UUID is used to represent the member in order to avoid duplicating member details in the serialized format.

type MemberUuidMap

type MemberUuidMap map[uuid.UUID]*system.Member

MemberUuidMap provides a map of UUID->*system.Member.

type PoolDatabase

type PoolDatabase struct {
	Ranks  PoolRankMap
	Uuids  PoolUuidMap
	Labels PoolLabelMap
}

PoolDatabase contains a set of maps for looking up DAOS Pool Service instances and methods for managing the pool membership.

func (*PoolDatabase) UnmarshalJSON

func (pdb *PoolDatabase) UnmarshalJSON(data []byte) error

UnmarshalJSON "inflates" the PoolDatabase from a compressed and serialized representation. The PoolUuidMap contains a full representation of each PoolService, whereas the other serialized maps simply use the Pool UUID as a placeholder for the mapping.

type PoolLabelMap

type PoolLabelMap map[string]*system.PoolService

PoolLabelMap provides a map of Label->*PoolService.

func (PoolLabelMap) MarshalJSON

func (plm PoolLabelMap) MarshalJSON() ([]byte, error)

MarshalJSON creates a serialized representation of the PoolLabelMap. The pool's UUID is used to represent the pool service in order to avoid duplicating pool service details in the serialized format.

type PoolLock

type PoolLock struct {
	// contains filtered or unexported fields
}

PoolLock represents a lock on a pool. These locks are reference counted to make them reentrant. Note that the lock release closure will only ever be called once, no matter how many times Release() is called.

func (*PoolLock) InContext

func (pl *PoolLock) InContext(parent context.Context) context.Context

InContext returns a new child context with the lock added as a value. NB: It is the caller's responsibility to ensure that the parent context is valid and does not already contain a different pool lock. For a more robust implementation, see the AddContextLock() function.

func (*PoolLock) Release

func (pl *PoolLock) Release()

Release releases the lock on the pool when the reference count reaches zero.

type PoolRankMap

type PoolRankMap map[ranklist.Rank][]*system.PoolService

PoolRankMap provides a map of Rank->[]*PoolService.

func (PoolRankMap) MarshalJSON

func (prm PoolRankMap) MarshalJSON() ([]byte, error)

MarshalJSON creates a serialized representation of the PoolRankMap. The pool's UUID is used to represent the pool service in order to avoid duplicating pool service details in the serialized format.

type PoolUuidMap

type PoolUuidMap map[uuid.UUID]*system.PoolService

PoolUuidMap provides a map of UUID->*PoolService.

type RaftComponents

type RaftComponents struct {
	Logger        logging.Logger
	Bootstrap     bool
	ReplicaAddr   *net.TCPAddr
	Config        *raft.Config
	LogStore      raft.LogStore
	StableStore   raft.StableStore
	SnapshotStore raft.SnapshotStore
}

RaftComponents holds the components required to start a raft instance.

func ConfigureComponents

func ConfigureComponents(log logging.Logger, dbCfg *DatabaseConfig) (*RaftComponents, error)

ConfigureComponents configures the raft components of the database.

type RankEntry

type RankEntry struct {
	PrimaryURI       string
	NumPrimaryCtxs   uint32
	SecondaryURIs    []string
	NumSecondaryCtxs []uint32
	Incarnation      uint64
}

RankEntry comprises the information about a rank in GroupMap.

type SnapshotDetails

type SnapshotDetails struct {
	Metadata      *raft.SnapshotMeta
	Path          string
	Version       uint
	MapVersion    uint
	SchemaVersion uint
	NextRank      uint
	MemberRanks   *ranklist.RankSet
	Pools         []string
}

SnapshotDetails contains details of a raft snapshot, including an interpretation of the snapshot data in database format.

func GetLatestSnapshot

func GetLatestSnapshot(log logging.Logger, cfg *DatabaseConfig) (*SnapshotDetails, error)

GetLatestSnapshot returns the latest snapshot found on the system.

func GetSnapshotInfo

func GetSnapshotInfo(log logging.Logger, cfg *DatabaseConfig) ([]*SnapshotDetails, error)

GetSnapshotInfo returns a list of snapshot details found on the system.

func ReadSnapshotInfo

func ReadSnapshotInfo(path string) (*SnapshotDetails, error)

ReadSnapshotInfo reads the snapshot metadata and data from the given path.

func (*SnapshotDetails) DecodeSnapshot

func (sd *SnapshotDetails) DecodeSnapshot(data []byte) error

DecodeSnapshot decodes the snapshot data into the SnapshotDetails.

type SystemDatabase

type SystemDatabase struct {
	Attributes map[string]string
}

SystemDatabase contains system-level information that must be raft-replicated.

Jump to

Keyboard shortcuts

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