Search in sources :

Example 1 with TaskClosure

use of io.dingodb.raft.closure.TaskClosure in project dingo by dingodb.

the class FSMCallerImpl method onTaskCommitted.

private void onTaskCommitted(final List<TaskClosure> closures) {
    for (int i = 0, size = closures.size(); i < size; i++) {
        final TaskClosure done = closures.get(i);
        done.onCommitted();
    }
}
Also used : TaskClosure(io.dingodb.raft.closure.TaskClosure)

Example 2 with TaskClosure

use of io.dingodb.raft.closure.TaskClosure in project dingo by dingodb.

the class FSMCallerImpl method doCommitted.

private void doCommitted(final long committedIndex) {
    if (!this.error.getStatus().isOk()) {
        return;
    }
    final long lastAppliedIndex = this.lastAppliedIndex.get();
    // We can tolerate the disorder of committed_index
    if (lastAppliedIndex >= committedIndex) {
        return;
    }
    final long startMs = Utils.monotonicMs();
    try {
        final List<Closure> closures = new ArrayList<>();
        final List<TaskClosure> taskClosures = new ArrayList<>();
        final long firstClosureIndex = this.closureQueue.popClosureUntil(committedIndex, closures, taskClosures);
        // Calls TaskClosure#onCommitted if necessary
        onTaskCommitted(taskClosures);
        Requires.requireTrue(firstClosureIndex >= 0, "Invalid firstClosureIndex");
        final IteratorImpl iterImpl = new IteratorImpl(this.fsm, this.logManager, closures, firstClosureIndex, lastAppliedIndex, committedIndex, this.applyingIndex);
        while (iterImpl.isGood()) {
            final LogEntry logEntry = iterImpl.entry();
            if (logEntry.getType() != EnumOutter.EntryType.ENTRY_TYPE_DATA) {
                if (logEntry.getType() == EnumOutter.EntryType.ENTRY_TYPE_CONFIGURATION) {
                    if (logEntry.getOldPeers() != null && !logEntry.getOldPeers().isEmpty()) {
                        // Joint stage is not supposed to be noticeable by end users.
                        this.fsm.onConfigurationCommitted(new Configuration(iterImpl.entry().getPeers()));
                    }
                }
                if (iterImpl.done() != null) {
                    // For other entries, we have nothing to do besides flush the
                    // pending tasks and run this closure to notify the caller that the
                    // entries before this one were successfully committed and applied.
                    iterImpl.done().run(Status.OK());
                }
                iterImpl.next();
                continue;
            }
            // Apply data task to user state machine
            doApplyTasks(iterImpl);
        }
        if (iterImpl.hasError()) {
            setError(iterImpl.getError());
            iterImpl.runTheRestClosureWithError();
        }
        final long lastIndex = iterImpl.getIndex() - 1;
        final long lastTerm = this.logManager.getTerm(lastIndex);
        final LogId lastAppliedId = new LogId(lastIndex, lastTerm);
        this.lastAppliedIndex.set(lastIndex);
        this.lastAppliedTerm = lastTerm;
        this.logManager.setAppliedId(lastAppliedId);
        notifyLastAppliedIndexUpdated(lastIndex);
    } finally {
        this.nodeMetrics.recordLatency("fsm-commit", Utils.monotonicMs() - startMs);
    }
}
Also used : TaskClosure(io.dingodb.raft.closure.TaskClosure) LoadSnapshotClosure(io.dingodb.raft.closure.LoadSnapshotClosure) Closure(io.dingodb.raft.Closure) SaveSnapshotClosure(io.dingodb.raft.closure.SaveSnapshotClosure) Configuration(io.dingodb.raft.conf.Configuration) ArrayList(java.util.ArrayList) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) LogId(io.dingodb.raft.entity.LogId) LogEntry(io.dingodb.raft.entity.LogEntry) TaskClosure(io.dingodb.raft.closure.TaskClosure)

Aggregations

TaskClosure (io.dingodb.raft.closure.TaskClosure)2 Closure (io.dingodb.raft.Closure)1 LoadSnapshotClosure (io.dingodb.raft.closure.LoadSnapshotClosure)1 SaveSnapshotClosure (io.dingodb.raft.closure.SaveSnapshotClosure)1 Configuration (io.dingodb.raft.conf.Configuration)1 LogEntry (io.dingodb.raft.entity.LogEntry)1 LogId (io.dingodb.raft.entity.LogId)1 ArrayList (java.util.ArrayList)1 CopyOnWriteArrayList (java.util.concurrent.CopyOnWriteArrayList)1