HDFS-16231. Fix TestDataNodeMetrics#testReceivePacketSlowMetrics (#3471)

This commit is contained in:
huhaiyang 2021-09-28 13:09:18 +08:00 committed by GitHub
parent 02993bc11e
commit 1f8f53f7d7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 15 additions and 6 deletions

View File

@ -169,6 +169,7 @@ public class TestDataNodeMetrics {
conf.setInt(DFSConfigKeys.DFS_METRICS_PERCENTILES_INTERVALS_KEY, interval); conf.setInt(DFSConfigKeys.DFS_METRICS_PERCENTILES_INTERVALS_KEY, interval);
MiniDFSCluster cluster = new MiniDFSCluster.Builder(conf) MiniDFSCluster cluster = new MiniDFSCluster.Builder(conf)
.numDataNodes(3).build(); .numDataNodes(3).build();
DataNodeFaultInjector oldInjector = DataNodeFaultInjector.get();
try { try {
cluster.waitActive(); cluster.waitActive();
DistributedFileSystem fs = cluster.getFileSystem(); DistributedFileSystem fs = cluster.getFileSystem();
@ -190,22 +191,30 @@ public class TestDataNodeMetrics {
DataNodeFaultInjector.set(injector); DataNodeFaultInjector.set(injector);
Path testFile = new Path("/testFlushNanosMetric.txt"); Path testFile = new Path("/testFlushNanosMetric.txt");
FSDataOutputStream fout = fs.create(testFile); FSDataOutputStream fout = fs.create(testFile);
DFSOutputStream dout = (DFSOutputStream) fout.getWrappedStream();
fout.write(new byte[1]); fout.write(new byte[1]);
fout.hsync(); fout.hsync();
DatanodeInfo[] pipeline = dout.getPipeline();
fout.close(); fout.close();
dout.close();
DatanodeInfo headDatanodeInfo = pipeline[0];
List<DataNode> datanodes = cluster.getDataNodes(); List<DataNode> datanodes = cluster.getDataNodes();
DataNode datanode = datanodes.get(0); DataNode headNode = datanodes.stream().filter(d -> d.getDatanodeId().equals(headDatanodeInfo))
MetricsRecordBuilder dnMetrics = getMetrics(datanode.getMetrics().name()); .findFirst().orElseGet(null);
assertNotNull("Could not find the head of the datanode write pipeline",
headNode);
MetricsRecordBuilder dnMetrics = getMetrics(headNode.getMetrics().name());
assertTrue("More than 1 packet received", assertTrue("More than 1 packet received",
getLongCounter("TotalPacketsReceived", dnMetrics) > 1L); getLongCounter("PacketsReceived", dnMetrics) > 1L);
assertTrue("More than 1 slow packet to mirror", assertTrue("More than 1 slow packet to mirror",
getLongCounter("TotalPacketsSlowWriteToMirror", dnMetrics) > 1L); getLongCounter("PacketsSlowWriteToMirror", dnMetrics) > 1L);
assertCounter("TotalPacketsSlowWriteToDisk", 1L, dnMetrics); assertCounter("PacketsSlowWriteToDisk", 1L, dnMetrics);
assertCounter("TotalPacketsSlowWriteToOsCache", 0L, dnMetrics); assertCounter("PacketsSlowWriteToOsCache", 0L, dnMetrics);
} finally { } finally {
if (cluster != null) { if (cluster != null) {
cluster.shutdown(); cluster.shutdown();
} }
DataNodeFaultInjector.set(oldInjector);
} }
} }