Documentation
¶
Overview ¶
Package wildcat
(C) Copyright Alex Gaetano Padula
Licensed under the Mozilla Public License, v. 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
https://www.mozilla.org/en-US/MPL/2.0/
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
Index ¶
- Constants
- type Compactor
- type DB
- type Flusher
- type IDGType
- type IDGenerator
- type IDGeneratorState
- type KLogEntry
- type Level
- type Memtable
- type MergeIterator
- func (mi *MergeIterator) Close()
- func (mi *MergeIterator) HasNext() bool
- func (mi *MergeIterator) HasPrev() bool
- func (mi *MergeIterator) IsAscending() bool
- func (mi *MergeIterator) Next() ([]byte, []byte, int64, bool)
- func (mi *MergeIterator) Prev() ([]byte, []byte, int64, bool)
- func (mi *MergeIterator) SetDirection(ascending bool) error
- type Options
- type SSTable
- type SyncOption
- type Txn
- func (txn *Txn) Commit() error
- func (txn *Txn) Delete(key []byte) error
- func (txn *Txn) Get(key []byte) ([]byte, error)
- func (txn *Txn) NewIterator(asc bool) (*MergeIterator, error)
- func (txn *Txn) NewPrefixIterator(prefix []byte, asc bool) (*MergeIterator, error)
- func (txn *Txn) NewRangeIterator(startKey []byte, endKey []byte, asc bool) (*MergeIterator, error)
- func (txn *Txn) Put(key []byte, value []byte) error
- func (txn *Txn) Rollback() error
- type WAL
Constants ¶
const ( SSTablePrefix = "sst_" // Prefix for SSTable files LevelPrefix = "l" // Prefix for level directories i.e. "l1", "l2", etc. WALFileExtension = ".wal" // Extension for Write Ahead Log files <id>.wal KLogExtension = ".klog" // Extension for KLog files VLogExtension = ".vlog" // Extension for VLog files IDGSTFileName = "idgstate" // Filename for ID generator state TempFileExtension = ".tmp" // Temporary file extension for intermediate files )
Prefixes, filenames, extensions constants
const ( FarFutureOffsetNs = 10_000_000_000 // 10 seconds in nanoseconds; added to time.Now().UnixNano() to scan all versions TombstoneBlockID int64 = -1 // Sentinel ValueBlockID indicating a deletion marker in KLogEntry FlushTargetLevel = 1 // Memtables are always flushed to level 1 (L0 is the active memtable) CompactionScoreThreshold = 1.0 // Compaction score above which a level triggers compaction PartitioningJobPriority = 10.0 // Highest priority value for last-level partitioning jobs MinSSTablesToCompact = 2 // Minimum number of SSTables required to perform a compaction SizeTieredMaxLevelIdx = 2 // Levels with index < this use size-tiered compaction; others use leveled MinLevelsForPartitioning = 2 // Minimum last-level index required before partitioning is considered MinBTreeOrder = 2 // Minimum allowed B-tree order for SSTables BytesPerMB = 1024 * 1024 // Bytes in a megabyte, used for human-readable log output JitterFraction = 4 // Divides backoff to produce ±25% jitter JitterCoinFlip = 2 // Used with rand.Intn for 50/50 jitter direction )
Internal constants used across the codebase to avoid magic numbers
const ( DefaultWriteBufferSize = 64 * 1024 * 1024 // Default write buffer size DefaultSyncOption = SyncNone // Default sync option for write operations DefaultSyncInterval = 16 * time.Nanosecond // Default sync interval for write operations DefaultLevelCount = 6 // Default number of levels in the LSM tree DefaultLevelMultiplier = 10 // Multiplier for the number of levels // 64MB -> 640MB -> 6.4GB -> 64GB -> 640GB -> 6.4TB DefaultBlockManagerLRUSize = 1024 // Size of the LRU cache for block managers DefaultPermission = 0750 // Default permission for created files DefaultMaxCompactionConcurrency = 4 // Default max compaction concurrency DefaultCompactionCooldownPeriod = 5 * time.Second // Default cooldown period for compaction DefaultCompactionBatchSize = 8 // Default max number of SSTables to compact at once DefaultCompactionSizeRatio = 1.1 // Default level size ratio that triggers compaction DefaultCompactionSizeThreshold = 8 // Default number of files to trigger size-tiered compaction DefaultCompactionScoreSizeWeight = 0.8 // Default weight for size-based score DefaultCompactionScoreCountWeight = 0.2 // Default weight for count-based score DefaultCompactionSizeTieredSimilarityRatio = 1.5 // Default similarity ratio for size-tiered compaction DefaultCompactionActiveSSTReadWaitBackoff = 8 * time.Microsecond // Backoff is used to avoid busy waiting when checking if sstables are safe to remove during compaction process final steps DefaultFlusherTickerInterval = 1 * time.Millisecond DefaultCompactorTickerInterval = 250 * time.Millisecond // Default interval for compactor ticker DefaultBloomFilterFPR = 0.01 // Default false positive rate for Bloom filter DefaultWALAppendRetry = 10 // Default number of retries for WAL append DefaultWALAppendBackoff = 128 * time.Microsecond // Default backoff duration for WAL append DefaultSSTableBTreeOrder = 10 // Default order of the B-tree for SSTables DefaultMaxConcurrentTxns = 65536 // Default max concurrent transactions DefaultTxnBeginRetry = 10 // Default retries for Begin() DefaultTxnBeginBackoff = 1 * time.Microsecond // Default initial backoff DefaultTxnBeginMaxBackoff = 100 * time.Millisecond // Default max backoff DefaultCompactionPartitionRatio = 0.2 // Move 20% of data back when partitioning DefaultCompactionPartitionDistributionRatio = 0.7 // 70% to L-1, 30% to L-2 )
Defaults
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Compactor ¶
type Compactor struct {
// contains filtered or unexported fields
}
Compactor is responsible for managing compaction jobs
type DB ¶
type DB struct {
// contains filtered or unexported fields
}
DB represents the main Wildcat structure
func (*DB) ForceFlush ¶
ForceFlush forces the flush of main current memtable and immutable memtables in flusher queue
func (*DB) GetTxn ¶
GetTxn retrieves a transaction by ID. Can be used on system recovery. You can recover an incomplete transaction.
func (*DB) Sync ¶
Sync escalates the Fdatasync operation for the current memtable's write ahead log. To only be used when sync option is set to SyncNone.
type Flusher ¶
type Flusher struct {
// contains filtered or unexported fields
}
Flusher is responsible for queuing and flushing memtables to disk
type IDGenerator ¶
type IDGenerator struct {
// contains filtered or unexported fields
}
IDGenerator is a thread-safe ID generator
type IDGeneratorState ¶
type IDGeneratorState struct {
LastSstID int64 // Last SSTable ID
LastWalID int64 // Last WAL ID
// contains filtered or unexported fields
}
IDGeneratorState represents the state of the ID generator. When system shuts down the state is saved to disk and restored on next startup.
type KLogEntry ¶
type KLogEntry struct {
Key []byte // Key of the entry
Timestamp int64 // Timestamp of the entry
ValueBlockID int64 // Block ID of the value
}
KLogEntry represents a key-value entry in the KLog
type Level ¶
type Level struct {
// contains filtered or unexported fields
}
Level is a disk level within Wildcat, which contains a list of immutable SSTables
type Memtable ¶
type Memtable struct {
// contains filtered or unexported fields
}
Memtable is a memory table structure
type MergeIterator ¶
type MergeIterator struct {
// contains filtered or unexported fields
}
MergeIterator combines multiple iterators into a single iterator
func NewMergeIterator ¶
func NewMergeIterator(db *DB, iterators []*iterator, ts int64, ascending bool) (*MergeIterator, error)
NewMergeIterator creates a new MergeIterator with the given iterators
func (*MergeIterator) Close ¶ added in v2.3.9
func (mi *MergeIterator) Close()
Close cleans up resources and returns iterators to the pool
func (*MergeIterator) HasNext ¶
func (mi *MergeIterator) HasNext() bool
HasNext returns true if there are more entries in the configured direction
func (*MergeIterator) HasPrev ¶
func (mi *MergeIterator) HasPrev() bool
HasPrev returns true if there are entries in the opposite direction
func (*MergeIterator) IsAscending ¶
func (mi *MergeIterator) IsAscending() bool
IsAscending returns the current iteration direction
func (*MergeIterator) Next ¶
func (mi *MergeIterator) Next() ([]byte, []byte, int64, bool)
Next returns the next key-value pair in the configured direction Returns slices that reference existing data to avoid allocations
func (*MergeIterator) Prev ¶
func (mi *MergeIterator) Prev() ([]byte, []byte, int64, bool)
Prev returns the previous key-value pair (opposite of configured direction)
func (*MergeIterator) SetDirection ¶
func (mi *MergeIterator) SetDirection(ascending bool) error
SetDirection changes the iteration direction
type Options ¶
type Options struct {
Directory string // Directory for Wildcat
WriteBufferSize int64 // Size of the write buffer
SyncOption SyncOption // Sync option for write operations
SyncInterval time.Duration // Interval for syncing the write buffer
LevelCount int // Number of levels in the LSM tree
LevelMultiplier int // Multiplier for the number of levels
BlockManagerLRUSize int // Size of the LRU cache for block managers
Permission os.FileMode // Permission for created files
LogChannel chan string // Channel for logging
STDOutLogging bool // Enable logging to standard output (default is false and if set, channel is ignored)
BloomFilter bool // Enable Bloom filter for SSTables
MaxCompactionConcurrency int // Maximum number of concurrent compactions
CompactionCooldownPeriod time.Duration // Cooldown period for compaction
CompactionBatchSize int // Max number of SSTables to compact at once
CompactionSizeRatio float64 // Level size ratio that triggers compaction
CompactionSizeThreshold int // Number of files to trigger size-tiered compaction
CompactionScoreSizeWeight float64 // Weight for size-based score
CompactionScoreCountWeight float64 // Weight for count-based score
CompactionSizeTieredSimilarityRatio float64 // Similarity ratio for size-tiered compaction. For grouping SSTables that are "roughly the same size" together for compaction.
CompactionActiveSSTReadWaitBackoff time.Duration // Backoff time for active SSTable read wait during compaction, to avoid busy waiting
CompactionPartitionRatio float64 // How much to move back (0.6 = 60% of data). Used for last level compaction
CompactionPartitionDistributionRatio float64 // How to split between L-1 and L-2 (0.7 = 70% to L-1, 30% to L-2)
CompactorTickerInterval time.Duration // Interval for compactor ticker
FlusherTickerInterval time.Duration // Interval for flusher ticker
BloomFilterFPR float64 // False positive rate for Bloom filter
WalAppendRetry int // Number of retries for WAL append
WalAppendBackoff time.Duration // Backoff duration for WAL append
SSTableBTreeOrder int // Order of the B-tree for SSTables
MaxConcurrentTxns int // Maximum concurrent transactions (buffer size)
TxnBeginRetry int // Number of retries for Begin() when buffer full
TxnBeginBackoff time.Duration // Initial backoff duration for Begin() retries
TxnBeginMaxBackoff time.Duration // Maximum backoff duration for Begin() retries
RecoverUncommittedTxns bool // Whether to recover uncommitted transactions on startup
}
Options represents the configuration options for Wildcat
type SSTable ¶
type SSTable struct {
Id int64 // SStable ID
Min []byte // The minimum key in the SSTable
Max []byte // The maximum key in the SSTable
Size int64 // The size of the SSTable in bytes
EntryCount int // The number of entries in the SSTable
Level int // The level of the SSTable
BloomFilter *bloomfilter.BloomFilter // Optional bloom filter for fast lookups
Timestamp int64 // Timestamp of latest entry in the SSTable
// contains filtered or unexported fields
}
SSTable represents a sorted string table
type SyncOption ¶
type SyncOption int
SyncOption is a block manager sync option that can be set for a *DB instance. the sync option will be used for all block managers created by the *DB instance internally.
const ( SyncNone SyncOption = iota // We don't sync SyncFull // We sync the entire block manager after each write SyncPartial // We sync based at intervals based on the SyncInterval option.. So every SyncInterval we sync the block manager. )
type Txn ¶
type Txn struct {
Id int64 // The transactions id, can be recovered
ReadSet map[string]int64 // Key -> Timestamp
WriteSet map[string][]byte // Key -> Value
DeleteSet map[string]bool // Key -> Deleted
Timestamp int64 // The timestamp of the transaction
Committed bool // Whether the transaction is committed
// contains filtered or unexported fields
}
Txn represents a transaction in a Wildcat DB instance
func (*Txn) NewIterator ¶
func (txn *Txn) NewIterator(asc bool) (*MergeIterator, error)
NewIterator creates a new bidirectional iterator
func (*Txn) NewPrefixIterator ¶
func (txn *Txn) NewPrefixIterator(prefix []byte, asc bool) (*MergeIterator, error)
NewPrefixIterator creates a new prefix bidirectional iterator
func (*Txn) NewRangeIterator ¶
NewRangeIterator creates a new range bidirectional iterator
Source Files
¶
Directories
¶
| Path | Synopsis |
|---|---|
|
Package blockmanager
|
Package blockmanager |
|
Package bloomfilter
|
Package bloomfilter |
|
Package buffer
|
Package buffer |
|
Package lru
|
Package lru |
|
Package queue
|
Package queue |
|
Package skiplist
|
Package skiplist |
|
Package tree
|
Package tree |
