ArafatKhan2198 commented on code in PR #6492:
URL: https://github.com/apache/ozone/pull/6492#discussion_r1591912386
##########
hadoop-ozone/recon/src/main/java/org/apache/hadoop/ozone/recon/ReconUtils.java:
##########
@@ -246,25 +257,106 @@ 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. If the directory structure
+ * is currently being rebuilt (indicated by the isRebuilding flag), this
method returns an empty string to signify
+ * that path construction is temporarily unavailable.
+ *
+ * @param omKeyInfo The OmKeyInfo object for the key
+ * @return The constructed full path of the key as a String, or an empty
string if a rebuild is in progress and
+ * the path cannot be constructed at this time.
+ * @throws IOException
+ */
+
+ public static String constructFullPath(OmKeyInfo omKeyInfo,
+ ReconNamespaceSummaryManager
reconNamespaceSummaryManager,
+ ReconOMMetadataManager
omMetadataManager)
+ throws IOException {
+
+ // Return empty string to signify that path construction is temporarily
unavailable
+ if (isRebuilding) {
+ return "";
+ }
+
+ StringBuilder fullPath = new StringBuilder(omKeyInfo.getKeyName());
+ long parentId = omKeyInfo.getParentObjectID();
+ boolean isDirectoryPresent = false;
+
+ while (parentId != 0) {
+ NSSummary nsSummary =
reconNamespaceSummaryManager.getNSSummary(parentId);
+ if (nsSummary == null) {
+ break;
+ }
+ if (nsSummary.getParentId() == -1 && !rebuildTriggered) {
+ synchronized (ReconUtils.class) {
+ if (!rebuildTriggered) {
+ triggerRebuild(reconNamespaceSummaryManager, omMetadataManager);
+ rebuildTriggered = true; // Set the flag to true inside a
synchronized block
+ }
+ }
+ }
+ 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)
{
+ synchronized (ReconUtils.class) {
+ if (!isRebuilding) {
+ isRebuilding = true;
+ ExecutorService executor = Executors.newSingleThreadExecutor(); //
Create the executor
Review Comment:
Added thread name `RebuildNSSummaryThread` for better debugabaility.
##########
hadoop-ozone/recon/src/main/java/org/apache/hadoop/ozone/recon/ReconUtils.java:
##########
@@ -246,25 +257,106 @@ 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. If the directory structure
+ * is currently being rebuilt (indicated by the isRebuilding flag), this
method returns an empty string to signify
+ * that path construction is temporarily unavailable.
+ *
+ * @param omKeyInfo The OmKeyInfo object for the key
+ * @return The constructed full path of the key as a String, or an empty
string if a rebuild is in progress and
+ * the path cannot be constructed at this time.
+ * @throws IOException
+ */
+
+ public static String constructFullPath(OmKeyInfo omKeyInfo,
+ ReconNamespaceSummaryManager
reconNamespaceSummaryManager,
+ ReconOMMetadataManager
omMetadataManager)
+ throws IOException {
+
+ // Return empty string to signify that path construction is temporarily
unavailable
+ if (isRebuilding) {
+ return "";
+ }
+
+ StringBuilder fullPath = new StringBuilder(omKeyInfo.getKeyName());
+ long parentId = omKeyInfo.getParentObjectID();
+ boolean isDirectoryPresent = false;
+
+ while (parentId != 0) {
+ NSSummary nsSummary =
reconNamespaceSummaryManager.getNSSummary(parentId);
+ if (nsSummary == null) {
+ break;
+ }
+ if (nsSummary.getParentId() == -1 && !rebuildTriggered) {
+ synchronized (ReconUtils.class) {
+ if (!rebuildTriggered) {
+ triggerRebuild(reconNamespaceSummaryManager, omMetadataManager);
+ rebuildTriggered = true; // Set the flag to true inside a
synchronized block
+ }
+ }
+ }
+ 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)
{
+ synchronized (ReconUtils.class) {
+ if (!isRebuilding) {
+ isRebuilding = true;
+ ExecutorService executor = Executors.newSingleThreadExecutor(); //
Create the executor
+ executor.submit(() -> {
+ try {
+
reconNamespaceSummaryManager.rebuildNSSummaryTree(omMetadataManager);
+ } finally {
+ isRebuilding = false;
+ rebuildTriggered = false;
+ executor.shutdown(); // Shutdown the executor here
Review Comment:
Right now the `executor.shutdown()` will be called outside the finally block
to ensure it is executed after the task submission and avoids prematurely
shutting down the thread that is still running.
--
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]