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();
}
}
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);
}
}
});
}
Aggregations