You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@flink.apache.org by pn...@apache.org on 2024/05/17 08:07:46 UTC
(flink) branch release-1.19 updated (190522c2c05 -> a160f8db1f7)
This is an automated email from the ASF dual-hosted git repository.
pnowojski pushed a change to branch release-1.19
in repository https://gitbox.apache.org/repos/asf/flink.git
from 190522c2c05 [FLINK-27741][table-planner] Fix NPE when use dense_rank() and rank()
new db051086b3b [hotfix] Make MockSourceSplit#addRecord calls chainable
new f6c5fee2418 [hotfix] Allow configuring initial splits in SourceOperatorTestContext
new 5aa02cbb633 [hotfix] Allow to use per split output via SourceOperatorTestContext
new a160f8db1f7 [FLINK-32828] Properly initialize initial splits in WatermarkOutputMultiplexer
The 4 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails. The revisions
listed as "add" were already present in the repository and have only
been added to this reference.
Summary of changes:
.../connector/source/mocks/MockSourceReader.java | 10 +--
.../connector/source/mocks/MockSourceSplit.java | 3 +-
.../streaming/api/operators/SourceOperator.java | 7 +-
.../api/operators/SourceOperatorAlignmentTest.java | 2 +-
.../api/operators/SourceOperatorTest.java | 1 +
.../api/operators/SourceOperatorTestContext.java | 31 +++++--
.../operators/SourceOperatorWatermarksTest.java | 97 ++++++++++++++++++++++
7 files changed, 130 insertions(+), 21 deletions(-)
create mode 100644 flink-streaming-java/src/test/java/org/apache/flink/streaming/api/operators/SourceOperatorWatermarksTest.java
(flink) 04/04: [FLINK-32828] Properly initialize initial splits in WatermarkOutputMultiplexer
Posted by pn...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
pnowojski pushed a commit to branch release-1.19
in repository https://gitbox.apache.org/repos/asf/flink.git
commit a160f8db1f76e672ac163ff251aea3413853c442
Author: Piotr Nowojski <pi...@gmail.com>
AuthorDate: Wed May 15 15:57:34 2024 +0200
[FLINK-32828] Properly initialize initial splits in WatermarkOutputMultiplexer
Without this fix, initial splits were registered in the multiplexer only
when first record from that split has been emitted. This was leading to
incorrectly emitted watermarks, as resulting watermark was not properly
combined from the initial splits, but only from the splits that have
already emitted at least one record.
---
.../streaming/api/operators/SourceOperator.java | 7 +-
.../api/operators/SourceOperatorAlignmentTest.java | 2 +-
.../operators/SourceOperatorWatermarksTest.java | 97 ++++++++++++++++++++++
3 files changed, 102 insertions(+), 4 deletions(-)
diff --git a/flink-streaming-java/src/main/java/org/apache/flink/streaming/api/operators/SourceOperator.java b/flink-streaming-java/src/main/java/org/apache/flink/streaming/api/operators/SourceOperator.java
index 91d9a463178..4325f04e991 100644
--- a/flink-streaming-java/src/main/java/org/apache/flink/streaming/api/operators/SourceOperator.java
+++ b/flink-streaming-java/src/main/java/org/apache/flink/streaming/api/operators/SourceOperator.java
@@ -169,7 +169,7 @@ public class SourceOperator<OUT, SplitT extends SourceSplit> extends AbstractStr
private final SourceOperatorAvailabilityHelper availabilityHelper =
new SourceOperatorAvailabilityHelper();
- private final List<SplitT> outputPendingSplits = new ArrayList<>();
+ private final List<SplitT> splitsToInitializeOutput = new ArrayList<>();
private int numSplits;
private final Map<String, Long> splitCurrentWatermarks = new HashMap<>();
@@ -343,6 +343,7 @@ public class SourceOperator<OUT, SplitT extends SourceSplit> extends AbstractStr
final List<SplitT> splits = CollectionUtil.iterableToList(readerState.get());
if (!splits.isEmpty()) {
LOG.info("Restoring state for {} split(s) to reader.", splits.size());
+ splitsToInitializeOutput.addAll(splits);
sourceReader.addSplits(splits);
}
@@ -465,7 +466,7 @@ public class SourceOperator<OUT, SplitT extends SourceSplit> extends AbstractStr
initializeLatencyMarkerEmitter(output);
lastInvokedOutput = output;
// Create per-split output for pending splits added before main output is initialized
- createOutputForSplits(outputPendingSplits);
+ createOutputForSplits(splitsToInitializeOutput);
this.operatingMode = OperatingMode.READING;
}
@@ -592,7 +593,7 @@ public class SourceOperator<OUT, SplitT extends SourceSplit> extends AbstractStr
// For splits arrived before the main output is initialized, store them into the
// pending list. Outputs of these splits will be created once the main output is
// ready.
- outputPendingSplits.addAll(newSplits);
+ splitsToInitializeOutput.addAll(newSplits);
} else {
// Create output directly for new splits if the main output is already initialized.
createOutputForSplits(newSplits);
diff --git a/flink-streaming-java/src/test/java/org/apache/flink/streaming/api/operators/SourceOperatorAlignmentTest.java b/flink-streaming-java/src/test/java/org/apache/flink/streaming/api/operators/SourceOperatorAlignmentTest.java
index dc029c272d8..db3f8f0ed1f 100644
--- a/flink-streaming-java/src/test/java/org/apache/flink/streaming/api/operators/SourceOperatorAlignmentTest.java
+++ b/flink-streaming-java/src/test/java/org/apache/flink/streaming/api/operators/SourceOperatorAlignmentTest.java
@@ -311,7 +311,7 @@ class SourceOperatorAlignmentTest {
assertThat(events).isEmpty();
}
- private static class PunctuatedGenerator implements WatermarkGenerator<Integer> {
+ static class PunctuatedGenerator implements WatermarkGenerator<Integer> {
private enum GenerationMode {
ALL,
diff --git a/flink-streaming-java/src/test/java/org/apache/flink/streaming/api/operators/SourceOperatorWatermarksTest.java b/flink-streaming-java/src/test/java/org/apache/flink/streaming/api/operators/SourceOperatorWatermarksTest.java
new file mode 100644
index 00000000000..63b7b8ff371
--- /dev/null
+++ b/flink-streaming-java/src/test/java/org/apache/flink/streaming/api/operators/SourceOperatorWatermarksTest.java
@@ -0,0 +1,97 @@
+/*
+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.streaming.api.operators;
+
+import org.apache.flink.api.common.eventtime.WatermarkStrategy;
+import org.apache.flink.api.connector.source.mocks.MockSourceSplit;
+import org.apache.flink.streaming.api.operators.source.CollectingDataOutput;
+import org.apache.flink.streaming.api.watermark.Watermark;
+import org.apache.flink.streaming.runtime.io.DataInputStatus;
+import org.apache.flink.streaming.util.MockOutput;
+
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+
+import javax.annotation.Nullable;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+/** Unit test for {@link SourceOperator} watermark alignment. */
+@SuppressWarnings("serial")
+class SourceOperatorWatermarksTest {
+
+ @Nullable private SourceOperatorTestContext context;
+ @Nullable private SourceOperator<Integer, MockSourceSplit> operator;
+
+ @BeforeEach
+ void setup() throws Exception {
+ context =
+ new SourceOperatorTestContext(
+ false,
+ true,
+ WatermarkStrategy.forGenerator(
+ ctx ->
+ new SourceOperatorAlignmentTest
+ .PunctuatedGenerator())
+ .withTimestampAssigner((r, t) -> r),
+ new MockOutput<>(new ArrayList<>()));
+ operator = context.getOperator();
+ }
+
+ @AfterEach
+ void tearDown() throws Exception {
+ context.close();
+ context = null;
+ operator = null;
+ }
+
+ @Test
+ void testPerPartitionWatermarksAfterRecovery() throws Exception {
+ List<MockSourceSplit> initialSplits = new ArrayList<>();
+ initialSplits.add(new MockSourceSplit(0).addRecord(1042).addRecord(1044));
+ initialSplits.add(new MockSourceSplit(1).addRecord(42).addRecord(44));
+ operator.initializeState(context.createStateContext(initialSplits));
+ operator.open();
+
+ CollectingDataOutput<Integer> actualOutput = new CollectingDataOutput<>();
+
+ // after emitting the first element from the first split, there can not be watermark
+ // emitted, as a watermark from the other split is still unknown.
+ assertThat(operator.emitNext(actualOutput)).isEqualTo(DataInputStatus.MORE_AVAILABLE);
+ assertNoWatermarks(actualOutput);
+
+ // after emitting two more elements (in this order: [1042, 1044, 42] but order doesn't
+ // matter for this test), three in total, watermark 42 can be finally emitted
+ assertThat(operator.emitNext(actualOutput)).isEqualTo(DataInputStatus.MORE_AVAILABLE);
+ assertThat(operator.emitNext(actualOutput)).isEqualTo(DataInputStatus.MORE_AVAILABLE);
+ assertWatermark(actualOutput, new Watermark(42));
+ }
+
+ private static void assertNoWatermarks(CollectingDataOutput<Integer> actualOutput) {
+ assertThat(actualOutput.getEvents()).noneMatch(element -> element instanceof Watermark);
+ }
+
+ private void assertWatermark(CollectingDataOutput<Integer> actualOutput, Watermark watermark) {
+ assertThat(actualOutput.getEvents()).containsOnlyOnce(watermark);
+ }
+}
(flink) 03/04: [hotfix] Allow to use per split output via SourceOperatorTestContext
Posted by pn...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
pnowojski pushed a commit to branch release-1.19
in repository https://gitbox.apache.org/repos/asf/flink.git
commit 5aa02cbb63397be67a02b6e7fd7fbea67f87a964
Author: Piotr Nowojski <pi...@gmail.com>
AuthorDate: Wed May 15 17:31:03 2024 +0200
[hotfix] Allow to use per split output via SourceOperatorTestContext
---
.../flink/api/connector/source/mocks/MockSourceReader.java | 10 +---------
.../flink/streaming/api/operators/SourceOperatorTest.java | 1 +
.../streaming/api/operators/SourceOperatorTestContext.java | 11 +++++++++--
3 files changed, 11 insertions(+), 11 deletions(-)
diff --git a/flink-core/src/test/java/org/apache/flink/api/connector/source/mocks/MockSourceReader.java b/flink-core/src/test/java/org/apache/flink/api/connector/source/mocks/MockSourceReader.java
index ce5660bd30f..2c1d4b40867 100644
--- a/flink-core/src/test/java/org/apache/flink/api/connector/source/mocks/MockSourceReader.java
+++ b/flink-core/src/test/java/org/apache/flink/api/connector/source/mocks/MockSourceReader.java
@@ -61,15 +61,7 @@ public class MockSourceReader implements SourceReader<Integer, MockSourceSplit>
private CompletableFuture<Void> availableFuture;
public MockSourceReader() {
- this(false, false);
- }
-
- public MockSourceReader(boolean waitingForMoreSplits, boolean markIdleOnNoSplits) {
- this(
- waitingForMoreSplits
- ? WaitingForSplits.WAIT_UNTIL_ALL_SPLITS_ASSIGNED
- : WaitingForSplits.DO_NOT_WAIT_FOR_SPLITS,
- markIdleOnNoSplits);
+ this(WaitingForSplits.DO_NOT_WAIT_FOR_SPLITS, false);
}
public MockSourceReader(
diff --git a/flink-streaming-java/src/test/java/org/apache/flink/streaming/api/operators/SourceOperatorTest.java b/flink-streaming-java/src/test/java/org/apache/flink/streaming/api/operators/SourceOperatorTest.java
index edb4a6150a7..5f983b15257 100644
--- a/flink-streaming-java/src/test/java/org/apache/flink/streaming/api/operators/SourceOperatorTest.java
+++ b/flink-streaming-java/src/test/java/org/apache/flink/streaming/api/operators/SourceOperatorTest.java
@@ -210,6 +210,7 @@ public class SourceOperatorTest {
List<StreamElement> outputStreamElements = new ArrayList<>();
context =
new SourceOperatorTestContext(
+ false,
false,
WatermarkStrategy.<Integer>forMonotonousTimestamps()
.withTimestampAssigner((element, recordTimestamp) -> element),
diff --git a/flink-streaming-java/src/test/java/org/apache/flink/streaming/api/operators/SourceOperatorTestContext.java b/flink-streaming-java/src/test/java/org/apache/flink/streaming/api/operators/SourceOperatorTestContext.java
index e24270e2684..13e31be1005 100644
--- a/flink-streaming-java/src/test/java/org/apache/flink/streaming/api/operators/SourceOperatorTestContext.java
+++ b/flink-streaming-java/src/test/java/org/apache/flink/streaming/api/operators/SourceOperatorTestContext.java
@@ -75,15 +75,22 @@ public class SourceOperatorTestContext implements AutoCloseable {
public SourceOperatorTestContext(boolean idle, WatermarkStrategy<Integer> watermarkStrategy)
throws Exception {
- this(idle, watermarkStrategy, new MockOutput<>(new ArrayList<>()));
+ this(idle, false, watermarkStrategy, new MockOutput<>(new ArrayList<>()));
}
public SourceOperatorTestContext(
boolean idle,
+ boolean usePerSplitOutputs,
WatermarkStrategy<Integer> watermarkStrategy,
Output<StreamRecord<Integer>> output)
throws Exception {
- mockSourceReader = new MockSourceReader(idle, idle);
+ mockSourceReader =
+ new MockSourceReader(
+ idle
+ ? MockSourceReader.WaitingForSplits.WAIT_UNTIL_ALL_SPLITS_ASSIGNED
+ : MockSourceReader.WaitingForSplits.DO_NOT_WAIT_FOR_SPLITS,
+ idle,
+ usePerSplitOutputs);
mockGateway = new MockOperatorEventGateway();
timeService = new TestProcessingTimeService();
operator =
(flink) 01/04: [hotfix] Make MockSourceSplit#addRecord calls chainable
Posted by pn...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
pnowojski pushed a commit to branch release-1.19
in repository https://gitbox.apache.org/repos/asf/flink.git
commit db051086b3b36f8b94e38fb7c656d21ad32d1b86
Author: Piotr Nowojski <pi...@gmail.com>
AuthorDate: Wed May 15 17:17:59 2024 +0200
[hotfix] Make MockSourceSplit#addRecord calls chainable
---
.../org/apache/flink/api/connector/source/mocks/MockSourceSplit.java | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/flink-core/src/test/java/org/apache/flink/api/connector/source/mocks/MockSourceSplit.java b/flink-core/src/test/java/org/apache/flink/api/connector/source/mocks/MockSourceSplit.java
index c2578596809..c45add729cd 100644
--- a/flink-core/src/test/java/org/apache/flink/api/connector/source/mocks/MockSourceSplit.java
+++ b/flink-core/src/test/java/org/apache/flink/api/connector/source/mocks/MockSourceSplit.java
@@ -84,10 +84,11 @@ public class MockSourceSplit implements SourceSplit, Serializable {
}
/** Add a record to this split. */
- public void addRecord(int record) {
+ public MockSourceSplit addRecord(int record) {
if (!records.offer(record)) {
throw new IllegalStateException("Failed to add record to split.");
}
+ return this;
}
@Override
(flink) 02/04: [hotfix] Allow configuring initial splits in SourceOperatorTestContext
Posted by pn...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
pnowojski pushed a commit to branch release-1.19
in repository https://gitbox.apache.org/repos/asf/flink.git
commit f6c5fee241861171ecb2515115b78e5237dfd723
Author: Piotr Nowojski <pi...@gmail.com>
AuthorDate: Wed May 15 17:27:28 2024 +0200
[hotfix] Allow configuring initial splits in SourceOperatorTestContext
---
.../api/operators/SourceOperatorTestContext.java | 20 +++++++++++++++-----
1 file changed, 15 insertions(+), 5 deletions(-)
diff --git a/flink-streaming-java/src/test/java/org/apache/flink/streaming/api/operators/SourceOperatorTestContext.java b/flink-streaming-java/src/test/java/org/apache/flink/streaming/api/operators/SourceOperatorTestContext.java
index 5a3c548a9c5..e24270e2684 100644
--- a/flink-streaming-java/src/test/java/org/apache/flink/streaming/api/operators/SourceOperatorTestContext.java
+++ b/flink-streaming-java/src/test/java/org/apache/flink/streaming/api/operators/SourceOperatorTestContext.java
@@ -47,7 +47,9 @@ import org.apache.flink.streaming.util.MockOutput;
import org.apache.flink.streaming.util.MockStreamConfig;
import java.util.ArrayList;
+import java.util.Collection;
import java.util.Collections;
+import java.util.List;
import static org.apache.flink.util.Preconditions.checkState;
@@ -124,10 +126,18 @@ public class SourceOperatorTestContext implements AutoCloseable {
}
public StateInitializationContext createStateContext() throws Exception {
- // Create a mock split.
- byte[] serializedSplitWithVersion =
- SimpleVersionedSerialization.writeVersionAndSerialize(
- new MockSourceSplitSerializer(), MOCK_SPLIT);
+ return createStateContext(Collections.singletonList(MOCK_SPLIT));
+ }
+
+ public StateInitializationContext createStateContext(Collection<MockSourceSplit> initialSplits)
+ throws Exception {
+
+ List<byte[]> serializedSplits = new ArrayList<>();
+ for (MockSourceSplit initialSplit : initialSplits) {
+ serializedSplits.add(
+ SimpleVersionedSerialization.writeVersionAndSerialize(
+ new MockSourceSplitSerializer(), initialSplit));
+ }
// Crate the state context.
OperatorStateStore operatorStateStore = createOperatorStateStore();
@@ -138,7 +148,7 @@ public class SourceOperatorTestContext implements AutoCloseable {
stateContext
.getOperatorStateStore()
.getListState(SourceOperator.SPLITS_STATE_DESC)
- .update(Collections.singletonList(serializedSplitWithVersion));
+ .update(serializedSplits);
return stateContext;
}