-
Notifications
You must be signed in to change notification settings - Fork 472
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
RDB: style enhancement for rdb load #1839
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -173,9 +173,13 @@ StatusOr<std::string> RDB::loadEncodedString() { | |
} | ||
|
||
// Normal string | ||
std::vector<char> vec(len); | ||
GET_OR_RET(stream_->Read(vec.data(), len)); | ||
return std::string(vec.data(), len); | ||
if (len == 0) { | ||
return ""; | ||
} | ||
std::string read_string; | ||
read_string.resize(len); | ||
GET_OR_RET(stream_->Read(read_string.data(), len)); | ||
Comment on lines
+179
to
+181
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I wonder if it's a RdbStringStream, it might call |
||
return read_string; | ||
} | ||
|
||
StatusOr<std::vector<std::string>> RDB::LoadListWithQuickList(int type) { | ||
|
@@ -196,19 +200,19 @@ StatusOr<std::vector<std::string>> RDB::LoadListWithQuickList(int type) { | |
|
||
if (container == QuickListNodeContainerPlain) { | ||
auto element = GET_OR_RET(loadEncodedString()); | ||
list.push_back(element); | ||
list.push_back(std::move(element)); | ||
continue; | ||
} | ||
|
||
auto encoded_string = GET_OR_RET(loadEncodedString()); | ||
if (type == RDBTypeListQuickList2) { | ||
ListPack lp(encoded_string); | ||
auto elements = GET_OR_RET(lp.Entries()); | ||
list.insert(list.end(), elements.begin(), elements.end()); | ||
list.insert(list.end(), std::make_move_iterator(elements.begin()), std::make_move_iterator(elements.end())); | ||
} else { | ||
ZipList zip_list(encoded_string); | ||
auto elements = GET_OR_RET(zip_list.Entries()); | ||
list.insert(list.end(), elements.begin(), elements.end()); | ||
list.insert(list.end(), std::make_move_iterator(elements.begin()), std::make_move_iterator(elements.end())); | ||
} | ||
} | ||
return list; | ||
|
@@ -222,7 +226,7 @@ StatusOr<std::vector<std::string>> RDB::LoadListObject() { | |
} | ||
for (size_t i = 0; i < len; i++) { | ||
auto element = GET_OR_RET(loadEncodedString()); | ||
list.push_back(element); | ||
list.push_back(std::move(element)); | ||
} | ||
return list; | ||
} | ||
|
@@ -241,7 +245,7 @@ StatusOr<std::vector<std::string>> RDB::LoadSetObject() { | |
} | ||
for (size_t i = 0; i < len; i++) { | ||
auto element = GET_OR_RET(LoadStringObject()); | ||
set.push_back(element); | ||
set.push_back(std::move(element)); | ||
} | ||
return set; | ||
} | ||
|
@@ -268,7 +272,7 @@ StatusOr<std::map<std::string, std::string>> RDB::LoadHashObject() { | |
for (size_t i = 0; i < len; i++) { | ||
auto field = GET_OR_RET(LoadStringObject()); | ||
auto value = GET_OR_RET(LoadStringObject()); | ||
hash[field] = value; | ||
hash[field] = std::move(value); | ||
} | ||
return hash; | ||
} | ||
|
@@ -471,7 +475,7 @@ Status RDB::saveRdbObject(int type, const std::string &key, const RedisObjValue | |
const auto &member_scores = std::get<std::vector<MemberScore>>(obj); | ||
redis::ZSet zset_db(storage_, ns_); | ||
uint64_t count = 0; | ||
db_status = zset_db.Add(key, ZAddFlags(0), (redis::ZSet::MemberScores *)&member_scores, &count); | ||
db_status = zset_db.Add(key, ZAddFlags(0), const_cast<std::vector<MemberScore> *>(&member_scores), &count); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is a const_cast but I think it's ok to calling it? |
||
} else if (type == RDBTypeHash || type == RDBTypeHashListPack || type == RDBTypeHashZipList || | ||
type == RDBTypeHashZipMap) { | ||
const auto &entries = std::get<std::map<std::string, std::string>>(obj); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
After a deep look into this function, I think it need some other change. In my view, I think it should not just return error when facing EOF.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The error should be returned only when some IO failure occurs, rather than not enough length.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@PragmaTwice The api is designed like this. It's not a standard fs api.
I've checkout redis rdb impl in rio, it just provide the same syntax.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For comparing:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think if we require a fs api, we can wrap a
Style api as underlying impl, but this case I think rdb will gurantee the size should match.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see. LGTM.