Comments (7)
Released 0.4.3.Final
from jgroups-raft.
No, this is a bug. Please create an issue and I will fix it.
However, is this a realistic scenario?
from jgroups-raft.
Hi,
I will create a test case for better understanding of the issue.
In some scenarios, like developing a service that uses groups-raft on my developer machine, it's a bit annoying to have to create 3 or 5 instances to get the consensus working.
Also, some test deployment of our infrastructure does not require fault tolerancy but needs to be very lightweight.
We could abstract the ReplicatedStatemachine and use another one for single node deployment. But it would have been great to be able to use the same one.
Last, when adding dynamically nodes to Raft using a service discovery mechanism, the first node that is launched will not be functional.
What do you think ?
Thanks
from jgroups-raft.
from jgroups-raft.
Hi,
To avoid changing a lot in the current RAFT protocol, I was thinking about adding a SINLGE_MEMBER protocol that will be lower than ELECTION and RAFT and will be used to fake other members. What do you think ?
A very ugly sample that seems to work for my use case.
package org.jgroups.protocols.raft;
import org.jgroups.Event;
import org.jgroups.Header;
import org.jgroups.Message;
import org.jgroups.stack.Protocol;
import org.jgroups.util.ExtendedUUID;
public class SINGLE_MEMBER extends Protocol {
private RAFT raft;
private ELECTION election;
@Override
public void init() throws Exception {
raft=findProtocol(RAFT.class);
election=findProtocol(ELECTION.class);
super.init();
}
private <T extends Protocol> T findProtocol(Class<T> clazz) {
for(Protocol p=up_prot; p != null; p=p.getUpProtocol()) {
if(p.getClass().equals(clazz))
return (T)p;
}
throw new IllegalStateException(clazz.getSimpleName() + " not found above " + this.getClass().getSimpleName());
}
@Override
public Object down(Message msg) {
if (this.isSingleMember()) {
Header electionHeader = msg.getHeader(election.getId());
Header raftHeader = msg.getHeader(raft.getId());
if (raftHeader != null && electionHeader != null) {
throw new IllegalStateException("Message contains a raft[" + raftHeader.getClass() + "] and election[" + electionHeader.getClass() + "] headers.");
}
if (raftHeader != null) {
handleRaftHeader(raftHeader);
} else if (electionHeader != null) {
handleElectionHeader(electionHeader);
}
return null;
}
return super.down(msg);
}
private void handleElectionHeader(Header header) {
if (header instanceof VoteRequest) {
VoteRequest voteRequest = (VoteRequest)header;
VoteResponse voteResponse = new VoteResponse(voteRequest.term(), true);
Message message = new Message();
message.putHeader(election.getId(), voteResponse);
this.up(message);
}
}
private void handleRaftHeader(Header header) {
if (header instanceof AppendEntriesRequest) {
AppendEntriesRequest req = (AppendEntriesRequest) header;
AppendResult appendResult = new AppendResult(true, req.prev_log_index + 1).commitIndex(raft.commitIndex());
AppendEntriesResponse resp = new AppendEntriesResponse(req.term(), appendResult);
/* Generate random sender because the leader has already voted */
ExtendedUUID randomSender = ExtendedUUID.randomUUID();
Message message = new Message(raft.leader()).src(randomSender);
message.putHeader(raft.getId(), resp);
this.up(message);
}
}
private boolean isSingleMember() {
return raft.majority() == 1;
}
}
What do you think ?
from jgroups-raft.
I'd prefer handling a single member with the generic algorithm. If you define a single member, then the majority is 1 and a single member should therefore always become leader.
from jgroups-raft.
OK, the reason a single member won't form a cluster is that a vote request is never sent to self. When a vote request is received, we determine what happens (e.g. Candidate -> Leader etc). But since we never receive our own vote request, this doesn't happen.
I changed this, so vote requests are now sent to all members including self. I also added VoteTest.testSingleMember()
to test this.
from jgroups-raft.
Related Issues (20)
- Add membership operations to RaftHandle
- Provide quorum reads for `ReplicatedStateMachine`
- `Client` and `ClientStub` issues during membership operations
- Liveness issue with ELECTION HOT 3
- can't remove leader by method of RaftHandle's removeServer HOT 9
- this.raftHandle.channel().disconnect() and reconnect trigger error "not found in retransmission table" HOT 7
- Questions HOT 2
- Ensure a single leader per term
- Configurable class loader for ReplicatedStateMachine block
- CounterTest.testIgnoreReturnValue test failure HOT 5
- Remove ant and use only maven HOT 2
- Restarting node after membership change
- Leader stepping down with membership change HOT 2
- Fix longest log check during election
- Liveness issue joining during election thread execution
- Concurrency issue leads to nodes voting twice in same term
- Election problem HOT 2
- The election process may elect a leader who has left the group HOT 7
- Leader left before the coordinator apply the election result HOT 5
- Multiple LevelDB instances in same process will cause a .sst file being locked HOT 5
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 jgroups-raft.