Repository navigation
MOD-20882: test RDB encoding v5 across shards, replication, slot migration, damaged input, data shapes and defrag - #1699
Conversation
test_rdb_dictionary.py checks one server and skips cluster mode, and the CI cluster lane runs one shard. The new file starts its own cluster of 3 shards, each with a replica, and checks that every shard writes and loads its own stream: - a SAVE on each master logs mode=stream and refers to its keys' shared strings, and the RDB is more than 4 times smaller than with sharing off; - a restart and DEBUG RELOAD of each shard load that stream and keep the data; - each replica full-syncs a stream from its master and holds the same data; - a promoted replica writes and reloads its own stream. The tests skip outside the oss-cluster lane, including existing-env. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #1699 +/- ##
==========================================
+ Coverage 87.74% 87.83% +0.08%
==========================================
Files 18 18
Lines 6723 6723
==========================================
+ Hits 5899 5905 +6
+ Misses 824 818 -6 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
test_short_read.py set Defaults.no_log = True when it was imported. RLTest imports every test file before a run, so every server in a full run logged to /dev/null, and every test that reads the server log skipped in CI: the three new cluster tests, and three tests of test_rdb_dictionary.py. testShortReadJson now builds its own Env with no_log set, and restores the default right after, so only its servers log nowhere. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
gabsow
left a comment
There was a problem hiding this comment.
Reviewed at ccd924c. Approving.
- The
test_short_read.pychange makes these tests run in CI. At188cfce, before it, the x64-jammy job skipped all six log-reading tests in all four lanes. Atccd924c:- the three new tests pass in the oss-cluster lane;
test_bgsave_reloads_the_fork_time_snapshot_under_concurrent_updates,test_dictionary_resets_with_tiny_table_round_tripandtest_writer_off_writes_self_contained_recordspass in the plain and--use-slaveslanes;testShortReadJsonstill passes in the plain lane.
- The scoped
no_logcan't leak in CI. RLTest 0.7.31 doesn't comparenoLogwhen it reuses an env. But it reuses envs only with--env-reuseor onexisting-env, and neither applies in CI: CI passestests.shonly--no-progress, andtests.shadds no reuse flag. So every test gets a fresh env, and the default is restored before the next test starts. - The checks test what they say:
- The save check counts only lines from the pid of the last save that started. A replica's sync child writing in the same window doesn't count.
- In the full-sync test,
sync_fullrises only after the replica reconnects, and the link isuponly after the load. When both hold, the new full sync has finished. - In the full-sync test, the replica must hold every one of the master's keys, with the same contents.
Three suggestions, none blocking:
1. A missing log still skips the test without failing it. _ServerLog, like _LogWatch in test_rdb_dictionary.py, calls env.skip() when it can't open the log. That's why all six tests were skipped with CI still green. These three run only in the oss-cluster lane, where the log should always exist. If they fail there instead of skipping (or whenever CI is set), the next change that silences the logs will show up. _LogWatch could do the same.
2. The DEBUG RELOAD step checks only the master. The comment says "on the master and its replica", and RLTest's dumpAndReload(shardId=...) does save and reload both. But only the master's log is checked. A second _ServerLog(env, shard, 'slave'), with the same two checks, would cover the replica too.
3. After a restart or reload, a shard that lost keys still passes. _assert_shard_documents checks only that the shard has more than one key and that each key it finds matches. Its docstring says "exactly the documents of its slots", but a shard that loads 2 of its ~100 keys passes. min_refs=len(keys) - 1 is computed from that same reduced count, so the refs check gets easier too. This applies to the restart, DEBUG RELOAD and promoted-replica checks. Recording each shard's key set before the restart or reload and comparing after would close it. The one-line version: assert that the masters' key counts add up to KEYS.
CI is green. freebsd.yml fails, and it fails on master too.
I did not run the code. This is from reading:
- the diff;
test_rdb_dictionary.pyandtest_short_read.pyatccd924c;- the x64-jammy job logs at
188cfceandccd924c; - RLTest 0.7.31's
env.py,__main__.py,redis_cluster.pyandredis_std.py.
`redis-cli --cluster reshard` moves a slot with MIGRATE, and the target RESTOREs every key without a load session, so each payload must be self-contained. A new test file starts its own 2-shard cluster and moves a slot of documents that share long strings with the target's own documents: one key alone, then COPY and REPLACE over KEYS, and again while the source runs a BGSAVE. The documents must arrive intact, the target must refuse no record, and both shards must still save and load a stream afterwards. Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
test_rdb_dictionary.py syncs a replica from a file and over the RDB channel into an empty replica. The new tests add the socket sync on the replication link itself, a replica asked for swapdb, a replica of a replica, and a replica that restarts on its own RDB and resumes with a partial sync. Each one checks that the sending side saved a stream, the receiving side loaded it with no refused record, and every document arrived. swapdb never runs with RedisJSON loaded: the module doesn't declare that it handles async loading, so the replica loads from a file. The test pins that. Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
A new test_rdb_dictionary_asm.py starts its own 2-shard cluster and holds a slot export open after its snapshot fork, so saves can run during it: - A BGSAVE on the exporting node logs mode=local reason=asm, while one on the importing node keeps streaming. Writes to shared-string keys during the snapshot reach the destination intact, nothing is refused, and the source trims the keys it gave away. Afterwards both nodes save and reload a stream again. - After a cancelled export and after one that fails at its handoff, the source streams again. Stacks on #1699. Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
* MOD-20882: test RDB encoding v5 with unusual data shapes A new tests/pytest/test_rdb_dictionary_shapes.py, test-only, plain lane only. Each test saves a stream, checks the counters the module logged for it, and reloads every document exactly: - strings under 8 UTF-8 bytes (and empty ones) are never shared, while 8-byte, emoji and CJK strings are; - a document larger than a 1% table fills it mid-document: the rest stays inline, and the next document starts with a reset; - a 2 MB string is written once for three documents, next to FP32 typed arrays that keep their type through the reload; - COPY, JSON.MERGE and a value equal to an object key add owners; - STRAPPEND, JSON.DEL, JSON.SET and DEL between saves still round-trip; - a shared string at JSON.SET's nesting limit round-trips. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * MOD-20882: skip the stream checks on Flex Flex saves each value on its own (mode=local reason=flex), so it writes no stream for these tests to check. test_rdb_dictionary.py skips Flex the same way. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
* MOD-20882: test truncated and partial RDB encoding v5 input Adds tests/pytest/test_rdb_dictionary_truncated.py (test plan section 3.7): - A stream RDB cut at record boundaries and inside records, including inside a definition and inside a record that refers to it: the server stops with a short read, the module refuses nothing and nothing crashes. - A stream RDB missing a later definition record, or a reset record: the load is refused with base_id_mismatch at the record after the gap. - A replica whose full sync from a mock master is cut inside a record, then between two records, retries and loads the whole stream. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * MOD-20882: skip the stream checks on Flex Flex saves each value on its own (mode=local reason=flex), so it writes no stream for these tests to check. test_rdb_dictionary.py skips Flex the same way. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
…le in the plain lane (#1706) * MOD-20882: test RDB encoding v5 with active defrag and in the plain-lane AOF path Redis defragments while it loads only during an AOF load, where a stream load holds the strings it interned. A defrag cycle that starts while the AOF tail replays must leave the string cache to the load: the save after it must define each shared string once. A defrag cycle between two saves moves every string, and the second save must still share them. The AOF preamble test runs in the plain lane, the only lane that the sanitizer job runs. test_rdb_dictionary.py checks the preamble only in the --use-aof lane. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * MOD-20882: skip the stream checks on Flex and start from an empty database Flex saves each value on its own (mode=local reason=flex), so it writes no stream for these tests to check. test_rdb_dictionary.py skips Flex the same way. The checks count every key the server holds, so the test env helper now runs FLUSHALL first, in case a run reuses a server. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes using high effort and found 1 potential issue.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, have a team admin enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit 8b4c85d. Configure here.
The cluster and MIGRATE tests checked only the keys that SCAN found after a restart, a DEBUG RELOAD, a promotion or a slot move, so a load or a MIGRATE that lost keys still passed while more than one key was left (Cursor Bugbot). Each check now compares the keys a server holds with the keys it should hold: - test_rdb_dictionary_cluster.py: the keys each shard held once the documents were written. The full-sync check also catches extra keys on the replica now. - test_rdb_dictionary_migrate.py: after the reshard, the target holds its own keys plus every moved key, and the source holds none of the moved keys. A DEBUG RELOAD keeps the keys the server held before it. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
gabsow
left a comment
There was a problem hiding this comment.
Re-reviewed at d43e48b. My approval at ccd924c was dismissed automatically when 1821ef5 was pushed. Approving again: CI is green, and every new test runs and passes in its lane.
- Key sets are now checked exactly. In the cluster and migrate files,
_load_documentsrecords each shard's keys, and the checks after a reload compare the exact set. The ASM file already did. That covers my third earlier suggestion and the cursor[bot] finding. - No new test skips everywhere. In the x64-jammy job, all 22 new tests pass in at least one lane:
- the cluster, ASM and migrate tests in oss-cluster;
- the replication tests in
--use-slaves; - the shapes, defrag and truncated tests in the plain lane.
Please fix the description: CI's sanitizer and valgrind jobs run neither tool. That's true on master as well as here.
san-run-tests/action.ymldeclares an input namedsanitizer, but it readsinputs.san. So the job builds and tests with an empty value: the log showsmake pytest LOG=1 CLEAR_LOGS=0 SAN= QUICK=1.flow-linux.ymlpassesVG=1totests.shas an argument.tests.shtreats$1as the module path, butMODULEis already set, so it shiftsVG=1away. The valgrind job runs all four lanes,--use-slavesincluded, and prints no valgrind output.
So these statements aren't true at the moment:
- "this is the first time the AOF preamble stream runs under the sanitizer", and the matching docstring of
test_an_aof_preamble_streams_and_loads_in_the_plain_lane; - the defrag tests "skip on the macOS, sanitizer and valgrind builds". They pass in both of those jobs and skip only on macOS;
- "Valgrind skips the
--use-slaveslane".
The CI wiring needs its own fix, in a separate PR.
Suggestions, none blocking:
- A missing log still skips the test without failing it (my first earlier suggestion). All seven files now copy the
env.skip()pattern, and nearly every new test depends on it. One shared helper that fails whenCIis set would cover all of them. - Two checks are weaker than what the tests claim:
- In
migrate.py,_reload_and_checkasserts onlyrefs >= len(keys) - 1. That's the only check behind "the target shares the migrated documents' strings with its own", and a target holding its own copies of the strings would still pass. Assertingdefs, asdefrag.pydoes withdefs=SHARED_STRINGS, would prove it. test_defrag_between_two_saves_keeps_the_strings_sharedpasses nodefs=either (defrag.py:366). Its docstring says the second save must find one copy of each shared string. If defrag can still be mid-cycle when the save forks,defs <= 2 * SHARED_STRINGSmay be the right bound.
- In
- The cluster file's
DEBUG RELOADstep still checks only the master (my second earlier suggestion). - The log, wait and server-launch helpers are copied into all seven files, and the copies already differ. There are four
_ServerLogvariants, and onlydefrag.py's_expect_stream_savetakesdefs=. Every file already importscommon.py, so moving the helpers there doesn't bring back the import problem the description mentions.
dismiss_stale_reviews is on, so a push for any of these will dismiss this approval again. Editing the description won't.
CI: 65 checks pass. FreeBSD fails at startup, as it does on master.
I did not run the code. This is from reading:
- the seven test files and the
test_short_read.pychange atd43e48b; tests.sh,san-run-tests/action.yml,flow-linux.ymlandflow-sanitizer.yml;- the x64-jammy, sanitizer and valgrind job logs at this head;
- the PR timeline.

Why
test_rdb_dictionary.pycovers RDB encoding v5 (#1682) on one server, and every test in it skips cluster mode. The CI cluster lane also runs a single shard. So nothing checked v5 per shard, across replication paths, slot migration, MIGRATE, damaged input, unusual data shapes or active defrag. This PR holds those tests from the MOD-20882 OSS test plan.test_rdb_dictionary_cluster.pyoss-clustertest_rdb_dictionary_asm.pyoss-clustertest_rdb_dictionary_replication.py--use-slavestest_rdb_dictionary_migrate.pyoss-clustertest_rdb_dictionary_truncated.py--use-slavestest_rdb_dictionary_shapes.pytest_rdb_dictionary_defrag.pyNot in this PR:
What
Test-only: 7 new test files and a fix to
test_short_read.py. Each new file skips outside its lane, existing-env included. Each one imports onlycommonand RLTest, not helpers from other test files, so a flow lane that removes another test file can't break its imports. None setsDefaultsat module level. The module's log lines are the oracle (phase=persistence_start mode=...,phase=persistence_ended defs= refs= resets= poisoned=,phase=loading_ended,status=refused), and every test reloads and compares its documents.§3.1 Several shards (
Env(shardsCount=3, useSlaves=True))test_every_shard_saves_and_reloads_its_own_stream: aSAVEon each master streams, and its RDB is more than 4 times smaller than with sharing off. A restart and aDEBUG RELOADof each shard load that stream, and every document comes back.test_every_replica_full_syncs_a_stream_from_its_master: afterDEBUG CHANGE-REPL-ID, each master's sync child writes a stream, and each replica loads it and holds the same documents.test_a_promoted_replica_saves_and_reloads_its_own_stream: a replica promoted withREPLICAOF NO ONEwrites its own stream from the strings it interned while it replicated, and reloads it. RLTest starts the replicas outside cluster mode, soCLUSTER FAILOVERis not available.§3.2 Atomic slot migration (2 shards)
A node that exports slots writes no cross-key stream (
reason=asm). The tests hold an export open after its snapshot fork (rdb-key-save-delayon the source,key-load-delayon the destination), as Redis's own ASM tests do.test_a_save_during_a_slot_export_is_self_contained: a BGSAVE on the importing node streams. A BGSAVE on the exporting node logsmode=local reason=asm, and the export is still running when it ends. Keys written during the snapshot arrive as last written, nothing is refused, the source trims every migrated key, and both nodes stream again afterwards.test_the_source_streams_again_after_a_cancelled_or_failed_export: after a cancelled export, and after one failed at its handoff (DEBUG ASM-FAILPOINT), the next BGSAVE streams again, and its RDB loads.§3.3 Replication modes
test_every_full_sync_mode_loads_a_stream: three full syncs from a diskless master: the RDB channel into a replica that loads from a file and holds keys of its own, the replication link into an empty replica that parses the socket, andrepl-diskless-load swapdb. Each saves a stream on the master, loads a stream on the replica, refuses nothing, and leaves the replica with exactly the master's documents.test_a_replica_of_a_replica_syncs_a_stream_from_the_replica: a replica's sync child writes a stream from the strings it interned while it loaded, and a third server loads it.test_a_restarted_replica_reloads_its_own_stream_then_resyncs: a replica loads its own stream after a restart and resumes with a partial sync.§3.5 MIGRATE (2 shards)
The
redis-cli --cluster reshardsteps:SETSLOT IMPORTING/MIGRATING, MIGRATE,SETSLOT NODE. A MIGRATE payload must be self-contained, or the target refuses it (reason=no_stream).test_a_resharded_slot_keeps_its_shared_string_documents: MIGRATE moves one key, then the rest withCOPY ... KEYS, thenREPLACE ... KEYSoverwrites them. The target refuses nothing and holds every document. Both shards then save and load a stream, and the target shares the migrated documents' strings with its own.test_a_slot_moves_while_the_source_runs_a_bgsave: the whole slot moves while the source's BGSAVE child runs. The child still writes a stream (poisoned=false), and the target holds every document.§3.7 Truncated input
test_a_stream_rdb_cut_short_stops_the_load_without_a_crash: a 40-key stream RDB cut at 9 points, at record boundaries and inside records. A server started on each cut file stops withShort read or OOM loading DB, without a crash.test_a_stream_rdb_missing_a_record_from_its_middle_is_refused: removing a record that defines a string, or a whole reset record, makes the load refuse the next one (reason=base_id_mismatch).test_a_full_sync_cut_while_the_replica_loads_is_retried_and_loads_the_whole_stream: a mock master cuts the RDB transfer inside a record, then between records. The replica keeps running, and the third, whole transfer loads all 400 documents.§3.9 Data shapes
test_only_strings_of_eight_bytes_or_more_are_shared: the 8-byte minimum counts UTF-8 bytes, not characters (a 7-byte string defines nothing, 8 bytes, emoji and CJK givedefs=3 refs=6).test_a_document_larger_than_the_table_keeps_the_rest_inline: at 1%, one document with 20,000 strings defines fewer than that and writes the rest inline, and the next document starts with a cleared table.test_megabyte_strings_and_typed_arrays_next_to_shared_strings: a 2 MB string is written once for 3 documents, and FP32 typed arrays keep their element type after the reload.test_copy_merge_and_a_key_used_as_a_value_add_owners:COPY,JSON.MERGEand a value equal to an object key add owners of a string.test_documents_changed_between_saves_round_trip:JSON.STRAPPEND,JSON.DEL,JSON.SETandDELbetween two saves.test_a_shared_string_at_the_nesting_limit_round_trips: a shared string 126 levels deep, the deepestJSON.SETaccepts.§3.10 Defrag and memory checkers
test_an_aof_preamble_streams_and_loads_in_the_plain_lane: an AOF turned on at runtime writes a stream preamble, andDEBUG LOADAOFloads it. The sanitizer job runs only the plain lane, so this is the first time the AOF preamble stream runs under the sanitizer.test_active_defrag_during_an_aof_stream_load_keeps_the_strings_shared: an active defrag cycle starts and stops during the load, and the next save still defines each shared string once.test_defrag_between_two_saves_keeps_the_strings_shared: after 2 full defrag cycles, a BGSAVE still streams and its RDB loads.The two defrag tests need Redis built with its jemalloc, so they skip on the macOS, sanitizer and valgrind builds.
test_short_read.pyfixtest_short_read.pysetDefaults.no_log = Truewhen it was imported. RLTest imports every test file before a run, so every server in a full run logged to/dev/null, and every test that reads the server log skipped in CI. That hid the tests above and 3 tests intest_rdb_dictionary.py(test_bgsave_reloads_the_fork_time_snapshot_under_concurrent_updates,test_dictionary_resets_with_tiny_table_round_trip,test_writer_off_writes_self_contained_records). NowtestShortReadJsonbuilds its ownEnvwithno_logset and restores the default right after, so only its servers log nowhere.Findings
repl-diskless-load swapdbnever runs with RedisJSON loaded: the replica logsSkipping diskless-load because there are modules that are not aware of async replicationand loads from a file, because RedisJSON doesn't setHANDLE_REPL_ASYNC_LOAD. The replication test pins that fallback.--use-slaveslane, and the sanitizer job runs only the plain lane.Testing
Each section was run locally (macOS arm64, Redis
unstable456b4b9a, RedisJSON built from these branches, withtest_short_readloaded as in CI). Each section was also run with sharing off, or against a module changed to break the rule it covers, and its tests failed there, as expected. The full results are in #1700–#1704 and #1706.Before the merge, CI on each PR showed every new test
[PASS]in its lane on every Linux and macOS job, with no failed test in any lane. On macOS, the 2 defrag tests skip, as described above.🤖 Generated with Claude Code
Note
Low Risk
Test-only changes with no production code; risk is limited to CI time and harness behavior (e.g.
Defaults.no_logscope).Overview
Adds seven new pytest modules (MOD-20882) that exercise RDB encoding v5 beyond single-server
test_rdb_dictionary.py: each file targets a CI lane, skips elsewhere, and asserts behavior viaJSON RDB dictionarylog lines (mode=stream/mode=local reason=asm,defs/refs/resets,status=refused) plus document round-trips.Coverage includes 3-shard cluster save/reload, replica full sync and promoted replica; atomic slot migration (self-contained export saves vs streaming importer); replication full-sync variants, replica-of-replica, and restart with partial resync; MIGRATE resharding including BGSAVE overlap; truncated/partial v5 streams and cut socket full sync retry; sharing rules (8-byte UTF-8 minimum, table budget, megabyte strings, nesting limit); and AOF preamble + active defrag (jemalloc-only defrag tests skip on macOS/sanitizer/valgrind).
test_short_read.pyno longer setsDefaults.no_log = Trueat import time;testShortReadJsontoggles it only for its ownEnvso log-oracle tests are not skipped in full CI runs.Reviewed by Cursor Bugbot for commit d43e48b. Bugbot is set up for automated code reviews on this repo. Configure here.