use of org.apache.ignite.raft.jraft.util.ThreadId in project ignite-3 by apache.
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 {
final String replicatorMetricName = getReplicatorMetricName(opts);
if (!metricRegistry.getNames().contains(replicatorMetricName)) {
metricRegistry.register(replicatorMetricName, 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.sendEmptyEntries(false);
return r.id;
}
use of org.apache.ignite.raft.jraft.util.ThreadId in project ignite-3 by apache.
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 org.apache.ignite.raft.jraft.util.ThreadId in project ignite-3 by apache.
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, this.commonOptions.getCommonExecutor());
}
use of org.apache.ignite.raft.jraft.util.ThreadId in project ignite-3 by apache.
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(getReplicatorMetricName(this.options)));
}
this.state = State.Destroyed;
notifyReplicatorStatusListener((Replicator) savedId.getData(), ReplicatorEvent.DESTROYED);
savedId.unlockAndDestroy();
// Avoid nulling id because it's used to sync replicator state on destroy.
}
use of org.apache.ignite.raft.jraft.util.ThreadId in project ignite-3 by apache.
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;
}
Aggregations