use of com.hazelcast.jet.impl.execution.StoreSnapshotTasklet.State.REACHED_BARRIER 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);
}
}
Aggregations