Search in sources :

Example 16 with ProgressState

use of com.hazelcast.jet.impl.util.ProgressState in project hazelcast by hazelcast.

the class ProcessorTaskletTest_Watermarks method callUntil.

private static void callUntil(ProcessorTasklet tasklet) {
    int iterCount = 0;
    for (ProgressState r; (r = tasklet.call()) != NO_PROGRESS; ) {
        assertEquals("Failed to make progress", MADE_PROGRESS, r);
        assertTrue(String.format("tasklet.call() invoked %d times without reaching %s. Last state was %s", CALL_COUNT_LIMIT, NO_PROGRESS, r), ++iterCount < CALL_COUNT_LIMIT);
    }
}
Also used : ProgressState(com.hazelcast.jet.impl.util.ProgressState)

Example 17 with ProgressState

use of com.hazelcast.jet.impl.util.ProgressState in project hazelcast-jet by hazelcast.

the class SenderTasklet method tryFillInbox.

private void tryFillInbox() {
    if (!inbox.isEmpty()) {
        progTracker.notDone();
        return;
    }
    if (instreamExhausted) {
        return;
    }
    progTracker.notDone();
    final ProgressState result = inboundEdgeStream.drainTo(inbox::add);
    progTracker.madeProgress(result.isMadeProgress());
    instreamExhausted = result.isDone();
    if (instreamExhausted) {
        inbox.add(new ObjectWithPartitionId(DONE_ITEM, -1));
    }
}
Also used : ProgressState(com.hazelcast.jet.impl.util.ProgressState) ObjectWithPartitionId(com.hazelcast.jet.impl.util.ObjectWithPartitionId)

Example 18 with ProgressState

use of com.hazelcast.jet.impl.util.ProgressState 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)

Example 19 with ProgressState

use of com.hazelcast.jet.impl.util.ProgressState in project hazelcast-jet by hazelcast.

the class ConcurrentInboundEdgeStream method drainTo.

// package-visible for testing
ProgressState drainTo(long now, Consumer<Object> dest) {
    tracker.reset();
    for (int queueIndex = 0; queueIndex < conveyor.queueCount(); queueIndex++) {
        final QueuedPipe<Object> q = conveyor.queue(queueIndex);
        if (q == null) {
            continue;
        }
        // skip queues where a snapshot barrier has already been received
        if (waitForSnapshot && receivedBarriers.get(queueIndex)) {
            continue;
        }
        ProgressState result = drainQueue(q, dest);
        tracker.mergeWith(result);
        if (itemDetector.item == DONE_ITEM) {
            conveyor.removeQueue(queueIndex);
            receivedBarriers.clear(queueIndex);
            numActiveQueues--;
            if (maybeEmitWm(watermarkCoalescer.queueDone(queueIndex), dest)) {
                return numActiveQueues == 0 ? DONE : MADE_PROGRESS;
            }
        } else if (itemDetector.item instanceof Watermark) {
            long wmTimestamp = ((Watermark) itemDetector.item).timestamp();
            boolean forwarded = maybeEmitWm(watermarkCoalescer.observeWm(now, queueIndex, wmTimestamp), dest);
            if (logger.isFinestEnabled()) {
                logger.finest("Received " + itemDetector.item + " from queue " + queueIndex + '/' + conveyor.queueCount() + (forwarded ? ", forwarded" : ", not forwarded"));
            }
            if (forwarded) {
                return MADE_PROGRESS;
            }
        } else if (itemDetector.item instanceof SnapshotBarrier) {
            observeBarrier(queueIndex, ((SnapshotBarrier) itemDetector.item).snapshotId());
        } else if (result.isMadeProgress()) {
            watermarkCoalescer.observeEvent(queueIndex);
        }
        if (numActiveQueues == 0) {
            return tracker.toProgressState();
        }
        if (itemDetector.item != null) {
            // if we have received the current snapshot from all active queues, forward it
            if (receivedBarriers.cardinality() == numActiveQueues) {
                dest.accept(new SnapshotBarrier(pendingSnapshotId));
                pendingSnapshotId++;
                receivedBarriers.clear();
                return MADE_PROGRESS;
            }
        }
    }
    // try to emit WM based on history
    if (maybeEmitWm(watermarkCoalescer.checkWmHistory(now), dest)) {
        return MADE_PROGRESS;
    }
    if (numActiveQueues > 0) {
        tracker.notDone();
    }
    return tracker.toProgressState();
}
Also used : ProgressState(com.hazelcast.jet.impl.util.ProgressState) Watermark(com.hazelcast.jet.core.Watermark)

Aggregations

ProgressState (com.hazelcast.jet.impl.util.ProgressState)19 Watermark (com.hazelcast.jet.core.Watermark)4 Nonnull (javax.annotation.Nonnull)3 JetException (com.hazelcast.jet.JetException)2 ObjectWithPartitionId (com.hazelcast.jet.impl.util.ObjectWithPartitionId)2 RestartableException (com.hazelcast.jet.RestartableException)1 LongLongAccumulator (com.hazelcast.jet.accumulator.LongLongAccumulator)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 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