Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -245,10 +245,11 @@ public static String constructFullPath(String keyName, long initialParentId, Str
public static StringBuilder constructFullPathPrefix(long initialParentId, String volumeName,
String bucketName, ReconNamespaceSummaryManager reconNamespaceSummaryManager,
ReconOMMetadataManager omMetadataManager) throws IOException {
StringBuilder fullPath = new StringBuilder();

long parentId = initialParentId;
boolean isDirectoryPresent = false;

List<String> pathSegments = new ArrayList<>();
while (parentId != 0) {
NSSummary nsSummary = reconNamespaceSummaryManager.getNSSummary(parentId);
if (nsSummary == null) {
Expand All @@ -265,26 +266,35 @@ public static StringBuilder constructFullPathPrefix(long initialParentId, String
}
// On the last pass, dir-name will be empty and parent will be zero, indicating the loop should end.
if (!nsSummary.getDirName().isEmpty()) {
fullPath.insert(0, nsSummary.getDirName() + OM_KEY_PREFIX);
pathSegments.add(nsSummary.getDirName());
}

// Move to the parent ID of the current directory
parentId = nsSummary.getParentId();
isDirectoryPresent = true;
}

// Prepend the volume and bucket to the constructed path
fullPath.insert(0, volumeName + OM_KEY_PREFIX + bucketName + OM_KEY_PREFIX);
Collections.reverse(pathSegments);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can save the reverse and just iterate the array backwards:

for(int counter=pathSegments.length-1; i >= 0; i--){

}    

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok

StringBuilder fullPath = new StringBuilder();

// Build the components in a list, then reverse and join once
fullPath.append(volumeName).append(OM_KEY_PREFIX)
.append(bucketName).append(OM_KEY_PREFIX);
for (String segment : pathSegments) {
fullPath.append(segment).append(OM_KEY_PREFIX);
}
// TODO - why is this needed? It seems lke it should handle double slashes in the path name,
// but its not clear how they get there. This normalize call is quite expensive as it
// creates several objects (URI, PATH, back to string). There was a bug fixed above
// where the last parent dirName was empty, which always caused a double // after the
// bucket name, but with that fixed, it seems like this should not be needed. All tests
// pass without it for key listing.
if (isDirectoryPresent) {
String path = fullPath.toString();
fullPath.setLength(0);
fullPath.append(OmUtils.normalizeKey(path, true));
if (fullPath.indexOf("//") >= 0) {
String path = fullPath.toString();
fullPath.setLength(0);
fullPath.append(OmUtils.normalizeKey(path, true));
}
}
return fullPath;
}
Expand Down
Loading