Skip to content

Commit

Permalink
HDDS-11357. Datanode Usageinfo Support Display Pipeline. (apache#7105)
Browse files Browse the repository at this point in the history
  • Loading branch information
slfan1989 authored Sep 10, 2024
1 parent 9477aa6 commit 33dbd4a
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 0 deletions.
1 change: 1 addition & 0 deletions hadoop-hdds/interface-client/src/main/proto/hdds.proto
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,7 @@ message DatanodeUsageInfoProto {
optional int64 containerCount = 5;
optional int64 committed = 6;
optional int64 freeSpaceToSpare = 7;
optional int64 pipelineCount = 8;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ public class DatanodeUsageInfo {
private DatanodeDetails datanodeDetails;
private SCMNodeStat scmNodeStat;
private int containerCount;
private int pipelineCount;

/**
* Constructs a DatanodeUsageInfo with DatanodeDetails and SCMNodeStat.
Expand All @@ -45,6 +46,7 @@ public DatanodeUsageInfo(
this.datanodeDetails = datanodeDetails;
this.scmNodeStat = scmNodeStat;
this.containerCount = -1;
this.pipelineCount = -1;
}

/**
Expand Down Expand Up @@ -145,6 +147,14 @@ public void setContainerCount(int containerCount) {
this.containerCount = containerCount;
}

public int getPipelineCount() {
return pipelineCount;
}

public void setPipelineCount(int pipelineCount) {
this.pipelineCount = pipelineCount;
}

/**
* Gets Comparator that compares two DatanodeUsageInfo on the basis of
* their utilization values. Utilization is (capacity - remaining) divided
Expand Down Expand Up @@ -210,6 +220,7 @@ private DatanodeUsageInfoProto.Builder toProtoBuilder(int clientVersion) {
}

builder.setContainerCount(containerCount);
builder.setPipelineCount(pipelineCount);
return builder;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -982,6 +982,7 @@ public DatanodeUsageInfo getUsageInfo(DatanodeDetails dn) {
DatanodeUsageInfo usageInfo = new DatanodeUsageInfo(dn, stat);
try {
usageInfo.setContainerCount(getContainerCount(dn));
usageInfo.setPipelineCount(getPipeLineCount(dn));
} catch (NodeNotFoundException ex) {
LOG.error("Unknown datanode {}.", dn, ex);
}
Expand Down Expand Up @@ -1610,6 +1611,11 @@ public int getContainerCount(DatanodeDetails datanodeDetails)
return nodeStateManager.getContainerCount(datanodeDetails.getUuid());
}

public int getPipeLineCount(DatanodeDetails datanodeDetails)
throws NodeNotFoundException {
return nodeStateManager.getPipelinesCount(datanodeDetails);
}

@Override
public void addDatanodeCommand(UUID dnId, SCMCommand command) {
writeLock().lock();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,8 @@ private void printInfo(DatanodeUsage info) {
+ " B", StringUtils.byteDesc(info.getRemaining()));
System.out.printf("%-13s: %s %n", "Remaining %",
PERCENT_FORMAT.format(info.getRemainingRatio()));
System.out.printf("%-13s: %d %n", "Pipeline(s)",
info.getPipelineCount());
System.out.printf("%-13s: %d %n", "Container(s)",
info.getContainerCount());
System.out.printf("%-24s: %s (%s) %n", "Container Pre-allocated",
Expand Down Expand Up @@ -192,6 +194,7 @@ private static class DatanodeUsage {
private long committed = 0;
private long freeSpaceToSpare = 0;
private long containerCount = 0;
private long pipelineCount = 0;

DatanodeUsage(HddsProtos.DatanodeUsageInfoProto proto) {
if (proto.hasNode()) {
Expand All @@ -212,6 +215,9 @@ private static class DatanodeUsage {
if (proto.hasContainerCount()) {
containerCount = proto.getContainerCount();
}
if (proto.hasPipelineCount()) {
pipelineCount = proto.getPipelineCount();
}
if (proto.hasFreeSpaceToSpare()) {
freeSpaceToSpare = proto.getFreeSpaceToSpare();
}
Expand Down Expand Up @@ -277,5 +283,8 @@ public double getRemainingRatio() {
return remaining / (double) capacity;
}

public long getPipelineCount() {
return pipelineCount;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ public void testCorrectJsonValuesInReport() throws IOException {
assertEquals(80.00, json.get(0).get("remainingPercent").doubleValue(), 0.001);

assertEquals(5, json.get(0).get("containerCount").longValue());
assertEquals(10, json.get(0).get("pipelineCount").longValue());
}

@Test
Expand Down Expand Up @@ -122,6 +123,7 @@ public void testOutputDataFieldsAligning() throws IOException {
assertThat(output).contains("Remaining :");
assertThat(output).contains("Remaining % :");
assertThat(output).contains("Container(s) :");
assertThat(output).contains("Pipeline(s) :");
assertThat(output).contains("Container Pre-allocated :");
assertThat(output).contains("Remaining Allocatable :");
assertThat(output).contains("Free Space To Spare :");
Expand All @@ -135,6 +137,7 @@ private List<HddsProtos.DatanodeUsageInfoProto> getUsageProto() {
.setRemaining(80)
.setUsed(10)
.setContainerCount(5)
.setPipelineCount(10)
.build());
return result;
}
Expand Down

0 comments on commit 33dbd4a

Please sign in to comment.