Search in sources :

Example 1 with DONE

use of com.hazelcast.jet.impl.execution.StoreSnapshotTasklet.State.DONE in project hazelcast-jet by hazelcast.

the class StoreSnapshotTasklet method stateMachineStep.

private void stateMachineStep() {
    switch(state) {
        case DRAIN:
            progTracker.notDone();
            ProgressState result = inboundEdgeStream.drainTo(o -> {
                if (o instanceof SnapshotBarrier) {
                    SnapshotBarrier barrier = (SnapshotBarrier) o;
                    assert pendingSnapshotId == barrier.snapshotId() : "Unexpected barrier, expected was " + pendingSnapshotId + ", but barrier was " + barrier.snapshotId() + ", this=" + this;
                    hasReachedBarrier = true;
                } else {
                    mapWriter.put((Entry<Data, Data>) o);
                }
            });
            if (result.isDone()) {
                inputIsDone = true;
            }
            if (result.isMadeProgress()) {
                progTracker.madeProgress();
                state = FLUSH;
                stateMachineStep();
            }
            return;
        case FLUSH:
            progTracker.notDone();
            CompletableFuture<Void> future = new CompletableFuture<>();
            future.whenComplete(withTryCatch(logger, (r, t) -> {
                // this callback may be called from a non-tasklet thread
                if (t != null) {
                    logger.severe("Error writing to snapshot map '" + currMapName() + "'", t);
                    snapshotContext.reportError(t);
                }
                // numActiveFlushes must be decremented last otherwise we may miss the error
                numActiveFlushes.decrementAndGet();
            }));
            if (mapWriter.tryFlushAsync(future)) {
                progTracker.madeProgress();
                numActiveFlushes.incrementAndGet();
                state = inputIsDone ? DONE : hasReachedBarrier ? REACHED_BARRIER : DRAIN;
            }
            return;
        case REACHED_BARRIER:
            progTracker.notDone();
            if (numActiveFlushes.get() == 0) {
                snapshotContext.snapshotDoneForTasklet();
                pendingSnapshotId++;
                mapWriter.setMapName(currMapName());
                state = inputIsDone ? DONE : DRAIN;
                hasReachedBarrier = false;
            }
            return;
        case DONE:
            if (numActiveFlushes.get() != 0) {
                progTracker.notDone();
            }
            snapshotContext.taskletDone(pendingSnapshotId - 1, isHigherPrioritySource);
            return;
        default:
            throw new JetException("Unexpected state: " + state);
    }
}
Also used : SnapshotRepository(com.hazelcast.jet.impl.SnapshotRepository) AsyncMapWriter(com.hazelcast.jet.impl.util.AsyncMapWriter) Data(com.hazelcast.nio.serialization.Data) DRAIN(com.hazelcast.jet.impl.execution.StoreSnapshotTasklet.State.DRAIN) CompletableFuture(java.util.concurrent.CompletableFuture) ProgressState(com.hazelcast.jet.impl.util.ProgressState) NodeEngine(com.hazelcast.spi.NodeEngine) FLUSH(com.hazelcast.jet.impl.execution.StoreSnapshotTasklet.State.FLUSH) JetException(com.hazelcast.jet.JetException) ILogger(com.hazelcast.logging.ILogger) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ExceptionUtil.withTryCatch(com.hazelcast.jet.impl.util.ExceptionUtil.withTryCatch) Entry(java.util.Map.Entry) REACHED_BARRIER(com.hazelcast.jet.impl.execution.StoreSnapshotTasklet.State.REACHED_BARRIER) ProgressTracker(com.hazelcast.jet.impl.util.ProgressTracker) Nonnull(javax.annotation.Nonnull) DONE(com.hazelcast.jet.impl.execution.StoreSnapshotTasklet.State.DONE) ProgressState(com.hazelcast.jet.impl.util.ProgressState) CompletableFuture(java.util.concurrent.CompletableFuture) Data(com.hazelcast.nio.serialization.Data) JetException(com.hazelcast.jet.JetException)

Aggregations

JetException (com.hazelcast.jet.JetException)1 SnapshotRepository (com.hazelcast.jet.impl.SnapshotRepository)1 DONE (com.hazelcast.jet.impl.execution.StoreSnapshotTasklet.State.DONE)1 DRAIN (com.hazelcast.jet.impl.execution.StoreSnapshotTasklet.State.DRAIN)1 FLUSH (com.hazelcast.jet.impl.execution.StoreSnapshotTasklet.State.FLUSH)1 REACHED_BARRIER (com.hazelcast.jet.impl.execution.StoreSnapshotTasklet.State.REACHED_BARRIER)1 AsyncMapWriter (com.hazelcast.jet.impl.util.AsyncMapWriter)1 ExceptionUtil.withTryCatch (com.hazelcast.jet.impl.util.ExceptionUtil.withTryCatch)1 ProgressState (com.hazelcast.jet.impl.util.ProgressState)1 ProgressTracker (com.hazelcast.jet.impl.util.ProgressTracker)1 ILogger (com.hazelcast.logging.ILogger)1 Data (com.hazelcast.nio.serialization.Data)1 NodeEngine (com.hazelcast.spi.NodeEngine)1 Entry (java.util.Map.Entry)1 CompletableFuture (java.util.concurrent.CompletableFuture)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 Nonnull (javax.annotation.Nonnull)1