|
cwist
Modern C web framework with libttak runtime
|
In-memory SQLite mirroring layer that can fall back to disk under memory pressure. More...
#include <stdatomic.h>#include <cwist/core/db/nuke_db.h>#include <cwist/core/macros.h>#include <cwist/core/mem/alloc.h>#include <cwist/sys/sys_info.h>#include <sqlite3.h>#include <stdio.h>#include <stdlib.h>#include <string.h>#include <unistd.h>#include <signal.h>#include <pthread.h>#include <sys/stat.h>#include <sys/mman.h>#include <sys/types.h>#include <sys/time.h>#include <errno.h>#include <fcntl.h>
Go to the source code of this file.
Macros | |
| #define | _POSIX_C_SOURCE 200809L |
| #define | _DEFAULT_SOURCE |
| #define | NSIG 32 |
Functions | |
| int | cwist_nuke_sync (void) |
| Persist the current in-memory database back to disk or checkpoint WAL mode. | |
| void | cwist_nuke_close (void) |
| Stop the sync thread, flush state, and tear down the global NUKE context. | |
| int | cwist_nuke_init (const char *disk_path, int sync_interval_ms) |
| Initialize the global NUKE database mirror around one disk database. | |
| sqlite3 * | cwist_nuke_get_db (void) |
| Return the SQLite handle that callers should use for the NUKE database. | |
| void | cwist_nuke_signal_handler (int signum) |
| Placeholder signal handler (no-op). | |
| unsigned char * | cwist_nuke_serialize (sqlite3_int64 *out_size) |
| Serialize the current NUKE database contents into a buffer. | |
| int | cwist_nuke_deserialize (unsigned char *data, sqlite3_int64 data_len) |
| Replace the in-memory NUKE database with serialized contents. | |
In-memory SQLite mirroring layer that can fall back to disk under memory pressure.
Definition in file nuke_db.c.
Stop the sync thread, flush state, and tear down the global NUKE context.
Close databases safely. Performs a final synchronization before closing handles.
Definition at line 293 of file nuke_db.c.
References cwist_nuke_sync().
Referenced by cwist_app_destroy(), cwist_app_use_nuke_db(), and cwist_nuke_init().
| int cwist_nuke_deserialize | ( | unsigned char * | data, |
| sqlite3_int64 | data_len | ||
| ) |
Replace the in-memory NUKE database with serialized contents.
Load a raw SQLite byte buffer into the in-memory database.
| data | Serialized database buffer; ownership transfers to SQLite, which frees it on close (SQLITE_DESERIALIZE_FREEONCLOSE). |
| data_len | Length of data in bytes. |
Definition at line 520 of file nuke_db.c.
References cwist_nuke_db_t::is_disk_mode, and cwist_nuke_db_t::mem_db.
Return the SQLite handle that callers should use for the NUKE database.
Get the raw SQLite3 handle for the In-Memory DB.
Definition at line 478 of file nuke_db.c.
References cwist_nuke_db_t::disk_db, cwist_nuke_db_t::is_disk_mode, and cwist_nuke_db_t::mem_db.
Referenced by cwist_app_get_db(), and cwist_app_use_nuke_db().
Initialize the global NUKE database mirror around one disk database.
Initialize Nuke DB.
| disk_path | Path to the on-disk SQLite database. |
| sync_interval_ms | Background sync interval in milliseconds. |
Definition at line 377 of file nuke_db.c.
References cwist_nuke_db_t::auto_sync, cwist_get_available_ram(), cwist_nuke_close(), CWIST_NUKE_ERR_GENERIC, CWIST_NUKE_ERR_LOW_MEMORY, CWIST_NUKE_OK, cwist_strdup(), cwist_nuke_db_t::disk_db, cwist_nuke_db_t::disk_path, cwist_nuke_db_t::is_disk_mode, cwist_nuke_db_t::load_successful, cwist_nuke_db_t::mem_db, and cwist_nuke_db_t::sync_interval_ms.
Referenced by cwist_app_use_nuke_db().
| unsigned char * cwist_nuke_serialize | ( | sqlite3_int64 * | out_size | ) |
Serialize the current NUKE database contents into a buffer.
Serialize the in-memory database to a raw byte buffer.
| out_size | Receives the serialized byte count. |
Definition at line 497 of file nuke_db.c.
References cwist_nuke_db_t::disk_db, cwist_nuke_db_t::is_disk_mode, and cwist_nuke_db_t::mem_db.
Placeholder signal handler (no-op).
Internal signal handler. Typically set up by cwist_nuke_init.
| signum | Signal number; unused. |
Definition at line 487 of file nuke_db.c.
References CWIST_UNUSED.
Persist the current in-memory database back to disk or checkpoint WAL mode.
Force synchronization from Memory to Disk.
Definition at line 228 of file nuke_db.c.
References cwist_nuke_db_t::disk_db, cwist_nuke_db_t::is_disk_mode, cwist_nuke_db_t::load_successful, and cwist_nuke_db_t::mem_db.
Referenced by cwist_nuke_close().