Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HDDS-9260. Optimize OmDbInsight API to avoid redundant recursive size calculations for deleted directories during data retrieval. #5265

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
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 @@ -580,10 +580,22 @@ protected long fetchSizeForDeletedDirectory(long objectId)
if (nsSummary == null) {
return 0L;
}
// Check if the deleted dir size is already computed and set previously.
if (nsSummary.getIsSizeOfDeletedDirectoryComputed()) {
ArafatKhan2198 marked this conversation as resolved.
Show resolved Hide resolved
return nsSummary.getSizeOfFiles();
}

// Initialize the total size
long totalSize = nsSummary.getSizeOfFiles();

// Compute the size recursively
for (long childId : nsSummary.getChildDir()) {
totalSize += fetchSizeForDeletedDirectory(childId);
}
// Update the size in the NSSummary and set sizeOfFilesSet to true to avoid
// re-computation the next time.
nsSummary.setSizeOfFiles(totalSize);
nsSummary.setIsSizeOfDeletedDirectoryComputed();
return totalSize;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,13 @@ public class NSSummary {
private int[] fileSizeBucket;
private Set<Long> childDir;
private String dirName;
private boolean isSizeOfDeletedDirectoryComputed;

public NSSummary() {
this(0, 0L, new int[ReconConstants.NUM_OF_FILE_SIZE_BINS],
new HashSet<>(), "");
// Prevents redundant size computation for deleted directories.
isSizeOfDeletedDirectoryComputed = false;
}

public NSSummary(int numOfFiles,
Expand Down Expand Up @@ -82,6 +85,14 @@ public void setSizeOfFiles(long sizeOfFiles) {
this.sizeOfFiles = sizeOfFiles;
}

public boolean getIsSizeOfDeletedDirectoryComputed() {
return isSizeOfDeletedDirectoryComputed;
}

public void setIsSizeOfDeletedDirectoryComputed() {
this.isSizeOfDeletedDirectoryComputed = true;
}

public void setFileSizeBucket(int[] fileSizeBucket) {
this.fileSizeBucket = Arrays.copyOf(fileSizeBucket,
ReconConstants.NUM_OF_FILE_SIZE_BINS);
Expand Down