Repository navigation
feat(replication): an old leader rejoins as a follower, and the High availability guide - #827
MathiasVDA wants to merge 3 commits into
Conversation
Under --failover, a member that serves a dataset without the lease and finds another member holding it at a higher epoch follows that member (decision record 0012, decision 6). It goes on from its own data when the new leader was promoted where its log ends, and copies a new base otherwise, so nothing it wrote past the promotion is kept. It stays a follower when it starts again with the same command line. Refs #781
A cluster of three with Docker Compose and one etcd, what happens when the leader goes away and comes back, what a write answers when the cluster cannot keep it safe, and stale reads with TripleTrail-Min-Version. docs/server.md describes how an old leader rejoins. Closes #781
|
The Generated by Claude Code |
|
Changes requested at a2e4fb1. The design follows decision record 0012 (decision 6), the two new tests pass here, and the guide chapter reads well. One must-fix, on the moment of the rejoin itself. Must fix: the old leader can take a write while it rejoins, and then follows from its own data with that write in it.
Reproduced with a scratch test on top of What I expect: no write can commit on the dataset after the position is read. For example, keep the fence (the unheld lease, or the read-only mode set first) until the dataset is attached read-only, and read the log position only once running writes are done (under the store's write exclusion). Please add a test that writes during the rejoin and compares the member with the leader. Also needed before merge: merge main, Small, not blocking: when the old leader checkpointed at shutdown and the replica had already read the new (empty) generation before it was promoted, the positions differ ( Generated by Claude Code |
Requested by Mathias · project thread
What and why
Closes #781, phase 4 of automatic failover (#14, decision record 0012, decision 6).
Before this change, an old leader that came back after a failover served its dataset fenced (writes
503) and never followed the new leader. Now, a--failovermember that serves a dataset without the lease and sees another member holding it at a higher epoch rejoins as a follower:replication::rejoinremoves the (unheld) lease and writes aNAME.replicaposition from the member's own data: its timeline and the end of its log. A log just started by the shutdown checkpoint counts as the end of the log before it. The member then follows the cluster, holder first, reusing the engine it already serves.HISTORYhas a promotion from exactly that position, the member reads on without a new base.--failover,servefollows a--datasetthat has a non-promotedNAME.replica(rejoined_replicas) instead of serving it.failover::election::round) callsrejoinwhen the lease holder is another node at a higher epoch.Clustergetsfollow_wait(--follow-wait) for that follower. A member that cannot follow from its own data (a dataset attached from outside--location) stays fenced and logs why once.How it was tested
tests/failover.rs, all with the in-memory lease, and also against etcd whenTRIPLETRAIL_TEST_ETCDis set:an_old_leader_that_comes_back_follows_the_new_one: a leader is stopped,borcis elected, andarestarts as it was started.afollows from its own data (norail.r1), gets the new leader's writes, counts for--sync-replicas, refuses writes (405), and stays a follower. A second restart, asservedoes it, follows again.an_old_leader_drops_what_it_wrote_past_the_promotion:aholds a write no replica got (answered503).bandccome back and elect one of them, andarestarts. It copies a new base and does not have that write.cargo test -p tripletrail-server --test failover --test replicationpasses. The failover tests passed on all 6 local runs since the tests took their final form.GUIDE_CHAPTER=14 cargo test -p tripletrail-server --test guidepasses. I checked that a wrong expected output fails it.cargo fmt, andcargo clippy --all-targets --all-features -D warningson tripletrail-server.Documentation
test: file);TripleTrail-Min-Version(tested).docs/server.md"Automatic failover": a new bullet on how an old leader rejoins, and the "Not yet" note is gone.Generated by Claude Code