Search in sources :

Example 46 with JetException

use of com.hazelcast.jet.JetException in project hazelcast by hazelcast.

the class CdcSourceP method handleConnectException.

private void handleConnectException(RuntimeException ce) {
    reconnectTracker.attemptFailed();
    if (reconnectTracker.shouldTryAgain()) {
        long waitTimeMs = reconnectTracker.getNextWaitTimeMs();
        logger.warning("Failed to initialize the connector task, retrying in " + waitTimeMs + "ms" + getCause(ce));
    } else {
        throw shutDownAndThrow(new JetException("Failed to connect to database" + getCause(ce)));
    }
}
Also used : JetException(com.hazelcast.jet.JetException)

Example 47 with JetException

use of com.hazelcast.jet.JetException in project hazelcast by hazelcast.

the class ReadHadoopNewApiP method getSplits.

private static <K, V> List<InputSplit> getSplits(Configuration configuration) throws Exception {
    InputFormat<K, V> inputFormat = extractInputFormat(configuration);
    Job job = Job.getInstance(configuration);
    try {
        return inputFormat.getSplits(job);
    } catch (InvalidInputException e) {
        String directory = configuration.get(INPUT_DIR, "");
        boolean ignoreFileNotFound = configuration.getBoolean(HadoopSources.IGNORE_FILE_NOT_FOUND, true);
        if (ignoreFileNotFound) {
            ILogger logger = Logger.getLogger(ReadHadoopNewApiP.class);
            logger.fine("The directory '" + directory + "' does not exist. This source will emit 0 items.");
            return emptyList();
        } else {
            throw new JetException("The input " + directory + " matches no files");
        }
    }
}
Also used : InvalidInputException(org.apache.hadoop.mapreduce.lib.input.InvalidInputException) ILogger(com.hazelcast.logging.ILogger) JetException(com.hazelcast.jet.JetException) Job(org.apache.hadoop.mapreduce.Job)

Example 48 with JetException

use of com.hazelcast.jet.JetException in project hazelcast by hazelcast.

the class JobSummaryTest method when_job_failed.

@Test
public void when_job_failed() {
    Pipeline p = Pipeline.create();
    p.readFrom(Sources.mapJournal("invalid", JournalInitialPosition.START_FROM_OLDEST)).withoutTimestamps().writeTo(Sinks.noop());
    Job job = instance.getJet().newJob(p, new JobConfig().setName("jobA"));
    String msg = "";
    try {
        job.join();
    } catch (Exception e) {
        msg = e.getMessage();
    }
    List<JobSummary> list = getJetClientInstanceImpl(client).getJobSummaryList();
    assertEquals(1, list.size());
    JobSummary jobSummary = list.get(0);
    assertContains(new JetException(jobSummary.getFailureText()).toString(), msg);
    assertNotEquals(0, jobSummary.getCompletionTime());
}
Also used : Util.idToString(com.hazelcast.jet.Util.idToString) JetException(com.hazelcast.jet.JetException) Job(com.hazelcast.jet.Job) JobConfig(com.hazelcast.jet.config.JobConfig) JetException(com.hazelcast.jet.JetException) Pipeline(com.hazelcast.jet.pipeline.Pipeline) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 49 with JetException

use of com.hazelcast.jet.JetException in project hazelcast-jet by hazelcast.

the class ProcessorTasklet method stateMachineStep.

@SuppressWarnings("checkstyle:returncount")
private void stateMachineStep(long now) {
    switch(state) {
        case PROCESS_WATERMARK:
            progTracker.notDone();
            if (pendingWatermark == null) {
                long wm = watermarkCoalescer.checkWmHistory(now);
                if (wm == NO_NEW_WM) {
                    state = PROCESS_INBOX;
                    // recursion
                    stateMachineStep(now);
                    break;
                }
                pendingWatermark = new Watermark(wm);
            }
            if (pendingWatermark.equals(IDLE_MESSAGE) || processor.tryProcessWatermark(pendingWatermark)) {
                state = EMIT_WATERMARK;
                // recursion
                stateMachineStep(now);
            }
            break;
        case EMIT_WATERMARK:
            progTracker.notDone();
            if (outbox.offer(pendingWatermark)) {
                state = PROCESS_INBOX;
                pendingWatermark = null;
                // recursion
                stateMachineStep(now);
            }
            break;
        case PROCESS_INBOX:
            progTracker.notDone();
            if (inbox.isEmpty() && (isSnapshotInbox() || processor.tryProcess())) {
                fillInbox(now);
            }
            if (!inbox.isEmpty()) {
                if (isSnapshotInbox()) {
                    processor.restoreFromSnapshot(inbox);
                } else {
                    processor.process(currInstream.ordinal(), inbox);
                }
            }
            if (inbox.isEmpty()) {
                // there is either snapshot or instream is done, not both
                if (currInstream != null && currInstream.isDone()) {
                    state = COMPLETE_EDGE;
                    progTracker.madeProgress();
                    return;
                } else if (context.snapshottingEnabled() && numActiveOrdinals > 0 && receivedBarriers.cardinality() == numActiveOrdinals) {
                    // we have an empty inbox and received the current snapshot barrier from all active ordinals
                    state = SAVE_SNAPSHOT;
                    return;
                } else if (numActiveOrdinals == 0) {
                    progTracker.madeProgress();
                    state = COMPLETE;
                } else {
                    state = PROCESS_WATERMARK;
                }
            }
            return;
        case COMPLETE_EDGE:
            progTracker.notDone();
            if (isSnapshotInbox() ? processor.finishSnapshotRestore() : processor.completeEdge(currInstream.ordinal())) {
                progTracker.madeProgress();
                state = initialProcessingState();
            }
            return;
        case SAVE_SNAPSHOT:
            assert context.snapshottingEnabled() : "Snapshotting is not enabled";
            progTracker.notDone();
            if (processor.saveToSnapshot()) {
                progTracker.madeProgress();
                state = EMIT_BARRIER;
            }
            return;
        case EMIT_BARRIER:
            assert context.snapshottingEnabled() : "Snapshotting is not enabled";
            progTracker.notDone();
            if (outbox.offerToEdgesAndSnapshot(new SnapshotBarrier(pendingSnapshotId))) {
                receivedBarriers.clear();
                pendingSnapshotId++;
                state = initialProcessingState();
            }
            return;
        case COMPLETE:
            progTracker.notDone();
            // check ssContext to see if a barrier should be emitted
            if (context.snapshottingEnabled()) {
                long currSnapshotId = ssContext.lastSnapshotId();
                assert currSnapshotId <= pendingSnapshotId : "Unexpected new snapshot id " + currSnapshotId + ", current was" + pendingSnapshotId;
                if (currSnapshotId == pendingSnapshotId) {
                    state = SAVE_SNAPSHOT;
                    progTracker.madeProgress();
                    return;
                }
            }
            if (processor.complete()) {
                progTracker.madeProgress();
                state = EMIT_DONE_ITEM;
            }
            return;
        case EMIT_DONE_ITEM:
            if (!outbox.offerToEdgesAndSnapshot(DONE_ITEM)) {
                progTracker.notDone();
                return;
            }
            state = END;
            return;
        default:
            // note ProcessorState.END goes here
            throw new JetException("Unexpected state: " + state);
    }
}
Also used : JetException(com.hazelcast.jet.JetException) Watermark(com.hazelcast.jet.core.Watermark)

Example 50 with JetException

use of com.hazelcast.jet.JetException 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)52 IOException (java.io.IOException)8 Nonnull (javax.annotation.Nonnull)8 ILogger (com.hazelcast.logging.ILogger)7 List (java.util.List)7 Map (java.util.Map)6 Util.idToString (com.hazelcast.jet.Util.idToString)5 JobConfig (com.hazelcast.jet.config.JobConfig)5 CompletableFuture (java.util.concurrent.CompletableFuture)5 BroadcastKey (com.hazelcast.jet.core.BroadcastKey)4 JobStatus (com.hazelcast.jet.core.JobStatus)4 Path (java.nio.file.Path)4 HashMap (java.util.HashMap)4 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)4 FunctionEx (com.hazelcast.function.FunctionEx)3 Job (com.hazelcast.jet.Job)3 DAG (com.hazelcast.jet.core.DAG)3 Watermark (com.hazelcast.jet.core.Watermark)3 Tuple2 (com.hazelcast.jet.datamodel.Tuple2)3 Pipeline (com.hazelcast.jet.pipeline.Pipeline)3