Repository navigation
Added BlockCache to HFile reader. - #13427
pacificleo wants to merge 2 commits into
Conversation
Summary: HBase 2.4+ does not allocate a block cache automatically within the CacheConfig but requires a BlockCache instance to be passed in. This is different from HBase 1.x where CacheConfig allocated and used a static global BlockCache instance. BlockCache speeds up lookup from the HFile. To emulate the behavior of HBase 1.x, we will allocate a global static global block cache here if it is enabled. The BlockCache can be controlle via hfile configs passed via hadoop configuration to the process. https://github.com/apache/hbase/blob/master/hbase-server/src/main/java/org/apache/hadoop/hbase/io/hfile/BlockCacheFactory.java Logs which show BlockCache was allocated [Driver] BlockCacheFactory: Allocating BlockCache size=3.20 GB, blockSize=64 KB [Driver] HoodieAvroHFileReader: Allocated a new global block cache for hfile readers LruBlockCache{blockCount=0, currentSize=2.40 MB, freeSize=3.20 GB, maxSize=3.20 GB, heapSize=2.40 MB, minSize=3.04 GB, minFactor=0.95, multiSize=1.52 GB, multiFactor=0.5, singleSize=778.24 MB, singleFactor=0.25} Test Plan: Tested using a perf tool to lookup 10K keys from RI. With BlockCache enabled, the time is 4x less. With BlockCache: [Driver] HoodieRecordIndexPerf: Time to lookup 10000 existing keys: 204462 [Driver] HoodieRecordIndexPerf: Time to lookup 10000 missing keys: 95169 Without BlockCache: [Driver] HoodieRecordIndexPerf: Time to lookup 10000 existing keys: 817908 [Driver] HoodieRecordIndexPerf: Time to lookup 10000 missing keys: 93470 Reviewers: syalla, O955 Project Hoodie Project Reviewer: Add blocking reviewers, #hoodie_blocking_reviewers, balajee Reviewed By: O955 Project Hoodie Project Reviewer: Add blocking reviewers, #hoodie_blocking_reviewers, balajee Subscribers: balajee Tags: #hudi_0.14, #has_java JIRA Issues: HUDI-6311 Differential Revision: https://code.uberinternal.com/D16768071
Summary: This library is required for enabling hfile Block Cache. Reviewers: syalla, O955 Project Hoodie Project Reviewer: Add blocking reviewers, #hoodie_blocking_reviewers, jingli Reviewed By: O955 Project Hoodie Project Reviewer: Add blocking reviewers, #hoodie_blocking_reviewers, jingli Tags: #hudi_0.14 JIRA Issues: HUDI-6594 Differential Revision: https://code.uberinternal.com/D17294457
|
|
||
| // 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. |
There was a problem hiding this comment.
"start_offset>" ==> "<start_offset>"
| 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 |
There was a problem hiding this comment.
"start_offset>" ==> "<start_offset>"
| // 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> |
| } | ||
|
|
||
| // The BlockCache keys are based on the name of the files being cached. Within HUDI, there is a non-zero chance that | ||
| // two different files can have the same name. Also, when multiple datasets are being accessed in the same JVM, there |
There was a problem hiding this comment.
- When do two files have the same name? Same file name in different paths?
| private static final Logger LOG = LoggerFactory.getLogger(HoodieAvroHFileReader.class); | ||
|
|
||
| // The global block cache instance used across all HFile readers | ||
| private static BlockCache GLOBAL_HFILE_BLOCK_CACHE; |
There was a problem hiding this comment.
- Why don't we just make it per file? After a file has been read, why do we need to keep its content in the cache?
- We have removed all the hbase dependencies, does it require us to bring some dependency back? If so, we probably cannot do it. Or just implement one by ourselves.
| <include>org.apache.hbase:hbase-server</include> | ||
| <include>org.apache.hbase.thirdparty:hbase-shaded-miscellaneous</include> | ||
| <include>org.apache.hbase.thirdparty:hbase-shaded-netty</include> | ||
| <include>org.apache.hbase.thirdparty:hbase-shaded-protobuf</include> |
There was a problem hiding this comment.
These Hbase dependencies have been removed from HUDI.
|
hey @rmahindra : can you take a first stab on reviewing this patch |
hudi-agent
left a comment
There was a problem hiding this comment.
🤖 This review was generated by an AI agent and may contain mistakes. Please verify any suggestions before applying.
Thanks for working on this! The PR re-enables BlockCache for HFile readers (which HBase 2.4+ no longer does automatically via CacheConfig) and shows a solid 4x speedup on RI lookups. A few things worth a closer look in the inline comments: an unused local variable hinting at an incomplete refactor, the unbounded growth of FILE_NAME_TO_PATH_MAP, and a couple of robustness concerns around the new regex-based InlineFS path parsing. Please take a look at any inline comments, and this should be ready for a Hudi committer or PMC member to take it from here. A few naming and dead-code nits in the new HoodieAvroHFileReader constructor logic, plus a typo in HoodieHFileDataBlock.
| // To avoid conflicts, we will only enable BlockCache if the name of the file is unique and has not been | ||
| // opened before. | ||
| final String cacheKey = path.getName(); | ||
| boolean enableBlockCache = false; |
There was a problem hiding this comment.
🤖 The local enableBlockCache is declared but never read or assigned after initialization. Looks like leftover from a previous iteration of the logic — could you remove it (or wire it into the actual branch decision below if that was the intent)?
- AI-generated; verify before applying. React 👍/👎 to flag quality.
| // Map of filename to the filepath for opened files | ||
| private static Map<String, String> FILE_NAME_TO_PATH_MAP = new HashMap<>(); | ||
|
|
||
| private final Path path; |
There was a problem hiding this comment.
🤖 FILE_NAME_TO_PATH_MAP is a process-lifetime static map with no eviction — every unique HFile name ever opened (including per-log-block inline paths from lookupRecords now keyed by pathHash) stays here forever. For long-running drivers/executors that touch many MDT files, log blocks, and multi-table workloads, this can grow into the millions of entries. Have you considered bounding it (e.g., a Guava Cache with size cap) or scoping it to a session?
- AI-generated; verify before applying. React 👍/👎 to flag quality.
| } | ||
|
|
||
| if (FILE_NAME_TO_PATH_MAP.get(cacheKey).equals(path.toString())) { | ||
| this.config = new CacheConfig(hadoopConf, GLOBAL_HFILE_BLOCK_CACHE); |
There was a problem hiding this comment.
🤖 The first-wins behavior here makes caching non-deterministic: whichever file with name X was opened first in the JVM gets to use the BlockCache; any subsequent file with the same name but a different path silently has its cache disabled (with a WARN). For workloads that open multiple datasets in one JVM (e.g., metaserver, multi-table services), this means a file's caching behavior depends on JVM warm-up order rather than its own attributes. Is that intentional? Would it be more predictable to either always-disable on collision, or to use a path-derived cache key (like the pathHash trick used in HoodieHFileDataBlock.lookupRecords) for all readers?
- AI-generated; verify before applying. React 👍/👎 to flag quality.
| String[] slices = inlineFSPath.toString().split("[?&=]"); | ||
| return Long.parseLong(slices[slices.length - 3]); | ||
| final Matcher matcher = START_OFFSET_PATTERN.matcher(inlineFSPath.toString()); | ||
| matcher.find(); |
There was a problem hiding this comment.
🤖 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.
| // The global block cache instance used across all HFile readers | ||
| private static BlockCache GLOBAL_HFILE_BLOCK_CACHE; | ||
| // Map of filename to the filepath for opened files | ||
| private static Map<String, String> FILE_NAME_TO_PATH_MAP = new HashMap<>(); |
There was a problem hiding this comment.
🤖 nit: could you add final here? private static final Map<String, String> FILE_NAME_TO_PATH_MAP = new HashMap<>(); — without it, the field can be accidentally reassigned, which would silently drop all the cache-conflict tracking.
- AI-generated; verify before applying. React 👍/👎 to flag quality.
| 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 |
There was a problem hiding this comment.
🤖 nit: small typo — cachableInlinePath should be cacheableInlinePath (the correct English spelling is "cacheable").
- AI-generated; verify before applying. React 👍/👎 to flag quality.
|
Temporarily closing this PR while we debug a GitHub settings error on master (#20471); it will be reopened shortly, no action needed. |
Change Logs
HBase 2.4+ does not allocate a block cache automatically within the CacheConfig
but requires a BlockCache instance to be passed in. This is different from HBase 1.x
where CacheConfig allocated and used a static global BlockCache instance.
singleFactor=0.25}
Impact
Lookups from MDT partitions like RI can be faster.
Risk level (write none, low medium or high below)
If medium or high, explain what verification was done to mitigate the risks.
Documentation Update
Describe any necessary documentation update if there is any new feature, config, or user-facing change. If not, put "none".
ticket number here and follow the instruction to make
changes to the website.
Contributor's checklist