Skip to content

Modules: add defrag API support.#8149

Merged
oranagra merged 4 commits intoredis:unstablefrom
yossigo:defrag-api
Dec 13, 2020
Merged

Modules: add defrag API support.#8149
oranagra merged 4 commits intoredis:unstablefrom
yossigo:defrag-api

Conversation

@yossigo
Copy link
Collaborator

@yossigo yossigo commented Dec 7, 2020

Add a new set of defrag functions that take a defrag context and allow
defragmenting memory blocks and RedisModuleStrings.

Modules can register a defrag callback which will be invoked when the
defrag process handles globals.

Modules with custom data types can also register a datatype-specific
defrag callback which is invoked for keys that require defragmentation.
The callback and associated functions support both one-step and
multi-step options, depending on the complexity of the key as exposed by
the free_effort callback.

Add a new set of defrag functions that take a defrag context and allow
defragmenting memory blocks and RedisModuleStrings.

Modules can register a defrag callback which will be invoked when the
defrag process handles globals.

Modules with custom data types can also register a datatype-specific
defrag callback which is invoked for keys that require defragmentation.
The callback and associated functions support both one-step and
multi-step options, depending on the complexity of the key as exposed by
the free_effort callback.
@yossigo yossigo added the state:major-decision Requires core team consensus label Dec 7, 2020
@yossigo yossigo requested a review from oranagra December 7, 2020 12:22
Copy link
Member

@oranagra oranagra left a comment

Choose a reason for hiding this comment

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

As we discussed, at some point in time we'll have to also add an option to defrag a dict (rax), both with and without the values in the dict (i.e. the rax nodes and header themselves need defragging).

Also as we discussed, at some point in time we'll need to add an option to defrag global incrementally (with cursors and such).

We probably need to mention these in some "todo" comment, or open an issue for some milestone (unless we plan on doing that in the next couple of weeks).

src/defrag.c Outdated
robj *obj = dictGetVal(kde);
serverAssert(obj->type == OBJ_MODULE);

long defragged = moduleDefragValue(dictGetKey(kde), obj);
Copy link
Member

Choose a reason for hiding this comment

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

do you think the module needs to know the db index?
it probably doesn't even need the key, but if we do provide the key, who knows what it needs it for...

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Not providing the key would be cleaner but we did see this become an issue with complex structures in the past.

When I come to think about it, if the db index is needed in addition to the key name it's an issue all over the place with the API.

@oranagra oranagra added the release-notes indication that this issue needs to be mentioned in the release notes label Dec 7, 2020
oranagra
oranagra previously approved these changes Dec 7, 2020
oranagra
oranagra previously approved these changes Dec 7, 2020
@yossigo yossigo requested a review from a team December 7, 2020 20:23
itamarhaber
itamarhaber previously approved these changes Dec 8, 2020
@yossigo
Copy link
Collaborator Author

yossigo commented Dec 8, 2020

Closes #4185

@oranagra oranagra linked an issue Dec 8, 2020 that may be closed by this pull request
@oranagra
Copy link
Member

oranagra commented Dec 8, 2020

@yossigo looking at #4185 i see this suggestion wasn't covered:

  • each module should announce support (yes,no,forbidden)

also, i remind you that we're missing:

  • a way to defrag globals incrementally
  • an API to defrag dict "primitive" (it's internals)

i'm not sure if we wanna cover the "forbidden" thing. i.e. if a user will enable defrag on a db with a module data type that doesn't support it, it risks running a "busy" loop that achieves nothing. but maybe that burden is for the user to read the module docs before enabling defrag.

regarding the other points, shall we open tickets and put them in some milestone?

@yossigo
Copy link
Collaborator Author

yossigo commented Dec 8, 2020

@oranagra Those points are listed in the meta modules issue (#8157). I'd feel better with active-defrag misbehaving due to specific module (so the user can disable defrag or remove the module) rather than a specific module disabling active-defrag globally.

@yossigo yossigo dismissed stale reviews from itamarhaber and oranagra via 170d0b5 December 9, 2020 18:48
@yossigo yossigo added the approval-needed Waiting for core team approval to be merged label Dec 10, 2020
@oranagra oranagra merged commit 63c1303 into redis:unstable Dec 13, 2020
@yossigo yossigo deleted the defrag-api branch December 13, 2020 08:03
@oranagra oranagra mentioned this pull request Jan 13, 2021
JackieXie168 pushed a commit to JackieXie168/redis that referenced this pull request Mar 2, 2021
Add a new set of defrag functions that take a defrag context and allow
defragmenting memory blocks and RedisModuleStrings.

Modules can register a defrag callback which will be invoked when the
defrag process handles globals.

Modules with custom data types can also register a datatype-specific
defrag callback which is invoked for keys that require defragmentation.
The callback and associated functions support both one-step and
multi-step options, depending on the complexity of the key as exposed by
the free_effort callback.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

approval-needed Waiting for core team approval to be merged release-notes indication that this issue needs to be mentioned in the release notes state:major-decision Requires core team consensus

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add modules API for active memory defragmentation

3 participants