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

feat: supported 'ptype' command #1586

Merged
merged 30 commits into from
Jul 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
c67ac2f
feat: supported 'ptype' command
lqxhub Jun 4, 2023
9ec9485
Simplified command `type` and `ptype` code
lqxhub Jun 10, 2023
99a97b2
Remove the capacity judgment
lqxhub Jun 11, 2023
ed7cca2
fix slavaof serialize response bug (#1583)
luky116 Jun 3, 2023
e691134
fix (#1587) (#1588)
ATX735 Jun 5, 2023
e0bdee6
fix unit test:type/set (#1577)
chenbt-hz Jun 6, 2023
a16858a
Fix memory leaks in HandleBGWorkerWriteDB and HandleMetaSyncResponse …
cheniujh Jun 6, 2023
424fb93
refactor: replace pstd/env with std::filesystem (#1470)
4kangjc Jun 6, 2023
9db60db
fix bug issue 1554: using unique_ptr.reset to fix the SIGABRT error (…
AlexStocks Jun 7, 2023
2b7032f
fix: incorrect manner of terminating the process (#1596)
machinly Jun 7, 2023
3f577ff
fix issue#1597: add rocksdb dependency to pstd (#1599)
A2ureStone Jun 7, 2023
b7ecdd0
fix_info_command
chejinge Jun 8, 2023
34c5de2
fix: gcc13 compile failed (#1601)
4kangjc Jun 9, 2023
336c931
ci: add unit test to github action (#1604)
machinly Jun 11, 2023
376c70f
chore:change `PLATFORM` field logic (#1615)
baerwang Jun 14, 2023
ef016fb
fix issue 1517: scan 命令不支持 type 参数 (#1582)
ptbxzrt Jun 14, 2023
8f86adc
fix: the unit test of type/set (#1617)
machinly Jun 18, 2023
d3a01d8
[fix issue1621] fix deadlock (#1620)
iiiuwioajdks Jun 18, 2023
87c0432
command `type` and `ptype` add unit test
lqxhub Jun 18, 2023
4f5314e
Merge branch 'unstable' into ptype
lqxhub Jun 18, 2023
23ff105
fix member variable initialization
lqxhub Jun 19, 2023
0888591
Merge branch 'unstable' into ptype
AlexStocks Jul 1, 2023
7bf5afb
Update issue templates
AlexStocks Jul 1, 2023
016d6fe
feat: supported 'ptype' command
lqxhub Jun 4, 2023
b14c3fd
fix unit test:type/set (#1577)
chenbt-hz Jun 6, 2023
d110dc6
fix issue#1597: add rocksdb dependency to pstd (#1599)
A2ureStone Jun 7, 2023
e480f24
fix: gcc13 compile failed (#1601)
4kangjc Jun 9, 2023
6072bc0
fix: the unit test of type/set (#1617)
machinly Jun 18, 2023
2f3db19
Modify other modules to use the new `type` function
lqxhub Jul 2, 2023
da9b876
fix function repeat
lqxhub Jul 2, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 38 additions & 0 deletions .github/ISSUE_TEMPLATE/bug_report.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
---
name: Bug report
about: Create a report to help us improve
title: ''
labels: ''
assignees: ''

---

**Describe the bug**
A clear and concise description of what the bug is.

**To Reproduce**
Steps to reproduce the behavior:
1. Go to '...'
2. Click on '....'
3. Scroll down to '....'
4. See error

**Expected behavior**
A clear and concise description of what you expected to happen.

**Screenshots**
If applicable, add screenshots to help explain your problem.

**Desktop (please complete the following information):**
- OS: [e.g. iOS]
- Browser [e.g. chrome, safari]
- Version [e.g. 22]

**Smartphone (please complete the following information):**
- Device: [e.g. iPhone6]
- OS: [e.g. iOS8.1]
- Browser [e.g. stock browser, safari]
- Version [e.g. 22]

**Additional context**
Add any other context about the problem here.
20 changes: 20 additions & 0 deletions .github/ISSUE_TEMPLATE/feature_request.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
---
name: Feature request
about: Suggest an idea for this project
title: ''
labels: ''
assignees: ''

---

**Is your feature request related to a problem? Please describe.**
A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]

**Describe the solution you'd like**
A clear and concise description of what you want to happen.

**Describe alternatives you've considered**
A clear and concise description of any alternative solutions or features you've considered.

**Additional context**
Add any other context or screenshots about the feature request here.
1 change: 1 addition & 0 deletions include/pika_command.h
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ const std::string kCmdNameTtl = "ttl";
const std::string kCmdNamePttl = "pttl";
const std::string kCmdNamePersist = "persist";
const std::string kCmdNameType = "type";
const std::string kCmdNamePType = "ptype";
const std::string kCmdNameScan = "scan";
const std::string kCmdNameScanx = "scanx";
const std::string kCmdNamePKSetexAt = "pksetexat";
Copy link

Choose a reason for hiding this comment

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

It's difficult to fully review the code patch without the context of the entire source code. However, based on this snippet:

  • A new command kCmdNamePType has been added.
  • The existing commands kCmdNameTtl, kCmdNamePttl, kCmdNamePersist, kCmdNameType, kCmdNameScan, kCmdNameScanx, and kCmdNamePKSetexAt are still present.
  • There don't appear to be any obvious syntax errors or bugs introduced in this patch.

Here are some general suggestions for code review:

  • Ensure that the names of the new and existing commands are consistent with the conventions used elsewhere in the codebase.
  • Check that the implementation logic for each command is correct and efficient.
  • Consider writing and executing unit tests to confirm that all of the commands are working as expected.
  • Ensure that the new code is properly documented and adheres to any relevant coding standards or best practices.

Copy link

Choose a reason for hiding this comment

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

Based on the provided code patch, here are some observations:

  1. A new constant variable kCmdNamePType has been added.

Improvement suggestion:

  • It's generally good practice to follow consistent naming conventions for variables. Consider using the same naming convention as other variables (e.g., camelCase or snake_case).

Bug risk assessment:

  • As this is just a constant string addition, there is a low risk of introducing bugs within this change alone.

Overall, this code patch seems relatively safe and straightforward, with only a minor improvement suggestion regarding naming conventions.

Expand Down
18 changes: 18 additions & 0 deletions include/pika_kv.h
Original file line number Diff line number Diff line change
Expand Up @@ -588,6 +588,24 @@ class TypeCmd : public Cmd {
void DoInitial() override;
};

class PTypeCmd : public Cmd {
public:
PTypeCmd(const std::string& name, int arity, uint16_t flag) : Cmd(name, arity, flag) {}
std::vector<std::string> current_key() const override {
std::vector<std::string> res;
res.push_back(key_);
return res;
}
void Do(std::shared_ptr<Slot> slot = nullptr) override;
void Split(std::shared_ptr<Slot> slot, const HintKeys& hint_keys) override {};
void Merge() override {};
Cmd* Clone() override { return new PTypeCmd(*this); }

private:
std::string key_;
void DoInitial() override;
};

class ScanCmd : public Cmd {
public:
ScanCmd(const std::string& name, int arity, uint16_t flag) : Cmd(name, arity, flag), pattern_("*") {}
Copy link

Choose a reason for hiding this comment

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

The code patch seems to add a new class PTypeCmd which inherits from Cmd and overrides some of its virtual methods. The implementation looks fine with no apparent bug risk.

However, it would be helpful to have some more context on the purpose of this new class and how it fits into the existing codebase. Additionally, it's worth noting that brief code reviews are often insufficient for thorough evaluation of code quality, maintainability, and scalability.

Expand Down
3 changes: 3 additions & 0 deletions src/pika_command.cc
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,9 @@ void InitCmdTable(CmdTable* cmd_table) {
std::unique_ptr<Cmd> typeptr =
std::make_unique<TypeCmd>(kCmdNameType, 2, kCmdFlagsRead | kCmdFlagsSingleSlot | kCmdFlagsKv);
cmd_table->insert(std::pair<std::string, std::unique_ptr<Cmd>>(kCmdNameType, std::move(typeptr)));
////PTypeCmd
std::unique_ptr<Cmd> pTypeptr = std::make_unique<PTypeCmd>(kCmdNamePType, 2, kCmdFlagsRead | kCmdFlagsSingleSlot | kCmdFlagsKv);
cmd_table->insert(std::pair<std::string, std::unique_ptr<Cmd>>(kCmdNamePType, std::move(pTypeptr)));
////ScanCmd
std::unique_ptr<Cmd> scanptr =
std::make_unique<ScanCmd>(kCmdNameScan, -2, kCmdFlagsRead | kCmdFlagsMultiSlot | kCmdFlagsKv);
Copy link

Choose a reason for hiding this comment

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

Based on the provided code patch, here is a brief code review:

  1. It appears that you're inserting a new command, PTypeCmd, into the cmd_table.

    • Make sure that the PTypeCmd class has been defined and implemented correctly.
    • Ensure that the constructor parameters, number of arguments (-2), and flags are appropriate for this command.
  2. Other parts of the code seem fine at first glance, but without additional context or the complete code, it's hard to provide more specific feedback.

Some general suggestions for improvement:

  • Review the overall design and structure of the code to ensure it follows best practices and provides good readability, maintainability, and modularity.
  • Consider adding comments to describe the purpose and functionality of different sections or classes in the code.
  • Verify if there are any error handling mechanisms or exception handling for potential exceptions that may occur during command execution.

Remember to thoroughly test the modified code to ensure it behaves as expected and doesn't introduce any bugs or issues.

Expand Down
40 changes: 29 additions & 11 deletions src/pika_kv.cc
Original file line number Diff line number Diff line change
Expand Up @@ -184,9 +184,7 @@ void DelCmd::Split(std::shared_ptr<Slot> slot, const HintKeys& hint_keys) {
}
}

void DelCmd::Merge() {
res_.AppendInteger(split_res_);
}
void DelCmd::Merge() { res_.AppendInteger(split_res_); }

void IncrCmd::DoInitial() {
if (!CheckArg(argv_.size())) {
Expand Down Expand Up @@ -804,9 +802,7 @@ void ExistsCmd::Split(std::shared_ptr<Slot> slot, const HintKeys& hint_keys) {
}
}

void ExistsCmd::Merge() {
res_.AppendInteger(split_res_);
}
void ExistsCmd::Merge() { res_.AppendInteger(split_res_); }

void ExpireCmd::DoInitial() {
if (!CheckArg(argv_.size())) {
Expand Down Expand Up @@ -1088,10 +1084,33 @@ void TypeCmd::DoInitial() {
}

void TypeCmd::Do(std::shared_ptr<Slot> slot) {
std::string res;
rocksdb::Status s = slot->db()->Type(key_, &res);
std::vector<std::string> types(1);
rocksdb::Status s = slot->db()->GetType(key_, true, types);
if (s.ok()) {
res_.AppendContent("+" + res);
res_.AppendContent("+" + types[0]);
} else {
res_.SetRes(CmdRes::kErrOther, s.ToString());
}
}

void PTypeCmd::DoInitial() {
if (!CheckArg(argv_.size())) {
res_.SetRes(CmdRes::kWrongNum, kCmdNameType);
return;
}
key_ = argv_[1];
}

void PTypeCmd::Do(std::shared_ptr<Slot> slot) {
std::vector<std::string> types(5);
rocksdb::Status s = slot->db()->GetType(key_, false, types);

if (s.ok()) {
res_.AppendArrayLen(types.size());
for (const auto& vs : types) {
res_.AppendStringLen(vs.size());
res_.AppendContent(vs);
}
} else {
res_.SetRes(CmdRes::kErrOther, s.ToString());
}
Expand Down Expand Up @@ -1328,8 +1347,7 @@ void PKScanRangeCmd::Do(std::shared_ptr<Slot> slot) {
std::string next_key;
std::vector<std::string> keys;
std::vector<storage::KeyValue> kvs;
rocksdb::Status s =
slot->db()->PKScanRange(type_, key_start_, key_end_, pattern_, limit_, &keys, &kvs, &next_key);
rocksdb::Status s = slot->db()->PKScanRange(type_, key_start_, key_end_, pattern_, limit_, &keys, &kvs, &next_key);

if (s.ok()) {
res_.AppendArrayLen(2);
Copy link

Choose a reason for hiding this comment

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

Overall, the code patch seems to involve mostly formatting changes and a few small modifications. Here are some potential bug risks and improvement suggestions for the code:

  1. DelCmd::Merge() and ExistsCmd::Merge(): The original code includes multiple lines for merging, but the modified code combines them into a single line. Since the implementation has been reduced, it's important to verify that the intended functionality is still correct.

  2. TypeCmd::Do(): In the modified code, GetType() method is used with the flag true, which retrieves the type as a single string in the "types" vector. However, the original code simply retrieved the type as a string directly. Ensure that the change doesn't affect the desired behavior of the code.

  3. PTypeCmd class: It seems to be a new addition to the code patch. The implementation scans the types of keys using GetType() with different flags and adds the results to the response. Review the new functionality carefully and ensure it aligns with your requirements.

  4. PKScanRangeCmd::Do(): The modified code no longer spans multiple lines for calling PKScanRange(); however, it's generally a good practice to maintain more readable formatting, particularly if the method accepts multiple arguments. Verify if the updated line is still readable and understandable.

  5. In general, consider adding comments or documentation to describe the purpose and functionality of the methods and classes, especially for newly added code.

Please note that this review is based solely on the provided code patch, and other parts of the codebase might also require review and consideration.

Copy link

Choose a reason for hiding this comment

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

Based on the code patch you provided, here are some observations and suggestions:

  1. In the DelCmd and ExistsCmd classes, the Merge() function implementation has been simplified to a single line. This change seems fine as long as it doesn't affect any existing functionality.

  2. In the TypeCmd class, the Do function has been modified to use the GetType method with a new parameter (true). Without knowing the details of your codebase and requirements, it's difficult to determine if this change is appropriate. Ensure that this change doesn't introduce any unintended side effects or break existing functionality.

  3. In the PTypeCmd class, a new command PType has been added, which fetches multiple types of a given key using the GetType method. The results are appended to the response in an array format. This implementation looks fine, assuming it aligns with your desired behavior.

  4. In the PKScanRangeCmd class, the Do function has been rewritten to call the PKScanRange method with updated arguments. This change seems reasonable, but ensure that it doesn't introduce any unintended behavior or break existing functionality.

It's challenging to conduct a comprehensive code review based on a small code patch. It's crucial to consider the context, purpose, and requirements of the code before making any changes. Additionally, testing and validating the modified code is essential to ensure it functions correctly and doesn't introduce regressions.

Expand Down
18 changes: 9 additions & 9 deletions src/pika_migrate_thread.cc
Original file line number Diff line number Diff line change
Expand Up @@ -662,9 +662,9 @@ int PikaMigrateThread::ReqMigrateOne(const std::string &key, const std::shared_p
std::unique_lock lm(migrator_mutex_);

int slot_id = GetSlotID(key);
std::string type_str;
std::vector<std::string> type_str(1);
char key_type;
rocksdb::Status s = slot->db()->Type(key, &type_str);
rocksdb::Status s = slot->db()->GetType(key, true, type_str);
if (!s.ok()) {
if (s.IsNotFound()) {
LOG(INFO) << "PikaMigrateThread::ReqMigrateOne key: " << key << " not found";
Expand All @@ -675,20 +675,20 @@ int PikaMigrateThread::ReqMigrateOne(const std::string &key, const std::shared_p
}
}

if (type_str == "string") {
if (type_str[0] == "string") {
key_type = 'k';
} else if (type_str == "hash") {
} else if (type_str[0] == "hash") {
key_type = 'h';
} else if (type_str == "list") {
} else if (type_str[0] == "list") {
key_type = 'l';
} else if (type_str == "set") {
} else if (type_str[0] == "set") {
key_type = 's';
} else if (type_str == "zset") {
} else if (type_str[0] == "zset") {
key_type = 'z';
} else if (type_str == "none") {
} else if (type_str[0] == "none") {
return 0;
} else {
LOG(WARNING) << "PikaMigrateThread::ReqMigrateOne key: " << key << " type: " << type_str << " is illegal";
LOG(WARNING) << "PikaMigrateThread::ReqMigrateOne key: " << key << " type: " << type_str[0] << " is illegal";
return -1;
}

Copy link

Choose a reason for hiding this comment

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

Here are some observations and suggestions regarding the provided code patch:

  1. In the original code, std::string type_str is used to store the value returned by slot->db()->Type(key, &type_str), but in the patch, it is changed to std::vector<std::string> type_str(1). It seems unnecessary to use a vector here since only a single value is required. You can revert it back to std::string type_str.

  2. The method GetType is used instead of Type, and an additional parameter true is passed. Check if this change in behavior is expected and documented, as it could affect the logic or results.

  3. Instead of comparing type_str directly to string literals like "string" or "hash", the patch compares type_str[0] to these values. This assumes that type_str will always contain at least one element. Ensure that this assumption is valid, and consider adding sufficient error handling if it's possible for type_str to be empty.

  4. While handling the case when type_str is illegal, the patch logs type_str[0] instead of type_str in the warning message. Confirm if this change is intentional, or if logging the entire type_str is more useful for debugging.

  5. Overall, the provided code patch looks fine with the assumption that the changes made are intentional and aligned with the desired behavior.

Expand Down
28 changes: 14 additions & 14 deletions src/pika_slot_command.cc
Original file line number Diff line number Diff line change
Expand Up @@ -891,22 +891,22 @@ void RemSlotKey(const std::string key, const std::shared_ptr<Slot>& slot) {
}

int GetKeyType(const std::string key, std::string &key_type, const std::shared_ptr<Slot>& slot) {
std::string type_str;
rocksdb::Status s = slot->db()->Type(key, &type_str);
std::vector<std::string> type_str(1);
rocksdb::Status s = slot->db()->GetType(key, true, type_str);
if (!s.ok()) {
LOG(WARNING) << "Get key type error: " << key << " " << s.ToString();
key_type = "";
return -1;
}
if (type_str == "string") {
if (type_str[0] == "string") {
key_type = "k";
} else if (type_str == "hash") {
} else if (type_str[0] == "hash") {
key_type = "h";
} else if (type_str == "list") {
} else if (type_str[0] == "list") {
key_type = "l";
} else if (type_str == "set") {
} else if (type_str[0] == "set") {
key_type = "s";
} else if (type_str == "zset") {
} else if (type_str[0] == "zset") {
key_type = "z";
} else {
LOG(WARNING) << "Get key type error: " << key;
Expand Down Expand Up @@ -1079,8 +1079,8 @@ void SlotsMgrtTagSlotCmd::Do(std::shared_ptr<Slot> slot) {

// check key type
int SlotsMgrtTagOneCmd::KeyTypeCheck(const std::shared_ptr<Slot>& slot) {
std::string type_str;
rocksdb::Status s = slot->db()->Type(key_, &type_str);
std::vector<std::string> type_str(1);
rocksdb::Status s = slot->db()->GetType(key_, true, type_str);
if (!s.ok()) {
if (s.IsNotFound()) {
LOG(INFO) << "Migrate slot key " << key_ << " not found";
Expand All @@ -1091,15 +1091,15 @@ int SlotsMgrtTagOneCmd::KeyTypeCheck(const std::shared_ptr<Slot>& slot) {
}
return -1;
}
if (type_str == "string") {
if (type_str[0] == "string") {
key_type_ = 'k';
} else if (type_str == "hash") {
} else if (type_str[0] == "hash") {
key_type_ = 'h';
} else if (type_str == "list") {
} else if (type_str[0] == "list") {
key_type_ = 'l';
} else if (type_str == "set") {
} else if (type_str[0] == "set") {
key_type_ = 's';
} else if (type_str == "zset") {
} else if (type_str[0] == "zset") {
key_type_ = 'z';
} else {
LOG(WARNING) << "Migrate slot key: " << key_ << " not found";
Copy link

Choose a reason for hiding this comment

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

Based on the code patch you provided, here are some observations and suggestions:

  1. In the original code, rocksdb::Status s = slot->db()->Type(key, &type_str); is used to get the type of a key, while in the patch it has been replaced with rocksdb::Status s = slot->db()->GetType(key, true, type_str); which uses a vector of strings instead of a single string. This change might indicate that the GetType function now returns multiple types for a given key. If this is the intended behavior, then the code changes are fine.

  2. In both the GetKeyType and SlotsMgrtTagOneCmd::KeyTypeCheck functions, the updated code compares type_str[0] with the key types ("string", "hash", "list", etc.) instead of directly comparing type_str itself. This indicates that type_str is now an array (vector) containing the type(s) of a key. Again, if this is the intended behavior, then the changes are correct.

  3. It seems like the RemSlotKey function has not been included in the code patch you provided. Make sure this function is properly updated, if necessary, based on the changes made in other parts of the code.

  4. It's important to review the implementation of the GetType function itself since it determines the behavior of getting the key type. Ensure that the function is correctly implemented and handles any potential errors or edge cases.

Overall, from the code patch you provided, it appears that the changes made relate to modifying the way key types are stored and retrieved. The actual correctness of these changes depends on the implementation details of the GetType function and the desired behavior of the code.

Expand Down
25 changes: 14 additions & 11 deletions src/storage/include/storage/storage.h
Original file line number Diff line number Diff line change
Expand Up @@ -131,8 +131,7 @@ struct BGTask {
Operation operation;
std::string argv;

BGTask(const DataType& _type = DataType::kAll, const Operation& _opeation = Operation::kNone,
std::string _argv = "")
BGTask(const DataType& _type = DataType::kAll, const Operation& _opeation = Operation::kNone, std::string _argv = "")
: type(_type), operation(_opeation), argv(std::move(_argv)) {}
};

Expand Down Expand Up @@ -424,7 +423,7 @@ class Storage {

// Removes and returns several random elements specified by count from the set value store at key.
Status SPop(const Slice& key, std::vector<std::string>* members, int64_t count);

// When called with just the key argument, return a random element from the
// set value stored at key.
// when called with the additional count argument, return an array of count
Expand Down Expand Up @@ -968,8 +967,12 @@ class Storage {
// return > 0 TTL in seconds
std::map<DataType, int64_t> TTL(const Slice& key, std::map<DataType, Status>* type_status);

// Reutrns the data type of the key
Status Type(const std::string& key, std::string* type);
// Reutrns the data all type of the key
// if single is true, the query will return the first one
Status GetType(const std::string& key, bool single, std::vector<std::string>& types);

// Reutrns the data all type of the key
Status Type(const std::string& key, std::vector<std::string>& types);
Copy link

Choose a reason for hiding this comment

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

函数名可能需要更具体点,与上面Type()区分。

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

嗯, 和Ptype保持一致会更好点


Status Keys(const DataType& data_type, const std::string& pattern, std::vector<std::string>* keys);

Expand Down Expand Up @@ -1019,29 +1022,29 @@ class Storage {

Status SetOptions(const OptionType& option_type, const std::string& db_type,
const std::unordered_map<std::string, std::string>& options);
void GetRocksDBInfo(std::string &info);
void GetRocksDBInfo(std::string& info);

private:
std::unique_ptr<RedisStrings> strings_db_;
Copy link

Choose a reason for hiding this comment

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

Overall, the code changes appear to be minor and mostly related to formatting. However, there are a couple of observations:

  • In the BGTask constructor, there is a typo in the parameter name _opeation, it should be _operation.
  • In the Storage class, the GetType method's signature and implementation do not match. The signature expects a reference to a vector of strings for the types parameter, while the implementation expects a pointer to a string.
  • There seems to be a typo in the comment for the GetRocksDBInfo method - "RocksDB" is misspelled as "RocksdDB".

Apart from these observations, no significant bug risks or improvement suggestions stand out from the code patch.

std::unique_ptr<RedisHashes> hashes_db_;
std::unique_ptr<RedisSets> sets_db_;
std::unique_ptr<RedisZSets> zsets_db_;
std::unique_ptr<RedisLists> lists_db_;
std::atomic<bool> is_opened_;
std::atomic<bool> is_opened_ = false;

std::unique_ptr<LRUCache<std::string, std::string>> cursors_store_;

// Storage start the background thread for compaction task
pthread_t bg_tasks_thread_id_;
pthread_t bg_tasks_thread_id_ = 0;
pstd::Mutex bg_tasks_mutex_;
pstd::CondVar bg_tasks_cond_var_;
std::queue<BGTask> bg_tasks_queue_;

std::atomic<int> current_task_type_;
std::atomic<bool> bg_tasks_should_exit_;
std::atomic<int> current_task_type_ = kNone;
std::atomic<bool> bg_tasks_should_exit_ = false;

// For scan keys in data base
std::atomic<bool> scan_keynum_exit_;
std::atomic<bool> scan_keynum_exit_ = false;
};

} // namespace storage
Copy link

Choose a reason for hiding this comment

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

Here are my observations and suggestions:

  • In the constructor of BGTask, _opeation should be _operation.
  • The default value for _argv parameter in the constructor of BGTask has been misspelled as _opeation.
  • The method signature for GetType should be modified to return a vector of strings as its return type.
  • is_opened_, bg_tasks_thread_id_, current_task_type_, and bg_tasks_should_exit_ have been assigned default values, but these variables can be initialized with initialization lists instead of using assignment statements.
  • The spelling of Reutrns in GetType and Type should be corrected to "Returns."
  • It's unclear what the purpose of cursors_store_ is. Its name doesn't suggest its use, and it's not used anywhere in the provided code patch. Consider renaming it or removing it altogether.
  • The use of pthread_t to manage background tasks is not recommended. C++11 introduced std::thread, which provides a simpler interface for managing threads. Consider migrating to std::thread.
  • The comment for GetRocksDBInfo mentions info as an input parameter, but in reality, it's an output parameter. Consider updating the comment for clarity.

Overall, the code seems reasonable, and I don't see any obvious bug risks.

Expand Down
Loading