You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hudi.apache.org by GitBox <gi...@apache.org> on 2022/11/18 06:04:42 UTC
[GitHub] [hudi] alexeykudinkin commented on a diff in pull request #6782: [HUDI-4911][HUDI-3301] Fixing `HoodieMetadataLogRecordReader` to avoid flushing cache for every lookup
alexeykudinkin commented on code in PR #6782:
URL: https://github.com/apache/hudi/pull/6782#discussion_r1026051823
##########
hudi-common/src/main/java/org/apache/hudi/common/table/log/AbstractHoodieLogRecordReader.java:
##########
@@ -18,37 +18,32 @@
package org.apache.hudi.common.table.log;
-import org.apache.hudi.common.model.DeleteRecord;
+import org.apache.avro.Schema;
Review Comment:
It's done automatically by the IDEA whenever it cleans up dead imports.
Let me see if i can adjust it to respect checkstyle instead.
##########
hudi-common/src/main/java/org/apache/hudi/common/table/log/AbstractHoodieLogRecordReader.java:
##########
@@ -188,40 +179,41 @@ protected AbstractHoodieLogRecordReader(FileSystem fs, String basePath, List<Str
this.path = basePath;
this.useScanV2 = useScanV2;
- // Key fields when populate meta fields is disabled (that is, virtual keys enabled)
- if (!tableConfig.populateMetaFields()) {
- this.populateMetaFields = false;
- this.simpleKeyGenFields = Option.of(
- Pair.of(tableConfig.getRecordKeyFieldProp(), tableConfig.getPartitionFieldProp()));
- }
- this.partitionName = partitionName;
- }
+ if (keyFieldOverride.isPresent()) {
+ // TODO elaborate
+ checkState(partitionNameOverride.isPresent());
- protected String getKeyField() {
- if (this.populateMetaFields) {
- return HoodieRecord.RECORD_KEY_METADATA_FIELD;
+ this.populateMetaFields = false;
+ this.recordKeyField = keyFieldOverride.get();
+ this.partitionPathFieldOpt = Option.empty();
+ } else if (tableConfig.populateMetaFields()) {
+ this.populateMetaFields = true;
+ this.recordKeyField = HoodieRecord.RECORD_KEY_METADATA_FIELD;
+ this.partitionPathFieldOpt = Option.of(HoodieRecord.PARTITION_PATH_METADATA_FIELD);
Review Comment:
Interesting point. We only leverage it in case of MT, where we have to override it explicitly.
Not sure if there's value supporting such capability more generally
##########
hudi-client/hudi-client-common/src/main/java/org/apache/hudi/io/HoodieSortedMergeHandle.java:
##########
@@ -127,8 +127,8 @@ public List<WriteStatus> close() {
throw new HoodieUpsertException("Failed to close UpdateHandle", e);
}
}
+
newRecordKeysSorted.clear();
Review Comment:
It's final unfortunately, and there's not a lot of value in setting it null (since handles goes out of scope anyway)
##########
hudi-common/src/main/java/org/apache/hudi/common/table/log/AbstractHoodieLogRecordReader.java:
##########
@@ -734,15 +696,22 @@ private void processQueuedBlocksForInstant(Deque<HoodieLogBlock> logBlocks, int
progress = (numLogFilesSeen - 1) / logFilePaths.size();
Review Comment:
We wouldn't get to this method if it would be empty
##########
hudi-common/src/main/java/org/apache/hudi/common/table/log/HoodieMergedLogRecordScanner.java:
##########
@@ -106,30 +109,85 @@ protected HoodieMergedLogRecordScanner(FileSystem fs, String basePath, List<Stri
}
}
- protected void performScan() {
+ /**
+ * Scans delta-log files processing blocks
+ */
+ public final void scan() {
+ scan(false);
+ }
+
+ public final void scan(boolean skipProcessingBlocks) {
+ scanInternal(Option.empty(), skipProcessingBlocks);
+ }
+
+ /**
+ * Provides incremental scanning capability where only provided keys will be looked
+ * up in the delta-log files, scanned and subsequently materialized into the internal
+ * cache
+ *
+ * @param keys to be looked up
+ */
+ public void scanByFullKeys(List<String> keys) {
+ if (forceFullScan) {
+ return; // no-op
+ }
+
+ List<String> missingKeys = keys.stream()
+ .filter(key -> !records.containsKey(key))
+ .collect(Collectors.toList());
+
+ if (missingKeys.isEmpty()) {
+ // All the required records are already fetched, no-op
+ return;
+ }
+
+ scanInternal(Option.of(KeySpec.fullKeySpec(missingKeys)), false);
+ }
+
+ /**
+ * Provides incremental scanning capability where only keys matching provided key-prefixes
+ * will be looked up in the delta-log files, scanned and subsequently materialized into
+ * the internal cache
+ *
+ * @param keyPrefixes to be looked up
+ */
+ public void scanByKeyPrefixes(List<String> keyPrefixes) {
+ // TODO add caching for queried prefixes
Review Comment:
I think i'll actually address it in this PR
##########
hudi-common/src/main/java/org/apache/hudi/common/table/log/HoodieMergedLogRecordScanner.java:
##########
@@ -330,6 +390,16 @@ public Builder withUseScanV2(boolean useScanV2) {
return this;
}
+ public Builder withKeyFiledOverride(String keyFieldOverride) {
Review Comment:
How did you make such suggestion change? It's pretty cool
##########
hudi-common/src/main/java/org/apache/hudi/metadata/HoodieBackedTableMetadata.java:
##########
@@ -240,38 +239,35 @@ public List<Pair<String, Option<HoodieRecord<HoodieMetadataPayload>>>> getRecord
return result;
}
- private Map<String, Option<HoodieRecord<HoodieMetadataPayload>>> readLogRecords(HoodieMetadataMergedLogRecordReader logRecordScanner,
+ private Map<String, Option<HoodieRecord<HoodieMetadataPayload>>> readLogRecords(HoodieMetadataLogRecordReader logRecordReader,
List<String> keys,
boolean fullKey,
List<Long> timings) {
HoodieTimer timer = HoodieTimer.start();
- if (logRecordScanner == null) {
+ if (logRecordReader == null) {
timings.add(timer.endTimer());
return Collections.emptyMap();
}
- String partitionName = logRecordScanner.getPartitionName().get();
+ Map<String, Option<HoodieRecord<HoodieMetadataPayload>>> logRecords = new HashMap<>(keys.size());
- Map<String, Option<HoodieRecord<HoodieMetadataPayload>>> logRecords = new HashMap<>();
- if (isFullScanAllowedForPartition(partitionName)) {
- checkArgument(fullKey, "If full-scan is required, only full keys could be used!");
- // Path which does full scan of log files
- for (String key : keys) {
- logRecords.put(key, logRecordScanner.getRecordByKey(key).get(0).getValue());
- }
- } else {
- // This path will do seeks pertaining to the keys passed in
- List<Pair<String, Option<HoodieRecord<HoodieMetadataPayload>>>> logRecordsList =
- fullKey ? logRecordScanner.getRecordsByKeys(keys)
- : logRecordScanner.getRecordsByKeyPrefixes(keys)
- .stream()
- .map(record -> Pair.of(record.getRecordKey(), Option.of(record)))
- .collect(Collectors.toList());
-
- for (Pair<String, Option<HoodieRecord<HoodieMetadataPayload>>> entry : logRecordsList) {
- logRecords.put(entry.getKey(), entry.getValue());
- }
+ // First, fetch the keys being looked up
+ List<Pair<String, Option<HoodieRecord<HoodieMetadataPayload>>>> logRecordsList =
Review Comment:
So this PR makes sure that we're not flushing the records cache w/in the Scanner whenever we do `getRecord*` (previously batch APIs, were always flushing it). As such, there's now essentially no difference b/w these 2 branches.
##########
hudi-common/src/main/java/org/apache/hudi/hadoop/CachingPath.java:
##########
@@ -127,6 +129,48 @@ public static CachingPath createPathUnsafe(String relativePath) {
}
}
+ // TODO java-doc
Review Comment:
Oh, this commit shouldn't be in here
--
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: commits-unsubscribe@hudi.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org