nsivabalan commented on code in PR #13602: URL: https://github.com/apache/hudi/pull/13602#discussion_r2228748934
########## hudi-common/src/main/java/org/apache/hudi/common/table/read/ReusableKeyBasedRecordBuffer.java: ########## @@ -0,0 +1,164 @@ +/* + * 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; + +import org.apache.hudi.common.config.RecordMergeMode; +import org.apache.hudi.common.config.TypedProperties; +import org.apache.hudi.common.engine.HoodieReaderContext; +import org.apache.hudi.common.model.DeleteRecord; +import org.apache.hudi.common.table.HoodieTableMetaClient; +import org.apache.hudi.common.table.PartialUpdateMode; +import org.apache.hudi.common.table.log.KeySpec; +import org.apache.hudi.common.table.log.block.HoodieDataBlock; +import org.apache.hudi.common.table.log.block.HoodieDeleteBlock; +import org.apache.hudi.common.util.Option; +import org.apache.hudi.common.util.ValidationUtils; +import org.apache.hudi.common.util.collection.ExternalSpillableMap; +import org.apache.hudi.expression.Expression; +import org.apache.hudi.expression.Predicates; + +import java.io.IOException; +import java.io.Serializable; +import java.util.Iterator; +import java.util.List; +import java.util.Map; +import java.util.Set; +import java.util.stream.Collectors; + +/** + * A {@link HoodieFileGroupRecordBuffer<T>} implementation that allows the user to create a record buffer with an existing mapping of key to latest record from the log files. + * The implementation is used when point lookups are required for the same file group, such as the metadata table's files partition. + * As a result, the buffer also requires a set of valid keys to be provided to avoid returning all records in the processed logs when doing these point or small-batch lookups. + * @param <T> the engine specific record type + */ +public class ReusableKeyBasedRecordBuffer<T> extends FileGroupRecordBuffer<T> { + private final Set<String> validKeys; + private final Map<Serializable, BufferedRecord<T>> existingRecords; Review Comment: Don't we want to keep this as ExternalSpillableMap ? ########## hudi-common/src/main/java/org/apache/hudi/metadata/HoodieBackedTableMetadata.java: ########## @@ -116,6 +122,8 @@ public class HoodieBackedTableMetadata extends BaseTableMetadata { private HoodieTableFileSystemView metadataFileSystemView; // should we reuse the open file handles, across calls private final boolean reuse; + private final transient Map<HoodieFileGroupId, Pair<HoodieAvroFileReader, FileGroupRecordBufferInitializer.ReusableFileGroupRecordBufferInitializer<IndexedRecord>>> reusableFileReaders Review Comment: for my question elsewhere on fixing base file reusability, is this how we are fixing it? but are we reseeking to the beginning of the file before every new call? ########## hudi-common/src/main/java/org/apache/hudi/common/table/read/HoodieFileGroupReader.java: ########## @@ -199,7 +154,10 @@ private void initRecordIterators() throws IOException { this.baseFileIterator = new CloseableMappingIterator<>(iter, readerContext::seal); } else { this.baseFileIterator = iter; - scanLogFiles(); + Pair<FileGroupRecordBuffer<T>, List<String>> intializationResult = recordBufferInitializer.getRecordBuffer( + readerContext, storage, inputSplit, orderingFieldName, metaClient, props, readerParameters, readStats, fileGroupUpdateCallback); + recordBuffer = intializationResult.getLeft(); + validBlockInstants = intializationResult.getRight(); recordBuffer.setBaseFileIterator(baseFileIterator); Review Comment: from what I heard, we found a gap wrt reusing base files properly. lets ensure we have a tracking ticket and is marked as blocker for 1.1 ########## hudi-common/src/main/java/org/apache/hudi/common/table/read/ReusableKeyBasedRecordBuffer.java: ########## @@ -0,0 +1,164 @@ +/* + * 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; + +import org.apache.hudi.common.config.RecordMergeMode; +import org.apache.hudi.common.config.TypedProperties; +import org.apache.hudi.common.engine.HoodieReaderContext; +import org.apache.hudi.common.model.DeleteRecord; +import org.apache.hudi.common.table.HoodieTableMetaClient; +import org.apache.hudi.common.table.PartialUpdateMode; +import org.apache.hudi.common.table.log.KeySpec; +import org.apache.hudi.common.table.log.block.HoodieDataBlock; +import org.apache.hudi.common.table.log.block.HoodieDeleteBlock; +import org.apache.hudi.common.util.Option; +import org.apache.hudi.common.util.ValidationUtils; +import org.apache.hudi.common.util.collection.ExternalSpillableMap; +import org.apache.hudi.expression.Expression; +import org.apache.hudi.expression.Predicates; + +import java.io.IOException; +import java.io.Serializable; +import java.util.Iterator; +import java.util.List; +import java.util.Map; +import java.util.Set; +import java.util.stream.Collectors; + +/** + * A {@link HoodieFileGroupRecordBuffer<T>} implementation that allows the user to create a record buffer with an existing mapping of key to latest record from the log files. + * The implementation is used when point lookups are required for the same file group, such as the metadata table's files partition. + * As a result, the buffer also requires a set of valid keys to be provided to avoid returning all records in the processed logs when doing these point or small-batch lookups. + * @param <T> the engine specific record type + */ +public class ReusableKeyBasedRecordBuffer<T> extends FileGroupRecordBuffer<T> { + private final Set<String> validKeys; + private final Map<Serializable, BufferedRecord<T>> existingRecords; + + ReusableKeyBasedRecordBuffer(HoodieReaderContext<T> readerContext, HoodieTableMetaClient hoodieTableMetaClient, + RecordMergeMode recordMergeMode, PartialUpdateMode partialUpdateMode, + TypedProperties props, Option<String> orderingFieldName, + UpdateProcessor<T> updateProcessor, Map<Serializable, BufferedRecord<T>> records) { + super(readerContext, hoodieTableMetaClient, recordMergeMode, partialUpdateMode, props, orderingFieldName, updateProcessor); + this.existingRecords = records; + ValidationUtils.checkArgument(readerContext.getKeyFilterOpt().orElse(null) instanceof Predicates.In, + () -> "Key filter should be of type Predicates.In, but found: " + readerContext.getKeyFilterOpt().map(filter -> filter.getClass().getSimpleName()).orElse("NULL")); Review Comment: I have a outdated version of this patch w/o your latest commit. was about to comment on the keyPredicate method which was creating new instance of ReusableKeyBasedRecordBuffer everytime. Looks like you just happened to fix that. ########## hudi-common/src/main/java/org/apache/hudi/common/table/read/ReusableKeyBasedRecordBuffer.java: ########## @@ -0,0 +1,164 @@ +/* + * 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; + +import org.apache.hudi.common.config.RecordMergeMode; +import org.apache.hudi.common.config.TypedProperties; +import org.apache.hudi.common.engine.HoodieReaderContext; +import org.apache.hudi.common.model.DeleteRecord; +import org.apache.hudi.common.table.HoodieTableMetaClient; +import org.apache.hudi.common.table.PartialUpdateMode; +import org.apache.hudi.common.table.log.KeySpec; +import org.apache.hudi.common.table.log.block.HoodieDataBlock; +import org.apache.hudi.common.table.log.block.HoodieDeleteBlock; +import org.apache.hudi.common.util.Option; +import org.apache.hudi.common.util.ValidationUtils; +import org.apache.hudi.common.util.collection.ExternalSpillableMap; +import org.apache.hudi.expression.Expression; +import org.apache.hudi.expression.Predicates; + +import java.io.IOException; +import java.io.Serializable; +import java.util.Iterator; +import java.util.List; +import java.util.Map; +import java.util.Set; +import java.util.stream.Collectors; + +/** + * A {@link HoodieFileGroupRecordBuffer<T>} implementation that allows the user to create a record buffer with an existing mapping of key to latest record from the log files. + * The implementation is used when point lookups are required for the same file group, such as the metadata table's files partition. + * As a result, the buffer also requires a set of valid keys to be provided to avoid returning all records in the processed logs when doing these point or small-batch lookups. + * @param <T> the engine specific record type + */ +public class ReusableKeyBasedRecordBuffer<T> extends FileGroupRecordBuffer<T> { + private final Set<String> validKeys; + private final Map<Serializable, BufferedRecord<T>> existingRecords; Review Comment: Essentially, should we make `HoodieFileGroupRecordBuffer.getLogRecords()` should return ExternalSpillableMap instead of regular map so that there won't be any mis-use of the returned 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]
