|
25 | 25 | import org.apache.fluss.flink.FlinkConnectorOptions; |
26 | 26 | import org.apache.fluss.flink.lake.split.LakeSnapshotAndFlussLogSplit; |
27 | 27 | import org.apache.fluss.flink.lake.split.LakeSnapshotSplit; |
| 28 | +import org.apache.fluss.flink.source.FlinkSource; |
| 29 | +import org.apache.fluss.flink.source.deserializer.RowDataDeserializationSchema; |
28 | 30 | import org.apache.fluss.flink.source.event.PartitionBucketsUnsubscribedEvent; |
29 | 31 | import org.apache.fluss.flink.source.event.PartitionsRemovedEvent; |
30 | 32 | import org.apache.fluss.flink.source.reader.LeaseContext; |
31 | 33 | import org.apache.fluss.flink.source.split.HybridSnapshotLogSplit; |
32 | 34 | import org.apache.fluss.flink.source.split.LogSplit; |
33 | 35 | import org.apache.fluss.flink.source.split.SnapshotSplit; |
34 | 36 | import org.apache.fluss.flink.source.split.SourceSplitBase; |
| 37 | +import org.apache.fluss.flink.source.state.SourceEnumeratorState; |
35 | 38 | import org.apache.fluss.flink.utils.FlinkTestBase; |
36 | 39 | import org.apache.fluss.lake.source.LakeSource; |
37 | 40 | import org.apache.fluss.lake.source.LakeSplit; |
|
53 | 56 |
|
54 | 57 | import org.apache.flink.api.connector.source.ReaderInfo; |
55 | 58 | import org.apache.flink.api.connector.source.SourceEvent; |
| 59 | +import org.apache.flink.api.connector.source.SplitEnumerator; |
56 | 60 | import org.apache.flink.api.connector.source.SplitsAssignment; |
57 | 61 | import org.apache.flink.api.connector.source.mocks.MockSplitEnumeratorContext; |
| 62 | +import org.apache.flink.table.data.RowData; |
58 | 63 | import org.junit.jupiter.api.BeforeAll; |
59 | 64 | import org.junit.jupiter.api.Test; |
60 | 65 | import org.junit.jupiter.api.io.TempDir; |
@@ -210,6 +215,100 @@ void testInvalidSplitAssignmentBatchSize() throws Exception { |
210 | 215 | } |
211 | 216 | } |
212 | 217 |
|
| 218 | + @Test |
| 219 | + void testRestoreFlussOnlySourceWithLakeSourceDoesNotGenerateLakeSplits(@TempDir Path tempDir) |
| 220 | + throws Throwable { |
| 221 | + long tableId = |
| 222 | + createTable(DEFAULT_TABLE_PATH, DEFAULT_AUTO_PARTITIONED_LOG_TABLE_DESCRIPTOR); |
| 223 | + ZooKeeperClient zooKeeperClient = FLUSS_CLUSTER_EXTENSION.getZooKeeperClient(); |
| 224 | + Map<Long, String> partitionNameByIds = |
| 225 | + waitUntilPartitions(zooKeeperClient, DEFAULT_TABLE_PATH); |
| 226 | + Long partitionId = partitionNameByIds.keySet().stream().sorted().findFirst().get(); |
| 227 | + String partitionName = partitionNameByIds.get(partitionId); |
| 228 | + |
| 229 | + LakeTableSnapshot lakeTableSnapshot = |
| 230 | + new LakeTableSnapshot( |
| 231 | + 0, |
| 232 | + ImmutableMap.of( |
| 233 | + new TableBucket(tableId, partitionId, 0), 50L, |
| 234 | + new TableBucket(tableId, partitionId, 1), 50L, |
| 235 | + new TableBucket(tableId, partitionId, 2), 50L)); |
| 236 | + LakeTableHelper lakeTableHelper = new LakeTableHelper(zooKeeperClient, tempDir.toString()); |
| 237 | + lakeTableHelper.registerLakeTableSnapshotV1(tableId, lakeTableSnapshot); |
| 238 | + |
| 239 | + ResolvedPartitionSpec partitionSpec = |
| 240 | + ResolvedPartitionSpec.fromPartitionName( |
| 241 | + Collections.singletonList("name"), partitionName); |
| 242 | + LakeSource<LakeSplit> lakeSource = |
| 243 | + new TestingLakeSource( |
| 244 | + DEFAULT_BUCKET_NUM, |
| 245 | + Collections.singletonList( |
| 246 | + new PartitionInfo( |
| 247 | + partitionId, partitionSpec, DEFAULT_REMOTE_DATA_DIR))); |
| 248 | + |
| 249 | + SourceEnumeratorState checkpointState; |
| 250 | + try (MockSplitEnumeratorContext<SourceSplitBase> context = |
| 251 | + new MockSplitEnumeratorContext<>(1); |
| 252 | + SplitEnumerator<SourceSplitBase, SourceEnumeratorState> enumerator = |
| 253 | + new FlinkSource<RowData>( |
| 254 | + flussConf, |
| 255 | + DEFAULT_TABLE_PATH, |
| 256 | + false, |
| 257 | + true, |
| 258 | + DEFAULT_LOG_TABLE_SCHEMA.getRowType(), |
| 259 | + null, |
| 260 | + null, |
| 261 | + OffsetsInitializer.timestamp(1000L), |
| 262 | + 0L, |
| 263 | + new RowDataDeserializationSchema(), |
| 264 | + streaming, |
| 265 | + null, |
| 266 | + LeaseContext.DEFAULT) |
| 267 | + .createEnumerator(context)) { |
| 268 | + checkpointState = enumerator.snapshotState(1L); |
| 269 | + assertThat(checkpointState.getRemainingHybridLakeFlussSplits()).isNull(); |
| 270 | + } |
| 271 | + |
| 272 | + try (MockSplitEnumeratorContext<SourceSplitBase> context = |
| 273 | + new MockSplitEnumeratorContext<>(DEFAULT_BUCKET_NUM); |
| 274 | + SplitEnumerator<SourceSplitBase, SourceEnumeratorState> restoredEnumerator = |
| 275 | + new FlinkSource<RowData>( |
| 276 | + flussConf, |
| 277 | + DEFAULT_TABLE_PATH, |
| 278 | + false, |
| 279 | + true, |
| 280 | + DEFAULT_LOG_TABLE_SCHEMA.getRowType(), |
| 281 | + null, |
| 282 | + null, |
| 283 | + OffsetsInitializer.full(), |
| 284 | + 0L, |
| 285 | + new RowDataDeserializationSchema(), |
| 286 | + streaming, |
| 287 | + null, |
| 288 | + lakeSource, |
| 289 | + LeaseContext.DEFAULT) |
| 290 | + .restoreEnumerator(context, checkpointState)) { |
| 291 | + assertThat(restoredEnumerator.snapshotState(1L).getRemainingHybridLakeFlussSplits()) |
| 292 | + .isEmpty(); |
| 293 | + |
| 294 | + restoredEnumerator.start(); |
| 295 | + context.runNextOneTimeCallable(); |
| 296 | + context.runNextOneTimeCallable(); |
| 297 | + |
| 298 | + for (int i = 0; i < DEFAULT_BUCKET_NUM; i++) { |
| 299 | + registerReader(context, restoredEnumerator, i); |
| 300 | + } |
| 301 | + |
| 302 | + List<SourceSplitBase> assignedSplits = |
| 303 | + getReadersAssignments(context).values().stream() |
| 304 | + .flatMap(List::stream) |
| 305 | + .collect(Collectors.toList()); |
| 306 | + assertThat(assignedSplits).isNotEmpty(); |
| 307 | + assertThat(assignedSplits).allMatch(split -> split instanceof LogSplit); |
| 308 | + assertThat(assignedSplits).noneMatch(split -> split instanceof LakeSnapshotSplit); |
| 309 | + } |
| 310 | + } |
| 311 | + |
213 | 312 | @Test |
214 | 313 | void testPkTableWithSnapshotSplits() throws Throwable { |
215 | 314 | long tableId = createTable(DEFAULT_TABLE_PATH, DEFAULT_PK_TABLE_DESCRIPTOR); |
@@ -852,7 +951,7 @@ void testPartitionsExpiredInFlussButExistInLake( |
852 | 951 | // --------------------- |
853 | 952 | private void registerReader( |
854 | 953 | MockSplitEnumeratorContext<SourceSplitBase> context, |
855 | | - FlinkSourceEnumerator enumerator, |
| 954 | + SplitEnumerator<SourceSplitBase, SourceEnumeratorState> enumerator, |
856 | 955 | int readerId) { |
857 | 956 | context.registerReader(new ReaderInfo(readerId, "location " + readerId)); |
858 | 957 | enumerator.addReader(readerId); |
|
0 commit comments