package storage
import "go.etcd.io/etcd/server/v3/storage"
Index ¶
- Constants
- Variables
- func CreateConfigChangeEnts(lg *zap.Logger, ids []uint64, self uint64, term, index uint64) []*raftpb.Entry
- func GetEffectiveNodeIDsFromWALEntries(lg *zap.Logger, snap *raftpb.Snapshot, ents []*raftpb.Entry) []uint64
- func OpenBackend(cfg config.ServerConfig, hooks backend.Hooks) backend.Backend
- func OpenSnapshotBackend(cfg config.ServerConfig, ss *snap.Snapshotter, snapshot *raftpb.Snapshot, hooks *BackendHooks) (backend.Backend, error)
- func RecoverSnapshotBackend(cfg config.ServerConfig, oldbe backend.Backend, snapshot *raftpb.Snapshot, beExist bool, hooks *BackendHooks) (backend.Backend, error)
- type BackendHooks
- func NewBackendHooks(lg *zap.Logger, indexer cindex.ConsistentIndexer) *BackendHooks
- func (bh *BackendHooks) OnPreCommitUnsafe(tx backend.UnsafeReadWriter)
- func (bh *BackendHooks) SetConfState(confState *raftpb.ConfState)
- type BackendQuota
- func (b *BackendQuota) Available(v any) bool
- func (b *BackendQuota) Cost(v any) int
- func (b *BackendQuota) Remaining() int64
- type Quota
- type Storage
Constants ¶
const ( // DefaultQuotaBytes is the number of bytes the backend Size may // consume before exceeding the space quota. DefaultQuotaBytes = int64(2 * 1024 * 1024 * 1024) // 2GB // MaxQuotaBytes is the maximum number of bytes suggested for a backend // quota. A larger quota may lead to degraded performance. MaxQuotaBytes = int64(8 * 1024 * 1024 * 1024) // 8GB )
Variables ¶
var ( DefaultQuotaSize = humanize.Bytes(uint64(DefaultQuotaBytes)) )
Functions ¶
func CreateConfigChangeEnts ¶
func CreateConfigChangeEnts(lg *zap.Logger, ids []uint64, self uint64, term, index uint64) []*raftpb.Entry
CreateConfigChangeEnts creates a series of Raft entries (i.e. EntryConfChange) to remove the set of given IDs from the cluster. The ID `self` is _not_ removed, even if present in the set. If `self` is not inside the given ids, it creates a Raft entry to add a default member with the given `self`.
func GetEffectiveNodeIDsFromWALEntries ¶
func GetEffectiveNodeIDsFromWALEntries(lg *zap.Logger, snap *raftpb.Snapshot, ents []*raftpb.Entry) []uint64
GetEffectiveNodeIDsFromWALEntries returns an ordered set of IDs included in the given snapshot and the entries. The given snapshot/entries can contain three kinds of ID-related entry: - ConfChangeAddNode, in which case the contained ID will Be added into the set. - ConfChangeRemoveNode, in which case the contained ID will Be removed from the set. - ConfChangeAddLearnerNode, in which the contained ID will Be added into the set.
func OpenBackend ¶
func OpenBackend(cfg config.ServerConfig, hooks backend.Hooks) backend.Backend
OpenBackend returns a backend using the current etcd db.
func OpenSnapshotBackend ¶
func OpenSnapshotBackend(cfg config.ServerConfig, ss *snap.Snapshotter, snapshot *raftpb.Snapshot, hooks *BackendHooks) (backend.Backend, error)
OpenSnapshotBackend renames a snapshot db to the current etcd db and opens it.
func RecoverSnapshotBackend ¶
func RecoverSnapshotBackend(cfg config.ServerConfig, oldbe backend.Backend, snapshot *raftpb.Snapshot, beExist bool, hooks *BackendHooks) (backend.Backend, error)
RecoverSnapshotBackend recovers the DB from a snapshot in case etcd crashes before updating the backend db after persisting raft snapshot to disk, violating the invariant snapshot.Metadata.Index < db.consistentIndex. In this case, replace the db with the snapshot db sent by the leader.
Types ¶
type BackendHooks ¶
type BackendHooks struct {
// contains filtered or unexported fields
}
func NewBackendHooks ¶
func NewBackendHooks(lg *zap.Logger, indexer cindex.ConsistentIndexer) *BackendHooks
func (*BackendHooks) OnPreCommitUnsafe ¶
func (bh *BackendHooks) OnPreCommitUnsafe(tx backend.UnsafeReadWriter)
func (*BackendHooks) SetConfState ¶
func (bh *BackendHooks) SetConfState(confState *raftpb.ConfState)
type BackendQuota ¶
type BackendQuota struct {
// contains filtered or unexported fields
}
func (*BackendQuota) Available ¶
func (b *BackendQuota) Available(v any) bool
func (*BackendQuota) Cost ¶
func (b *BackendQuota) Cost(v any) int
func (*BackendQuota) Remaining ¶
func (b *BackendQuota) Remaining() int64
type Quota ¶
type Quota interface {
// Available judges whether the given request fits within the quota.
Available(req any) bool
// Cost computes the charge against the quota for a given request.
Cost(req any) int
// Remaining is the amount of charge left for the quota.
Remaining() int64
}
Quota represents an arbitrary quota against arbitrary requests. Each request costs some charge; if there is not enough remaining charge, then there are too few resources available within the quota to apply the request.
func NewBackendQuota ¶
func NewBackendQuota(lg *zap.Logger, quotaBackendBytesCfg int64, be backend.Backend, name string) Quota
NewBackendQuota creates a quota layer with the given storage limit.
type Storage ¶
type Storage interface {
// Save function saves ents and state to the underlying stable storage.
// Save MUST block until st and ents are on stable storage.
Save(st *raftpb.HardState, ents []*raftpb.Entry) error
// SaveSnap function saves snapshot to the underlying stable storage.
SaveSnap(snap *raftpb.Snapshot) error
// Close closes the Storage and performs finalization.
Close() error
// Release releases the locked wal files older than the provided snapshot.
Release(snap *raftpb.Snapshot) error
// Sync WAL
Sync() error
// MinimalEtcdVersion returns minimal etcd storage able to interpret WAL log.
MinimalEtcdVersion() *semver.Version
}
func NewStorage ¶
func NewStorage(lg *zap.Logger, w *wal.WAL, s *snap.Snapshotter) Storage
Source Files ¶
backend.go hooks.go metrics.go quota.go storage.go util.go
Directories ¶
| Path | Synopsis |
|---|---|
| storage/backend | Package backend defines a standard interface for etcd's backend MVCC storage. |
| storage/backend/testing | |
| storage/datadir | |
| storage/mvcc | Package mvcc defines etcd's stable MVCC storage. |
| storage/mvcc/testutil | |
| storage/schema | |
| storage/wal | Package wal provides an implementation of write ahead log that is used by etcd. |
| storage/wal/testing | |
| storage/wal/walpb |
- Version
- v3.7.1 (latest)
- Published
- Jul 23, 2026
- Platform
- linux/amd64
- Imports
- 24 packages
- Last checked
- 4 hours ago –
Tools for package owners.