This is an automated email from the ASF dual-hosted git repository.
yiguolei pushed a commit to branch branch-4.2
in repository https://gitbox.apache.org/repos/asf/doris.git
The following commit(s) were added to refs/heads/branch-4.2 by this push:
new 77f05b2adca branch-4.2:[fix](iceberg) Deduplicate delete manifest
reads across snapshots in expire_snapshots (#70276)
77f05b2adca is described below
commit 77f05b2adca6a649de0ad8559f91e1f2a2530c58
Author: daidai <[email protected]>
AuthorDate: Tue Nov 24 15:33:14 2026 +0800
branch-4.2:[fix](iceberg) Deduplicate delete manifest reads across
snapshots in expire_snapshots (#70276)
### What problem does this PR solve?
Issue Number: N/A
Related PR: #64304
Problem Summary:
On branch-4.2, `expire_snapshots` reads each snapshot's delete manifests
before classifying deleted files. Adjacent snapshots can share an
immutable manifest, so the same manifest is opened and decoded
repeatedly. The existing `putIfAbsent` only deduplicates the resulting
delete-file entries.
Track manifest paths within each `buildDeleteFileContentMap` call and
read each distinct delete manifest once. This adapts the existing master
optimization to the legacy FE implementation without bringing over the
connector migration. Classification still uses the table's spec map, and
read failures still abort the operation.
### Release note
Reduce redundant delete manifest reads when expiring Iceberg snapshots.
### Check List (For Author)
- Test
- [ ] Regression test
- [x] Unit Test: `IcebergExpireSnapshotsActionTest`,
`BaseIcebergActionTest`, and `IcebergSnapshotMaintenanceCoverageTest`
via `run-fe-ut.sh --run`: 11 passed, 2 pre-existing disabled
stale-metadata tests skipped, 0 failures.
- [ ] Manual test (add detailed scripts or steps below)
- [ ] No need to test or manual test. Explain why:
- [ ] This is a refactor/code format and no logic has been changed.
- [ ] Previous test can cover this change.
- [ ] No code files have been changed.
- [ ] Other reason
The new shared-manifest test fails before the fix (an input stream opens
3 times instead of 1) and passes after it. The tests count actual
input-stream opens, cover position/equality deletes across partition
specs, preserve the exact classification map, and check repeated calls
and read-failure propagation. Both changed Java files pass Checkstyle.
No SQL regression was added because the optimization preserves SQL
results; the I/O reduction is asserted at the FileIO boundary.
- Behavior changed:
- [ ] No.
- [x] Yes. Shared delete manifests are read once per classification
call; file classification and cleanup semantics are preserved.
- Does this need documentation?
- [x] No.
- [ ] Yes.
### Check List (For Reviewer who merge this PR)
- [ ] Confirm the release note
- [ ] Confirm test cases
- [ ] Confirm document
- [ ] Add branch pick label
---
.../action/IcebergExpireSnapshotsAction.java | 11 +-
.../action/IcebergExpireSnapshotsActionTest.java | 183 +++++++++++++++++++++
2 files changed, 193 insertions(+), 1 deletion(-)
diff --git
a/fe/fe-core/src/main/java/org/apache/doris/datasource/iceberg/action/IcebergExpireSnapshotsAction.java
b/fe/fe-core/src/main/java/org/apache/doris/datasource/iceberg/action/IcebergExpireSnapshotsAction.java
index 00f216bd3fa..024cf981d0a 100644
---
a/fe/fe-core/src/main/java/org/apache/doris/datasource/iceberg/action/IcebergExpireSnapshotsAction.java
+++
b/fe/fe-core/src/main/java/org/apache/doris/datasource/iceberg/action/IcebergExpireSnapshotsAction.java
@@ -29,6 +29,7 @@ import org.apache.doris.datasource.iceberg.IcebergMetadataOps;
import org.apache.doris.info.PartitionNamesInfo;
import org.apache.doris.nereids.trees.expressions.Expression;
+import com.google.common.annotations.VisibleForTesting;
import com.google.common.collect.Lists;
import org.apache.iceberg.DeleteFile;
import org.apache.iceberg.ExpireSnapshots;
@@ -46,9 +47,11 @@ import java.time.ZoneId;
import java.time.format.DateTimeFormatter;
import java.time.format.DateTimeParseException;
import java.util.HashMap;
+import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Optional;
+import java.util.Set;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.atomic.AtomicLong;
@@ -273,8 +276,11 @@ public class IcebergExpireSnapshotsAction extends
BaseIcebergAction {
}
}
- private Map<String, FileContent> buildDeleteFileContentMap(Table
icebergTable) throws UserException {
+ @VisibleForTesting
+ Map<String, FileContent> buildDeleteFileContentMap(Table icebergTable)
throws UserException {
Map<String, FileContent> deleteFileContentByPath = new HashMap<>();
+ // Snapshots share immutable delete manifests; read each path once
within this call.
+ Set<String> visitedDeleteManifests = new HashSet<>();
try {
for (org.apache.iceberg.Snapshot snapshot :
icebergTable.snapshots()) {
List<ManifestFile> deleteManifests =
snapshot.deleteManifests(icebergTable.io());
@@ -282,6 +288,9 @@ public class IcebergExpireSnapshotsAction extends
BaseIcebergAction {
continue;
}
for (ManifestFile manifest : deleteManifests) {
+ if (!visitedDeleteManifests.add(manifest.path())) {
+ continue;
+ }
try (CloseableIterable<DeleteFile> deleteFiles =
ManifestFiles.readDeleteManifest(
manifest, icebergTable.io(),
icebergTable.specs())) {
for (DeleteFile deleteFile : deleteFiles) {
diff --git
a/fe/fe-core/src/test/java/org/apache/doris/datasource/iceberg/action/IcebergExpireSnapshotsActionTest.java
b/fe/fe-core/src/test/java/org/apache/doris/datasource/iceberg/action/IcebergExpireSnapshotsActionTest.java
new file mode 100644
index 00000000000..7fe332ab35b
--- /dev/null
+++
b/fe/fe-core/src/test/java/org/apache/doris/datasource/iceberg/action/IcebergExpireSnapshotsActionTest.java
@@ -0,0 +1,183 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements. See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership. The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License. You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied. See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+package org.apache.doris.datasource.iceberg.action;
+
+import org.apache.doris.common.UserException;
+import org.apache.doris.datasource.iceberg.IcebergMetadataOps;
+
+import com.google.common.base.Throwables;
+import com.google.common.collect.ImmutableMap;
+import org.apache.iceberg.DataFiles;
+import org.apache.iceberg.FileContent;
+import org.apache.iceberg.FileFormat;
+import org.apache.iceberg.FileMetadata;
+import org.apache.iceberg.ManifestFile;
+import org.apache.iceberg.PartitionSpec;
+import org.apache.iceberg.Schema;
+import org.apache.iceberg.Snapshot;
+import org.apache.iceberg.Table;
+import org.apache.iceberg.catalog.Namespace;
+import org.apache.iceberg.catalog.TableIdentifier;
+import org.apache.iceberg.inmemory.InMemoryCatalog;
+import org.apache.iceberg.io.FileIO;
+import org.apache.iceberg.io.InputFile;
+import org.apache.iceberg.types.Types;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.mockito.Mockito;
+
+import java.io.IOException;
+import java.io.UncheckedIOException;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Optional;
+import java.util.Set;
+
+public class IcebergExpireSnapshotsActionTest {
+ private InMemoryCatalog catalog;
+ private Table table;
+ private IcebergExpireSnapshotsAction action;
+ private boolean failNextRead;
+ private final IOException readFailure = new IOException("injected manifest
read failure");
+
+ @BeforeEach
+ public void setUp() {
+ catalog = new InMemoryCatalog();
+ catalog.initialize("expiration", Collections.emptyMap());
+ catalog.createNamespace(Namespace.of("db1"));
+ table = catalog.createTable(TableIdentifier.of("db1", "expiration"),
new Schema(
+ Types.NestedField.required(1, "id", Types.IntegerType.get())),
+ PartitionSpec.unpartitioned(),
Collections.singletonMap("format-version", "2"));
+ action = new IcebergExpireSnapshotsAction(Collections.emptyMap(),
Optional.empty(), Optional.empty(),
+ Mockito.mock(IcebergMetadataOps.class));
+ }
+
+ @AfterEach
+ public void tearDown() throws IOException {
+ catalog.close();
+ }
+
+ @Test
+ public void readsSharedDeleteManifestsOncePerCallAcrossPartitionSpecs()
throws Exception {
+ appendBaseFile();
+
table.newRowDelta().addDeletes(FileMetadata.deleteFileBuilder(table.spec()).ofPositionDeletes()
+
.withPath("s3://b/db1/position-delete.parquet").withReferencedDataFile("s3://b/db1/base.parquet")
+
.withFileSizeInBytes(64).withRecordCount(1).withFormat(FileFormat.PARQUET).build()).commit();
+
+ table.updateSpec().addField("id").commit();
+ appendPartitionedFile("partitioned.parquet");
+
table.newRowDelta().addDeletes(FileMetadata.deleteFileBuilder(table.spec()).ofEqualityDeletes(1)
+
.withPath("s3://b/db1/equality-delete.parquet").withPartitionPath("id=1")
+
.withFileSizeInBytes(64).withRecordCount(1).withFormat(FileFormat.PARQUET).build()).commit();
+ appendPartitionedFile("next.parquet");
+ appendPartitionedFile("last.parquet");
+
+ Set<String> manifestPaths = new HashSet<>();
+ Set<Integer> specIds = new HashSet<>();
+ int manifestReferences = 0;
+ for (Snapshot snapshot : table.snapshots()) {
+ for (ManifestFile manifest : snapshot.deleteManifests(table.io()))
{
+ manifestPaths.add(manifest.path());
+ specIds.add(manifest.partitionSpecId());
+ manifestReferences++;
+ }
+ }
+ Assertions.assertTrue(manifestReferences > manifestPaths.size(),
"snapshots must share delete manifests");
+ Assertions.assertEquals(2, specIds.size(), "both partition specs must
have delete manifests");
+
+ Map<String, Integer> streamOpens = new HashMap<>();
+ Table recordedTable = recordManifestOpens(streamOpens);
+ Map<String, FileContent> expected = ImmutableMap.of(
+ "s3://b/db1/position-delete.parquet",
FileContent.POSITION_DELETES,
+ "s3://b/db1/equality-delete.parquet",
FileContent.EQUALITY_DELETES);
+ Assertions.assertEquals(expected,
action.buildDeleteFileContentMap(recordedTable));
+ Assertions.assertEquals(manifestPaths, streamOpens.keySet());
+ for (String path : manifestPaths) {
+ Assertions.assertEquals(1, streamOpens.get(path).intValue(), path);
+ }
+
+ Assertions.assertEquals(expected,
action.buildDeleteFileContentMap(recordedTable));
+ for (String path : manifestPaths) {
+ Assertions.assertEquals(2, streamOpens.get(path).intValue(), "a
new call must reopen " + path);
+ }
+ }
+
+ @Test
+ public void handlesTablesWithoutSnapshotsOrDeleteManifests() throws
Exception {
+ Map<String, Integer> streamOpens = new HashMap<>();
+
Assertions.assertTrue(action.buildDeleteFileContentMap(recordManifestOpens(streamOpens)).isEmpty());
+ appendBaseFile();
+
Assertions.assertTrue(action.buildDeleteFileContentMap(recordManifestOpens(streamOpens)).isEmpty());
+ Assertions.assertTrue(streamOpens.isEmpty());
+ }
+
+ @Test
+ public void propagatesReadFailuresAndReopensTheManifestOnRetry() throws
Exception {
+ appendBaseFile();
+
table.newRowDelta().addDeletes(FileMetadata.deleteFileBuilder(table.spec()).ofEqualityDeletes(1)
+ .withPath("s3://b/db1/equality-delete.parquet")
+
.withFileSizeInBytes(64).withRecordCount(1).withFormat(FileFormat.PARQUET).build()).commit();
+ Map<String, Integer> streamOpens = new HashMap<>();
+ Table recordedTable = recordManifestOpens(streamOpens);
+ failNextRead = true;
+
+ UserException failure = Assertions.assertThrows(UserException.class,
+ () -> action.buildDeleteFileContentMap(recordedTable));
+ Assertions.assertTrue(failure.getMessage().contains("Failed to build
delete file content map"));
+ Assertions.assertSame(readFailure, Throwables.getRootCause(failure));
+
Assertions.assertEquals(ImmutableMap.of("s3://b/db1/equality-delete.parquet",
FileContent.EQUALITY_DELETES),
+ action.buildDeleteFileContentMap(recordedTable));
+ Assertions.assertEquals(1, streamOpens.size());
+ Assertions.assertEquals(2,
streamOpens.values().iterator().next().intValue());
+ }
+
+ private void appendBaseFile() {
+
table.newAppend().appendFile(DataFiles.builder(table.spec()).withPath("s3://b/db1/base.parquet")
+
.withFileSizeInBytes(64).withRecordCount(1).withFormat(FileFormat.PARQUET).build()).commit();
+ }
+
+ private void appendPartitionedFile(String name) {
+
table.newAppend().appendFile(DataFiles.builder(table.spec()).withPath("s3://b/db1/"
+ name)
+ .withPartitionPath("id=1").withFileSizeInBytes(64)
+
.withRecordCount(1).withFormat(FileFormat.PARQUET).build()).commit();
+ }
+
+ private Table recordManifestOpens(Map<String, Integer> streamOpens) {
+ FileIO recordingIo = Mockito.spy(table.io());
+ Mockito.doAnswer(invocation -> {
+ InputFile input =
table.io().newInputFile(invocation.getArgument(0, ManifestFile.class));
+ InputFile recordingInput = Mockito.spy(input);
+ Mockito.doAnswer(open -> {
+ streamOpens.merge(input.location(), 1, Integer::sum);
+ if (failNextRead) {
+ failNextRead = false;
+ throw new UncheckedIOException(readFailure);
+ }
+ return input.newStream();
+ }).when(recordingInput).newStream();
+ return recordingInput;
+ }).when(recordingIo).newInputFile(Mockito.any(ManifestFile.class));
+ Table recordedTable = Mockito.spy(table);
+ Mockito.doReturn(recordingIo).when(recordedTable).io();
+ return recordedTable;
+ }
+}
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]