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;
}
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();
}
}
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();
}
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;
}
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));
}
}
Aggregations