Skip to content

Add COPY command#7953

Merged
oranagra merged 16 commits intoredis:unstablefrom
swamp0407:add_copy_command
Nov 17, 2020
Merged

Add COPY command#7953
oranagra merged 16 commits intoredis:unstablefrom
swamp0407:add_copy_command

Conversation

@swamp0407
Copy link
Contributor

I'm not used to using git and I'm not familiar with how to do PR, so I'm sorry if I made a mistake.

Syntax:

COPY <key> <new-key> [DB <dest-db>] [REPLACE]

see #6599

Co-authored-by: tmgauss

I'm not very good at English, so there may be something wrong with the grammar of the comments in the code, etc. I'm sorry, but please check.

fix indent

fix some format

add test units for COPY command
@madolson madolson self-requested a review October 26, 2020 19:53
Copy link
Contributor

@madolson madolson left a comment

Choose a reason for hiding this comment

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

I'll take a deeper look through all the copying tomorrow but I added some high level comments.

I think I fixed the test with this PR: #7966. Redis ACLs are being simplified in weird ways.

assert {[r get mynewkey] eq "foobar"}
r flushdb
}

Copy link
Contributor

Choose a reason for hiding this comment

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

It would be nice to add a test for all the different types. You can use debug digest to validate that the key/values are the same.

Copy link
Contributor

Choose a reason for hiding this comment

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

Looks like the stream digest doesn't include consumer group information, probably worth expanding on that.

Copy link
Member

Choose a reason for hiding this comment

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

i'm not certain we want digest to include it.
there are commands that modify these which consider them metadata.
IIRC they do perform dirty++ and are propagated to replicas and RDB/AOF, and only avoid doing signalModifyKey (invalidating WATCH), so maybe that means that they should indeed be in the digest.
@guybe7 anything to add?

Copy link
Collaborator

Choose a reason for hiding this comment

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

since CGs go in the AOF and RDB i think they should be included in the digest

@oranagra
Copy link
Member

just mentioning that i didn't go over the code yet (just took a quick look at the comments @madolson gave).

p.s. maybe in a followup PR, you can add module API callback so that modules can provide cloning functionality. but let's put that aside for now.

Copy link
Contributor

@madolson madolson left a comment

Choose a reason for hiding this comment

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

Most of it reviewed now! Generally looks good.

assert {[r get mynewkey] eq "foobar"}
r flushdb
}

Copy link
Contributor

Choose a reason for hiding this comment

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

Looks like the stream digest doesn't include consumer group information, probably worth expanding on that.

@swamp0407
Copy link
Contributor Author

thanks @madolson @oranagra @guybe7 !
I fixed the code, but I wasn't sure how to fix things like removing the fast flag and keeping the LRU.
Please review.

@oranagra
Copy link
Member

@swamp0407 you did remove the fast flag (added use-memory instead).
and i think the conclusion from the discussion was that we want it to behave like RESTORE, so we we use dbDelete and dbAdd (don't keep the LRU).
both of these aspects are fine in the last version of the code in that respect (unless we hear other concerns / opinions that support changing that).
I see you changed to lookupKeyRead, which is wrong IMHO, let's wait for @madolson to respond in that discussion.

@madolson
Copy link
Contributor

madolson commented Nov 4, 2020

The lookupKeyRead behavior is weird, but it looks like it's well established in other places, so I guess we should keep that consistent. Still a couple of other open comments. @swamp0407

@swamp0407
Copy link
Contributor Author

thanks @oranagra @madolson
In addition to the areas you suggested I should fix, I have also changed the code that copies the inset object.

Should I also do a fix to include the consumer group information in the digest of the stream key? I'm not sure I can implement it correctly.

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.

haven't yet reviewed the streams code.

i think the fix for DEBUG DIGEST and steams can be a separate PR.
unless this one really needs it in order to validate correct result.
maybe you can use XINFO FULL instead for now.

@swamp0407
Copy link
Contributor Author

Thank you for reviewing my code. @oranagra

Please check it out as I have corrected it.
I have also fixed my mistake that I found in the dupStream function.

And, I don't need to use the stream consumer group's digest, so I won't touch it.

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.

few more comments..
btw, it may be a good idea to move all the 'dupXxxxObject` functions to their respective type c files eventually.
all this type specific logic sounds like it shouldn't be in object.c.
but let's do that after we're done with the other comments, for an easier review of everyone involved.

@swamp0407
Copy link
Contributor Author

thanks @oranagra
I have corrected my codes.

I wrote the code in reference to streamReplyWithRange in t_stream.c, but I didn't understand the streamReplyWithRange function correctly, so the part about adding nack to the group and consumer pel got complicated.

After reading the code again, I thought that the same key nack would never go into multiple people's pel.

I also fixed the part about creating a new consumer.
Let me know if there is any problems with this fix.

@oranagra
Copy link
Member

oranagra commented Nov 8, 2020

@swamp0407 looks like i responded to your last push before you submitted your last message.
AFAIK the entries in the PEL of the group and consumers point to the same memory (see rdb loading).

@itamarhaber
Copy link
Member

Before we seal this one, I have a couple of notes:

  • Should this be a multi-key command? I'm torn between liking the simplicity (e.g. MOVE), my general dislike of multi-key commands but acknowledging there may be a future (see MIGRATE).
  • Should this support a DELETE (or similar) option to delete the source key? This would make this into an uber-command that could eventually replace/deprecate MOVE and RENAME
  • The current implementation copies the source's TTL, if set. I agree with this default, but perhaps we'd like to add a NOTTL (or similar) option.

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

  1. it must be a multi-key command, unless we only want to let it copy a key to another db (keeping it's name), which i think is a big miss
  2. i would have considered it a good idea to add a DELETE argument if they where sharing code, but the fact is that if we do that, it'll just be a shortcut to the MOVE/RENAME implementation which is a fast command. so i'm not sure that's wise. but anyway, we can always add more arguments in the future.
  3. i guess we can add NOTTL, EX <ttl>, and even KEEPTTL. not sure if that's needed, but either way we can add later.

@itamarhaber
Copy link
Member

WRT 1, I guess I meant variadic keys, something like COPY SOURCE key [...] DEST key [...]

@oranagra
Copy link
Member

ohh...
i don't see the value of that (just sending it inside a MULTI will do the same thing, no disadvantages).
has anyone ever requested such a thing for MOVE or RENAME?

madolson
madolson previously approved these changes Nov 10, 2020
@madolson
Copy link
Contributor

I don't like the multi-key approach when there are flags involved, it really complicates the command. As oran said you can always multi-exec them. I also agree that we can add flags later as needed.

From my understanding the follows up here are:

  1. Reorganize the functions so that they are located in their respective types.
  2. Extend the debug digest functionality so that it also includes consumer groups.

Since neither of these require a major consensus, I am OK with the current iteration. @redis/core-team conensus?

Co-authored-by: Itamar Haber <[email protected]>
itamarhaber
itamarhaber previously approved these changes Nov 11, 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.

i went over all the comments to check that we didn't forget anything, found another minor issue.

other than that:

  1. revert the additional "del" keyspace notification
  2. and move all the "dupXxxx" functions to their respective C files. try to find the correct place in each C file for this kind of API (not part of the commands section), and make sure to give them the right prefix. please do this refactory in a separate commit, so it'll be easy to review actual changes.

after that, i guess we're ready to merge this.

} else if (!strcasecmp(c->argv[j]->ptr, "db") && additional >= 1) {
if (getLongLongFromObject(c->argv[j+1], &dbid) == C_ERR ||
dbid < INT_MIN || dbid > INT_MAX ||
selectDb(c, dbid) == C_ERR)
Copy link
Member

Choose a reason for hiding this comment

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

this trick of using selectDb to check if the dbid is in range is not very good.
if we exit with syntax error on the next argument, the selected db remains the dest db.
either re-select the original db right away, or just match the dbid range manually.

@oranagra oranagra merged commit ea7cf73 into redis:unstable Nov 17, 2020
@oranagra
Copy link
Member

@swamp0407 thank you. merged.

JackieXie168 pushed a commit to JackieXie168/redis that referenced this pull request Nov 19, 2020
Syntax:
COPY <key> <new-key> [DB <dest-db>] [REPLACE]

No support for module keys yet.

Co-authored-by: tmgauss
Co-authored-by: Itamar Haber <[email protected]>
Co-authored-by: Oran Agra <[email protected]>
@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
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 state:needs-doc-pr requires a PR to redis-doc repository

Projects

None yet

Development

Successfully merging this pull request may close these issues.

COPY command

6 participants