Commit Graph
3 Commits
Author SHA1 Message Date
Lauri Ojansivu e191baef7e Recover abandoned History writers online, fenced, without stopping servers.
A legacy History writer holds a token on its board's gate until its write is
confirmed, with no expiry, so an uncertain write can never become invisible to
a chain migration. A writer that died kept its token forever, and the only way
to remove it was the offline tool with every server stopped. Maintainer
decision of 2026-09-30: build online recovery - liveness heartbeats and fencing
on History inserts - and keep the offline tool as the fallback.

Each writer on an upgraded server now writes a lease beside its token
(historyWriterLeases) and renews it while it works. Before every legacy
History insert it claims the row id in the lease; only an active lease can
claim. Recovery takes a lease only after it has been expired for another full
lease period (HISTORY_WRITER_LEASE_MS, default 30 s). It sets the lease to
fenced, so the old writer can neither renew nor claim. A claimed row id is
then fenced by a tombstone under that id, so the unique _id makes a late
insert fail, and a row that had already landed stays. Only then is the token
removed. Safety rests on the fence; clocks only decide when a lease may be
taken, and a slow writer that is taken loses its write with an error.
Tombstones use the reserved board id #history-writer-fence and are invisible
to every board reader. A Sync append refuses a tombstone as its planned row.

A chain migration takes abandoned writers by itself while the board drains,
a full gate does the same once, and releases/recover-history-writer.cjs
--recover-expired does it on demand, online. Tokens without a lease (older
servers) are listed and still need the offline procedure.

MongoDB tests with two clients: a writer that died after claiming a row is
taken and its late insert fails; a fenced slow writer cannot claim; a row
that landed before the fence is kept; live writers and lease-less tokens are
not taken; a migration drains a dead writer and completes on the real chain
head. A full-app test covers the production binding. 563 server tests pass.

Thanks to xet7 !
2026-09-30 11:03:37 +03:00
Lauri Ojansivu 09b51d75a3 Recover uncertain History writer admission with exact offline retirement 2026-09-28 16:50:42 +03:00
Lauri Ojansivu 54a4ef0691 Drain participating History writers before persistent migration ownership 2026-09-28 16:41:28 +03:00