Documentation
¶
Overview ¶
builder.go implements VersionBuilder for applying edits to versions.
VersionBuilder efficiently applies a sequence of edits to a version without creating intermediate versions with full copies of state.
Reference: RocksDB v10.7.5
- db/version_builder.h
- db/version_builder.cc
Package version manages database versions and the LSM-tree structure.
A Version represents a snapshot of the database state at a point in time. It contains the list of SST files at each level and provides methods for querying and iterating over the data.
A VersionSet manages all versions and the MANIFEST file. It provides the interface for logging and applying VersionEdits to create new versions.
Reference: RocksDB v10.7.5
- db/version_set.h (Version class)
- db/version_set.cc
version_set.go implements the VersionSet which manages all versions.
VersionSet maintains the set of all versions and handles MANIFEST file operations. It provides thread-safe access to the current version.
Reference: RocksDB v10.7.5
- db/version_set.h (VersionSet class)
- db/version_set.cc
Whitebox Testing Hooks ¶
This file contains whitebox testing hooks for crash testing (requires -tags crashtest). In production builds, these compile to no-ops with zero overhead. See docs/testing/README.md for usage.
Index ¶
- Constants
- Variables
- type Builder
- type RecoveredColumnFamily
- type Version
- func (v *Version) Files(level int) []*manifest.FileMetaData
- func (v *Version) NumFiles(level int) int
- func (v *Version) NumLevelBytes(level int) uint64
- func (v *Version) NumLevels() int
- func (v *Version) OverlappingInputs(level int, begin, end []byte) []*manifest.FileMetaData
- func (v *Version) Ref()
- func (v *Version) TotalFiles() int
- func (v *Version) Unref()
- func (v *Version) VersionNumber() uint64
- type VersionSet
- func (vs *VersionSet) Close() error
- func (vs *VersionSet) Create() error
- func (vs *VersionSet) Current() *Version
- func (vs *VersionSet) CurrentVersionNumber() uint64
- func (vs *VersionSet) GetManifestFileNumber() uint64
- func (vs *VersionSet) LastSequence() uint64
- func (vs *VersionSet) LogAndApply(edit *manifest.VersionEdit) error
- func (vs *VersionSet) LogNumber() uint64
- func (vs *VersionSet) ManifestFileNumber() uint64
- func (vs *VersionSet) MaxColumnFamily() uint32
- func (vs *VersionSet) NextFileNumber() uint64
- func (vs *VersionSet) NextVersionNumber() uint64
- func (vs *VersionSet) NumLevelBytes(level int) uint64
- func (vs *VersionSet) NumLevelFiles(level int) int
- func (vs *VersionSet) NumLiveVersions() int
- func (vs *VersionSet) Recover() error
- func (vs *VersionSet) RecoveredColumnFamilies() []RecoveredColumnFamily
- func (vs *VersionSet) SetLastSequence(seq uint64)
- func (vs *VersionSet) SyncManifest() error
- type VersionSetOptions
Constants ¶
const MaxNumLevels = 7
MaxNumLevels is the maximum number of levels in the LSM-tree.
Variables ¶
var ( ErrNotFound = errors.New("version: not found") ErrCorruption = errors.New("version: corruption") ErrInvalidManifest = errors.New("version: invalid manifest") ErrNoCurrentManifest = errors.New("version: no current manifest") ErrManifestTooLarge = errors.New("version: manifest too large") )
Errors returned by VersionSet operations.
var ErrComparatorMismatch = errors.New("version: comparator mismatch")
ErrComparatorMismatch indicates that the database was created with a different comparator.
Functions ¶
This section is empty.
Types ¶
type Builder ¶
type Builder struct {
// contains filtered or unexported fields
}
Builder accumulates changes to a Version and produces a new Version.
Usage:
builder := NewBuilder(vset, baseVersion) builder.Apply(edit1) builder.Apply(edit2) newVersion := builder.SaveTo(vset)
func NewBuilder ¶
func NewBuilder(vset *VersionSet, base *Version) *Builder
NewBuilder creates a new Builder based on the given Version.
func (*Builder) Apply ¶
func (b *Builder) Apply(edit *manifest.VersionEdit) error
Apply applies a VersionEdit to the builder.
func (*Builder) SaveTo ¶
func (b *Builder) SaveTo(vset *VersionSet) *Version
SaveTo creates a new Version with all the accumulated changes.
type RecoveredColumnFamily ¶
RecoveredColumnFamily holds information about a column family recovered from MANIFEST.
type Version ¶
type Version struct {
// contains filtered or unexported fields
}
Version represents a snapshot of the database state at a point in time. Each Version keeps track of the set of SST files at each level.
Versions are immutable once created. New versions are created by applying VersionEdits to an existing version via the VersionBuilder.
Versions use reference counting to manage their lifetime. When a Version is no longer needed, call Unref() to decrement the reference count.
func NewVersion ¶
func NewVersion(vset *VersionSet, versionNumber uint64) *Version
NewVersion creates a new empty Version.
func (*Version) Files ¶
func (v *Version) Files(level int) []*manifest.FileMetaData
Files returns the files at the given level.
func (*Version) NumLevelBytes ¶
NumLevelBytes returns the total size of files at the given level.
func (*Version) OverlappingInputs ¶
func (v *Version) OverlappingInputs(level int, begin, end []byte) []*manifest.FileMetaData
OverlappingInputs returns the files at the given level that overlap with the key range [begin, end]. If begin or end is nil, it means "no bound".
func (*Version) TotalFiles ¶
TotalFiles returns the total number of files across all levels.
func (*Version) Unref ¶
func (v *Version) Unref()
Unref decrements the reference count and deletes the version if it reaches 0.
func (*Version) VersionNumber ¶
VersionNumber returns the version number for debugging.
type VersionSet ¶
type VersionSet struct {
// contains filtered or unexported fields
}
VersionSet manages the set of versions and the MANIFEST file.
func NewVersionSet ¶
func NewVersionSet(opts VersionSetOptions) *VersionSet
NewVersionSet creates a new VersionSet.
func (*VersionSet) Close ¶
func (vs *VersionSet) Close() error
Close closes the VersionSet and releases resources.
func (*VersionSet) Create ¶
func (vs *VersionSet) Create() error
Create creates a new database with an initial empty version.
func (*VersionSet) Current ¶
func (vs *VersionSet) Current() *Version
Current returns the current (newest) version. The caller should call Ref() on the returned version if they need to keep it.
func (*VersionSet) CurrentVersionNumber ¶
func (vs *VersionSet) CurrentVersionNumber() uint64
CurrentVersionNumber returns the current version number.
func (*VersionSet) GetManifestFileNumber ¶
func (vs *VersionSet) GetManifestFileNumber() uint64
GetManifestFileNumber returns the current MANIFEST file number.
func (*VersionSet) LastSequence ¶
func (vs *VersionSet) LastSequence() uint64
LastSequence returns the last sequence number.
func (*VersionSet) LogAndApply ¶
func (vs *VersionSet) LogAndApply(edit *manifest.VersionEdit) error
LogAndApply logs a VersionEdit to the MANIFEST and applies it.
func (*VersionSet) LogNumber ¶
func (vs *VersionSet) LogNumber() uint64
LogNumber returns the current log file number.
func (*VersionSet) ManifestFileNumber ¶
func (vs *VersionSet) ManifestFileNumber() uint64
ManifestFileNumber returns the current manifest file number.
func (*VersionSet) MaxColumnFamily ¶
func (vs *VersionSet) MaxColumnFamily() uint32
MaxColumnFamily returns the maximum column family ID seen in the MANIFEST.
func (*VersionSet) NextFileNumber ¶
func (vs *VersionSet) NextFileNumber() uint64
NextFileNumber allocates a new file number.
func (*VersionSet) NextVersionNumber ¶
func (vs *VersionSet) NextVersionNumber() uint64
NextVersionNumber allocates a new version number.
func (*VersionSet) NumLevelBytes ¶
func (vs *VersionSet) NumLevelBytes(level int) uint64
NumLevelBytes returns the total size of files at the given level.
func (*VersionSet) NumLevelFiles ¶
func (vs *VersionSet) NumLevelFiles(level int) int
NumLevelFiles returns the number of files at the given level.
func (*VersionSet) NumLiveVersions ¶
func (vs *VersionSet) NumLiveVersions() int
NumLiveVersions returns the number of live versions.
func (*VersionSet) Recover ¶
func (vs *VersionSet) Recover() error
Recover reads the MANIFEST file and recovers the database state.
func (*VersionSet) RecoveredColumnFamilies ¶
func (vs *VersionSet) RecoveredColumnFamilies() []RecoveredColumnFamily
RecoveredColumnFamilies returns the column families recovered from MANIFEST. This should be called after Recover() to get the non-default CFs.
func (*VersionSet) SetLastSequence ¶
func (vs *VersionSet) SetLastSequence(seq uint64)
SetLastSequence sets the last sequence number.
func (*VersionSet) SyncManifest ¶
func (vs *VersionSet) SyncManifest() error
SyncManifest ensures the MANIFEST file is synced to disk. This is useful before creating checkpoints.
type VersionSetOptions ¶
type VersionSetOptions struct {
// DBName is the database directory path.
DBName string
// FS is the filesystem to use.
FS vfs.FS
// MaxManifestFileSize is the maximum size of a MANIFEST file before rotation.
MaxManifestFileSize uint64
// NumLevels is the number of levels in the LSM tree.
NumLevels int
// ComparatorName is the name of the comparator used by the database.
// This is validated against the comparator stored in the MANIFEST.
// If empty, defaults to "leveldb.BytewiseComparator".
ComparatorName string
// Logger is an optional logger for MANIFEST operations.
// If nil, no logging is performed.
Logger logging.Logger
}
VersionSetOptions configures the VersionSet.
func DefaultVersionSetOptions ¶
func DefaultVersionSetOptions(dbname string) VersionSetOptions
DefaultVersionSetOptions returns default options.