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

Added support for defrag API. #387

Merged
merged 4 commits into from
Sep 5, 2024
Merged

Added support for defrag API. #387

merged 4 commits into from
Sep 5, 2024

Conversation

MeirShpilraien
Copy link
Collaborator

@MeirShpilraien MeirShpilraien commented Sep 3, 2024

The PR adds support for defrag API.
The PR introduce a new struct, DefragContext, which provide a safe API over *mut raw::RedisModuleDefragCtx.

Notice that we do expose an unsafe API to create DefragContext from *mut raw::RedisModuleDefragCtx. This is because we do not have a safe API for datatype registration. User must register an unsafe function as the defrag callback of the datatype and create the DefragContext from *mut raw::RedisModuleDefragCtx. We should consider adding a safe API for datatype creation.

In addition, the PR introduce 3 new proc macros:

  • defrag_function - allows to register a function to defrag global data
  • defrag_start_function - allows to register a function to defrag global data when defrag cycle starts.
  • defrag_end_function - allows to register a function to defrag global data when defrag cycle ends.

Example and test for the new API were added.

Notice: The start and the end callbacks for defrag was added on this PR

The PR adds support for defrag API.
The PR introduce a new struct, `DefragContext`, which provide
a safe API over `*mut raw::RedisModuleDefragCtx`.

**Notice** that we do expose an unsafe API to create `DefragContext` from `*mut raw::RedisModuleDefragCtx`.
This is because we do not have a safe API for datatype registeration. User must register an unsafe function as the defrag callback of the datatype and create the `DefragContext` from `*mut raw::RedisModuleDefragCtx`. We should consider adding a safe API for datatype creation.

In addition, the PR introduce 3 new proc macros:

* defrag_function - allows to register a function to defrag global data
* defrag_start_function - allows to register a function to defrag global data when defrag cycle starts.
* defrag_end_function - allows to register a function to defrag global data when defrag cycle ends.

Example and test for the new API were added.
MeirShpilraien added a commit to RedisJSON/RedisJSON that referenced this pull request Sep 3, 2024
The PR adds support for active defrag on RedisJSON. A pre condition for this PR is that the following PR's will be megred:

* [Redis defrad module API extentions](redis/redis#13509)
* [redismodule-rs support for active defrag API](RedisLabsModules/redismodule-rs#387)
* [IJSON support for defrag](RedisJSON/ijson#1)

The PR register defrag function on the json datatype and uses the new capability of ISON to defrag the key.

**Notice**:

* that increamental defrag of the json key is **not** support. In order to support it we need to implement the free_effort callback. This is not trivial and even if it was it would have cause the json object to potentially be freed when the GIL is not hold, which violate the assumption of our shared string implementation (it is not thread safe). We leave it for future improvment.

* If we run on a Redis version that do not support the defrag start callback, we can still partially support defrag. In that case the IJSON object will be defraged but the shared strings dictionaty will not be reinitialize. This basically means that shared strings will not be defraged.

Tests were added to cover the new functionality.
examples/data_type.rs Outdated Show resolved Hide resolved
redismodule-rs-macros/src/lib.rs Show resolved Hide resolved
redismodule-rs-macros/src/lib.rs Show resolved Hide resolved
redismodule-rs-macros/src/lib.rs Show resolved Hide resolved
src/context/defrag.rs Outdated Show resolved Hide resolved
src/context/defrag.rs Outdated Show resolved Hide resolved
src/context/defrag.rs Outdated Show resolved Hide resolved
src/context/defrag.rs Outdated Show resolved Hide resolved
src/context/defrag.rs Outdated Show resolved Hide resolved
tests/integration.rs Outdated Show resolved Hide resolved
ephraimfeldblum
ephraimfeldblum previously approved these changes Sep 3, 2024
ephraimfeldblum
ephraimfeldblum previously approved these changes Sep 4, 2024
examples/data_type.rs Show resolved Hide resolved
examples/data_type.rs Show resolved Hide resolved
examples/data_type.rs Show resolved Hide resolved
examples/data_type.rs Show resolved Hide resolved
src/context/defrag.rs Show resolved Hide resolved
src/context/defrag.rs Show resolved Hide resolved
});
}

pub fn register_defrag_functions(ctx: &Context) -> Result<(), RedisError> {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Forgotten documentation for this public function. :-)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Its public because it is use from the macro, but sure will add a comment.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Thanks!

#[test]
fn test_defrag() -> Result<()> {
let port: u16 = 6503;
let _guards = vec![start_redis_server_with_module("data_type", port)
Copy link
Collaborator

Choose a reason for hiding this comment

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

So this is just one guard, not a vector of multiple?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I actually not sure why it is a vec, but this is how it is done on all the other tests, will leave to change it on another PR.

Copy link
Collaborator

Choose a reason for hiding this comment

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

No problem.

tests/integration.rs Show resolved Hide resolved
src/context/defrag.rs Show resolved Hide resolved
@YaacovHazan YaacovHazan merged commit 41ccda7 into master Sep 5, 2024
0 of 2 checks passed
@YaacovHazan YaacovHazan deleted the register_defrag_func branch September 5, 2024 08:00
MeirShpilraien added a commit to RedisJSON/RedisJSON that referenced this pull request Sep 10, 2024
The PR adds support for active defrag on RedisJSON. A pre condition for this PR is that the following PR's will be megred:

* [Redis defrad module API extentions](redis/redis#13509)
* [redismodule-rs support for active defrag API](RedisLabsModules/redismodule-rs#387)
* [IJSON support for defrag](RedisJSON/ijson#1)

The PR register defrag function on the json datatype and uses the new capability of ISON to defrag the key.

**Notice**:

* Increamental defrag of the json key is **not** support. In order to support it we need to implement the free_effort callback. This is not trivial and even if it was it would have cause the json object to potentially be freed when the GIL is not hold, which violate the assumption of our shared string implementation (it is not thread safe). We leave it for future improvment.

* If we run on a Redis version that do not support the defrag start callback, we can still partially support defrag. In that case the IJSON object will be defraged but the shared strings dictionatrywill not be reinitialize. This basically means that shared strings will not be defraged.

Tests were added to cover the new functionality.
MeirShpilraien added a commit to RedisJSON/RedisJSON that referenced this pull request Sep 16, 2024
The PR adds support for active defrag on RedisJSON. A pre condition for this PR is that the following PR's will be megred:

* [Redis defrad module API extentions](redis/redis#13509)
* [redismodule-rs support for active defrag API](RedisLabsModules/redismodule-rs#387)
* [IJSON support for defrag](RedisJSON/ijson#1)

The PR register defrag function on the json datatype and uses the new capability of ISON to defrag the key.

**Notice**:

* Increamental defrag of the json key is **not** support. In order to support it we need to implement the free_effort callback. This is not trivial and even if it was it would have cause the json object to potentially be freed when the GIL is not hold, which violate the assumption of our shared string implementation (it is not thread safe). We leave it for future improvment.

* If we run on a Redis version that do not support the defrag start callback, we can still partially support defrag. In that case the IJSON object will be defraged but the shared strings dictionatrywill not be reinitialize. This basically means that shared strings will not be defraged.

Tests were added to cover the new functionality.

(cherry picked from commit 6539e1e)
MeirShpilraien added a commit to RedisJSON/RedisJSON that referenced this pull request Sep 16, 2024
The PR adds support for active defrag on RedisJSON. A pre condition for this PR is that the following PR's will be megred:

* [Redis defrad module API extentions](redis/redis#13509)
* [redismodule-rs support for active defrag API](RedisLabsModules/redismodule-rs#387)
* [IJSON support for defrag](RedisJSON/ijson#1)

The PR register defrag function on the json datatype and uses the new capability of ISON to defrag the key.

**Notice**:

* Increamental defrag of the json key is **not** support. In order to support it we need to implement the free_effort callback. This is not trivial and even if it was it would have cause the json object to potentially be freed when the GIL is not hold, which violate the assumption of our shared string implementation (it is not thread safe). We leave it for future improvment.

* If we run on a Redis version that do not support the defrag start callback, we can still partially support defrag. In that case the IJSON object will be defraged but the shared strings dictionatrywill not be reinitialize. This basically means that shared strings will not be defraged.

Tests were added to cover the new functionality.

(cherry picked from commit 6539e1e)
MeirShpilraien added a commit to RedisJSON/RedisJSON that referenced this pull request Sep 16, 2024
The PR adds support for active defrag on RedisJSON. A pre condition for this PR is that the following PR's will be megred:

* [Redis defrad module API extentions](redis/redis#13509)
* [redismodule-rs support for active defrag API](RedisLabsModules/redismodule-rs#387)
* [IJSON support for defrag](RedisJSON/ijson#1)

The PR register defrag function on the json datatype and uses the new capability of ISON to defrag the key.

**Notice**:

* Increamental defrag of the json key is **not** support. In order to support it we need to implement the free_effort callback. This is not trivial and even if it was it would have cause the json object to potentially be freed when the GIL is not hold, which violate the assumption of our shared string implementation (it is not thread safe). We leave it for future improvment.

* If we run on a Redis version that do not support the defrag start callback, we can still partially support defrag. In that case the IJSON object will be defraged but the shared strings dictionatrywill not be reinitialize. This basically means that shared strings will not be defraged.

Tests were added to cover the new functionality.

(cherry picked from commit 6539e1e)
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.

4 participants