nsivabalan commented on a change in pull request #2494:
URL: https://github.com/apache/hudi/pull/2494#discussion_r571102569



##########
File path: 
hudi-common/src/main/java/org/apache/hudi/metadata/HoodieBackedTableMetadata.java
##########
@@ -188,41 +196,51 @@ private synchronized void openFileSliceIfNeeded() throws 
IOException {
 
     // Load the schema
     Schema schema = 
HoodieAvroUtils.addMetadataFields(HoodieMetadataRecord.getClassSchema());
-    logRecordScanner = new 
HoodieMetadataMergedLogRecordScanner(metaClient.getFs(), metadataBasePath,
-            logFilePaths, schema, latestMetaInstantTimestamp, 
MAX_MEMORY_SIZE_IN_BYTES, BUFFER_SIZE,
+    HoodieMetadataMergedLogRecordScanner logRecordScanner = new 
HoodieMetadataMergedLogRecordScanner(metaClient.getFs(),
+            metadataBasePath, logFilePaths, schema, 
latestMetaInstantTimestamp, MAX_MEMORY_SIZE_IN_BYTES, BUFFER_SIZE,
             spillableMapDirectory, null);
 
     LOG.info("Opened metadata log files from " + logFilePaths + " at instant " 
+ latestInstantTime
         + "(dataset instant=" + latestInstantTime + ", metadata instant=" + 
latestMetaInstantTimestamp + ")");
 
     metrics.ifPresent(metrics -> 
metrics.updateMetrics(HoodieMetadataMetrics.SCAN_STR, timer.endTimer()));
+
+    if (metadataConfig.enableReuse()) {
+      // cache for later reuse
+      cachedBaseFileReader = baseFileReader;
+      cachedLogRecordScanner = logRecordScanner;
+    }
+
+    return Pair.of(baseFileReader, logRecordScanner);
   }
 
-  private void closeIfNeeded() {
+  private void closeIfNeeded(Pair<HoodieFileReader, 
HoodieMetadataMergedLogRecordScanner> readers) {
     try {
       if (!metadataConfig.enableReuse()) {
-        close();
+        readers.getKey().close();

Review comment:
       thnx for the detailed explanation Prasanth. will sync up w/ you offline. 
but still have some doubts/clarifications. 
   wrt statement 'one thread could be reading a key, while another could be 
closing the readers".
   Let's talk about 2 scenarios. 
   a. reuse is not enabled. every thread is going to reinitialize the reader 
and close in the end and has a local copy of reader. And hence should not be an 
issue. 
   b. reuse is enabled. close() is invoked only when the 
HoodieBackedMetadataTable itself will be closed. So, I thought no thread will 
invoke close() when some other thread is reading. 
   May be I am missing something here. as I told, will sync up directly.  




----------------------------------------------------------------
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.

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to