Tech News
← Back to articles

Filedb: Disk-based key-value store inspired by Bitcask

read original related products more articles

filedb

A key-value store inspired by Bitcask.

FileDB is a Zig-implementation of Bitcask by Riak1 paper.

FileDB stores record metadata in a log-structured hashtable and parallely keeps 1 disk file open for inserting records in append-only mode. On restarts or MAX_FILE_REACHED , the disk file is rotated and all the oldfiles are kept open for reading only .

, the disk file is rotated and all the oldfiles are kept open for reading . A compaction process running every config.compactionInterval seconds, reads all the disk files and combines them into one file while updating the metadata hashtable.

seconds, reads all the disk files and combines them into one file while updating the metadata hashtable. A sync process syncs the open disk files once every config.syncInterval . Sync also can be done on every request if config.alwaysFsync is True.

Read about internals in-depth at FileDb.

Since the metadata keeps an exact location of file and position in file for a record, fetching records become O(1) operation. All metadata records are constant size, so irrespective of the size of the value of a record the in-memory store keeps a constant sized metadata. Provides high throughput by using the open file in append only mode.

Methods

init(allocator: std.mem.Allocator, options: ?config.Options) : Intialized FileDB deinit() : Deinitalizes FileDB put(key:[]const u8, value: []const u8) : Inserts a key-value pair in the database to be tracked. get(key:[]const u8) : Retrieved a key-value pair from the database. delete(key: []const u8) : Delete a key-value pair from the database list(allocator: std.mem.Allocator) : Returns a list of keys stored in the database. sync() : Syncs the current open datafile on the disk storeHashMap() : Creates the HINTS file loadKeyDir() : Loads the hashmap from the HINTS file

... continue reading