|
32 | 32 | import org.apache.fluss.flink.source.split.LogSplit; |
33 | 33 | import org.apache.fluss.flink.source.split.SnapshotSplit; |
34 | 34 | import org.apache.fluss.flink.source.split.SourceSplitBase; |
| 35 | +import org.apache.fluss.flink.source.state.SourceEnumeratorState; |
35 | 36 | import org.apache.fluss.flink.utils.FlinkTestBase; |
36 | 37 | import org.apache.fluss.lake.source.LakeSource; |
37 | 38 | import org.apache.fluss.lake.source.LakeSplit; |
@@ -210,6 +211,97 @@ void testInvalidSplitAssignmentBatchSize() throws Exception { |
210 | 211 | } |
211 | 212 | } |
212 | 213 |
|
| 214 | + @Test |
| 215 | + void testRestoreFlussOnlySourceWithLakeSourceDoesNotGenerateLakeSplits(@TempDir Path tempDir) |
| 216 | + throws Throwable { |
| 217 | + long tableId = |
| 218 | + createTable(DEFAULT_TABLE_PATH, DEFAULT_AUTO_PARTITIONED_LOG_TABLE_DESCRIPTOR); |
| 219 | + ZooKeeperClient zooKeeperClient = FLUSS_CLUSTER_EXTENSION.getZooKeeperClient(); |
| 220 | + Map<Long, String> partitionNameByIds = |
| 221 | + waitUntilPartitions(zooKeeperClient, DEFAULT_TABLE_PATH); |
| 222 | + Long partitionId = partitionNameByIds.keySet().stream().sorted().findFirst().get(); |
| 223 | + String partitionName = partitionNameByIds.get(partitionId); |
| 224 | + |
| 225 | + LakeTableSnapshot lakeTableSnapshot = |
| 226 | + new LakeTableSnapshot( |
| 227 | + 0, |
| 228 | + ImmutableMap.of( |
| 229 | + new TableBucket(tableId, partitionId, 0), 50L, |
| 230 | + new TableBucket(tableId, partitionId, 1), 50L, |
| 231 | + new TableBucket(tableId, partitionId, 2), 50L)); |
| 232 | + LakeTableHelper lakeTableHelper = new LakeTableHelper(zooKeeperClient, tempDir.toString()); |
| 233 | + lakeTableHelper.registerLakeTableSnapshotV1(tableId, lakeTableSnapshot); |
| 234 | + |
| 235 | + ResolvedPartitionSpec partitionSpec = |
| 236 | + ResolvedPartitionSpec.fromPartitionName( |
| 237 | + Collections.singletonList("name"), partitionName); |
| 238 | + LakeSource<LakeSplit> lakeSource = |
| 239 | + new TestingLakeSource( |
| 240 | + DEFAULT_BUCKET_NUM, |
| 241 | + Collections.singletonList( |
| 242 | + new PartitionInfo( |
| 243 | + partitionId, partitionSpec, DEFAULT_REMOTE_DATA_DIR))); |
| 244 | + |
| 245 | + SourceEnumeratorState checkpointState; |
| 246 | + try (MockSplitEnumeratorContext<SourceSplitBase> context = |
| 247 | + new MockSplitEnumeratorContext<>(1)) { |
| 248 | + FlinkSourceEnumerator enumerator = |
| 249 | + new FlinkSourceEnumerator( |
| 250 | + DEFAULT_TABLE_PATH, |
| 251 | + flussConf, |
| 252 | + true, |
| 253 | + false, |
| 254 | + context, |
| 255 | + OffsetsInitializer.timestamp(1000L), |
| 256 | + DEFAULT_SCAN_PARTITION_DISCOVERY_INTERVAL_MS, |
| 257 | + streaming, |
| 258 | + null, |
| 259 | + null, |
| 260 | + LeaseContext.DEFAULT, |
| 261 | + false); |
| 262 | + |
| 263 | + checkpointState = enumerator.snapshotState(1L); |
| 264 | + assertThat(checkpointState.getRemainingHybridLakeFlussSplits()).isNotNull().isEmpty(); |
| 265 | + } |
| 266 | + |
| 267 | + try (MockSplitEnumeratorContext<SourceSplitBase> context = |
| 268 | + new MockSplitEnumeratorContext<>(DEFAULT_BUCKET_NUM); |
| 269 | + MockWorkExecutor workExecutor = new MockWorkExecutor(context); |
| 270 | + FlinkSourceEnumerator restoredEnumerator = |
| 271 | + new FlinkSourceEnumerator( |
| 272 | + DEFAULT_TABLE_PATH, |
| 273 | + flussConf, |
| 274 | + false, |
| 275 | + true, |
| 276 | + context, |
| 277 | + checkpointState.getAssignedBuckets(), |
| 278 | + checkpointState.getAssignedPartitions(), |
| 279 | + checkpointState.getRemainingHybridLakeFlussSplits(), |
| 280 | + OffsetsInitializer.full(), |
| 281 | + DEFAULT_SCAN_PARTITION_DISCOVERY_INTERVAL_MS, |
| 282 | + streaming, |
| 283 | + null, |
| 284 | + lakeSource, |
| 285 | + workExecutor, |
| 286 | + LeaseContext.DEFAULT, |
| 287 | + true)) { |
| 288 | + restoredEnumerator.start(); |
| 289 | + runPeriodicPartitionDiscovery(workExecutor); |
| 290 | + |
| 291 | + for (int i = 0; i < DEFAULT_BUCKET_NUM; i++) { |
| 292 | + registerReader(context, restoredEnumerator, i); |
| 293 | + } |
| 294 | + |
| 295 | + List<SourceSplitBase> assignedSplits = |
| 296 | + getReadersAssignments(context).values().stream() |
| 297 | + .flatMap(List::stream) |
| 298 | + .collect(Collectors.toList()); |
| 299 | + assertThat(assignedSplits).isNotEmpty(); |
| 300 | + assertThat(assignedSplits).allMatch(split -> split instanceof LogSplit); |
| 301 | + assertThat(assignedSplits).noneMatch(split -> split instanceof LakeSnapshotSplit); |
| 302 | + } |
| 303 | + } |
| 304 | + |
213 | 305 | @Test |
214 | 306 | void testPkTableWithSnapshotSplits() throws Throwable { |
215 | 307 | long tableId = createTable(DEFAULT_TABLE_PATH, DEFAULT_PK_TABLE_DESCRIPTOR); |
|
0 commit comments