Skip to content

Commit 365bc43

Browse files
committed
[fix](iceberg) Normalize V2 metadata read failures
1 parent 73da744 commit 365bc43

3 files changed

Lines changed: 168 additions & 33 deletions

File tree

‎fe/fe-connector/fe-connector-iceberg/src/main/java/org/apache/doris/connector/iceberg/IcebergExceptionUtils.java‎

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -31,15 +31,31 @@ private IcebergExceptionUtils() {
3131

3232
static RuntimeException wrapTableLoadFailure(
3333
IcebergTableHandle handle, Exception failure, String fallbackPrefix) {
34-
// Iceberg and FileIO implementations wrap missing metadata differently. Inspect every cause so all
35-
// read paths preserve the stable table-format contract instead of exposing a filesystem wrapper message.
36-
boolean metadataNotFound = ExceptionUtils.getThrowableList(failure).stream()
37-
.anyMatch(cause -> cause instanceof NotFoundException
38-
|| cause instanceof FileNotFoundException);
39-
if (metadataNotFound) {
40-
return new DorisConnectorException("Metadata not found in metadata location for table "
41-
+ handle.getDbName() + "." + handle.getTableName(), failure);
34+
if (isMetadataNotFound(failure)) {
35+
return metadataNotFound(handle, failure);
4236
}
4337
return new RuntimeException(fallbackPrefix + failure.getMessage(), failure);
4438
}
39+
40+
static RuntimeException wrapMetadataReadFailure(
41+
IcebergTableHandle handle, RuntimeException failure) {
42+
if (isMetadataNotFound(failure)) {
43+
return metadataNotFound(handle, failure);
44+
}
45+
return failure;
46+
}
47+
48+
private static boolean isMetadataNotFound(Throwable failure) {
49+
// Iceberg and FileIO implementations wrap missing metadata differently. Inspect every cause so eager
50+
// planners and background lazy split iteration preserve one stable table-scoped error contract.
51+
return ExceptionUtils.getThrowableList(failure).stream()
52+
.anyMatch(cause -> cause instanceof NotFoundException
53+
|| cause instanceof FileNotFoundException);
54+
}
55+
56+
private static DorisConnectorException metadataNotFound(
57+
IcebergTableHandle handle, Throwable failure) {
58+
return new DorisConnectorException("Metadata not found in metadata location for table "
59+
+ handle.getDbName() + "." + handle.getTableName(), failure);
60+
}
4561
}

‎fe/fe-connector/fe-connector-iceberg/src/main/java/org/apache/doris/connector/iceberg/IcebergScanPlanProvider.java‎

Lines changed: 61 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -418,8 +418,18 @@ public boolean supportsFileCache() {
418418
*/
419419
@Override
420420
public List<ConnectorScanRange> planScan(ConnectorSession session, ConnectorScanRequest request) {
421-
return planScanInternal(session, request.getTableHandle(), request.getColumns(),
422-
request.getFilter(), request.isCountPushdown());
421+
IcebergTableHandle handle = (IcebergTableHandle) request.getTableHandle();
422+
try {
423+
return planScanInternal(session, handle, request.getColumns(),
424+
request.getFilter(), request.isCountPushdown());
425+
} catch (RuntimeException e) {
426+
// Normal data scans and native position_deletes run on File Scanner V2. Keep the serialized JNI
427+
// system-table route untouched because its deferred reads belong to the V1 scanner contract.
428+
if (!handle.isSystemTable() || isPositionDeletesSysTable(handle)) {
429+
throw IcebergExceptionUtils.wrapMetadataReadFailure(handle, e);
430+
}
431+
throw e;
432+
}
423433
}
424434

425435
/**
@@ -465,8 +475,10 @@ public long streamingSplitEstimate(ConnectorSession session, ConnectorTableHandl
465475
fileCount += (added == null ? 0 : added) + (existing == null ? 0 : existing);
466476
}
467477
} catch (IOException e) {
468-
throw new RuntimeException("Failed to count iceberg manifest files for batch decision, error message is:"
469-
+ e.getMessage(), e);
478+
throw IcebergExceptionUtils.wrapTableLoadFailure(iceHandle, e,
479+
"Failed to count iceberg manifest files for batch decision, error message is:");
480+
} catch (RuntimeException e) {
481+
throw IcebergExceptionUtils.wrapMetadataReadFailure(iceHandle, e);
470482
}
471483
return fileCount >= threshold ? fileCount : -1;
472484
}
@@ -501,9 +513,15 @@ public ConnectorSplitSource streamSplits(ConnectorSession session, ConnectorTabl
501513
long fileSplitSize = sessionLong(session, FILE_SPLIT_SIZE, 0L);
502514
long sliceSize = fileSplitSize > 0 ? fileSplitSize
503515
: sessionLong(session, MAX_FILE_SPLIT_SIZE, DEFAULT_MAX_FILE_SPLIT_SIZE);
504-
CloseableIterable<FileScanTask> tasks = streamingFileScanTasks(scan, session, table, filter, sliceSize);
505-
return new IcebergStreamingSplitSource(tasks, table, formatVersion, partitioned,
506-
orderedPartitionKeys, zone, uriNormalizer, sliceSize, iceHandle.getRewriteFileScope());
516+
try {
517+
CloseableIterable<FileScanTask> tasks = streamingFileScanTasks(
518+
scan, session, table, filter, sliceSize);
519+
return new IcebergStreamingSplitSource(tasks, table, formatVersion, partitioned,
520+
orderedPartitionKeys, zone, uriNormalizer, sliceSize,
521+
iceHandle.getRewriteFileScope(), iceHandle);
522+
} catch (RuntimeException e) {
523+
throw IcebergExceptionUtils.wrapMetadataReadFailure(iceHandle, e);
524+
}
507525
}
508526

509527
private static ConnectorSplitSource emptySplitSource() {
@@ -564,6 +582,7 @@ private final class IcebergStreamingSplitSource implements ConnectorSplitSource
564582
private final UnaryOperator<String> uriNormalizer;
565583
private final long sliceSize;
566584
private final Set<String> rewriteScope;
585+
private final IcebergTableHandle handle;
567586
// Lazily opened on first hasNext() so the ctor never throws — iceberg's ParallelIterable submits
568587
// manifest readers in tasks.iterator(), which can fail; opening it eagerly here would throw out of
569588
// streamSplits() BEFORE the source is returned, leaking the planFiles() iterable (the engine pump's
@@ -578,7 +597,8 @@ private final class IcebergStreamingSplitSource implements ConnectorSplitSource
578597

579598
IcebergStreamingSplitSource(CloseableIterable<FileScanTask> tasks, Table table, int formatVersion,
580599
boolean partitioned, List<String> orderedPartitionKeys, ZoneId zone,
581-
UnaryOperator<String> uriNormalizer, long sliceSize, Set<String> rewriteScope) {
600+
UnaryOperator<String> uriNormalizer, long sliceSize, Set<String> rewriteScope,
601+
IcebergTableHandle handle) {
582602
this.tasks = tasks;
583603
this.table = table;
584604
this.formatVersion = formatVersion;
@@ -588,25 +608,31 @@ private final class IcebergStreamingSplitSource implements ConnectorSplitSource
588608
this.uriNormalizer = uriNormalizer;
589609
this.sliceSize = sliceSize;
590610
this.rewriteScope = rewriteScope;
611+
this.handle = handle;
591612
}
592613

593614
@Override
594615
public boolean hasNext() {
595-
if (buffered != null) {
596-
return true;
597-
}
598-
if (iterator == null) {
599-
iterator = tasks.iterator();
600-
}
601-
while (iterator.hasNext()) {
602-
IcebergScanRange range = buildRangeForTask(iterator.next(), table, formatVersion, partitioned,
603-
orderedPartitionKeys, zone, uriNormalizer, sliceSize, rewriteScope, null, scratch);
604-
if (range != null) {
605-
buffered = range;
616+
try {
617+
if (buffered != null) {
606618
return true;
607619
}
620+
if (iterator == null) {
621+
iterator = tasks.iterator();
622+
}
623+
while (iterator.hasNext()) {
624+
IcebergScanRange range = buildRangeForTask(iterator.next(), table, formatVersion, partitioned,
625+
orderedPartitionKeys, zone, uriNormalizer, sliceSize, rewriteScope, null, scratch);
626+
if (range != null) {
627+
buffered = range;
628+
return true;
629+
}
630+
}
631+
return false;
632+
} catch (RuntimeException e) {
633+
// Lazy manifest opening happens on the split-pump thread, after streamSplits has returned.
634+
throw IcebergExceptionUtils.wrapMetadataReadFailure(handle, e);
608635
}
609-
return false;
610636
}
611637

612638
@Override
@@ -1606,7 +1632,11 @@ public Map<String, String> getScanNodeProperties(
16061632
if (!systemTable) {
16071633
scanSchema = pinnedSchema(table, iceHandle);
16081634
exactScan = buildScan(table, iceHandle, filter, session);
1609-
applicableEqualityDeleteFieldIds = cachedApplicableEqualityDeleteFieldIds(table, exactScan);
1635+
try {
1636+
applicableEqualityDeleteFieldIds = cachedApplicableEqualityDeleteFieldIds(table, exactScan);
1637+
} catch (RuntimeException e) {
1638+
throw IcebergExceptionUtils.wrapMetadataReadFailure(iceHandle, e);
1639+
}
16101640
hasApplicableEqualityDeletes = !applicableEqualityDeleteFieldIds.isEmpty();
16111641
Optional<Map<Integer, List<String>>> nameMapping = IcebergSchemaUtils.extractNameMapping(table);
16121642
if (requiresCurrentScanSemantics(
@@ -1625,11 +1655,17 @@ public Map<String, String> getScanNodeProperties(
16251655
// PERF-03: the non-system format resolution falls back to an unfiltered whole-table planFiles() when the
16261656
// table sets neither write-format nor write.format.default; memoize that inference per (table, snapshot)
16271657
// across queries via formatCache (pure metadata, no credential gate). Null cache (offline) resolves live.
1628-
props.put(ScanNodePropertyKeys.FILE_FORMAT_TYPE,
1629-
systemTable ? "jni"
1630-
: IcebergWriterHelper.getFileFormat(table,
1658+
String fileFormatType = "jni";
1659+
if (!systemTable) {
1660+
try {
1661+
fileFormatType = IcebergWriterHelper.getFileFormat(table,
16311662
TableIdentifier.of(iceHandle.getDbName(), iceHandle.getTableName()), formatCache)
1632-
.name().toLowerCase(Locale.ROOT));
1663+
.name().toLowerCase(Locale.ROOT);
1664+
} catch (RuntimeException e) {
1665+
throw IcebergExceptionUtils.wrapMetadataReadFailure(iceHandle, e);
1666+
}
1667+
}
1668+
props.put(ScanNodePropertyKeys.FILE_FORMAT_TYPE, fileFormatType);
16331669
// [D-065] System (metadata) tables ($snapshots/$files/...) read via the JNI serialized-split path
16341670
// (planSystemTableScan): the metadata-table schema travels INSIDE the serialized FileScanTask, so BE
16351671
// needs neither the base-table path_partition_keys (a metadata table is not base-spec partitioned ->

‎fe/fe-connector/fe-connector-iceberg/src/test/java/org/apache/doris/connector/iceberg/IcebergScanPlanProviderTest.java‎

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,72 @@ public void planScanMissingMetadataFileHasStableTableError() {
225225
"Metadata not found in metadata location for table default.missing_table"), ex.getMessage());
226226
}
227227

228+
@Test
229+
public void planScanMissingManifestListHasStableTableError() {
230+
Table table = createTable("missing_manifest_list", SCHEMA, PartitionSpec.unpartitioned());
231+
table.newAppend().appendFile(dataFile(table.spec(),
232+
"s3://b/db/missing_manifest_list/f1.parquet", 1024, null, null)).commit();
233+
table.io().deleteFile(table.currentSnapshot().manifestListLocation());
234+
IcebergScanPlanProvider provider = providerOver(table);
235+
236+
DorisConnectorException ex = Assertions.assertThrows(DorisConnectorException.class,
237+
() -> provider.planScan(emptySession(), ConnectorScanRequest.builder(
238+
new IcebergTableHandle("db1", "missing_manifest_list"), Collections.emptyList()).build()));
239+
Assertions.assertTrue(ex.getMessage().contains(
240+
"Metadata not found in metadata location for table db1.missing_manifest_list"), ex.getMessage());
241+
}
242+
243+
@Test
244+
public void streamingMissingManifestListHasStableTableError() {
245+
Table table = createTable("missing_stream_manifest", SCHEMA, PartitionSpec.unpartitioned());
246+
table.newAppend().appendFile(dataFile(table.spec(),
247+
"s3://b/db/missing_stream_manifest/f1.parquet", 1024, null, null)).commit();
248+
table.io().deleteFile(table.currentSnapshot().manifestListLocation());
249+
IcebergScanPlanProvider provider = providerOver(table);
250+
IcebergTableHandle handle = new IcebergTableHandle("db1", "missing_stream_manifest");
251+
252+
DorisConnectorException estimate = Assertions.assertThrows(DorisConnectorException.class,
253+
() -> provider.streamingSplitEstimate(batchSession(1, true), handle, Optional.empty(), false));
254+
Assertions.assertTrue(estimate.getMessage().contains(
255+
"Metadata not found in metadata location for table db1.missing_stream_manifest"),
256+
estimate.getMessage());
257+
258+
DorisConnectorException lazy = Assertions.assertThrows(DorisConnectorException.class, () -> {
259+
try (ConnectorSplitSource source = provider.streamSplits(
260+
emptySession(), handle, Collections.emptyList(), Optional.empty(), -1L)) {
261+
source.hasNext();
262+
}
263+
});
264+
Assertions.assertTrue(lazy.getMessage().contains(
265+
"Metadata not found in metadata location for table db1.missing_stream_manifest"),
266+
lazy.getMessage());
267+
}
268+
269+
@Test
270+
public void scanPropertiesMissingDeleteManifestHasStableTableError() {
271+
Schema schema = new Schema(
272+
Arrays.asList(
273+
Types.NestedField.required(1, "id", Types.IntegerType.get()),
274+
Types.NestedField.optional(2, "name", Types.StringType.get())),
275+
Collections.singleton(1));
276+
Table table = createTable("missing_delete_manifest", schema, PartitionSpec.unpartitioned(),
277+
Collections.singletonMap(TableProperties.FORMAT_VERSION, "2"));
278+
table.newAppend().appendFile(dataFile(table.spec(),
279+
"s3://b/db/missing_delete_manifest/f1.parquet", 1024, null, null)).commit();
280+
table.newRowDelta().addDeletes(equalityDeleteFile(
281+
"s3://b/db/missing_delete_manifest/eq.parquet", FileFormat.PARQUET, 1)).commit();
282+
String deleteManifest = table.currentSnapshot().deleteManifests(table.io()).get(0).path().toString();
283+
table.io().deleteFile(deleteManifest);
284+
IcebergScanPlanProvider provider = providerOver(table);
285+
286+
DorisConnectorException ex = Assertions.assertThrows(DorisConnectorException.class,
287+
() -> provider.getScanNodeProperties(emptySession(),
288+
new IcebergTableHandle("db1", "missing_delete_manifest"),
289+
Collections.singletonList(new IcebergColumnHandle("name", 2)), Optional.empty()));
290+
Assertions.assertTrue(ex.getMessage().contains(
291+
"Metadata not found in metadata location for table db1.missing_delete_manifest"), ex.getMessage());
292+
}
293+
228294
@Test
229295
public void planScanResolvesTableInsideAuthContext() {
230296
// The remote loadTable must sit INSIDE context.executeAuthenticated so the FE-injected Kerberos UGI
@@ -1374,6 +1440,23 @@ private static List<ConnectorScanRange> planPositionDeletes(Table table, List<Co
13741440
.build());
13751441
}
13761442

1443+
@Test
1444+
public void positionDeletesMissingManifestListHasStableTableError() {
1445+
DeleteFile deleteFile = FileMetadata.deleteFileBuilder(PartitionSpec.unpartitioned())
1446+
.ofPositionDeletes()
1447+
.withPath("s3://b/db/t1/pos-delete.parquet")
1448+
.withFileSizeInBytes(100)
1449+
.withRecordCount(1)
1450+
.build();
1451+
Table table = tableWithPositionDelete(deleteFile);
1452+
table.io().deleteFile(table.currentSnapshot().manifestListLocation());
1453+
1454+
DorisConnectorException ex = Assertions.assertThrows(DorisConnectorException.class,
1455+
() -> planPositionDeletes(table, Collections.emptyList()));
1456+
Assertions.assertTrue(ex.getMessage().contains(
1457+
"Metadata not found in metadata location for table db1.t1"), ex.getMessage());
1458+
}
1459+
13771460
@Test
13781461
public void planScanPositionDeletesEmitsNativeRangeMatchingTheBeRoutingContract() {
13791462
// WHY: this is THE contract. BE routes a range into iceberg_position_delete_sys_table_reader iff

0 commit comments

Comments
 (0)