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 00e6b3ecb0..e0daca78b9 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 @@ -70,7 +70,8 @@ class BPOfferService { * handshake. */ volatile DatanodeRegistration bpRegistration; - + + private final String nameserviceId; private final DataNode dn; /** @@ -120,12 +121,16 @@ class BPOfferService { mWriteLock.unlock(); } - BPOfferService(List nnAddrs, - List lifelineNnAddrs, DataNode dn) { + BPOfferService( + final String nameserviceId, + List nnAddrs, + List lifelineNnAddrs, + DataNode dn) { Preconditions.checkArgument(!nnAddrs.isEmpty(), "Must pass at least one NN."); Preconditions.checkArgument(nnAddrs.size() == lifelineNnAddrs.size(), "Must pass same number of NN addresses and lifeline addresses."); + this.nameserviceId = nameserviceId; this.dn = dn; for (int i = 0; i < nnAddrs.size(); ++i) { @@ -170,6 +175,14 @@ class BPOfferService { return false; } + /** + * Gets nameservice id to which this {@link BPOfferService} maps to. + * @return nameservice id, which can be null. + */ + String getNameserviceId() { + return nameserviceId; + } + String getBlockPoolId() { readLock(); try { 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 ddc28b72a7..21e2a3b518 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 @@ -25,7 +25,6 @@ import java.io.IOException; import java.net.InetSocketAddress; import java.net.SocketTimeoutException; import java.util.ArrayList; -import java.util.Collection; import java.util.Collections; import java.util.HashMap; import java.util.LinkedList; @@ -279,7 +278,10 @@ class BPServiceActor implements Runnable { // This also initializes our block pool in the DN if we are // the first NN connection for this BP. bpos.verifyAndSetNamespaceInfo(this, nsInfo); - + + /* set thread name again to include NamespaceInfo when it's available. */ + this.bpThread.setName(formatThreadName("heartbeating", nnAddr)); + // Second phase of the handshake with the NN. register(nsInfo); } @@ -547,14 +549,15 @@ class BPServiceActor implements Runnable { lifelineSender.start(); } } - - private String formatThreadName(String action, InetSocketAddress addr) { - Collection dataDirs = - DataNode.getStorageLocations(dn.getConf()); - return "DataNode: [" + dataDirs.toString() + "] " + - action + " to " + addr; + + private String formatThreadName( + final String action, + final InetSocketAddress addr) { + final String prefix = bpos.getBlockPoolId() != null ? bpos.getBlockPoolId() + : bpos.getNameserviceId(); + return prefix + " " + action + " to " + addr; } - + //This must be called only by blockPoolManager. void stop() { shouldServiceRun = false; @@ -1008,8 +1011,8 @@ class BPServiceActor implements Runnable { } public void start() { - lifelineThread = new Thread(this, formatThreadName("lifeline", - lifelineNnAddr)); + lifelineThread = new Thread(this, + formatThreadName("lifeline", lifelineNnAddr)); lifelineThread.setDaemon(true); lifelineThread.setUncaughtExceptionHandler( new Thread.UncaughtExceptionHandler() { diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/datanode/BlockPoolManager.java b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/datanode/BlockPoolManager.java index e94bbb762f..f6a11c24bb 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/datanode/BlockPoolManager.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/datanode/BlockPoolManager.java @@ -211,7 +211,7 @@ class BlockPoolManager { lifelineAddrs.add(nnIdToLifelineAddr != null ? nnIdToLifelineAddr.get(nnId) : null); } - BPOfferService bpos = createBPOS(addrs, lifelineAddrs); + BPOfferService bpos = createBPOS(nsToAdd, addrs, lifelineAddrs); bpByNameserviceId.put(nsToAdd, bpos); offerServices.add(bpos); } @@ -261,8 +261,10 @@ class BlockPoolManager { /** * Extracted out for test purposes. */ - protected BPOfferService createBPOS(List nnAddrs, + protected BPOfferService createBPOS( + final String nameserviceId, + List nnAddrs, List lifelineNnAddrs) { - return new BPOfferService(nnAddrs, lifelineNnAddrs, dn); + return new BPOfferService(nameserviceId, nnAddrs, lifelineNnAddrs, dn); } } diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/datanode/TestBPOfferService.java b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/datanode/TestBPOfferService.java index b9220e0f6c..aa47eeb3e3 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/datanode/TestBPOfferService.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/datanode/TestBPOfferService.java @@ -412,7 +412,7 @@ public class TestBPOfferService { Mockito.eq(new InetSocketAddress(port))); } - return new BPOfferService(Lists.newArrayList(nnMap.keySet()), + return new BPOfferService("test_ns", Lists.newArrayList(nnMap.keySet()), Collections.nCopies(nnMap.size(), null), mockDn); } diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/datanode/TestBlockPoolManager.java b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/datanode/TestBlockPoolManager.java index 8bf40e30fa..560b32e0ee 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/datanode/TestBlockPoolManager.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/datanode/TestBlockPoolManager.java @@ -51,7 +51,9 @@ public class TestBlockPoolManager { bpm = new BlockPoolManager(mockDN){ @Override - protected BPOfferService createBPOS(List nnAddrs, + protected BPOfferService createBPOS( + final String nameserviceId, + List nnAddrs, List lifelineNnAddrs) { final int idx = mockIdx++; doLog("create #" + idx);