Search in sources :

Example 6 with Closure

use of io.dingodb.raft.Closure in project dingo by dingodb.

the class ClosureQueueImpl method popClosureUntil.

@Override
public long popClosureUntil(final long endIndex, final List<Closure> closures, final List<TaskClosure> taskClosures) {
    closures.clear();
    if (taskClosures != null) {
        taskClosures.clear();
    }
    this.lock.lock();
    try {
        final int queueSize = this.queue.size();
        if (queueSize == 0 || endIndex < this.firstIndex) {
            return endIndex + 1;
        }
        if (endIndex > this.firstIndex + queueSize - 1) {
            LOG.error("Invalid endIndex={}, firstIndex={}, closureQueueSize={}", endIndex, this.firstIndex, queueSize);
            return -1;
        }
        final long outFirstIndex = this.firstIndex;
        for (long i = outFirstIndex; i <= endIndex; i++) {
            final Closure closure = this.queue.pollFirst();
            if (taskClosures != null && closure instanceof TaskClosure) {
                taskClosures.add((TaskClosure) closure);
            }
            closures.add(closure);
        }
        this.firstIndex = endIndex + 1;
        return outFirstIndex;
    } finally {
        this.lock.unlock();
    }
}
Also used : Closure(io.dingodb.raft.Closure)

Example 7 with Closure

use of io.dingodb.raft.Closure in project dingo by dingodb.

the class ClosureQueueImpl method clear.

@Override
public void clear() {
    List<Closure> savedQueue;
    this.lock.lock();
    try {
        this.firstIndex = 0;
        savedQueue = this.queue;
        this.queue = new LinkedList<>();
    } finally {
        this.lock.unlock();
    }
    final Status status = new Status(RaftError.EPERM, "Leader stepped down");
    Utils.runInThread(() -> {
        for (final Closure done : savedQueue) {
            if (done != null) {
                done.run(status);
            }
        }
    });
}
Also used : Status(io.dingodb.raft.Status) Closure(io.dingodb.raft.Closure)

Aggregations

Closure (io.dingodb.raft.Closure)7 Status (io.dingodb.raft.Status)4 CatchUpClosure (io.dingodb.raft.closure.CatchUpClosure)3 ReadIndexClosure (io.dingodb.raft.closure.ReadIndexClosure)3 SynchronizedClosure (io.dingodb.raft.closure.SynchronizedClosure)3 Configuration (io.dingodb.raft.conf.Configuration)3 LogEntry (io.dingodb.raft.entity.LogEntry)3 LogId (io.dingodb.raft.entity.LogId)3 RpcRequestClosure (io.dingodb.raft.rpc.RpcRequestClosure)3 RpcResponseClosure (io.dingodb.raft.rpc.RpcResponseClosure)3 ArrayList (java.util.ArrayList)3 CopyOnWriteArrayList (java.util.concurrent.CopyOnWriteArrayList)3 Message (com.google.protobuf.Message)2 BlockingWaitStrategy (com.lmax.disruptor.BlockingWaitStrategy)2 EventFactory (com.lmax.disruptor.EventFactory)2 EventHandler (com.lmax.disruptor.EventHandler)2 EventTranslator (com.lmax.disruptor.EventTranslator)2 RingBuffer (com.lmax.disruptor.RingBuffer)2 Disruptor (com.lmax.disruptor.dsl.Disruptor)2 ProducerType (com.lmax.disruptor.dsl.ProducerType)2