Repository navigation
Re-route staged cluster monitor lines when the slot map changes - #885
fcostaoliveira wants to merge 28 commits into
Conversation
In cluster --monitor-input mode a monitor line is routed once, when it is staged on its owner primary's queue, and is counted as generated then. Since #799 lines are also staged on a primary while it refreshes CLUSTER SLOTS or redials. A refresh committed before the queue drains could leave the lines on the wrong connection: - the slot moved: the lines went to the old owner and got -MOVED, and handle_moved() then cleared and uncounted the rest of the queue (#835); - the owner was retired: the commit loop cleared and uncounted its queue (#836); - the owner was demoted: the lines drained on a replica connection, or, if it was redialing, the replica reset cleared them (#836). The replay cursor had already moved past cleared lines, so they were never sent, and later selections wrapped and repeated earlier lines. Totals Count stayed exact, so nothing reported it. On a scripted 3-node peer replaying 20 SET lines, master missed up to 8 and duplicated up to 4 per run, and sent up to 8 to a node that did not own their slot. Each staged line now keeps its slot, and committing a map moves every line to the slot's current primary, as hand_off_replay_requests() does for held replays. A slot's lines are on one queue and move together, so each slot keeps its selection order. They stay counted. An unowned slot keeps its lines on a primary that is still one, or goes to the fallback primary. Only a line whose new primary was given up on, or whose queue is full, is dropped and uncounted, as before. handle_moved() and the demoted-replica redial keep the queue for that re-route; a redial to a different endpoint still clears it. The work happens only at commit time, so the drain path and non-monitor runs do not change. test_cluster_unowned_slots.py adds a scripted primary/replica/spare fixture that moves a slot, retires the primary or demotes it (with and without -MOVED, after a silent change, while redialing, and with an unowned slot), at pipeline 1 and 4. It checks that every file line is sent exactly once, to its slot's owner, in order, with Totals Count 40 and exit 0. The queue-ownership unit test now expects demotion and promotion to keep staged monitor lines. Fixes #835 Fixes #836 Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
🤖 Automated first-pass review — a human maintainer's review is still required before merge. Thanks for this. It's a big one, but the description and commit messages make it easy to follow, and the scripted failover fixtures plus the fails-on-master unit blocks are what I'd want for a change to accounting and routing. A few questions:
Nitpicking: The core re-route looks right to me, and the per-slot ordering argument holds. I'd like the different-endpoint question answered before this merges, and since this is cluster-routing territory, a second look from whoever owns cluster topology handling would be good. (would file this as a comment, not a formal block) |
reroute_staged_monitor_commands() kept a staged line for an unowned slot on its connection if that connection's role was primary. A node the new map lists as a replica while its reconnect timer is pending is not relabeled (set_shard_role() runs only when it is redialed), so it still looked like a primary. Its unowned lines stayed on it until the timer fired and the next refresh moved them, after lines selected later had been sent, so the slot's selection order was lost. Decide "primary" from the committed map's shard groups instead of the connection's role. A retired connection is not in the map, so the retired vector is no longer needed. A line the re-route drops, because its new primary was given up on or its queue is full, is now logged to --failed-keys-file, warned about once per commit and counted as an error, as hand_off_replay_requests() does for replays. Before, it was only uncounted. The README says that lines already sent are resent only with --retry-on-error, and that each slot keeps its selection order. test_cluster_unowned_slots.py adds a demote-hole case where A closes instead of answering the refresh and R's CLUSTERDOWN commits the map while A's reconnect timer is pending. Before this change, lines 4 and 6 were sent after line 19. The unit test calls the re-route with a given-up primary and checks that the line is dropped and uncounted. Co-Authored-By: Claude Opus 5.5 <[email protected]>
The warning for staged monitor lines the re-route drops said "that no primary can send", which is wrong when the primary is up and only its queue is full. It now names both reasons. The --failed-keys-file record for such a line used the command label MONITOR, while the same line failing after it is sent is logged as ARBITRARY. It now uses ARBITRARY too, so one monitor line has one label. The unit test for a line whose new primary was given up on now also checks that the drop counts as an error and is logged to --failed-keys-file with its key and reason. Co-Authored-By: Claude Opus 5.5 <[email protected]>
The README and the re-route comments said every slot keeps its selection order. That holds for a slot that had an owner whenever its lines were staged: they are all on one queue and move together. Lines staged while the slot had no owner went to fallback_primary_conn_id(), which can change between selections, so once the slot has an owner they merge in connection order. The text now says so. Behaviour is unchanged. reroute_staged_monitor_commands() now asserts that a staged line has a slot. Only keyed lines are staged, and a keyless UINT_MAX slot would be dropped as slot-owner-down-for-monitor-line, so a later change to the staging condition would fail loudly instead. In test_cluster_unowned_slots.py, _Node defines the ping_reply and set_reply hooks that _Failover overrides, instead of the handler probing for them. Co-Authored-By: Claude Opus 5.5 <[email protected]>
The pending=True case held R's third PING after A's refresh, closed A after a 0.3 s sleep and answered that PING with CLUSTERDOWN 1.3 s after A's first SET. Under CPU load it failed about 1 run in 10 on its node.held check. If A's CLUSTERDOWN reached memtier late, R had already filled the in-flight budget with lines staged on A. It stalled with nothing outstanding on R, sent no PING after the refresh, and the map was committed only by A's reconnect timer. Delaying A's first SET reply by 0.5 s reproduced it 5 times in 9. Before the refresh, R's PINGs are now answered only once A has received the lines selected before them, so R cannot stall. After the refresh, R holds the first PING behind which an unowned line is staged on A. Because the client alternates PING and monitor line, that is any line selected before the PING that no node has received. A closes its refresh once that PING is held, and the PING gets CLUSTERDOWN one second after A's SLOTS request arrived. That request bounds memtier's last CLUSTERDOWN poll, so the reply is always acted on. The 0.3 s sleep and the 1.3 s guess are gone, and node.held is still asserted. Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
Thanks for the careful read. Answers in order, with lines at c5889c3; the follow-ups are 2e850ed (wording, assert, nit) and 3376ad7 (fixture). Queue-full drop on reroute. You're right that the cap isn't needed here. Order for slots that used to be unowned. Correct, and it wasn't covered. Lines staged while the slot had no owner went to Re-processing moved lines. It's intended, and it's safe because the target rule is idempotent. An owned line resolves to Keyless sentinel. Agreed. Only keyed lines are staged: Fixture timing. Good call; it wasn't solid. In CI on c5889c3 the case passed in all 6 cells that run the file, ASAN, TSAN and UBSan included, on the first attempt. Locally, under load (one CPU, two busy loops, nice 19), it failed 1 run in 10 on its Nit. Done in 2e850ed: Release notes. Agreed. 🤖 Generated with Claude Code |
reroute_staged_monitor_commands() checked for a given-up primary (disconnected with no reconnect timer) only when a line moved. A line whose slot's primary is the connection it is already on stayed there. Nothing sends from that connection or uncounts the line, so a --requests run would never finish. The commit redials such a primary before the re-route, so this needs that redial to fail at once and the connection to be left dead. The check now runs for every line. An unowned line on a given-up primary no longer stays: it moves to another primary, as from any connection that is not a primary of the map. The unit test checks both cases: the owned line is dropped, uncounted and counted as an error, and the unowned line moves to the primary that is still dialing. stage_unsent() now sets the slot of the line it stages (the slot the second shard owns) instead of leaving it 0. The pending=True fixture comment names the C++ CLUSTERDOWN throttle (m_last_clusterdown_refresh, 1000000 us, in handle_response()) that its one-second wait depends on. Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
Thanks for the second pass. Line numbers are at 08fab58, which follows 3376ad7. Malformed or stale refresh. The churn is bounded, and it is the same as on master. target == i on a given-up primary. Mostly pre-existing, but worth closing. A committed map that lists a disconnected primary with no timer redials it before the re-route runs (1196-1207). So this needs that redial to fail at once and the connection to be left dead: Release note. Agreed. The PR body now has a line about drops counting as errors. Throttle comment. Done. The wait comment names
Checks on 08fab58: make check 18/18, the whole test file 28/28, the pending case 5/5 under load, and clang-format clean. 🤖 Generated with Claude Code |
handle_moved() no longer flushes a connection's staged monitor lines: they wait for a committed map to move them. A connection that runs out of reconnect attempts usually ends its thread, and the run then abandons what is left and fails. Under --read-preference other than primary, with a peer still in setup, attempt_reconnect() and the reconnect timer instead leave the connection dead and the thread goes on. Its staged lines stayed counted with nothing to send them, so a --requests run waited on them until some other commit came. Master flushed the lines staged before the -MOVED, but kept those staged after it. Both branches now call handle_connection_given_up(). cluster_client runs the re-route there: lines of the dead primary's own slots are dropped, uncounted, logged and counted as errors, and the rest move to their slot's primary. The unit test gives up a primary with a staged line while a peer is still dialing, and checks that the line is dropped and uncounted and counts as an error. On 08fab58 the line stayed counted. Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
Thanks. Line numbers are at 4d6f516, which follows 08fab58. -MOVED, then given up. In the usual case nothing hangs, and it's the same as master. A connection that runs out of reconnect attempts calls The other cases' Exit code. A re-route drop doesn't change it. main() returns 2 for a connection-stage abort, 1 if a worker thread ended early or output or verification failed, and 0 otherwise (memtier_benchmark.cpp:6780-6792). The error count isn't consulted. Suggested release note: "With Checks on 4d6f516: make check 18/18, the whole test file 28/28, and clang-format clean. 🤖 Generated with Claude Code |
reroute_staged_monitor_commands() sent an unowned line on a primary that is not kept to fallback_primary_conn_id(), and dropped it if that primary was given up on. While the seed is refreshing CLUSTER SLOTS, fallback_primary_conn_id() also counts a primary that is disconnected with no reconnect timer, because the refresh may redial it. So a given-up primary listed first won over a later one that was dialing or reconnect-pending, and the line was dropped instead of moved (Cursor Bugbot). The re-route now picks its own fallback once per call: the first connected primary of the map, else the first one that is not given up on. A line is dropped only if there is none. fallback_primary_conn_id() and its other callers are unchanged. The unit test gives up the first of two primaries while the second dials and the seed refreshes SLOTS, and checks that the unowned line moves to the second. It failed on 4d6f516. Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
Thanks for the careful pass. Line numbers are at f87277c.
Re-entrancy. It's safe. Shared drop helper. Feasible. The accounting is already shared through Error counts. Agreed. The exit code doesn't change (memtier_benchmark.cpp:6780-6792), and it's in the release notes. Fixture and throttle. Fair point. If the throttle grew, the case would most likely still pass, just exercise less, so the risk is lost coverage rather than a confusing failure. Stderr can't help, because memtier logs nothing when it throttles a CLUSTERDOWN. The clean option is a fixture-side assert, with no wall clock involved: R's CLUSTER SLOTS (the commit) must arrive before A's second connection, with a message naming the throttle. It's about five lines, and I can add it here or in a follow-up. Suite time: the file runs in 6 CI cells and adds 0.4-0.85 min per cell. Under the sanitizers the 19 cases take about 48 s, and the existing tests and the OSS-CLUSTER jobs are unchanged.
🤖 Generated with Claude Code |
reroute_staged_monitor_commands() uncounts the lines it drops, which lowers m_reqs_generated below --requests again, but it scheduled a fill only on connections that received a moved line. After a drop-only pass, whether at a commit or from the give-up hook, a producer that had paused at the --requests cap in hold_pipeline() had no reply left to wake it, and a primary given up on wakes no peer. When any line is dropped, schedule a fill on every connection that is not disconnected, as the commit does after retiring a connection. The unit test parks a connected producer at the cap, drops a line on the given-up primary through each entry point, and checks that the producer's deferred fill is armed. It failed on f87277c (Cursor Bugbot). Co-Authored-By: Claude Opus 5.5 <[email protected]>
The comment above the deferred-fill forward declaration had lost its first half, and the harness comment still said the test never runs the event loop, which finish_dial() now does. Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
Thanks. Most of this was answered in the earlier replies, so here is the short version with pointers. Rejected refresh after
Release notes. Yes. The PR body's release-notes line says drops now count as errors and are written to Give-up hook re-entrancy. Agreed, and two independent reviews checked it. The re-route only swaps and pushes queues, logs, adjusts counters and arms deferred fills; it never re-enters reconnect logic or holds a queue reference across a send. Details are in the round-8 reply.
A fixture-side assert that names the throttle if it ever changes is in the follow-up list. 🤖 Generated with Claude Code |
handle_cluster_slots() dials the nodes of a reply before it commits the reply's map. A dial that fails at once (connect_shard_connection() -> attempt_reconnect()) can leave a primary dead under --read-preference other than primary, and the give-up hook then re-routed its staged monitor lines by the map about to be replaced. A line whose slot the reply moves to a live primary was dropped as slot-owner-down-for-monitor-line, and the commit could not bring it back (Cursor Bugbot). The hook now does nothing while handle_cluster_slots() walks the reply. The flag is set before the node loop and cleared before the every-shard-malformed return and before the commit, whose own re-route then runs in the same call. Every shard that dials a node reaches any_valid_shard = true, so a skipped hook is never left without that commit. The unit test redials a given-up primary at a multicast address, which Linux refuses at once, inside handle_cluster_slots(), and checks that its line moves to the slot's new primary. It failed on 2153722. It also checks the deferred hook directly, and that a malformed reply clears the flag. Co-Authored-By: Claude Opus 5.5 <[email protected]>
When a shard's reconnect timer fires, cluster_client::reconnect() hands the redial to a CLUSTER SLOTS refresh over the main connection and the timer is freed. Until that reply is committed the shard is disconnected with no reconnect timer, which is what the re-route takes for given up. A give-up of another connection in that window ran the re-route at once and dropped the shard's lines as slot-owner-down-for-monitor-line, although the commit was about to redial it and keep them (Cursor Bugbot). While the refresh is in flight (slots_refresh_in_flight(), now shared with fallback_primary_conn_id()), the give-up hook only records that a re-route is due. The commit's own re-route runs it. If the reply is empty, an error or rejected, handle_cluster_slots_rejected() runs it before the refresh is retried, so the lines are dropped as before. If the main connection is lost with the request, the next give-up runs it, including the main connection's own with nothing staged on it. The unit test leaves the slot's owner waiting on the seed's refresh, gives up another connection holding a line for that slot, and commits a reply that redials the owner. Both lines must still be on it. It failed on 02f67b0. Two more blocks check the rejected refresh and the lost main connection. Co-Authored-By: Claude Opus 5.5 <[email protected]>
handle_cluster_slots_rejected() ran the re-route left to a SLOTS refresh for any connection's empty, error or rejected reply. Other primaries ask for CLUSTER SLOTS too (after -MOVED or CLUSTERDOWN), so such a reply arriving while the main connection's refresh was still in flight dropped the lines of a primary waiting on that refresh to redial it: the case e9cdaf6 fixed, through a narrower window. Found in review. It now takes the connection whose reply was rejected. For another connection it does nothing while the main connection's refresh is in flight. Once the main connection is lost, the flag outlives its refresh, and any connection's rejection still runs it. Tests: another connection's rejection during the refresh keeps the lines, failing on e9cdaf6; a rejection with nothing deferred keeps them; and after the main connection is lost a rejection runs the re-route. A probe drives the seed's real reply ("*0" and a reply with no usable shard) through shard_connection, so both call sites are covered. The parse-window block now runs with no main refresh in flight, since a refresh in flight defers the give-up on its own. Each end of a deferral is also checked to use the flag up. Review nits: comments, a has_staged local, and listen_any() reused. Co-Authored-By: Claude Opus 5.5 <[email protected]>
When a shard's reconnect timer fires, cluster_client::reconnect() leaves the redial to a CLUSTER SLOTS refresh: the shard is then disconnected with no reconnect timer, which the re-route took for given up. e9cdaf6 and 18929b9 inferred the wait from the main connection's refresh state instead, and missed two cases (Cursor Bugbot): the main connection reconnecting, when no refresh is in flight yet its next one redials the shard, so the shard's lines were dropped; and the main connection given up on with nothing staged, which ran no re-route, so the shard's counted lines kept a --requests run open. reconnect() now marks the shard as awaiting a SLOTS redial. The re-route does not take a marked shard for given up, so its lines stay and lines for its slots move to it. The mark is cleared when the shard is dialed again (connect_shard_connection(), as a commit's redial does), when a commit retires it, and when it or the main connection is given up on. The main connection's give-up then re-routes, so lines that waited on it are dropped. A shard's lines thus wait exactly as long as the shard itself does. This replaces the deferral of e9cdaf6 and 18929b9: m_reroute_after_refresh, slots_refresh_in_flight() and handle_cluster_slots_rejected() are gone. A rejected reply no longer drops a waiting shard's lines; the refresh is retried and a later map redials it. The parse-window skip (02f67b0) and the drop wake (ab4c642) stay. The unit test marks the shard through reconnect() and checks that a give-up keeps its lines, that the commit redials it and keeps them, that a map without it moves them, and that a give-up while the seed waits on its reconnect timer keeps them, which failed on 18929b9. It also checks that the seed's give-up with nothing staged drops them, which also failed on 18929b9. Co-Authored-By: Claude Opus 5.5 <[email protected]>
The re-route, the replay hand-off and the unowned fallback each tested "nothing will dial this primary again" their own way, and the re-route was bitten twice by the gap between them. They now share cluster_client::primary_given_up(): disconnected, no reconnect timer, and no redial left to a SLOTS refresh. Review feedback. - The replay hand-off runs at a commit, right after the redials, when no target can still be awaiting one, so it is unchanged. - The unowned fallback keeps its deliberate difference: while the seed refreshes SLOTS it also counts a primary given up on, which that commit redials. It now counts a shard waiting on a SLOTS redial too, as the re-route does, also while the seed waits on its reconnect timer. Also from review: - A keyless staged line, which only a staging bug could produce, is dropped as unroutable-monitor-line instead of looking like a failover in --failed-keys-file. - A comment says why the give-up hook may return early during a parse even for the main connection. - The 1 s CLUSTERDOWN throttle is CLUSTERDOWN_REFRESH_INTERVAL_USEC in cluster_client.h, which the pending fixture reads. Unit tests: the shard's reconnect while the seed is down (the seed is redialed and the shard waits on it), a shard on its own reconnect timer, and the fallback counting a waiting shard, which failed on 916813f. Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
Thanks. Fixed in a27888f; answers to the rest below.
🤖 Generated with Claude Code |
cluster_client::connect() dropped client::connect()'s result and always returned 0. A dial of the main connection that failed before reaching the event loop (a resolve or socket setup error, or a connect() error that libevent 2.1 doesn't report) therefore looked like a dial in progress. When the main connection's own reconnect timer fired, handle_reconnect_timer_event() logged "connecting" and armed nothing, so the main connection and any shard waiting on its refresh stayed down. With --max-reconnect-attempts of 2 or more, or unlimited, the cap was never reached. The fallback in a27888f only covered the first retry. Return that result. The timer's failed-reconnect path then counts and re-arms each retry, up to the cap, and gives the main connection up at the cap. A shard's reconnect() keeps the shard waiting on the main connection and starts its first retry, instead of retrying the shard itself. At startup, client::prepare() now aborts on such a failure, as it does without --cluster-mode, and a --reconnect-interval reconnect that fails exits as it does there. With libevent 2.0 the failure is reported from inside connect(), but connect()'s disconnect() then frees any timer that callback armed and clears m_reconnecting, so the retry above is not skipped. Unit cases: a cap of 2, where the timer fires again and the seed ends given up on, and an unlimited cap, where the timer stays armed. Both fail on a27888f. Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
Follow-up in af66a36. The recheck found that a27888f's fix only bounded the first retry, and corrects one claim of mine.
🤖 Generated with Claude Code |
|
One correction to my last comment: 🤖 Generated with Claude Code |
Add an RLTest case where a primary is given up on mid-run while a replica is still in setup, so the thread goes on and the monitor lines staged on the primary are dropped. It checks the slot-owner-down-for-monitor-line records in --failed-keys-file, and that the Errors count under ALL STATS matches the failed-keys records. It fails on master, which records no such line, and on a mutant that uncounts the lines without counting them as errors. Call primary_given_up() directly in reroute_staged_monitor_commands() instead of through a forwarding lambda, and let the test's header regex accept any whitespace in the #define. Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
Thanks. Answers below; the integration check and the nits are in 5cd86ff.
🤖 Generated with Claude Code |
Whether a line is staged on A before A is given up on depends on scheduling, and no peer can observe it: a line staged on A stalls the client at pipeline 1. So A's redial now stays in setup for two seconds (X's for five), and the scenario runs up to 3 times until memtier reports "dropped N staged monitor line(s)". The PR base never does. Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
Thanks. A peer can't tell when a line is staged on A, and holding A until it is deadlocks the client at 🤖 Generated with Claude Code |
|
Answers for the updated review:
🤖 Generated with Claude Code |
The CI plain job needed all 3 tries. On a fast client, A and X dropped together, before any SLOTS refresh: R went idle while A was disconnected (no line is selected then), and nothing woke it once A's redial was in setup, so no line was staged on A. Now X's first PONG is held, so X sees its drop at once, and X is dropped only once A's redial is accepted. X's refresh then lands while A is in setup and wakes R, whose next line is staged on A. A's third SET waits until X holds its PING, for starved hosts. The 3-try loop stays as a margin. Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
Test reliability update in 75906f6: on 4cd3552, The test now drives that from evidence. X's first PONG is held, so X sees its drop at once (tests/test_cluster_unowned_slots.py:771), and X is dropped only when A's redial is accepted (:781). X's refresh then lands while A is in setup and wakes R, whose next line is staged on A. A's third SET waits until X holds its PING, for starved hosts (:820). Per try: idle 100/100, starved 100/100 (nice 19, 8 busy loops). The base fails every try (0/10, then 🤖 Generated with Claude Code |
The cap bounds memory for new staging. A re-route only moves lines that are already selected and counted, so dropping one there for the merged queue's size brought back the loss this PR removes (e.g. a retired primary's slots all landing on one survivor). Producers still never stage on a queue at the cap: they send the line themselves. The cap is now a member so a unit test can lower it; the test fails with the old queue-full drop. primary_given_up() also asserts that an awaiting-redial mark implies a down connection with no timer, and the assert before the UINT_MAX branch says why both exist. Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
Thanks for the review. Pushed e89036c.
🤖 Generated with Claude Code |
|
Two corrections to my previous reply:
🤖 Generated with Claude Code |
|
Thanks.
🤖 Generated with Claude Code |
A --cluster-mode seed at the broadcast address fails connect() before the event loop (ENETUNREACH or EACCES without SO_BROADCAST). Since cluster_client::connect() passes the failure on, prepare aborts with "prepare: failed to connect, test aborted." and exit 1, within the 10s bound. Master launches the thread and ends it with no request sent. The test probes the address first and skips, with the reason, where connect() would not fail at once. Co-Authored-By: Claude Opus 5.5 <[email protected]>
#897 moved the retire body into release_retired_connection() and added handle_connection_retired(). Both connection hooks are kept. The helper now carries this branch's retire path: it clears the awaiting-redial mark before disconnect(), re-routes staged monitor lines instead of flushing them (only a replica retired by the hook can still hold any, and none do today), and keeps the key-pool uncount and the replay hand-off. Co-Authored-By: Claude Opus 5.5 <[email protected]>
The OSS-CLUSTER TLS cell's Run tests step took 2393 s on master 33ff193, 7 s under its 40-minute limit, and timed out on #885. Split both full-suite cluster cells into two file shards with utils/select_test_shard.py, and validate the split with utils/check_test_shards.py, as the sanitizer workflows already do. Fixes #898 Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
Thanks.
🤖 Generated with Claude Code |
ci: run the OSS-CLUSTER full-suite cells as two shards each (#899) The OSS-CLUSTER TLS cell's Run tests step reached its 40-minute limit (2393 s on master 33ff193; timed out on #885). Both full-suite cluster cells now run as two file shards, chosen by utils/select_test_shard.py and checked by utils/check_test_shards.py, as the sanitizer workflows already do. Each shard runs in 17-23 minutes, and the 922 tests are each assigned exactly once. Fixes #898 Co-Authored-By: Claude Opus 5.5 <[email protected]>
Picks up the two-shard split of the OSS-CLUSTER full-suite CI cells; only .github/workflows/ci.yml changes. Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
bugbot run |
|
Thanks.
🤖 Generated with Claude Code |
Picks up 14 master commits, including the connect-failure changes in #855 (libevent 2.1.8's error callback from a failing connect), #823 (hardened libevent failures), #822 (TLS error reporting) and the libevent compatibility CI from #545. No conflicts. Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
bugbot run |
There was a problem hiding this comment.
✅ Bugbot reviewed your changes and found no new issues!
Comment @cursor review or bugbot run to trigger another review on this PR
Reviewed by Cursor Bugbot for commit a054ad2. Configure here.
Fixes #835.
Fixes #836 for staged monitor lines. Routed built-in keys (
m_key_index_pools) on a retired or demoted connection are still cleared, as before; that is now #889.Problem
With
--cluster-mode --monitor-input, a monitor line was routed once, when it was staged, and nothing checked the committed slot map again before it was sent. The replay cursor had already moved past each staged line, so every line lost here was never sent. Later selections then wrapped and repeated earlier lines. Totals Count and the exit code stayed the same, so nothing reported it. There were four ways to lose or misroute lines:--monitor-input: a staged monitor command is sent to the connection it was staged on even after a newer slot map moved its slot. The MOVED that follows flushes the rest of that queue. #835): the line went to the old owner, got-MOVED, andhandle_moved()flushed the rest of that connection's queue.--monitor-input: when a slot-map refresh retires or demotes a primary, its staged monitor lines are silently dropped and replaced (or sent to the demoted node) #836): the commit loop cleared the retired connection's queue.--monitor-input: when a slot-map refresh retires or demotes a primary, its staged monitor lines are silently dropped and replaced (or sent to the demoted node) #836): the writes drained on what was now a replica connection.connect_shard_connection's replica-reset branch cleared the queue.Change
reroute_staged_monitor_commands()moves each line to its slot's current primary.m_reqs_generatedis unchanged for moved lines. A line is dropped only when the primary it would be sent from was given up on (and, for an unowned slot, no other primary is live or reconnecting). A move never drops a line, even past the staging cap: the cap bounds new staging, and a producer still sends a line itself rather than stage it on a queue at the cap. A dropped line no longer counts toward--requests, but it now counts as an error, is logged to--failed-keys-file(slot-owner-down-for-monitor-line;unroutable-monitor-linefor a keyless line, which only a staging bug could stage), and prints one warning per map commit. "Given up on" is one test,primary_given_up(), shared by the re-route, the replay hand-off and the unowned fallback, and it asserts (asserts are live in release builds;configure.acdoesn't defineNDEBUG) that an awaiting-redial mark implies a down connection with no timer; the fallback additionally counts a given-up primary while the seed refreshes SLOTS, since that commit redials it. The error count and failed-keys logging matchhand_off_replay_requests(). Before, these drops were silent.--requestsrun never finished. Master has the same hang.cluster_client::connect()now returnsclient::connect()'s error instead of 0. A main-connection dial that fails before reaching the event loop (a resolve or socket error, or aconnect()error that libevent 2.1 doesn't report through the event loop) is retried on its reconnect timer every time and counted against--max-reconnect-attempts. It is no longer taken for a dial in progress and left down with no timer. A shard that left its redial to the main connection keeps waiting while the main connection retries; once the main connection is given up on, the shard's staged lines are dropped and counted. Master leaves both connections down in this case.--read-preferenceother than primary, a primary can be given up on while its thread keeps running. A newhandle_connection_given_up()hook runs the re-route at that point, so its staged lines are dropped or moved at once instead of staying counted until the next commit. A give-up whilehandle_cluster_slots()is parsing a reply is left to that reply's commit. A shard whose reconnect timer left its redial to a CLUSTER SLOTS refresh has no timer but isn't given up on: it is marked as awaiting that redial, and the re-route keeps its lines. The mark ends when the shard is dialed again, when a map retires it, or when it or the main connection is given up on; the main connection's give-up re-routes, so lines that waited on it are dropped. Dropped lines also wake every producer, since uncounting them can let a producer parked at the--requestscap continue.role_primaryon its connection, so the re-route reads the new map's shard groups instead.release_retired_connection(), shared with Don't count connection rejections as replies #897'shandle_connection_retired(). It clears the awaiting-redial mark beforedisconnect()and re-routes staged lines instead of flushing them.handle_moved()no longer flushes the staged queue. A replica redial or a promotion keeps staged monitor lines; a redial to a different endpoint still clears both queues.--monitor-inputpays one empty-queue check per connection per topology commit.Results
Scripted 3-node peer, sequential 20-line monitor file replayed with
--requests=40(alternating PING and the monitor line), pipeline 1 and 4. Each cell shows lines missing / duplicated / misrouted for that case:Totals Count was 40 and the exit code 0 in every run, on both builds.
On a real 3-primary cluster (Redis 8.6.0, 1,000,000
INCRlines, pipeline 16,--retry-on-error), slot migration, failover, a drained primary's retirement and a paused takeover lost 1 to 63 lines per run on master and 0 with this PR.Release notes
With
--monitor-inputin--cluster-mode, an already-selected monitor line that can no longer be sent (its slot's primary was given up on) is now counted as an error and logged to--failed-keys-fileinstead of being skipped silently. This changes the reported error counts, not the exit code.In
--cluster-mode, a dial of the main connection that fails before reaching the event loop (for example an unreachable network, which libevent 2.1 doesn't report through the event loop) is now handled as without--cluster-mode. With--reconnect-on-error, every retry counts against--max-reconnect-attempts, instead of the connection being left down with no retry. At startup, such a failure now aborts at once with "prepare: failed to connect, test aborted.", as without--cluster-mode(a startup dial is not retried, even with--reconnect-on-error). The exit code is unchanged.Tests
tests/test_cluster_unowned_slots.py, covering 19 cases.tests/unit/cluster_transaction_test.cppexpected a replica redial or a promotion to clear staged monitor lines, which is the redialing-demote loss above. It now expects them to be kept. New unit blocks cover the drop wake, the parse-window skip, the awaiting-redial mark (both reconnect paths, the main connection's give-up, the shard's own timer, and an unreachable main connection with a cap of 1, 2 and unlimited), a move onto a queue at the staging cap, and the shared given-up test.test_cluster_startup_dial_failing_at_once_abortsseeds--cluster-modewith 255.255.255.255, whoseconnect()fails before the event loop. It checks for exit 1 and "prepare: failed to connect, test aborted." within 10 s, and skips with a reason where that dial wouldn't fail at once. Master instead launches the thread and ends it with no request sent.test_given_up_primary_monitor_drops_are_reportedgives a primary up mid-run while a replica is still in setup, so its staged lines are dropped. It checks theslot-owner-down-for-monitor-linerecords in--failed-keys-fileand that theErrorscount underALL STATSequals the number of failed-keys records (the drops plus any request held for resend when the thread ended). The fake servers order the drops from evidence, so a line is staged on the primary while its redial is in setup. A 3-try loop is kept only as a margin. It fails on master and on a mutant that skips the error count.connect()'s error, starting that retry from a shard'sreconnect(), and marking the shard before it), the two given-up rules added in 08fab58, the live-primary fallback added in f87277c (its unit block reproduces Bugbot's dead-primary case), the wake on a drop, the parse-window skip, the fallback's use of the shared given-up test, and every part of the awaiting-redial mark: setting it on both reconnect paths, honouring it, and clearing it on a redial, a retirement and the main connection's give-up. A unit test reaches the drop path and checks the error count and the failed-keys record, and a pending-reconnect case catches the role-based rule. Three survive. Marking the shard afterconnect()but before that retry is equivalent on libevent 2.1, where the give-up can't run insideconnect(). The wake of the target connection can't be seen in the unit harness, and every fixture wakes the target some other way. The replay hand-off using the old given-up test is equivalent, since it runs right after the commit's redials.make check18/18.make check18/18 and 63/63 RLTest, including Back off CLUSTERDOWN topology refreshes per client #877's tests.Affected versions
The staging queue, and with it the slot-move and retire losses, came in with 38a5369 (#395, cluster
--monitor-input), released in 2.4.0 through 2.5.2. Since 38a5369 any redial cleared staged lines. #799 (4018396, unreleased) kept them for same-endpoint primary redials but still cleared them on a replica redial, demotion included, and began staging during refresh and backoff, which widened the window.🤖 Generated with Claude Code
Note
High Risk
Changes cluster monitor replay, topology commit, reconnect/give-up handling, and request accounting during failovers—areas that can hang runs or mis-count ops if wrong.
Overview
Cluster
--monitor-inputreplay now keeps unsent monitor lines aligned with the slot map instead of flushing them on failover, redial, or-MOVED.Each staged line records its hash slot; on every committed
CLUSTER SLOTSmap (and when a primary is given up mid-run),reroute_staged_monitor_commands()moves lines to the slot’s current primary while preserving per-slot order. Lines are dropped only when no viable primary exists (primary_given_up()): they are uncounted for--requests, counted as errors, and logged to--failed-keys-file. Replica redials still clear routed read keys only; staged monitor writes survive same-endpoint primary redials, demotion, and promotion. Shards waiting on a seed refresh useawaiting_slots_redialso they are not treated as permanently dead.Other fixes:
cluster_client::connect()propagates immediate dial failures (startup abort; main-connection retries bounded by--max-reconnect-attempts);handle_moved()no longer clears the staged monitor queue. README documents the new semantics. Integration tests (_Failover, given-up primary drops) and expandedcluster_transaction_test.cppcover the behavior.Reviewed by Cursor Bugbot for commit a054ad2. Bugbot is set up for automated code reviews on this repo. Configure here.