Skip to content

v0.5.0

Choose a tag to compare

@beriberikix beriberikix released this 02 Aug 20:40
· 9 commits to main since this release

First tagged release of ZephyrDB, an embedded multi-model database for Zephyr RTOS built for memory-constrained targets. Three storage models share one instance, one lock, and one set of statically sized buffers.

Key-value

Namespaced records on NVS or ZMS. Records carry their namespace and key on storage, so a read verifies what it found rather than trusting an ID, and a hash collision between two different keys is reported instead of silently overwriting.

  • Byte and string APIs — zdb_kv_set / zdb_kv_set_str and their getters. The string form stores the terminator and always returns a terminated result, so truncation cannot hand back an unterminated buffer.
  • Defaults table — point zdb_cfg_t at a table and zdb_init() writes any key that is absent. On first boot that seeds everything; after a firmware update that adds entries it writes only the new ones, leaving values the device changed alone. One rule covers both.
  • Iteration across reboots — the key index is mirrored into a reserved backend record, so zdb_kv_iter_* enumerates keys written by previous runs, not just this session.
  • Factory reset — zdb_kv_reset_namespace() clears a namespace and re-applies its defaults.

Time-series

Append-only streams on LittleFS or FCB, buffered in RAM and flushed on a work queue.

  • Cursors over an inclusive time window, forward or reverse (zdb_ts_cursor_open / _open_desc), with an optional predicate.
  • Aggregates — MIN, MAX, AVG, SUM, COUNT. Counting a whole stream reads no payloads, deriving the total from stored sizes; the value-bearing aggregates report when a scan hit its configured cap rather than passing off a partial answer.
  • Consumed watermark — zdb_ts_watermark_set/get/clear records how far a consumer processed, so an uploader resumes instead of replaying. A watermark that fails its integrity check reads as unset, which makes a restart re-process rather than skip.
  • Bounded streams (CONFIG_ZDB_TS_ROLLOVER) — keep a recent window instead of filling the partition, discarding the oldest segment whole.
  • Compact records (CONFIG_ZDB_TS_DELTA_ENCODING) — 16 bytes instead of 28, about 1.75x the samples per byte. Records stay fixed size and independently decodable, so reverse cursors and the payload-free count still work.
  • Several streams open at once (CONFIG_ZDB_TS_MAX_STREAMS), each with its own ingest buffer.
  • Corrupt trailing records are detected and truncated on open, with counters exported through the stats API.

Documents

Typed fields — integer, double, string, bool, bytes — with AND-combined equality queries, stored on a filesystem.

  • Atomic saves. A document is staged and renamed into place, so an interrupted write leaves the previous version intact rather than a truncated file. The stored CRC covers the header and every field payload, so corruption is reported on open instead of returned as valid-looking values.
  • An interrupted save is recovered on the next open.
  • FlatBuffers export for sending a document off-device.

Across all models

Bounded, statically sized allocation on the core and time-series paths, with build-time assertions that the configured slab blocks actually fit the contexts they hold. Optional mutation events with a zbus adapter, runtime statistics, and a zdb shell command tree.

Requirements

  • Zephyr v4.4.1 or compatible — the first release family shipping <zephyr/kvss/zms.h>.
  • flatcc-zephyr only if you enable CONFIG_ZDB_FLATBUFFERS.

Using it

manifest:
  projects:
    - name: zephyrdb
      url: https://github.com/beriberikix/zephyrdb
      path: modules/lib/zephyrdb
      revision: v0.5.0

See zephyrdb-example for a working application, the samples directory for ten focused ones, and the documentation.

Verification

148 test cases across 10 suites plus 3 samples run in CI on native_sim, with a cross-compile gate for nRF52840 DK. Suites cover both backend choices for key-value and the optional configurations for time-series, including the ones that are off by default.

Known limitations

Worth reading before adopting:

  • Concurrency is coarse. One mutex per instance, held for the duration of each operation, so operations on one instance serialize. Separate instances are independent.
  • Heap use in two places. The key index and the entire document model allocate from the kernel heap; size CONFIG_HEAP_MEM_POOL_SIZE accordingly. The core and time-series paths do not.
  • Iteration is bounded by CONFIG_ZDB_KV_INDEX_MAX_ENTRIES (default 128). Keys past that bound remain readable but are not enumerable — and so are not cleared by a namespace reset.
  • Document queries scan every collection. There is no index and no collection filter; each candidate is fully deserialized.
  • The FCB time-series backend is reduced. Aggregates, reverse cursors, watermarks, and recovery report ZDB_ERR_UNSUPPORTED or no-op there. LittleFS is the fuller backend.
  • Nested document fields are reserved, not implemented. The doc_cbor_nested sample shows the interim pattern.
  • Power-loss behaviour is only simulated in CI. Restart handling is exercised with deinit/init cycles against a mounted backend; a real power cut is covered only by the hardware suite, which CI builds but does not run.

Planned and declined enhancements are tracked as issues.

Stability

0.x — the API may change between minor releases. On-disk formats are versioned and readers accept older ones, so stored data survives an upgrade.