JingsongLi commented on code in PR #8357: URL: https://github.com/apache/paimon/pull/8357#discussion_r3475174399
########## paimon-core/src/main/java/org/apache/paimon/operation/ManifestEntryExternalSort.java: ########## @@ -0,0 +1,281 @@ +/* + * 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.paimon.operation; + +import org.apache.paimon.CoreOptions; +import org.apache.paimon.codegen.CodeGenUtils; +import org.apache.paimon.codegen.RecordComparator; +import org.apache.paimon.compression.CompressOptions; +import org.apache.paimon.data.BinaryRow; +import org.apache.paimon.disk.IOManager; +import org.apache.paimon.io.RollingFileWriter; +import org.apache.paimon.manifest.FileEntry; +import org.apache.paimon.manifest.FileKind; +import org.apache.paimon.manifest.ManifestEntry; +import org.apache.paimon.manifest.ManifestEntrySerializer; +import org.apache.paimon.manifest.ManifestFile; +import org.apache.paimon.manifest.ManifestFileMeta; +import org.apache.paimon.options.MemorySize; +import org.apache.paimon.sort.BinaryExternalSortBuffer; +import org.apache.paimon.utils.MutableObjectIterator; +import org.apache.paimon.utils.Pair; + +import javax.annotation.Nullable; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.Collections; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.function.Function; + +import static org.apache.paimon.utils.ManifestReadThreadPool.sequentialBatchedExecute; + +/** Spillable external sort utilities for manifest entries. */ +public class ManifestEntryExternalSort { + + static Pair<List<ManifestFileMeta>, List<ManifestFileMeta>> sortAndWriteMinorEntries( + List<ManifestFileMeta> section, + ManifestFileSorter.ManifestSortKey sortKey, + ExternalSortConfig config, + ManifestFile manifestFile, + @Nullable Integer manifestReadParallelism) + throws Exception { + try (EntrySorter sorter = new EntrySorter(sortKey, config)) { + Map<FileEntry.Identifier, ManifestEntry> deleteEntries = new HashMap<>(); + Function<ManifestFileMeta, List<ManifestEntry>> reader = + meta -> manifestFile.read(meta.fileName(), meta.fileSize()); + for (ManifestEntry entry : + sequentialBatchedExecute(reader, section, manifestReadParallelism)) { + sorter.write(entry); Review Comment: In the minor-compaction path, DELETE entries are also inserted into the external sorter, but `writeSurvivingAddsToManifest` later skips every DELETE row and the remaining deletes are sorted/written from `deleteEntries`. For delete-heavy manifests this duplicates serialization and spill IO. Could we feed only ADD entries into the external sorter and keep DELETE entries only in the map? -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
