yihua commented on code in PR #13670: URL: https://github.com/apache/hudi/pull/13670#discussion_r2250269572
########## hudi-common/src/main/java/org/apache/hudi/common/table/read/buffer/RecordsBasedFileGroupRecordBufferLoader.java: ########## @@ -0,0 +1,85 @@ +/* + * 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.hudi.common.table.read.buffer; + +import org.apache.hudi.common.config.TypedProperties; +import org.apache.hudi.common.engine.HoodieReaderContext; +import org.apache.hudi.common.table.HoodieTableMetaClient; +import org.apache.hudi.common.table.read.BaseFileUpdateCallback; +import org.apache.hudi.common.table.read.BufferedRecord; +import org.apache.hudi.common.table.read.HoodieReadStats; +import org.apache.hudi.common.table.read.InputSplit; +import org.apache.hudi.common.table.read.ReaderParameters; +import org.apache.hudi.common.util.Option; +import org.apache.hudi.common.util.collection.Pair; +import org.apache.hudi.exception.HoodieIOException; +import org.apache.hudi.storage.HoodieStorage; + +import java.io.IOException; +import java.io.Serializable; +import java.util.Collections; +import java.util.List; +import java.util.Map; + +/** + * Records based {@link FileGroupRecordBuffer} which takes in a map of records to be merged with a base file of interest. + * This will be used in write paths for COW merge cases. + * @param <T> Engine native presentation of the record. + */ +public class RecordsBasedFileGroupRecordBufferLoader<T> extends DefaultFileGroupRecordBufferLoader<T> { + + private final Map<Serializable, BufferedRecord<T>> toBeMergedRecords; + + private RecordsBasedFileGroupRecordBufferLoader(Map<Serializable, BufferedRecord<T>> toBeMergedRecords) { + super(); + this.toBeMergedRecords = toBeMergedRecords; Review Comment: +1 on using `Iterator<Pair<String, BufferedRecord<T>>`. `keyToNewRecords` is more of a implementation detail in the current way of how the merge handle is implemented. I think the reason is that historically the merge handle takes care of both COW merge and MOR compaction where the MOR compaction uses a separate constructor which takes `keyToNewRecords` directly. Now that MOR compaction completely relies on the file group reader-based logic in a separate merge handle class `FileGroupReaderBasedMergeHandle`, the "write" merge handle `HoodieWriteMergeHandle` should only take an iterator of records as the input. And this record buffer loader can directly take the iterator of records and does the merging inside the loader (i.e., such a logic below can be migrated from the merge handle to the buffer loader class), so that the merge handle can handle write logic only, which look better in terms of single responsibility of classes. ``` protected void populateIncomingRecordsMap(Iterator<HoodieRecord<T>> newRecordsItr) { initIncomingRecordsMap(); while (newRecordsItr.hasNext()) { HoodieRecord<T> record = newRecordsItr.next(); // update the new location of the record, so we know where to find it next if (needsUpdateLocation()) { record.unseal(); record.setNewLocation(newRecordLocation); record.seal(); } // NOTE: Once Records are added to map (spillable-map), DO NOT change it as they won't persist keyToNewRecords.put(record.getRecordKey(), record); } if (keyToNewRecords instanceof ExternalSpillableMap) { ExternalSpillableMap<String, HoodieRecord<T>> spillableMap = (ExternalSpillableMap<String, HoodieRecord<T>>) keyToNewRecords; LOG.info("Number of entries in MemoryBasedMap => {}, Total size in bytes of MemoryBasedMap => {}, " + "Number of entries in BitCaskDiskMap => {}, Size of file spilled to disk => {}", spillableMap.getInMemoryMapNumEntries(), spillableMap.getCurrentInMemoryMapSize(), spillableMap.getDiskBasedMapNumEntries(), spillableMap.getSizeOfFileOnDiskInBytes()); } } ``` -- 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]
