Skip to content

Commit

Permalink
Added limit parameter to the DU
Browse files Browse the repository at this point in the history
  • Loading branch information
ArafatKhan2198 committed Apr 10, 2024
1 parent 1d5a90f commit def81a0
Show file tree
Hide file tree
Showing 10 changed files with 26 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ private ReconConstants() {
/**
* The maximum number of top disk usage records to return in a /du response.
*/
public static final int DISK_USAGE_TOP_RECORDS_LIMIT = 30;
public static final String DEFAULT_DISK_USAGE_TOP_RECORDS_LIMIT = "30";
public static final String DEFAULT_OPEN_KEY_INCLUDE_NON_FSO = "false";
public static final String DEFAULT_OPEN_KEY_INCLUDE_FSO = "false";
public static final String DEFAULT_FETCH_COUNT = "1000";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@
import javax.ws.rs.core.Response;
import java.io.IOException;

import static org.apache.hadoop.ozone.recon.ReconConstants.DEFAULT_DISK_USAGE_TOP_RECORDS_LIMIT;

/**
* REST APIs for namespace metadata summary.
*/
Expand Down Expand Up @@ -112,7 +114,8 @@ public Response getBasicInfo(
public Response getDiskUsage(@QueryParam("path") String path,
@DefaultValue("false") @QueryParam("files") boolean listFile,
@DefaultValue("false") @QueryParam("replica") boolean withReplica,
@DefaultValue("true") @QueryParam("sortSubPaths") boolean sortSubpaths)
@DefaultValue("true") @QueryParam("sortSubPaths") boolean sortSubpaths,
@DefaultValue(DEFAULT_DISK_USAGE_TOP_RECORDS_LIMIT) @QueryParam("limit") int limit)
throws IOException {
if (path == null || path.length() == 0) {
return Response.status(Response.Status.BAD_REQUEST).build();
Expand All @@ -125,10 +128,10 @@ public Response getDiskUsage(@QueryParam("path") String path,
}

EntityHandler handler = EntityHandler.getEntityHandler(
reconNamespaceSummaryManager,
omMetadataManager, reconSCM, path);
reconNamespaceSummaryManager,
omMetadataManager, reconSCM, path);

duResponse = handler.getDuResponse(listFile, withReplica, sortSubpaths);
duResponse = handler.getDuResponse(listFile, withReplica, sortSubpaths, limit);

return Response.ok(duResponse).build();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
import java.util.List;
import java.util.Set;

import static org.apache.hadoop.ozone.recon.ReconConstants.DISK_USAGE_TOP_RECORDS_LIMIT;
import static org.apache.hadoop.ozone.recon.ReconConstants.DEFAULT_DISK_USAGE_TOP_RECORDS_LIMIT;
import static org.apache.hadoop.ozone.recon.ReconUtils.sortDiskUsageDescendingWithLimit;

/**
Expand Down Expand Up @@ -90,7 +90,7 @@ private BucketObjectDBInfo getBucketObjDbInfo(String[] names)

@Override
public DUResponse getDuResponse(
boolean listFile, boolean withReplica, boolean sortSubpaths)
boolean listFile, boolean withReplica, boolean sortSubpaths, int limit)
throws IOException {
DUResponse duResponse = new DUResponse();
duResponse.setPath(getNormalizedPath());
Expand Down Expand Up @@ -149,7 +149,7 @@ public DUResponse getDuResponse(
if (sortSubpaths) {
// Parallel sort directory/files DU data in descending order of size and returns the top N elements.
dirDUData = sortDiskUsageDescendingWithLimit(dirDUData,
DISK_USAGE_TOP_RECORDS_LIMIT);
limit);
}

duResponse.setDuData(dirDUData);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
import java.util.List;
import java.util.Set;

import static org.apache.hadoop.ozone.recon.ReconConstants.DISK_USAGE_TOP_RECORDS_LIMIT;
import static org.apache.hadoop.ozone.recon.ReconConstants.DEFAULT_DISK_USAGE_TOP_RECORDS_LIMIT;
import static org.apache.hadoop.ozone.recon.ReconUtils.sortDiskUsageDescendingWithLimit;

/**
Expand Down Expand Up @@ -83,7 +83,7 @@ private ObjectDBInfo getDirectoryObjDbInfo(String[] names)

@Override
public DUResponse getDuResponse(
boolean listFile, boolean withReplica, boolean sortSubPaths)
boolean listFile, boolean withReplica, boolean sortSubPaths, int limit)
throws IOException {
DUResponse duResponse = new DUResponse();
duResponse.setPath(getNormalizedPath());
Expand Down Expand Up @@ -161,7 +161,7 @@ public DUResponse getDuResponse(
if (sortSubPaths) {
// Parallel sort subdirDUData in descending order of size and returns the top N elements.
subdirDUData = sortDiskUsageDescendingWithLimit(subdirDUData,
DISK_USAGE_TOP_RECORDS_LIMIT);
limit);
}

duResponse.setDuData(subdirDUData);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ public abstract NamespaceSummaryResponse getSummaryResponse()
throws IOException;

public abstract DUResponse getDuResponse(
boolean listFile, boolean withReplica, boolean sort)
boolean listFile, boolean withReplica, boolean sort, int limit)
throws IOException;

public abstract QuotaUsageResponse getQuotaResponse()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ private ObjectDBInfo getKeyDbObjectInfo(String[] names)

@Override
public DUResponse getDuResponse(
boolean listFile, boolean withReplica, boolean sort)
boolean listFile, boolean withReplica, boolean sort, int limit)
throws IOException {
DUResponse duResponse = new DUResponse();
duResponse.setPath(getNormalizedPath());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@
import java.util.ArrayList;
import java.util.List;

import static org.apache.hadoop.ozone.recon.ReconConstants.DISK_USAGE_TOP_RECORDS_LIMIT;
import static org.apache.hadoop.ozone.om.OMConfigKeys.OZONE_OM_USER_MAX_VOLUME_DEFAULT;
import static org.apache.hadoop.ozone.recon.ReconConstants.DEFAULT_DISK_USAGE_TOP_RECORDS_LIMIT;
import static org.apache.hadoop.ozone.recon.ReconUtils.sortDiskUsageDescendingWithLimit;

/**
Expand Down Expand Up @@ -91,7 +92,7 @@ private ObjectDBInfo getPrefixObjDbInfo()

@Override
public DUResponse getDuResponse(
boolean listFile, boolean withReplica, boolean sortSubPaths)
boolean listFile, boolean withReplica, boolean sortSubPaths, int limit)
throws IOException {
DUResponse duResponse = new DUResponse();
duResponse.setPath(getNormalizedPath());
Expand Down Expand Up @@ -143,8 +144,7 @@ public DUResponse getDuResponse(

if (sortSubPaths) {
// Parallel sort volumeDuData in descending order of size and returns the top N elements.
volumeDuData = sortDiskUsageDescendingWithLimit(volumeDuData,
DISK_USAGE_TOP_RECORDS_LIMIT);
volumeDuData = sortDiskUsageDescendingWithLimit(volumeDuData, limit);
}

duResponse.setDuData(volumeDuData);
Expand All @@ -159,7 +159,7 @@ public QuotaUsageResponse getQuotaResponse()
SCMNodeStat stats = getReconSCM().getScmNodeManager().getStats();
long quotaInBytes = stats.getCapacity().get();
long quotaUsedInBytes =
getDuResponse(true, true, false).getSizeWithReplica();
getDuResponse(true, true, false, OZONE_OM_USER_MAX_VOLUME_DEFAULT).getSizeWithReplica();
quotaUsageResponse.setQuota(quotaInBytes);
quotaUsageResponse.setQuotaUsed(quotaUsedInBytes);
return quotaUsageResponse;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public NamespaceSummaryResponse getSummaryResponse()

@Override
public DUResponse getDuResponse(
boolean listFile, boolean withReplica, boolean sort)
boolean listFile, boolean withReplica, boolean sort, int limit)
throws IOException {
DUResponse duResponse = new DUResponse();
duResponse.setStatus(ResponseStatus.PATH_NOT_FOUND);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,6 @@
import java.util.ArrayList;
import java.util.List;


import static org.apache.hadoop.ozone.recon.ReconConstants.DISK_USAGE_TOP_RECORDS_LIMIT;
import static org.apache.hadoop.ozone.recon.ReconUtils.sortDiskUsageDescendingWithLimit;

/**
Expand Down Expand Up @@ -96,7 +94,7 @@ private VolumeObjectDBInfo getVolumeObjDbInfo(String[] names)

@Override
public DUResponse getDuResponse(
boolean listFile, boolean withReplica, boolean sortSubPaths)
boolean listFile, boolean withReplica, boolean sortSubPaths, int limit)
throws IOException {
DUResponse duResponse = new DUResponse();
duResponse.setPath(getNormalizedPath());
Expand Down Expand Up @@ -138,8 +136,7 @@ public DUResponse getDuResponse(

if (sortSubPaths) {
// Parallel sort bucketDuData in descending order of size and returns the top N elements.
bucketDuData = sortDiskUsageDescendingWithLimit(bucketDuData,
DISK_USAGE_TOP_RECORDS_LIMIT);
bucketDuData = sortDiskUsageDescendingWithLimit(bucketDuData, limit);
}

duResponse.setDuData(bucketDuData);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,8 @@ private long getEntitySize(String path) throws IOException {
EntityHandler.getEntityHandler(reconNamespaceSummaryManager,
omMetadataManager, reconSCM, path);
if (null != entityHandler) {
DUResponse duResponse = entityHandler.getDuResponse(false, false, false);
DUResponse duResponse =
entityHandler.getDuResponse(false, false, false, 10000);
if (null != duResponse && duResponse.getStatus() == ResponseStatus.OK) {
return duResponse.getSize();
}
Expand Down

0 comments on commit def81a0

Please sign in to comment.