use of io.dingodb.raft.util.ThreadId in project dingo by dingodb.
the class Replicator method destroy.
void destroy() {
final ThreadId savedId = this.id;
LOG.info("Replicator {} is going to quit", savedId);
releaseReader();
// Unregister replicator metric set
if (this.nodeMetrics.isEnabled()) {
//
this.nodeMetrics.getMetricRegistry().removeMatching(MetricFilter.startsWith(this.metricName));
}
setState(State.Destroyed);
notifyReplicatorStatusListener((Replicator) savedId.getData(), ReplicatorEvent.DESTROYED);
savedId.unlockAndDestroy();
this.id = null;
}
use of io.dingodb.raft.util.ThreadId in project dingo by dingodb.
the class ReplicatorGroupImpl method sendHeartbeat.
@Override
public void sendHeartbeat(final PeerId peer, final RpcResponseClosure<RpcRequests.AppendEntriesResponse> closure) {
final ThreadId rid = this.replicatorMap.get(peer);
if (rid == null) {
if (closure != null) {
closure.run(new Status(RaftError.EHOSTDOWN, "Peer %s is not connected", peer));
}
return;
}
Replicator.sendHeartbeat(rid, closure);
}
use of io.dingodb.raft.util.ThreadId in project dingo by dingodb.
the class ReplicatorGroupImpl method addReplicator.
@Override
public boolean addReplicator(final PeerId peer, final ReplicatorType replicatorType, final boolean sync) {
Requires.requireTrue(this.commonOptions.getTerm() != 0);
this.failureReplicators.remove(peer);
if (this.replicatorMap.containsKey(peer)) {
return true;
}
final ReplicatorOptions opts = this.commonOptions == null ? new ReplicatorOptions() : this.commonOptions.copy();
opts.setReplicatorType(replicatorType);
opts.setPeerId(peer);
if (!sync) {
final RaftClientService client = opts.getRaftRpcService();
if (client != null && !client.checkConnection(peer.getEndpoint(), true)) {
LOG.error("Fail to check replicator connection to peer={}, replicatorType={}.", peer, replicatorType);
this.failureReplicators.put(peer, replicatorType);
return false;
}
}
final ThreadId rid = Replicator.start(opts, this.raftOptions);
if (rid == null) {
LOG.error("Fail to start replicator to peer={}, replicatorType={}.", peer, replicatorType);
this.failureReplicators.put(peer, replicatorType);
return false;
}
return this.replicatorMap.put(peer, rid) == null;
}
use of io.dingodb.raft.util.ThreadId in project dingo by dingodb.
the class ReplicatorGroupImpl method findTheNextCandidate.
@Override
public PeerId findTheNextCandidate(final ConfigurationEntry conf) {
PeerId peerId = null;
int priority = Integer.MIN_VALUE;
long maxIndex = -1L;
for (final Map.Entry<PeerId, ThreadId> entry : this.replicatorMap.entrySet()) {
if (!conf.contains(entry.getKey())) {
continue;
}
final int nextPriority = entry.getKey().getPriority();
if (nextPriority == ElectionPriority.NotElected) {
continue;
}
final long nextIndex = Replicator.getNextIndex(entry.getValue());
if (nextIndex > maxIndex) {
maxIndex = nextIndex;
peerId = entry.getKey();
priority = peerId.getPriority();
} else if (nextIndex == maxIndex && nextPriority > priority) {
peerId = entry.getKey();
priority = peerId.getPriority();
}
}
if (maxIndex == -1L) {
return null;
} else {
return peerId;
}
}
Aggregations