Skip to content

MOD-18948: verify every write command replicates to the replica - #1656

Merged
LiranAbir merged 1 commit into
masterfrom
MOD-18948-json-replication-verification
Sep 30, 2026
Merged

LiranAbir merged 1 commit into
masterfrom
MOD-18948-json-replication-verification

Conversation

@LiranAbir

@LiranAbir LiranAbir commented Sep 29, 2026 •

Copy link
Copy Markdown
Contributor

MOD-18948 — RedisJSON half. RedisBloom half is RedisBloom/RedisBloom#1072.

Why

A write command can be implemented correctly on the primary while its propagation to the replica is wrong or missing, and nothing in the suite catches it. The divergence is silent — master_link_status:up, matching replication offsets — until a failover promotes the replica. MOD-16050 is the canonical case: in RedisBloom, CF.LOADCHUNK replicated only its header chunk and never the data chunks, while CF.INFO reported the full inserted count on both sides and the replica held nothing.

The suite already runs once with --use-slaves, but that variant only asserts the primary's replies. Nothing ever reads the replica.

What

tests/pytest/test_replication.py — a table of one representative invocation per write command (15). Each row runs on the primary, waits for the replica to ack, then compares the key set and the document read back in full.

The invocation per command is chosen to be the form most likely to diverge rather than the simplest one:

  • a mid-array index over a tail append (JSON.ARRINSERT $.arr 1, JSON.ARRPOP $.arr 1, JSON.DEL $.arr[1]) — the elements after it shift,
  • a null-valued JSON.MERGE (RFC 7386: deletes the member) over a plain overwrite,
  • a float delta on an integer (JSON.NUMINCRBY $.a 1.5) — promotes the stored number's type,
  • create-on-write over overwriting an existing key.

No argument permutations, no encoding matrix.

testEveryWriteCommandIsCovered enumerates write commands from the running server (COMMAND LIST FILTERBY MODULE ReJSON, filtered on the write flag) and fails if any is missing from the table — a newly added command cannot land without a replication test. It currently discovers exactly the 15 in the table.

Runs on a standalone Env(useSlaves=True), ~13s. Picked up by the default RLTest collection, so no tests.sh change.

Notes

  • JSON.GET '$' is the fingerprint rather than DUMP. Unlike a probabilistic sketch, a JSON document has no internal state the full read does not show — and this suite sets Defaults.decode_responses, so a binary RDB payload cannot come back over these connections. (The RedisBloom PR does compare DUMP, because there a bloom bit array is invisible to every read command.)
  • A read that returns the type default proves nothing — both sides match trivially. Every row asserts the primary's read-back is non-default before comparing it, and asserts WAIT actually acked rather than timing out.
  • Replica read errors are turned into comparable values instead of raising, so one diverging row does not abort the remaining rows.
  • RLTest starts the replica with --slaveof but never waits for the sync, so the test polls master_link_status before the first write.
  • Skipped on --env oss-cluster: RLTest's cluster env creates no replicas at all, and its getSlaveConnection() is an unconditional raise.
  • The env is pinned to RESP2, matching the rest of the suite.

Verification

All four tests.sh variants, locally:

Variant Result
general 2 passed
--use-slaves 2 passed
--use-aof 2 passed
--env oss-cluster coverage passed, replication skipped

Negative controls, run and then discarded:

  • Wiping the replica after the ack reds 15/15 rows, each named.
  • Relaxing the coverage assertion prints the discovered set — exactly the 15 commands in the table, so the guard is not passing vacuously.

RedisTimeSeries is the remaining module; the enterprise side is RED-217947.

🤖 Generated with Claude Code


Note

Low Risk
Test-only change; no production or replication implementation code is modified.

Overview
Adds tests/pytest/test_replication.py so each ReJSON write command gets a primary→replica integrity check—addressing gaps where replication can look healthy but data diverges (MOD-18948).

testWriteCommandsReplicate runs 15 table-driven cases on a standalone Env(useSlaves=True, protocol=2): flush, optional setup, one “stress” write per command, WAIT for replica ack, then compare key sets and JSON.GET / JSON.TYPE on master vs replica. Helpers wait for master_link_status: up, reject trivial readbacks, and surface replica read errors without aborting other rows. Skipped on cluster (no replica connection).

testEveryWriteCommandIsCovered (Redis ≥7) lists module write commands via COMMAND LIST / COMMAND INFO and fails if any are missing from the table (with KNOWN_EXCLUSIONS for intentional gaps).

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

A write command can be implemented correctly on the primary while its
propagation to the replica is wrong or missing, and nothing in the suite
catches it. The divergence is silent -- master_link_status:up, matching
replication offsets -- until a failover promotes the replica. MOD-16050 is
the canonical case: in RedisBloom, CF.LOADCHUNK replicated only its header
chunk and never the data chunks, and CF.INFO reported the full inserted
count on both sides while the replica held nothing.

The suite already runs once with --use-slaves, but that variant only asserts
the primary's replies. Nothing ever reads the replica.

Add tests/pytest/test_replication.py, a table of one representative
invocation per write command (15 of them). Each row runs on the primary,
waits for the replica to ack, then compares the key set and the document
read back in full.

The invocation per command is chosen to be the form most likely to diverge
rather than the simplest one: a mid-array index over a tail append, a
null-valued JSON.MERGE (which deletes the member) over a plain overwrite, a
float delta on an integer (which promotes the stored type), create-on-write
over overwriting an existing key. No argument permutations.

JSON.GET '$' is the fingerprint rather than DUMP: unlike a probabilistic
sketch, a JSON document has no internal state the full read does not show,
and this suite sets Defaults.decode_responses, so a binary RDB payload
cannot come back over these connections.

A read that returns the type default proves nothing, since both sides match
trivially. Every row asserts the primary's read-back is non-default before
comparing it, and asserts WAIT actually acked rather than timing out.

testEveryWriteCommandIsCovered enumerates write commands from the running
server via COMMAND LIST FILTERBY MODULE and fails if any is missing from the
table, so a newly added command cannot land without a replication test.

Co-Authored-By: Claude Opus 5 <[email protected]>
@codecov

codecov Bot commented Sep 29, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 88.06%. Comparing base (180c471) to head (da6b722).

Additional details and impacted files
@@           Coverage Diff           @@
##           master    #1656   +/-   ##
=======================================
  Coverage   88.06%   88.06%           
=======================================
  Files          17       17           
  Lines        5957     5957           
=======================================
  Hits         5246     5246           
  Misses        711      711           

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@LiranAbir
LiranAbir merged commit 3bde2f3 into master Sep 30, 2026
113 of 114 checks passed
@LiranAbir
LiranAbir deleted the MOD-18948-json-replication-verification branch September 30, 2026 09:04
LiranAbir added a commit that referenced this pull request Oct 8, 2026
…1662)

Two of the three nightly failures since #1656 are the same hang, in the
--use-aof env group, after test_replication had already passed:

  09-30 x64-bionic  and  10-01 x64-rocky10:
    test_replication:testEveryWriteCommandIsCovered  [PASS]
    Test Timeout, printing trace.
    redis_std.py stopEnv -> _stopProcess(SLAVE) -> process.communicate()

RLTest sends SIGTERM to the test's replica, waits 30 s, then calls
communicate() with no timeout; the replica, running with AOF, did not exit.
The hang predates this test -- test_mset_replication_in_aof hits it too,
with a replica running AOF -- but in the --use-aof group no other test
starts a replica, so test_replication is what brings one in. Raising the
WAIT timeout would not help: the test itself passes.

- testWriteCommandsReplicate skips under AOF, before it builds the replica
  env. Replication stays covered by the general and --use-slaves groups.
- testEveryWriteCommandIsCovered no longer asks for a replica at all: it only
  reads the command table, and it is the test whose teardown hung on both
  legs.

Locally, every tests.sh variant passes, and under --use-aof no replica is
started any more.

Co-authored-by: Claude Opus 5.5 <[email protected]>
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.

2 participants