Java Code Examples for org.apache.flink.runtime.checkpoint.TaskStateSnapshot#getSubtaskStateByOperatorID()

The following examples show how to use org.apache.flink.runtime.checkpoint.TaskStateSnapshot#getSubtaskStateByOperatorID() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TestTaskStateManager.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
@Nonnull
@Override
public PrioritizedOperatorSubtaskState prioritizedOperatorState(OperatorID operatorID) {
	TaskStateSnapshot jmTaskStateSnapshot = getLastJobManagerTaskStateSnapshot();
	TaskStateSnapshot tmTaskStateSnapshot = getLastTaskManagerTaskStateSnapshot();

	if (jmTaskStateSnapshot == null) {

		return PrioritizedOperatorSubtaskState.emptyNotRestored();
	} else {

		OperatorSubtaskState jmOpState = jmTaskStateSnapshot.getSubtaskStateByOperatorID(operatorID);

		if (jmOpState == null) {

			return PrioritizedOperatorSubtaskState.emptyNotRestored();
		} else {

			List<OperatorSubtaskState> tmStateCollection = Collections.emptyList();

			if (tmTaskStateSnapshot != null) {
				OperatorSubtaskState tmOpState = tmTaskStateSnapshot.getSubtaskStateByOperatorID(operatorID);
				if (tmOpState != null) {
					tmStateCollection = Collections.singletonList(tmOpState);
				}
			}
			PrioritizedOperatorSubtaskState.Builder builder =
				new PrioritizedOperatorSubtaskState.Builder(jmOpState, tmStateCollection);
			return builder.build();
		}
	}
}
 
Example 2
Source File: TestTaskStateManager.java    From flink with Apache License 2.0 5 votes vote down vote up
@Nonnull
@Override
public PrioritizedOperatorSubtaskState prioritizedOperatorState(OperatorID operatorID) {
	TaskStateSnapshot jmTaskStateSnapshot = getLastJobManagerTaskStateSnapshot();
	TaskStateSnapshot tmTaskStateSnapshot = getLastTaskManagerTaskStateSnapshot();

	if (jmTaskStateSnapshot == null) {

		return PrioritizedOperatorSubtaskState.emptyNotRestored();
	} else {

		OperatorSubtaskState jmOpState = jmTaskStateSnapshot.getSubtaskStateByOperatorID(operatorID);

		if (jmOpState == null) {

			return PrioritizedOperatorSubtaskState.emptyNotRestored();
		} else {

			List<OperatorSubtaskState> tmStateCollection = Collections.emptyList();

			if (tmTaskStateSnapshot != null) {
				OperatorSubtaskState tmOpState = tmTaskStateSnapshot.getSubtaskStateByOperatorID(operatorID);
				if (tmOpState != null) {
					tmStateCollection = Collections.singletonList(tmOpState);
				}
			}
			PrioritizedOperatorSubtaskState.Builder builder =
				new PrioritizedOperatorSubtaskState.Builder(jmOpState, tmStateCollection);
			return builder.build();
		}
	}
}
 
Example 3
Source File: TestTaskStateManager.java    From flink with Apache License 2.0 5 votes vote down vote up
@Nonnull
@Override
public PrioritizedOperatorSubtaskState prioritizedOperatorState(OperatorID operatorID) {
	TaskStateSnapshot jmTaskStateSnapshot = getLastJobManagerTaskStateSnapshot();
	TaskStateSnapshot tmTaskStateSnapshot = getLastTaskManagerTaskStateSnapshot();

	if (jmTaskStateSnapshot == null) {

		return PrioritizedOperatorSubtaskState.emptyNotRestored();
	} else {

		OperatorSubtaskState jmOpState = jmTaskStateSnapshot.getSubtaskStateByOperatorID(operatorID);

		if (jmOpState == null) {

			return PrioritizedOperatorSubtaskState.emptyNotRestored();
		} else {

			List<OperatorSubtaskState> tmStateCollection = Collections.emptyList();

			if (tmTaskStateSnapshot != null) {
				OperatorSubtaskState tmOpState = tmTaskStateSnapshot.getSubtaskStateByOperatorID(operatorID);
				if (tmOpState != null) {
					tmStateCollection = Collections.singletonList(tmOpState);
				}
			}
			PrioritizedOperatorSubtaskState.Builder builder =
				new PrioritizedOperatorSubtaskState.Builder(jmOpState, tmStateCollection);
			return builder.build();
		}
	}
}
 
Example 4
Source File: TaskStateManagerImpl.java    From Flink-CEPplus with Apache License 2.0 4 votes vote down vote up
@Nonnull
@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.emptyNotRestored();
	}

	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,
		true);

	return builder.build();
}
 
Example 5
Source File: LocalStateForwardingTest.java    From Flink-CEPplus with Apache License 2.0 4 votes vote down vote up
/**
 * This tests the forwarding of jm and tm-local state from the futures reported by the backends, through the
 * async checkpointing thread to the {@link org.apache.flink.runtime.state.TaskStateManager}.
 */
@Test
public void testReportingFromSnapshotToTaskStateManager() {

	TestTaskStateManager taskStateManager = new TestTaskStateManager();

	StreamMockEnvironment streamMockEnvironment = new StreamMockEnvironment(
		new Configuration(),
		new Configuration(),
		new ExecutionConfig(),
		1024 * 1024,
		new MockInputSplitProvider(),
		0,
		taskStateManager);

	StreamTask testStreamTask = new StreamTaskTest.NoOpStreamTask(streamMockEnvironment);
	CheckpointMetaData checkpointMetaData = new CheckpointMetaData(0L, 0L);
	CheckpointMetrics checkpointMetrics = new CheckpointMetrics();

	Map<OperatorID, OperatorSnapshotFutures> snapshots = new HashMap<>(1);
	OperatorSnapshotFutures osFuture = new OperatorSnapshotFutures();

	osFuture.setKeyedStateManagedFuture(createSnapshotResult(KeyedStateHandle.class));
	osFuture.setKeyedStateRawFuture(createSnapshotResult(KeyedStateHandle.class));
	osFuture.setOperatorStateManagedFuture(createSnapshotResult(OperatorStateHandle.class));
	osFuture.setOperatorStateRawFuture(createSnapshotResult(OperatorStateHandle.class));

	OperatorID operatorID = new OperatorID();
	snapshots.put(operatorID, osFuture);

	StreamTask.AsyncCheckpointRunnable checkpointRunnable =
		new StreamTask.AsyncCheckpointRunnable(
			testStreamTask,
			snapshots,
			checkpointMetaData,
			checkpointMetrics,
			0L);

	checkpointRunnable.run();

	TaskStateSnapshot lastJobManagerTaskStateSnapshot = taskStateManager.getLastJobManagerTaskStateSnapshot();
	TaskStateSnapshot lastTaskManagerTaskStateSnapshot = taskStateManager.getLastTaskManagerTaskStateSnapshot();

	OperatorSubtaskState jmState =
		lastJobManagerTaskStateSnapshot.getSubtaskStateByOperatorID(operatorID);

	OperatorSubtaskState tmState =
		lastTaskManagerTaskStateSnapshot.getSubtaskStateByOperatorID(operatorID);

	performCheck(osFuture.getKeyedStateManagedFuture(), jmState.getManagedKeyedState(), tmState.getManagedKeyedState());
	performCheck(osFuture.getKeyedStateRawFuture(), jmState.getRawKeyedState(), tmState.getRawKeyedState());
	performCheck(osFuture.getOperatorStateManagedFuture(), jmState.getManagedOperatorState(), tmState.getManagedOperatorState());
	performCheck(osFuture.getOperatorStateRawFuture(), jmState.getRawOperatorState(), tmState.getRawOperatorState());
}
 
Example 6
Source File: TaskStateManagerImpl.java    From flink with Apache License 2.0 4 votes vote down vote up
@Nonnull
@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.emptyNotRestored();
	}

	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,
		true);

	return builder.build();
}
 
Example 7
Source File: LocalStateForwardingTest.java    From flink with Apache License 2.0 4 votes vote down vote up
/**
 * This tests the forwarding of jm and tm-local state from the futures reported by the backends, through the
 * async checkpointing thread to the {@link org.apache.flink.runtime.state.TaskStateManager}.
 */
@Test
public void testReportingFromSnapshotToTaskStateManager() {

	TestTaskStateManager taskStateManager = new TestTaskStateManager();

	StreamMockEnvironment streamMockEnvironment = new StreamMockEnvironment(
		new Configuration(),
		new Configuration(),
		new ExecutionConfig(),
		1024 * 1024,
		new MockInputSplitProvider(),
		0,
		taskStateManager);

	StreamTask testStreamTask = new StreamTaskTest.NoOpStreamTask(streamMockEnvironment);
	CheckpointMetaData checkpointMetaData = new CheckpointMetaData(0L, 0L);
	CheckpointMetrics checkpointMetrics = new CheckpointMetrics();

	Map<OperatorID, OperatorSnapshotFutures> snapshots = new HashMap<>(1);
	OperatorSnapshotFutures osFuture = new OperatorSnapshotFutures();

	osFuture.setKeyedStateManagedFuture(createSnapshotResult(KeyedStateHandle.class));
	osFuture.setKeyedStateRawFuture(createSnapshotResult(KeyedStateHandle.class));
	osFuture.setOperatorStateManagedFuture(createSnapshotResult(OperatorStateHandle.class));
	osFuture.setOperatorStateRawFuture(createSnapshotResult(OperatorStateHandle.class));

	OperatorID operatorID = new OperatorID();
	snapshots.put(operatorID, osFuture);

	StreamTask.AsyncCheckpointRunnable checkpointRunnable =
		new StreamTask.AsyncCheckpointRunnable(
			testStreamTask,
			snapshots,
			checkpointMetaData,
			checkpointMetrics,
			0L);

	checkpointRunnable.run();

	TaskStateSnapshot lastJobManagerTaskStateSnapshot = taskStateManager.getLastJobManagerTaskStateSnapshot();
	TaskStateSnapshot lastTaskManagerTaskStateSnapshot = taskStateManager.getLastTaskManagerTaskStateSnapshot();

	OperatorSubtaskState jmState =
		lastJobManagerTaskStateSnapshot.getSubtaskStateByOperatorID(operatorID);

	OperatorSubtaskState tmState =
		lastTaskManagerTaskStateSnapshot.getSubtaskStateByOperatorID(operatorID);

	performCheck(osFuture.getKeyedStateManagedFuture(), jmState.getManagedKeyedState(), tmState.getManagedKeyedState());
	performCheck(osFuture.getKeyedStateRawFuture(), jmState.getRawKeyedState(), tmState.getRawKeyedState());
	performCheck(osFuture.getOperatorStateManagedFuture(), jmState.getManagedOperatorState(), tmState.getManagedOperatorState());
	performCheck(osFuture.getOperatorStateRawFuture(), jmState.getRawOperatorState(), tmState.getRawOperatorState());
}
 
Example 8
Source File: TaskStateManagerImpl.java    From flink with Apache License 2.0 4 votes vote down vote up
@Nonnull
@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.emptyNotRestored();
	}

	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,
		true);

	return builder.build();
}
 
Example 9
Source File: LocalStateForwardingTest.java    From flink with Apache License 2.0 4 votes vote down vote up
/**
 * This tests the forwarding of jm and tm-local state from the futures reported by the backends, through the
 * async checkpointing thread to the {@link org.apache.flink.runtime.state.TaskStateManager}.
 */
@Test
public void testReportingFromSnapshotToTaskStateManager() throws Exception {

	TestTaskStateManager taskStateManager = new TestTaskStateManager();

	StreamMockEnvironment streamMockEnvironment = new StreamMockEnvironment(
		new Configuration(),
		new Configuration(),
		new ExecutionConfig(),
		1024 * 1024,
		new MockInputSplitProvider(),
		0,
		taskStateManager);

	StreamTask testStreamTask = new StreamTaskTest.NoOpStreamTask(streamMockEnvironment);
	CheckpointMetaData checkpointMetaData = new CheckpointMetaData(0L, 0L);
	CheckpointMetrics checkpointMetrics = new CheckpointMetrics();

	Map<OperatorID, OperatorSnapshotFutures> snapshots = new HashMap<>(1);
	OperatorSnapshotFutures osFuture = new OperatorSnapshotFutures();

	osFuture.setKeyedStateManagedFuture(createSnapshotResult(KeyedStateHandle.class));
	osFuture.setKeyedStateRawFuture(createSnapshotResult(KeyedStateHandle.class));
	osFuture.setOperatorStateManagedFuture(createSnapshotResult(OperatorStateHandle.class));
	osFuture.setOperatorStateRawFuture(createSnapshotResult(OperatorStateHandle.class));
	osFuture.setInputChannelStateFuture(createSnapshotCollectionResult(InputChannelStateHandle.class));
	osFuture.setResultSubpartitionStateFuture(createSnapshotCollectionResult(ResultSubpartitionStateHandle.class));

	OperatorID operatorID = new OperatorID();
	snapshots.put(operatorID, osFuture);

	AsyncCheckpointRunnable checkpointRunnable = new AsyncCheckpointRunnable(
		snapshots,
		checkpointMetaData,
		checkpointMetrics,
		0L,
		testStreamTask.getName(),
		asyncCheckpointRunnable -> {},
		asyncCheckpointRunnable -> {},
		testStreamTask.getEnvironment(),
		testStreamTask);

	checkpointRunnable.run();

	TaskStateSnapshot lastJobManagerTaskStateSnapshot = taskStateManager.getLastJobManagerTaskStateSnapshot();
	TaskStateSnapshot lastTaskManagerTaskStateSnapshot = taskStateManager.getLastTaskManagerTaskStateSnapshot();

	OperatorSubtaskState jmState =
		lastJobManagerTaskStateSnapshot.getSubtaskStateByOperatorID(operatorID);

	OperatorSubtaskState tmState =
		lastTaskManagerTaskStateSnapshot.getSubtaskStateByOperatorID(operatorID);

	performCheck(osFuture.getKeyedStateManagedFuture(), jmState.getManagedKeyedState(), tmState.getManagedKeyedState());
	performCheck(osFuture.getKeyedStateRawFuture(), jmState.getRawKeyedState(), tmState.getRawKeyedState());
	performCheck(osFuture.getOperatorStateManagedFuture(), jmState.getManagedOperatorState(), tmState.getManagedOperatorState());
	performCheck(osFuture.getOperatorStateRawFuture(), jmState.getRawOperatorState(), tmState.getRawOperatorState());
	performCollectionCheck(osFuture.getInputChannelStateFuture(), jmState.getInputChannelState(), tmState.getInputChannelState());
	performCollectionCheck(osFuture.getResultSubpartitionStateFuture(), jmState.getResultSubpartitionState(), tmState.getResultSubpartitionState());
}