Search in sources :

Example 1 with ThreadId

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;
}
Also used : ThreadId(io.dingodb.raft.util.ThreadId)

Example 2 with ThreadId

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);
}
Also used : ThreadId(io.dingodb.raft.util.ThreadId)

Example 3 with ThreadId

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;
}
Also used : ThreadId(io.dingodb.raft.util.ThreadId) ArrayList(java.util.ArrayList)

Example 4 with ThreadId

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;
}
Also used : ThreadId(io.dingodb.raft.util.ThreadId) PeerId(io.dingodb.raft.entity.PeerId)

Example 5 with ThreadId

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;
}
Also used : ThreadId(io.dingodb.raft.util.ThreadId) MetricRegistry(com.codahale.metrics.MetricRegistry)

Aggregations

ThreadId (io.dingodb.raft.util.ThreadId)9 PeerId (io.dingodb.raft.entity.PeerId)2 MetricRegistry (com.codahale.metrics.MetricRegistry)1 Status (io.dingodb.raft.Status)1 ReplicatorOptions (io.dingodb.raft.option.ReplicatorOptions)1 RaftClientService (io.dingodb.raft.rpc.RaftClientService)1 ArrayList (java.util.ArrayList)1 Map (java.util.Map)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 ConcurrentMap (java.util.concurrent.ConcurrentMap)1