feat: Add command metadata and update tests - #78
bravo1goingdark wants to merge 8 commits into
Conversation
4b981f0 to
01cb0cd
Compare
| "bloom", | ||
| ] | ||
| commands: [ | ||
| ["BF.ADD", bloom_add_command, "write fast deny-oom", 1, 1, 1, "fast write bloom"], |
There was a problem hiding this comment.
Does this remove the bloom and other ACL categories from all the commands? Can you run the integration tests to validate if this passes?
You can check the valkey_module! macro to see how the command creation works in there. Specifically, how the ACL category is set through it
f6b7b22 to
a90bf9e
Compare
This commit adds the `valkey_command` macro to all the bloom filter commands in `src/lib.rs`. This macro provides metadata about the commands, such as their arity, flags, and key specifications. This is important for Valkey to properly handle the commands. The tests in `tests/test_bloom_command.py` have been updated to reflect the new command arities and to add a new test that verifies that the key specifications are present for the commands that have them. Finally, some string formatting in `src/bloom/data_type.rs` and `src/bloom/utils.rs` has been updated to use the more modern and efficient f-string style formatting. Signed-off-by: Ashutosh Kumar <kumarashutosh34169@gmail.com>
Signed-off-by: Ashutosh Kumar <kumarashutosh34169@gmail.com>
…mmand] Signed-off-by: bravo1goingdark <kumarashutosh34169@gmail.com>
a90bf9e to
e6323d7
Compare
Signed-off-by: bravo1goingdark <kumarashutosh34169@gmail.com>
Signed-off-by: bravo1goingdark <kumarashutosh34169@gmail.com>
|
|
should i close this pr ? |
|
We will take a look at the latest PR here..... @zackcam - Do you have some time this week to help review this? |
I should be able to take a look this week at it. I'll try and make time to look at it |
| arity: 3, | ||
| key_spec: [{ | ||
| begin_search: Index({ index: 1 }), | ||
| find_keys: Range({ last_key: 1, steps: 1, limit: 0 }), |
There was a problem hiding this comment.
Maybe I'm reading wrong: https://valkey.io/topics/key-specs/ but should these have last_key as 0? so like 0, 1, 0 would be the same for all I think?
There was a problem hiding this comment.
I was looking at:
The SET command has a range of 0, 1 and 0.
Which I think would be the same sort as we do?
There was a problem hiding this comment.
You were reading it right: lastkey is relative to begin_search, so 0 means only the first key. Updated all 9 BF.* commands to Range({ last_key: 0, steps: 1, limit: 0 }).
This also fixes the legacy values derived from it — COMMAND INFO now reports first/last/step as 1, 1, 1 instead of 1, 2, 1 (previously the value argument was reported as a key). The test now asserts both the key spec range and those legacy positions.
| self.verify_command_arity('BF.INFO', -2) | ||
| self.verify_command_arity('BF.INSERT', -2) | ||
|
|
||
| def test_bloom_command_keyspecs_present(self): |
There was a problem hiding this comment.
For this do we want to check that keyspecs are correct not just present?
There was a problem hiding this comment.
Good call — replaced test_bloom_command_keyspecs_present with test_bloom_command_keyspecs, which now checks the actual values for all 9 commands instead of presence for 4:
- key spec flags (RW/insert for writes, RO/access for reads)
begin_searchtypeindexwith index 1find_keystyperangewith0, 1, 0- legacy
first_key_pos/last_key_pos/step_count= 1/1/1
Verified the assertions actually bite: with last_key back at 1 the test fails on last_key_pos.
| /// Command handler for BF.ADD <key> <item> | ||
| #[valkey_command({ | ||
| name: "BF.ADD", | ||
| summary: "Add a single item to a bloom filter; creates the filter if it does not exist", |
There was a problem hiding this comment.
I think we want these to be the same as commands json files. If those aren't punctually correct I'm fine with us changing those to match these. (This one is same idea just different wording on it)
There was a problem hiding this comment.
Aligned the three that differed: BF.ADD, BF.MADD and BF.LOAD summaries now use the exact wording from src/commands/*.json (the other six already matched).
While diffing the two, the JSON arity for BF.MADD/BF.MEXISTS said 3 but both are variadic, so I changed those to -3 to match the macro and what the server reports. Happy to split that into a separate change if you'd rather keep the JSON edits out of this PR.
The find_keys range for all BF.* commands now uses last_key 0 instead of 1, so the key spec describes only the single <key> argument instead of also treating the value argument as a key. This matches the range of 0, 1, 0 that SET uses as documented in the key specs documentation and fixes the legacy first/last key/step values reported by COMMAND INFO (1, 1, 1 instead of 1, 2, 1). Summaries of BF.ADD, BF.MADD and BF.LOAD now match the wording in the command JSON files. The arity of BF.MADD and BF.MEXISTS in those JSON files is corrected from 3 to -3 to match their variadic syntax. test_bloom_command_keyspecs_present is replaced by test_bloom_command_keyspecs, which validates the actual key spec values (flags, begin_search, find_keys range) and the legacy key positions for all 9 commands instead of only checking presence for 4 of them, and an arity assertion for BF.LOAD is added. Signed-off-by: bravo1goingdark <kumarashutosh34169@gmail.com>
|
Addressed all three review comments in 42fcf5f:
|
|
Navigate logical layers of code changes, visualize relationships, and explore their blast radius. No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Advanced Run ID: 📒 Files selected for processing (2)
Included review availability: Your plan provides up to 1 included review per hour; 0 remain after this review. 📝 WalkthroughWalkthroughBloom command handlers now declare metadata through attributes, with ACL categories assigned after the server-version check. Command arity and key-spec tests reflect the declarations. The change also updates Rust format strings and replication-test accounting assertions. ChangesBloom command metadata
Format string updates
Replication test accounting
Suggested reviewers: Change: Feature Merge Risk: ⚪ Minimal · up to No actionable issue remains that would prevent merging after normal checks. 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
zackcam
left a comment
There was a problem hiding this comment.
Just one comment on the test, I think utilizing the https://valkey.io/commands/command-getkeys/ might be a nicer way of checking
|
|
||
| def test_bloom_command_keyspecs(self): | ||
| for command, expected_flags in self.EXPECTED_BLOOM_KEYSPECS.items(): | ||
| self.verify_command_keyspec(command, expected_flags) |
There was a problem hiding this comment.
keys = self.client.execute_command('COMMAND', 'GETKEYS', command, 'k', 'item')
assert keys == [b'k'], f"{command} GETKEYS returned {keys}, expected [b'k']"
info = self.client.execute_command('COMMAND', 'INFO', command)[command]
assert (info['first_key_pos'], info['last_key_pos'], info['step_count']) \
== (1, 1, 1), f"{command} legacy key positions wrong: {info}"
specs = info['key_specifications']
assert len(specs) == 1, f"{command} expected 1 key spec, got {len(specs)}"
flags = {f.decode() if isinstance(f, bytes) else f
for f in specs[0]['flags']}
assert flags == expected_flags, \
f"{command} flags {sorted(flags)}, expected {sorted(expected_flags)}"
Maybe something like this would be cleaner for testing. Right now seems quite long of a test.
There was a problem hiding this comment.
Done in a9344bf — GETKEYS is the main check now and I dropped the field-by-field key spec assertions, so the test went from ~75 lines to ~30. It still catches the old bug: with last_key at 1, GETKEYS BF.ADD k item returns [k, item].
Two heads-ups from running it: sending GETKEYS as split args (execute_command('COMMAND', 'GETKEYS', ...)) errors because valkey-py runs its COMMAND INFO parser over the reply — one string works, same as the ACL test. And GETKEYS validates arity, so each command needs its own sample args.
There was a problem hiding this comment.
Perfect thank you, yeah I didn't actually make the changes locally to test my snippet sorry just wanted to give the general idea but looks good now. Will run the workflows and see about getting it merged
COMMAND GETKEYS is now the primary assertion: it proves the key spec extracts the filter key and nothing else, which covers the begin_search index and the find_keys range without inspecting them field by field. The legacy first/last key/step tuple and the key spec flags are still checked directly. Sample arguments after the key differ per command because GETKEYS validates arity. Verified the test still catches the old bug: with last_key 1, GETKEYS BF.ADD k item returns [k, item] instead of [k]. Signed-off-by: bravo1goingdark <kumarashutosh34169@gmail.com>
| was_rejected = primary_cmd_stats.get("rejected_calls", 0) == 1 | ||
| was_failed = primary_cmd_stats.get("calls", 0) == 1 and primary_cmd_stats.get("failed_calls", 0) == 1 | ||
| assert was_rejected or was_failed |
There was a problem hiding this comment.
Why did this have to change from the original?
There was a problem hiding this comment.
Because this PR gives the commands real arity metadata, so the server now catches the two arity mistakes before the module ever runs.
Before, all four reached the module: calls=1, failed_calls=1. Now BF.ADD key item1 item2 and BF.MADD key are rejected at the server: rejected_calls=1, calls=0. BF.RESERVE (bad error rate) and BF.INSERT (bad capacity) still run and fail inside the module, so they keep the original numbers.
I've replaced the rejected or failed with the exact expectation per command in 06f3e5e, so the reason is visible in the test. Checked on valkey 8.0, 8.1 and unstable — the replication test passes on all three.
The two arity mistakes in this list are now rejected by the server before the module runs, since the commands carry real arity metadata, so they show up as rejected_calls with no calls at all. BF.RESERVE and BF.INSERT still run and fail inside the module, keeping calls 1 and failed_calls 1. Replace "rejected or failed" with the exact expectation per command so the reason for the change is visible in the test itself. Verified against valkey 8.0, 8.1 and unstable. Signed-off-by: bravo1goingdark <kumarashutosh34169@gmail.com>
Add
#[valkey_command]Metadata & KeySpecs for Bloom Filter CommandsThis PR adds the
#[valkey_command]macro to all Bloom Filter commands insrc/lib.rs, enabling properSetCommandInfosupport through thevalkeymodule-rscrate.The macro now provides Valkey with complete metadata, including:
As a result,
COMMAND INFO BF.*now correctly reports the KeySpec metadata for each Bloom Filter command.Changes Included
Added
#[valkey_command]to all Bloom Filter commands:BF.ADDBF.MADDBF.EXISTSBF.MEXISTSBF.CARDBF.RESERVEBF.INFOBF.INSERTBF.LOADImplemented complete KeySpecs for each command:
begin_searchfind_keysrw,insert,update,access)Updated tests in
tests/test_bloom_command.py:Minor cleanup:
src/bloom/data_type.rssrc/bloom/utils.rsNotes / Limitations
The current version of
valkeymodule-rsdoes not support argument metadata (args:) inSetCommandInfo.Because of this limitation, this PR implements all supported metadata (KeySpecs), but cannot yet add full CLI argument autocomplete like the built-in
SETcommand.Once
argssupport is added upstream invalkeymodule-rs, I can follow up with another PR to provide complete argument specifications for full autocomplete.Verification
Example output of
COMMAND INFO BF.ADD, showing that KeySpec metadata is now present: