Search in sources :

Example 6 with ProgressState

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

the class ReceiverTasklet method call.

@Override
@Nonnull
public ProgressState call() {
    if (receptionDone) {
        return collector.offerBroadcast(DONE_ITEM);
    }
    tracker.reset();
    tracker.notDone();
    tryFillInbox();
    for (ObjWithPtionIdAndSize o; (o = inbox.peek()) != null; ) {
        final Object item = o.getItem();
        if (item == DONE_ITEM) {
            receptionDone = true;
            inbox.remove();
            assert inbox.peek() == null : "Found something in the queue beyond the DONE_ITEM: " + inbox.remove();
            break;
        }
        ProgressState outcome = item instanceof BroadcastItem ? collector.offerBroadcast((BroadcastItem) item) : collector.offer(item, o.getPartitionId());
        if (!outcome.isDone()) {
            tracker.madeProgress(outcome.isMadeProgress());
            break;
        }
        tracker.madeProgress();
        inbox.remove();
        ackItem(o.estimatedMemoryFootprint);
    }
    return tracker.toProgressState();
}
Also used : ProgressState(com.hazelcast.jet.impl.util.ProgressState) Nonnull(javax.annotation.Nonnull)

Example 7 with ProgressState

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

the class OutboxImpl method offerInternal.

private boolean offerInternal(@Nonnull int[] ordinals, @Nonnull Object item) {
    assert unfinishedItem == null || item.equals(unfinishedItem) : "Different item offered after previous call returned false: expected=" + unfinishedItem + ", got=" + item;
    assert unfinishedItemOrdinals == null || Arrays.equals(unfinishedItemOrdinals, ordinals) : "Offered to different ordinals after previous call returned false: expected=" + Arrays.toString(unfinishedItemOrdinals) + ", got=" + Arrays.toString(ordinals);
    assert numRemainingInBatch != -1 : "Outbox.offer() called again after it returned false, without a " + "call to reset(). You probably didn't return from Processor method after Outbox.offer() " + "or AbstractProcessor.tryEmit() returned false";
    numRemainingInBatch--;
    boolean done = true;
    if (numRemainingInBatch == -1) {
        done = false;
    } else {
        for (int i = 0; i < ordinals.length; i++) {
            if (broadcastTracker.get(i)) {
                continue;
            }
            ProgressState result = doOffer(outstreams[ordinals[i]], item);
            if (result.isMadeProgress()) {
                progTracker.madeProgress();
            }
            if (result.isDone()) {
                broadcastTracker.set(i);
            } else {
                done = false;
            }
        }
    }
    if (done) {
        broadcastTracker.clear();
        unfinishedItem = null;
        unfinishedItemOrdinals = null;
    } else {
        numRemainingInBatch = -1;
        unfinishedItem = item;
        // noinspection ConstantConditions,AssertWithSideEffects
        assert (unfinishedItemOrdinals = Arrays.copyOf(ordinals, ordinals.length)) != null;
    }
    return done;
}
Also used : ProgressState(com.hazelcast.jet.impl.util.ProgressState)

Example 8 with ProgressState

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

the class StoreSnapshotTasklet method stateMachineStep.

private void stateMachineStep() {
    switch(state) {
        case DRAIN:
            progTracker.notDone();
            if (pendingEntry != null) {
                if (!ssWriter.offer(pendingEntry)) {
                    return;
                }
                progTracker.madeProgress();
            }
            pendingEntry = null;
            ProgressState result = inboundEdgeStream.drainTo(addToInboxFunction);
            if (result.isDone()) {
                assert ssWriter.isEmpty() : "input is done, but we had some entries and not the barrier";
                snapshotContext.storeSnapshotTaskletDone(pendingSnapshotId - 1, isHigherPrioritySource);
                state = DONE;
                progTracker.reset();
            }
            progTracker.madeProgress(result.isMadeProgress());
            if (hasReachedBarrier) {
                state = FLUSH;
                stateMachineStep();
            }
            break;
        case FLUSH:
            progTracker.notDone();
            if (ssWriter.flushAndResetMap()) {
                progTracker.madeProgress();
                state = REACHED_BARRIER;
            }
            break;
        case REACHED_BARRIER:
            if (ssWriter.hasPendingAsyncOps()) {
                progTracker.notDone();
                return;
            }
            // check for writing error
            Throwable error = ssWriter.getError();
            if (error != null) {
                logger.severe("Error writing to snapshot map", error);
                snapshotContext.reportError(error);
            }
            progTracker.madeProgress();
            long bytes = ssWriter.getTotalPayloadBytes();
            long keys = ssWriter.getTotalKeys();
            long chunks = ssWriter.getTotalChunks();
            snapshotContext.phase1DoneForTasklet(bytes, keys, chunks);
            metrics.set(new LongLongAccumulator(bytes, keys));
            ssWriter.resetStats();
            pendingSnapshotId++;
            hasReachedBarrier = false;
            state = DRAIN;
            progTracker.notDone();
            break;
        default:
            // note State.DONE also goes here
            throw new JetException("Unexpected state: " + state);
    }
}
Also used : LongLongAccumulator(com.hazelcast.jet.accumulator.LongLongAccumulator) ProgressState(com.hazelcast.jet.impl.util.ProgressState) JetException(com.hazelcast.jet.JetException)

Example 9 with ProgressState

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

the class OutboxImpl method offerInternal.

private boolean offerInternal(@Nonnull int[] ordinals, @Nonnull Object item) {
    if (shouldBlock()) {
        return false;
    }
    assert unfinishedItem == null || item.equals(unfinishedItem) : "Different item offered after previous call returned false: expected=" + unfinishedItem + ", got=" + item;
    assert unfinishedItemOrdinals == null || Arrays.equals(unfinishedItemOrdinals, ordinals) : "Offered to different ordinals after previous call returned false: expected=" + Arrays.toString(unfinishedItemOrdinals) + ", got=" + Arrays.toString(ordinals);
    assert numRemainingInBatch != -1 : "Outbox.offer() called again after it returned false, without a " + "call to reset(). You probably didn't return from Processor method after Outbox.offer() " + "or AbstractProcessor.tryEmit() returned false";
    numRemainingInBatch--;
    boolean done = true;
    if (numRemainingInBatch == -1) {
        done = false;
    } else {
        if (ordinals.length == 0) {
            // edge case - emitting to outbox with 0 ordinals is a progress
            progTracker.madeProgress();
        }
        for (int i = 0; i < ordinals.length; i++) {
            if (broadcastTracker.get(i)) {
                continue;
            }
            ProgressState result = doOffer(outstreams[ordinals[i]], item);
            if (result.isMadeProgress()) {
                progTracker.madeProgress();
            }
            if (result.isDone()) {
                broadcastTracker.set(i);
                if (!(item instanceof BroadcastItem)) {
                    // we are the only updating thread, no need for CAS operations
                    lazyIncrement(counters, ordinals[i]);
                }
            } else {
                done = false;
            }
        }
    }
    if (done) {
        broadcastTracker.clear();
        unfinishedItem = null;
        unfinishedItemOrdinals = null;
        if (item instanceof Watermark) {
            long wmTimestamp = ((Watermark) item).timestamp();
            if (wmTimestamp != WatermarkCoalescer.IDLE_MESSAGE.timestamp()) {
                // emitted to each ordinal, but we don't do that currently.
                assert lastForwardedWm.get() <= wmTimestamp : "current=" + lastForwardedWm.get() + ", new=" + wmTimestamp;
                lastForwardedWm.set(wmTimestamp);
            }
        }
    } else {
        numRemainingInBatch = -1;
        unfinishedItem = item;
        // noinspection ConstantConditions,AssertWithSideEffects
        assert (unfinishedItemOrdinals = Arrays.copyOf(ordinals, ordinals.length)) != null;
    }
    return done;
}
Also used : ProgressState(com.hazelcast.jet.impl.util.ProgressState) Watermark(com.hazelcast.jet.core.Watermark)

Example 10 with ProgressState

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

the class ReceiverTasklet method call.

@Override
@Nonnull
public ProgressState call() {
    if (receptionDone) {
        return collector.offerBroadcast(DONE_ITEM);
    }
    if (connectionChanged) {
        throw new RestartableException("The member was reconnected: " + sourceAddressString);
    }
    tracker.reset();
    tracker.notDone();
    tryFillInbox();
    int ackItemLocal = 0;
    for (ObjWithPtionIdAndSize o; (o = inbox.peek()) != null; ) {
        final Object item = o.getItem();
        if (item == DONE_ITEM) {
            receptionDone = true;
            inbox.remove();
            assert inbox.peek() == null : "Found something in the queue beyond the DONE_ITEM: " + inbox.remove();
            break;
        }
        ProgressState outcome = item instanceof BroadcastItem ? collector.offerBroadcast((BroadcastItem) item) : collector.offer(item, o.getPartitionId());
        if (!outcome.isDone()) {
            tracker.madeProgress(outcome.isMadeProgress());
            break;
        }
        tracker.madeProgress();
        inbox.remove();
        ackItemLocal += o.estimatedMemoryFootprint;
    }
    ackItem(ackItemLocal);
    numWaitingInInbox = inbox.size();
    return tracker.toProgressState();
}
Also used : RestartableException(com.hazelcast.jet.RestartableException) ProgressState(com.hazelcast.jet.impl.util.ProgressState) Nonnull(javax.annotation.Nonnull)

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