|
ZephyrDB
Embedded database for Zephyr RTOS: KV, time-series, and document models
|
Instance lifecycle, status codes, health, telemetry, and the cursor framework. More...
Classes | |
| struct | zdb_bytes_t |
| Immutable byte span (pointer + length). More... | |
| struct | zdb_ts_stats_t |
| Time-series durability counters (see zdb_ts_stats_get()). More... | |
| struct | zdb_ts_stats_export_t |
| Compact, packed telemetry export of zdb_ts_stats_t for transport or logging. More... | |
| struct | zdb_kv_default_t |
| One entry in a key-value defaults table. More... | |
| struct | zdb_cfg_t |
| Instance configuration passed to zdb_init(). More... | |
| struct | zdb_t |
| Database instance. More... | |
| struct | zdb_cursor |
| Cursor for cooperative scans (currently opened via zdb_ts_cursor_open()). More... | |
Macros | |
| #define | ZDB_DEFINE_STATIC(db_name, cfg_name) |
| Declare a static zdb_t wired to Kconfig-sized slabs. | |
Typedefs | |
| typedef bool(* | zdb_predicate_fn) (zdb_model_t model, const zdb_bytes_t *record, void *user_ctx) |
| Record filter callback for cursor scans. | |
| typedef struct zdb_cursor | zdb_cursor_t |
| Cursor for cooperative scans (currently opened via zdb_ts_cursor_open()). | |
Enumerations | |
| enum | zdb_status_t { ZDB_OK = 0 , ZDB_ERR_INVAL , ZDB_ERR_NOMEM , ZDB_ERR_NOT_FOUND , ZDB_ERR_IO , ZDB_ERR_BUSY , ZDB_ERR_TIMEOUT , ZDB_ERR_UNSUPPORTED , ZDB_ERR_CORRUPT , ZDB_ERR_INTERNAL , ZDB_ERR_COLLISION } |
| Status codes returned by every ZephyrDB API. More... | |
| enum | zdb_model_t { ZDB_MODEL_CORE = 0 , ZDB_MODEL_KV , ZDB_MODEL_TS } |
| Data-model selector used by cursors and predicates. More... | |
| enum | zdb_backend_t { ZDB_BACKEND_NONE = 0 , ZDB_BACKEND_NVS , ZDB_BACKEND_ZMS , ZDB_BACKEND_LFS , ZDB_BACKEND_FCB } |
| Storage backend identifiers. More... | |
| enum | zdb_health_t { ZDB_HEALTH_OK = 0 , ZDB_HEALTH_DEGRADED , ZDB_HEALTH_READONLY , ZDB_HEALTH_FAULT } |
| Instance health as reported by zdb_health(). More... | |
Functions | |
| zdb_status_t | zdb_init (zdb_t *db, const zdb_cfg_t *cfg) |
| Initialize a database instance. | |
| zdb_status_t | zdb_deinit (zdb_t *db) |
| Tear down an instance and release all module state. | |
| zdb_health_t | zdb_health (const zdb_t *db) |
| Report the instance's current health. | |
| const char * | zdb_status_str (zdb_status_t status) |
| Return a short printable name for a status code. | |
| const char * | zdb_health_str (zdb_health_t health) |
| Return a short printable name for a health value. | |
| void | zdb_ts_stats_get (const zdb_t *db, zdb_ts_stats_t *out_stats) |
| Copy the live time-series durability counters. | |
| void | zdb_ts_stats_reset (zdb_t *db) |
| Reset the time-series durability counters to zero. | |
| zdb_status_t | zdb_ts_stats_export (const zdb_t *db, zdb_ts_stats_export_t *out_export) |
| Fill a packed, CRC-protected telemetry export of the TS stats. | |
| zdb_status_t | zdb_ts_stats_export_validate (const zdb_ts_stats_export_t *export_data) |
| Validate a received telemetry export record. | |
| zdb_status_t | zdb_cursor_reset (zdb_cursor_t *cursor) |
| Rewind a cursor to the start of its scan. | |
| zdb_status_t | zdb_cursor_close (zdb_cursor_t *cursor) |
| Close a cursor and release its slab allocation. | |
| void | zdb_shell_register (zdb_t *db) |
Bind an instance to the zdb shell command tree (CONFIG_ZDB_SHELL). | |
Instance lifecycle, status codes, health, telemetry, and the cursor framework.
| #define ZDB_DEFINE_STATIC | ( | db_name, | |
| cfg_name ) |
Declare a static zdb_t wired to Kconfig-sized slabs.
Declares the core and cursor slabs plus the KV I/O and TS ingest slabs for whichever of those modules are enabled, and a static zdb_t db_name pointing at them. Call zdb_init(&db_name, &cfg) before first use.
| db_name | Name of the zdb_t variable to declare. |
| cfg_name | Configuration name; currently unused by the macro — pass the same zdb_cfg_t to zdb_init(). |
| typedef struct zdb_cursor zdb_cursor_t |
Cursor for cooperative scans (currently opened via zdb_ts_cursor_open()).
Treat the members as internal; drive the cursor with zdb_cursor_next(), zdb_cursor_reset(), and zdb_cursor_close().
| typedef bool(* zdb_predicate_fn) (zdb_model_t model, const zdb_bytes_t *record, void *user_ctx) |
Record filter callback for cursor scans.
| model | Data model the record belongs to. |
| record | Raw record bytes (valid only during the call). |
| user_ctx | Opaque pointer supplied at cursor open. |
| enum zdb_backend_t |
| enum zdb_health_t |
Instance health as reported by zdb_health().
Health is derived from time-series integrity checks: a stream whose records fail framing or CRC validation, or which cannot be recovered, moves the instance to ZDB_HEALTH_DEGRADED. A build without CONFIG_ZDB_TS therefore stays ZDB_HEALTH_OK for its lifetime.
Health only ever worsens. Nothing restores an instance to ZDB_HEALTH_OK, because the faults it records are evidence that data was already lost or rewritten; re-run zdb_init() for a fresh verdict. Each change is reported once as a ZDB_CORE_EVENT_HEALTH event.
| Enumerator | |
|---|---|
| ZDB_HEALTH_OK | Fully operational. |
| ZDB_HEALTH_DEGRADED | Operational with recovered/ignored faults. |
| ZDB_HEALTH_READONLY | Writes disabled. |
| ZDB_HEALTH_FAULT | Not operational. |
| enum zdb_model_t |
| enum zdb_status_t |
Status codes returned by every ZephyrDB API.
| Enumerator | |
|---|---|
| ZDB_OK | Success. |
| ZDB_ERR_INVAL | Invalid argument (NULL pointer, bad length, ...). |
| ZDB_ERR_NOMEM | Out of slab memory, or payload exceeds a slab block. |
| ZDB_ERR_NOT_FOUND | Requested record/key/document does not exist. |
| ZDB_ERR_IO | Backend storage read/write failure. |
| ZDB_ERR_BUSY | Resource is held (e.g. another TS stream is active). |
| ZDB_ERR_TIMEOUT | Timed out waiting (e.g. zdb_ts_flush_sync()). |
| ZDB_ERR_UNSUPPORTED | Operation not supported by the active backend/build. |
| ZDB_ERR_CORRUPT | Stored data failed integrity checks (CRC, framing). |
| ZDB_ERR_INTERNAL | Unexpected internal state. |
| ZDB_ERR_COLLISION | KV record-ID hash collision with a different key (see zdb_kv_set()). |
| zdb_status_t zdb_cursor_close | ( | zdb_cursor_t * | cursor | ) |
Close a cursor and release its slab allocation.
| cursor | Open cursor; safe to call once per open. |
| ZDB_OK | Success. |
| ZDB_ERR_INVAL | cursor is NULL or not open. |
| zdb_status_t zdb_cursor_reset | ( | zdb_cursor_t * | cursor | ) |
Rewind a cursor to the start of its scan.
| cursor | Open cursor. |
| ZDB_OK | Success. |
| ZDB_ERR_INVAL | cursor is NULL or not open. |
| zdb_status_t zdb_deinit | ( | zdb_t * | db | ) |
Tear down an instance and release all module state.
Closes any active TS stream and frees internal contexts back to the slabs. The instance may be re-initialized with zdb_init() afterwards.
| db | Initialized instance. |
| ZDB_OK | Success. |
| ZDB_ERR_INVAL | db is NULL or not initialized. |
| zdb_health_t zdb_health | ( | const zdb_t * | db | ) |
Report the instance's current health.
| db | Initialized instance. |
db is NULL or uninitialized. | const char * zdb_health_str | ( | zdb_health_t | health | ) |
Return a short printable name for a health value.
| health | Any zdb_health_t value. |
| zdb_status_t zdb_init | ( | zdb_t * | db, |
| const zdb_cfg_t * | cfg ) |
Initialize a database instance.
Binds cfg (kept by reference — it must outlive the instance), validates the slab wiring for the enabled modules, and readies the instance for module opens.
| db | Instance declared via ZDB_DEFINE_STATIC() or manually wired. |
| cfg | Configuration; see zdb_cfg_t for backend requirements. |
| ZDB_OK | Success. |
| ZDB_ERR_INVAL | db or cfg is NULL, or a required slab is missing. |
| void zdb_shell_register | ( | zdb_t * | db | ) |
Bind an instance to the zdb shell command tree (CONFIG_ZDB_SHELL).
Registers db as the target of every zdb command. Call it after zdb_init(); until then the commands report that no instance is registered. One instance at a time; a later call replaces the binding, and passing NULL unbinds.
See docs/shell.md for the command reference.
| db | Initialized instance, or NULL to unbind. |
| const char * zdb_status_str | ( | zdb_status_t | status | ) |
Return a short printable name for a status code.
| status | Any zdb_status_t value. |
| zdb_status_t zdb_ts_stats_export | ( | const zdb_t * | db, |
| zdb_ts_stats_export_t * | out_export ) |
Fill a packed, CRC-protected telemetry export of the TS stats.
The CRC covers every byte of the record except the crc field itself, so any tampering or transport corruption is detected by zdb_ts_stats_export_validate().
| db | Initialized instance. |
| out_export | Destination record. |
| ZDB_OK | Success. |
| ZDB_ERR_INVAL | db or out_export is NULL. |
| zdb_status_t zdb_ts_stats_export_validate | ( | const zdb_ts_stats_export_t * | export_data | ) |
Validate a received telemetry export record.
| export_data | Record to check. |
| ZDB_OK | CRC and version are valid. |
| ZDB_ERR_INVAL | export_data is NULL. |
| ZDB_ERR_CORRUPT | CRC mismatch. |
| ZDB_ERR_UNSUPPORTED | Unknown format version. |
| void zdb_ts_stats_get | ( | const zdb_t * | db, |
| zdb_ts_stats_t * | out_stats ) |
Copy the live time-series durability counters.
| db | Initialized instance. |
| out_stats | Destination; zeroed when db is NULL/uninitialized. |
| void zdb_ts_stats_reset | ( | zdb_t * | db | ) |
Reset the time-series durability counters to zero.
| db | Initialized instance (NULL is ignored). |