Skip to content

Added support for defrag API.#387

Merged
YaacovHazan merged 4 commits into
masterfrom
register_defrag_func
Sep 5, 2024
Merged

Added support for defrag API.#387
YaacovHazan merged 4 commits into
masterfrom
register_defrag_func

Conversation

@MeirShpilraien
Copy link
Copy Markdown

@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 pushed 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.
Comment thread examples/data_type.rs Outdated
Comment thread redismodule-rs-macros/src/lib.rs
Comment thread redismodule-rs-macros/src/lib.rs
Comment thread redismodule-rs-macros/src/lib.rs
Comment thread src/context/defrag.rs Outdated
Comment thread src/context/defrag.rs Outdated
Comment thread src/context/defrag.rs Outdated
Comment thread src/context/defrag.rs Outdated
Comment thread src/context/defrag.rs Outdated
Comment thread tests/integration.rs Outdated
ephraimfeldblum
ephraimfeldblum previously approved these changes Sep 3, 2024
ephraimfeldblum
ephraimfeldblum previously approved these changes Sep 4, 2024
Comment thread examples/data_type.rs
Comment thread examples/data_type.rs
Comment thread examples/data_type.rs
Comment thread examples/data_type.rs
Comment thread src/context/defrag.rs
Comment thread src/context/defrag.rs
Comment thread src/context/defrag.rs
});
}

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

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
Copy Markdown
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
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thanks!

Comment thread tests/integration.rs
#[test]
fn test_defrag() -> Result<()> {
let port: u16 = 6503;
let _guards = vec![start_redis_server_with_module("data_type", port)
Copy link
Copy Markdown
Contributor

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
Copy Markdown
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
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

No problem.

Comment thread tests/integration.rs
Comment thread src/context/defrag.rs
@YaacovHazan YaacovHazan merged commit 41ccda7 into master Sep 5, 2024
@YaacovHazan YaacovHazan deleted the register_defrag_func branch September 5, 2024 08:00
MeirShpilraien pushed 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 pushed 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 pushed 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 pushed 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)
@github-actions github-actions Bot mentioned this pull request May 4, 2026
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