Repository navigation
shard: replica announcements and limits on cross-location waits - #203
Draft
stevephodgson wants to merge 9 commits into
Draft
stevephodgson wants to merge 9 commits into
stevephodgson wants to merge 9 commits into
Conversation
Extract replica address tracking from ShardSharedinto a new ReplicaTracker class. The state management is a little bit different to the old code but behaviorally there are no significant differences here. Add tests for registry updates and the published snapshots.
At the moment, shards find their peers only through the registry. We would like to reduce the time taken for the cluster to observe and respond to partitions, but the overloaded registry is an impediment. This commit introduces new shard replica messages containing identity, location, leadership and address information, signed with the shard key. This will allow one shard shard replica to announce itself to the existing shad replicas immediatley rather than waiting for one full registry poll.
If the new shard flag -replica-announcements is set, then each replica sends an announcement every 100ms to the replicas it knows of at it's last location. Replicas configured to lead also send to the replicas they know of at other locations. The tracker keeps each peer's registry record and last announcement separately. An announcement is used for one minute after we receive it, with its receipt time as the peer's last-seen time. After that the registry record is used, with an unusable registry address filled in from the last announcement. Changes are compared against the last published snapshot, so an expiry that has not been published yet is not missed. At most one leader is published per remote location. Fresh announcements win over registry records, and within a source the most recent wins.
Unless it runs with -no-replication, a replica that has not been initiated will not finish starting until the registry has addresses for all five replicas at its location. On an initial start it also asks the registry to hold the fetch until all five are known. One missing replica holds up the others. With replica announcements enabled, drop both requirements. A replica still has to register itself, fetch whatever the registry knows, and find its own address there. A replica that registers later is found through announcements: it gets our address from the registry and announces itself to us. Enable announcements in ternrun and terntests. terntests now starts each shard's followers before its leader. A follower's first fetch can then run before the leader has registered, in which case the follower learns about the leader from the leader's announcements.
eggsfs_shard_staleness_lag and the LogsDB reader and follower lag metrics already show how far behind a replica is. They do not show the log index visible to reads, or the backlog relative to the release point the writer knows of. On a secondary that release point can be ahead of what has been released in its local log. Add eggsfs_shard_progress with the last applied index, taken from the snapshot that reads use, the highest release point the writer knows of, and the backlog between them. A follower at a secondary location reports the release point it learnt from its own leader, not the primary's. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
The primary leader holds some CDC responses, for the steps of mkdir and rename and for strongly consistent reads, until the leader at each other location confirms it has applied the entry. No metric shows which locations these waits are for, how long they take, or how long responses are held; only debug logs mention them. A secondary that keeps registering but has stopped applying entries still looks live, and the responses it holds do not show up in metrics. Add eggsfs_shard_cross_location_wait, tagged by target location. It counts waits started, skipped because the location looked down, dropped mid-wait and confirmed, with the total time to confirmation, the number outstanding and the age of the oldest. Add eggsfs_shard_cross_location_held with the number of responses delayed and the total time they were held. The wait policy is unchanged. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
A wait for a location ends when it confirms, when it drops out of the published leaders, or when the staleness check finds it has not been seen for -region-staleness-threshold (10 minutes by default). A secondary that is still published and keeps registering but has stopped applying entries meets none of these, so each CDC response that waits on it is held indefinitely. Add -region-wait-timeout, default 15s. Once a wait has run that long, stop waiting for the locations that have not confirmed, send the response and count those waits as timed_out. This does not depend on replica announcements. Zero disables the timeout. CDC can now proceed without confirmation that every location has the change. Read gating on the secondary is separate and unchanged, so it can still serve an older namespace, including a mkdir or cross-shard rename that has only partly replicated there. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Registrations and announcements both carry on while a secondary's apply loop is stuck, so neither tells the primary whether the secondary is keeping up. Add the last applied index visible to reads, and the time the primary created that entry, to each announcement. The tracker publishes this progress for the selected leader at each remote location, but only while the published address is the one that announced it. Progress is kept when announcements stop, along with when we last heard one, even if the registry reports newer registrations. A registration cannot tell lost announcements apart from a restart at the same address with announcements off, so that restart also looks silent. Add eggsfs_shard_cross_location_view with the age of each leader's last announcement and its reported apply lag, which is receipt time minus entry creation time. Lag is only meaningful on the primary, where both times come from the same clock. Nothing uses this progress for wait decisions yet. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
The staleness check already skips locations that are missing or look down. A secondary that still looks live is waited for, and if it is not applying entries, each response waiting on it is held for the full 15s timeout. Announced progress lets the primary avoid starting those waits. Before starting a new wait, look at the location leader's last announced progress. Skip the wait if nothing has been heard for 5s (-region-silence-threshold), or if the last announcement showed 15s or more of apply lag (-region-lag-threshold). Lag catches a secondary whose announcer runs but whose apply loop has stalled. The primary's idle heartbeat entries keep a healthy idle secondary's lag low; with -heartbeat-emission-interval 0 it would look behind. Both checks need announcements, each is disabled by zero, and neither affects waits already running. A location with no announced progress for its current address is still waited for, under the timeout. A leader that restarts at the same address with announcements off keeps its old progress and is skipped as silent. Skipped waits are counted as silent or lagging. Like a timeout, a skip lets CDC proceed without confirmation that the secondary has the change. Set the wait, silence and lag limits to zero to turn these early releases off. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Background
The shard leader at the primary location holds some CDC responses (mkdir and rename steps, and strongly consistent reads) until the leader at each secondary location confirms it has applied the entry. Shards learn about those leaders from the registry. In steady state they register with it and poll it every two to four minutes. A location is skipped once it has not been seen for
-region-staleness-threshold(10 minutes by default). This leads to several problems.Approach
With
-replica-announcements, replicas send each other signed announcements every 100ms. An announcement carries leadership, addresses, and the last applied index with its entry time. It is used for one minute after receipt, and then the registry record is used again. At most one leader is published per remote location. With announcements on, a replica starts once it has registered itself and fetched what the registry knows. It finds later replicas through their announcements.Three new limits release CDC responses early:
-region-wait-timeout(15s) ends a wait that has run that long, with or without announcements.-region-silence-threshold(5s) skips new waits for a leader not heard from for that long.-region-lag-threshold(15s) skips new waits for a leader whose last announcement showed that much apply lag.The last two need announcements. Setting all three to 0 turns the early releases off; the staleness check still applies. New metrics cover progress, waits, held responses, and each remote leader's announcement age and lag.
Implications
The cost of hitting one of these thresholds is that we trade off consistency for IO latency. When CDC completes after a skipped or timed-out wait, that location may not have applied the change.