|
@@ -205,6 +205,12 @@ public class TestNameNodeMetrics {
|
|
|
final Path file = getTestPath("testCorruptBlock");
|
|
|
createFile(file, 100, (short)2);
|
|
|
|
|
|
+ // Disable the heartbeats, so that no corrupted replica
|
|
|
+ // can be fixed
|
|
|
+ for (DataNode dn : cluster.getDataNodes()) {
|
|
|
+ DataNodeTestUtils.setHeartbeatsDisabledForTests(dn, true);
|
|
|
+ }
|
|
|
+
|
|
|
// Corrupt first replica of the block
|
|
|
LocatedBlock block = NameNodeAdapter.getBlockLocations(
|
|
|
cluster.getNameNode(), file.toString(), 0, 1).get(0);
|
|
@@ -215,12 +221,23 @@ public class TestNameNodeMetrics {
|
|
|
} finally {
|
|
|
cluster.getNamesystem().writeUnlock();
|
|
|
}
|
|
|
- Thread.sleep(1000); // Wait for block to be marked corrupt
|
|
|
+ BlockManagerTestUtil.getComputedDatanodeWork(bm);
|
|
|
+ BlockManagerTestUtil.updateState(bm);
|
|
|
MetricsRecordBuilder rb = getMetrics(NS_METRICS);
|
|
|
assertGauge("CorruptBlocks", 1L, rb);
|
|
|
assertGauge("PendingReplicationBlocks", 1L, rb);
|
|
|
assertGauge("ScheduledReplicationBlocks", 1L, rb);
|
|
|
+
|
|
|
fs.delete(file, true);
|
|
|
+ // During the file deletion, both BlockManager#corruptReplicas and
|
|
|
+ // BlockManager#pendingReplications will be updated, i.e., the records
|
|
|
+ // for the blocks of the deleted file will be removed from both
|
|
|
+ // corruptReplicas and pendingReplications. The corresponding
|
|
|
+ // metrics (CorruptBlocks and PendingReplicationBlocks) will only be updated
|
|
|
+ // when BlockManager#computeDatanodeWork is run where the
|
|
|
+ // BlockManager#udpateState is called. And in
|
|
|
+ // BlockManager#computeDatanodeWork the metric ScheduledReplicationBlocks
|
|
|
+ // will also be updated.
|
|
|
rb = waitForDnMetricValue(NS_METRICS, "CorruptBlocks", 0L);
|
|
|
assertGauge("PendingReplicationBlocks", 0L, rb);
|
|
|
assertGauge("ScheduledReplicationBlocks", 0L, rb);
|