use of io.dingodb.raft.conf.Configuration in project dingo by dingodb.
the class NodeImpl method addLearners.
@Override
public void addLearners(final List<PeerId> learners, final Closure done) {
checkPeers(learners);
this.writeLock.lock();
try {
final Configuration newConf = new Configuration(this.conf.getConf());
for (final PeerId peer : learners) {
newConf.addLearner(peer);
}
unsafeRegisterConfChange(this.conf.getConf(), newConf, done);
} finally {
this.writeLock.unlock();
}
}
use of io.dingodb.raft.conf.Configuration in project dingo by dingodb.
the class NodeImpl method checkDeadNodes.
private boolean checkDeadNodes(final Configuration conf, final long monotonicNowMs, final boolean stepDownOnCheckFail) {
// Check learner replicators at first.
for (final PeerId peer : conf.getLearners()) {
checkReplicator(peer);
}
// Ensure quorum nodes alive.
final List<PeerId> peers = conf.listPeers();
final Configuration deadNodes = new Configuration();
if (checkDeadNodes0(peers, monotonicNowMs, true, deadNodes)) {
return true;
}
if (stepDownOnCheckFail) {
LOG.warn("Node {} steps down when alive nodes don't satisfy quorum, term={}, deadNodes={}, conf={}.", getNodeId(), this.currTerm, deadNodes, conf);
final Status status = new Status();
status.setError(RaftError.ERAFTTIMEDOUT, "Majority of the group dies: %d/%d", deadNodes.size(), peers.size());
stepDown(this.currTerm, false, status);
}
return false;
}
use of io.dingodb.raft.conf.Configuration in project dingo by dingodb.
the class CliServiceImpl method recordConfigurationChange.
private void recordConfigurationChange(final String groupId, final List<String> oldPeersList, final List<String> newPeersList) {
final Configuration oldConf = new Configuration();
for (final String peerIdStr : oldPeersList) {
final PeerId oldPeer = new PeerId();
oldPeer.parse(peerIdStr);
oldConf.addPeer(oldPeer);
}
final Configuration newConf = new Configuration();
for (final String peerIdStr : newPeersList) {
final PeerId newPeer = new PeerId();
newPeer.parse(peerIdStr);
newConf.addPeer(newPeer);
}
LOG.info("Configuration of replication group {} changed from {} to {}.", groupId, oldConf, newConf);
}
use of io.dingodb.raft.conf.Configuration in project dingo by dingodb.
the class NodeImpl method addPeer.
@Override
public void addPeer(final PeerId peer, final Closure done) {
Requires.requireNonNull(peer, "Null peer");
this.writeLock.lock();
try {
Requires.requireTrue(!this.conf.getConf().contains(peer), "Peer already exists in current configuration");
final Configuration newConf = new Configuration(this.conf.getConf());
newConf.addPeer(peer);
unsafeRegisterConfChange(this.conf.getConf(), newConf, done);
} finally {
this.writeLock.unlock();
}
}
use of io.dingodb.raft.conf.Configuration in project dingo by dingodb.
the class NodeImpl method resetPeers.
@Override
public Status resetPeers(final Configuration newPeers) {
Requires.requireNonNull(newPeers, "Null new peers");
Requires.requireTrue(!newPeers.isEmpty(), "Empty new peers");
Requires.requireTrue(newPeers.isValid(), "Invalid new peers: %s", newPeers);
this.writeLock.lock();
try {
if (newPeers.isEmpty()) {
LOG.warn("Node {} set empty peers.", getNodeId());
return new Status(RaftError.EINVAL, "newPeers is empty");
}
if (!this.state.isActive()) {
LOG.warn("Node {} is in state {}, can't set peers.", getNodeId(), this.state);
return new Status(RaftError.EPERM, "Bad state: %s", this.state);
}
// bootstrap?
if (this.conf.getConf().isEmpty()) {
LOG.info("Node {} set peers to {} from empty.", getNodeId(), newPeers);
this.conf.setConf(newPeers);
stepDown(this.currTerm + 1, false, new Status(RaftError.ESETPEER, "Set peer from empty configuration"));
return Status.OK();
}
if (this.state == State.STATE_LEADER && this.confCtx.isBusy()) {
LOG.warn("Node {} set peers need wait current conf changing.", getNodeId());
return new Status(RaftError.EBUSY, "Changing to another configuration");
}
// check equal, maybe retry direct return
if (this.conf.getConf().equals(newPeers)) {
return Status.OK();
}
final Configuration newConf = new Configuration(newPeers);
LOG.info("Node {} set peers from {} to {}.", getNodeId(), this.conf.getConf(), newPeers);
this.conf.setConf(newConf);
this.conf.getOldConf().reset();
stepDown(this.currTerm + 1, false, new Status(RaftError.ESETPEER, "Raft node set peer normally"));
return Status.OK();
} finally {
this.writeLock.unlock();
}
}
Aggregations