Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug] Fix NoSuchElementException when enable partition mark done #4356

Merged
merged 1 commit into from
Oct 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,10 @@ public PartitionMarkDoneTriggerState(boolean isRestored, OperatorStateStore stat
public List<String> restore() throws Exception {
List<String> pendingPartitions = new ArrayList<>();
if (isRestored) {
pendingPartitions.addAll(pendingPartitionsState.get().iterator().next());
Iterator<List<String>> state = pendingPartitionsState.get().iterator();
if (state.hasNext()) {
pendingPartitions.addAll(state.next());
}
}
return pendingPartitions;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import org.apache.paimon.Snapshot;
import org.apache.paimon.data.BinaryRow;
import org.apache.paimon.data.GenericRow;
import org.apache.paimon.flink.FlinkConnectorOptions;
import org.apache.paimon.flink.utils.TestingMetricUtils;
import org.apache.paimon.fs.local.LocalFileIO;
import org.apache.paimon.io.CompactIncrement;
Expand All @@ -37,6 +38,7 @@
import org.apache.paimon.utils.SnapshotManager;
import org.apache.paimon.utils.ThrowingConsumer;

import org.apache.paimon.shade.guava30.com.google.common.collect.ImmutableMap;
import org.apache.paimon.shade.guava30.com.google.common.collect.Lists;

import org.apache.flink.api.common.ExecutionConfig;
Expand Down Expand Up @@ -281,6 +283,34 @@ public void testRestoreCommitUser() throws Exception {
Assertions.assertThat(actual).hasSameElementsAs(Lists.newArrayList(commitUser));
}

@Test
public void testRestoreEmptyMarkDoneState() throws Exception {
FileStoreTable table = createFileStoreTable(o -> {}, Collections.singletonList("b"));

String commitUser = UUID.randomUUID().toString();

// 1. Generate operatorSubtaskState
OperatorSubtaskState snapshot;
{
OneInputStreamOperatorTestHarness<Committable, Committable> testHarness =
createLossyTestHarness(table, commitUser);

testHarness.open();
snapshot = writeAndSnapshot(table, commitUser, 1, 1, testHarness);
testHarness.close();
}
// 2. enable mark done.
table =
table.copy(
ImmutableMap.of(
FlinkConnectorOptions.PARTITION_IDLE_TIME_TO_DONE.key(), "1h"));

// 3. restore from state.
OneInputStreamOperatorTestHarness<Committable, Committable> testHarness =
createLossyTestHarness(table);
testHarness.initializeState(snapshot);
}

@Test
public void testCommitInputEnd() throws Exception {
FileStoreTable table = createFileStoreTable();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,10 +88,15 @@ protected void assertResults(FileStoreTable table, String... expected) {
}

protected FileStoreTable createFileStoreTable() throws Exception {
return createFileStoreTable(options -> {});
return createFileStoreTable(options -> {}, Collections.emptyList());
}

protected FileStoreTable createFileStoreTable(Consumer<Options> setOptions) throws Exception {
return createFileStoreTable(setOptions, Collections.emptyList());
}

protected FileStoreTable createFileStoreTable(
Consumer<Options> setOptions, List<String> partitionKeys) throws Exception {
Options conf = new Options();
conf.set(CoreOptions.PATH, tablePath.toString());
conf.setString("bucket", "1");
Expand All @@ -101,7 +106,7 @@ protected FileStoreTable createFileStoreTable(Consumer<Options> setOptions) thro
schemaManager.createTable(
new Schema(
ROW_TYPE.getFields(),
Collections.emptyList(),
partitionKeys,
Collections.emptyList(),
conf.toMap(),
""));
Expand Down
Loading