Bound the checkpoint after a removed key to a short wait, once per sign-out
Store::truncate_wal ran PRAGMA wal_checkpoint(TRUNCATE) with the connection's busy timeout of five seconds. A checkpoint that truncates holds the writer lock of the log while it waits for readers, so a reader that kept a snapshot made every removed row cost the whole timeout with the store's mutex held, and other writers failed with "database is locked" meanwhile. KeyStore::sign_out removes up to four rows (the synced copies, the device key, the record) and ran the checkpoint after each: 20 s and failing writers in the gate's probe. - truncate_wal now sets a busy timeout of 150 ms (CHECKPOINT_WAIT) around the pragma and restores the timeout the connection had (read back with PRAGMA busy_timeout, so a value set by a caller survives) whatever the checkpoint returned. A blocked checkpoint still leaves the delete standing and warns. - SqliteKeyStore overrides sign_out: the trait's own steps run on a private SignOutPass whose remove deletes the row and notes it, and the sign-out truncates the log once after its last step (also when a step failed, the removals before it have happened). KeyStore::remove on its own still truncates after the row it removed. - The three sentences that said the bytes "stay in the log until the next checkpoint" (keystore.rs, Store::truncate_wal, docs/architecture.md) are corrected: they go when a later checkpoint truncates the log, later writes overwrite those frames, or the last connection closes and the log is deleted. Tests: with a raw connection holding a read snapshot, a sign-out with four removals returns in about 170 ms (it took 20 s) while a writer on another connection with a one-second busy timeout writes throughout without an error (it got "database is locked" nineteen times), and the next removal after the reader is gone truncates the log again; a unit test shows a blocked truncate_wal returns in under a second, leaves the log, and restores a non-default busy timeout, and that the same call truncates once the reader is gone. Both tests fail on the previous code. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
2e026a043c
commit
0ac4095143
4 files changed
+225
-33
No files matched your search
+10
-4
@@ -378,10 +378,16 @@ what it deletes, and deleting a key (`Store::delete_identity`, and the
|
||||
`KeyStore::remove` a sign-out deletes with) is followed by a
|
||||
`PRAGMA wal_checkpoint(TRUNCATE)`, so that the frame of the write-ahead log that
|
||||
held the key's page goes too: neither `client.db` nor `client.db-wal` has the
|
||||
key's text afterwards. If another connection blocks the checkpoint the delete
|
||||
stands, a warning is logged, and the bytes stay in the log until the next
|
||||
checkpoint. Keys deleted before `secure_delete` was on stay in the free pages
|
||||
until the database is vacuumed.
|
||||
key's text afterwards. A sign-out runs the checkpoint once, after its last step,
|
||||
not after each row it removes. The checkpoint waits for another connection for
|
||||
150 ms at most (the connection's own busy timeout is restored after it), because
|
||||
while it waits for a reader it holds the writer lock of the log and every other
|
||||
writer waits with it. If another connection blocks it (one that keeps reading an
|
||||
old snapshot) the delete stands, a warning is logged, and the bytes stay in the
|
||||
log file until a later checkpoint truncates the log, later writes overwrite
|
||||
those frames, or the last connection to the database closes and the log is
|
||||
deleted. Keys deleted before `secure_delete` was on stay in the free pages until
|
||||
the database is vacuumed.
|
||||
|
||||
`voelin-identity` comes from the private VoelinProtocol repository as a git
|
||||
dependency pinned by commit ([building.md](building.md#depending-on-voelinprotocol)).
|
||||
|
||||
Reference in new issue
Block a user