|
@@ -603,6 +603,60 @@ public class TestDataNodeMetrics {
|
|
|
MetricsRecordBuilder rb = getMetrics(dn.getMetrics().name());
|
|
|
assertCounter("HeartbeatsNumOps", 1L, rb);
|
|
|
}
|
|
|
+ @Test(timeout = 60000)
|
|
|
+ public void testSlowMetrics() throws Exception {
|
|
|
+ DataNodeFaultInjector dnFaultInjector = new DataNodeFaultInjector() {
|
|
|
+ @Override public void delay() {
|
|
|
+ try {
|
|
|
+ Thread.sleep(310);
|
|
|
+ } catch (InterruptedException e) {
|
|
|
+ }
|
|
|
+ }
|
|
|
+ };
|
|
|
+ DataNodeFaultInjector oldDnInjector = DataNodeFaultInjector.get();
|
|
|
+ DataNodeFaultInjector.set(dnFaultInjector);
|
|
|
+
|
|
|
+ Configuration conf = new HdfsConfiguration();
|
|
|
+ MiniDFSCluster cluster = null;
|
|
|
+ try {
|
|
|
+ cluster = new MiniDFSCluster.Builder(conf).numDataNodes(3).build();
|
|
|
+ final FileSystem fs = cluster.getFileSystem();
|
|
|
+ List<DataNode> datanodes = cluster.getDataNodes();
|
|
|
+ assertEquals(datanodes.size(), 3);
|
|
|
+ final DataNode datanode = datanodes.get(0);
|
|
|
+ MetricsRecordBuilder rb = getMetrics(datanode.getMetrics().name());
|
|
|
+ final long longFileLen = 10;
|
|
|
+ final long startFlushOrSyncValue =
|
|
|
+ getLongCounter("SlowFlushOrSyncCount", rb);
|
|
|
+ final long startAckToUpstreamValue =
|
|
|
+ getLongCounter("SlowAckToUpstreamCount", rb);
|
|
|
+ final AtomicInteger x = new AtomicInteger(0);
|
|
|
+
|
|
|
+ GenericTestUtils.waitFor(new Supplier<Boolean>() {
|
|
|
+ @Override public Boolean get() {
|
|
|
+ x.getAndIncrement();
|
|
|
+ try {
|
|
|
+ DFSTestUtil
|
|
|
+ .createFile(fs, new Path("/time.txt." + x.get()), longFileLen,
|
|
|
+ (short) 3, Time.monotonicNow());
|
|
|
+ } catch (IOException ioe) {
|
|
|
+ LOG.error("Caught IOException while ingesting DN metrics", ioe);
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ MetricsRecordBuilder rbNew = getMetrics(datanode.getMetrics().name());
|
|
|
+ final long endFlushOrSyncValue = getLongCounter("SlowFlushOrSyncCount", rbNew);
|
|
|
+ final long endAckToUpstreamValue = getLongCounter("SlowAckToUpstreamCount", rbNew);
|
|
|
+ return endFlushOrSyncValue > startFlushOrSyncValue
|
|
|
+ && endAckToUpstreamValue > startAckToUpstreamValue;
|
|
|
+ }
|
|
|
+ }, 30, 30000);
|
|
|
+ } finally {
|
|
|
+ DataNodeFaultInjector.set(oldDnInjector);
|
|
|
+ if (cluster != null) {
|
|
|
+ cluster.shutdown();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
@Test
|
|
|
public void testNNRpcMetricsWithHA() throws IOException {
|