Repository navigation
Count requests dropped at reconnect under --retry-on-error as errors - #661
Conversation
|
🤖 Automated first-pass review — a human maintainer's review is still required before merge. Thanks for this. I went through the drop sites and the new One question, which you already half-flagged in the description: on Ctrl+C the sweep now counts requests sitting in a retry/replay queue as errors ( Nitpicking: the comment above the sweep is fairly long for what the code does. Leaving it as is would be fine too. The core change looks solid to me. Since it changes what |
60ce056 to
0736de4
Compare
0736de4 to
965f106
Compare
|
Thanks. Addressed in 965f106, which is also rebased onto current master (969c4de). a. Flakiness in b. A later CLUSTER SLOTS hand-off after c. The "Account it like any other drop" comment. Reworded to "It cannot be resent: abandon it." That fallback, and the in-flight one above it, now also log a Also in this push: the reason is |
With --retry-on-error, a request memtier gives up on after its connection drops is logged to --failed-keys-file but was never counted as an error, so the run reported "errors 0". Since #620 a request abandoned when the run ends is counted, so whether a lost request reached the error total depended only on where it was dropped. Add connections_manager::abandon_requests(), which uncounts the requests from the generated total (as the drop sites already did) and counts each one as an error, and use it at every place a request held for resend is dropped for good: - drain_replay_queue_after_reconnect(): "connection-dropped" (max retries reached) and "no-captured-bytes-for-replay" - cluster_client::hand_off_replay_requests(): "transaction-not-replayed", "no-slot-owner-for-replay", "slot-owner-down-for-replay" - shard_connection::disconnect() under --retry-on-error: "transaction-not-replayed" and requests with no captured bytes - client::disconnect_all(): "run-ended-before-resend" (unchanged count) A request moved to the replay queue and later resent is not counted; it is counted only where it is finally dropped. Requests dropped on a disconnect without --retry-on-error are still only uncounted, as before. The failed-keys rows are unchanged. Fixes #652 Co-Authored-By: Claude Opus 5.5 <[email protected]>
When --max-reconnect-attempts is exhausted the thread ends, and the
requests held for resend on that connection were freed with it: no
failed-keys row and no error. Log them as "max-reconnect-attempts-exceeded"
and count them as errors, through a new
shard_connection::abandon_replay_requests(), which disconnect_all() now
uses too for "run-ended-before-resend".
The other connections that disconnect() and keep their held requests
(max attempts reached while peers are mid-setup, READONLY failure without
--reconnect-on-error) are not giving up: a CLUSTER SLOTS refresh reconnects
them and resends, retires them and hands the requests off, or the run end
counts them in disconnect_all().
Tests:
- test_transaction_requests_are_not_retried: the error total equals the
failed-keys rows, so the --transaction drop in disconnect() is covered.
- test_requests_dropped_at_hand_off_count_as_errors: a scripted two-node
cluster drops a connection with writes in flight and retires it with
their slot unowned ("no-slot-owner-for-replay").
- test_replays_abandoned_when_reconnects_run_out_are_counted.
Refs #652
Co-Authored-By: Claude Opus 5.5 <[email protected]>
When one connection runs out of --max-reconnect-attempts it breaks the
thread's event loop. Only that connection's replay queue was abandoned:
the other connections on the same thread had already moved their
in-flight requests to their own replay queues on the same outage, and
those were freed with the connections, without a --failed-keys-file row
or an error. With -c4 --pipeline 16 only 16 of the 64 lost requests were
counted.
client_group::run() now abandons, once the loop returns, every request
still held for resend on any connection of the thread
("thread-ended-before-resend"); a normal run end has already emptied
them. The connection that ran out logs its own requests as
"max-reconnect-attempts-exceeded", or "connection-lost-no-reconnect"
without --reconnect-on-error, with a stderr summary; the
handle_reconnect_timer_event() terminal path now does the same instead
of nothing. disconnect()'s no-captured-bytes fallbacks log a
"not-replayable" row too. The memtier_errors_total HELP text and the
m_errors comment now include requests given up on without a reply.
Fixes #652
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Without --reconnect-on-error, the first connection that loses its server ends the whole thread before the other connections on it handle their own EOF. Their requests are still in flight, not in a replay queue, so the client_group::run() sweep missed them: with -t2 -c4 --pipeline=16 and a SHUTDOWN, 32 of the 128 lost requests were counted. The same happens with --reconnect-on-error when only one connection drops. Under --retry-on-error, the sweep now disconnects every connection that still has requests in flight, which moves them to its replay queue, before abandoning the queue. On Ctrl+C in-flight requests are still dropped as before. The connection that ends the thread now only records its reason; the sweep logs its requests with it, so one stderr warning covers the whole thread instead of one per connection plus one for the thread. Fixes #652 Co-Authored-By: Claude Opus 5.5 <[email protected]>
965f106 to
63a3295
Compare
|
Thanks. 63a3295 addresses the points from your 08:22 edit and is rebased onto master 6eedafb. a. Description out of date. Updated. It lists every reason this PR adds: b. Sibling test failing before the fix. Confirmed. It fails 3/3 on master ( c. d. Timer-path reason. Confirmed. e. Double warnings. Before, the per-connection line and the thread-level line counted disjoint sets, so nothing was double-counted, but it was two lines for one outage. They are now one line. The connection that ends the thread only records its reason, and the sweep logs its requests with that reason. The thread gets one "N request(s) held for resend when the thread ended ..." warning. Earlier question: a CLUSTER SLOTS hand-off after |
|
On the 09:51 point about Ctrl+C: The asymmetry is intentional. A request in a retry or replay queue at Ctrl+C has already been sent at least once and been given up on by the server or the connection. memtier was holding it only to resend it, and the interrupt is what stops that resend, so it is logged and counted, as The exit code and the reported window are unchanged. The PR body's fix section states the Ctrl+C semantics. I've kept the reason The sweep comment is long because it documents those two cases. I'll shorten it if you want. |
…ts() #661 added connections_manager::abandon_requests() as the single path for "uncount and count as an error". Use it in drop_pending_requests() instead of dec_reqs_generated() plus a separate inc_error() loop, so every give-up site counts the same way. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Decision: with
--retry-on-error, a request memtier sends and then gives up on (never resent, never answered) counts as an error and gets a--failed-keys-filerow.client::disconnect_all()already does this forrun-ended-before-resendsince #620. Ops stay uncounted, as before. Without--retry-on-error, requests dropped on a disconnect are still only uncounted, as today.Summary
With
--retry-on-error, every request memtier sends and then gives up on without a reply is now logged to--failed-keys-fileand counted as an error, wherever it is dropped. That covers the reconnect drain, the cluster hand-off,disconnect()under--transaction, and the end of a thread that lost its server. Before, onlyrun-ended-before-resendwas counted (#620). Every drop site goes through one helper,connections_manager::abandon_requests().Problem
With
--retry-on-error, a request dropped after its connection drops was logged to--failed-keys-filebut never counted as an error. The run reportederrors 0 (+0)next to hundreds ofconnection-droppedrows. A request abandoned when the run ends has been counted since #620, so whether a lost request reached the error total depended only on where it was dropped.Root cause
The drop sites that run at reconnect or hand-off time called
dec_reqs_generated()but neverm_stats.inc_error():shard_connection::drain_replay_queue_after_reconnect():connection-dropped,no-captured-bytes-for-replaycluster_client::hand_off_replay_requests():transaction-not-replayed,no-slot-owner-for-replay,slot-owner-down-for-replayshard_connection::disconnect()under--retry-on-error:transaction-not-replayed, plus requests with no captured bytesSeparately, when
--max-reconnect-attemptsran out and the thread ended, the requests held for resend were freed with the connections, with no row and no error. That covered every connection on the thread, not only the one that ran out: on the same outage its sibling connections (other--clientson the thread) had already moved their in-flight requests into their own replay queues. With-t1 -c4 --pipeline 16and the server gone, 64 requests vanished; counting only the connection that ran out still left 48 of them uncounted. Without--reconnect-on-errorit was worse: the first EOF ends the thread before the siblings handle their own EOF, so their requests are still in flight, not even in a replay queue. With a real server,-t2 -c4 --pipeline=16andSHUTDOWN, only 32 of 128 were counted at the previous head of this PR, and 0 on master.Fix
connections_manager::abandon_requests(count)uncounts the requests (dec_reqs_generated(), as before) and counts each one as an error.run_stats::inc_error()now takes an optional count. Every drop site above uses it.shard_connection::abandon_replay_requests(reason)logs and abandons everything still held for resend on a connection. Two places use it:disconnect_all(), forrun-ended-before-resend(same rows and counts as before);client_group::run(), once the thread's event loop returns, for every connection of every client on the thread. Under--retry-on-errorit first callsdisconnect()on each connection that still has requests in flight, which moves them to its replay queue. It skips that on Ctrl+C: in-flight requests are dropped there as before.attempt_reconnect()orhandle_reconnect_timer_event()) records its reason, and its requests are logged with it:max-reconnect-attempts-exceeded, orconnection-lost-no-reconnectwhen--reconnect-on-erroris off. The timer path is only armed from the--reconnect-on-errorbranch ofattempt_reconnect(), so it always uses the first reason.thread-ended-before-resend. This covers the siblings above and any other early loop break.run-ended-before-resenddoes.disconnect_all(), and has nothing in flight, so nothing is counted twice.memtier_errors_total's HELP text,docs/REALTIME_METRICS.mdand them_errorscomment now say errors include requests given up on without a reply.max-reconnect-attempts-exceeded,connection-lost-no-reconnectandthread-ended-before-resend, plusnot-replayablefor thedisconnect()fallbacks for requests with no captured bytes (only whenmallocfails during capture). Those fallbacks had no row before.Overlap with #669: open PR #669 adds
drop_pending_requests()/abandon_unanswered_requests(). Whichever of the two PRs lands second should route its drops throughabandon_requests(). This PR does not depend on #669.Not given up on (unchanged, on purpose)
read-preference != primary, "leaving connection dead and continuing"), and a READONLY failure without--reconnect-on-error. Both calldisconnect(), which keeps the held requests. They are not abandoned at that point. A CLUSTER SLOTS refresh either reconnects the connection and resends them, or retires it and hands them off throughhand_off_replay_requests(), which counts what it can't place. Anything still held when the run ends is counted bydisconnect_all()asrun-ended-before-resend.cluster_client::disconnect(), which deletes non-main connections. It is only reached through--reconnect-interval, andverify_cluster_option()rejects that option in cluster mode. In standalone,client::disconnect()keeps the single connection and its replay queue, which is drained after the reconnect.slot-owner-down-for-replaynow counts like the other hand-off reasons. It is not covered by a test, because it needs a node that dropped out of a previous map, gave up reconnecting, and is then named again as the slot owner.Test evidence
Before = origin/master code. Mutant = this branch with the
disconnect()--retry-on-error --transactionbranch reverted to plaindec_reqs_generated.test_dropped_replays_are_counted_as_errors(new;CLIENT KILL SKIPME yes,connection-dropped)0 == 144,0 == 176)test_transaction_requests_are_not_retried(now asserts errors == failed-keys rows)21 == 53,16 == 48,22 == 55)15 == 47,14 == 54,15 == 55)test_requests_dropped_at_hand_off_count_as_errors(new; scripted two-node cluster intest_cluster_failed_keys.py,no-slot-owner-for-replay)0 == 7or0 == 8)test_replays_abandoned_when_reconnects_run_out_are_counted(new;max-reconnect-attempts-exceeded)test_replays_held_by_sibling_clients_are_counted_when_thread_ends(new;-t1 -c4 --pipeline 16,--reconnect-on-error --max-reconnect-attempts=1, every connection closed, reconnect refused)0 == 64); 5/5 FAIL (16 == 64) on the commit before 965f106test_in_flight_requests_of_sibling_clients_are_counted_when_thread_ends(new; same, but the peer closes only the first connection)0 == 32); 965f106 3/3 FAIL (8 == 32)test_requests_lost_without_reconnect_are_counted_when_thread_ends(new;-c4 --pipeline 8 --retry-on-error, no--reconnect-on-error,connection-lost-no-reconnect)0 == 32); 965f106 3/3 FAIL (8 == 32)Real server,
-t2 -c4 --pipeline=16 --retry-on-error, killed withSHUTDOWN NOSAVEfrom a--command: 965f106 logged and counted 32 rows; this head logs 128 rows (32connection-lost-no-reconnect, 96thread-ended-before-resend) witherrors 128.test_dropped_replays_are_counted_as_errorsnow also acceptsrun-ended-before-resendrows: a kill in the last ms of--test-timecan leave held requests fordisconnect_all(). It still asserts errors == rows.How the hand-off test works:
no-slot-owner-for-replay.Full files with this branch:
tests/test_retry_on_error.py--env osstest_transaction_drops_not_logged_without_retryfailed once with "no CLIENT KILL found a memtier connection", a timing miss in its kill loop, and passed 4/4 on rerun. That test does not use--retry-on-error, and it also passes 4/4 on 965f106.tests/test_retry_on_error.py--env oss-cluster --shards-count 3tests/test_cluster_failed_keys.pyFixes #652
Affected versions
2.4.0 through 2.5.2 (latest) and master.
--retry-on-error), which added the replay queue and theconnection-droppeddrop withoutinc_error(). The first tag that contains it is 2.4.0.--transactiondrop indisconnect()(--transaction with --retry-on-error: EXEC replayed without its MULTI after a reconnect is retried forever #611) are on master only.🤖 Generated with Claude Code