-
Notifications
You must be signed in to change notification settings - Fork 131
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
项目代码理解问题 #71
Comments
@Lxxx11 |
@Lxxx11 剩下的问题我看都是代码逻辑不清晰,你可以先尝试问下GPT之类的东西。那种工具对于raft这种常见代码回答的会很准。 |
doHeartBeat(): |
@Lxxx11 这块的代码写的确实很恶心,我记得当时是因为什么特殊情况所以这些写的。 doHeartBeat(): |
明白了!感谢答复! |
@Lxxx11 不客气,有帮助的话可以帮忙宣传下项目,有时间的话也可以提个pr改进下项目质量。我先关闭issue了,又需要你可以再打开。 |
接收快照那块有些没看懂什么逻辑
sendRequestVote中
我知道m_nextIndex是leader下次同步日志的时候需要从哪个日志开始发送
但是这个for循环没理解啥意思 不应该存的是将要发送的日志下标吗 那数组长度不应该是peer节点的数量吗
int lastLogIndex = getLastLogIndex();
for (int i = 0; i <m_nextIndex.size() ; i++) {
m_nextIndex[i] = lastLogIndex + 1 ;
m_matchIndex[i] = 0;
}
接收领导者的快照,没太看懂以下代码逻辑
auto lastLogIndex = getLastLogIndex();
if (lastLogIndex > args->lastsnapshotincludeindex()) {
m_logs.erase(m_logs.begin(), m_logs.begin() + getSlicesIndexFromLogIndex(args->lastsnapshotincludeindex()) + 1);
} else {
m_logs.clear();
}
doHeartBeat():没太看懂以下代码逻辑
if (preLogIndex != m_lastSnapshotIncludeIndex) {
for (int j = getSlicesIndexFromLogIndex(preLogIndex) + 1; j < m_logs.size(); ++j) {
mprrpc::LogEntry *sendEntryPtr = appendEntriesArgs->add_entries();
*sendEntryPtr = m_logs[j];
}
} else {
for (const auto& item: m_logs) {
mprrpc::LogEntry *sendEntryPtr = appendEntriesArgs->add_entries();
*sendEntryPtr = item;
}
}
int lastLogIndex = getLastLogIndex();
//构造返回值
const std::shared_ptrmprrpc::AppendEntriesReply appendEntriesReply = std::make_sharedmprrpc::AppendEntriesReply();
appendEntriesReply->set_appstate(Disconnected);
std::thread t(&Raft::sendAppendEntries, this, i, appendEntriesArgs, appendEntriesReply,
appendNums);
t.detach();
}
The text was updated successfully, but these errors were encountered: