Skip to content

feat: add copy cmd #5032

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

Merged
merged 2 commits into from
Apr 30, 2025
Merged

feat: add copy cmd #5032

merged 2 commits into from
Apr 30, 2025

Conversation

BorysTheDev
Copy link
Contributor

fixes: #3878

I've implemented COPY via the rename mechanism. To my mind in the future if we decide to implement the whole functionality of COPY it will be good idea to unite code of the MOVE COPY RENAME commands together

@@ -300,12 +300,14 @@ OpStatus OpPersist(const OpArgs& op_args, string_view key);

class Renamer {
public:
Renamer(Transaction* t, std::string_view src_key, std::string_view dest_key, unsigned shard_count)
Renamer(Transaction* t, std::string_view src_key, std::string_view dest_key, unsigned shard_count,
Copy link
Contributor

Choose a reason for hiding this comment

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

I do not see the search index updating.
Now, RENAME removes the search index for the source file. Please add a simple test and verify the search index for both the source and the destination after the COPY operation is executed.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Could you clarify what search index are you talking about

Copy link
Contributor

Choose a reason for hiding this comment

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

You can execute FT.SEARCH before copy and after.
Please verify that the source document can be found before and after the copy. Also, the destination can't be found before and can be found after.

Copy link
Contributor

Choose a reason for hiding this comment

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

Please take a look at the PR: #4995
It fixes the particular issue, but it unconditionally removes the search index for the source file.
I guess you have to add the condition, is it a copy or a rename?
Also, don't forget to add the test to verify it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

But I don't use that code

Copy link
Contributor

Choose a reason for hiding this comment

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

@vyavdoshenko

What you changed is the single shard optimization that we have in Rename command that @BorysTheDev is not using in his code.

Normal rename (without) the optimization mentioned above always:

  1. Serializes the key via dump command
  2. Deserializes it again by loading it to the destination shard

Both of these flows handle the indexes transparently so there is no question of correctness here. We also have tests for this behaviour see SearchFamilyTest::DocsEditing and as this is the exact same flow with a different name there is no point to act any further.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@vyavdoshenko I've checked everything works as @kostasrim said

kostasrim
kostasrim previously approved these changes Apr 30, 2025
Copy link
Contributor

@kostasrim kostasrim left a comment

Choose a reason for hiding this comment

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

LGTM

void GenericFamily::Copy(CmdArgList args, const CommandContext& cmd_cntx) {
CmdArgParser parser(args);
auto [k1, k2] = parser.Next<std::string_view, std::string_view>();
bool replace = parser.Check("REPLACE");
Copy link
Contributor

Choose a reason for hiding this comment

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

We don't support [DB destination-db] option right ? Also I guess, we parse COPY k1 k2 NONSENSE and allow it (including COPY k1 k2 nonsense more nonsense here)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yes we don't support [DB destination-db], but I forget to add check for nonsense


const char* keys[2] = {"b", "x"};
auto ren_fb = pp_->at(0)->LaunchFiber([&] {
for (size_t i = 0; i < 200; ++i) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Too much 🤣

Copy link
Contributor

@vyavdoshenko vyavdoshenko left a comment

Choose a reason for hiding this comment

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

lgtm

@kostasrim kostasrim merged commit 2661fe1 into main Apr 30, 2025
10 checks passed
@kostasrim kostasrim deleted the add_COPY_cmd branch April 30, 2025 13:25
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.

implement COPY
4 participants