From 670224ae59f69bb2fdc7b988bf6641dd95958e5a Mon Sep 17 00:00:00 2001 From: Tsz-Wo Nicholas Sze Date: Tue, 13 Jun 2017 09:45:10 +0800 Subject: [PATCH] HDFS-11947. When constructing a thread name, BPOfferService may print a bogus warning message. Contributed by Weiwei Yang --- .../hadoop/hdfs/server/datanode/BPOfferService.java | 12 +++++++++--- .../hadoop/hdfs/server/datanode/BPServiceActor.java | 4 ++-- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/datanode/BPOfferService.java b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/datanode/BPOfferService.java index 5466f1fc718..ccc39a67481 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/datanode/BPOfferService.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/datanode/BPOfferService.java @@ -181,14 +181,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 { @@ -196,6 +198,10 @@ class BPOfferService { } } + String getBlockPoolId() { + return getBlockPoolId(false); + } + boolean hasBlockPoolId() { return getNamespaceInfo() != null; } diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/datanode/BPServiceActor.java b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/datanode/BPServiceActor.java index aedfc708610..c26027222af 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/datanode/BPServiceActor.java +++ b/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; }