Documentation
¶
Index ¶
- Constants
- type Checkpoint
- type CheckpointData
- type CompactionManager
- type CompactionStats
- type Engine
- type FileData
- type LSMTree
- type LevelData
- type Manifest
- func (m *Manifest) GetCurrentWAL() string
- func (m *Manifest) GetLastCheckpoint() int64
- func (m *Manifest) GetLevelFiles(level int) ([]FileData, error)
- func (m *Manifest) Save() error
- func (m *Manifest) UpdateCurrentWAL(walFile string) error
- func (m *Manifest) UpdateLastCheckpoint(timestamp int64) error
- func (m *Manifest) UpdateLevel(level int, files []FileData) error
- type ManifestData
- type MmapBlock
- type MmapFile
- type Stats
- type WAL
- type WALEntry
Constants ¶
const ( OpTypePut byte = 1 OpTypeDelete byte = 2 )
WAL operation types
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Checkpoint ¶
type Checkpoint struct {
// contains filtered or unexported fields
}
Checkpoint represents a snapshot of the memory table
func NewCheckpoint ¶
func NewCheckpoint(baseDir string) (*Checkpoint, error)
NewCheckpoint creates a new checkpoint manager
func (*Checkpoint) GetLastWALTimestamp ¶
func (c *Checkpoint) GetLastWALTimestamp() int64
GetLastWALTimestamp returns the last WAL timestamp included in the checkpoint
type CheckpointData ¶
type CheckpointData struct {
// Timestamp when the checkpoint was created
Timestamp int64 `json:"timestamp"`
// Last WAL entry timestamp included in this checkpoint
LastWALTimestamp int64 `json:"last_wal_timestamp"`
// Memory table data
MemTable map[string][]byte `json:"mem_table"`
// Memory table size
MemTableSize int64 `json:"mem_table_size"`
}
CheckpointData represents the data stored in a checkpoint file
type CompactionManager ¶
type CompactionManager struct {
// contains filtered or unexported fields
}
CompactionManager handles background compaction of LSM tree levels
func NewCompactionManager ¶
func NewCompactionManager(tree *LSMTree, dataDir string, numWorkers int) *CompactionManager
NewCompactionManager creates a new compaction manager
func (*CompactionManager) GetStats ¶
func (c *CompactionManager) GetStats() CompactionStats
GetStats returns the current compaction statistics
func (*CompactionManager) RunCompaction ¶
func (c *CompactionManager) RunCompaction() error
RunCompaction runs a compaction cycle
func (*CompactionManager) ScheduleCompaction ¶
func (c *CompactionManager) ScheduleCompaction(sourceLevel, targetLevel int, blocks []blockInfo)
ScheduleCompaction schedules a compaction task
func (*CompactionManager) Start ¶
func (c *CompactionManager) Start()
Start starts the compaction workers
func (*CompactionManager) Stop ¶
func (c *CompactionManager) Stop()
Stop stops the compaction workers
type CompactionStats ¶
type CompactionStats struct {
// Number of compactions performed
CompactionCount int
// Number of blocks compacted
BlocksCompacted int
// Number of bytes read
BytesRead int64
// Number of bytes written
BytesWritten int64
// Total compaction time
TotalTime time.Duration
// CPU usage percentage (0-100)
CPUUsagePercent float64
// Number of compaction tasks in queue
TasksInQueue int
// Number of compaction tasks dropped due to queue full
TasksDropped int
// Last compaction timestamp
LastCompactionTime time.Time
// Compaction throughput (bytes/second)
CompactionThroughput float64
}
CompactionStats tracks statistics about compaction operations
type Engine ¶
type Engine struct {
// contains filtered or unexported fields
}
Engine is the main storage engine that integrates LSM tree, WAL, and compaction
func (*Engine) RunCompaction ¶
RunCompaction manually triggers a compaction cycle
type FileData ¶
type FileData struct {
// File path
Path string `json:"path"`
// File size
Size int64 `json:"size"`
// Timestamp when the file was created
Timestamp int64 `json:"timestamp"`
// Min key in the file
MinKey string `json:"min_key"`
// Max key in the file
MaxKey string `json:"max_key"`
// Number of entries in the file
EntryCount int `json:"entry_count"`
}
FileData represents data about a file in the LSM tree
type LSMTree ¶
type LSMTree struct {
// contains filtered or unexported fields
}
LSMTree implements a Log-Structured Merge Tree for efficient storage with level-triggered compaction.
func NewLSMTree ¶
NewLSMTree creates a new LSM tree with the given data directory
func (*LSMTree) StartCompactionWorker ¶
func (t *LSMTree) StartCompactionWorker()
StartCompactionWorker starts a background goroutine for compaction
type LevelData ¶
type LevelData struct {
// Level number
Level int `json:"level"`
// Files in this level
Files []FileData `json:"files"`
}
LevelData represents data about a level in the LSM tree
type Manifest ¶
type Manifest struct {
// contains filtered or unexported fields
}
Manifest represents the state of the LSM tree
func NewManifest ¶
NewManifest creates a new manifest
func (*Manifest) GetCurrentWAL ¶
GetCurrentWAL returns the current WAL file
func (*Manifest) GetLastCheckpoint ¶
GetLastCheckpoint returns the last checkpoint timestamp
func (*Manifest) GetLevelFiles ¶
GetLevelFiles returns the files in a level
func (*Manifest) UpdateCurrentWAL ¶
UpdateCurrentWAL updates the current WAL file
func (*Manifest) UpdateLastCheckpoint ¶
UpdateLastCheckpoint updates the last checkpoint timestamp
type ManifestData ¶
type ManifestData struct {
// Timestamp when the manifest was created
Timestamp int64 `json:"timestamp"`
// LSM tree levels
Levels []LevelData `json:"levels"`
// Current WAL file
CurrentWAL string `json:"current_wal"`
// Last checkpoint timestamp
LastCheckpoint int64 `json:"last_checkpoint"`
}
ManifestData represents the data stored in a manifest file
type MmapBlock ¶
type MmapBlock struct {
// contains filtered or unexported fields
}
MmapBlock represents a memory-mapped block file with index
func NewMmapBlock ¶
NewMmapBlock creates a new memory-mapped block
type MmapFile ¶
type MmapFile struct {
// contains filtered or unexported fields
}
MmapFile represents a memory-mapped file for zero-copy reads
func NewMmapFile ¶
NewMmapFile creates a new memory-mapped file
func (*MmapFile) Data ¶
Data returns the entire memory-mapped data as a byte slice This is a zero-copy operation
type Stats ¶
type Stats struct {
// Memory table size
MemTableSize int64
// Number of keys in memory table
MemTableKeys int
// Compaction statistics
CompactionStats CompactionStats
// LSM tree level sizes
LevelSizes [7]int64
// LSM tree level block counts
LevelBlocks [7]int
}
Stats returns statistics about the storage engine
type WAL ¶
type WAL struct {
// contains filtered or unexported fields
}
WAL (Write-Ahead Log) provides durability guarantees by logging operations before they are applied to the main data structure.
func (*WAL) AppendDelete ¶
AppendDelete appends a DELETE operation to the WAL