-
Notifications
You must be signed in to change notification settings - Fork 2
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: raft join failed #181 #188
base: unstable
Are you sure you want to change the base?
Conversation
Co-authored-by: LHG41278 <[email protected]> Co-authored-by: marsevilspirit <[email protected]>
WalkthroughThe pull request includes several code cleanups and minor adjustments to control flow across multiple files. Unused include directives have been removed, and comments have been added for clarity. Error handling in RAFT-related commands has been reorganized to ensure responses are set before returning. The handling of TCP connections has been enhanced with an additional conditional event trigger. Furthermore, enumeration types in both the RAFT and replication modules have been updated to explicitly use Changes
Sequence Diagram(s)sequenceDiagram
participant TM as ThreadManager
participant WT as WriteThread
participant RT as ReadThread
TM->>TM: Initiate TCP connection (DoTCPConnect)
alt write_thread_ exists
TM->>WT: Add EVENT_NULL to write thread
end
TM->>RT: Add event to read thread
sequenceDiagram
participant CMD as RaftCommand Handler
participant RES as Response Setter
participant CL as Client
CMD->>RES: Set error response (e.g., "Already cluster member")
CMD-->>CL: Return after setting response
Possibly related PRs
Suggested reviewers
Poem
📜 Recent review detailsConfiguration used: CodeRabbit UI 📒 Files selected for processing (5)
💤 Files with no reviewable changes (1)
🚧 Files skipped from review as they are similar to previous changes (4)
⏰ Context from checks skipped due to timeout of 90000ms (2)
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
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.
LGTM,同步修改到我本地后运行以下测试:
for i, f := range followers {
res, err := f.Do(ctx, "RAFT.CLUSTER", "JOIN", "127.0.0.1:12111").Result()
if err != nil {
fmt.Printf("[Consistency]RAFT.CLUSTER Follower %d JOIN fail: %v\n", i, err)
continue
}
msg, ok := res.(string)
fmt.Printf("[Consistency]RAFT.CLUSTER Follower %d: %v, %v\n", i, ok, msg)
err = f.Close()
if err != nil {
fmt.Println("[Consistency]RAFT.CLUSTER CLOSE fail.", err.Error())
return
}
}
得到如下结果:
src/net/thread_manager.h
Outdated
@@ -354,6 +354,9 @@ uint64_t ThreadManager<T>::DoTCPConnect(T &t, int fd, const std::shared_ptr<Conn | |||
} | |||
|
|||
readThread_->AddNewEvent(connId, fd, BaseEvent::EVENT_READ); | |||
if (writeThread_) { | |||
writeThread_->AddNewEvent(connId, fd, BaseEvent::EVENT_NULL); // add null event to write_thread epoll |
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.
想问一下向写线程添加空事件的目的是啥
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.
raft join failed是因为当读写线程分离时,尝试通过写线程output,结果发现写事件里没有对应的Id,导致write错误,真正解决问题的就是这里
Fixed the issue of raft join failure.
#181
Summary by CodeRabbit
Refactor
Documentation
Chores