Skip to content

MOD-21370 : test the string table budget of RDB encoding v5 - #1705

Open
LiranAbir wants to merge 4 commits into
masterfrom
MOD-20882-rdb-dictionary-budget
Open

LiranAbir wants to merge 4 commits into
masterfrom
MOD-20882-rdb-dictionary-budget

Conversation

@LiranAbir

@LiranAbir LiranAbir commented Nov 17, 2026 •

Copy link
Copy Markdown
Contributor

Based on master, apart from #1699, so this PR can merge on its own and its failing test can be discussed separately (see MOD-21358 below).

It also carries #1699's test_short_read.py fix (the first commit). Without it, test_short_read.py sends every server's log to /dev/null in a full CI run, and the tests here that read the server log skip. The change is the same in both PRs, so whichever merges second keeps it as is.

Why

json-rdb-dictionary-max-memory-percent caps the string table of one RDB encoding v5 save (#1682). The budget formula, the clamping of module arguments and the table resets are unit-tested against a fake module API, and test_rdb_dictionary.py covers a tiny table's reset markers and the writer turned off. Nothing checked on a real server that the budget follows used_memory, that a setting change applies from the next save only, that an out-of-range module argument is refused, or that a full table stays within its budget in the fork child. This is §3.6 of the MOD-20882 OSS test plan.

What

A new tests/pytest/test_rdb_dictionary_budget.py, test-only. Every test runs on one plain server and skips in the --use-slaves, --use-aof, oss-cluster and existing-env lanes. The module's log lines are the oracle, and every test reloads and compares every document.

  • test_a_config_change_applies_from_the_next_save: at 7%, a SAVE logs mode=stream percent=7 with budget_bytes within 10% of 7% of used_memory. A BGSAVE that starts at 7% (slowed with rdb-key-save-delay) keeps streaming while CONFIG SET turns sharing off. Its RDB reloads as a stream, and the next SAVE logs mode=plain reason=off.
  • test_a_module_argument_that_does_not_parse_is_refused: a server of its own started with the module argument 100 comes up (the control), and one started with abc does not.
  • test_a_module_argument_outside_0_to_100_is_refused: servers started with -1 and 101 must not come up. This test fails until MOD-21358 is fixed: redismodule-rs uses a module argument as the config's default without checking its range, so both load and each save clamps the value. The range check of CONFIG SET is already covered by test_rdb_dictionary.py.
  • test_a_table_that_fills_resets_and_stays_within_its_budget: 200 documents in pairs that share 1,000 distinct strings per pair, plus 10 strings in every document.
    • At 100%, the save defines each of the 100,010 strings exactly once, references them 101,990 times, and never resets.
    • At 1%, the table resets (99 times locally) and still references strings, and that RDB reloads every document.
    • On Linux with jemalloc, the fork child's rdb_last_cow_size shows the table: against sharing off, the full table adds more than the 1% budget plus 1 MB, and the 1% table adds no more than that. macOS reports no copy-on-write, and valgrind and sanitizer builds use libc malloc, so the memory check runs only where it means something.

The file imports only common.TimeLimit and RLTest, and sets no Defaults at module level.

Findings:

  • The plan expects reason=budget for a budget too small for any entry. The code logs it only when the budget comes out at 0 bytes, which a running server never does (1% of used_memory is tens of KB). A small table fills and resets instead, which is what the last test checks.
  • An out-of-range module argument (150, -5) loads: CONFIG GET reports it as given, while saves use the clamped value. The developer confirmed it should be refused. Filed as MOD-21358; the range test above fails until it is fixed.
  • A module argument that is not a number (abc) makes the module fail to load, so the server aborts. An out-of-range one should do the same.

Testing

Run locally (macOS arm64) against Redis unstable 456b4b9a, with RedisJSON built from this branch. The mutant and Linux rows are from the first commit, run with test_short_read loaded too, as in CI:

Run Result
plain lane 3 passed, test_a_module_argument_outside_0_to_100_is_refused fails (MOD-21358)
--use-slaves, --use-aof, --env oss-cluster 4/4 skipped
Mutant: the save table ignores its budget only test_a_table_that_fills_resets_and_stays_within_its_budget fails (resets=0)
Mutant: the setting is read once only test_a_config_change_applies_from_the_next_save fails (the next save still logs percent=7)
Linux arm64 (Docker, redis:8.10.1, module built for Linux), the copy-on-write numbers of the last test, 5 rounds full table +4.6 MB, 1% table +0.29 MB against a 68 KB budget, so the 1 MB slack separates them both ways

🤖 Generated with Claude Code


Note

Low Risk
Test-only changes with no production code; one new test is expected to fail until MOD-21358 lands.

Overview
Adds test_rdb_dictionary_budget.py, end-to-end pytest coverage on a plain Redis server for RDB encoding v5’s json-rdb-dictionary-max-memory-percent string table budget. Tests drive SAVE/BGSAVE, parse module JSON RDB dictionary log lines, and DEBUG RELOAD NOSAVE to verify documents round-trip.

Coverage includes: 7% budget tied to used_memory, config snapshotted for in-flight saves vs next-save behavior when sharing is turned off, module load refusal for non-numeric args (with a known-failing case for -1/101 until MOD-21358), and 1% budget exercising table resets while staying within budget (optional jemalloc COW checks on Linux).

test_short_read.py stops setting Defaults.no_log = True globally; only testShortReadJson toggles it so other tests (including the new budget suite) can use server logs.

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

@codecov

codecov Bot commented Nov 17, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 87.74%. Comparing base (ccd924c) to head (da86b49).

Additional details and impacted files
@@                        Coverage Diff                        @@
##           MOD-20882-rdb-dictionary-cluster    #1705   +/-   ##
=================================================================
  Coverage                             87.74%   87.74%           
=================================================================
  Files                                    18       18           
  Lines                                  6723     6723           
=================================================================
  Hits                                   5899     5899           
  Misses                                  824      824           

☔ 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.

@cursor cursor Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Stale Bugbot comment from a previous run.

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes using high effort and found 1 potential issue.

Fix All in Cursor

❌ 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 fba739c. Configure here.

LiranAbir and others added 4 commits November 18, 2026 15:05
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>
A new tests/pytest/test_rdb_dictionary_budget.py checks
json-rdb-dictionary-max-memory-percent on a real server, in the plain lane:

- the budget is the configured share of used_memory at save start, a
  running BGSAVE keeps the setting it started with, and the next save
  takes a CONFIG SET made meanwhile;
- a module argument of 150 counts as 100 and one of -5 turns sharing
  off, while CONFIG SET still refuses both;
- a 1% table resets and still shares strings, a full table defines each
  string once, and every document reloads. On Linux with jemalloc, the
  fork child's copy-on-write memory shows the 1% table stays within its
  budget while a full table does not.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…abase

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>
The developer confirmed that a json-rdb-dictionary-max-memory-percent
module argument outside 0 to 100 should stop the module from loading,
not be clamped (MOD-21358). Replace the two tests that asserted the
clamp:

- test_a_module_argument_that_does_not_parse_is_refused: a server
  started with 100 comes up, and one started with abc does not.
- test_a_module_argument_outside_0_to_100_is_refused: servers started
  with -1 and 101 must not come up. It fails until MOD-21358 is fixed
  in redismodule-rs.

The range check of CONFIG SET stays covered by test_rdb_dictionary.py.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@LiranAbir
LiranAbir force-pushed the MOD-20882-rdb-dictionary-budget branch from fba739c to b5ba16a Compare November 18, 2026 13:07
@LiranAbir
LiranAbir changed the base branch from MOD-20882-rdb-dictionary-cluster to master November 18, 2026 13:07
@LiranAbir LiranAbir changed the title MOD-20882: test the string table budget of RDB encoding v5 MOD-21358: test the string table budget of RDB encoding v5 Nov 18, 2026
@LiranAbir LiranAbir changed the title MOD-21358: test the string table budget of RDB encoding v5 MOD-20882 : test the string table budget of RDB encoding v5 Nov 18, 2026
@LiranAbir LiranAbir changed the title MOD-20882 : test the string table budget of RDB encoding v5 MOD-21358 : test the string table budget of RDB encoding v5 Nov 18, 2026
@LiranAbir LiranAbir changed the title MOD-21358 : test the string table budget of RDB encoding v5 MOD-21370 : test the string table budget of RDB encoding v5 Nov 18, 2026

This branch has not been deployed

No deployments
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.

1 participant