sumitagrawl commented on code in PR #6492:
URL: https://github.com/apache/ozone/pull/6492#discussion_r1584276957


##########
hadoop-ozone/recon/src/main/java/org/apache/hadoop/ozone/recon/ReconUtils.java:
##########
@@ -246,25 +254,83 @@ public void untarCheckpointFile(File tarFile, Path 
destPath)
     }
   }
 
+
+  /**
+   * Constructs the full path of a key from its OmKeyInfo using a bottom-up 
approach, starting from the leaf node.
+   *
+   * The method begins with the leaf node (the key itself) and recursively 
prepends parent directory names, fetched
+   * via NSSummary objects, until reaching the parent bucket (parentId is -1). 
It effectively builds the path from
+   * bottom to top, finally prepending the volume and bucket names to complete 
the full path.
+   *
+   * @param omKeyInfo The OmKeyInfo object for the key
+   * @return The constructed full path of the key as a String.
+   * @throws IOException
+   */
+  public static String constructFullPath(OmKeyInfo omKeyInfo,
+                                         ReconNamespaceSummaryManager 
reconNamespaceSummaryManager,
+                                         ReconOMMetadataManager 
omMetadataManager)
+      throws IOException {
+    StringBuilder fullPath = new StringBuilder(omKeyInfo.getKeyName());
+    long parentId = omKeyInfo.getParentObjectID();
+    boolean isDirectoryPresent = false;
+    boolean rebuildTriggered = false;
+
+    while (parentId != 0) {
+      NSSummary nsSummary = 
reconNamespaceSummaryManager.getNSSummary(parentId);
+      if (nsSummary == null) {
+        break;
+      }
+      if (nsSummary.getParentId() == -1 && !rebuildTriggered) {
+        // Trigger rebuild asynchronously and continue path construction
+        triggerRebuild(reconNamespaceSummaryManager, omMetadataManager);

Review Comment:
   This may triggered multiple time by different request, need avoid trigger 
again using global atomic boolean and to be run only once.



##########
hadoop-ozone/recon/src/main/java/org/apache/hadoop/ozone/recon/tasks/NSSummaryTaskDbEventHandler.java:
##########
@@ -132,6 +132,10 @@ protected void handlePutDirEvent(OmDirectoryInfo 
directoryInfo,
       curNSSummary = new NSSummary();
     }
     curNSSummary.setDirName(dirName);
+    // Set the parent directory ID
+    if (parentObjectId != -1) {
+      curNSSummary.setParentId(parentObjectId);
+    }

Review Comment:
   what is the scenario for -1 for NSSummary? check for the else part impact



##########
hadoop-ozone/recon/src/main/java/org/apache/hadoop/ozone/recon/ReconUtils.java:
##########
@@ -246,25 +254,83 @@ public void untarCheckpointFile(File tarFile, Path 
destPath)
     }
   }
 
+
+  /**
+   * Constructs the full path of a key from its OmKeyInfo using a bottom-up 
approach, starting from the leaf node.
+   *
+   * The method begins with the leaf node (the key itself) and recursively 
prepends parent directory names, fetched
+   * via NSSummary objects, until reaching the parent bucket (parentId is -1). 
It effectively builds the path from
+   * bottom to top, finally prepending the volume and bucket names to complete 
the full path.
+   *
+   * @param omKeyInfo The OmKeyInfo object for the key
+   * @return The constructed full path of the key as a String.
+   * @throws IOException
+   */
+  public static String constructFullPath(OmKeyInfo omKeyInfo,
+                                         ReconNamespaceSummaryManager 
reconNamespaceSummaryManager,
+                                         ReconOMMetadataManager 
omMetadataManager)
+      throws IOException {
+    StringBuilder fullPath = new StringBuilder(omKeyInfo.getKeyName());
+    long parentId = omKeyInfo.getParentObjectID();
+    boolean isDirectoryPresent = false;
+    boolean rebuildTriggered = false;
+
+    while (parentId != 0) {
+      NSSummary nsSummary = 
reconNamespaceSummaryManager.getNSSummary(parentId);
+      if (nsSummary == null) {
+        break;
+      }
+      if (nsSummary.getParentId() == -1 && !rebuildTriggered) {
+        // Trigger rebuild asynchronously and continue path construction
+        triggerRebuild(reconNamespaceSummaryManager, omMetadataManager);
+        rebuildTriggered = true; // Prevent multiple rebuild triggers
+      }
+      fullPath.insert(0, nsSummary.getDirName() + OM_KEY_PREFIX);
+
+      // Move to the parent ID of the current directory
+      parentId = nsSummary.getParentId();
+      isDirectoryPresent = true;
+    }
+
+    // Prepend the volume and bucket to the constructed path
+    String volumeName = omKeyInfo.getVolumeName();
+    String bucketName = omKeyInfo.getBucketName();
+    fullPath.insert(0, volumeName + OM_KEY_PREFIX + bucketName + 
OM_KEY_PREFIX);
+    if (isDirectoryPresent) {
+      return OmUtils.normalizeKey(fullPath.toString(), true);
+    }
+    return fullPath.toString();
+  }
+
+  private static void triggerRebuild(ReconNamespaceSummaryManager 
reconNamespaceSummaryManager,
+                                     ReconOMMetadataManager omMetadataManager) 
{
+    // Run this method in a separate thread
+    Executors.newSingleThreadExecutor().submit(() -> {

Review Comment:
   check if need relase the Executor thread or not



##########
hadoop-ozone/recon/src/main/java/org/apache/hadoop/ozone/recon/ReconUtils.java:
##########
@@ -246,25 +254,83 @@ public void untarCheckpointFile(File tarFile, Path 
destPath)
     }
   }
 
+
+  /**
+   * Constructs the full path of a key from its OmKeyInfo using a bottom-up 
approach, starting from the leaf node.
+   *
+   * The method begins with the leaf node (the key itself) and recursively 
prepends parent directory names, fetched
+   * via NSSummary objects, until reaching the parent bucket (parentId is -1). 
It effectively builds the path from
+   * bottom to top, finally prepending the volume and bucket names to complete 
the full path.
+   *
+   * @param omKeyInfo The OmKeyInfo object for the key
+   * @return The constructed full path of the key as a String.
+   * @throws IOException
+   */
+  public static String constructFullPath(OmKeyInfo omKeyInfo,
+                                         ReconNamespaceSummaryManager 
reconNamespaceSummaryManager,
+                                         ReconOMMetadataManager 
omMetadataManager)
+      throws IOException {
+    StringBuilder fullPath = new StringBuilder(omKeyInfo.getKeyName());
+    long parentId = omKeyInfo.getParentObjectID();
+    boolean isDirectoryPresent = false;
+    boolean rebuildTriggered = false;
+
+    while (parentId != 0) {
+      NSSummary nsSummary = 
reconNamespaceSummaryManager.getNSSummary(parentId);
+      if (nsSummary == null) {
+        break;
+      }
+      if (nsSummary.getParentId() == -1 && !rebuildTriggered) {
+        // Trigger rebuild asynchronously and continue path construction
+        triggerRebuild(reconNamespaceSummaryManager, omMetadataManager);
+        rebuildTriggered = true; // Prevent multiple rebuild triggers
+      }
+      fullPath.insert(0, nsSummary.getDirName() + OM_KEY_PREFIX);
+
+      // Move to the parent ID of the current directory
+      parentId = nsSummary.getParentId();
+      isDirectoryPresent = true;
+    }
+
+    // Prepend the volume and bucket to the constructed path
+    String volumeName = omKeyInfo.getVolumeName();

Review Comment:
   If bucket or parent directory does not exist, full path may be wrong. In 
this case, need give empty representing something wrong.



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


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to