Store: the message database on Crafter.DB
One table without an ordered column: Crafter.DB enforces the order on every write, and a List() import after a restart can carry an older stamp than the last row, so a conversation is sorted on read. A row carries the plan it was written under, the SIM's country code and its operator, a column each. Messages are looked up by imsd id (unique across imsd's runs by its run token: an id names one message, and an empty one — a text imsd has not answered yet — none); read marks and deletes go per message and per conversation; every write but a Compact is caught at this one boundary — a store that refuses one (Crafter.DB's IOError: the disk full, the file system read-only) answers nullopt from Add, false or a count of 0 (a row appended before its Flush failed is tombstoned; an in-place write whose Flush failed stays in the row as the process reads it; SetState's state and imsd's id land in place even when a reason cannot — the id is inline in the row, 64 bytes as imsd bounds it, one past that refused rather than thrown), and tells its onWriteState listener once of the refusal and once of the next write that got room, which is one that grew a file: Crafter.DB allocates its extents, so a write that fit the ones it had (an in-place one, a short row) is no recovery. So a refused write ends no caller's process and the app's banner can say so. A lock file beside the table, held for the store's life, makes a second store on the same directory throw LockedError (the table's own lock sits on an inode a Compact replaces); it is built on Crafter.DB's File and Os — the directory made 0700 at every component, the file 0600 and never a symlink, a lock that fails for any reason but another holder an IOError, not a LockedError. Every change a call answers as made — a row id, true, a count — is committed before the call returns, so a row Add returned is on disk. The file's format is held by the build: static_asserts on the row's size and layout fingerprint (Crafter.DB's Layout) and on the stored values of Direction and MessageState, so a column changed without a version bump fails the build and not a user's open, and an enumerator moved fails it where an open would misread the stored states without a word. Tested: tests/Store in a temp directory: the round trip, the sort of a later-appended older message, the updates, the lookup by imsd id and an erased row's, an id past imsd's bound refused, the lock from a second open, persistence across a reopen, Compact, a row kept by a child process that ends without a flush, the private file modes, and a write refused under the file-size limit (told once with its reason, the rows before it standing, an in-place write going through and telling nothing, a state landing without its refused reason and imsd's id beside it, the next Add after the limit's lifting telling of the recovery once), and a Flush failing after its Append (the descriptor pointed at /dev/null for the one write) tombstoning the row Add refused.
This commit is contained in:
parent
724cd409ba
commit
9707c9fa26
3 changed files with 544 additions and 0 deletions
|
|
@ -137,6 +137,7 @@ extern "C" Configuration CrafterBuildProject(std::span<const std::string_view> a
|
|||
cfg.AddTest("Time").Dependencies({ Core.get() });
|
||||
cfg.AddTest("Wrap").Dependencies({ Core.get() });
|
||||
cfg.AddTest("Model").Dependencies({ Core.get() });
|
||||
cfg.AddTest("Store").Dependencies({ Core.get(), db });
|
||||
|
||||
LintRules::AddRules(cfg);
|
||||
return cfg;
|
||||
|
|
|
|||
Loading…
Reference in a new issue