Documentation
¶
Index ¶
Constants ¶
const ( // OneMegabyte represents one mebibyte (1 MiB). OneMegabyte = 1024 * 1024 // OneGigabyte represents one gibibyte (1 GiB). OneGigabyte = 1024 * OneMegabyte // MaxKeyOrValueSize is the maximum allowed size for a key or value. // This acts as a safety bound to prevent excessive memory usage. MaxKeyOrValueSize = 32 * OneMegabyte // DataDirName is the name of the directory where datafiles are stored. DataDirName = "data" // DefaultDirectoryPath is the default base path for Bitcask storage. DefaultDirectoryPath = "./" // DataFilePrefix is the prefix used for datafile names. DataFilePrefix = "bk_" // MergedFilePrefix is the prefix used for temporary merged datafiles // created during compaction. MergedFilePrefix = "merged_" // DataFileExt is the file extension for datafiles. DataFileExt = ".data" // HintFileExt is the file extension for hint files. HintFileExt = ".hint" // DatafileZeroName is the name of the initial datafile. DatafileZeroName = "bk_0.data" // DefaultDataFileSizeMB is the default maximum size of a datafile in megabytes. DefaultDataFileSizeMB = 64 // MinimumDataFileSizeMB is the minimum allowed datafile size in megabytes. MinimumDataFileSizeMB = 64 // MaximumDataFileSizeMB is the maximum allowed datafile size in megabytes. MaximumDataFileSizeMB = 256 // DefaultSyncInterval is the default interval (in seconds) for fsync operations. DefaultSyncInterval = 15 // MinimumSyncInterval is the minimum allowed sync interval in seconds. MinimumSyncInterval = 5 // DefaultSizeCheckInterval is the default interval (in seconds) for checking // active datafile size and triggering rotation. DefaultSizeCheckInterval = 5 // MinimumSizeCheckInterval is the minimum allowed size check interval in seconds. MinimumSizeCheckInterval = 5 // DefaultGarbageRatio is the default minimum garbage ratio required // for a datafile to be eligible for compaction. DefaultGarbageRatio = 0.4 // MinGarbageRatio is the lower bound for garbage ratio configuration. MinGarbageRatio = 0.33 // MaxGarbageRatio is the upper bound for garbage ratio configuration. MaxGarbageRatio = 0.75 // DefaultMinRequiredMergableFiles is the default minimum number of // immutable files required to trigger a merge. DefaultMinRequiredMergableFiles = 3 // MinRequiredMergableFiles is the minimum allowed value for merge eligibility. MinRequiredMergableFiles = 2 // DefaultMinTotalSizeForMergeMB is the default minimum total size (in MB) // of immutable datafiles required to trigger a merge. DefaultMinTotalSizeForMergeMB = 256 // MinTotalSizeForMergeMB is the minimum allowed merge size threshold (in MB). MinTotalSizeForMergeMB = 128 // DefaultMaxMergeFiles is the default maximum number of files that may // participate in a single merge operation. DefaultMaxMergeFiles = 5 // DefaultMaxMergeBytesGB is the default maximum number of bytes (in GB) // that may be processed in a single merge operation. DefaultMaxMergeBytesGB = 2 )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Bitcask ¶
type Bitcask struct {
DirectoryPath string
MaximumDatafileSize int64
ListenerPort int
SyncInterval uint
SizeCheckInterval uint
GarbageRatio float64
MinRequiredMergableFiles int
MinTotalSizeForMerge int64
MaxMergeFiles int
MaxMergeBytes int64
// contains filtered or unexported fields
}
func (*Bitcask) Start ¶
Start initializes the Bitcask instance and begins serving requests.
It performs the following steps:
- Acquires an exclusive lock on the data directory
- Creates the data directory if it does not exist
- Rebuilds the KeyDir from hint files and/or datafiles
- Opens or creates the active datafile
- Starts the TCP server
- Launches background goroutines for syncing, rotation, and compaction
Start returns an error if initialization fails. On success, the instance runs until Stop is called.
type KeyDir ¶
type KeyDir map[string]KeyDirEntry
KeyDir is the in-memory index mapping keys to their latest on-disk entries.
It is the primary structure used to service read requests efficiently without scanning datafiles.
type KeyDirEntry ¶
type KeyDirEntry struct {
FileName string // Datafile name containing the record
Offset uint32 // Byte offset in the datafile where the record starts
ValueSize uint32 // Size of the value in bytes
RecordSize uint32 // Total size of the record on disk (header + key + value)
Timestamp int64 // Timestamp of the record
}
KeyDirEntry represents the in-memory index entry for a single key.
Each entry points to the latest known version of a key stored on disk. Older versions may still exist in immutable datafiles but are ignored based on the Timestamp.
The KeyDir is rebuilt on startup by scanning datafiles or reading hint files.