You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@flink.apache.org by "infocusmodereal (via GitHub)" <gi...@apache.org> on 2026/03/23 22:09:50 UTC
[PR] [FLINK-39308][runtime] Skip empty file-merging operator state snapshots [flink]
infocusmodereal opened a new pull request, #27814:
URL: https://github.com/apache/flink/pull/27814
## What is the purpose of the change
This pull request avoids materializing file-merging operator state handles when operator list state is registered but empty.
Today `DefaultOperatorStateBackendSnapshotStrategy` only takes the empty fast path when there are no registered operator states at all. If empty operator list states are registered, file-merging checkpoints can still create tiny segment-backed handles. During restore, `OperatorStateRestoreOperation` opens those handles even though they contain no operator-state partitions. On object stores this adds avoidable restore overhead.
## Brief change log
- Detect the case where there are no broadcast states and all registered operator list states are empty
- Reuse the existing empty snapshot fast path for that case
- Return `EmptyFileMergingOperatorStreamStateHandle` for file-merging checkpoints and `SnapshotResult.empty()` otherwise
- Add tests for empty registered operator state snapshots and file-merging restore
## Verifying this change
Please make sure both new and modified tests in this PR follow [the conventions for tests defined in our code quality guide](https://flink.apache.org/how-to-contribute/code-style-and-quality-common/#7-testing).
This change added tests and can be verified as follows:
- Added `testSnapshotWithEmptyRegisteredOperatorState`
- Added `testFileMergingSnapshotRestoreWithEmptyRegisteredUnionState`
- Ran `JAVA_HOME=$(/usr/libexec/java_home -v 17) ./mvnw -pl flink-runtime -Dtest=OperatorStateBackendTest,OperatorStateRestoreOperationTest,SharedStateRegistryTest test -Djdk17 -Pjava17-target`
## Does this pull request potentially affect one of the following parts:
- Dependencies (does it add or upgrade a dependency): no
- The public API, i.e., is any changed class annotated with `@Public(Evolving)`: no
- The serializers: no
- The runtime per-record code paths (performance sensitive): no
- Anything that affects deployment or recovery: JobManager (and its components), Checkpointing, Kubernetes/Yarn, ZooKeeper: yes
- The S3 file system connector: no
## Documentation
- Does this pull request introduce a new feature? no
- If yes, how is the feature documented? not applicable
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@flink.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [FLINK-39308][runtime] Skip empty file-merging operator state snapshots [flink]
Posted by "davidradl (via GitHub)" <gi...@apache.org>.
davidradl commented on code in PR #27814:
URL: https://github.com/apache/flink/pull/27814#discussion_r2989639946
##########
flink-runtime/src/main/java/org/apache/flink/runtime/state/DefaultOperatorStateBackendSnapshotStrategy.java:
##########
@@ -236,6 +251,20 @@ public SnapshotResultSupplier<OperatorStateHandle> asyncSnapshot(
};
}
+ private boolean hasOnlyEmptyOperatorListStates(
+ Map<String, PartitionableListState<?>> registeredOperatorStatesDeepCopies) {
+ if (registeredOperatorStatesDeepCopies.isEmpty()) {
+ return false;
+ }
+
+ for (PartitionableListState<?> listState : registeredOperatorStatesDeepCopies.values()) {
Review Comment:
I see the method is called `private boolean hasOnlyEmptyOperatorListStates(`
I am not sure what the test for emptiness is. The only thing I see is `listState == null`,
but `if listState == null` then we return `false`.
What am I missing?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@flink.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [FLINK-39308][runtime] Skip empty file-merging operator state snapshots [flink]
Posted by "featzhang (via GitHub)" <gi...@apache.org>.
featzhang commented on code in PR #27814:
URL: https://github.com/apache/flink/pull/27814#discussion_r3008537747
##########
flink-runtime/src/main/java/org/apache/flink/runtime/state/DefaultOperatorStateBackendSnapshotStrategy.java:
##########
@@ -122,6 +122,21 @@ public SnapshotResultSupplier<OperatorStateHandle> asyncSnapshot(
Map<String, BackendWritableBroadcastState<?, ?>> registeredBroadcastStatesDeepCopies =
syncPartResource.getRegisteredBroadcastStatesDeepCopies();
+ if (registeredBroadcastStatesDeepCopies.isEmpty()
+ && hasOnlyEmptyOperatorListStates(registeredOperatorStatesDeepCopies)) {
+ if (streamFactory instanceof FsMergingCheckpointStorageLocation) {
Review Comment:
After casting to FsMergingCheckpointStorageLocation, it directly returns EmptyFileMergingOperatorStreamStateHandle. Add a comment explaining why empty snapshots take this branch.
##########
flink-runtime/src/test/java/org/apache/flink/runtime/state/OperatorStateBackendTest.java:
##########
@@ -489,6 +490,124 @@ void testFileMergingSnapshotEmpty(@TempDir File tmpFolder) throws Exception {
assertThat(stateHandle).isInstanceOf(FileMergingOperatorStreamStateHandle.class);
}
+ @Test
+ void testSnapshotWithEmptyRegisteredOperatorState() throws Exception {
+ final AbstractStateBackend abstractStateBackend = new HashMapStateBackend();
+ CloseableRegistry cancelStreamRegistry = new CloseableRegistry();
+
+ Environment env = createMockEnvironment();
+ final OperatorStateBackend operatorStateBackend =
+ abstractStateBackend.createOperatorStateBackend(
+ new OperatorStateBackendParametersImpl(
+ env, "testOperator", emptyStateHandles, cancelStreamRegistry));
+
+ ListStateDescriptor<Integer> stateDescriptor =
+ new ListStateDescriptor<>("test-empty-list-state", IntSerializer.INSTANCE);
+ try {
+ ListState<Integer> listState = operatorStateBackend.getListState(stateDescriptor);
+ assertThat(listState.get()).isEmpty();
+
+ CheckpointStreamFactory streamFactory = new MemCheckpointStreamFactory(4096);
+
+ RunnableFuture<SnapshotResult<OperatorStateHandle>> snapshot =
+ operatorStateBackend.snapshot(
+ 0L,
+ 0L,
+ streamFactory,
+ CheckpointOptions.forCheckpointWithDefaultLocation());
+
+ SnapshotResult<OperatorStateHandle> snapshotResult =
+ FutureUtils.runIfNotDoneAndGet(snapshot);
+ OperatorStateHandle stateHandle = snapshotResult.getJobManagerOwnedSnapshot();
+ assertThat(stateHandle).isNull();
+ } finally {
+ operatorStateBackend.close();
+ operatorStateBackend.dispose();
+ }
+ }
+
+ @Test
+ void testFileMergingSnapshotRestoreWithEmptyRegisteredUnionState(@TempDir File tmpFolder)
Review Comment:
In testFileMergingSnapshotRestoreWithEmptyRegisteredUnionState, the finally block only calls discardState() on stateHandle. Consider additionally verifying that FsMerging-related resources (temp files, snapshotManager) are correctly released to prevent leaks.
##########
flink-runtime/src/main/java/org/apache/flink/runtime/state/DefaultOperatorStateBackendSnapshotStrategy.java:
##########
@@ -122,6 +122,21 @@ public SnapshotResultSupplier<OperatorStateHandle> asyncSnapshot(
Map<String, BackendWritableBroadcastState<?, ?>> registeredBroadcastStatesDeepCopies =
syncPartResource.getRegisteredBroadcastStatesDeepCopies();
+ if (registeredBroadcastStatesDeepCopies.isEmpty()
+ && hasOnlyEmptyOperatorListStates(registeredOperatorStatesDeepCopies)) {
+ if (streamFactory instanceof FsMergingCheckpointStorageLocation) {
+ FsMergingCheckpointStorageLocation location =
+ (FsMergingCheckpointStorageLocation) streamFactory;
+ return snapshotCloseableRegistry ->
+ SnapshotResult.of(
+ EmptyFileMergingOperatorStreamStateHandle.create(
+ location.getExclusiveStateHandle(),
+ location.getSharedStateHandle()));
+ } else {
+ return snapshotCloseableRegistry -> SnapshotResult.empty();
Review Comment:
The else branch returns SnapshotResult.empty(). Add a comment explaining that this is the handling strategy for empty snapshots when not using FsMerging, for clarity.
##########
flink-runtime/src/test/java/org/apache/flink/runtime/state/OperatorStateBackendTest.java:
##########
@@ -489,6 +490,124 @@ void testFileMergingSnapshotEmpty(@TempDir File tmpFolder) throws Exception {
assertThat(stateHandle).isInstanceOf(FileMergingOperatorStreamStateHandle.class);
}
+ @Test
+ void testSnapshotWithEmptyRegisteredOperatorState() throws Exception {
Review Comment:
In testSnapshotWithEmptyRegisteredOperatorState, currently asserts stateHandle is null. Also assert snapshotResult.isEmpty() or its type to ensure empty snapshot behavior is as expected.
##########
flink-runtime/src/test/java/org/apache/flink/runtime/state/OperatorStateBackendTest.java:
##########
@@ -489,6 +490,124 @@ void testFileMergingSnapshotEmpty(@TempDir File tmpFolder) throws Exception {
assertThat(stateHandle).isInstanceOf(FileMergingOperatorStreamStateHandle.class);
}
+ @Test
+ void testSnapshotWithEmptyRegisteredOperatorState() throws Exception {
+ final AbstractStateBackend abstractStateBackend = new HashMapStateBackend();
+ CloseableRegistry cancelStreamRegistry = new CloseableRegistry();
+
+ Environment env = createMockEnvironment();
+ final OperatorStateBackend operatorStateBackend =
+ abstractStateBackend.createOperatorStateBackend(
+ new OperatorStateBackendParametersImpl(
+ env, "testOperator", emptyStateHandles, cancelStreamRegistry));
+
+ ListStateDescriptor<Integer> stateDescriptor =
+ new ListStateDescriptor<>("test-empty-list-state", IntSerializer.INSTANCE);
+ try {
+ ListState<Integer> listState = operatorStateBackend.getListState(stateDescriptor);
+ assertThat(listState.get()).isEmpty();
+
+ CheckpointStreamFactory streamFactory = new MemCheckpointStreamFactory(4096);
+
+ RunnableFuture<SnapshotResult<OperatorStateHandle>> snapshot =
+ operatorStateBackend.snapshot(
+ 0L,
+ 0L,
+ streamFactory,
+ CheckpointOptions.forCheckpointWithDefaultLocation());
+
+ SnapshotResult<OperatorStateHandle> snapshotResult =
+ FutureUtils.runIfNotDoneAndGet(snapshot);
+ OperatorStateHandle stateHandle = snapshotResult.getJobManagerOwnedSnapshot();
+ assertThat(stateHandle).isNull();
+ } finally {
+ operatorStateBackend.close();
+ operatorStateBackend.dispose();
+ }
+ }
+
+ @Test
+ void testFileMergingSnapshotRestoreWithEmptyRegisteredUnionState(@TempDir File tmpFolder)
+ throws Exception {
+ final AbstractStateBackend abstractStateBackend = new HashMapStateBackend();
+ CloseableRegistry cancelStreamRegistry = new CloseableRegistry();
+
+ Environment env = createMockEnvironment();
+ OperatorStateBackend operatorStateBackend =
+ abstractStateBackend.createOperatorStateBackend(
+ new OperatorStateBackendParametersImpl(
+ env, "testOperator", emptyStateHandles, cancelStreamRegistry));
+
+ ListStateDescriptor<Integer> stateDescriptor =
+ new ListStateDescriptor<>("test-empty-union-state", IntSerializer.INSTANCE);
+ ListState<Integer> unionState = operatorStateBackend.getUnionListState(stateDescriptor);
+ assertThat(unionState.get()).isEmpty();
+
+ Path checkpointBaseDir = new Path(tmpFolder.toString());
+ Path sharedStateDir =
+ new Path(
+ checkpointBaseDir,
+ AbstractFsCheckpointStorageAccess.CHECKPOINT_SHARED_STATE_DIR);
+ Path taskOwnedStateDir =
+ new Path(
+ checkpointBaseDir,
+ AbstractFsCheckpointStorageAccess.CHECKPOINT_TASK_OWNED_STATE_DIR);
+
+ JobID jobId = JobID.generate();
+ final FileMergingSnapshotManager.SubtaskKey subtaskKey =
+ new FileMergingSnapshotManager.SubtaskKey(jobId.toHexString(), "opId", 1, 1);
+ LocalFileSystem fs = getSharedInstance();
+ CheckpointStorageLocationReference cslReference =
+ AbstractFsCheckpointStorageAccess.encodePathAsReference(
+ fromLocalFile(fs.pathToFile(checkpointBaseDir)));
+ FileMergingSnapshotManager snapshotManager =
+ createFileMergingSnapshotManager(
+ checkpointBaseDir, sharedStateDir, taskOwnedStateDir, subtaskKey);
+ CheckpointStreamFactory streamFactory =
+ new FsMergingCheckpointStorageLocation(
+ subtaskKey,
+ fs,
+ checkpointBaseDir,
+ sharedStateDir,
+ taskOwnedStateDir,
+ cslReference,
+ 1024,
+ 1024,
+ snapshotManager,
+ 0);
+
+ OperatorStateHandle stateHandle = null;
+ try {
+ RunnableFuture<SnapshotResult<OperatorStateHandle>> snapshot =
+ operatorStateBackend.snapshot(
+ 0L,
+ 0L,
+ streamFactory,
+ CheckpointOptions.forCheckpointWithDefaultLocation());
+
+ SnapshotResult<OperatorStateHandle> snapshotResult =
+ FutureUtils.runIfNotDoneAndGet(snapshot);
+ stateHandle = snapshotResult.getJobManagerOwnedSnapshot();
+
+ assertThat(stateHandle).isInstanceOf(EmptyFileMergingOperatorStreamStateHandle.class);
Review Comment:
Asserting stateHandle type as EmptyFileMergingOperatorStreamStateHandle is correct. Add a comment explaining this is a special case for empty operator state to improve readability.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@flink.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [FLINK-39308][runtime] Skip empty file-merging operator state snapshots [flink]
Posted by "flinkbot (via GitHub)" <gi...@apache.org>.
flinkbot commented on PR #27814:
URL: https://github.com/apache/flink/pull/27814#issuecomment-4114054208
<!--
Meta data
{
"version" : 1,
"metaDataEntries" : [ {
"hash" : "15177a326df69ac3efa0bbd1fab8cd717b30f687",
"status" : "UNKNOWN",
"url" : "TBD",
"triggerID" : "15177a326df69ac3efa0bbd1fab8cd717b30f687",
"triggerType" : "PUSH"
} ]
}-->
## CI report:
* 15177a326df69ac3efa0bbd1fab8cd717b30f687 UNKNOWN
<details>
<summary>Bot commands</summary>
The @flinkbot bot supports the following commands:
- `@flinkbot run azure` re-run the last Azure build
</details>
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@flink.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [FLINK-39308][runtime] Skip empty file-merging operator state snapshots [flink]
Posted by "davidradl (via GitHub)" <gi...@apache.org>.
davidradl commented on code in PR #27814:
URL: https://github.com/apache/flink/pull/27814#discussion_r2989618911
##########
flink-runtime/src/main/java/org/apache/flink/runtime/state/DefaultOperatorStateBackendSnapshotStrategy.java:
##########
@@ -122,6 +122,21 @@ public SnapshotResultSupplier<OperatorStateHandle> asyncSnapshot(
Map<String, BackendWritableBroadcastState<?, ?>> registeredBroadcastStatesDeepCopies =
syncPartResource.getRegisteredBroadcastStatesDeepCopies();
+ if (registeredBroadcastStatesDeepCopies.isEmpty()
Review Comment:
It is strange that this if does
registeredOperatorStatesDeepCopies.isEmpty()
and the first thing the method you have introduced does is:
registeredOperatorStatesDeepCopies.isEmpty()
I suggest doing everything in the method
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@flink.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org