-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
fix slave's binlog offset greater than master bug #1682
Changes from 2 commits
fe29ed9
049c634
30233d2
1b94dd8
606eca3
9af8564
24a0989
d9e0ca5
56a1e18
6d678c3
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 |
---|---|---|
|
@@ -4,9 +4,6 @@ | |
package proxy | ||
|
||
import ( | ||
"sync" | ||
"unsafe" | ||
|
||
"pika/codis/v2/pkg/proxy/redis" | ||
"pika/codis/v2/pkg/utils/sync2/atomic2" | ||
) | ||
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. Based on the provided code patch, it seems that some import statements have been removed: "sync" and "unsafe". It's difficult to perform a comprehensive code review without the full context of the codebase, but here are a few general suggestions:
Remember, without more information about the surrounding code, it's challenging to provide specific recommendations. It's always useful to test the modified code thoroughly to identify any potential bugs or performance issues. |
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,6 +11,8 @@ | |
|
||
const std::string SlotKeyPrefix = "_internal:slotkey:4migrate:"; | ||
const std::string SlotTagPrefix = "_internal:slottag:4migrate:"; | ||
const size_t KSlotKeyPrefixLen = 27; | ||
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. 别这么写 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. 金鸽的意思是,把 size_t 改为int,大家评估下 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. 不是,27怎么来的? 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.
SlotTagPrefix 字符串的长度 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.
优化了下,直接使用 length |
||
|
||
const size_t MaxKeySendSize = 10 * 1024; | ||
|
||
extern uint32_t crc32tab[256]; | ||
|
@@ -32,7 +34,6 @@ std::string GetSlotKey(int slot); | |
std::string GetSlotsTagKey(uint32_t crc); | ||
int GetSlotsID(const std::string &str, uint32_t *pcrc, int *phastag); | ||
void RemSlotKeyByType(const std::string &type, const std::string &key, const std::shared_ptr<Slot>& slot); | ||
void WriteSAddToBinlog(const std::string &key, const std::string &value, const std::shared_ptr<Slot>& slot); | ||
|
||
class PikaMigrate { | ||
public: | ||
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. Based on the code patch you provided, here's a brief code review:
Apart from these specific changes, without the context of the entire codebase and its purpose, it's challenging to provide further bug risks or improvement suggestions. A comprehensive code review typically involves examining the logic, error handling, performance optimizations, coding conventions, and adherence to best practices. Consider providing more details or sharing the rest of the code if you require a more thorough review. 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. Here are some observations and suggestions for code review:
Note: Without the complete code context and implementation details, it may be challenging to identify potential bugs or provide further improvement suggestions. 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. Without the complete context and understanding of the codebase, it is challenging to provide a thorough code review. However, based on the provided code patch, here are some observations:
Apart from these specific observations, perform a thorough testing of the modified code to check for bug risks or potential improvements. Additionally, consider including comments that explain the purpose and functionality of key functions or blocks of code to aid future maintenance. |
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -369,6 +369,12 @@ Status ConsensusCoordinator::Reset(const LogOffset& offset) { | |
|
||
Status ConsensusCoordinator::ProposeLog(const std::shared_ptr<Cmd>& cmd_ptr, std::shared_ptr<PikaClientConn> conn_ptr, | ||
std::shared_ptr<std::string> resp_ptr) { | ||
std::vector<std::string> keys = cmd_ptr->current_key(); | ||
// slotkey shouldn't add binlog | ||
if (cmd_ptr->name() == kCmdNameSAdd && !keys.empty() && keys[0].compare(0, KSlotKeyPrefixLen, SlotKeyPrefix) == 0) { | ||
return Status::OK(); | ||
} | ||
|
||
LogOffset log_offset; | ||
|
||
stable_logger_->Logger()->Lock(); | ||
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. Overall, the code patch you provided seems fine. Here are a few observations and suggestions:
Example: if (cmd_ptr->name() == kCmdNameSAdd && !keys.empty() &&
(keys[0].starts_with(SlotKeyPrefix) || keys[0].starts_with(SlotTagPrefix))) {
return Status::OK();
}
Remember to thoroughly test the code with various scenarios to ensure it functions as intended and doesn't introduce any unintended side effects. |
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -816,7 +816,6 @@ void AddSlotKey(const std::string type, const std::string key, const std::shared | |
LOG(ERROR) << "sadd key[" << key << "] to slotKey[" << slot_key << "] failed, error: " << s.ToString(); | ||
return; | ||
} | ||
WriteSAddToBinlog(slot_key, members.front(), slot); | ||
|
||
// if res == 0, indicate the key is existed; may return, | ||
// prevent write slot_key success, but write tag_key failed, so always write tag_key | ||
|
@@ -827,24 +826,6 @@ void AddSlotKey(const std::string type, const std::string key, const std::shared | |
LOG(ERROR) << "sadd key[" << key << "] to tagKey[" << tag_key << "] failed, error: " << s.ToString(); | ||
return; | ||
} | ||
WriteSAddToBinlog(tag_key, members.front(), slot); | ||
} | ||
} | ||
|
||
// write sadd key to binlog for slave | ||
void WriteSAddToBinlog(const std::string &key, const std::string &value, const std::shared_ptr<Slot>& slot) { | ||
std::shared_ptr<Cmd> cmd_ptr = g_pika_cmd_table_manager->GetCmd("sadd"); | ||
std::unique_ptr<PikaCmdArgsType> args = std::unique_ptr<PikaCmdArgsType>(new PikaCmdArgsType()); | ||
args->push_back("SADD"); | ||
args->push_back(key); | ||
args->push_back(value); | ||
cmd_ptr->Initial(*args, slot->GetDBName()); | ||
|
||
std::shared_ptr<SyncMasterSlot> sync_slot = | ||
g_pika_rm->GetSyncMasterSlotByName(SlotInfo(slot->GetDBName(), slot->GetSlotID())); | ||
Status s = sync_slot->ConsensusProposeLog(cmd_ptr); | ||
if (!s.ok()) { | ||
LOG(ERROR) << "write sadd key to binlog failed, key: " << key; | ||
} | ||
} | ||
|
||
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. Based on the provided code patch, here are some observations and suggestions:
Remember to thoroughly test the modified code to ensure its correctness and robustness after making any changes. |
||
|
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.
Below is a code review of the provided code patch:
"sync"
package has an indentation inconsistency. It should be indented with a tab or spaces to match the other imports.//
instead of@@
."pika/codis/v2/pkg/proxy/redis"
. If it is not required, it can be safely removed.Improvement suggestions:
Please provide more specific information or code if you'd like a more detailed review or have any particular concerns.