Skip to content

Commit cc4c4be

Browse files
authored
HDFS-17331:Fix Blocks are always -1 and DataNode version are always UNKNOWN in federationhealth.html (apache#6429). Contributed by lei w.
Signed-off-by: Shuyan Zhang <[email protected]>
1 parent 4c3d4e6 commit cc4c4be

File tree

5 files changed

+27
-6
lines changed

5 files changed

+27
-6
lines changed

hadoop-hdfs-project/hadoop-hdfs-client/src/main/java/org/apache/hadoop/hdfs/protocol/DatanodeInfo.java

+13-2
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ private DatanodeInfo(final String ipAddr, final String hostName,
143143
final int xceiverCount, final String networkLocation,
144144
final AdminStates adminState, final String upgradeDomain,
145145
final long lastBlockReportTime, final long lastBlockReportMonotonic,
146-
final int blockCount) {
146+
final int blockCount, final String softwareVersion) {
147147
super(ipAddr, hostName, datanodeUuid, xferPort, infoPort, infoSecurePort,
148148
ipcPort);
149149
this.capacity = capacity;
@@ -162,6 +162,7 @@ private DatanodeInfo(final String ipAddr, final String hostName,
162162
this.lastBlockReportTime = lastBlockReportTime;
163163
this.lastBlockReportMonotonic = lastBlockReportMonotonic;
164164
this.numBlocks = blockCount;
165+
this.softwareVersion = softwareVersion;
165166
}
166167

167168
/** Network location name. */
@@ -699,6 +700,7 @@ public static class DatanodeInfoBuilder {
699700
private long lastBlockReportTime = 0L;
700701
private long lastBlockReportMonotonic = 0L;
701702
private int numBlocks = 0;
703+
private String softwareVersion;
702704

703705
// Please use setNumBlocks explicitly to set numBlocks as this method doesn't have
704706
// sufficient info about numBlocks
@@ -718,6 +720,9 @@ public DatanodeInfoBuilder setFrom(DatanodeInfo from) {
718720
this.upgradeDomain = from.getUpgradeDomain();
719721
this.lastBlockReportTime = from.getLastBlockReportTime();
720722
this.lastBlockReportMonotonic = from.getLastBlockReportMonotonic();
723+
if (from.getSoftwareVersion() != null) {
724+
this.softwareVersion = from.getSoftwareVersion();
725+
}
721726
setNodeID(from);
722727
return this;
723728
}
@@ -844,18 +849,24 @@ public DatanodeInfoBuilder setLastBlockReportMonotonic(long time) {
844849
this.lastBlockReportMonotonic = time;
845850
return this;
846851
}
852+
847853
public DatanodeInfoBuilder setNumBlocks(int blockCount) {
848854
this.numBlocks = blockCount;
849855
return this;
850856
}
851857

858+
public DatanodeInfoBuilder setSoftwareVersion(String dnVersion) {
859+
this.softwareVersion = dnVersion;
860+
return this;
861+
}
862+
852863
public DatanodeInfo build() {
853864
return new DatanodeInfo(ipAddr, hostName, datanodeUuid, xferPort,
854865
infoPort, infoSecurePort, ipcPort, capacity, dfsUsed, nonDfsUsed,
855866
remaining, blockPoolUsed, cacheCapacity, cacheUsed, lastUpdate,
856867
lastUpdateMonotonic, xceiverCount, location, adminState,
857868
upgradeDomain, lastBlockReportTime, lastBlockReportMonotonic,
858-
numBlocks);
869+
numBlocks, softwareVersion);
859870
}
860871
}
861872
}

hadoop-hdfs-project/hadoop-hdfs-client/src/main/java/org/apache/hadoop/hdfs/protocolPB/PBHelperClient.java

+5-1
Original file line numberDiff line numberDiff line change
@@ -385,6 +385,9 @@ public static DatanodeInfoProto convert(DatanodeInfo info) {
385385
if (info.getUpgradeDomain() != null) {
386386
builder.setUpgradeDomain(info.getUpgradeDomain());
387387
}
388+
if (info.getSoftwareVersion() != null) {
389+
builder.setSoftwareVersion(info.getSoftwareVersion());
390+
}
388391
builder
389392
.setId(convert((DatanodeID) info))
390393
.setCapacity(info.getCapacity())
@@ -786,7 +789,8 @@ static public DatanodeInfo convert(DatanodeInfoProto di) {
786789
di.getLastBlockReportTime() : 0)
787790
.setLastBlockReportMonotonic(di.hasLastBlockReportMonotonic() ?
788791
di.getLastBlockReportMonotonic() : 0)
789-
.setNumBlocks(di.getNumBlocks());
792+
.setNumBlocks(di.getNumBlocks())
793+
.setSoftwareVersion(di.getSoftwareVersion());
790794

791795
if (di.hasNonDfsUsed()) {
792796
dinfo.setNonDfsUsed(di.getNonDfsUsed());

hadoop-hdfs-project/hadoop-hdfs-client/src/main/proto/hdfs.proto

+1
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,7 @@ message DatanodeInfoProto {
133133
optional uint64 lastBlockReportTime = 15 [default = 0];
134134
optional uint64 lastBlockReportMonotonic = 16 [default = 0];
135135
optional uint32 numBlocks = 17 [default = 0];
136+
optional string softwareVersion = 18;
136137
}
137138

138139
/**

hadoop-hdfs-project/hadoop-hdfs-rbf/src/main/java/org/apache/hadoop/hdfs/server/federation/metrics/NamenodeBeanMetrics.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -481,7 +481,7 @@ private String getNodesImpl(final DatanodeReportType type) {
481481
innerinfo.put("adminState", node.getAdminState().toString());
482482
innerinfo.put("nonDfsUsedSpace", node.getNonDfsUsed());
483483
innerinfo.put("capacity", node.getCapacity());
484-
innerinfo.put("numBlocks", -1); // node.numBlocks()
484+
innerinfo.put("numBlocks", node.getNumBlocks());
485485
innerinfo.put("version", (node.getSoftwareVersion() == null ?
486486
"UNKNOWN" : node.getSoftwareVersion()));
487487
innerinfo.put("used", node.getDfsUsed());

hadoop-hdfs-project/hadoop-hdfs-rbf/src/main/java/org/apache/hadoop/hdfs/server/federation/router/RouterClientProtocol.java

+7-2
Original file line numberDiff line numberDiff line change
@@ -1101,10 +1101,15 @@ private DatanodeStorageReport[] mergeDtanodeStorageReport(
11011101
DatanodeInfo dnInfo = dn.getDatanodeInfo();
11021102
String nodeId = dnInfo.getXferAddr();
11031103
DatanodeStorageReport oldDn = datanodesMap.get(nodeId);
1104-
if (oldDn == null ||
1105-
dnInfo.getLastUpdate() > oldDn.getDatanodeInfo().getLastUpdate()) {
1104+
if (oldDn == null) {
1105+
datanodesMap.put(nodeId, dn);
1106+
} else if (dnInfo.getLastUpdate() > oldDn.getDatanodeInfo().getLastUpdate()) {
1107+
dnInfo.setNumBlocks(dnInfo.getNumBlocks() +
1108+
oldDn.getDatanodeInfo().getNumBlocks());
11061109
datanodesMap.put(nodeId, dn);
11071110
} else {
1111+
oldDn.getDatanodeInfo().setNumBlocks(
1112+
oldDn.getDatanodeInfo().getNumBlocks() + dnInfo.getNumBlocks());
11081113
LOG.debug("{} is in multiple subclusters", nodeId);
11091114
}
11101115
}

0 commit comments

Comments
 (0)