Skip to content

Support save rdb#958

Closed
ColinChamber wants to merge 4 commits intoapache:unstablefrom
ColinChamber:feat-save-rdb
Closed

Support save rdb#958
ColinChamber wants to merge 4 commits intoapache:unstablefrom
ColinChamber:feat-save-rdb

Conversation

@ColinChamber
Copy link
Copy Markdown
Contributor

@ColinChamber ColinChamber commented Oct 7, 2022

This refers to #1001.

Comment thread src/redis_rdb.h Outdated
Status Dump(const std::string &file_name);

private:
class Util {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I think that Util is not a very suitable name for a class. Could you please choose something more descriptive?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Thank you. I use Composer to replace Util. Do you think that's ok?

Comment thread src/redis_rdb.cc Outdated
Comment thread src/redis_rdb.cc Outdated
Comment thread src/redis_rdb.h Outdated
Comment thread src/redis_rdb.cc
}

RedisDatabase::Util::Util(const std::string &file_name) {
file_.open(file_name, std::ofstream::binary);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

What happens if a file fails to open? Will the user be informed?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Thank you.Do you think it's OK to throw an exception?

Comment thread src/redis_rdb.cc Outdated
Comment thread src/redis_rdb.cc Outdated
Comment thread src/redis_rdb.h
Comment thread src/redis_rdb.cc Outdated
Comment thread src/redis_rdb.cc Outdated
Comment thread src/redis_rdb.cc Outdated
Comment thread src/redis_rdb.cc Outdated
Comment thread src/redis_rdb.cc
uint32_t len32 = htonl(len);
s = saveRaw(&len32, 4);
}
return s;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

What happens if the length exceeds uint32?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

According to the kvrocks metadata size(4byte) design, this situation does not exist.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I think you can use uint32_t if it will not happen.

Comment thread src/redis_rdb.cc Outdated
Comment thread src/redis_rdb.h Outdated
*/

#define RDB_VERSION 6
#define SELECT_DB 0
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I prefer a more concrete name here.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

May I ask for a suggested name?

@git-hulk
Copy link
Copy Markdown
Member

git-hulk commented Oct 7, 2022

@ColinChamber Can you help to add more background information?

ColinChamber and others added 3 commits October 7, 2022 15:45
Signed-off-by: tison <wander4096@gmail.com>
@ColinChamber ColinChamber marked this pull request as ready for review October 16, 2022 12:37
Comment thread src/redis_cmd.cc
class CommandSave: public Commander {
public:
Status Execute(Server *svr, Connection *conn, std::string *output) override {
Redis::RedisDatabase RDB(svr->storage_, conn->GetNamespace());
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I'd prefer rdb instead of RDB variable name

Comment thread src/redis_rdb.h
#include "redis_db.h"

namespace Redis {
class RedisDatabase : public Database {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

@ColinChamber I think you can rename RedisDatabase to something like DumpCreator and move all the functionality from Composer to DumpCreator. Thus, you won't have RedisDatabase with just 1 method and inside it one private class and such long things like RedisDatabase::Composer::MethodName(). What do you think?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Is the class name DumpCreator ok if the parser is added in the future?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Do you mean the parser for importing the dump?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Parse the Redis dump file. I know few people need it, but if someone wants to achieve it.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

So you think about the RedisDatabase class and its inner classes, for example, DumpCreator and DumpLoader/DumpImporter/etc. ?

Comment thread src/redis_rdb.cc
const int RDB_32BITLEN = 0x80;

enum RDBOpCode: unsigned char {
RDB_OPCODE_EXPIRETIME = 253, /* Expire time in seconds. */
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

@ColinChamber Additionally you can have a look at this commit (1dcf225) and pay attention to const and enum naming to make relevant changes in your PR.

Copy link
Copy Markdown
Member

@tanruixiang tanruixiang left a comment

Choose a reason for hiding this comment

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

Hi. I found a simple package name typo.

* under the License.
*/

package integration
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
package integration
package save

Copy link
Copy Markdown
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.

I'd prefer you create an issue or at least update the PR description about why you made this change. Otherwise, we review the implementation details but lose the aim of doing all this stuff.

@PragmaTwice
Copy link
Copy Markdown
Member

I'd prefer you create an issue or at least update the PR description about why you made this change. Otherwise, we review the implementation details but lose the aim of doing all this stuff.

There is an issue #1001, although it has not been linked to this PR.

@tisonkun
Copy link
Copy Markdown
Member

@PragmaTwice Thank you! I'll check it.

@ColinChamber
Copy link
Copy Markdown
Contributor Author

There's a little tricky to dump RDB in Kvrocks. My current test for this PR is far from enough. I'm sorry that I should close it first. Maybe I will resubmit after I understand every detail. Thanks to every reviewer.

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