siddhantsangwan commented on code in PR #9646:
URL: https://github.com/apache/ozone/pull/9646#discussion_r2711311517
##########
hadoop-hdds/server-scm/src/main/java/org/apache/hadoop/hdds/scm/node/SCMNodeManager.java:
##########
@@ -1737,6 +1771,65 @@ public long getTotalReserved(DatanodeDetails
datanodeDetails)
return reserved;
}
+ /**
+ * Compute aggregated raw filesystem capacity/available/used for a datanode
+ * from the storage reports.
+ */
+ public FsUsageTotals getTotalFilesystemUsage(DatanodeDetails
datanodeDetails) {
+ final DatanodeInfo datanodeInfo;
+ try {
+ datanodeInfo = nodeStateManager.getNode(datanodeDetails);
+ } catch (NodeNotFoundException exception) {
+ LOG.error("Node not found when calculating fs usage for {}.",
datanodeDetails, exception);
+ return null;
+ }
+
+ long capacity = 0L;
+ long available = 0L;
+ boolean hasFsReport = false;
+ for (StorageReportProto r : datanodeInfo.getStorageReports()) {
+ if (r.hasFailed() && r.getFailed()) {
+ continue;
+ }
+ if (r.hasFsCapacity() && r.hasFsAvailable()) {
+ hasFsReport = true;
+ capacity += r.getFsCapacity();
+ available += r.getFsAvailable();
+ }
+ }
+ if (!hasFsReport) {
+ LOG.debug("Datanode {} does not have filesystem storage stats in its
storage reports.", datanodeDetails);
+ }
+ return hasFsReport ? new FsUsageTotals(capacity, available, capacity -
available) : null;
+ }
+
+ /**
+ * Simple class for grouping disk space related values.
+ */
+ public static final class FsUsageTotals {
+ private final long capacity;
+ private final long available;
+ private final long used;
+
+ private FsUsageTotals(long capacity, long available, long used) {
+ this.capacity = capacity;
+ this.available = available;
+ this.used = used;
+ }
+
+ public long getCapacity() {
+ return capacity;
+ }
+
+ public long getAvailable() {
+ return available;
+ }
+
+ public long getUsed() {
+ return used;
+ }
+ }
+
Review Comment:
Makes sense - updated.
--
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]