Skip to content
Open
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 @@ -104,8 +104,7 @@ public class FlinkSourceSplitReader implements SplitReader<RecordAndPos, SourceS

@Nullable private LakeSource<LakeSplit> lakeSource;

// table id, will be null when haven't received any split
private Long tableId;
private final Long tableId;

private final Map<TableBucket, Long> stoppingOffsets;
private LakeSplitReaderGenerator lakeSplitReaderGenerator;
Expand All @@ -127,6 +126,7 @@ public FlinkSourceSplitReader(
new FlinkMetricRegistry(flinkSourceReaderMetrics.getSourceReaderMetricGroup());
this.connection = ConnectionFactory.createConnection(flussConf, flinkMetricRegistry);
this.table = connection.getTable(tablePath);
this.tableId = table.getTableInfo().getTableId();
this.sourceOutputType = sourceOutputType;
this.boundedSplits = new ArrayDeque<>();
this.subscribedBuckets = new HashMap<>();
Expand Down Expand Up @@ -188,15 +188,10 @@ public void handleSplitsChanges(SplitsChange<SourceSplitBase> splitsChanges) {
}
for (SourceSplitBase sourceSplitBase : splitsChanges.splits()) {
LOG.info("add split {}", sourceSplitBase.splitId());
// init table id
if (tableId == null) {
tableId = sourceSplitBase.getTableBucket().getTableId();
} else {
checkArgument(
tableId.equals(sourceSplitBase.getTableBucket().getTableId()),
"table id not equal across splits {}",
splitsChanges.splits());
}
checkArgument(
tableId.equals(sourceSplitBase.getTableBucket().getTableId()),
"table id not equal across splits {}",
splitsChanges.splits());

if (sourceSplitBase.isHybridSnapshotLogSplit()) {
HybridSnapshotLogSplit hybridSnapshotLogSplit =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,25 @@ void testHandleHybridSnapshotLogSplitChangesAndFetch() throws Exception {
}
}

@Test
void testTableIdChange() throws Exception {
TablePath tablePath = TablePath.of(DEFAULT_DB, "test-only-snapshot-table");
long tableId = createTable(tablePath, DEFAULT_PK_TABLE_DESCRIPTOR);
try (FlinkSourceSplitReader splitReader =
createSplitReader(tablePath, DEFAULT_PK_TABLE_SCHEMA.getRowType())) {
assertThatThrownBy(
() ->
splitReader.handleSplitsChanges(
new SplitsAddition<>(
Collections.singletonList(
new LogSplit(
new TableBucket(tableId + 1, 0),
null,
0)))))
.hasMessageContaining("table id not equal across splits");
}
}

private Map<String, List<RecordAndPos>> constructRecords(
Map<TableBucket, List<InternalRow>> rows) {
Map<String, List<RecordAndPos>> expectedRecords = new HashMap<>();
Expand Down