Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Package review PR #1

Open
wants to merge 57 commits into
base: test
Choose a base branch
from
Open

Package review PR #1

wants to merge 57 commits into from

Conversation

KarthikSubbarao
Copy link
Member

@KarthikSubbarao KarthikSubbarao commented Apr 29, 2024

This is a PR which merges current changes in unstable into an empty branch in order to help with a review code of the entire codebase.

@KarthikSubbarao KarthikSubbarao changed the title Package review Package review PR May 1, 2024
@KarthikSubbarao KarthikSubbarao self-assigned this May 1, 2024
src/commands/bloom.rs Outdated Show resolved Hide resolved
src/commands/bloom.rs Outdated Show resolved Hide resolved
src/commands/bloom.rs Outdated Show resolved Hide resolved
Comment on lines 276 to 296
let mut result = Vec::new();
match value {
Some(bf) => {
for item in input_args.iter().take(argc).skip(idx) {
result.push(RedisValue::Integer(bf.add_item(item.as_slice())));
}
Ok(RedisValue::Array(result))
}
None => {
if nocreate {
return Err(RedisError::Str("ERR not found"));
}
let mut bf = BloomFilterType::new_reserved(fp_rate, capacity, expansion);
for item in input_args.iter().take(argc).skip(idx) {
result.push(RedisValue::Integer(bf.add_item(item.as_slice())));
}
match filter_key.set_value(&BLOOM_FILTER_TYPE, bf) {
Ok(_) => Ok(RedisValue::Array(result)),
Err(_) => Err(RedisError::Str(ERROR)),
}
}
Copy link

Choose a reason for hiding this comment

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

Could we check the bloom filter exists or not first and then insert the data in a single flow. Don't like the code duplication around insertion.

Copy link
Member Author

Choose a reason for hiding this comment

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

I can create a separate function for multi adds and call it from both flows. I wanted to handle both through the same flow, however it will be out of reference scope and result in a moved error

pub struct BloomFilterType {
pub expansion: u32,
pub fp_rate: f32,
pub filters: Vec<BloomFilter>,
Copy link

Choose a reason for hiding this comment

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

Does the underlying support scalable bloom filters or do we need to support this mechanism?

Copy link
Member Author

Choose a reason for hiding this comment

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

This particular library does not have auto scaling

https://docs.rs/bloomfilter/1.0.13/bloomfilter/struct.Bloom.html

src/commands/bloom_util.rs Outdated Show resolved Hide resolved
Comment on lines 74 to 79
let new_capacity = filter.capacity * self.expansion;
let mut new_filter = BloomFilter::new(self.fp_rate, new_capacity);
// Add item.
new_filter.bloom.set(item);
new_filter.num_items += 1;
self.filters.push(new_filter);
Copy link

Choose a reason for hiding this comment

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

Shouldn't we fail the request if the expansion is much higher than we can support?

Copy link
Member Author

Choose a reason for hiding this comment

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

expansion really means expansion_rate. I can rename this variable if that would help clarify this.

I don't think there is a limit on the number of sub filters an object can have. But (if we want) we can define a config for this to either silently fail expansion (by allowing a set) beyond a limit of X sub filters per object OR explicitly return an error (without a set).

Copy link
Member Author

Choose a reason for hiding this comment

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

One other aspect we should handle this checking / rejecting based on memory overhead of every operation that creates a new BloomFilter object (BF.ADD, BF.MADD, BD.RESERVE, BF.INSERT, RDB Load). Before any of these operations, we should probably check the memory usage and reject the operations if there is not sufficient space. We have a mechanism to compute the estimated additional memory overhead per creation.

src/wrapper/bloom_callback.rs Show resolved Hide resolved
src/commands/bloom_data_type.rs Outdated Show resolved Hide resolved
KarthikSubbarao pushed a commit that referenced this pull request Aug 23, 2024
Signed-off-by: Viktor Söderqvist <[email protected]>
Co-authored-by: Madelyn Olson <[email protected]>
Signed-off-by: Karthik Subbarao <[email protected]>
Signed-off-by: Karthik Subbarao <[email protected]>
… objects. Update RDB load/save

Signed-off-by: Karthik Subbarao <[email protected]>
Signed-off-by: Karthik Subbarao <[email protected]>
Signed-off-by: Karthik Subbarao <[email protected]>
Signed-off-by: Karthik Subbarao <[email protected]>
Signed-off-by: Karthik Subbarao <[email protected]>
Signed-off-by: Karthik Subbarao <[email protected]>
Signed-off-by: Karthik Subbarao <[email protected]>
Signed-off-by: Karthik Subbarao <[email protected]>
Signed-off-by: Karthik Subbarao <[email protected]>
Signed-off-by: Karthik Subbarao <[email protected]>
Signed-off-by: Karthik Subbarao <[email protected]>
…oom module + Add basic sanity tests

Signed-off-by: Karthik Subbarao <[email protected]>
KarthikSubbarao and others added 8 commits September 14, 2024 00:26
…alse positive rate correctness

Signed-off-by: Karthik Subbarao <[email protected]>
Add unit testing for scaling & non scaling filters
…s, integration tests and ASAN testing

Signed-off-by: zackcam <[email protected]>
Adding github workflow for building, running format checks, unit tests, integration tests and ASAN testing
zackcam and others added 2 commits October 1, 2024 17:03
…ionality for more flexibility in the future (#6)

Signed-off-by: zackcam <[email protected]>
…ity (#7)

Add test for bloom command arity, behavior and basic error

Set up a base case for valkey bloom filter module

Optimize BF.INSERT arguments handling and BF.INFO response when NONSCALING set

Add test for basic valkey command

Signed-off-by: Vanessa Tang <[email protected]>
zackcam and others added 2 commits October 10, 2024 12:10
…lters and other core functionality validation (#15)

* Add Integration Testing for correctness of scaling and non scaling filters, and maxmemory, memory usage, type, encoding, etc

* Refactor correctness integration tests

Signed-off-by: Karthik Subbarao <[email protected]>

* Fix comment

Signed-off-by: Karthik Subbarao <[email protected]>

* Refactor

Signed-off-by: Karthik Subbarao <[email protected]>

* Fix import

Signed-off-by: Karthik Subbarao <[email protected]>

---------

Signed-off-by: KarthikSubbarao <[email protected]>
Signed-off-by: Karthik Subbarao <[email protected]>
Copy link
Member

@parthpatel parthpatel left a comment

Choose a reason for hiding this comment

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

Mostly just questions - trying to understand this code base.

// "unsafe extern C" based on the Rust module API definition

/// # Safety
pub unsafe extern "C" fn bloom_rdb_save(rdb: *mut raw::RedisModuleIO, value: *mut c_void) {
Copy link
Member

Choose a reason for hiding this comment

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

Why are we not using "https://docs.rust-embedded.org/book/interoperability/rust-with-c.html#no_mangle" as recommended by Rust documentation?

@@ -0,0 +1,103 @@
name: ci
Copy link
Member

Choose a reason for hiding this comment

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

If I am a new developer looking at this file, how do I understand the intent of this file without documentation? Are these configurations obvious? What documentation did you read to write this file?

valkey-module = "0.1.2"
bloomfilter = "1.0.13"
lazy_static = "1.4.0"
libc = "0.2"
Copy link
Member

Choose a reason for hiding this comment

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

Why do we need libc?
Why do we not depend on "valkey-module-macros" package? (valkey-module-rs github repo)

debug-assertions = true

[features]
enable-system-alloc = ["valkey-module/enable-system-alloc"]
Copy link
Member

Choose a reason for hiding this comment

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

What is the intention with this configuration?

@@ -0,0 +1,2 @@
valkey
Copy link
Member

Choose a reason for hiding this comment

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

What does this file do?

}

/// Command handler for BF.EXISTS <key> <item>
fn bloom_exists_command(ctx: &Context, args: Vec<ValkeyString>) -> ValkeyResult {
Copy link
Member

Choose a reason for hiding this comment

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

Why do we need these wrapper functions? Can't we feed the commands from command_handler module directly in the macro below?

data_types: [
BLOOM_FILTER_TYPE,
],
init: initialize,
Copy link
Member

Choose a reason for hiding this comment

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

Does the valkey module not have a default? What happens if we don't specify this?

use valkey_module::native_types::ValkeyType;
use valkey_module::{logging, raw};

const BLOOM_FILTER_TYPE_ENCODING_VERSION: i32 = 0;
Copy link
Member

Choose a reason for hiding this comment

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

Why 0 ?

"bloomfltr",
BLOOM_FILTER_TYPE_ENCODING_VERSION,
raw::RedisModuleTypeMethods {
version: raw::REDISMODULE_TYPE_METHOD_VERSION as u64,
Copy link
Member

Choose a reason for hiding this comment

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

u64? that seem like an overkill.

…ness. Fixed others tests and updated the build.sh script for running single integration tests (#16)

Signed-off-by: Karthik Subbarao <[email protected]>
* Handle bloom object max allowed size limit, switch fp rate to f64, update defrag exemption logic and free effort logic

Signed-off-by: Karthik Subbarao <[email protected]>

* Update error message and add unit test

Signed-off-by: Karthik Subbarao <[email protected]>

* Rename config

Signed-off-by: Karthik Subbarao <[email protected]>

* Rename configs

Signed-off-by: Karthik Subbarao <[email protected]>

---------

Signed-off-by: Karthik Subbarao <[email protected]>
zackcam and others added 2 commits November 5, 2024 12:01
…ters and memory_bytes. Additionally updated drop and created tests around this new info handler (#19)

Signed-off-by: zackcam <[email protected]>
* add bf.load and bf.dump to support bloom filter aofrewrite.

Signed-off-by: wuranxx <[email protected]>

add version in BloomFilterType.
change bf.load behavior: bf.load can't override exists keys.

Signed-off-by: wuranxx <[email protected]>

* remove bf.dump.
add bloom filter encode decode  comment.
add unit test for decode error case.

Signed-off-by: wuranxx <[email protected]>

* 1. Currently, the version field is added to the array only encode.
2. Add metrics when decode bloomFilterType.
3. Add metrics test when load bloom filter from aof.

Signed-off-by: wuranxx <[email protected]>

* 1. Add filter bytes check and unit test.
2. Fixed some comments and returned error messages.

Signed-off-by: wuranxx <[email protected]>

* fix `test_bf_decode_when_bytes_is_exceed_limit_should_failed` unit test.

Signed-off-by: wuranxx <[email protected]>

* Add expansion maximum value check to filter decode.

Signed-off-by: wuranxx <[email protected]>

---------

Signed-off-by: wuranxx <[email protected]>
* Support for DEBUG DIGEST module data type callback

Signed-off-by: Nihal Mehta <[email protected]>

* Update test cases

Signed-off-by: Nihal Mehta <[email protected]>

* Move digest to wrapper

Signed-off-by: Nihal Mehta <[email protected]>

* Update tests

Signed-off-by: Nihal Mehta <[email protected]>

* Add more scenarios for debug test

Signed-off-by: Nihal Mehta <[email protected]>

* Clean code and add scenario for debug test

Signed-off-by: Nihal Mehta <[email protected]>

---------

Signed-off-by: Nihal Mehta <[email protected]>
…filter dependency to version 3.0 (#23)

* Updating how we create BloomFilter from rdb loads. BloomFilter vec now has capacity of filter we are loading from

Signed-off-by: zackcam <[email protected]>

* Updating bloomfilter dependency to version 3, fixing breaking changes as well

Signed-off-by: zackcam <[email protected]>

* Updating the digest changes to follow updated version of bloom. As well as removing unnecesary fields saved in rdb

Signed-off-by: zackcam <[email protected]>

* Update log in src/bloom/data_type.rs

Signed-off-by: KarthikSubbarao <[email protected]>

* Update comment in src/bloom/utils.rs

Signed-off-by: KarthikSubbarao <[email protected]>

* Clippy error in src/bloom/data_type.rs

Signed-off-by: KarthikSubbarao <[email protected]>

---------

Signed-off-by: zackcam <[email protected]>
Signed-off-by: KarthikSubbarao <[email protected]>
Co-authored-by: KarthikSubbarao <[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.

7 participants