Skip to content

Releases

ZephyrDB v0.7.0 — events-focused refresh

Choose a tag to compare

@beriberikix beriberikix released this 03 Aug 21:37
19b628f

Eventing grew from key-value only to cover every model, but the documentation and the tests did not follow, and a year of new features shipped emitting nothing. This release makes what ZephyrDB reports match what it does, puts the whole surface under CI, and reports the state changes that were happening silently.

README.md still described eventing as key-value only — and it is the Doxygen mainpage, so that text was the published API site's definition of the feature.

Added

  • Instance events. A fourth listener category, zdb_core_event_listener_t / zdb_core_event_t, registered through zdb_cfg_t.core_event_listeners. Reports ZDB_CORE_EVENT_INIT, ZDB_CORE_EVENT_DEINIT and ZDB_CORE_EVENT_HEALTH, the last carrying prev_health and health. Health was previously observable only by polling zdb_health().
  • ZDB_TS_EVENT_ROLLOVER — a bounded stream discarding its oldest segments, with the bytes dropped in truncated_bytes. This is the only place ZephyrDB destroys data on purpose, and it used to do so silently.
  • ZDB_TS_EVENT_WATERMARK — a consumed watermark set or cleared.
  • ZDB_EVENT_KV_INDEX_FULL — a key that stored successfully but did not fit CONFIG_ZDB_KV_INDEX_MAX_ENTRIES. The value stays readable by name; only enumeration is lost.
  • zdb_core_event_chan and zdb_eventing_zbus_publish_core().
  • Test suites unit/core_events, unit/doc_events and unit/eventing_zbus — the zbus adapter had no automated coverage of any kind before this.

Fixed

  • Health could never degrade with CONFIG_ZDB_STATS=n. zdb_health_check() decided from durability counters that compile away when statistics are off, so such builds reported ZDB_HEALTH_OK no matter how much corruption they met.
  • Document events never reported failures. zdb_doc_save(), zdb_doc_delete() and zdb_doc_create() passed a hardcoded ZDB_OK and returned before the emit on every error path.
  • Time-series recovery never reported failures. Ten early returns in zdb_ts_recover_stream() emitted nothing.
  • Flush events undercounted. Only the periodic work-queue drain emitted, so flushes caused by zdb_ts_close() or by a full ingest buffer during append were invisible and flushed_bytes did not reflect what reached storage.
  • zdb_deinit() could crash after an append. The time-series context was freed without settling a queued flush, leaving the work queue to run a handler in memory that had since been reused.
  • samples/eventing_zbus had no sample.yaml, so Twister never built it — the reason this drift went unnoticed. It now builds in CI, mounts LittleFS so its time-series and document paths actually run, and fails rather than silently skipping them.
  • The documented arm64 test workflow was broken. Zephyr matches boards/<board-target>.overlay, and native_sim.overlay only matches an unqualified target, so native_sim/native/64 built without the LittleFS partition and every filesystem-backed suite failed. Each suite now ships the qualified name alongside it.

Changed

  • CONFIG_ZDB_EVENTING now depends on ZDB_CORE rather than requiring a data model, since instance events are model-independent.
  • Event callbacks are documented as never running while an internal lock is held, so a listener may call back into the same instance. Flush, rollover and health events detected inside locked sections are published on release.
  • Health is documented as one-way and derived from time-series integrity checks.
  • README, docs/api.md and docs/configuration.md rewritten around the four categories.

Upgrading

Existing listeners will observe behaviour changes: document events and time-series recovery now deliver failure statuses they previously never sent, and flush events fire from more paths. A listener that assumed status was always ZDB_OK should be reviewed.

Requires Zephyr v4.4.1. 0.x: the API may change between minor releases; on-disk formats are versioned and readers accept older ones.

Full changelog: https://github.com/beriberikix/zephyrdb/blob/v0.7.0/CHANGELOG.md

ZephyrDB v0.6.0

Choose a tag to compare

@beriberikix beriberikix released this 03 Aug 03:21
a0f852a

ZephyrDB v0.6.0 reworks the zdb shell command tree. The previous tree reached
10 of the library's 57 public functions; this one covers everything that has a
sensible console form — 36 commands across all three models — and fixes several
ways the old commands mishandled data.

See the new Shell Guide
for the full reference.

Breaking changes

The command surface was redesigned for consistency. Existing invocations need
updating:

Before Now
zdb kv set <ns> <key> <value> zdb kv set str|hex|raw <ns> <key> <value>
zdb ts query <stream> <agg> … zdb ts agg <stream> <agg> …
zdb ts flush <stream> zdb ts flush sync <stream> [timeout_ms]
zdb stats zdb stats show
zdb doc open <coll> <id> zdb doc get <coll> <id> [field]

Also changed:

  • zdb kv get and zdb kv list no longer print a shell_hexdump table. They
    print a hex: line that can be pasted straight back into zdb kv set hex,
    plus a str: line when the value is printable.
  • zdb ts append no longer forces a flush. Closing a stream already persists
    buffered samples, so the old hardcoded two-second timeout only added a way
    to fail.
  • Command output follows one format throughout: name: value for scalars,
    [i] key=value … for listing rows, a closing shown:/truncated: summary,
    and error: <op> failed: <STATUS> with an optional hint:. Commands return
    a negative errno matching the status they printed.

Fixes

  • zdb kv set stored strlen() bytes, dropping the NUL terminator that
    zdb_kv_set_str() stores and offering no way to write binary at all.
    Encoding is now explicit: str keeps the terminator, raw omits it, hex
    decodes bytes.
  • zdb kv get read into a fixed 256-byte buffer and truncated silently. The
    buffer is now sized to one KV I/O slab block, which bounds any storable
    record, so it cannot truncate.
  • zdb ts query never reported zdb_ts_agg_result_t.truncated, so an
    aggregate capped at CONFIG_ZDB_TS_MAX_AGG_POINTS read as exact.
    zdb ts agg reports it.
  • zdb_kv_iter_open() discarded a failed key-index allocation, so a
    CONFIG_HEAP_MEM_POOL_SIZE too small for CONFIG_ZDB_KV_INDEX_MAX_ENTRIES
    made zdb kv list report an empty namespace instead of a problem. It now
    returns ZDB_ERR_NOMEM.
  • The FCB time-series backend did not compile at all. zdb_cursor_next()
    referenced undeclared locals in its FCB branch, zdb_ts_flush_work_handler()
    and zdb_ts_append_i64() left locals and a label unused, and three static
    helpers exist only for scans FCB does not perform. Nothing in the repository
    built FCB, so none of it had ever been caught.

New commands

  • Core — zdb info reports the version, enabled models, active backends,
    and the compile-time bounds an operator will hit. zdb stats reset and
    zdb stats export round out the counters.
  • Key-value — zdb kv reset (factory reset a namespace) and
    zdb kv defaults.
  • Time-series — zdb ts read and zdb ts tail walk samples in either
    direction, zdb ts recover truncates a corrupt tail, and
    zdb ts watermark get|set|clear manages the consumer watermark.
  • Documents — the model is now usable from a console at all:
    zdb doc create, delete, get (whole document or one field),
    list, set i64|f64|str|bool|bytes, and find i64|f64|str|bool.

API additions

All additive; no existing signature changed.

  • zdb_ts_cursor_next_sample(cursor, out_sample) — the decoded form of
    zdb_cursor_next(). Raw cursor records carry a build-dependent layout with
    part of the timestamp in the segment header, so they were not portably
    decodable by a caller.
  • zdb_health_str(health) — the companion to the existing zdb_status_str().
  • ZDB_VERSION_MAJOR / _MINOR / _PATCH / _STRING.

Notes

  • CONFIG_CBPRINTF_FP_SUPPORT=y is required by zdb ts agg and the f64
    document commands, which print doubles. Its default y if FPU does not fire
    on every target.
  • CONFIG_HEAP_MEM_POOL_SIZE must fit the KV key index, which is sized by
    CONFIG_ZDB_KV_INDEX_MAX_ENTRIES and CONFIG_ZDB_MAX_KEY_LEN.
  • Tab completion cannot offer namespace, stream, or collection names — there
    is no API to enumerate them, and a filesystem scan inside line editing would
    stall the console. zdb kv list, zdb doc list, and zdb info are the
    substitutes. The Shell Guide explains the reasoning.
  • samples/shell_basic now enables all three models and seeds a namespace, a
    stream, and a document, so every command has something to report.
  • New tests/unit/shell suite drives the whole tree through the dummy shell
    backend; tests/unit/shell_fcb is build-only and guards the FCB paths.

v0.5.0

Choose a tag to compare

@beriberikix beriberikix released this 02 Aug 20:40

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.