Search in sources :

Example 1 with SnapshotPhase1Operation

use of com.hazelcast.jet.impl.operation.SnapshotPhase1Operation in project hazelcast by hazelcast.

the class MasterSnapshotContext method tryBeginSnapshot.

void tryBeginSnapshot() {
    mc.coordinationService().submitToCoordinatorThread(() -> {
        boolean isTerminal;
        String snapshotMapName;
        CompletableFuture<Void> future;
        mc.lock();
        long localExecutionId;
        try {
            if (mc.jobStatus() != RUNNING) {
                logger.fine("Not beginning snapshot, " + mc.jobIdString() + " is not RUNNING, but " + mc.jobStatus());
                return;
            }
            if (snapshotInProgress) {
                logger.fine("Not beginning snapshot since one is already in progress " + mc.jobIdString());
                return;
            }
            if (terminalSnapshotFuture.isDone()) {
                logger.fine("Not beginning snapshot since terminal snapshot is already completed " + mc.jobIdString());
                return;
            }
            Tuple3<String, Boolean, CompletableFuture<Void>> requestedSnapshot = snapshotQueue.poll();
            if (requestedSnapshot == null) {
                return;
            }
            snapshotInProgress = true;
            snapshotMapName = requestedSnapshot.f0();
            assert requestedSnapshot.f1() != null;
            isTerminal = requestedSnapshot.f1();
            future = requestedSnapshot.f2();
            mc.jobExecutionRecord().startNewSnapshot(snapshotMapName);
            localExecutionId = mc.executionId();
        } finally {
            mc.unlock();
        }
        mc.writeJobExecutionRecord(false);
        long newSnapshotId = mc.jobExecutionRecord().ongoingSnapshotId();
        boolean isExport = snapshotMapName != null;
        int snapshotFlags = SnapshotFlags.create(isTerminal, isExport);
        String finalMapName = isExport ? exportedSnapshotMapName(snapshotMapName) : snapshotDataMapName(mc.jobId(), mc.jobExecutionRecord().ongoingDataMapIndex());
        mc.nodeEngine().getHazelcastInstance().getMap(finalMapName).clear();
        logFine(logger, "Starting snapshot %d for %s, flags: %s, writing to: %s", newSnapshotId, jobNameAndExecutionId(mc.jobName(), localExecutionId), SnapshotFlags.toString(snapshotFlags), snapshotMapName);
        Function<ExecutionPlan, Operation> factory = plan -> new SnapshotPhase1Operation(mc.jobId(), localExecutionId, newSnapshotId, finalMapName, snapshotFlags);
        // Need to take a copy of executionId: we don't cancel the scheduled task when the execution
        // finalizes. If a new execution is started in the meantime, we'll use the execution ID to detect it.
        mc.invokeOnParticipants(factory, responses -> onSnapshotPhase1Complete(responses, localExecutionId, newSnapshotId, finalMapName, snapshotFlags, future), null, true);
    });
}
Also used : SnapshotPhase2Operation(com.hazelcast.jet.impl.operation.SnapshotPhase2Operation) LoggingUtil(com.hazelcast.jet.impl.util.LoggingUtil) CompletableFuture.completedFuture(java.util.concurrent.CompletableFuture.completedFuture) CompletableFuture(java.util.concurrent.CompletableFuture) Function(java.util.function.Function) ExecutionNotFoundException(com.hazelcast.jet.impl.exception.ExecutionNotFoundException) ArrayList(java.util.ArrayList) Level(java.util.logging.Level) JetException(com.hazelcast.jet.JetException) Util.jobNameAndExecutionId(com.hazelcast.jet.impl.util.Util.jobNameAndExecutionId) ILogger(com.hazelcast.logging.ILogger) Operation(com.hazelcast.spi.impl.operationservice.Operation) ExceptionUtil.withTryCatch(com.hazelcast.jet.impl.util.ExceptionUtil.withTryCatch) MemberInfo(com.hazelcast.internal.cluster.MemberInfo) Map(java.util.Map) SnapshotPhase1Operation(com.hazelcast.jet.impl.operation.SnapshotPhase1Operation) LinkedList(java.util.LinkedList) EXPORTED_SNAPSHOTS_PREFIX(com.hazelcast.jet.impl.JobRepository.EXPORTED_SNAPSHOTS_PREFIX) Nonnull(javax.annotation.Nonnull) Nullable(javax.annotation.Nullable) Tuple3(com.hazelcast.jet.datamodel.Tuple3) SnapshotFlags(com.hazelcast.jet.impl.execution.SnapshotFlags) Collection(java.util.Collection) JobRepository.snapshotDataMapName(com.hazelcast.jet.impl.JobRepository.snapshotDataMapName) ExecutionException(java.util.concurrent.ExecutionException) JobRepository.exportedSnapshotMapName(com.hazelcast.jet.impl.JobRepository.exportedSnapshotMapName) SnapshotPhase1Result(com.hazelcast.jet.impl.operation.SnapshotPhase1Operation.SnapshotPhase1Result) Tuple3.tuple3(com.hazelcast.jet.datamodel.Tuple3.tuple3) List(java.util.List) Util.idToString(com.hazelcast.jet.Util.idToString) LoggingUtil.logFine(com.hazelcast.jet.impl.util.LoggingUtil.logFine) ExecutionPlan(com.hazelcast.jet.impl.execution.init.ExecutionPlan) Entry(java.util.Map.Entry) RUNNING(com.hazelcast.jet.core.JobStatus.RUNNING) Queue(java.util.Queue) SnapshotStats(com.hazelcast.jet.impl.JobExecutionRecord.SnapshotStats) IMap(com.hazelcast.map.IMap) SnapshotPhase1Operation(com.hazelcast.jet.impl.operation.SnapshotPhase1Operation) Util.idToString(com.hazelcast.jet.Util.idToString) SnapshotPhase2Operation(com.hazelcast.jet.impl.operation.SnapshotPhase2Operation) Operation(com.hazelcast.spi.impl.operationservice.Operation) SnapshotPhase1Operation(com.hazelcast.jet.impl.operation.SnapshotPhase1Operation) CompletableFuture(java.util.concurrent.CompletableFuture) ExecutionPlan(com.hazelcast.jet.impl.execution.init.ExecutionPlan)

Aggregations

MemberInfo (com.hazelcast.internal.cluster.MemberInfo)1 JetException (com.hazelcast.jet.JetException)1 Util.idToString (com.hazelcast.jet.Util.idToString)1 RUNNING (com.hazelcast.jet.core.JobStatus.RUNNING)1 Tuple3 (com.hazelcast.jet.datamodel.Tuple3)1 Tuple3.tuple3 (com.hazelcast.jet.datamodel.Tuple3.tuple3)1 SnapshotStats (com.hazelcast.jet.impl.JobExecutionRecord.SnapshotStats)1 EXPORTED_SNAPSHOTS_PREFIX (com.hazelcast.jet.impl.JobRepository.EXPORTED_SNAPSHOTS_PREFIX)1 JobRepository.exportedSnapshotMapName (com.hazelcast.jet.impl.JobRepository.exportedSnapshotMapName)1 JobRepository.snapshotDataMapName (com.hazelcast.jet.impl.JobRepository.snapshotDataMapName)1 ExecutionNotFoundException (com.hazelcast.jet.impl.exception.ExecutionNotFoundException)1 SnapshotFlags (com.hazelcast.jet.impl.execution.SnapshotFlags)1 ExecutionPlan (com.hazelcast.jet.impl.execution.init.ExecutionPlan)1 SnapshotPhase1Operation (com.hazelcast.jet.impl.operation.SnapshotPhase1Operation)1 SnapshotPhase1Result (com.hazelcast.jet.impl.operation.SnapshotPhase1Operation.SnapshotPhase1Result)1 SnapshotPhase2Operation (com.hazelcast.jet.impl.operation.SnapshotPhase2Operation)1 ExceptionUtil.withTryCatch (com.hazelcast.jet.impl.util.ExceptionUtil.withTryCatch)1 LoggingUtil (com.hazelcast.jet.impl.util.LoggingUtil)1 LoggingUtil.logFine (com.hazelcast.jet.impl.util.LoggingUtil.logFine)1 Util.jobNameAndExecutionId (com.hazelcast.jet.impl.util.Util.jobNameAndExecutionId)1