use of com.alipay.sofa.jraft.util.ThreadId in project sofa-jraft by sofastack.
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 com.alipay.sofa.jraft.util.ThreadId in project sofa-jraft by sofastack.
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;
}
}
use of com.alipay.sofa.jraft.util.ThreadId in project sofa-jraft by sofastack.
the class ReplicatorGroupImpl method sendHeartbeat.
@Override
public void sendHeartbeat(final PeerId peer, final RpcResponseClosure<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 com.alipay.sofa.jraft.util.ThreadId in project sofa-jraft by sofastack.
the class ReplicatorGroupImpl method waitCaughtUp.
@Override
public boolean waitCaughtUp(final PeerId peer, final long maxMargin, final long dueTime, final CatchUpClosure done) {
final ThreadId rid = this.replicatorMap.get(peer);
if (rid == null) {
return false;
}
Replicator.waitForCaughtUp(rid, maxMargin, dueTime, done);
return true;
}
Aggregations