Преглед изворни кода

HDFS-11947. When constructing a thread name, BPOfferService may print a bogus warning message. Contributed by Weiwei Yang

Tsz-Wo Nicholas Sze пре 8 година
родитељ
комит
bec79ca249

+ 9 - 3
hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/datanode/BPOfferService.java

@@ -183,14 +183,16 @@ class BPOfferService {
     return nameserviceId;
   }
 
-  String getBlockPoolId() {
+  String getBlockPoolId(boolean quiet) {
     readLock();
     try {
       if (bpNSInfo != null) {
         return bpNSInfo.getBlockPoolID();
       } else {
-        LOG.warn("Block pool ID needed, but service not yet registered with " +
-                "NN, trace:", new Exception());
+        if (!quiet) {
+          LOG.warn("Block pool ID needed, but service not yet registered with "
+              + "NN, trace:", new Exception());
+        }
         return null;
       }
     } finally {
@@ -198,6 +200,10 @@ class BPOfferService {
     }
   }
 
+  String getBlockPoolId() {
+    return getBlockPoolId(false);
+  }
+
   boolean hasBlockPoolId() {
     return getNamespaceInfo() != null;
   }

+ 2 - 2
hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/datanode/BPServiceActor.java

@@ -553,8 +553,8 @@ class BPServiceActor implements Runnable {
   private String formatThreadName(
       final String action,
       final InetSocketAddress addr) {
-    final String prefix = bpos.getBlockPoolId() != null ? bpos.getBlockPoolId()
-        : bpos.getNameserviceId();
+    String bpId = bpos.getBlockPoolId(true);
+    final String prefix = bpId != null ? bpId : bpos.getNameserviceId();
     return prefix + " " + action + " to " + addr;
   }