Comments (8)
The votedFor
is not saved because the node hasn't voted for anyone in that term.
In the scenario you said, when Node 2 and 3 become followers, they will save the first log, a NoOp log with only term in it. So Node 4 won't have a chance to become a leader without that log.
The NoOp log is the tricky part in the Raft algorithm. I cannot remember the exact chapter where it is discussed. Maybe the edge cases in the last several chapters.
from xraft.
But the log is written after the node becomes follower from candidate.
Thus, in a concurrent scenario, Node 4 can request Node 2 and Node 3 right after they become follower and before writing the log.
from xraft.
Sorry, my explanation might not be clear. The NoOp log is inserted by the new leader and replicated to followers.
- Node 1 receives enough votes and becomes a leader. Node 1 inserts a NoOp log and starts to replicate its log immediately.
- Node 2 and 3 receive AppendEntriesRpc from the leader, set the leader to Node 1, merge the logs from AppendEntriesRpc.
So, Node 4 won't get enough votes before step 2 or after step 2.
Hope this answers your question.
from xraft.
Okay, I see. Thanks for your further explanation.
You mean the leader writes NoOp in this task, right?
And in this task the leader will send AppendEntriesRpc requests to other nodes.
But the 2nd step in your comment is not atomic, i.e., the operation set leader and merge logs are executed in two lines:
xraft/xraft-core/src/main/java/in/xnnyygn/xraft/core/node/NodeImpl.java
Lines 611 to 612 in 3442abc
So here's the concurrency scenario: before
appendEntries(rpc)
is executed (before writing NoOp log), Node 4 can launch the new leader election process and get votes from Node 2 and 3.from xraft.
I guess you have misunderstood the thread model of XRaft. It's a single thread application except the connection handlers.
For the node receiving AppendEntriesRpc
, while it is processing
xraft/xraft-core/src/main/java/in/xnnyygn/xraft/core/node/NodeImpl.java
Lines 580 to 585 in 3442abc
Any new messages will be queued and processed later, not at the same time.
TaskContext comes from here.
xraft/xraft-core/src/main/java/in/xnnyygn/xraft/core/node/NodeBuilder.java
Lines 268 to 269 in 3442abc
from xraft.
Sorry for my misunderstanding. Now I've got the thread model. Thanks again for your explanation.
I seemingly find out a possible buggy scenario, which can occur when using FileLog
instead of default MemoryLog
.
After Node 1 finishes synchronizing the NoOp log (lastLogTerm = 1
) with all nodes (Node 2, 3 and 4), a following generate snapshot command persists the log on disk. Then, Node 4 lanuches an new election process with term = 1
(volatile) and lastLogTerm = 1
(persistent) after a restart, and requests Node 2 and 3 for votes.
Here Node 2 and 3 can vote for Node 4 in case both two conditions hold.
We know that
votedFor == null
holds on Node 2 and 3.
Here in isNewerThan
method, Node 2 and 3's logTerm
equals 1, while the rpc's lastLogTerm
is also 1, and all logIndex
equals 0. Thus, the method returns false. Finally, Node 2 and 3 can vote for Node 4.
from xraft.
Of course node 2 and 3 should vote for node 4 if node 4 has effectively latest log.
After node 4 receives AppendEntriesRpc
from node 1, its term will be the same as node 1, 2, and 3. If node 4 restarts due to some unexpected error, it will continue to be a follower while receiving AppendEntriesRpc
or heart beat messages from node 1. Should there be a weird network partition, node 1 could not contact node 4 but they were both able to connect to node 2 and 3, node 4 attempted to become a leader and it was sure to be successful. However, the cluster will be unstable.
from xraft.
A network partition is not essential. When AppendEntriesRpc
requests are delayed, the situation occurs. And Raft should be tolerant to message delay faults.
from xraft.
Related Issues (20)
- [ERROR] Failed to execute goal on project xraft-kvstore: Could not resolve dependencies for project in.xnnyygn.xraft:xraft-kvstore:jar:0.1.0-SNAPSHOT: Could not find artifact in.xnnyygn.xraft:xraft-core:jar:0.1.0-SNAPSHOT -> [Help 1] HOT 4
- 集群成员变更中书中文字与代码实现存在出入
- 请教一个关于选举成功后第一条NoOp日志的问题 HOT 3
- 书与仓库中的代码不一致 HOT 1
- 书中关于CANDIDATE也拥有选举超时的任务 HOT 3
- 如果未提交的日志放在内存中,会不会导致已提交后也会被推翻? HOT 5
- kvstore get 操作 是不是从日志的最后往前搜索
- 没有preVote的源码 HOT 1
- Error:(9, 26) java: package com.google.protobuf does not exist
- 关于第二章内容的一点疑问
- 请问xraft和sofa-jraft在架构和设计逻辑上一样吗? HOT 1
- 书中84页的“另一种情况是,多个节点以不同的term启动,选举超时后.....,此时仍旧会比较日志” HOT 1
- Duplicate vote response can make illegal leader without a quorum HOT 7
- 这里在崩溃的时候,会不会导致数据不一致 HOT 1
- ls: ./lib: No such file or directory HOT 1
- Missing check for `result.getTerm() == role.getTerm()` in `doProcessRequestVoteResult()` can result in two leaders with the same term. HOT 4
- 书和项目的关系 HOT 3
- Xraft-kvstore does not satisfy linearizability HOT 1
- java.util.ConcurrentModificationException in `List<Entry> entries` of `MemoryEntrySequence` HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from xraft.