You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@flink.apache.org by "ruibinx (via GitHub)" <gi...@apache.org> on 2023/12/16 06:26:26 UTC

[PR] [FLINK-33863] Fix restoring compressed operator state [flink]

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

   ## What is the purpose of the change
   
   This PR fixes an issue related to restoring multiple operator states when snapshot compression is enabled. see: https://issues.apache.org/jira/browse/FLINK-30113
   
   
   ## Brief change log
   
   - sort the operator states by offsets before restoring.
   
   
   ## Verifying this change
   still working on tests
   
   ## 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: yes
     - The S3 file system connector: no
   ## Documentation
   
     - Does this pull request introduce a new feature?  no
   
   


-- 
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-33863][checkpoint] Fix restoring compressed operator state [flink]

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

   @ruibinx Thanks for the clarification and update, LGTM, let's wait for CI green.


-- 
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-33863][checkpoint] Fix restoring compressed operator state [flink]

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

   @flinkbot run azure


-- 
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-33863][checkpoint] Fix restoring compressed operator state [flink]

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


##########
flink-runtime/src/main/java/org/apache/flink/runtime/state/OperatorStateRestoreOperation.java:
##########
@@ -168,9 +170,25 @@ public Void restore() throws Exception {
                     }
                 }
 
+                // sort state by offsets
+                List<Map.Entry<String, OperatorStateHandle.StateMetaInfo>> entries =
+                        stateHandle.getStateNameToPartitionOffsets().entrySet().stream()
+                                .sorted(
+                                        Comparator.comparingLong(
+                                                entry -> {
+                                                    OperatorStateHandle.StateMetaInfo
+                                                            stateMetaInfo = entry.getValue();
+                                                    long[] offsets = stateMetaInfo.getOffsets();
+                                                    if (offsets == null || offsets.length == 0) {
+                                                        return Long.MIN_VALUE;
+                                                    } else {
+                                                        return offsets[0];
+                                                    }

Review Comment:
   Thanks for the clarification.
   According to the [constructor](https://github.com/apache/flink/blob/master/flink-runtime/src/main/java/org/apache/flink/runtime/state/OperatorStateHandle.java#L63C17-L63C17)  of `StateMetaInfo` and the [serde](https://github.com/apache/flink/blob/master/flink-runtime/src/main/java/org/apache/flink/runtime/checkpoint/metadata/MetadataV2V3SerializerBase.java#L626) of `OperatorStateHandle`, I think the `offsets` can not be null.  And let it stay as it is. :) 



-- 
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-33863][checkpoint] Fix restoring compressed operator state [flink]

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


##########
flink-runtime/src/main/java/org/apache/flink/runtime/state/OperatorStateRestoreOperation.java:
##########
@@ -168,9 +170,25 @@ public Void restore() throws Exception {
                     }
                 }
 
+                // sort state by offsets
+                List<Map.Entry<String, OperatorStateHandle.StateMetaInfo>> entries =
+                        stateHandle.getStateNameToPartitionOffsets().entrySet().stream()
+                                .sorted(
+                                        Comparator.comparingLong(
+                                                entry -> {
+                                                    OperatorStateHandle.StateMetaInfo
+                                                            stateMetaInfo = entry.getValue();
+                                                    long[] offsets = stateMetaInfo.getOffsets();
+                                                    if (offsets == null || offsets.length == 0) {
+                                                        return Long.MIN_VALUE;
+                                                    } else {
+                                                        return offsets[0];
+                                                    }

Review Comment:
   Yeah I think so. The case we encountered should be a zero-length array.



-- 
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-33863][checkpoint] Fix restoring compressed operator state [flink]

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


##########
flink-runtime/src/test/java/org/apache/flink/runtime/state/OperatorStateRestoreOperationTest.java:
##########
@@ -0,0 +1,112 @@
+/*
+ * 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.ExecutionConfig;
+import org.apache.flink.api.common.state.BroadcastState;
+import org.apache.flink.api.common.state.ListStateDescriptor;
+import org.apache.flink.api.common.state.MapStateDescriptor;
+import org.apache.flink.core.fs.CloseableRegistry;
+import org.apache.flink.runtime.checkpoint.CheckpointOptions;
+import org.apache.flink.runtime.state.memory.MemCheckpointStreamFactory;
+
+import org.jetbrains.annotations.Nullable;
+import org.junit.Test;
+
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+

Review Comment:
   Added.



-- 
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-33863][checkpoint] Fix restoring compressed operator state [flink]

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


##########
flink-runtime/src/test/java/org/apache/flink/runtime/state/OperatorStateRestoreOperationTest.java:
##########
@@ -0,0 +1,112 @@
+/*
+ * 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.ExecutionConfig;
+import org.apache.flink.api.common.state.BroadcastState;
+import org.apache.flink.api.common.state.ListStateDescriptor;
+import org.apache.flink.api.common.state.MapStateDescriptor;
+import org.apache.flink.core.fs.CloseableRegistry;
+import org.apache.flink.runtime.checkpoint.CheckpointOptions;
+import org.apache.flink.runtime.state.memory.MemCheckpointStreamFactory;
+
+import org.jetbrains.annotations.Nullable;

Review Comment:
   ```suggestion
   import javax.annotation.Nullable;
   ```



##########
flink-runtime/src/test/java/org/apache/flink/runtime/state/OperatorStateRestoreOperationTest.java:
##########
@@ -0,0 +1,112 @@
+/*
+ * 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.ExecutionConfig;
+import org.apache.flink.api.common.state.BroadcastState;
+import org.apache.flink.api.common.state.ListStateDescriptor;
+import org.apache.flink.api.common.state.MapStateDescriptor;
+import org.apache.flink.core.fs.CloseableRegistry;
+import org.apache.flink.runtime.checkpoint.CheckpointOptions;
+import org.apache.flink.runtime.state.memory.MemCheckpointStreamFactory;
+
+import org.jetbrains.annotations.Nullable;
+import org.junit.Test;
+
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+

Review Comment:
   Need some comments here, otherwise `checkstyle` would be fail.



##########
flink-runtime/src/main/java/org/apache/flink/runtime/state/OperatorStateRestoreOperation.java:
##########
@@ -168,9 +170,25 @@ public Void restore() throws Exception {
                     }
                 }
 
+                // sort state by offsets
+                List<Map.Entry<String, OperatorStateHandle.StateMetaInfo>> entries =
+                        stateHandle.getStateNameToPartitionOffsets().entrySet().stream()
+                                .sorted(
+                                        Comparator.comparingLong(
+                                                entry -> {
+                                                    OperatorStateHandle.StateMetaInfo
+                                                            stateMetaInfo = entry.getValue();
+                                                    long[] offsets = stateMetaInfo.getOffsets();
+                                                    if (offsets == null || offsets.length == 0) {
+                                                        return Long.MIN_VALUE;
+                                                    } else {
+                                                        return offsets[0];
+                                                    }

Review Comment:
   ```suggestion
      Preconditions.checkNotNull(offsets);
      Preconditions.checkState(offsets.length > 0);
      return offsets[0];                                                                        
   ```
   
   I think we should throw exceptions as early as possible.



##########
flink-runtime/src/main/java/org/apache/flink/runtime/state/OperatorStateRestoreOperation.java:
##########
@@ -168,9 +170,25 @@ public Void restore() throws Exception {
                     }
                 }
 
+                // sort state by offsets

Review Comment:
   How about describing the root cause here?
   something like: 
   >  sort state handles by offsets to avoid building `SnappyFramedInputStream` with EOF stream.
   
   And IIUC,  we only need to sort the state handles when compression is enabled?  



##########
flink-runtime/src/test/java/org/apache/flink/runtime/state/OperatorStateRestoreOperationTest.java:
##########
@@ -0,0 +1,112 @@
+/*
+ * 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.ExecutionConfig;
+import org.apache.flink.api.common.state.BroadcastState;
+import org.apache.flink.api.common.state.ListStateDescriptor;
+import org.apache.flink.api.common.state.MapStateDescriptor;
+import org.apache.flink.core.fs.CloseableRegistry;
+import org.apache.flink.runtime.checkpoint.CheckpointOptions;
+import org.apache.flink.runtime.state.memory.MemCheckpointStreamFactory;
+
+import org.jetbrains.annotations.Nullable;
+import org.junit.Test;

Review Comment:
   ```suggestion
   import org.junit.jupiter.api.Test;
   ```
   The newly added tests should preferably use JUnit 5.
   
   https://flink.apache.org/how-to-contribute/code-style-and-quality-common/#:~:text=Testing-,%23,-Tooling



-- 
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-33863] Fix restoring compressed operator state [flink]

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

   <!--
   Meta data
   {
     "version" : 1,
     "metaDataEntries" : [ {
       "hash" : "052dab59db8f519765c51228f87277bd85b83a45",
       "status" : "UNKNOWN",
       "url" : "TBD",
       "triggerID" : "052dab59db8f519765c51228f87277bd85b83a45",
       "triggerType" : "PUSH"
     } ]
   }-->
   ## CI report:
   
   * 052dab59db8f519765c51228f87277bd85b83a45 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-33863][checkpoint] Fix restoring compressed operator state [flink]

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


-- 
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-33863][checkpoint] Fix restoring compressed operator state [flink]

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


##########
flink-runtime/src/test/java/org/apache/flink/runtime/state/OperatorStateRestoreOperationTest.java:
##########
@@ -0,0 +1,112 @@
+/*
+ * 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.ExecutionConfig;
+import org.apache.flink.api.common.state.BroadcastState;
+import org.apache.flink.api.common.state.ListStateDescriptor;
+import org.apache.flink.api.common.state.MapStateDescriptor;
+import org.apache.flink.core.fs.CloseableRegistry;
+import org.apache.flink.runtime.checkpoint.CheckpointOptions;
+import org.apache.flink.runtime.state.memory.MemCheckpointStreamFactory;
+
+import org.jetbrains.annotations.Nullable;

Review Comment:
   Fixed.



##########
flink-runtime/src/test/java/org/apache/flink/runtime/state/OperatorStateRestoreOperationTest.java:
##########
@@ -0,0 +1,112 @@
+/*
+ * 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.ExecutionConfig;
+import org.apache.flink.api.common.state.BroadcastState;
+import org.apache.flink.api.common.state.ListStateDescriptor;
+import org.apache.flink.api.common.state.MapStateDescriptor;
+import org.apache.flink.core.fs.CloseableRegistry;
+import org.apache.flink.runtime.checkpoint.CheckpointOptions;
+import org.apache.flink.runtime.state.memory.MemCheckpointStreamFactory;
+
+import org.jetbrains.annotations.Nullable;
+import org.junit.Test;

Review Comment:
   Fixed, thanks!



-- 
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-33863][checkpoint] Fix restoring compressed operator state [flink]

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


##########
flink-runtime/src/main/java/org/apache/flink/runtime/state/OperatorStateRestoreOperation.java:
##########
@@ -168,9 +170,25 @@ public Void restore() throws Exception {
                     }
                 }
 
+                // sort state by offsets

Review Comment:
   Done.



-- 
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-33863][checkpoint] Fix restoring compressed operator state [flink]

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


##########
flink-runtime/src/main/java/org/apache/flink/runtime/state/OperatorStateRestoreOperation.java:
##########
@@ -168,9 +170,25 @@ public Void restore() throws Exception {
                     }
                 }
 
+                // sort state by offsets
+                List<Map.Entry<String, OperatorStateHandle.StateMetaInfo>> entries =
+                        stateHandle.getStateNameToPartitionOffsets().entrySet().stream()
+                                .sorted(
+                                        Comparator.comparingLong(
+                                                entry -> {
+                                                    OperatorStateHandle.StateMetaInfo
+                                                            stateMetaInfo = entry.getValue();
+                                                    long[] offsets = stateMetaInfo.getOffsets();
+                                                    if (offsets == null || offsets.length == 0) {
+                                                        return Long.MIN_VALUE;
+                                                    } else {
+                                                        return offsets[0];
+                                                    }

Review Comment:
   It's confusing for me too, but we do encountered a few states with empty offset. The operator states deserialization code also ignores states with empty offset(https://github.com/apache/flink/blob/7cae20f22a24403210ca5d6addf83571fcf46843/flink-runtime/src/main/java/org/apache/flink/runtime/state/OperatorStateRestoreOperation.java#L225). I think throwing exception here might break backward compatibility.



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