This project is based on the key/value storage engine designed by basho's bitcask paper.
- Step 1: Load the files in the data directory and open their file descriptors.
- Step 2: Traverse the contents of the data file to construct an in-memory index.
- All keys are stored in memory; all values are stored on disk.
- Bitcask model contains only one read/write(active) file and multiple read-only(inactive) files.
- Merge operation
Key: key | Value: ValuePos {Fid, Offset, Size}
We used B Tree and Adaptive Radix Tree as our memory index in this project because these two data structures support efficient insertion, reading, and deletion of data.
One datafile contains multiple records. We separate our single encoded record into two parts: Header and Real Data.
crc | type | keySize | valueSize | key | value |
---|---|---|---|---|---|
uint32 | RecordType | uint32 | uint32 | []byte | []byte |
4 bytes | 1 bytes | variable-length field (max 5 bytes) | variable-length field (max 5 bytes) | variable-length field | variable-length field |
Standard File I/O, MMAP I/O