Fix grant ledger ownership and truncated-record recovery

This commit is contained in:
dingo
2026-10-02 06:24:56 -04:00
parent c588be237c
commit 7ac587743c
6 changed files with 180 additions and 9 deletions
+10 -1
View File
@@ -63,7 +63,16 @@ changes need a new version.
ledger (`--session-grant-ledger`; `/objects/dev-session-grants.v1` in dev, outside the
object namespaces and ignored by backups) and fsynced **before** Welcome; a failed
write refuses the session and keeps the grant consumed in memory. A replacement
process loads unexpired entries into admission at startup. Corrupt content, I/O
process loads unexpired entries into admission at startup. Before any read or rewrite,
an opener obtains a nonblocking exclusive OS lock on a stable sibling `.lock` file
(POSIX flock / Windows share-denied handle), held until the append handle closes.
A competing opener fails before mutation, including failed duplicate server starts.
The lock file is never removed during normal operation: replacing it could split
ownership. OS process exit releases the lock; no stale-lock deletion is needed.
Records must end with LF and contain at most 37 bytes before it. Incomplete tails
and oversized records are rejected before compaction, leaving ledger bytes intact.
The text format has no checksum: syntactically valid corruption or removal of entire
records is not detected; this is not a tamper-evident ledger. Corrupt content, I/O
failure or more than 65536 entries fail closed. The ledger does not survive a
restore-to-bundle (a rewind) or a lost volume; grants expire within an hour.