akv is an in-memory key-value store backed by a single flat file.
Currently in development, not production ready
- Concurrent Key-Value Store Library in a single file
- Usage Example
- Multithreaded Server Example
- Implement OS-level file locking (
flock/LockFileEx) to prevent multi-process data corruption. - Implement atomic file replacement via an interim temporary file swap to protect against crash corruption.
- Initialization: When
make_storeis called, the library parses the.dbfile and populates an internal Odin map. Keys and values are percent-encoded on disk to cleanly handle delimiters (:and;). - Runtime Operations: All runtime reads, writes, and deletions interact with the in-memory map. Concurrency is managed via an internal
sync.Mutex, making operations fully thread-safe. - Memory Ownership: Because Odin lacks garbage collection, string management is explicit.
readreturns a clone of the value that the caller must free. - Persistence: Changes are only persisted to disk when you explicitly call
sync().
Initializes the store from a file path. Note: This should only be called once on your main thread during initialization.
Thread-safe read. Returns a cloned copy of the value string. The caller is responsible for freeing this string.
Thread-safe insert or update. Returns an error if the key already exists.
Thread-safe deletion of a key and its value from the store.
Flushes the in-memory map back to disk.