Search in sources :

Example 11 with ProgressState

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

the class ProcessorTaskletTest method callUntil.

private static void callUntil(Tasklet tasklet, ProgressState expectedState) {
    int iterCount = 0;
    for (ProgressState r; (r = tasklet.call()) != expectedState; ) {
        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, expectedState, r), ++iterCount < CALL_COUNT_LIMIT);
    }
}
Also used : ProgressState(com.hazelcast.jet.impl.util.ProgressState)

Example 12 with ProgressState

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

the class ProcessorTasklet method fillInbox.

private void fillInbox() {
    assert inbox.isEmpty() : "inbox is not empty";
    assert pendingWatermark == null : "null wm expected, but was " + pendingWatermark;
    // We need to collect metrics before draining the queues into Inbox,
    // otherwise they would appear empty even for slow processors
    queuesCapacity.set(instreamCursor == null ? 0 : sum(instreamCursor.getList(), InboundEdgeStream::capacities));
    queuesSize.set(instreamCursor == null ? 0 : sum(instreamCursor.getList(), InboundEdgeStream::sizes));
    if (instreamCursor == null) {
        return;
    }
    final InboundEdgeStream first = instreamCursor.value();
    ProgressState result;
    do {
        currInstream = instreamCursor.value();
        result = NO_PROGRESS;
        // skip ordinals where a snapshot barrier has already been received
        if (waitForAllBarriers && receivedBarriers.get(currInstream.ordinal())) {
            instreamCursor.advance();
            continue;
        }
        result = currInstream.drainTo(addToInboxFunction);
        progTracker.madeProgress(result.isMadeProgress());
        // check if the last drained item is special
        Object lastItem = inbox.queue().peekLast();
        if (lastItem instanceof Watermark) {
            long newWmValue = ((Watermark) inbox.queue().removeLast()).timestamp();
            long wm = watermarkCoalescer.observeWm(currInstream.ordinal(), newWmValue);
            if (wm != NO_NEW_WM) {
                pendingWatermark = new Watermark(wm);
            }
        } else if (lastItem instanceof SnapshotBarrier) {
            SnapshotBarrier barrier = (SnapshotBarrier) inbox.queue().removeLast();
            observeBarrier(currInstream.ordinal(), barrier);
        } else if (lastItem != null && !(lastItem instanceof BroadcastItem)) {
            watermarkCoalescer.observeEvent(currInstream.ordinal());
        }
        if (result.isDone()) {
            receivedBarriers.clear(currInstream.ordinal());
            long wm = watermarkCoalescer.queueDone(currInstream.ordinal());
            // In this case we might overwrite the WM here, but that's fine since the second WM should be newer.
            if (wm != NO_NEW_WM) {
                assert pendingWatermark == null || pendingWatermark.timestamp() < wm : "trying to assign lower WM. Old=" + pendingWatermark.timestamp() + ", new=" + wm;
                pendingWatermark = new Watermark(wm);
            }
            instreamCursor.remove();
            numActiveOrdinals--;
        }
        // pop current priority group
        if (!instreamCursor.advance()) {
            instreamCursor = popInstreamGroup();
            break;
        }
    } while (!result.isMadeProgress() && instreamCursor.value() != first);
    // we are the only updating thread, no need for CAS operations
    lazyAdd(receivedCounts, currInstream.ordinal(), inbox.size());
    if (!inbox.isEmpty()) {
        lazyIncrement(receivedBatches, currInstream.ordinal());
    }
}
Also used : ProgressState(com.hazelcast.jet.impl.util.ProgressState) Watermark(com.hazelcast.jet.core.Watermark)

Example 13 with ProgressState

use of com.hazelcast.jet.impl.util.ProgressState in project hazelcast 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(addToInboxFunction);
    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 14 with ProgressState

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

the class ProcessorTaskletTest_Snapshots method callUntil.

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

Example 15 with ProgressState

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

the class ProcessorTaskletTest_Blocking method callUntil.

private static void callUntil(Tasklet tasklet, ProgressState expectedState) {
    System.out.println("================= call tasklet");
    int iterCount = 0;
    for (ProgressState r; (r = tasklet.call()) != expectedState; ) {
        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, expectedState, r), ++iterCount < CALL_COUNT_LIMIT);
        System.out.println("================= call tasklet");
    }
}
Also used : ProgressState(com.hazelcast.jet.impl.util.ProgressState)

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