Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.hbase.CellComparatorImpl;
import org.apache.hadoop.hbase.io.hfile.CacheConfig;
import org.apache.hadoop.hbase.io.hfile.HFile;
import org.apache.hudi.common.bootstrap.index.HFileBootstrapIndex;
import org.apache.hudi.common.engine.TaskContextSupplier;
Expand Down Expand Up @@ -113,22 +112,21 @@ protected HoodieAvroHFileWriter createWriter(
@Override
protected HoodieAvroFileReader createReader(
Configuration conf) throws Exception {
CacheConfig cacheConfig = new CacheConfig(conf);
return new HoodieAvroHFileReader(conf, getFilePath(), cacheConfig, getFilePath().getFileSystem(conf), Option.empty());
return new HoodieAvroHFileReader(conf, getFilePath(), getFilePath().getFileSystem(conf), Option.empty());
}

@Override
protected void verifyMetadata(Configuration conf) throws IOException {
FileSystem fs = getFilePath().getFileSystem(conf);
HFile.Reader hfileReader = HoodieHFileUtils.createHFileReader(fs, getFilePath(), new CacheConfig(conf), conf);
HFile.Reader hfileReader = HoodieHFileUtils.createHFileReader(fs, getFilePath(), conf);
assertEquals(HFILE_COMPARATOR.getClass(), hfileReader.getComparator().getClass());
assertEquals(NUM_RECORDS, hfileReader.getEntries());
}

@Override
protected void verifySchema(Configuration conf, String schemaPath) throws IOException {
FileSystem fs = getFilePath().getFileSystem(conf);
HFile.Reader hfileReader = HoodieHFileUtils.createHFileReader(fs, getFilePath(), new CacheConfig(conf), conf);
HFile.Reader hfileReader = HoodieHFileUtils.createHFileReader(fs, getFilePath(), conf);
assertEquals(getSchemaFromResource(TestHoodieHFileReaderWriter.class, schemaPath),
new Schema.Parser().parse(new String(hfileReader.getHFileInfo().get(SCHEMA_KEY.getBytes()))));
}
Expand Down Expand Up @@ -216,7 +214,7 @@ public void testReadHFileFormatRecords() throws Exception {
// Reading byte array in HFile format, without actual file path
Configuration hadoopConf = fs.getConf();
HoodieAvroHFileReader hfileReader =
new HoodieAvroHFileReader(hadoopConf, new Path(DUMMY_BASE_PATH), new CacheConfig(hadoopConf), fs, content, Option.empty());
new HoodieAvroHFileReader(hadoopConf, new Path(DUMMY_BASE_PATH), fs, content, Option.empty());
Schema avroSchema = getSchemaFromResource(TestHoodieReaderWriterBase.class, "/exampleSchema.avsc");
assertEquals(NUM_RECORDS, hfileReader.getTotalRecords());
verifySimpleRecords(hfileReader.getRecordIterator(avroSchema));
Expand Down Expand Up @@ -424,7 +422,7 @@ public void testHoodieHFileCompatibility(String hfilePrefix) throws IOException

Configuration hadoopConf = fs.getConf();
HoodieAvroHFileReader hfileReader =
new HoodieAvroHFileReader(hadoopConf, new Path(DUMMY_BASE_PATH), new CacheConfig(hadoopConf), fs, content, Option.empty());
new HoodieAvroHFileReader(hadoopConf, new Path(DUMMY_BASE_PATH), fs, content, Option.empty());
Schema avroSchema = getSchemaFromResource(TestHoodieReaderWriterBase.class, "/exampleSchema.avsc");
assertEquals(NUM_RECORDS_FIXTURE, hfileReader.getTotalRecords());
verifySimpleRecords(hfileReader.getRecordIterator(avroSchema));
Expand All @@ -433,7 +431,7 @@ public void testHoodieHFileCompatibility(String hfilePrefix) throws IOException
verifyHFileReader(HoodieHFileUtils.createHFileReader(fs, new Path(DUMMY_BASE_PATH), content),
hfilePrefix, true, HFILE_COMPARATOR.getClass(), NUM_RECORDS_FIXTURE);
hfileReader =
new HoodieAvroHFileReader(hadoopConf, new Path(DUMMY_BASE_PATH), new CacheConfig(hadoopConf), fs, content, Option.empty());
new HoodieAvroHFileReader(hadoopConf, new Path(DUMMY_BASE_PATH), fs, content, Option.empty());
avroSchema = getSchemaFromResource(TestHoodieReaderWriterBase.class, "/exampleSchemaWithUDT.avsc");
assertEquals(NUM_RECORDS_FIXTURE, hfileReader.getTotalRecords());
verifySimpleRecords(hfileReader.getRecordIterator(avroSchema));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,6 @@
import org.apache.hadoop.fs.FSDataOutputStream;
import org.apache.hadoop.fs.FileStatus;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.hbase.io.hfile.CacheConfig;
import org.apache.hadoop.util.Time;
import org.apache.parquet.avro.AvroSchemaConverter;
import org.apache.parquet.schema.MessageType;
Expand Down Expand Up @@ -535,8 +534,7 @@ public void testVirtualKeysInBaseFiles() throws Exception {
table.getHoodieView().sync();
List<FileSlice> fileSlices = table.getSliceView().getLatestFileSlices("files").collect(Collectors.toList());
HoodieBaseFile baseFile = fileSlices.get(0).getBaseFile().get();
HoodieAvroHFileReader hoodieHFileReader = new HoodieAvroHFileReader(context.getHadoopConf().get(), new Path(baseFile.getPath()),
new CacheConfig(context.getHadoopConf().get()));
HoodieAvroHFileReader hoodieHFileReader = new HoodieAvroHFileReader(context.getHadoopConf().get(), new Path(baseFile.getPath()));
List<IndexedRecord> records = HoodieAvroHFileReader.readAllRecords(hoodieHFileReader);
records.forEach(entry -> {
if (populateMetaFields) {
Expand Down Expand Up @@ -955,9 +953,7 @@ private void verifyMetadataRecordKeyExcludeFromPayloadBaseFiles(HoodieTable tabl
}
final HoodieBaseFile baseFile = fileSlices.get(0).getBaseFile().get();

HoodieAvroHFileReader hoodieHFileReader = new HoodieAvroHFileReader(context.getHadoopConf().get(),
new Path(baseFile.getPath()),
new CacheConfig(context.getHadoopConf().get()));
HoodieAvroHFileReader hoodieHFileReader = new HoodieAvroHFileReader(context.getHadoopConf().get(), new Path(baseFile.getPath()));
List<IndexedRecord> records = HoodieAvroHFileReader.readAllRecords(hoodieHFileReader);
records.forEach(entry -> {
if (enableMetaFields) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,6 @@
import org.apache.hadoop.fs.LocalFileSystem;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.hbase.Cell;
import org.apache.hadoop.hbase.io.hfile.CacheConfig;
import org.apache.hadoop.hbase.io.hfile.HFile;
import org.apache.hadoop.hbase.io.hfile.HFileScanner;
import org.junit.jupiter.api.AfterAll;
Expand Down Expand Up @@ -996,12 +995,10 @@ public Stream<GenericRecord> readHFile(String[] paths) {
List<GenericRecord> valuesAsList = new LinkedList<>();

FileSystem fs = FSUtils.getFs(paths[0], context.getHadoopConf().get());
CacheConfig cacheConfig = new CacheConfig(fs.getConf());
Schema schema = null;
for (String path : paths) {
try {
HFile.Reader reader =
HoodieHFileUtils.createHFileReader(fs, new Path(path), cacheConfig, fs.getConf());
HFile.Reader reader = HoodieHFileUtils.createHFileReader(fs, new Path(path), fs.getConf());
if (schema == null) {
schema = new Schema.Parser().parse(new String(reader.getHFileInfo().get(SCHEMA_KEY.getBytes())));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,6 @@
import org.apache.hadoop.fs.FileStatus;
import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.hbase.io.hfile.CacheConfig;
import org.apache.hadoop.util.Time;
import org.apache.parquet.avro.AvroSchemaConverter;
import org.apache.parquet.schema.MessageType;
Expand Down Expand Up @@ -811,8 +810,7 @@ public void testVirtualKeysInBaseFiles() throws Exception {
table.getHoodieView().sync();
List<FileSlice> fileSlices = table.getSliceView().getLatestFileSlices("files").collect(Collectors.toList());
HoodieBaseFile baseFile = fileSlices.get(0).getBaseFile().get();
HoodieAvroHFileReader hoodieHFileReader = new HoodieAvroHFileReader(context.getHadoopConf().get(), new Path(baseFile.getPath()),
new CacheConfig(context.getHadoopConf().get()));
HoodieAvroHFileReader hoodieHFileReader = new HoodieAvroHFileReader(context.getHadoopConf().get(), new Path(baseFile.getPath()));
List<IndexedRecord> records = HoodieAvroHFileReader.readAllRecords(hoodieHFileReader);
records.forEach(entry -> {
if (populateMetaFields) {
Expand Down Expand Up @@ -1340,9 +1338,7 @@ private void verifyMetadataRecordKeyExcludeFromPayloadBaseFiles(HoodieTable tabl
}
final HoodieBaseFile baseFile = fileSlices.get(0).getBaseFile().get();

HoodieAvroHFileReader hoodieHFileReader = new HoodieAvroHFileReader(context.getHadoopConf().get(),
new Path(baseFile.getPath()),
new CacheConfig(context.getHadoopConf().get()));
HoodieAvroHFileReader hoodieHFileReader = new HoodieAvroHFileReader(context.getHadoopConf().get(), new Path(baseFile.getPath()));
List<IndexedRecord> records = HoodieAvroHFileReader.readAllRecords(hoodieHFileReader);
records.forEach(entry -> {
if (enableMetaFields) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@
import org.apache.avro.generic.IndexedRecord;
import org.apache.hadoop.fs.FileStatus;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.hbase.io.hfile.CacheConfig;
import org.apache.parquet.avro.AvroSchemaConverter;
import org.apache.parquet.schema.MessageType;
import org.junit.jupiter.params.ParameterizedTest;
Expand Down Expand Up @@ -407,9 +406,7 @@ private void verifyMetadataRecordKeyExcludeFromPayloadBaseFiles(HoodieTable tabl
}
final HoodieBaseFile baseFile = fileSlices.get(0).getBaseFile().get();

HoodieAvroHFileReader hoodieHFileReader = new HoodieAvroHFileReader(context.getHadoopConf().get(),
new Path(baseFile.getPath()),
new CacheConfig(context.getHadoopConf().get()));
HoodieAvroHFileReader hoodieHFileReader = new HoodieAvroHFileReader(context.getHadoopConf().get(), new Path(baseFile.getPath()));
List<IndexedRecord> records = HoodieAvroHFileReader.readAllRecords(hoodieHFileReader);
records.forEach(entry -> {
assertNull(((GenericRecord) entry).get(HoodieRecord.RECORD_KEY_METADATA_FIELD));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@
import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.hbase.Cell;
import org.apache.hadoop.hbase.io.hfile.CacheConfig;
import org.apache.hadoop.hbase.io.hfile.HFile;
import org.apache.hadoop.hbase.io.hfile.HFileScanner;
import org.apache.spark.SparkConf;
Expand Down Expand Up @@ -261,12 +260,11 @@ public static Stream<GenericRecord> readHFile(JavaSparkContext jsc, String[] pat
List<GenericRecord> valuesAsList = new LinkedList<>();

FileSystem fs = FSUtils.getFs(paths[0], jsc.hadoopConfiguration());
CacheConfig cacheConfig = new CacheConfig(fs.getConf());
Schema schema = null;
for (String path : paths) {
try {
HFile.Reader reader =
HoodieHFileUtils.createHFileReader(fs, new Path(path), cacheConfig, fs.getConf());
HoodieHFileUtils.createHFileReader(fs, new Path(path), fs.getConf());
if (schema == null) {
schema = new Schema.Parser().parse(new String(reader.getHFileInfo().get(SCHEMA_KEY.getBytes())));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ private static String getUserKeyFromCellKey(String cellKey) {
*/
private static HFile.Reader createReader(String hFilePath, Configuration conf, FileSystem fileSystem) {
LOG.info("Opening HFile for reading :" + hFilePath);
return HoodieHFileUtils.createHFileReader(fileSystem, new HFilePathForReader(hFilePath), new CacheConfig(conf), conf);
return HoodieHFileUtils.createHFileReader(fileSystem, new HFilePathForReader(hFilePath), conf);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
import org.apache.hadoop.fs.Path;

import java.io.File;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import static org.apache.hudi.common.util.ValidationUtils.checkArgument;

Expand All @@ -38,6 +40,11 @@ public class InLineFSUtils {
private static final String EQUALS_STR = "=";
private static final String LOCAL_FILESYSTEM_SCHEME = "file";

// Regex pattern to find the start offset from inline filesystem paths
private static final Pattern START_OFFSET_PATTERN = Pattern.compile("\\?start_offset=(\\d+)");
// Regex pattern to find the length from inline filesystem paths
private static final Pattern LENGTH_PATTERN = Pattern.compile("&length=(\\d+)");

/**
* Get the InlineFS Path for a given schema and its Path.
* <p>
Expand Down Expand Up @@ -98,8 +105,9 @@ public static Path getOuterFilePathFromInlinePath(Path inlineFSPath) {
public static long startOffset(Path inlineFSPath) {
assertInlineFSPath(inlineFSPath);

String[] slices = inlineFSPath.toString().split("[?&=]");
return Long.parseLong(slices[slices.length - 3]);
final Matcher matcher = START_OFFSET_PATTERN.matcher(inlineFSPath.toString());
matcher.find();

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤖 matcher.find() return value isn't checked here (and the same below on line 123 for length). If the path doesn't contain ?start_offset=<digits> for any reason, matcher.group(1) will throw IllegalStateException("No match found") with no path context — making diagnosis harder than the previous split-based failure. Could you check find() and throw a HoodieException with the offending path instead?

- AI-generated; verify before applying. React 👍/👎 to flag quality.

return Long.parseLong(matcher.group(1));
}

/**
Expand All @@ -111,8 +119,9 @@ public static long startOffset(Path inlineFSPath) {
public static long length(Path inlinePath) {
assertInlineFSPath(inlinePath);

String[] slices = inlinePath.toString().split("[?&=]");
return Long.parseLong(slices[slices.length - 1]);
final Matcher matcher = LENGTH_PATTERN.matcher(inlinePath.toString());
matcher.find();
return Long.parseLong(matcher.group(1));
}

private static void assertInlineFSPath(Path inlinePath) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.hbase.io.hfile.CacheConfig;
import org.apache.parquet.avro.AvroSchemaConverter;
import org.apache.parquet.format.converter.ParquetMetadataConverter;
import org.apache.parquet.hadoop.ParquetFileReader;
Expand Down Expand Up @@ -338,8 +337,7 @@ private MessageType readSchemaFromHFileBaseFile(Path hFilePath) throws IOExcepti
LOG.info("Reading schema from " + hFilePath);

FileSystem fs = metaClient.getRawFs();
CacheConfig cacheConfig = new CacheConfig(fs.getConf());
try (HoodieAvroHFileReader hFileReader = new HoodieAvroHFileReader(fs.getConf(), hFilePath, cacheConfig)) {
try (HoodieAvroHFileReader hFileReader = new HoodieAvroHFileReader(fs.getConf(), hFilePath)) {
return convertAvroSchemaToParquet(hFileReader.getSchema());
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,10 @@
import org.apache.hudi.common.model.HoodieRecord;
import org.apache.hudi.common.model.HoodieRecord.HoodieRecordType;
import org.apache.hudi.common.util.Option;
import org.apache.hudi.common.util.StringUtils;
import org.apache.hudi.common.util.collection.ClosableIterator;
import org.apache.hudi.common.util.collection.CloseableMappingIterator;
import org.apache.hudi.common.util.hash.HashID;
import org.apache.hudi.exception.HoodieException;
import org.apache.hudi.exception.HoodieIOException;
import org.apache.hudi.io.storage.HoodieAvroHFileReader;
Expand Down Expand Up @@ -176,7 +178,7 @@ protected <T> ClosableIterator<HoodieRecord<T>> deserializeRecords(byte[] conten
Configuration hadoopConf = FSUtils.buildInlineConf(getBlockContentLocation().get().getHadoopConf());
FileSystem fs = FSUtils.getFs(pathForReader.toString(), hadoopConf);
// Read the content
try (HoodieAvroHFileReader reader = new HoodieAvroHFileReader(hadoopConf, pathForReader, new CacheConfig(hadoopConf),
try (HoodieAvroHFileReader reader = new HoodieAvroHFileReader(hadoopConf, pathForReader,
fs, content, Option.of(getSchemaFromHeader()))) {
return unsafeCast(reader.getRecordIterator(readerSchema));
}
Expand All @@ -197,9 +199,15 @@ protected <T> ClosableIterator<HoodieRecord<T>> lookupRecords(List<String> sorte
blockContentLoc.getContentPositionInLogFile(),
blockContentLoc.getBlockSize());

// HFile BlockCache key is based on the name of the file. The inlinefs path has the format
// inlinefs://<path_to_outer_file>/<outer_file_scheme>/?start_offset=start_offset>&length=<length> whose filename
// component is parsed as "?start_offset=start_offset>&length=<length>" ignoring the actual outer file itself.
// To keep this unique (as cache keys should be unique for each file), we add a hash which is calculated from the
// entire filename. So the cache key would now be ?start_offset=start_offset>&length=<length>&pathHash=<hash>
final String pathHash = StringUtils.toHexString(HashID.hash(inlinePath.toString(), HashID.Size.BITS_128));
Path cachableInlinePath = new Path(inlinePath.toString() + "&pathHash=" + pathHash);
try (final HoodieAvroHFileReader reader =
new HoodieAvroHFileReader(inlineConf, inlinePath, new CacheConfig(inlineConf), inlinePath.getFileSystem(inlineConf),
Option.of(getSchemaFromHeader()))) {
new HoodieAvroHFileReader(inlineConf, cachableInlinePath, inlinePath.getFileSystem(inlineConf), Option.of(getSchemaFromHeader()))) {
// Get writer's schema from the header

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤖 nit: small typo — cachableInlinePath should be cacheableInlinePath (the correct English spelling is "cacheable").

- AI-generated; verify before applying. React 👍/👎 to flag quality.

final ClosableIterator<HoodieRecord<IndexedRecord>> recordIterator =
fullKey ? reader.getRecordsByKeysIterator(sortedKeys, readerSchema) : reader.getRecordsByKeyPrefixIterator(sortedKeys, readerSchema);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.hbase.io.hfile.CacheConfig;

import java.io.IOException;

Expand All @@ -33,8 +32,7 @@ protected HoodieFileReader newParquetFileReader(Configuration conf, Path path) {
}

protected HoodieFileReader newHFileFileReader(Configuration conf, Path path) throws IOException {
CacheConfig cacheConfig = new CacheConfig(conf);
return new HoodieAvroHFileReader(conf, path, cacheConfig);
return new HoodieAvroHFileReader(conf, path);
}

@Override
Expand Down
Loading