Skip to content

Commit

Permalink
Enabling native hfile reader for SI to avoid NPE on deletes
Browse files Browse the repository at this point in the history
  • Loading branch information
vinothchandar committed Nov 14, 2024
1 parent 8d4fe25 commit ba8dd8d
Showing 1 changed file with 3 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
import org.apache.hudi.avro.HoodieAvroUtils;
import org.apache.hudi.avro.model.HoodieMetadataRecord;
import org.apache.hudi.common.config.HoodieCommonConfig;
import org.apache.hudi.common.config.HoodieConfig;
import org.apache.hudi.common.config.HoodieMetadataConfig;
import org.apache.hudi.common.data.HoodieData;
import org.apache.hudi.common.data.HoodieListData;
Expand Down Expand Up @@ -78,7 +77,6 @@
import java.util.stream.Collectors;

import static org.apache.hudi.common.config.HoodieMetadataConfig.DEFAULT_METADATA_ENABLE_FULL_SCAN_LOG_FILES;
import static org.apache.hudi.common.config.HoodieReaderConfig.USE_NATIVE_HFILE_READER;
import static org.apache.hudi.common.util.CollectionUtils.toStream;
import static org.apache.hudi.common.util.ConfigUtils.DEFAULT_HUDI_CONFIG_FOR_READER;
import static org.apache.hudi.common.util.ValidationUtils.checkState;
Expand Down Expand Up @@ -584,10 +582,7 @@ private Pair<HoodieSeekingFileReader<?>, HoodieMetadataLogRecordReader> openRead
try {
HoodieTimer timer = HoodieTimer.start();
// Open base file reader
// If the partition is a secondary index partition, use the HBase HFile reader instead of native HFile reader.
// TODO (HUDI-7831): Support reading secondary index records using native HFile reader.
boolean shouldUseNativeHFileReader = !partitionName.startsWith(HoodieTableMetadataUtil.PARTITION_NAME_SECONDARY_INDEX_PREFIX);
Pair<HoodieSeekingFileReader<?>, Long> baseFileReaderOpenTimePair = getBaseFileReader(slice, timer, shouldUseNativeHFileReader);
Pair<HoodieSeekingFileReader<?>, Long> baseFileReaderOpenTimePair = getBaseFileReader(slice, timer);
HoodieSeekingFileReader<?> baseFileReader = baseFileReaderOpenTimePair.getKey();
final long baseFileOpenMs = baseFileReaderOpenTimePair.getValue();

Expand All @@ -606,20 +601,16 @@ private Pair<HoodieSeekingFileReader<?>, HoodieMetadataLogRecordReader> openRead
}
}

private Pair<HoodieSeekingFileReader<?>, Long> getBaseFileReader(FileSlice slice, HoodieTimer timer, boolean shouldUseNativeHFileReader) throws IOException {
private Pair<HoodieSeekingFileReader<?>, Long> getBaseFileReader(FileSlice slice, HoodieTimer timer) throws IOException {
HoodieSeekingFileReader<?> baseFileReader;
long baseFileOpenMs;
// If the base file is present then create a reader
Option<HoodieBaseFile> baseFile = slice.getBaseFile();
if (baseFile.isPresent()) {
StoragePath baseFilePath = baseFile.get().getStoragePath();
HoodieConfig readerConfig = DEFAULT_HUDI_CONFIG_FOR_READER;
if (!shouldUseNativeHFileReader) {
readerConfig.setValue(USE_NATIVE_HFILE_READER, "false");
}
baseFileReader = (HoodieSeekingFileReader<?>) HoodieIOFactory.getIOFactory(metadataMetaClient.getStorage())
.getReaderFactory(HoodieRecordType.AVRO)
.getFileReader(readerConfig, baseFilePath);
.getFileReader(DEFAULT_HUDI_CONFIG_FOR_READER, baseFilePath);
baseFileOpenMs = timer.endTimer();
LOG.info(String.format("Opened metadata base file from %s at instant %s in %d ms", baseFilePath,
baseFile.get().getCommitTime(), baseFileOpenMs));
Expand Down

0 comments on commit ba8dd8d

Please sign in to comment.