package backend
import "go.etcd.io/etcd/server/v3/storage/backend"
Package backend defines a standard interface for etcd's backend MVCC storage.
Index ¶
- Constants
- Variables
- func ValidateCalledInsideApply(lg *zap.Logger)
- func ValidateCalledInsideUnittest(lg *zap.Logger)
- func ValidateCalledOutSideApply(lg *zap.Logger)
- func VerifyBackendConsistency(b Backend, lg *zap.Logger, skipSafeRangeBucket bool, bucket ...Bucket)
- type Backend
- func New(bcfg BackendConfig) Backend
- func NewDefaultBackend(lg *zap.Logger, path string, opts ...BackendConfigOption) Backend
- type BackendConfig
- type BackendConfigOption
- type BatchTx
- type Bucket
- type BucketID
- type HookFunc
- type Hooks
- type ReadTx
- type Snapshot
- type UnsafeReadWriter
- type UnsafeReader
- type UnsafeWriter
Constants ¶
const ( EnvVerifyValueLock verify.VerificationType = "lock" )
Variables ¶
var ( // InitialMmapSize is the initial size of the mmapped region. Setting this larger than // the potential max db size can prevent writer from blocking reader. // This only works for linux. InitialMmapSize = uint64(10 * 1024 * 1024 * 1024) )
Functions ¶
func ValidateCalledInsideApply ¶
func ValidateCalledInsideUnittest ¶
func ValidateCalledOutSideApply ¶
func VerifyBackendConsistency ¶
func VerifyBackendConsistency(b Backend, lg *zap.Logger, skipSafeRangeBucket bool, bucket ...Bucket)
VerifyBackendConsistency verifies data in ReadTx and BatchTx are consistent.
Types ¶
type Backend ¶
type Backend interface { // ReadTx returns a read transaction. It is replaced by ConcurrentReadTx in the main data path, see #10523. ReadTx() ReadTx BatchTx() BatchTx // ConcurrentReadTx returns a non-blocking read transaction. ConcurrentReadTx() ReadTx Snapshot() Snapshot Hash(ignores func(bucketName, keyName []byte) bool) (uint32, error) // Size returns the current size of the backend physically allocated. // The backend can hold DB space that is not utilized at the moment, // since it can conduct pre-allocation or spare unused space for recycling. // Use SizeInUse() instead for the actual DB size. Size() int64 // SizeInUse returns the current size of the backend logically in use. // Since the backend can manage free space in a non-byte unit such as // number of pages, the returned value can be not exactly accurate in bytes. SizeInUse() int64 // OpenReadTxN returns the number of currently open read transactions in the backend. OpenReadTxN() int64 Defrag() error ForceCommit() Close() error // SetTxPostLockInsideApplyHook sets a txPostLockInsideApplyHook. SetTxPostLockInsideApplyHook(func()) }
func New ¶
func New(bcfg BackendConfig) Backend
func NewDefaultBackend ¶
func NewDefaultBackend(lg *zap.Logger, path string, opts ...BackendConfigOption) Backend
type BackendConfig ¶
type BackendConfig struct { // Path is the file path to the backend file. Path string // BatchInterval is the maximum time before flushing the BatchTx. BatchInterval time.Duration // BatchLimit is the maximum puts before flushing the BatchTx. BatchLimit int // BackendFreelistType is the backend boltdb's freelist type. BackendFreelistType bolt.FreelistType // MmapSize is the number of bytes to mmap for the backend. MmapSize uint64 // Logger logs backend-side operations. Logger *zap.Logger // UnsafeNoFsync disables all uses of fsync. UnsafeNoFsync bool `json:"unsafe-no-fsync"` // Mlock prevents backend database file to be swapped Mlock bool // Hooks are getting executed during lifecycle of Backend's transactions. Hooks Hooks }
func DefaultBackendConfig ¶
func DefaultBackendConfig(lg *zap.Logger) BackendConfig
type BackendConfigOption ¶
type BackendConfigOption func(*BackendConfig)
func WithMmapSize ¶
func WithMmapSize(size uint64) BackendConfigOption
type BatchTx ¶
type BatchTx interface { Lock() Unlock() // Commit commits a previous tx and begins a new writable one. Commit() // CommitAndStop commits the previous tx and does not create a new one. CommitAndStop() LockInsideApply() LockOutsideApply() UnsafeReadWriter }
type Bucket ¶
type Bucket interface { // ID returns a unique identifier of a bucket. // The id must NOT be persisted and can be used as lightweight identificator // in the in-memory maps. ID() BucketID Name() []byte // String implements Stringer (human readable name). String() string // IsSafeRangeBucket is a hack to avoid inadvertently reading duplicate keys; // overwrites on a bucket should only fetch with limit=1, but safeRangeBucket // is known to never overwrite any key so range is safe. IsSafeRangeBucket() bool }
type BucketID ¶
type BucketID int
type HookFunc ¶
type HookFunc func(tx UnsafeReadWriter)
type Hooks ¶
type Hooks interface { // OnPreCommitUnsafe is executed before Commit of transactions. // The given transaction is already locked. OnPreCommitUnsafe(tx UnsafeReadWriter) }
Hooks allow to add additional logic executed during transaction lifetime.
func NewHooks ¶
type ReadTx ¶
type ReadTx interface { RLock() RUnlock() UnsafeReader }
type Snapshot ¶
type Snapshot interface { // Size gets the size of the snapshot. Size() int64 // WriteTo writes the snapshot into the given writer. WriteTo(w io.Writer) (n int64, err error) // Close closes the snapshot. Close() error }
type UnsafeReadWriter ¶
type UnsafeReadWriter interface { UnsafeReader UnsafeWriter }
type UnsafeReader ¶
type UnsafeReader interface { UnsafeRange(bucket Bucket, key, endKey []byte, limit int64) (keys [][]byte, vals [][]byte) UnsafeForEach(bucket Bucket, visitor func(k, v []byte) error) error }
type UnsafeWriter ¶
type UnsafeWriter interface { UnsafeCreateBucket(bucket Bucket) UnsafeDeleteBucket(bucket Bucket) UnsafePut(bucket Bucket, key []byte, value []byte) UnsafeSeqPut(bucket Bucket, key []byte, value []byte) UnsafeDelete(bucket Bucket, key []byte) }
Source Files ¶
backend.go batch_tx.go config_linux.go doc.go hooks.go metrics.go read_tx.go tx_buffer.go verify.go
Directories ¶
Path | Synopsis |
---|---|
storage/backend/testing |
- Version
- v3.6.0 (latest)
- Published
- May 15, 2025
- Platform
- linux/amd64
- Imports
- 23 packages
- Last checked
- 4 hours ago –
Tools for package owners.