From d950b6546c1fba17c5ee980e4235f3d424b7ac98 Mon Sep 17 00:00:00 2001 From: nxshock Date: Sun, 11 Dec 2022 21:33:51 +0500 Subject: [PATCH] Add notes about current store state --- README.md | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 5ed2b58..4474fec 100644 --- a/README.md +++ b/README.md @@ -4,17 +4,17 @@ Simple key-value store for single-user applications. ## Pros -* Simple one file structure +* Simple two file structure (data file and index file) * Internal Zstandard compression by [klauspost/compress/zstd](https://github.com/klauspost/compress/tree/master/zstd) * Threadsafe operations through `sync.RWMutex` ## Cons * Index stored in memory (`map[key hash (28 bytes)]file offset (int64)`) -* Need to read the whole file on store open to create file index (you can use index file options to avoid this) +* No transaction system +* Index file is fully rewrited on every store commit * No way to recover disk space from deleted records * Write/Delete operations block Read and each other operations -* Need to decode whole file until stored value ## Usage @@ -63,9 +63,6 @@ type Options struct { // Disk write buffer size in bytes DiskBufferSize int - - // Use index file - UseIndexFile bool } ``` @@ -87,6 +84,17 @@ File is log stuctured list of commands: | Length | Record body bytes length | int64 | | Body | Gob-encoded record | variable | +Index file is simple gob-encoded map: + +```go +map[string]struct { + BlockOffset int64 + RecordOffset int64 +} +``` + +where map key is data key hash and value - data offset in data file. + ## Resource consumption Store requirements: @@ -97,4 +105,4 @@ Store requirements: ## TODO - [ ] Add recovery previous state of store file on write error -- [ ] Add fast file seek to value (add compressed block start position) +- [ ] Add method for index rebuild