Search in sources :

Example 36 with TaskStateSnapshot

use of org.apache.flink.runtime.checkpoint.TaskStateSnapshot in project flink by apache.

the class TaskLocalStateStoreImplTest method createTaskStateSnapshot.

@Nonnull
private TaskStateSnapshot createTaskStateSnapshot() {
    final Map<OperatorID, OperatorSubtaskState> operatorSubtaskStates = new HashMap<>();
    operatorSubtaskStates.put(new OperatorID(), OperatorSubtaskState.builder().build());
    operatorSubtaskStates.put(new OperatorID(), OperatorSubtaskState.builder().build());
    final TaskStateSnapshot taskStateSnapshot = new TaskStateSnapshot(operatorSubtaskStates);
    return taskStateSnapshot;
}
Also used : TaskStateSnapshot(org.apache.flink.runtime.checkpoint.TaskStateSnapshot) HashMap(java.util.HashMap) OperatorID(org.apache.flink.runtime.jobgraph.OperatorID) OperatorSubtaskState(org.apache.flink.runtime.checkpoint.OperatorSubtaskState) Nonnull(javax.annotation.Nonnull)

Example 37 with TaskStateSnapshot

use of org.apache.flink.runtime.checkpoint.TaskStateSnapshot in project flink by apache.

the class TestTaskLocalStateStore method dispose.

public void dispose() {
    if (!disposed) {
        disposed = true;
        for (TaskStateSnapshot stateSnapshot : taskStateSnapshotsByCheckpointID.values()) {
            try {
                stateSnapshot.discardState();
            } catch (Exception e) {
                throw new RuntimeException(e);
            }
        }
        taskStateSnapshotsByCheckpointID.clear();
    }
}
Also used : TaskStateSnapshot(org.apache.flink.runtime.checkpoint.TaskStateSnapshot)

Example 38 with TaskStateSnapshot

use of org.apache.flink.runtime.checkpoint.TaskStateSnapshot in project flink by apache.

the class TaskStateManagerImpl method prioritizedOperatorState.

@Override
public PrioritizedOperatorSubtaskState prioritizedOperatorState(OperatorID operatorID) {
    if (jobManagerTaskRestore == null) {
        return PrioritizedOperatorSubtaskState.emptyNotRestored();
    }
    TaskStateSnapshot jobManagerStateSnapshot = jobManagerTaskRestore.getTaskStateSnapshot();
    OperatorSubtaskState jobManagerSubtaskState = jobManagerStateSnapshot.getSubtaskStateByOperatorID(operatorID);
    if (jobManagerSubtaskState == null) {
        return PrioritizedOperatorSubtaskState.empty(jobManagerTaskRestore.getRestoreCheckpointId());
    }
    long restoreCheckpointId = jobManagerTaskRestore.getRestoreCheckpointId();
    TaskStateSnapshot localStateSnapshot = localStateStore.retrieveLocalState(restoreCheckpointId);
    localStateStore.pruneMatchingCheckpoints((long checkpointId) -> checkpointId != restoreCheckpointId);
    List<OperatorSubtaskState> alternativesByPriority = Collections.emptyList();
    if (localStateSnapshot != null) {
        OperatorSubtaskState localSubtaskState = localStateSnapshot.getSubtaskStateByOperatorID(operatorID);
        if (localSubtaskState != null) {
            alternativesByPriority = Collections.singletonList(localSubtaskState);
        }
    }
    LOG.debug("Operator {} has remote state {} from job manager and local state alternatives {} from local " + "state store {}.", operatorID, jobManagerSubtaskState, alternativesByPriority, localStateStore);
    PrioritizedOperatorSubtaskState.Builder builder = new PrioritizedOperatorSubtaskState.Builder(jobManagerSubtaskState, alternativesByPriority, jobManagerTaskRestore.getRestoreCheckpointId());
    return builder.build();
}
Also used : TaskStateSnapshot(org.apache.flink.runtime.checkpoint.TaskStateSnapshot) PrioritizedOperatorSubtaskState(org.apache.flink.runtime.checkpoint.PrioritizedOperatorSubtaskState) PrioritizedOperatorSubtaskState(org.apache.flink.runtime.checkpoint.PrioritizedOperatorSubtaskState) OperatorSubtaskState(org.apache.flink.runtime.checkpoint.OperatorSubtaskState)

Example 39 with TaskStateSnapshot

use of org.apache.flink.runtime.checkpoint.TaskStateSnapshot in project flink by apache.

the class TaskLocalStateStoreImpl method tryLoadTaskStateSnapshotFromDisk.

@GuardedBy("lock")
@Nullable
private TaskStateSnapshot tryLoadTaskStateSnapshotFromDisk(long checkpointID) {
    final File taskStateSnapshotFile = getTaskStateSnapshotFile(checkpointID);
    if (taskStateSnapshotFile.exists()) {
        TaskStateSnapshot taskStateSnapshot = null;
        try (ObjectInputStream ois = new ObjectInputStream(new FileInputStream(taskStateSnapshotFile))) {
            taskStateSnapshot = (TaskStateSnapshot) ois.readObject();
            LOG.debug("Loaded task state snapshot for checkpoint {} successfully from disk.", checkpointID);
        } catch (IOException | ClassNotFoundException e) {
            LOG.debug("Could not read task state snapshot file {} for checkpoint {}. Deleting the corresponding local state.", taskStateSnapshotFile, checkpointID);
            discardLocalStateForCheckpoint(checkpointID, Optional.empty());
        }
        return taskStateSnapshot;
    }
    return null;
}
Also used : TaskStateSnapshot(org.apache.flink.runtime.checkpoint.TaskStateSnapshot) IOException(java.io.IOException) File(java.io.File) FileInputStream(java.io.FileInputStream) ObjectInputStream(java.io.ObjectInputStream) GuardedBy(javax.annotation.concurrent.GuardedBy) Nullable(javax.annotation.Nullable)

Example 40 with TaskStateSnapshot

use of org.apache.flink.runtime.checkpoint.TaskStateSnapshot in project flink by apache.

the class TaskLocalStateStoreImpl method storeLocalState.

@Override
public void storeLocalState(@Nonnegative long checkpointId, @Nullable TaskStateSnapshot localState) {
    if (localState == null) {
        localState = NULL_DUMMY;
    }
    if (LOG.isTraceEnabled()) {
        LOG.trace("Stored local state for checkpoint {} in subtask ({} - {} - {}) : {}.", checkpointId, jobID, jobVertexID, subtaskIndex, localState);
    } else if (LOG.isDebugEnabled()) {
        LOG.debug("Stored local state for checkpoint {} in subtask ({} - {} - {})", checkpointId, jobID, jobVertexID, subtaskIndex);
    }
    Map.Entry<Long, TaskStateSnapshot> toDiscard = null;
    synchronized (lock) {
        if (disposed) {
            // we ignore late stores and simply discard the state.
            toDiscard = new AbstractMap.SimpleEntry<>(checkpointId, localState);
        } else {
            TaskStateSnapshot previous = storedTaskStateByCheckpointID.put(checkpointId, localState);
            persistLocalStateMetadata(checkpointId, localState);
            if (previous != null) {
                toDiscard = new AbstractMap.SimpleEntry<>(checkpointId, previous);
            }
        }
    }
    if (toDiscard != null) {
        asyncDiscardLocalStateForCollection(Collections.singletonList(toDiscard));
    }
}
Also used : AbstractMap(java.util.AbstractMap) TaskStateSnapshot(org.apache.flink.runtime.checkpoint.TaskStateSnapshot) Map(java.util.Map) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) AbstractMap(java.util.AbstractMap) TreeMap(java.util.TreeMap) SortedMap(java.util.SortedMap)

Aggregations

TaskStateSnapshot (org.apache.flink.runtime.checkpoint.TaskStateSnapshot)42 Test (org.junit.Test)28 OperatorID (org.apache.flink.runtime.jobgraph.OperatorID)19 JobID (org.apache.flink.api.common.JobID)17 ExecutionAttemptID (org.apache.flink.runtime.executiongraph.ExecutionAttemptID)16 CheckpointMetaData (org.apache.flink.runtime.checkpoint.CheckpointMetaData)13 JobManagerTaskRestore (org.apache.flink.runtime.checkpoint.JobManagerTaskRestore)13 OperatorSubtaskState (org.apache.flink.runtime.checkpoint.OperatorSubtaskState)13 CheckpointMetrics (org.apache.flink.runtime.checkpoint.CheckpointMetrics)12 TestCheckpointResponder (org.apache.flink.runtime.taskmanager.TestCheckpointResponder)9 CheckpointResponder (org.apache.flink.runtime.taskmanager.CheckpointResponder)8 IOException (java.io.IOException)7 HashMap (java.util.HashMap)6 OperatorStateHandle (org.apache.flink.runtime.state.OperatorStateHandle)6 CompletableFuture (java.util.concurrent.CompletableFuture)5 KeyedStateHandle (org.apache.flink.runtime.state.KeyedStateHandle)5 TestTaskStateManager (org.apache.flink.runtime.state.TestTaskStateManager)5 InMemoryStateChangelogStorage (org.apache.flink.runtime.state.changelog.inmemory.InMemoryStateChangelogStorage)5 ArrayList (java.util.ArrayList)4 Map (java.util.Map)4