1
0
mirror of https://github.com/nxshock/zkv.git synced 2024-11-27 11:21:02 +05:00
Go to file
2022-12-03 12:41:11 +05:00
.gitattributes Initial commit 2022-02-16 16:08:20 +05:00
.gitignore Initial commit 2022-02-16 16:08:20 +05:00
defaults.go Add option for limit a number of parallel reads 2022-12-03 12:40:36 +05:00
errors.go New version 2022-12-02 20:32:09 +05:00
go.mod New version 2022-12-02 20:32:09 +05:00
go.sum New version 2022-12-02 20:32:09 +05:00
LICENSE Initial commit 2022-02-16 16:08:20 +05:00
options.go Add option for limit a number of parallel reads 2022-12-03 12:40:36 +05:00
README.md Add some notes 2022-12-03 12:41:11 +05:00
record.go Make constant key length 2022-12-02 21:37:34 +05:00
utils.go Make constant key length 2022-12-02 21:37:34 +05:00
zkv_test.go New version 2022-12-02 20:32:09 +05:00
zkv.go Add option for limit a number of parallel reads 2022-12-03 12:40:36 +05:00

zkv

Simple key-value store for single-user applications.

Pros

  • Simple one file structure
  • Internal Zstandard compression by klauspost/compress/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
  • No way to recover disk space from deleted records
  • Write/Delete operations block Read and each other operations

Usage

Create or open existing file:

db, err := Open("path to file")

Data operations:

// Write data
err = db.Set(key, value) // key and value can be any of type

// Read data
var value ValueType
err = db.Get(key)

// Delete data
err = db.Delete(key)

File structure

Record is encoding/gob structure:

Field Description Size
Type Record type uint8
KeyHash Key hash 28 bytes
ValueBytes Value gob-encoded bytes variable

File is log stuctured list of commands:

Field Description Size
Length Record body bytes length int64
Body Gob-encoded record variable