curcur commented on a change in pull request #16836:
URL: https://github.com/apache/flink/pull/16836#discussion_r689500262
##########
File path:
flink-runtime/src/main/java/org/apache/flink/runtime/checkpoint/StateAssignmentOperation.java
##########
@@ -108,6 +108,7 @@ public void assignStates() {
OperatorID operatorID =
operatorIDPair
.getUserDefinedOperatorID()
+ .filter(operatorStates::containsKey)
Review comment:
this seems not having any effect since `operatorStates` starts with
empty.
But why the tests fails after removing this?
##########
File path:
flink-tests/src/test/java/org/apache/flink/test/checkpointing/CheckpointRestoreWithUidHashITCase.java
##########
@@ -0,0 +1,147 @@
+/*
+ * 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.test.checkpointing;
+
+import org.apache.flink.api.common.restartstrategy.RestartStrategies;
+import org.apache.flink.api.common.state.CheckpointListener;
+import org.apache.flink.api.common.state.ListState;
+import org.apache.flink.api.common.state.ListStateDescriptor;
+import org.apache.flink.runtime.jobgraph.OperatorID;
+import org.apache.flink.runtime.state.FunctionInitializationContext;
+import org.apache.flink.runtime.state.FunctionSnapshotContext;
+import org.apache.flink.streaming.api.CheckpointingMode;
+import org.apache.flink.streaming.api.checkpoint.CheckpointedFunction;
+import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;
+import org.apache.flink.streaming.api.functions.source.RichSourceFunction;
+
+import org.junit.Test;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Iterator;
+import java.util.List;
+import java.util.stream.IntStream;
+
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.Matchers.contains;
+
+/**
+ * This case verifies that if {@code uidHash} is set, the job would still be
able to restored from
+ * the checkpoints correctly without losing states due to mismatched operator
id.
+ */
+public class CheckpointRestoreWithUidHashITCase {
+
+ @Test
+ public void testCheckpointRestoreWithUidHash() throws Exception {
+ final int maxNumber = 1000;
+
+ StreamExecutionEnvironment env =
StreamExecutionEnvironment.getExecutionEnvironment();
+ env.setRestartStrategy(RestartStrategies.fixedDelayRestart(2, 500));
+ env.enableCheckpointing(500, CheckpointingMode.EXACTLY_ONCE);
+
+ String uidHash = new OperatorID().toHexString();
+ Iterator<Integer> sinkIterator =
+ env.addSource(new StatefulSource(maxNumber))
+ .setUidHash(uidHash)
+ .executeAndCollect();
+ List<Integer> result = new ArrayList<>();
+ sinkIterator.forEachRemaining(result::add);
+ assertThat(result, contains(IntStream.range(0,
maxNumber).boxed().toArray()));
+ }
+
+ private static class StatefulSource extends RichSourceFunction<Integer>
+ implements CheckpointedFunction, CheckpointListener {
+
+ private final int maxNumber;
+
+ private ListState<Integer> nextNumberState;
+
+ private int nextNumber;
+
+ private volatile boolean isCanceled;
+
+ private volatile boolean isWaiting;
+
+ private volatile long firstCheckpointIdAfterWaiting;
+
+ private volatile boolean checkpointCompletedAfterWaiting;
+
+ public StatefulSource(int maxNumber) {
+ this.maxNumber = maxNumber;
+ }
+
+ @Override
+ public void initializeState(FunctionInitializationContext context)
throws Exception {
+ nextNumberState =
+ context.getOperatorStateStore()
+ .getListState(new ListStateDescriptor<>("next",
Integer.class));
+ if (nextNumberState.get().iterator().hasNext()) {
+ nextNumber = nextNumberState.get().iterator().next();
+ }
+ }
+
+ @Override
+ public void run(SourceContext<Integer> ctx) throws Exception {
+ emitRecordsTill(maxNumber / 3, ctx);
+
+ if (getRuntimeContext().getAttemptNumber() == 0) {
+ // Wait till one checkpoint is snapshot and completed
Review comment:
snapshotted
--
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: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]