Some checks failed
Go Tests / Run Tests (1.24.2) (push) Has been cancelled
Adds a complete LSM-based storage engine with these features: - Single-writer based architecture for the storage engine - WAL for durability, and hey it's configurable - MemTable with skip list implementation for fast read/writes - SSTable with block-based structure for on-disk level-based storage - Background compaction with tiered strategy - ACID transactions - Good documentation (I hope)
83 lines
2.6 KiB
Go
83 lines
2.6 KiB
Go
package compaction
|
|
|
|
// CompactionStrategy defines the interface for selecting files for compaction
|
|
type CompactionStrategy interface {
|
|
// SelectCompaction selects files for compaction and returns a CompactionTask
|
|
SelectCompaction() (*CompactionTask, error)
|
|
|
|
// CompactRange selects files within a key range for compaction
|
|
CompactRange(minKey, maxKey []byte) error
|
|
|
|
// LoadSSTables reloads SSTable information from disk
|
|
LoadSSTables() error
|
|
|
|
// Close closes any resources held by the strategy
|
|
Close() error
|
|
}
|
|
|
|
// CompactionExecutor defines the interface for executing compaction tasks
|
|
type CompactionExecutor interface {
|
|
// CompactFiles performs the actual compaction of the input files
|
|
CompactFiles(task *CompactionTask) ([]string, error)
|
|
|
|
// DeleteCompactedFiles removes the input files that were successfully compacted
|
|
DeleteCompactedFiles(filePaths []string) error
|
|
}
|
|
|
|
// FileTracker defines the interface for tracking file states during compaction
|
|
type FileTracker interface {
|
|
// MarkFileObsolete marks a file as obsolete (can be deleted)
|
|
MarkFileObsolete(path string)
|
|
|
|
// MarkFilePending marks a file as being used in a compaction
|
|
MarkFilePending(path string)
|
|
|
|
// UnmarkFilePending removes the pending mark from a file
|
|
UnmarkFilePending(path string)
|
|
|
|
// IsFileObsolete checks if a file is marked as obsolete
|
|
IsFileObsolete(path string) bool
|
|
|
|
// IsFilePending checks if a file is marked as pending compaction
|
|
IsFilePending(path string) bool
|
|
|
|
// CleanupObsoleteFiles removes files that are no longer needed
|
|
CleanupObsoleteFiles() error
|
|
}
|
|
|
|
// TombstoneManager defines the interface for tracking and managing tombstones
|
|
type TombstoneManager interface {
|
|
// AddTombstone records a key deletion
|
|
AddTombstone(key []byte)
|
|
|
|
// ForcePreserveTombstone marks a tombstone to be preserved indefinitely
|
|
ForcePreserveTombstone(key []byte)
|
|
|
|
// ShouldKeepTombstone checks if a tombstone should be preserved during compaction
|
|
ShouldKeepTombstone(key []byte) bool
|
|
|
|
// CollectGarbage removes expired tombstone records
|
|
CollectGarbage()
|
|
}
|
|
|
|
// CompactionCoordinator defines the interface for coordinating compaction processes
|
|
type CompactionCoordinator interface {
|
|
// Start begins background compaction
|
|
Start() error
|
|
|
|
// Stop halts background compaction
|
|
Stop() error
|
|
|
|
// TriggerCompaction forces a compaction cycle
|
|
TriggerCompaction() error
|
|
|
|
// CompactRange triggers compaction on a specific key range
|
|
CompactRange(minKey, maxKey []byte) error
|
|
|
|
// TrackTombstone adds a key to the tombstone tracker
|
|
TrackTombstone(key []byte)
|
|
|
|
// GetCompactionStats returns statistics about the compaction state
|
|
GetCompactionStats() map[string]interface{}
|
|
}
|