瀏覽代碼

HDFS-17634. RBF: Fix web UI missing DN last block report (#7080)

Felix Nguyen 6 月之前
父節點
當前提交
09b348753f

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

@@ -25,6 +25,7 @@ import java.util.Collection;
 import java.util.Collections;
 import java.util.Collections;
 import java.util.HashMap;
 import java.util.HashMap;
 import java.util.Map;
 import java.util.Map;
+import java.util.Optional;
 import java.util.concurrent.ExecutionException;
 import java.util.concurrent.ExecutionException;
 import java.util.concurrent.TimeUnit;
 import java.util.concurrent.TimeUnit;
 import java.util.function.Function;
 import java.util.function.Function;
@@ -476,6 +477,7 @@ public class NamenodeBeanMetrics
         innerinfo.put("infoSecureAddr", node.getInfoSecureAddr());
         innerinfo.put("infoSecureAddr", node.getInfoSecureAddr());
         innerinfo.put("xferaddr", node.getXferAddr());
         innerinfo.put("xferaddr", node.getXferAddr());
         innerinfo.put("location", node.getNetworkLocation());
         innerinfo.put("location", node.getNetworkLocation());
+        innerinfo.put("uuid", Optional.ofNullable(node.getDatanodeUuid()).orElse(""));
         innerinfo.put("lastContact", getLastContact(node));
         innerinfo.put("lastContact", getLastContact(node));
         innerinfo.put("usedSpace", node.getDfsUsed());
         innerinfo.put("usedSpace", node.getDfsUsed());
         innerinfo.put("adminState", node.getAdminState().toString());
         innerinfo.put("adminState", node.getAdminState().toString());
@@ -492,6 +494,7 @@ public class NamenodeBeanMetrics
         innerinfo.put("volfails", -1); // node.getVolumeFailures()
         innerinfo.put("volfails", -1); // node.getVolumeFailures()
         innerinfo.put("blockPoolUsedPercentStdDev",
         innerinfo.put("blockPoolUsedPercentStdDev",
             Util.getBlockPoolUsedPercentStdDev(storageReports));
             Util.getBlockPoolUsedPercentStdDev(storageReports));
+        innerinfo.put("lastBlockReport", getLastBlockReport(node));
         info.put(node.getXferAddrWithHostname(),
         info.put(node.getXferAddrWithHostname(),
             Collections.unmodifiableMap(innerinfo));
             Collections.unmodifiableMap(innerinfo));
       }
       }
@@ -795,6 +798,10 @@ public class NamenodeBeanMetrics
     return (now() - node.getLastUpdate()) / 1000;
     return (now() - node.getLastUpdate()) / 1000;
   }
   }
 
 
+  private long getLastBlockReport(DatanodeInfo node) {
+    return (now() - node.getLastBlockReportTime()) / 60000;
+  }
+
   /////////////////////////////////////////////////////////
   /////////////////////////////////////////////////////////
   // NameNodeStatusMXBean
   // NameNodeStatusMXBean
   /////////////////////////////////////////////////////////
   /////////////////////////////////////////////////////////

+ 18 - 0
hadoop-hdfs-project/hadoop-hdfs-rbf/src/test/java/org/apache/hadoop/hdfs/server/federation/router/TestRouterRpc.java

@@ -135,6 +135,8 @@ import org.apache.hadoop.security.UserGroupInformation;
 import org.apache.hadoop.service.Service.STATE;
 import org.apache.hadoop.service.Service.STATE;
 import org.apache.hadoop.test.GenericTestUtils;
 import org.apache.hadoop.test.GenericTestUtils;
 import org.apache.hadoop.test.LambdaTestUtils;
 import org.apache.hadoop.test.LambdaTestUtils;
+
+import org.codehaus.jettison.json.JSONArray;
 import org.codehaus.jettison.json.JSONException;
 import org.codehaus.jettison.json.JSONException;
 import org.codehaus.jettison.json.JSONObject;
 import org.codehaus.jettison.json.JSONObject;
 import org.junit.After;
 import org.junit.After;
@@ -1880,6 +1882,22 @@ public class TestRouterRpc {
     JSONObject jsonObject = new JSONObject(jsonString0);
     JSONObject jsonObject = new JSONObject(jsonString0);
     assertEquals(NUM_SUBCLUSTERS * NUM_DNS, jsonObject.names().length());
     assertEquals(NUM_SUBCLUSTERS * NUM_DNS, jsonObject.names().length());
 
 
+    JSONObject jsonObjectNn =
+        new JSONObject(cluster.getRandomNamenode().getNamenode().getNamesystem().getLiveNodes());
+    // DN report by NN and router should be the same
+    String randomDn = (String) jsonObjectNn.names().get(0);
+    JSONObject randomReportNn = jsonObjectNn.getJSONObject(randomDn);
+    JSONObject randomReportRouter = jsonObject.getJSONObject(randomDn);
+    JSONArray keys = randomReportNn.names();
+    for (int i = 0; i < keys.length(); i++) {
+      String key = keys.getString(i);
+      // Skip the 2 keys that always return -1
+      if (key.equals("blockScheduled") || key.equals("volfails")) {
+        continue;
+      }
+      assertEquals(randomReportRouter.get(key), randomReportNn.get(key));
+    }
+
     // We should be caching this information
     // We should be caching this information
     String jsonString1 = metrics.getLiveNodes();
     String jsonString1 = metrics.getLiveNodes();
     assertEquals(jsonString0, jsonString1);
     assertEquals(jsonString0, jsonString1);