Skip to content

Add module data-type support for COPY.#8112

Merged
yossigo merged 4 commits intoredis:unstablefrom
yossigo:module-copy-support
Dec 9, 2020
Merged

Add module data-type support for COPY.#8112
yossigo merged 4 commits intoredis:unstablefrom
yossigo:module-copy-support

Conversation

@yossigo
Copy link
Collaborator

@yossigo yossigo commented Nov 30, 2020

This adds a copy callback for module data types, in order to make
modules compatible with the new COPY command.

The callback is optional and COPY will fail for keys with data types
that do not implement it.

This adds a copy callback for module data types, in order to make
modules compatible with the new COPY command.

The callback is optional and COPY will fail for keys with data types
that do not implement it.
@yossigo yossigo added the state:major-decision Requires core team consensus label Nov 30, 2020
@yossigo yossigo requested a review from oranagra November 30, 2020 16:33
oranagra
oranagra previously approved these changes Nov 30, 2020
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.

@MeirShpilraien please take a look.

i suppose a context and auto-memory doesn't apply here.

@MeirShpilraien
Copy link

@oranagra @yossigo
LGTM

@yossigo yossigo requested a review from oranagra November 30, 2020 19:54
oranagra
oranagra previously approved these changes Nov 30, 2020
src/db.c Outdated
addReplyError(c, "Copying module type object is not supported");
return;
case OBJ_MODULE: {
moduleValue *mv = o->ptr;
Copy link
Contributor

Choose a reason for hiding this comment

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

Sort of a nitpick, but we don't encapsulate module logic that well. It seems like this should be closer to:

case OBJ_MODULE: 
    newobj = moduleDupOrReply(c, o);
    if (!newobj) return;
    break;

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'm actually happy with this kind of nitpicking, it's not consistent with how it's done else where but heck, LIBTYFI.

Copy link
Contributor

Choose a reason for hiding this comment

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

I agree that's how it's done elsewhere, but I think that is probably an area worth refactoring too :)

* RedisModuleEvent_FlushDB to hook into that.
* * **copy**: A callback function pointer that is used to make a copy of the specified key.
* The module is expected to perform a deep copy of the specified value and return it.
* In addition, hints about the names of the source and destination keys is provided.
Copy link
Contributor

Choose a reason for hiding this comment

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

Why are hints provided? It seems like it is breaking it's not information the module should need, since keys shouldn't really know where they are. Since you can move them around after they are copied and achieve the same effect.

Copy link
Member

Choose a reason for hiding this comment

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

we've come to realize that a lot of modules do things they shouldn't!
one case that seems semi-common is storing extra metadata on keys outside of the keyspace.
simple modules will not use that information, but the complex ones may depend on it.
p.s. these modules go through hoops to overcome the absence of the key name in the free callback, and we recently added it for the unlink callback.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

That's also why I refer to this as a hint rather than a hard commitment to provide a key name. We also have the same thing in rdb_save and rdb_load where the key name can be queried from RedisModuleIO but it may or may not be there depending on the context.

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah, the whole notion that we added a "hint" is sort of weird. I don't know why anyone would actually want to rely on it. If they want to store additional metadata outside of the keyspace, it seems like the notification system is a better approach?

@oranagra
Copy link
Member

oranagra commented Dec 1, 2020

@redis/core-team please approve

@yossigo yossigo merged commit 4e064fb into redis:unstable Dec 9, 2020
@yossigo yossigo deleted the module-copy-support branch December 9, 2020 18:22
@oranagra oranagra added the release-notes indication that this issue needs to be mentioned in the release notes label Dec 9, 2020
@oranagra oranagra mentioned this pull request Jan 13, 2021
JackieXie168 pushed a commit to JackieXie168/redis that referenced this pull request Mar 2, 2021
This adds a copy callback for module data types, in order to make
modules compatible with the new COPY command.

The callback is optional and COPY will fail for keys with data types
that do not implement it.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

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.

5 participants