Skip to content

Commit 91af256

Browse files
authored
HADOOP-17995. Stale record should be remove when DataNodePeerMetrics#dumpSendPacketDownstreamAvgInfoAsJson (#3630)
1 parent 646c470 commit 91af256

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/metrics2/lib/MutableRollingAverages.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -179,8 +179,11 @@ public void snapshot(MetricsRecordBuilder builder, boolean all) {
179179
long totalCount = 0;
180180

181181
for (final SumAndCount sumAndCount : entry.getValue()) {
182-
totalCount += sumAndCount.getCount();
183-
totalSum += sumAndCount.getSum();
182+
if (Time.monotonicNow() - sumAndCount.getSnapshotTimeStamp()
183+
< recordValidityMs) {
184+
totalCount += sumAndCount.getCount();
185+
totalSum += sumAndCount.getSum();
186+
}
184187
}
185188

186189
if (totalCount != 0) {

hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/datanode/TestDataNodePeerMetrics.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,10 +122,16 @@ public void testRemoveStaleRecord() throws Exception {
122122
GenericTestUtils.waitFor(
123123
() -> rollingAverages.getStats(numSamples).size() > 0, 500, 5000);
124124
assertEquals(3, rollingAverages.getStats(numSamples).size());
125+
String json = peerMetrics.dumpSendPacketDownstreamAvgInfoAsJson();
126+
for (String peerAddr : peerAddrList) {
127+
assertThat(json, containsString(peerAddr));
128+
}
125129
/* wait for stale report to be removed */
126130
GenericTestUtils.waitFor(
127131
() -> rollingAverages.getStats(numSamples).isEmpty(), 500, 10000);
128132
assertEquals(0, rollingAverages.getStats(numSamples).size());
133+
json = peerMetrics.dumpSendPacketDownstreamAvgInfoAsJson();
134+
assertEquals("{}", json);
129135

130136
/* dn can report peer metrics normally when it added back to cluster */
131137
for (String peerAddr : peerAddrList) {
@@ -138,6 +144,10 @@ public void testRemoveStaleRecord() throws Exception {
138144
GenericTestUtils.waitFor(
139145
() -> rollingAverages.getStats(numSamples).size() > 0, 500, 10000);
140146
assertEquals(3, rollingAverages.getStats(numSamples).size());
147+
json = peerMetrics.dumpSendPacketDownstreamAvgInfoAsJson();
148+
for (String peerAddr : peerAddrList) {
149+
assertThat(json, containsString(peerAddr));
150+
}
141151
}
142152

143153
/**

0 commit comments

Comments
 (0)