voonhous commented on code in PR #13724:
URL: https://github.com/apache/hudi/pull/13724#discussion_r2335895429
##########
hudi-common/src/main/java/org/apache/hudi/io/storage/HFileReaderFactory.java:
##########
@@ -55,9 +58,34 @@ public HFileReaderFactory(HoodieStorage storage,
public HFileReader createHFileReader() throws IOException {
final long fileSize = determineFileSize();
final SeekableDataInputStream inputStream = createInputStream(fileSize);
+
+ if (shouldEnableBlockCaching()) {
+ HFileReaderConfig config = createHFileReaderConfig();
+ String filePath = getFilePath();
+ return new CachingHFileReaderImpl(inputStream, fileSize, filePath,
config);
+ }
+
return new HFileReaderImpl(inputStream, fileSize);
}
+ private boolean shouldEnableBlockCaching() {
+ return metadataConfig.getHFileBlockCacheEnabled();
+ }
+
+ private HFileReaderConfig createHFileReaderConfig() {
+ int blockCacheSize = metadataConfig.getHFileBlockCacheSize();
+ int cacheTtlMinutes = metadataConfig.getHFileBlockCacheTTLMinutes();
+ return new HFileReaderConfig(blockCacheSize, cacheTtlMinutes);
+ }
+
+ private String getFilePath() {
+ if (fileSource.isLeft()) {
+ return fileSource.asLeft().toString();
+ }
+ // For byte array content, use a hash-based identifier
+ return "bytes:" + Arrays.hashCode(fileSource.asRight());
Review Comment:
Changed this to:
```
int murmurHash = MurmurHash.getInstance().hash(fileSource.asRight());
return String.valueOf(murmurHash);
```
From what i understand, It's better than `Arrays.hashCode` it does chunk
processing instead of a byte by byte processing although both of them have
`O(n)` complexity.
##########
hudi-io/src/main/java/org/apache/hudi/io/hfile/CachingHFileReaderImpl.java:
##########
@@ -0,0 +1,150 @@
+/*
+ * 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.io.hfile;
+
+import org.apache.hudi.io.SeekableDataInputStream;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.io.IOException;
+import java.util.concurrent.TimeUnit;
+
+/**
+ * HFile reader implementation with integrated caching functionality. This
extends BaseHFileReaderImpl and overrides the block instantiation method to add
caching capabilities.
+ * <p>
+ * Uses a shared static cache across all instances to maximize cache hits when
multiple readers access the same file.
+ */
+public class CachingHFileReaderImpl extends HFileReaderImpl {
+
+ private static final Logger LOG =
LoggerFactory.getLogger(CachingHFileReaderImpl.class);
+
+ private static volatile HFileBlockCache GLOBAL_BLOCK_CACHE;
+ // Store first config to check against cache config
+ private static volatile HFileReaderConfig INITIAL_CONFIG;
+ private static final Object CACHE_LOCK = new Object();
+
+ private final String filePath;
+
+ public CachingHFileReaderImpl(SeekableDataInputStream stream, long fileSize,
String filePath) {
+ this(stream, fileSize, filePath,
HFileReaderConfig.DEFAULT_BLOCK_CACHE_SIZE);
+ }
Review Comment:
Not used, removed.
--
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]