Skip to content
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

Add the support of the load RDB command #1798

Merged
merged 7 commits into from
Oct 17, 2023

Conversation

xq2010
Copy link
Contributor

@xq2010 xq2010 commented Oct 9, 2023

This PR is for #1753

@git-hulk
Copy link
Member

git-hulk commented Oct 9, 2023

Hi @xq2010 Thanks for your excellent contribution first!

About how to load the RDB file, I'm wondering if it's better to export a command to do this. For example, we can support a new command like load $type $path which allows loading RDB file from local.

$ redis-cli 6666> load RDB /path/to/your/rdb_file

So that we don't need to introduce a new tool. How do you feel about this? cc @apache/kvrocks-committers

@xq2010
Copy link
Contributor Author

xq2010 commented Oct 9, 2023

Hi @xq2010 Thanks for your excellent contribution first!↳

About how to load the RDB file, I'm wondering if it's better to export a command to do this. For example, we can support a new command like load $type $path which allows loading RDB file from local.↳

$ redis-cli 6666> load RDB /path/to/your/rdb_file

So that we don't need to introduce a new tool. How do you feel about this? cc @apache/kvrocks-committers↳

If we add the 'load rdb' command, we need to determine how to process an existing key that's present in both kvrocks and rdb, particularly when the key's type is a string in rdb. It will overwrite the existing key in kvrocks, which may be of a different type."

@git-hulk
Copy link
Member

git-hulk commented Oct 9, 2023

If we add the 'load rdb' command, we need to determine how to process an existing key that's present in both kvrocks and rdb, particularly when the key's type is a string in rdb. It will overwrite the existing key in kvrocks, which may be of a different type."

Yes, it's a good concern. I prefer overwriting by default if it exists and we can offer an option NX like the set command to let users determine in the future. This is my personal perspective, would like to hear more voices about the loading way design.

@xq2010
Copy link
Contributor Author

xq2010 commented Oct 9, 2023

Yes, it's a good concern. I prefer overwriting by default if it exists and we can offer an option NX like the set command to let users determine in the future. This is my personal perspective, would like to hear more voices about the loading way design.↳

Using NX is a good idea, I would also like to hear more opinions.

@PragmaTwice
Copy link
Member

Thanks for your contribution!

Agree with @git-hulk, I think it would be better to just implement it like a command inside the kvrocks process instead of a new program.

@xq2010
Copy link
Contributor Author

xq2010 commented Oct 9, 2023

@git-hulk @PragmaTwice Okay, I will add a command to load the RDB file. The command might be rdb load <path> [namespace]. Do you have any suggestions or advice?

@git-hulk
Copy link
Member

git-hulk commented Oct 9, 2023

@git-hulk @PragmaTwice Okay, I will add a command to load the RDB file. The command might be rdb load [namespace]. Do you have any suggestions or advice?

Thank you! Sounds good to me, but [namespace] seems unnecessary since it knows the current namespace once it enters the command.

@xq2010
Copy link
Contributor Author

xq2010 commented Oct 9, 2023

Thank you! Sounds good to me, but [namespace] seems unnecessary since it knows the current namespace once it enters the command.↳

Yes, it's unnecessary to use a namespace.

If the RDB file contains multiple db, the current implementation sets the namespace of each db to <ns>_<db number>. The password will be the same as the namespace. Only db 0 will use the current namespace.
Perhaps using a parameter to specify which db to load would be better. If so, the command would be rdb load <path> [database number (default 0)].

@git-hulk
Copy link
Member

git-hulk commented Oct 9, 2023

Perhaps using a parameter to specify which db to load would be better. If so, the command would be rdb load [database number (default 0)].

@xq2010 Yes, I think this is a good solution.

@git-hulk
Copy link
Member

@xq2010 Cool! The overall design is nice. I'll take another pass to take a look at detail implementation tomorrow.

Copy link
Member

@tisonkun tisonkun left a comment

Choose a reason for hiding this comment

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

Generally looks good. But I don't have time to check in details for giving an approval on the implementation 🤣

CMakeLists.txt Outdated Show resolved Hide resolved
src/storage/rdb.h Outdated Show resolved Hide resolved
src/storage/rdb.cc Show resolved Hide resolved
src/storage/rdb.cc Outdated Show resolved Hide resolved
src/storage/rdb.cc Outdated Show resolved Hide resolved
src/storage/rdb.cc Outdated Show resolved Hide resolved
tests/cppunit/rdb_test.cc Show resolved Hide resolved
tests/cppunit/rdb_util.h Show resolved Hide resolved
tests/cppunit/rdb_stream_test.cc Outdated Show resolved Hide resolved
src/storage/rdb.cc Outdated Show resolved Hide resolved
src/storage/rdb.cc Outdated Show resolved Hide resolved
src/commands/cmd_server.cc Outdated Show resolved Hide resolved
src/common/rdb_stream.h Outdated Show resolved Hide resolved
@git-hulk git-hulk changed the title feat(load rdb file): add redis2kvrocks to load rdb file to kvrocks Add the support of the load RDB command Oct 11, 2023
Copy link
Contributor

@torwig torwig left a comment

Choose a reason for hiding this comment

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

@xq2010 Good job, thank you for your effort. Just a little nitpicking from me :)

src/common/rdb_stream.cc Outdated Show resolved Hide resolved
src/storage/rdb.cc Outdated Show resolved Hide resolved
src/storage/rdb.cc Outdated Show resolved Hide resolved
src/storage/rdb.cc Outdated Show resolved Hide resolved
src/storage/rdb.cc Outdated Show resolved Hide resolved
src/storage/rdb.cc Outdated Show resolved Hide resolved
src/storage/rdb.cc Outdated Show resolved Hide resolved
src/storage/rdb.cc Outdated Show resolved Hide resolved
src/storage/rdb.cc Outdated Show resolved Hide resolved
src/storage/rdb.cc Outdated Show resolved Hide resolved
@xq2010
Copy link
Contributor Author

xq2010 commented Oct 12, 2023

Thanks for your review, I will review it later

src/common/rdb_stream.cc Show resolved Hide resolved
src/common/rdb_stream.cc Outdated Show resolved Hide resolved
src/common/rdb_stream.h Outdated Show resolved Hide resolved
@git-hulk
Copy link
Member

Hi @xq2010 How's this PR going? Should we take another round review?

@xq2010
Copy link
Contributor Author

xq2010 commented Oct 16, 2023

@git-hulk Thank you for your review. I've made some corrections. Could you please review it once more?

@git-hulk
Copy link
Member

@git-hulk Thank you for your review. I've made some corrections. Could you please review it once more?

Sure, thanks for your efforts!

@git-hulk
Copy link
Member

I would like to merge this PR today if no more comments.

@mapleFU
Copy link
Member

mapleFU commented Oct 17, 2023

I'm a bit busy these few days. I'll go through it before Thursday. You can merge this first if other doesn't have any comments.

Copy link
Contributor

@torwig torwig left a comment

Choose a reason for hiding this comment

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

Generally, LGTM.

@git-hulk git-hulk merged commit 45deba9 into apache:unstable Oct 17, 2023
28 checks passed
@xq2010 xq2010 deleted the feature/redis2kvrocks branch October 18, 2023 06:34
#include "fmt/format.h"
#include "vendor/crc64.h"

StatusOr<size_t> RdbStringStream::Read(char *buf, size_t n) {
Copy link
Member

Choose a reason for hiding this comment

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

The syntax of RdbStringStream is different from RdbFileStream. The previous one will return a smaller size when n is greater than remaining buffer, but RdbFileStream will always return Status::NotOK. Is this expected?

Copy link
Member

Choose a reason for hiding this comment

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

Oh I make it wrong. So they're same.

Comment on lines +176 to +177
std::vector<char> vec(len);
GET_OR_RET(stream_->Read(vec.data(), len));
Copy link
Member

Choose a reason for hiding this comment

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

Could it be len == 0?

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, it is possible, could you help me fix it?

Copy link
Member

Choose a reason for hiding this comment

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

#1839
I've create a pull request for it.

Thanks again for your contribution!

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.

6 participants