Search in sources :

Example 6 with ThreadId

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;
}
Also used : ThreadId(com.alipay.sofa.jraft.util.ThreadId)

Example 7 with ThreadId

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;
    }
}
Also used : ThreadId(com.alipay.sofa.jraft.util.ThreadId) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) ConcurrentMap(java.util.concurrent.ConcurrentMap) Map(java.util.Map) PeerId(com.alipay.sofa.jraft.entity.PeerId)

Example 8 with ThreadId

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);
}
Also used : Status(com.alipay.sofa.jraft.Status) ThreadId(com.alipay.sofa.jraft.util.ThreadId)

Example 9 with ThreadId

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;
}
Also used : ThreadId(com.alipay.sofa.jraft.util.ThreadId)

Aggregations

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