the-other-tim-brown commented on code in PR #13602:
URL: https://github.com/apache/hudi/pull/13602#discussion_r2226968453
##########
hudi-common/src/main/java/org/apache/hudi/common/table/read/FileGroupRecordBuffer.java:
##########
@@ -135,6 +129,16 @@ protected FileGroupRecordBuffer(HoodieReaderContext<T>
readerContext,
readerContext, recordMergeMode, enablePartialMerging, recordMerger,
orderingFieldName, payloadClass, readerSchema, props, partialUpdateMode);
}
+ protected ExternalSpillableMap<Serializable, BufferedRecord<T>>
initializeRecordsMap(String spillableMapBasePath) throws IOException {
Review Comment:
This change allows the ReusableKeyBasedRecordBuffer to skip this step
##########
hudi-common/src/main/java/org/apache/hudi/common/table/read/FileGroupRecordBufferInitializer.java:
##########
@@ -0,0 +1,176 @@
+/*
+ * 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.HoodieMemoryConfig;
+import org.apache.hudi.common.config.HoodieReaderConfig;
+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.PartialUpdateMode;
+import org.apache.hudi.common.table.log.HoodieMergedLogRecordReader;
+import org.apache.hudi.common.util.ConfigUtils;
+import org.apache.hudi.common.util.Option;
+import org.apache.hudi.common.util.collection.Pair;
+import org.apache.hudi.storage.HoodieStorage;
+
+import java.io.Closeable;
+import java.util.List;
+
+import static org.apache.hudi.common.util.ConfigUtils.getIntWithAltKeys;
+
+/**
+ * This interface defines the contract for initializing a {@link
FileGroupRecordBuffer} for a given file group.
+ * The implementation is expected to establish the record buffer and populate
it with the records from the log files.
+ * @param <T> the engine specific record type
+ */
+public interface FileGroupRecordBufferInitializer<T> {
Review Comment:
This is the largest change of the PR. The initializer is responsible for
creating the record buffer and loading it with any records. This may be useful
for the MergeHandle changes as well.
Also I am very open to any suggestions on naming, I truly dislike this part
of coding 😅
##########
hudi-common/src/main/java/org/apache/hudi/avro/HoodieAvroReaderContext.java:
##########
@@ -69,15 +70,26 @@
*/
public class HoodieAvroReaderContext extends
HoodieReaderContext<IndexedRecord> {
private final String payloadClass;
+ private final Map<StoragePath, HoodieAvroFileReader> reusableFileReaders;
Review Comment:
This is an optional cache of readers, this is only used by the
HoodieBackedTableMetadata right now
##########
hudi-client/hudi-spark-client/src/test/java/org/apache/hudi/client/functional/TestHoodieBackedTableMetadata.java:
##########
@@ -133,55 +133,55 @@ public void testTableOperations(boolean reuseReaders, int
tableVersion) throws E
@ParameterizedTest
@CsvSource({"true,6", "true,8", "false,6", "false,8"})
public void testMultiReaderForHoodieBackedTableMetadata(boolean reuse, int
tableVersion) throws Exception {
- final int taskNumber = 3;
+ final int taskNumber = 6;
Review Comment:
Test is updated to ensure more possibility for threads overlapping with each
other and to make the correctness assertions more interesting.
##########
hudi-common/src/main/java/org/apache/hudi/common/table/read/ReusableKeyBasedRecordBuffer.java:
##########
@@ -0,0 +1,186 @@
+/*
+ * 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.Predicate;
+import org.apache.hudi.expression.Predicates;
+
+import java.io.IOException;
+import java.io.Serializable;
+import java.util.Collections;
+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) {
+ this(readerContext, hoodieTableMetaClient, recordMergeMode,
partialUpdateMode, props, orderingFieldName, updateProcessor, records,
Collections.emptySet());
+ }
+
+ private ReusableKeyBasedRecordBuffer(HoodieReaderContext<T> readerContext,
HoodieTableMetaClient hoodieTableMetaClient,
+ RecordMergeMode recordMergeMode,
PartialUpdateMode partialUpdateMode,
+ TypedProperties props, Option<String>
orderingFieldName,
+ UpdateProcessor<T> updateProcessor,
Map<Serializable, BufferedRecord<T>> records, Set<String> validKeys) {
+ super(readerContext, hoodieTableMetaClient, recordMergeMode,
partialUpdateMode, props, orderingFieldName, updateProcessor);
+ this.existingRecords = records;
+ this.validKeys = validKeys;
+ }
+
+ public ReusableKeyBasedRecordBuffer<T> withKeyPredicate(Option<Predicate>
keyFilter) {
+ ValidationUtils.checkArgument(keyFilter.get() instanceof Predicates.In, ()
-> "Key filter should be of type Predicates.In, but found: " +
keyFilter.get().getClass().getName());
+ List<Expression> children = ((Predicates.In)
keyFilter.get()).getRightChildren();
+ Set<String> validKeys = children.stream().map(e -> (String)
e.eval(null)).collect(Collectors.toSet());
+ return new ReusableKeyBasedRecordBuffer<>(readerContext,
hoodieTableMetaClient, recordMergeMode, partialUpdateMode,
+ props, orderingFieldName, updateProcessor, existingRecords, validKeys);
+ }
+
+ @Override
+ protected ExternalSpillableMap<Serializable, BufferedRecord<T>>
initializeRecordsMap(String spillableMapBasePath) {
+ return (ExternalSpillableMap<Serializable, BufferedRecord<T>>)
existingRecords;
+ }
+
+ @Override
+ protected void initializeLogRecordIterator() {
+ logRecordIterator = new RemainingRecordIterator<>(validKeys,
existingRecords);
Review Comment:
In the standard key based record buffer, we will iterate through the
remaining keys to process records that are only present in the log files. This
record buffer will filter those based on the key filter.
--
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]