Search in sources :

Example 6 with ThreadId

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

Example 7 with ThreadId

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

Example 8 with ThreadId

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

Example 9 with ThreadId

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

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