Repository navigation
Releases
ZephyrDB v0.7.0 — events-focused refresh
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 throughzdb_cfg_t.core_event_listeners. ReportsZDB_CORE_EVENT_INIT,ZDB_CORE_EVENT_DEINITandZDB_CORE_EVENT_HEALTH, the last carryingprev_healthandhealth. Health was previously observable only by pollingzdb_health(). ZDB_TS_EVENT_ROLLOVER— a bounded stream discarding its oldest segments, with the bytes dropped intruncated_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 fitCONFIG_ZDB_KV_INDEX_MAX_ENTRIES. The value stays readable by name; only enumeration is lost.zdb_core_event_chanandzdb_eventing_zbus_publish_core().- Test suites
unit/core_events,unit/doc_eventsandunit/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 reportedZDB_HEALTH_OKno matter how much corruption they met. - Document events never reported failures.
zdb_doc_save(),zdb_doc_delete()andzdb_doc_create()passed a hardcodedZDB_OKand 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 andflushed_bytesdid 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_zbushad nosample.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, andnative_sim.overlayonly matches an unqualified target, sonative_sim/native/64built without the LittleFS partition and every filesystem-backed suite failed. Each suite now ships the qualified name alongside it.
Changed
CONFIG_ZDB_EVENTINGnow depends onZDB_CORErather 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.mdanddocs/configuration.mdrewritten 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
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 getandzdb kv listno longer print ashell_hexdumptable. They
print ahex:line that can be pasted straight back intozdb kv set hex,
plus astr:line when the value is printable.zdb ts appendno 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: valuefor scalars,
[i] key=value …for listing rows, a closingshown:/truncated:summary,
anderror: <op> failed: <STATUS>with an optionalhint:. Commands return
a negative errno matching the status they printed.
Fixes
zdb kv setstoredstrlen()bytes, dropping the NUL terminator that
zdb_kv_set_str()stores and offering no way to write binary at all.
Encoding is now explicit:strkeeps the terminator,rawomits it,hex
decodes bytes.zdb kv getread 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 querynever reportedzdb_ts_agg_result_t.truncated, so an
aggregate capped atCONFIG_ZDB_TS_MAX_AGG_POINTSread as exact.
zdb ts aggreports it.zdb_kv_iter_open()discarded a failed key-index allocation, so a
CONFIG_HEAP_MEM_POOL_SIZEtoo small forCONFIG_ZDB_KV_INDEX_MAX_ENTRIES
madezdb kv listreport an empty namespace instead of a problem. It now
returnsZDB_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()
andzdb_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 inforeports the version, enabled models, active backends,
and the compile-time bounds an operator will hit.zdb stats resetand
zdb stats exportround out the counters. - Key-value —
zdb kv reset(factory reset a namespace) and
zdb kv defaults. - Time-series —
zdb ts readandzdb ts tailwalk samples in either
direction,zdb ts recovertruncates a corrupt tail, and
zdb ts watermark get|set|clearmanages 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, andfind 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 existingzdb_status_str().ZDB_VERSION_MAJOR/_MINOR/_PATCH/_STRING.
Notes
CONFIG_CBPRINTF_FP_SUPPORT=yis required byzdb ts aggand thef64
document commands, which print doubles. Itsdefault y if FPUdoes not fire
on every target.CONFIG_HEAP_MEM_POOL_SIZEmust fit the KV key index, which is sized by
CONFIG_ZDB_KV_INDEX_MAX_ENTRIESandCONFIG_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, andzdb infoare the
substitutes. The Shell Guide explains the reasoning. samples/shell_basicnow enables all three models and seeds a namespace, a
stream, and a document, so every command has something to report.- New
tests/unit/shellsuite drives the whole tree through the dummy shell
backend;tests/unit/shell_fcbis build-only and guards the FCB paths.
v0.5.0
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_strand 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_tat a table andzdb_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/clearrecords 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-zephyronly if you enableCONFIG_ZDB_FLATBUFFERS.
Using it
manifest:
projects:
- name: zephyrdb
url: https://github.com/beriberikix/zephyrdb
path: modules/lib/zephyrdb
revision: v0.5.0See 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_SIZEaccordingly. 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_UNSUPPORTEDor no-op there. LittleFS is the fuller backend. - Nested document fields are reserved, not implemented. The
doc_cbor_nestedsample 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.