You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@flink.apache.org by "mayuehappy (via GitHub)" <gi...@apache.org> on 2025/04/16 07:04:05 UTC

[PR] [FLINK-37552] Support switching between ForStKeyedStatebackend and ForStSyncKeyedStatebackend [flink]

mayuehappy opened a new pull request, #26466:
URL: https://github.com/apache/flink/pull/26466

   …rStSyncKeyedStatebackend
   
   <!--
   *Thank you very much for contributing to Apache Flink - we are happy that you want to help us improve Flink. To help the community review your contribution in the best possible way, please go through the checklist below, which will get the contribution into a shape in which it can be best reviewed.*
   
   *Please understand that we do not do this to make contributions to Flink a hassle. In order to uphold a high standard of quality for code contributions, while at the same time managing a large number of contributions, we need contributors to prepare the contributions well, and give reviewers enough contextual information for the review. Please also understand that contributions that do not follow this guide will take longer to review and thus typically be picked up with lower priority by the community.*
   
   ## Contribution Checklist
   
     - Make sure that the pull request corresponds to a [JIRA issue](https://issues.apache.org/jira/projects/FLINK/issues). Exceptions are made for typos in JavaDoc or documentation files, which need no JIRA issue.
     
     - Name the pull request in the form "[FLINK-XXXX] [component] Title of the pull request", where *FLINK-XXXX* should be replaced by the actual issue number. Skip *component* if you are unsure about which is the best component.
     Typo fixes that have no associated JIRA issue should be named following this pattern: `[hotfix] [docs] Fix typo in event time introduction` or `[hotfix] [javadocs] Expand JavaDoc for PuncuatedWatermarkGenerator`.
   
     - Fill out the template below to describe the changes contributed by the pull request. That will give reviewers the context they need to do the review.
     
     - Make sure that the change passes the automated tests, i.e., `mvn clean verify` passes. You can set up Azure Pipelines CI to do that following [this guide](https://cwiki.apache.org/confluence/display/FLINK/Azure+Pipelines#AzurePipelines-Tutorial:SettingupAzurePipelinesforaforkoftheFlinkrepository).
   
     - Each pull request should address only one issue, not mix up code from multiple issues.
     
     - Each commit in the pull request has a meaningful commit message (including the JIRA id)
   
     - Once all items of the checklist are addressed, remove the above text and this checklist, leaving only the filled out template below.
   
   
   **(The sections below can be removed for hotfixes of typos)**
   -->
   
   ## What is the purpose of the change
   
   *(For example: This pull request makes task deployment go through the blob server, rather than through RPC. That way we avoid re-transferring them on each deployment (during recovery).)*
   
   Support switching between ForStKeyedStatebackend and ForStSyncKeyedStatebackend
   
   ## Brief change log
   
   Convert the `StateMetaInfo` of `ForStKeyeStatebackend` and `ForStSyncKeyeStatebackend` into a unified format through the `RegisteredStateMetaInfoUtils` during recovery.
   
   
   ## Verifying this change
   
   
   *(Please pick either of the following options)*
   
   
   
   This change is already covered by existing tests, such as *(please describe tests)*.
   
   ForStAsyncAndSyncCompatibilityTest#testForStTransFromAsyncToSync and ForStAsyncAndSyncCompatibilityTest#testForStTransFromSyncToAsync 
   
   This change added tests and can be verified as follows:
   
   *(example:)*
     - *Added integration tests for end-to-end deployment with large payloads (100MB)*
     - *Extended integration test for recovery after master (JobManager) failure*
     - *Added test that validates that TaskInfo is transferred only once across recoveries*
     - *Manually verified the change by running a 4 node cluster with 2 JobManagers and 4 TaskManagers, a stateful streaming program, and killing one JobManager and two TaskManagers during the execution, verifying that recovery happens correctly.*
   
   ## 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: JCheckpointing
     - The S3 file system connector: (no)
   
   ## Documentation
   
     - Does this pull request introduce a new feature? ( no)
     - If yes, how is the feature documented? (not documented)
   


-- 
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-37552] Support switching between ForStKeyedStatebackend and ForStSyncKeyedStatebackend [flink]

Posted by "mayuehappy (via GitHub)" <gi...@apache.org>.
mayuehappy commented on PR #26466:
URL: https://github.com/apache/flink/pull/26466#issuecomment-2820819302

   > Thanks for the PR! One overall question:
   > 
   > Could we transform `snapshot` to `metainfo` directly in recovery code path, instead of transform from two versions of `metainfo`?
   
   @Zakelly thanks for your suggestion , I've updated the code , PTAL


-- 
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-37552] Support switching between ForStKeyedStatebackend and ForStSyncKeyedStatebackend [flink]

Posted by "flinkbot (via GitHub)" <gi...@apache.org>.
flinkbot commented on PR #26466:
URL: https://github.com/apache/flink/pull/26466#issuecomment-2808611542

   <!--
   Meta data
   {
     "version" : 1,
     "metaDataEntries" : [ {
       "hash" : "fb737504b18fef516f9c8a6ae0f527b6d4c232fa",
       "status" : "UNKNOWN",
       "url" : "TBD",
       "triggerID" : "fb737504b18fef516f9c8a6ae0f527b6d4c232fa",
       "triggerType" : "PUSH"
     } ]
   }-->
   ## CI report:
   
   * fb737504b18fef516f9c8a6ae0f527b6d4c232fa 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-37552] Support switching between ForStKeyedStatebackend and ForStSyncKeyedStatebackend [flink]

Posted by "fredia (via GitHub)" <gi...@apache.org>.
fredia commented on code in PR #26466:
URL: https://github.com/apache/flink/pull/26466#discussion_r2080905375


##########
flink-runtime/src/main/java/org/apache/flink/runtime/state/RegisteredStateMetaInfoUtils.java:
##########
@@ -0,0 +1,176 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.flink.runtime.state;
+
+import org.apache.flink.api.common.state.v2.StateDescriptor;
+import org.apache.flink.api.common.typeutils.TypeSerializerSnapshot;
+import org.apache.flink.api.common.typeutils.base.ListSerializer;
+import org.apache.flink.api.common.typeutils.base.MapSerializer;
+import org.apache.flink.runtime.state.metainfo.StateMetaInfoSnapshot;
+import org.apache.flink.util.Preconditions;
+
+/**
+ * Utilities for transforming {@link RegisteredKeyValueStateBackendMetaInfo} to {@link
+ * org.apache.flink.runtime.state.v2.RegisteredKeyValueStateBackendMetaInfo}.
+ */
+public class RegisteredStateMetaInfoUtils {
+
+    private RegisteredStateMetaInfoUtils() {}
+
+    public static org.apache.flink.runtime.state.v2.RegisteredKeyValueStateBackendMetaInfo
+            createMetaInfoV2FromV1Snapshot(StateMetaInfoSnapshot stateMeta) {
+
+        Preconditions.checkArgument(
+                stateMeta
+                        .getBackendStateType()
+                        .equals(StateMetaInfoSnapshot.BackendStateType.KEY_VALUE));
+
+        StateDescriptor.Type newStateType;
+        TypeSerializerSnapshot oldValueSerializerSnapshot =
+                stateMeta.getTypeSerializerSnapshot(
+                        StateMetaInfoSnapshot.CommonSerializerKeys.VALUE_SERIALIZER);
+        TypeSerializerSnapshot newUserKeySerializerSnapshot = oldValueSerializerSnapshot;
+        TypeSerializerSnapshot newStateSerializerSnapshot = null;
+
+        switch (org.apache.flink.api.common.state.StateDescriptor.Type.valueOf(
+                stateMeta.getOption(StateMetaInfoSnapshot.CommonOptionsKeys.KEYED_STATE_TYPE))) {
+            case VALUE:
+                newStateType = StateDescriptor.Type.VALUE;
+                break;
+            case REDUCING:
+                newStateType = StateDescriptor.Type.REDUCING;
+                break;
+            case AGGREGATING:
+                newStateType = StateDescriptor.Type.AGGREGATING;
+                break;
+            case LIST:
+                newStateType = StateDescriptor.Type.LIST;
+                newStateSerializerSnapshot =
+                        ((ListSerializer) oldValueSerializerSnapshot.restoreSerializer())
+                                .getElementSerializer()
+                                .snapshotConfiguration();
+                break;
+            case MAP:
+                newStateType = StateDescriptor.Type.MAP;
+                newStateSerializerSnapshot =
+                        ((MapSerializer) oldValueSerializerSnapshot.restoreSerializer())
+                                .getValueSerializer()
+                                .snapshotConfiguration();
+                newUserKeySerializerSnapshot =
+                        ((MapSerializer) oldValueSerializerSnapshot.restoreSerializer())
+                                .getKeySerializer()
+                                .snapshotConfiguration();
+                break;
+            default:
+                throw new UnsupportedOperationException(
+                        "Unsupported state type to transform from org.apache.flink.runtime.state.RegisteredKeyValueStateBackendMetaInfo to org.apache.flink.runtime.state.v2.RegisteredKeyValueStateBackendMetaInfo");
+        }
+
+        if (!newStateType.equals(StateDescriptor.Type.MAP)) {
+            return new org.apache.flink.runtime.state.v2.RegisteredKeyValueStateBackendMetaInfo<>(
+                    stateMeta.getName(),
+                    newStateType,
+                    StateSerializerProvider.fromPreviousSerializerSnapshot(
+                            stateMeta.getTypeSerializerSnapshot(
+                                    StateMetaInfoSnapshot.CommonSerializerKeys
+                                            .NAMESPACE_SERIALIZER)),
+                    StateSerializerProvider.fromPreviousSerializerSnapshot(
+                            newStateSerializerSnapshot),
+                    StateSnapshotTransformer.StateSnapshotTransformFactory.noTransform());
+        } else {
+            return new org.apache.flink.runtime.state.v2
+                    .RegisteredKeyAndUserKeyValueStateBackendMetaInfo<>(
+                    stateMeta.getName(),
+                    newStateType,
+                    StateSerializerProvider.fromPreviousSerializerSnapshot(
+                            stateMeta.getTypeSerializerSnapshot(
+                                    StateMetaInfoSnapshot.CommonSerializerKeys
+                                            .NAMESPACE_SERIALIZER)),
+                    StateSerializerProvider.fromPreviousSerializerSnapshot(
+                            newStateSerializerSnapshot),
+                    StateSerializerProvider.fromPreviousSerializerSnapshot(
+                            newUserKeySerializerSnapshot),
+                    StateSnapshotTransformer.StateSnapshotTransformFactory.noTransform());
+        }
+    }
+
+    public static RegisteredKeyValueStateBackendMetaInfo createMetaInfoV1FromV2Snapshot(
+            StateMetaInfoSnapshot stateMeta) {
+
+        Preconditions.checkArgument(
+                stateMeta
+                        .getBackendStateType()
+                        .equals(StateMetaInfoSnapshot.BackendStateType.KEY_VALUE_V2));
+        org.apache.flink.api.common.state.StateDescriptor.Type newStateType;
+        TypeSerializerSnapshot oldValueSerializerSnapshot =
+                stateMeta.getTypeSerializerSnapshot(
+                        StateMetaInfoSnapshot.CommonSerializerKeys.VALUE_SERIALIZER);
+        TypeSerializerSnapshot oldUserKeySerializerSnapshot =
+                stateMeta.getTypeSerializerSnapshot(
+                        StateMetaInfoSnapshot.CommonSerializerKeys.USER_KEY_SERIALIZER);
+        ;

Review Comment:
   nit: remove `;`



##########
flink-runtime/src/main/java/org/apache/flink/runtime/state/RegisteredStateMetaInfoUtils.java:
##########
@@ -0,0 +1,176 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.flink.runtime.state;
+
+import org.apache.flink.api.common.state.v2.StateDescriptor;
+import org.apache.flink.api.common.typeutils.TypeSerializerSnapshot;
+import org.apache.flink.api.common.typeutils.base.ListSerializer;
+import org.apache.flink.api.common.typeutils.base.MapSerializer;
+import org.apache.flink.runtime.state.metainfo.StateMetaInfoSnapshot;
+import org.apache.flink.util.Preconditions;
+
+/**
+ * Utilities for transforming {@link RegisteredKeyValueStateBackendMetaInfo} to {@link
+ * org.apache.flink.runtime.state.v2.RegisteredKeyValueStateBackendMetaInfo}.
+ */
+public class RegisteredStateMetaInfoUtils {
+
+    private RegisteredStateMetaInfoUtils() {}
+
+    public static org.apache.flink.runtime.state.v2.RegisteredKeyValueStateBackendMetaInfo
+            createMetaInfoV2FromV1Snapshot(StateMetaInfoSnapshot stateMeta) {
+
+        Preconditions.checkArgument(
+                stateMeta
+                        .getBackendStateType()
+                        .equals(StateMetaInfoSnapshot.BackendStateType.KEY_VALUE));
+
+        StateDescriptor.Type newStateType;
+        TypeSerializerSnapshot oldValueSerializerSnapshot =
+                stateMeta.getTypeSerializerSnapshot(
+                        StateMetaInfoSnapshot.CommonSerializerKeys.VALUE_SERIALIZER);
+        TypeSerializerSnapshot newUserKeySerializerSnapshot = oldValueSerializerSnapshot;
+        TypeSerializerSnapshot newStateSerializerSnapshot = null;
+
+        switch (org.apache.flink.api.common.state.StateDescriptor.Type.valueOf(
+                stateMeta.getOption(StateMetaInfoSnapshot.CommonOptionsKeys.KEYED_STATE_TYPE))) {
+            case VALUE:
+                newStateType = StateDescriptor.Type.VALUE;
+                break;
+            case REDUCING:
+                newStateType = StateDescriptor.Type.REDUCING;
+                break;
+            case AGGREGATING:
+                newStateType = StateDescriptor.Type.AGGREGATING;
+                break;
+            case LIST:
+                newStateType = StateDescriptor.Type.LIST;
+                newStateSerializerSnapshot =
+                        ((ListSerializer) oldValueSerializerSnapshot.restoreSerializer())
+                                .getElementSerializer()
+                                .snapshotConfiguration();
+                break;
+            case MAP:
+                newStateType = StateDescriptor.Type.MAP;
+                newStateSerializerSnapshot =
+                        ((MapSerializer) oldValueSerializerSnapshot.restoreSerializer())
+                                .getValueSerializer()
+                                .snapshotConfiguration();
+                newUserKeySerializerSnapshot =
+                        ((MapSerializer) oldValueSerializerSnapshot.restoreSerializer())
+                                .getKeySerializer()
+                                .snapshotConfiguration();
+                break;
+            default:
+                throw new UnsupportedOperationException(
+                        "Unsupported state type to transform from org.apache.flink.runtime.state.RegisteredKeyValueStateBackendMetaInfo to org.apache.flink.runtime.state.v2.RegisteredKeyValueStateBackendMetaInfo");
+        }
+
+        if (!newStateType.equals(StateDescriptor.Type.MAP)) {
+            return new org.apache.flink.runtime.state.v2.RegisteredKeyValueStateBackendMetaInfo<>(
+                    stateMeta.getName(),
+                    newStateType,
+                    StateSerializerProvider.fromPreviousSerializerSnapshot(
+                            stateMeta.getTypeSerializerSnapshot(
+                                    StateMetaInfoSnapshot.CommonSerializerKeys
+                                            .NAMESPACE_SERIALIZER)),
+                    StateSerializerProvider.fromPreviousSerializerSnapshot(
+                            newStateSerializerSnapshot),
+                    StateSnapshotTransformer.StateSnapshotTransformFactory.noTransform());
+        } else {
+            return new org.apache.flink.runtime.state.v2
+                    .RegisteredKeyAndUserKeyValueStateBackendMetaInfo<>(
+                    stateMeta.getName(),
+                    newStateType,
+                    StateSerializerProvider.fromPreviousSerializerSnapshot(
+                            stateMeta.getTypeSerializerSnapshot(
+                                    StateMetaInfoSnapshot.CommonSerializerKeys
+                                            .NAMESPACE_SERIALIZER)),
+                    StateSerializerProvider.fromPreviousSerializerSnapshot(
+                            newStateSerializerSnapshot),
+                    StateSerializerProvider.fromPreviousSerializerSnapshot(
+                            newUserKeySerializerSnapshot),
+                    StateSnapshotTransformer.StateSnapshotTransformFactory.noTransform());
+        }
+    }
+
+    public static RegisteredKeyValueStateBackendMetaInfo createMetaInfoV1FromV2Snapshot(
+            StateMetaInfoSnapshot stateMeta) {
+
+        Preconditions.checkArgument(
+                stateMeta
+                        .getBackendStateType()
+                        .equals(StateMetaInfoSnapshot.BackendStateType.KEY_VALUE_V2));
+        org.apache.flink.api.common.state.StateDescriptor.Type newStateType;
+        TypeSerializerSnapshot oldValueSerializerSnapshot =
+                stateMeta.getTypeSerializerSnapshot(
+                        StateMetaInfoSnapshot.CommonSerializerKeys.VALUE_SERIALIZER);
+        TypeSerializerSnapshot oldUserKeySerializerSnapshot =
+                stateMeta.getTypeSerializerSnapshot(
+                        StateMetaInfoSnapshot.CommonSerializerKeys.USER_KEY_SERIALIZER);
+        ;
+        TypeSerializerSnapshot newUserKeySerializerSnapshot = oldValueSerializerSnapshot;

Review Comment:
   How about renaming `newUserKeySerializerSnapshot` to `newStateSerializerSnapshot`?



##########
flink-runtime/src/main/java/org/apache/flink/runtime/state/RegisteredStateMetaInfoUtils.java:
##########
@@ -0,0 +1,176 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.flink.runtime.state;
+
+import org.apache.flink.api.common.state.v2.StateDescriptor;
+import org.apache.flink.api.common.typeutils.TypeSerializerSnapshot;
+import org.apache.flink.api.common.typeutils.base.ListSerializer;
+import org.apache.flink.api.common.typeutils.base.MapSerializer;
+import org.apache.flink.runtime.state.metainfo.StateMetaInfoSnapshot;
+import org.apache.flink.util.Preconditions;
+
+/**
+ * Utilities for transforming {@link RegisteredKeyValueStateBackendMetaInfo} to {@link
+ * org.apache.flink.runtime.state.v2.RegisteredKeyValueStateBackendMetaInfo}.
+ */
+public class RegisteredStateMetaInfoUtils {
+
+    private RegisteredStateMetaInfoUtils() {}
+
+    public static org.apache.flink.runtime.state.v2.RegisteredKeyValueStateBackendMetaInfo
+            createMetaInfoV2FromV1Snapshot(StateMetaInfoSnapshot stateMeta) {
+
+        Preconditions.checkArgument(
+                stateMeta
+                        .getBackendStateType()
+                        .equals(StateMetaInfoSnapshot.BackendStateType.KEY_VALUE));
+
+        StateDescriptor.Type newStateType;
+        TypeSerializerSnapshot oldValueSerializerSnapshot =
+                stateMeta.getTypeSerializerSnapshot(
+                        StateMetaInfoSnapshot.CommonSerializerKeys.VALUE_SERIALIZER);
+        TypeSerializerSnapshot newUserKeySerializerSnapshot = oldValueSerializerSnapshot;
+        TypeSerializerSnapshot newStateSerializerSnapshot = null;

Review Comment:
   ```
   newUserKeySerializerSnapshot = null;
   newStateSerializerSnapshot = oldValueSerializerSnapshot?
   ```
   
   Otherwise, the `NPE` will be thrown, we can add tests about other states in `ForStAsyncAndSyncCompatibilityTest` to verify.
   



-- 
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-37552] Support switching between ForStKeyedStatebackend and ForStSyncKeyedStatebackend [flink]

Posted by "mayuehappy (via GitHub)" <gi...@apache.org>.
mayuehappy commented on PR #26466:
URL: https://github.com/apache/flink/pull/26466#issuecomment-2865823429

   @fredia thanks for the reivew , i've updated the PR. PTAL


-- 
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-37552] Support switching between ForStKeyedStatebackend and ForStSyncKeyedStatebackend [flink]

Posted by "fredia (via GitHub)" <gi...@apache.org>.
fredia merged PR #26466:
URL: https://github.com/apache/flink/pull/26466


-- 
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