Skip to content

Test the -READONLY retry to the slot primary under RESP2 and RESP3 - #886

Merged
fcostaoliveira merged 2 commits into
masterfrom
claude/readonly-retry-test-462
Oct 25, 2026
Merged

fcostaoliveira merged 2 commits into
masterfrom
claude/readonly-retry-test-462

Conversation

@fcostaoliveira

@fcostaoliveira fcostaoliveira commented Oct 25, 2026 •

Copy link
Copy Markdown
Collaborator

Fixes #462.

Problem

The pinned RLTest fork already fixed #462's root cause: --use-slaves replicas now join the cluster, and on master the read-preference cells run 29 tests that pass. The one skip left was test_readonly_retry_resp2_resp3, a placeholder that always skipped. Its TODO named #100, an unrelated PR. The drop tests (#592, #651) cover a -READONLY that isn't retried, but nothing covered the resend itself.

Change

New tests/test_cluster_readonly_retry.py, with four scripted peers on ephemeral ports (two decoys). It needs no replicas and no failover timing, and runs under --protocol=resp2 and resp3:

  • Stale primary: the map names A the primary. B answers its first SET with -CLUSTERDOWN, so memtier refreshes through B, and the new map makes B the primary and A its replica. A holds its SETs until memtier sends it READONLY, which memtier does only after applying the new map. A then rejects them, and any sent after it, with -READONLY, and they must be resent to B.
  • Replica read: a SET marked --command-is-read goes to replica A under --read-preference=secondary. A rejects it, and it must be resent to the primary, B.

Each test checks:

  • every key is accepted exactly once by B, after at most one rejection by A;
  • Count is 12 and Errors is 0;
  • Retry Attempts and Retried Ops match the resends;
  • there are no MOVED replies or connection errors;
  • the histogram and per-second counts add up;
  • --failed-keys-file stays empty;
  • the --requests run ends with exit code 0.

The placeholder is removed.

The rest of #462: when replicas are expected but discovery finds none, the read-preference tests skipped instead of failing, and the cell still went green.

  • Replicas expected: with --use-slaves (OSS_CLUSTER_REPLICAS=1) in cluster mode, get_cluster_replica_connections() now raises when CLUSTER NODES lists no replicas or reading it fails. The message includes the reply or the error. It raises rather than asserting, because RLTest drops a failed assert when the test then skips.
  • Replicas not expected: every other cell has none configured, so its tests still skip.
  • Docs: the helper's docstring and the README's "Testing with replicas" section now describe the RLTest fork's real cluster replicas.
  • Decoy primaries: the retry tests add two primaries, C (the seed) and D (last in the map), that own no key's slot. Both must get no SET, so a resend to any other connection fails. Before this, a resend to the lowest- or highest-numbered other connection passed all four tests.

Tests

  • Discovery, both directions (3-shard cluster with replicas): with this PR 36 tests pass and none skip. When discovery finds no replicas, the 22 tests that the old tree skips (green) now fail. When discovery raises, 24 fail; 2 of those are slot-move tests the simulation breaks on the old tree too. Without replicas configured, the same 22 still skip.

  • Where it runs: the file runs in the 7 test-ubuntu cells, coverage shard 7/8, and the ASan, UBSan and TSan plaintext shard 1/2 cells (standalone and cluster).

  • Runs: 5/5. Under load (1 CPU, 2 busy loops, nice 19) it also passes 5/5.

  • Mutants: these fail all four tests: no retry, a retry to the same connection, double counting, either retry counter left unincremented, and a lost request. A resend routed by --read-preference fails the two replica-read tests. Removing the stale-primary guard is caught by the existing test_cluster_readonly_drop.py.

  • make check: 18/18.

Affected versions

Test-only. The placeholder came in with ee757e7 (#456, --read-preference), so the gap is in 2.5.0 through 2.5.2 and master.

🤖 Generated with Claude Code


Note

Low Risk
Test and documentation changes only; no production memtier_benchmark code paths are modified.

Overview
Adds deterministic integration tests for cluster -READONLY handling with --retry-on-error: a new test_cluster_readonly_retry.py drives memtier against four scripted TCP “shard” peers (no RLTest replicas or failover timing). It covers a stale topology path (-CLUSTERDOWN → map refresh → replica rejects with -READONLY) and a replica read path (--read-preference=secondary on a read-marked SET), under RESP2 and RESP3, asserting each key lands once on the slot primary, retry JSON counters, and exit 0. The always-skipping test_readonly_retry_resp2_resp3 placeholder in test_read_preference_failover.py is removed.

Tightens replica CI expectations (#462): cluster_replicas_expected() plus get_cluster_replica_connections() now raise when the env was started with --use-slaves but CLUSTER NODES is unreadable or lists no replicas, instead of warning and letting tests skip as green. Failover retry tests use the same rule when replica topology is missing. README replaces the old “testing limitations” harness-gap text with documentation of the pinned RLTest fork that registers replicas in the cluster.

Reviewed by Cursor Bugbot for commit 92d6a7e. Bugbot is set up for automated code reviews on this repo. Configure here.

The read-preference failover cells ran test_readonly_retry_resp2_resp3,
a placeholder that always skipped: it waited for a way to time CLUSTER
FAILOVER against an in-flight pipeline (its TODO named #100, an unrelated
PR). The drop tests (#592, #651) cover a -READONLY that is not retried,
but nothing covered the resend itself.

test_cluster_readonly_retry.py drives it with two scripted peers on
ephemeral ports, so it needs no replicas or failover timing, under
--protocol=resp2 and resp3:

- stale primary: the map names A the primary. B answers its first SET
  with -CLUSTERDOWN, memtier refreshes through B and the new map makes B
  the primary and A its replica. A holds its SETs until memtier sends it
  READONLY, which it does only once the new map is applied, then rejects
  them with -READONLY. They must be resent to B.
- replica read: a SET marked --command-is-read goes to replica A under
  --read-preference=secondary and is rejected; it must be resent to the
  primary B.

Each key must be accepted by B exactly once after at most one rejection
by A. The JSON must count each request once, with no errors, Retry
Attempts and Retried Ops matching the resends, a histogram of the run's
requests and, for the replica read, latency spanning both attempts. No
key is written to --failed-keys-file, and the --requests run must exit
0. Reverting the resend, resending to the rejecting connection, routing
the resend by --read-preference, double counting, or skipping the retry
counters fails the tests.

The placeholder is removed. The new file runs in every default cell.

Fixes #462

Co-Authored-By: Claude Opus 5.5 <[email protected]>
#462 was narrowed to one remaining gap: get_cluster_replica_connections()
returned an empty list when CLUSTER NODES listed no replicas, or when
reading it raised, and its 22 callers in the read-preference, key-affix
and failover tests then called env.skip(). RLTest counts a skip as a
pass, so an OSS-CLUSTER + replicas cell that lost its replicas went
green. The docstring and README still blamed RLTest's --slaveof
replicas, which the pinned fork replaced with CLUSTER MEET and CLUSTER
REPLICATE.

On a cluster started with --use-slaves (OSS_CLUSTER_REPLICAS=1), the
helper now raises AssertionError in both cases, with the CLUSTER NODES
reply or the error, so those tests fail. Cells without replicas still
get an empty list and skip. test_requests_complete_after_primary_failover
finds its replica on its own and fails the same way. The docstrings and
the README section describe the current behaviour.

test_cluster_readonly_retry.py: C, the seed, and D, last in the map,
each own a slot no key maps to and must get no SET, so a resend to the
lowest- or highest-numbered other connection instead of the slot
primary fails all 4 tests (it passed them before). The stale-mode
comment now says A's SETs are rejected after READONLY: held until it,
or sent after it.

Fixes #462

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@fcostaoliveira

Copy link
Copy Markdown
Collaborator Author

Owner summary at 92d6a7e: all 7 lenses approve (SEM, OUT, TEST, BUILD, LIFE, INTER, MAINT).

🤖 Generated with Claude Code

@fcostaoliveira
fcostaoliveira merged commit 5628493 into master Oct 25, 2026
151 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

test harness: read-preference CI cell silently skips all tests

1 participant