package mvcc
import "go.etcd.io/etcd/server/v3/storage/mvcc"
Package mvcc defines etcd's stable MVCC storage.
Index ¶
- Constants
- Variables
- func BucketKeyToBytes(rev BucketKey, bytes []byte) []byte
- func ChanBufLen() int
- func IsTombstone(b []byte) bool
- func NewRevBytes() []byte
- func NewStore(lg *zap.Logger, b backend.Backend, le lease.Lessor, cfg StoreConfig) *store
- func ReportEventReceived(n int)
- func RevToBytes(rev Revision, bytes []byte) []byte
- func SetFinishedCompact(tx backend.BatchTx, value int64)
- func SetScheduledCompact(tx backend.BatchTx, value int64)
- func UnsafeReadFinishedCompact(tx backend.UnsafeReader) (int64, bool)
- func UnsafeReadScheduledCompact(tx backend.UnsafeReader) (int64, bool)
- func UnsafeSetFinishedCompact(tx backend.UnsafeWriter, value int64)
- func UnsafeSetScheduledCompact(tx backend.UnsafeWriter, value int64)
- type BucketKey
- type FilterFunc
- type HashStorage
- type KV
- type KeyValueHash
- type RangeOptions
- type RangeResult
- type ReadTxMode
- type ReadView
- type Revision
- type StoreConfig
- type TxnRead
- type TxnWrite
- type WatchID
- type WatchResponse
- type WatchStream
- type Watchable
- type WatchableKV
- type WriteView
Constants ¶
const ( // Use ConcurrentReadTx and the txReadBuffer is copied ConcurrentReadTxMode = ReadTxMode(1) // Use backend ReadTx and txReadBuffer is not copied = ReadTxMode(2) )
Variables ¶
var ( ErrCompacted = errors.New("mvcc: required revision has been compacted") ErrFutureRev = errors.New("mvcc: required revision is a future revision") )
var ( ErrWatcherNotExist = errors.New("mvcc: watcher does not exist") ErrEmptyWatcherRange = errors.New("mvcc: watcher range is empty") ErrWatcherDuplicateID = errors.New("mvcc: duplicate watch ID provided on the WatchStream") )
var ErrRevisionNotFound = errors.New("mvcc: revision not found")
Functions ¶
func BucketKeyToBytes ¶
func ChanBufLen ¶
func ChanBufLen() int
func IsTombstone ¶
func NewRevBytes ¶
func NewRevBytes() []byte
func NewStore ¶
func NewStore(lg *zap.Logger, b backend.Backend, le lease.Lessor, cfg StoreConfig) *store
NewStore returns a new store. It is useful to create a store inside mvcc pkg. It should only be used for testing externally. revive:disable-next-line:unexported-return this is used internally in the mvcc pkg
func ReportEventReceived ¶
func ReportEventReceived(n int)
ReportEventReceived reports that an event is received. This function should be called when the external systems received an event from mvcc.Watcher.
func RevToBytes ¶
func SetFinishedCompact ¶
func SetFinishedCompact(tx backend.BatchTx, value int64)
func SetScheduledCompact ¶
func SetScheduledCompact(tx backend.BatchTx, value int64)
func UnsafeReadFinishedCompact ¶
func UnsafeReadScheduledCompact ¶
func UnsafeSetFinishedCompact ¶
func UnsafeSetFinishedCompact(tx backend.UnsafeWriter, value int64)
func UnsafeSetScheduledCompact ¶
func UnsafeSetScheduledCompact(tx backend.UnsafeWriter, value int64)
Types ¶
type BucketKey ¶
type BucketKey struct {
Revision
// contains filtered or unexported fields
}
BucketKey indicates modification of the key-value space. The set of changes that share same main revision changes the key-value space atomically.
func BytesToBucketKey ¶
type FilterFunc ¶
type FilterFunc func(e *mvccpb.Event) bool
FilterFunc returns true if the given event should be filtered out.
type HashStorage ¶
type HashStorage interface {
// Hash computes the hash of the whole backend keyspace,
// including key, lease, and other buckets in storage.
// This is designed for testing ONLY!
// Do not rely on this in production with ongoing transactions,
// since Hash operation does not hold MVCC locks.
// Use "HashByRev" method instead for "key" bucket consistency checks.
Hash() (hash uint32, revision int64, err error)
// HashByRev computes the hash of all MVCC revisions up to a given revision.
HashByRev(rev int64) (hash KeyValueHash, currentRev int64, err error)
// Store adds hash value in local cache, allowing it to be returned by HashByRev.
Store(valueHash KeyValueHash)
// Hashes returns list of up to `hashStorageMaxSize` newest previously stored hashes.
Hashes() []KeyValueHash
}
func NewHashStorage ¶
func NewHashStorage(lg *zap.Logger, s *store) HashStorage
type KV ¶
type KV interface {
ReadView
WriteView
// Read creates a read transaction.
Read(mode ReadTxMode, trace *traceutil.Trace) TxnRead
// Write creates a write transaction.
Write(trace *traceutil.Trace) TxnWrite
// HashStorage returns HashStorage interface for KV storage.
HashStorage() HashStorage
// Compact frees all superseded keys with revisions less than rev.
Compact(trace *traceutil.Trace, rev int64) (<-chan struct{}, error)
// Commit commits outstanding txns into the underlying backend.
Commit()
// Restore restores the KV store from a backend.
Restore(b backend.Backend) error
Close() error
}
type KeyValueHash ¶
type RangeOptions ¶
type RangeOptions struct {
Limit int64
Rev int64
CountOnly bool
FastKeysOnly bool
WithTotalCount bool
}
type RangeResult ¶
type ReadTxMode ¶
type ReadTxMode uint32
type ReadView ¶
type ReadView interface {
// FirstRev returns the first KV revision at the time of opening the txn.
// After a compaction, the first revision increases to the compaction
// revision.
FirstRev() int64
// Rev returns the revision of the KV at the time of opening the txn.
Rev() int64
// Range gets the keys in the range at rangeRev.
// The returned rev is the current revision of the KV when the operation is executed.
// If rangeRev <=0, range gets the keys at currentRev.
// If `end` is nil, the request returns the key.
// If `end` is not nil and not empty, it gets the keys in range [key, range_end).
// If `end` is not nil and empty, it gets the keys greater than or equal to key.
// Limit limits the number of keys returned.
// If the required rev is compacted, ErrCompacted will be returned.
Range(ctx context.Context, key, end []byte, ro RangeOptions) (r *RangeResult, err error)
}
type Revision ¶
type Revision struct {
// Main is the main revision of a set of changes that happen atomically.
Main int64
// Sub is the sub revision of a change in a set of changes that happen
// atomically. Each change has different increasing sub revision in that
// set.
Sub int64
}
func BytesToRev ¶
func (Revision) GreaterThan ¶
type StoreConfig ¶
type StoreConfig struct {
CompactionBatchLimit int
CompactionSleepInterval time.Duration
}
type TxnRead ¶
type TxnRead interface {
ReadView
// End marks the transaction is complete and ready to commit.
End()
}
TxnRead represents a read-only transaction with operations that will not block other read transactions.
type TxnWrite ¶
type TxnWrite interface {
TxnRead
WriteView
// Changes gets the changes made since opening the write txn.
Changes() []*mvccpb.KeyValue
}
TxnWrite represents a transaction that can modify the store.
func NewReadOnlyTxnWrite ¶
type WatchID ¶
type WatchID int64
type WatchResponse ¶
type WatchResponse struct {
// WatchID is the WatchID of the watcher this response sent to.
WatchID WatchID
// Events contains all the events that needs to send.
Events []*mvccpb.Event
// Revision is the revision of the KV when the watchResponse is created.
// For a normal response, the revision should be the same as the last
// modified revision inside Events. For a delayed response to a unsynced
// watcher, the revision is greater than the last modified revision
// inside Events.
Revision int64
// CompactRevision is set when the watcher is cancelled due to compaction.
CompactRevision int64
}
type WatchStream ¶
type WatchStream interface {
// Watch creates a watcher. The watcher watches the events happening or
// happened on the given key or range [key, end) from the given startRev.
//
// The whole event history can be watched unless compacted.
// If "startRev" <=0, watch observes events after currentRev.
//
// The returned "id" is the ID of this watcher. It appears as WatchID
// in events that are sent to the created watcher through stream channel.
// The watch ID is used when it's not equal to AutoWatchID. Otherwise,
// an auto-generated watch ID is returned.
Watch(ctx context.Context, id WatchID, key, end []byte, startRev int64, fcs ...FilterFunc) (WatchID, error)
// Chan returns a chan. All watch response will be sent to the returned chan.
Chan() <-chan WatchResponse
// RequestProgress requests the progress of the watcher with given ID. The response
// will only be sent if the watcher is currently synced.
// The responses will be sent through the WatchRespone Chan attached
// with this stream to ensure correct ordering.
// The responses contains no events. The revision in the response is the progress
// of the watchers since the watcher is currently synced.
RequestProgress(id WatchID)
// RequestProgressAll requests a progress notification for all
// watchers sharing the stream. If all watchers are synced, a
// progress notification with watch ID -1 will be sent to an
// arbitrary watcher of this stream, and the function returns
// true.
RequestProgressAll() bool
// Cancel cancels a watcher by giving its ID. If watcher does not exist, an error will be
// returned.
Cancel(id WatchID) error
// Close closes Chan and release all related resources.
Close()
// Rev returns the current revision of the KV the stream watches on.
Rev() int64
}
type Watchable ¶
type Watchable interface {
// NewWatchStream returns a WatchStream that can be used to
// watch events happened or happening on the KV.
NewWatchStream() WatchStream
}
Watchable is the interface that wraps the NewWatchStream function.
type WatchableKV ¶
WatchableKV is a KV that can be watched.
func New ¶
func New(lg *zap.Logger, b backend.Backend, le lease.Lessor, cfg StoreConfig) WatchableKV
type WriteView ¶
type WriteView interface {
// DeleteRange deletes the given range from the store.
// A deleteRange increases the rev of the store if any key in the range exists.
// The number of key deleted will be returned.
// The returned rev is the current revision of the KV when the operation is executed.
// It also generates one event for each key delete in the event history.
// if the `end` is nil, deleteRange deletes the key.
// if the `end` is not nil, deleteRange deletes the keys in range [key, range_end).
DeleteRange(key, end []byte) (n, rev int64)
// Put puts the given key, value into the store. Put also takes additional argument lease to
// attach a lease to a key-value pair as meta-data. KV implementation does not validate the lease
// id.
// A put also increases the rev of the store, and generates one event in the event history.
// The returned rev is the current revision of the KV when the operation is executed.
Put(key, value []byte, lease lease.LeaseID) (rev int64)
}
Source Files ¶
doc.go hash.go index.go key_index.go kv.go kv_view.go kvstore.go kvstore_compaction.go kvstore_txn.go metrics.go metrics_txn.go revision.go store.go watchable_store.go watchable_store_txn.go watcher.go watcher_group.go
Directories ¶
| Path | Synopsis |
|---|---|
| storage/mvcc/testutil |
- Version
- v3.7.1 (latest)
- Published
- Jul 23, 2026
- Platform
- linux/amd64
- Imports
- 26 packages
- Last checked
- 4 hours ago –
Tools for package owners.