use of io.dingodb.raft.util.ThreadId in project dingo by dingodb.
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;
}
use of io.dingodb.raft.util.ThreadId in project dingo by dingodb.
the class ReplicatorGroupImpl method stopReplicator.
@Override
public boolean stopReplicator(final PeerId peer) {
LOG.info("Stop replicator to {}.", peer);
this.failureReplicators.remove(peer);
final ThreadId rid = this.replicatorMap.remove(peer);
if (rid == null) {
return false;
}
// erase entry first to avoid race condition
return Replicator.stop(rid);
}
use of io.dingodb.raft.util.ThreadId in project dingo by dingodb.
the class ReplicatorGroupImpl method stopAll.
@Override
public boolean stopAll() {
final List<ThreadId> rids = new ArrayList<>(this.replicatorMap.values());
this.replicatorMap.clear();
this.failureReplicators.clear();
for (final ThreadId rid : rids) {
Replicator.stop(rid);
}
return true;
}
use of io.dingodb.raft.util.ThreadId in project dingo by dingodb.
the class ReplicatorGroupImpl method stopAllAndFindTheNextCandidate.
@Override
public ThreadId stopAllAndFindTheNextCandidate(final ConfigurationEntry conf) {
ThreadId candidate = null;
final PeerId candidateId = findTheNextCandidate(conf);
if (candidateId != null) {
candidate = this.replicatorMap.get(candidateId);
} else {
LOG.info("Fail to find the next candidate.");
}
for (final ThreadId r : this.replicatorMap.values()) {
if (r != candidate) {
Replicator.stop(r);
}
}
this.replicatorMap.clear();
this.failureReplicators.clear();
return candidate;
}
use of io.dingodb.raft.util.ThreadId in project dingo by dingodb.
the class Replicator method start.
public static ThreadId start(final ReplicatorOptions opts, final RaftOptions raftOptions) {
if (opts.getLogManager() == null || opts.getBallotBox() == null || opts.getNode() == null) {
throw new IllegalArgumentException("Invalid ReplicatorOptions.");
}
final Replicator r = new Replicator(opts, raftOptions);
if (!r.rpcService.connect(opts.getPeerId().getEndpoint())) {
LOG.error("Fail to init sending channel to {}.", opts.getPeerId());
// Return and it will be retried later.
return null;
}
// Register replicator metric set.
final MetricRegistry metricRegistry = opts.getNode().getNodeMetrics().getMetricRegistry();
if (metricRegistry != null) {
try {
if (!metricRegistry.getNames().contains(r.metricName)) {
metricRegistry.register(r.metricName, new ReplicatorMetricSet(opts, r));
}
} catch (final IllegalArgumentException e) {
// ignore
}
}
// Start replication
r.id = new ThreadId(r, r);
r.id.lock();
notifyReplicatorStatusListener(r, ReplicatorEvent.CREATED);
LOG.info("Replicator={}@{} is started", r.id, r.options.getPeerId());
r.catchUpClosure = null;
r.lastRpcSendTimestamp = Utils.monotonicMs();
r.startHeartbeatTimer(Utils.nowMs());
// id.unlock in sendEmptyEntries
r.sendProbeRequest();
return r.id;
}
Aggregations