You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@flink.apache.org by "zhipeng93 (via GitHub)" <gi...@apache.org> on 2023/02/22 13:12:13 UTC
[GitHub] [flink-ml] zhipeng93 opened a new pull request, #216: [Flink-31173] Fix serveral iteration bugs
zhipeng93 opened a new pull request, #216:
URL: https://github.com/apache/flink-ml/pull/216
## What is the purpose of the change
This PR fixes several iteration bugs.
## Brief change log
*(for example:)*
- Restrict that TailOperator should only have one input since it does not align the epoch watermarks.
- Let ReplayOperator replay records when it receives max epoch watermark
- Fix wrong typeinfo in ProxyOperatorStateBackend.
## 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)
## 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
[GitHub] [flink-ml] zhipeng93 commented on a diff in pull request #216: [FLINK-31173] Fix serveral iteration bugs
Posted by "zhipeng93 (via GitHub)" <gi...@apache.org>.
zhipeng93 commented on code in PR #216:
URL: https://github.com/apache/flink-ml/pull/216#discussion_r1172168270
##########
flink-ml-tests/src/test/java/org/apache/flink/test/iteration/BoundedIterationWithBroadcastITCase.java:
##########
@@ -0,0 +1,152 @@
+/*
+ * 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.iteration;
+
+import org.apache.flink.api.common.functions.MapFunction;
+import org.apache.flink.api.common.typeinfo.Types;
+import org.apache.flink.iteration.DataStreamList;
+import org.apache.flink.iteration.IterationBody;
+import org.apache.flink.iteration.IterationBodyResult;
+import org.apache.flink.iteration.IterationConfig;
+import org.apache.flink.iteration.IterationConfig.OperatorLifeCycle;
+import org.apache.flink.iteration.Iterations;
+import org.apache.flink.iteration.ReplayableDataStreamList;
+import org.apache.flink.ml.common.broadcast.BroadcastUtils;
+import org.apache.flink.ml.common.iteration.TerminateOnMaxIter;
+import org.apache.flink.runtime.jobgraph.JobGraph;
+import org.apache.flink.runtime.minicluster.MiniCluster;
+import org.apache.flink.streaming.api.datastream.DataStream;
+import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;
+import org.apache.flink.streaming.api.functions.sink.SinkFunction;
+import org.apache.flink.testutils.junit.SharedObjects;
+import org.apache.flink.testutils.junit.SharedReference;
+import org.apache.flink.util.TestLogger;
+
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.List;
+import java.util.concurrent.BlockingQueue;
+import java.util.concurrent.LinkedBlockingQueue;
+
+import static org.apache.flink.test.iteration.UnboundedStreamIterationITCase.createMiniClusterConfiguration;
+import static org.junit.Assert.assertEquals;
+
+/** Tests using {@link BroadcastUtils#withBroadcastStream} in iterations. */
+public class BoundedIterationWithBroadcastITCase extends TestLogger {
+
+ @Rule public final SharedObjects sharedObjects = SharedObjects.create();
+
+ private MiniCluster miniCluster;
+
+ private SharedReference<BlockingQueue<Long>> result;
+
+ @Before
+ public void setup() throws Exception {
+ miniCluster = new MiniCluster(createMiniClusterConfiguration(1, 1));
+ miniCluster.start();
+
+ result = sharedObjects.add(new LinkedBlockingQueue<>());
+ }
+
+ @After
+ public void teardown() throws Exception {
+ if (miniCluster != null) {
+ miniCluster.close();
+ }
+ }
+
+ @Test
+ public void testIterationWithBroadcastJobGraph() throws Exception {
Review Comment:
Before calling `DefaultOperatorStateBackend#getListState`, we need to call `stateDescriptor.getElementSerializer()`. If it is null, it throws NPE here.
--
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
[GitHub] [flink-ml] zhipeng93 commented on a diff in pull request #216: [Flink-31173] Fix serveral iteration bugs
Posted by "zhipeng93 (via GitHub)" <gi...@apache.org>.
zhipeng93 commented on code in PR #216:
URL: https://github.com/apache/flink-ml/pull/216#discussion_r1169988979
##########
flink-ml-iteration/src/main/java/org/apache/flink/iteration/proxy/state/ProxyOperatorStateBackend.java:
##########
@@ -58,12 +62,24 @@ public <K, V> BroadcastState<K, V> getBroadcastState(MapStateDescriptor<K, V> st
return wrappedBackend.getBroadcastState(newDescriptor);
}
+ private <S> TypeInformation<S> getTypeInfo(ListStateDescriptor<S> stateDescriptor)
+ throws Exception {
+ Field f = StateDescriptor.class.getDeclaredField("typeInfo");
+ f.setAccessible(true);
+ return ((ListTypeInfo) f.get(stateDescriptor)).getElementTypeInfo();
+ }
+
@Override
public <S> ListState<S> getListState(ListStateDescriptor<S> stateDescriptor) throws Exception {
ListStateDescriptor<S> newDescriptor =
- new ListStateDescriptor<>(
- stateNamePrefix.prefix(stateDescriptor.getName()),
- stateDescriptor.getElementSerializer());
+ stateDescriptor.isSerializerInitialized()
Review Comment:
Good catch. I have updated the check for `UnionListState` and `BroadcastState`.
--
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
[GitHub] [flink-ml] lindong28 commented on a diff in pull request #216: [FLINK-31173] Fix serveral iteration bugs
Posted by "lindong28 (via GitHub)" <gi...@apache.org>.
lindong28 commented on code in PR #216:
URL: https://github.com/apache/flink-ml/pull/216#discussion_r1171065833
##########
flink-ml-tests/src/test/java/org/apache/flink/test/iteration/BoundedIterationWithBroadcastITCase.java:
##########
@@ -0,0 +1,152 @@
+/*
+ * 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.iteration;
+
+import org.apache.flink.api.common.functions.MapFunction;
+import org.apache.flink.api.common.typeinfo.Types;
+import org.apache.flink.iteration.DataStreamList;
+import org.apache.flink.iteration.IterationBody;
+import org.apache.flink.iteration.IterationBodyResult;
+import org.apache.flink.iteration.IterationConfig;
+import org.apache.flink.iteration.IterationConfig.OperatorLifeCycle;
+import org.apache.flink.iteration.Iterations;
+import org.apache.flink.iteration.ReplayableDataStreamList;
+import org.apache.flink.ml.common.broadcast.BroadcastUtils;
+import org.apache.flink.ml.common.iteration.TerminateOnMaxIter;
+import org.apache.flink.runtime.jobgraph.JobGraph;
+import org.apache.flink.runtime.minicluster.MiniCluster;
+import org.apache.flink.streaming.api.datastream.DataStream;
+import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;
+import org.apache.flink.streaming.api.functions.sink.SinkFunction;
+import org.apache.flink.testutils.junit.SharedObjects;
+import org.apache.flink.testutils.junit.SharedReference;
+import org.apache.flink.util.TestLogger;
+
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.List;
+import java.util.concurrent.BlockingQueue;
+import java.util.concurrent.LinkedBlockingQueue;
+
+import static org.apache.flink.test.iteration.UnboundedStreamIterationITCase.createMiniClusterConfiguration;
+import static org.junit.Assert.assertEquals;
+
+/** Tests using {@link BroadcastUtils#withBroadcastStream} in iterations. */
+public class BoundedIterationWithBroadcastITCase extends TestLogger {
+
+ @Rule public final SharedObjects sharedObjects = SharedObjects.create();
+
+ private MiniCluster miniCluster;
+
+ private SharedReference<BlockingQueue<Long>> result;
+
+ @Before
+ public void setup() throws Exception {
+ miniCluster = new MiniCluster(createMiniClusterConfiguration(1, 1));
+ miniCluster.start();
+
+ result = sharedObjects.add(new LinkedBlockingQueue<>());
+ }
+
+ @After
+ public void teardown() throws Exception {
+ if (miniCluster != null) {
+ miniCluster.close();
+ }
+ }
+
+ @Test
+ public void testIterationWithBroadcastJobGraph() throws Exception {
Review Comment:
Suppose that `ProxyOperatorStateBackend#wrappedBackend` is a `DefaultOperatorStateBackend`. Then `ProxyOperatorStateBackend#getUnionListState` invokes `DefaultOperatorStateBackend#getUnionListState`, which should in turn invoke `DefaultOperatorStateBackend#getListState` and initialize the state descriptor, right?
--
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
[GitHub] [flink-ml] zhipeng93 commented on a diff in pull request #216: [Flink-31173] Fix serveral iteration bugs
Posted by "zhipeng93 (via GitHub)" <gi...@apache.org>.
zhipeng93 commented on code in PR #216:
URL: https://github.com/apache/flink-ml/pull/216#discussion_r1169987013
##########
flink-ml-tests/src/test/java/org/apache/flink/test/iteration/BoundedTailOperatorWithUnionInputIterationITCase.java:
##########
@@ -0,0 +1,75 @@
+/*
+ * 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.iteration;
+
+import org.apache.flink.iteration.DataStreamList;
+import org.apache.flink.iteration.IterationBody;
+import org.apache.flink.iteration.IterationBodyResult;
+import org.apache.flink.iteration.IterationConfig;
+import org.apache.flink.iteration.IterationConfig.OperatorLifeCycle;
+import org.apache.flink.iteration.Iterations;
+import org.apache.flink.iteration.ReplayableDataStreamList;
+import org.apache.flink.ml.common.iteration.TerminateOnMaxIter;
+import org.apache.flink.streaming.api.datastream.DataStream;
+import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;
+
+import org.junit.Test;
+
+import static org.junit.Assert.assertEquals;
+
+/** Tests the case that Tail operator contains multiple inputs. */
+public class BoundedTailOperatorWithUnionInputIterationITCase {
+
+ @Test
+ public void testTailOperatorWithUnionInput() {
+ StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment();
+ DataStream<Long> input1 = env.fromSequence(0, 10);
+ DataStream<Long> input2 = env.fromSequence(0, 10);
+ String expectedErrorMessage =
+ "Tail operator should have only one input. Please check whether operator "
+ + "\"Union\" contains multiple inputs.";
+
+ try {
+ Iterations.iterateBoundedStreamsUntilTermination(
+ DataStreamList.of(input1),
+ ReplayableDataStreamList.replay(input2),
+ new IterationConfig(OperatorLifeCycle.PER_ROUND),
+ new IterationBodyWithUnionAsFeedback());
+ } catch (UnsupportedOperationException e) {
+ assertEquals(expectedErrorMessage, e.getMessage());
+ }
+ }
+
+ private static class IterationBodyWithUnionAsFeedback implements IterationBody {
+
+ @Override
+ public IterationBodyResult process(
+ DataStreamList variableStreams, DataStreamList dataStreams) {
+
+ DataStream<Long> variableStream = variableStreams.get(0);
+ DataStream<Long> constantStream = dataStreams.get(0);
+ DataStream<Integer> terminationCriteria =
+ constantStream.flatMap(new TerminateOnMaxIter<>(3));
+ return new IterationBodyResult(
+ DataStreamList.of(variableStream.union(constantStream)),
Review Comment:
Currently `TailOperator` does not align the epoch watermarks from its inputs, thus will cause the iteration incorrect.
To support using `opA union opB` as the feedback, users can now use `(opA union opB).map(x -> x)` for a workaround.
--
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
[GitHub] [flink-ml] zhipeng93 commented on a diff in pull request #216: [Flink-31173] Fix serveral iteration bugs
Posted by "zhipeng93 (via GitHub)" <gi...@apache.org>.
zhipeng93 commented on code in PR #216:
URL: https://github.com/apache/flink-ml/pull/216#discussion_r1169983940
##########
flink-ml-tests/src/test/java/org/apache/flink/test/iteration/BoundedPerRoundCheckpointITCase.java:
##########
@@ -106,7 +106,7 @@ public void testFailoverAndRestore() throws Exception {
}
// 0 ~ 4 round and termination information
- assertEquals(4, roundsStat.size());
+ assertEquals(5, roundsStat.size());
Review Comment:
Thanks for pointing this out. This fix is not consistent with the java doc yet. I will do this fix in a later PR.
--
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
[GitHub] [flink-ml] zhipeng93 commented on a diff in pull request #216: [Flink-31173] Fix serveral iteration bugs
Posted by "zhipeng93 (via GitHub)" <gi...@apache.org>.
zhipeng93 commented on code in PR #216:
URL: https://github.com/apache/flink-ml/pull/216#discussion_r1169987013
##########
flink-ml-tests/src/test/java/org/apache/flink/test/iteration/BoundedTailOperatorWithUnionInputIterationITCase.java:
##########
@@ -0,0 +1,75 @@
+/*
+ * 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.iteration;
+
+import org.apache.flink.iteration.DataStreamList;
+import org.apache.flink.iteration.IterationBody;
+import org.apache.flink.iteration.IterationBodyResult;
+import org.apache.flink.iteration.IterationConfig;
+import org.apache.flink.iteration.IterationConfig.OperatorLifeCycle;
+import org.apache.flink.iteration.Iterations;
+import org.apache.flink.iteration.ReplayableDataStreamList;
+import org.apache.flink.ml.common.iteration.TerminateOnMaxIter;
+import org.apache.flink.streaming.api.datastream.DataStream;
+import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;
+
+import org.junit.Test;
+
+import static org.junit.Assert.assertEquals;
+
+/** Tests the case that Tail operator contains multiple inputs. */
+public class BoundedTailOperatorWithUnionInputIterationITCase {
+
+ @Test
+ public void testTailOperatorWithUnionInput() {
+ StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment();
+ DataStream<Long> input1 = env.fromSequence(0, 10);
+ DataStream<Long> input2 = env.fromSequence(0, 10);
+ String expectedErrorMessage =
+ "Tail operator should have only one input. Please check whether operator "
+ + "\"Union\" contains multiple inputs.";
+
+ try {
+ Iterations.iterateBoundedStreamsUntilTermination(
+ DataStreamList.of(input1),
+ ReplayableDataStreamList.replay(input2),
+ new IterationConfig(OperatorLifeCycle.PER_ROUND),
+ new IterationBodyWithUnionAsFeedback());
+ } catch (UnsupportedOperationException e) {
+ assertEquals(expectedErrorMessage, e.getMessage());
+ }
+ }
+
+ private static class IterationBodyWithUnionAsFeedback implements IterationBody {
+
+ @Override
+ public IterationBodyResult process(
+ DataStreamList variableStreams, DataStreamList dataStreams) {
+
+ DataStream<Long> variableStream = variableStreams.get(0);
+ DataStream<Long> constantStream = dataStreams.get(0);
+ DataStream<Integer> terminationCriteria =
+ constantStream.flatMap(new TerminateOnMaxIter<>(3));
+ return new IterationBodyResult(
+ DataStreamList.of(variableStream.union(constantStream)),
Review Comment:
Currently `TailOperator` does not align the epoch watermarks from its inputs, thus will cause the result of iteration wrong.
To support using `opA union opB` as the feedback, users can now use `(opA union opB).map(x -> x)` for a workaround.
--
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
[GitHub] [flink-ml] lindong28 commented on pull request #216: [FLINK-31173] Fix serveral iteration bugs
Posted by "lindong28 (via GitHub)" <gi...@apache.org>.
lindong28 commented on PR #216:
URL: https://github.com/apache/flink-ml/pull/216#issuecomment-1515941832
Thanks for the update. LGTM.
--
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
[GitHub] [flink-ml] zhipeng93 commented on a diff in pull request #216: [Flink-31173] Fix serveral iteration bugs
Posted by "zhipeng93 (via GitHub)" <gi...@apache.org>.
zhipeng93 commented on code in PR #216:
URL: https://github.com/apache/flink-ml/pull/216#discussion_r1169999415
##########
flink-ml-tests/src/test/java/org/apache/flink/test/iteration/BoundedIterationWithBroadcastITCase.java:
##########
@@ -0,0 +1,152 @@
+/*
+ * 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.iteration;
+
+import org.apache.flink.api.common.functions.MapFunction;
+import org.apache.flink.api.common.typeinfo.Types;
+import org.apache.flink.iteration.DataStreamList;
+import org.apache.flink.iteration.IterationBody;
+import org.apache.flink.iteration.IterationBodyResult;
+import org.apache.flink.iteration.IterationConfig;
+import org.apache.flink.iteration.IterationConfig.OperatorLifeCycle;
+import org.apache.flink.iteration.Iterations;
+import org.apache.flink.iteration.ReplayableDataStreamList;
+import org.apache.flink.ml.common.broadcast.BroadcastUtils;
+import org.apache.flink.ml.common.iteration.TerminateOnMaxIter;
+import org.apache.flink.runtime.jobgraph.JobGraph;
+import org.apache.flink.runtime.minicluster.MiniCluster;
+import org.apache.flink.streaming.api.datastream.DataStream;
+import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;
+import org.apache.flink.streaming.api.functions.sink.SinkFunction;
+import org.apache.flink.testutils.junit.SharedObjects;
+import org.apache.flink.testutils.junit.SharedReference;
+import org.apache.flink.util.TestLogger;
+
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.List;
+import java.util.concurrent.BlockingQueue;
+import java.util.concurrent.LinkedBlockingQueue;
+
+import static org.apache.flink.test.iteration.UnboundedStreamIterationITCase.createMiniClusterConfiguration;
+import static org.junit.Assert.assertEquals;
+
+/** Tests using {@link BroadcastUtils#withBroadcastStream} in iterations. */
+public class BoundedIterationWithBroadcastITCase extends TestLogger {
+
+ @Rule public final SharedObjects sharedObjects = SharedObjects.create();
+
+ private MiniCluster miniCluster;
+
+ private SharedReference<BlockingQueue<Long>> result;
+
+ @Before
+ public void setup() throws Exception {
+ miniCluster = new MiniCluster(createMiniClusterConfiguration(1, 1));
+ miniCluster.start();
+
+ result = sharedObjects.add(new LinkedBlockingQueue<>());
+ }
+
+ @After
+ public void teardown() throws Exception {
+ if (miniCluster != null) {
+ miniCluster.close();
+ }
+ }
+
+ @Test
+ public void testIterationWithBroadcastJobGraph() throws Exception {
Review Comment:
The `getListState` in `DefaultOperatorStateBackend` does the initialization here [1] while `ProxyOperatorStateBackend` does not.
[1] [ProxyOperatorStateBackend](https://github.com/apache/flink/blob/master/flink-runtime/src/main/java/org/apache/flink/runtime/state/DefaultOperatorStateBackend.java#L257)
--
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
[GitHub] [flink-ml] zhipeng93 commented on pull request #216: [Flink-31173] Fix serveral iteration bugs
Posted by "zhipeng93 (via GitHub)" <gi...@apache.org>.
zhipeng93 commented on PR #216:
URL: https://github.com/apache/flink-ml/pull/216#issuecomment-1445562636
@gaoyunhaii Can you help to review this PR?
--
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
[GitHub] [flink-ml] zhipeng93 commented on a diff in pull request #216: [Flink-31173] Fix serveral iteration bugs
Posted by "zhipeng93 (via GitHub)" <gi...@apache.org>.
zhipeng93 commented on code in PR #216:
URL: https://github.com/apache/flink-ml/pull/216#discussion_r1169987013
##########
flink-ml-tests/src/test/java/org/apache/flink/test/iteration/BoundedTailOperatorWithUnionInputIterationITCase.java:
##########
@@ -0,0 +1,75 @@
+/*
+ * 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.iteration;
+
+import org.apache.flink.iteration.DataStreamList;
+import org.apache.flink.iteration.IterationBody;
+import org.apache.flink.iteration.IterationBodyResult;
+import org.apache.flink.iteration.IterationConfig;
+import org.apache.flink.iteration.IterationConfig.OperatorLifeCycle;
+import org.apache.flink.iteration.Iterations;
+import org.apache.flink.iteration.ReplayableDataStreamList;
+import org.apache.flink.ml.common.iteration.TerminateOnMaxIter;
+import org.apache.flink.streaming.api.datastream.DataStream;
+import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;
+
+import org.junit.Test;
+
+import static org.junit.Assert.assertEquals;
+
+/** Tests the case that Tail operator contains multiple inputs. */
+public class BoundedTailOperatorWithUnionInputIterationITCase {
+
+ @Test
+ public void testTailOperatorWithUnionInput() {
+ StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment();
+ DataStream<Long> input1 = env.fromSequence(0, 10);
+ DataStream<Long> input2 = env.fromSequence(0, 10);
+ String expectedErrorMessage =
+ "Tail operator should have only one input. Please check whether operator "
+ + "\"Union\" contains multiple inputs.";
+
+ try {
+ Iterations.iterateBoundedStreamsUntilTermination(
+ DataStreamList.of(input1),
+ ReplayableDataStreamList.replay(input2),
+ new IterationConfig(OperatorLifeCycle.PER_ROUND),
+ new IterationBodyWithUnionAsFeedback());
+ } catch (UnsupportedOperationException e) {
+ assertEquals(expectedErrorMessage, e.getMessage());
+ }
+ }
+
+ private static class IterationBodyWithUnionAsFeedback implements IterationBody {
+
+ @Override
+ public IterationBodyResult process(
+ DataStreamList variableStreams, DataStreamList dataStreams) {
+
+ DataStream<Long> variableStream = variableStreams.get(0);
+ DataStream<Long> constantStream = dataStreams.get(0);
+ DataStream<Integer> terminationCriteria =
+ constantStream.flatMap(new TerminateOnMaxIter<>(3));
+ return new IterationBodyResult(
+ DataStreamList.of(variableStream.union(constantStream)),
Review Comment:
Currently `TailOperator` does not align the epoch watermarks from its inputs, thus will cause the result of iteration wrong.
To support using `opA union opB` as the feedback, users can now use `(opA union opB).map(x -> x)` as a temp workaround.
--
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
[GitHub] [flink-ml] lindong28 commented on a diff in pull request #216: [FLINK-31173] Fix serveral iteration bugs
Posted by "lindong28 (via GitHub)" <gi...@apache.org>.
lindong28 commented on code in PR #216:
URL: https://github.com/apache/flink-ml/pull/216#discussion_r1171070892
##########
flink-ml-tests/src/test/java/org/apache/flink/test/iteration/BoundedTailOperatorWithUnionInputIterationITCase.java:
##########
@@ -0,0 +1,75 @@
+/*
+ * 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.iteration;
+
+import org.apache.flink.iteration.DataStreamList;
+import org.apache.flink.iteration.IterationBody;
+import org.apache.flink.iteration.IterationBodyResult;
+import org.apache.flink.iteration.IterationConfig;
+import org.apache.flink.iteration.IterationConfig.OperatorLifeCycle;
+import org.apache.flink.iteration.Iterations;
+import org.apache.flink.iteration.ReplayableDataStreamList;
+import org.apache.flink.ml.common.iteration.TerminateOnMaxIter;
+import org.apache.flink.streaming.api.datastream.DataStream;
+import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;
+
+import org.junit.Test;
+
+import static org.junit.Assert.assertEquals;
+
+/** Tests the case that Tail operator contains multiple inputs. */
+public class BoundedTailOperatorWithUnionInputIterationITCase {
+
+ @Test
+ public void testTailOperatorWithUnionInput() {
+ StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment();
+ DataStream<Long> input1 = env.fromSequence(0, 10);
+ DataStream<Long> input2 = env.fromSequence(0, 10);
+ String expectedErrorMessage =
+ "Tail operator should have only one input. Please check whether operator "
+ + "\"Union\" contains multiple inputs.";
+
+ try {
+ Iterations.iterateBoundedStreamsUntilTermination(
+ DataStreamList.of(input1),
+ ReplayableDataStreamList.replay(input2),
+ new IterationConfig(OperatorLifeCycle.PER_ROUND),
+ new IterationBodyWithUnionAsFeedback());
+ } catch (UnsupportedOperationException e) {
+ assertEquals(expectedErrorMessage, e.getMessage());
+ }
+ }
+
+ private static class IterationBodyWithUnionAsFeedback implements IterationBody {
+
+ @Override
+ public IterationBodyResult process(
+ DataStreamList variableStreams, DataStreamList dataStreams) {
+
+ DataStream<Long> variableStream = variableStreams.get(0);
+ DataStream<Long> constantStream = dataStreams.get(0);
+ DataStream<Integer> terminationCriteria =
+ constantStream.flatMap(new TerminateOnMaxIter<>(3));
+ return new IterationBodyResult(
+ DataStreamList.of(variableStream.union(constantStream)),
Review Comment:
Given that we have this work around, is it possible for `Iterations#addTails` to add the `map(x -> x)` instead of throwing exception?
Can you help describe the current behavior/issue if we don't throw exception in `Iterations#addTails`?
--
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
[GitHub] [flink-ml] lindong28 commented on a diff in pull request #216: [FLINK-31173] Fix serveral iteration bugs
Posted by "lindong28 (via GitHub)" <gi...@apache.org>.
lindong28 commented on code in PR #216:
URL: https://github.com/apache/flink-ml/pull/216#discussion_r1171070892
##########
flink-ml-tests/src/test/java/org/apache/flink/test/iteration/BoundedTailOperatorWithUnionInputIterationITCase.java:
##########
@@ -0,0 +1,75 @@
+/*
+ * 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.iteration;
+
+import org.apache.flink.iteration.DataStreamList;
+import org.apache.flink.iteration.IterationBody;
+import org.apache.flink.iteration.IterationBodyResult;
+import org.apache.flink.iteration.IterationConfig;
+import org.apache.flink.iteration.IterationConfig.OperatorLifeCycle;
+import org.apache.flink.iteration.Iterations;
+import org.apache.flink.iteration.ReplayableDataStreamList;
+import org.apache.flink.ml.common.iteration.TerminateOnMaxIter;
+import org.apache.flink.streaming.api.datastream.DataStream;
+import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;
+
+import org.junit.Test;
+
+import static org.junit.Assert.assertEquals;
+
+/** Tests the case that Tail operator contains multiple inputs. */
+public class BoundedTailOperatorWithUnionInputIterationITCase {
+
+ @Test
+ public void testTailOperatorWithUnionInput() {
+ StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment();
+ DataStream<Long> input1 = env.fromSequence(0, 10);
+ DataStream<Long> input2 = env.fromSequence(0, 10);
+ String expectedErrorMessage =
+ "Tail operator should have only one input. Please check whether operator "
+ + "\"Union\" contains multiple inputs.";
+
+ try {
+ Iterations.iterateBoundedStreamsUntilTermination(
+ DataStreamList.of(input1),
+ ReplayableDataStreamList.replay(input2),
+ new IterationConfig(OperatorLifeCycle.PER_ROUND),
+ new IterationBodyWithUnionAsFeedback());
+ } catch (UnsupportedOperationException e) {
+ assertEquals(expectedErrorMessage, e.getMessage());
+ }
+ }
+
+ private static class IterationBodyWithUnionAsFeedback implements IterationBody {
+
+ @Override
+ public IterationBodyResult process(
+ DataStreamList variableStreams, DataStreamList dataStreams) {
+
+ DataStream<Long> variableStream = variableStreams.get(0);
+ DataStream<Long> constantStream = dataStreams.get(0);
+ DataStream<Integer> terminationCriteria =
+ constantStream.flatMap(new TerminateOnMaxIter<>(3));
+ return new IterationBodyResult(
+ DataStreamList.of(variableStream.union(constantStream)),
Review Comment:
Given that we have this work around, is it possible for `Iterations#addTails` to add the `map(x -> x)` instead of throwing exception?
--
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
[GitHub] [flink-ml] zhipeng93 commented on a diff in pull request #216: [Flink-31173] Fix serveral iteration bugs
Posted by "zhipeng93 (via GitHub)" <gi...@apache.org>.
zhipeng93 commented on code in PR #216:
URL: https://github.com/apache/flink-ml/pull/216#discussion_r1169988979
##########
flink-ml-iteration/src/main/java/org/apache/flink/iteration/proxy/state/ProxyOperatorStateBackend.java:
##########
@@ -58,12 +62,24 @@ public <K, V> BroadcastState<K, V> getBroadcastState(MapStateDescriptor<K, V> st
return wrappedBackend.getBroadcastState(newDescriptor);
}
+ private <S> TypeInformation<S> getTypeInfo(ListStateDescriptor<S> stateDescriptor)
+ throws Exception {
+ Field f = StateDescriptor.class.getDeclaredField("typeInfo");
+ f.setAccessible(true);
+ return ((ListTypeInfo) f.get(stateDescriptor)).getElementTypeInfo();
+ }
+
@Override
public <S> ListState<S> getListState(ListStateDescriptor<S> stateDescriptor) throws Exception {
ListStateDescriptor<S> newDescriptor =
- new ListStateDescriptor<>(
- stateNamePrefix.prefix(stateDescriptor.getName()),
- stateDescriptor.getElementSerializer());
+ stateDescriptor.isSerializerInitialized()
Review Comment:
Good catch. I have updated the code and checked `UnionListState` and `BroadcastState`.
--
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
[GitHub] [flink-ml] zhipeng93 commented on a diff in pull request #216: [Flink-31173] Fix serveral iteration bugs
Posted by "zhipeng93 (via GitHub)" <gi...@apache.org>.
zhipeng93 commented on code in PR #216:
URL: https://github.com/apache/flink-ml/pull/216#discussion_r1169999415
##########
flink-ml-tests/src/test/java/org/apache/flink/test/iteration/BoundedIterationWithBroadcastITCase.java:
##########
@@ -0,0 +1,152 @@
+/*
+ * 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.iteration;
+
+import org.apache.flink.api.common.functions.MapFunction;
+import org.apache.flink.api.common.typeinfo.Types;
+import org.apache.flink.iteration.DataStreamList;
+import org.apache.flink.iteration.IterationBody;
+import org.apache.flink.iteration.IterationBodyResult;
+import org.apache.flink.iteration.IterationConfig;
+import org.apache.flink.iteration.IterationConfig.OperatorLifeCycle;
+import org.apache.flink.iteration.Iterations;
+import org.apache.flink.iteration.ReplayableDataStreamList;
+import org.apache.flink.ml.common.broadcast.BroadcastUtils;
+import org.apache.flink.ml.common.iteration.TerminateOnMaxIter;
+import org.apache.flink.runtime.jobgraph.JobGraph;
+import org.apache.flink.runtime.minicluster.MiniCluster;
+import org.apache.flink.streaming.api.datastream.DataStream;
+import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;
+import org.apache.flink.streaming.api.functions.sink.SinkFunction;
+import org.apache.flink.testutils.junit.SharedObjects;
+import org.apache.flink.testutils.junit.SharedReference;
+import org.apache.flink.util.TestLogger;
+
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.List;
+import java.util.concurrent.BlockingQueue;
+import java.util.concurrent.LinkedBlockingQueue;
+
+import static org.apache.flink.test.iteration.UnboundedStreamIterationITCase.createMiniClusterConfiguration;
+import static org.junit.Assert.assertEquals;
+
+/** Tests using {@link BroadcastUtils#withBroadcastStream} in iterations. */
+public class BoundedIterationWithBroadcastITCase extends TestLogger {
+
+ @Rule public final SharedObjects sharedObjects = SharedObjects.create();
+
+ private MiniCluster miniCluster;
+
+ private SharedReference<BlockingQueue<Long>> result;
+
+ @Before
+ public void setup() throws Exception {
+ miniCluster = new MiniCluster(createMiniClusterConfiguration(1, 1));
+ miniCluster.start();
+
+ result = sharedObjects.add(new LinkedBlockingQueue<>());
+ }
+
+ @After
+ public void teardown() throws Exception {
+ if (miniCluster != null) {
+ miniCluster.close();
+ }
+ }
+
+ @Test
+ public void testIterationWithBroadcastJobGraph() throws Exception {
Review Comment:
The `getListState` in `DefaultOperatorStateBackend` does the initialization here [1] while `ProxyOperatorStateBackend` does not.
--
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
[GitHub] [flink-ml] zhipeng93 commented on a diff in pull request #216: [Flink-31173] Fix serveral iteration bugs
Posted by "zhipeng93 (via GitHub)" <gi...@apache.org>.
zhipeng93 commented on code in PR #216:
URL: https://github.com/apache/flink-ml/pull/216#discussion_r1169999415
##########
flink-ml-tests/src/test/java/org/apache/flink/test/iteration/BoundedIterationWithBroadcastITCase.java:
##########
@@ -0,0 +1,152 @@
+/*
+ * 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.iteration;
+
+import org.apache.flink.api.common.functions.MapFunction;
+import org.apache.flink.api.common.typeinfo.Types;
+import org.apache.flink.iteration.DataStreamList;
+import org.apache.flink.iteration.IterationBody;
+import org.apache.flink.iteration.IterationBodyResult;
+import org.apache.flink.iteration.IterationConfig;
+import org.apache.flink.iteration.IterationConfig.OperatorLifeCycle;
+import org.apache.flink.iteration.Iterations;
+import org.apache.flink.iteration.ReplayableDataStreamList;
+import org.apache.flink.ml.common.broadcast.BroadcastUtils;
+import org.apache.flink.ml.common.iteration.TerminateOnMaxIter;
+import org.apache.flink.runtime.jobgraph.JobGraph;
+import org.apache.flink.runtime.minicluster.MiniCluster;
+import org.apache.flink.streaming.api.datastream.DataStream;
+import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;
+import org.apache.flink.streaming.api.functions.sink.SinkFunction;
+import org.apache.flink.testutils.junit.SharedObjects;
+import org.apache.flink.testutils.junit.SharedReference;
+import org.apache.flink.util.TestLogger;
+
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.List;
+import java.util.concurrent.BlockingQueue;
+import java.util.concurrent.LinkedBlockingQueue;
+
+import static org.apache.flink.test.iteration.UnboundedStreamIterationITCase.createMiniClusterConfiguration;
+import static org.junit.Assert.assertEquals;
+
+/** Tests using {@link BroadcastUtils#withBroadcastStream} in iterations. */
+public class BoundedIterationWithBroadcastITCase extends TestLogger {
+
+ @Rule public final SharedObjects sharedObjects = SharedObjects.create();
+
+ private MiniCluster miniCluster;
+
+ private SharedReference<BlockingQueue<Long>> result;
+
+ @Before
+ public void setup() throws Exception {
+ miniCluster = new MiniCluster(createMiniClusterConfiguration(1, 1));
+ miniCluster.start();
+
+ result = sharedObjects.add(new LinkedBlockingQueue<>());
+ }
+
+ @After
+ public void teardown() throws Exception {
+ if (miniCluster != null) {
+ miniCluster.close();
+ }
+ }
+
+ @Test
+ public void testIterationWithBroadcastJobGraph() throws Exception {
Review Comment:
The `getListState` in `DefaultOperatorStateBackend` does the initialization here [1] while `ProxyOperatorStateBackend` does not.
[1] https://github.com/apache/flink/blob/master/flink-runtime/src/main/java/org/apache/flink/runtime/state/DefaultOperatorStateBackend.java#L257
--
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
[GitHub] [flink-ml] lindong28 commented on a diff in pull request #216: [Flink-31173] Fix serveral iteration bugs
Posted by "lindong28 (via GitHub)" <gi...@apache.org>.
lindong28 commented on code in PR #216:
URL: https://github.com/apache/flink-ml/pull/216#discussion_r1167966461
##########
flink-ml-tests/src/test/java/org/apache/flink/test/iteration/BoundedPerRoundCheckpointITCase.java:
##########
@@ -106,7 +106,7 @@ public void testFailoverAndRestore() throws Exception {
}
// 0 ~ 4 round and termination information
- assertEquals(4, roundsStat.size());
+ assertEquals(5, roundsStat.size());
Review Comment:
Can you help explain why it should be the expected result according to the Iteration API semantics?
##########
flink-ml-iteration/src/main/java/org/apache/flink/iteration/proxy/state/ProxyOperatorStateBackend.java:
##########
@@ -58,12 +62,24 @@ public <K, V> BroadcastState<K, V> getBroadcastState(MapStateDescriptor<K, V> st
return wrappedBackend.getBroadcastState(newDescriptor);
}
+ private <S> TypeInformation<S> getTypeInfo(ListStateDescriptor<S> stateDescriptor)
+ throws Exception {
+ Field f = StateDescriptor.class.getDeclaredField("typeInfo");
+ f.setAccessible(true);
+ return ((ListTypeInfo) f.get(stateDescriptor)).getElementTypeInfo();
+ }
+
@Override
public <S> ListState<S> getListState(ListStateDescriptor<S> stateDescriptor) throws Exception {
ListStateDescriptor<S> newDescriptor =
- new ListStateDescriptor<>(
- stateNamePrefix.prefix(stateDescriptor.getName()),
- stateDescriptor.getElementSerializer());
+ stateDescriptor.isSerializerInitialized()
Review Comment:
Does `getUnionListState()` also need to check this?
##########
flink-ml-tests/src/test/java/org/apache/flink/test/iteration/BoundedTailOperatorWithUnionInputIterationITCase.java:
##########
@@ -0,0 +1,75 @@
+/*
+ * 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.iteration;
+
+import org.apache.flink.iteration.DataStreamList;
+import org.apache.flink.iteration.IterationBody;
+import org.apache.flink.iteration.IterationBodyResult;
+import org.apache.flink.iteration.IterationConfig;
+import org.apache.flink.iteration.IterationConfig.OperatorLifeCycle;
+import org.apache.flink.iteration.Iterations;
+import org.apache.flink.iteration.ReplayableDataStreamList;
+import org.apache.flink.ml.common.iteration.TerminateOnMaxIter;
+import org.apache.flink.streaming.api.datastream.DataStream;
+import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;
+
+import org.junit.Test;
+
+import static org.junit.Assert.assertEquals;
+
+/** Tests the case that Tail operator contains multiple inputs. */
+public class BoundedTailOperatorWithUnionInputIterationITCase {
+
+ @Test
+ public void testTailOperatorWithUnionInput() {
+ StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment();
+ DataStream<Long> input1 = env.fromSequence(0, 10);
+ DataStream<Long> input2 = env.fromSequence(0, 10);
+ String expectedErrorMessage =
+ "Tail operator should have only one input. Please check whether operator "
+ + "\"Union\" contains multiple inputs.";
+
+ try {
+ Iterations.iterateBoundedStreamsUntilTermination(
+ DataStreamList.of(input1),
+ ReplayableDataStreamList.replay(input2),
+ new IterationConfig(OperatorLifeCycle.PER_ROUND),
+ new IterationBodyWithUnionAsFeedback());
+ } catch (UnsupportedOperationException e) {
+ assertEquals(expectedErrorMessage, e.getMessage());
+ }
+ }
+
+ private static class IterationBodyWithUnionAsFeedback implements IterationBody {
+
+ @Override
+ public IterationBodyResult process(
+ DataStreamList variableStreams, DataStreamList dataStreams) {
+
+ DataStream<Long> variableStream = variableStreams.get(0);
+ DataStream<Long> constantStream = dataStreams.get(0);
+ DataStream<Integer> terminationCriteria =
+ constantStream.flatMap(new TerminateOnMaxIter<>(3));
+ return new IterationBodyResult(
+ DataStreamList.of(variableStream.union(constantStream)),
Review Comment:
The program seems semantically correct: it wants to use the union of "the constant input and the feedack stream" as the feedback stream in the next iteration.
Can you explain why we should not support programs like this?
And if we do need this it, would it be simpler to move it to `BoundedPerRoundStreamIterationITCase#testPerRoundIterationWithUnion`?
##########
flink-ml-tests/src/test/java/org/apache/flink/test/iteration/BoundedIterationWithBroadcastITCase.java:
##########
@@ -0,0 +1,152 @@
+/*
+ * 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.iteration;
+
+import org.apache.flink.api.common.functions.MapFunction;
+import org.apache.flink.api.common.typeinfo.Types;
+import org.apache.flink.iteration.DataStreamList;
+import org.apache.flink.iteration.IterationBody;
+import org.apache.flink.iteration.IterationBodyResult;
+import org.apache.flink.iteration.IterationConfig;
+import org.apache.flink.iteration.IterationConfig.OperatorLifeCycle;
+import org.apache.flink.iteration.Iterations;
+import org.apache.flink.iteration.ReplayableDataStreamList;
+import org.apache.flink.ml.common.broadcast.BroadcastUtils;
+import org.apache.flink.ml.common.iteration.TerminateOnMaxIter;
+import org.apache.flink.runtime.jobgraph.JobGraph;
+import org.apache.flink.runtime.minicluster.MiniCluster;
+import org.apache.flink.streaming.api.datastream.DataStream;
+import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;
+import org.apache.flink.streaming.api.functions.sink.SinkFunction;
+import org.apache.flink.testutils.junit.SharedObjects;
+import org.apache.flink.testutils.junit.SharedReference;
+import org.apache.flink.util.TestLogger;
+
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.List;
+import java.util.concurrent.BlockingQueue;
+import java.util.concurrent.LinkedBlockingQueue;
+
+import static org.apache.flink.test.iteration.UnboundedStreamIterationITCase.createMiniClusterConfiguration;
+import static org.junit.Assert.assertEquals;
+
+/** Tests using {@link BroadcastUtils#withBroadcastStream} in iterations. */
+public class BoundedIterationWithBroadcastITCase extends TestLogger {
+
+ @Rule public final SharedObjects sharedObjects = SharedObjects.create();
+
+ private MiniCluster miniCluster;
+
+ private SharedReference<BlockingQueue<Long>> result;
+
+ @Before
+ public void setup() throws Exception {
+ miniCluster = new MiniCluster(createMiniClusterConfiguration(1, 1));
+ miniCluster.start();
+
+ result = sharedObjects.add(new LinkedBlockingQueue<>());
+ }
+
+ @After
+ public void teardown() throws Exception {
+ if (miniCluster != null) {
+ miniCluster.close();
+ }
+ }
+
+ @Test
+ public void testIterationWithBroadcastJobGraph() throws Exception {
Review Comment:
Can you help explain why `ListStateDescriptor` is not initialized in this test but initialized in other tests?
##########
flink-ml-iteration/src/main/java/org/apache/flink/iteration/proxy/state/ProxyOperatorStateBackend.java:
##########
@@ -58,12 +62,24 @@ public <K, V> BroadcastState<K, V> getBroadcastState(MapStateDescriptor<K, V> st
return wrappedBackend.getBroadcastState(newDescriptor);
}
+ private <S> TypeInformation<S> getTypeInfo(ListStateDescriptor<S> stateDescriptor)
+ throws Exception {
+ Field f = StateDescriptor.class.getDeclaredField("typeInfo");
Review Comment:
It is probably more readable to use `ReflectionUtils` in a way similar to `OutputReflectionContext`.
--
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
[GitHub] [flink-ml] zhipeng93 commented on a diff in pull request #216: [FLINK-31173] Fix serveral iteration bugs
Posted by "zhipeng93 (via GitHub)" <gi...@apache.org>.
zhipeng93 commented on code in PR #216:
URL: https://github.com/apache/flink-ml/pull/216#discussion_r1172105766
##########
flink-ml-tests/src/test/java/org/apache/flink/test/iteration/BoundedTailOperatorWithUnionInputIterationITCase.java:
##########
@@ -0,0 +1,75 @@
+/*
+ * 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.iteration;
+
+import org.apache.flink.iteration.DataStreamList;
+import org.apache.flink.iteration.IterationBody;
+import org.apache.flink.iteration.IterationBodyResult;
+import org.apache.flink.iteration.IterationConfig;
+import org.apache.flink.iteration.IterationConfig.OperatorLifeCycle;
+import org.apache.flink.iteration.Iterations;
+import org.apache.flink.iteration.ReplayableDataStreamList;
+import org.apache.flink.ml.common.iteration.TerminateOnMaxIter;
+import org.apache.flink.streaming.api.datastream.DataStream;
+import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;
+
+import org.junit.Test;
+
+import static org.junit.Assert.assertEquals;
+
+/** Tests the case that Tail operator contains multiple inputs. */
+public class BoundedTailOperatorWithUnionInputIterationITCase {
+
+ @Test
+ public void testTailOperatorWithUnionInput() {
+ StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment();
+ DataStream<Long> input1 = env.fromSequence(0, 10);
+ DataStream<Long> input2 = env.fromSequence(0, 10);
+ String expectedErrorMessage =
+ "Tail operator should have only one input. Please check whether operator "
+ + "\"Union\" contains multiple inputs.";
+
+ try {
+ Iterations.iterateBoundedStreamsUntilTermination(
+ DataStreamList.of(input1),
+ ReplayableDataStreamList.replay(input2),
+ new IterationConfig(OperatorLifeCycle.PER_ROUND),
+ new IterationBodyWithUnionAsFeedback());
+ } catch (UnsupportedOperationException e) {
+ assertEquals(expectedErrorMessage, e.getMessage());
+ }
+ }
+
+ private static class IterationBodyWithUnionAsFeedback implements IterationBody {
+
+ @Override
+ public IterationBodyResult process(
+ DataStreamList variableStreams, DataStreamList dataStreams) {
+
+ DataStream<Long> variableStream = variableStreams.get(0);
+ DataStream<Long> constantStream = dataStreams.get(0);
+ DataStream<Integer> terminationCriteria =
+ constantStream.flatMap(new TerminateOnMaxIter<>(3));
+ return new IterationBodyResult(
+ DataStreamList.of(variableStream.union(constantStream)),
Review Comment:
I am afraid adding `map(x -> x)` to the wrapped operator does not work here. Currently iterations do not support `watermark` alignment. The bug comes in because `TailOperator` does not align the `epochwatermark`, rather than watermarks. `epochwatermark` should be viewed as a normal record from Flink framework's view.
The current situation is that:
- The tailOperator sends the epochwatermark to headOperator.
- headOperator expects that the epochwatermark should be strictly increasing.
- The tail operator made an assumption that it has only one input and it does not align the epochwatermarks. When receiving epochwatermarks, it directly pushes to the head operator.
If the tail operator has two inputs, it will push two same epochwatermarks to headOperator, which breaks the assumption.
I also added a TODO there.
--
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
[GitHub] [flink-ml] zhipeng93 commented on a diff in pull request #216: [FLINK-31173] Fix serveral iteration bugs
Posted by "zhipeng93 (via GitHub)" <gi...@apache.org>.
zhipeng93 commented on code in PR #216:
URL: https://github.com/apache/flink-ml/pull/216#discussion_r1172203484
##########
flink-ml-tests/src/test/java/org/apache/flink/test/iteration/BoundedIterationWithBroadcastITCase.java:
##########
@@ -0,0 +1,152 @@
+/*
+ * 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.iteration;
+
+import org.apache.flink.api.common.functions.MapFunction;
+import org.apache.flink.api.common.typeinfo.Types;
+import org.apache.flink.iteration.DataStreamList;
+import org.apache.flink.iteration.IterationBody;
+import org.apache.flink.iteration.IterationBodyResult;
+import org.apache.flink.iteration.IterationConfig;
+import org.apache.flink.iteration.IterationConfig.OperatorLifeCycle;
+import org.apache.flink.iteration.Iterations;
+import org.apache.flink.iteration.ReplayableDataStreamList;
+import org.apache.flink.ml.common.broadcast.BroadcastUtils;
+import org.apache.flink.ml.common.iteration.TerminateOnMaxIter;
+import org.apache.flink.runtime.jobgraph.JobGraph;
+import org.apache.flink.runtime.minicluster.MiniCluster;
+import org.apache.flink.streaming.api.datastream.DataStream;
+import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;
+import org.apache.flink.streaming.api.functions.sink.SinkFunction;
+import org.apache.flink.testutils.junit.SharedObjects;
+import org.apache.flink.testutils.junit.SharedReference;
+import org.apache.flink.util.TestLogger;
+
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.List;
+import java.util.concurrent.BlockingQueue;
+import java.util.concurrent.LinkedBlockingQueue;
+
+import static org.apache.flink.test.iteration.UnboundedStreamIterationITCase.createMiniClusterConfiguration;
+import static org.junit.Assert.assertEquals;
+
+/** Tests using {@link BroadcastUtils#withBroadcastStream} in iterations. */
+public class BoundedIterationWithBroadcastITCase extends TestLogger {
+
+ @Rule public final SharedObjects sharedObjects = SharedObjects.create();
+
+ private MiniCluster miniCluster;
+
+ private SharedReference<BlockingQueue<Long>> result;
+
+ @Before
+ public void setup() throws Exception {
+ miniCluster = new MiniCluster(createMiniClusterConfiguration(1, 1));
+ miniCluster.start();
+
+ result = sharedObjects.add(new LinkedBlockingQueue<>());
+ }
+
+ @After
+ public void teardown() throws Exception {
+ if (miniCluster != null) {
+ miniCluster.close();
+ }
+ }
+
+ @Test
+ public void testIterationWithBroadcastJobGraph() throws Exception {
Review Comment:
Before calling `DefaultOperatorStateBackend#getListState`, `ProxyOperatorStateBackend` will call `getElementSerializer` first, this may lead to NPE.
--
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
[GitHub] [flink-ml] lindong28 closed pull request #216: [FLINK-31173] Fix serveral iteration bugs
Posted by "lindong28 (via GitHub)" <gi...@apache.org>.
lindong28 closed pull request #216: [FLINK-31173] Fix serveral iteration bugs
URL: https://github.com/apache/flink-ml/pull/216
--
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