HDFS-11558. BPServiceActor thread name is too long. Contributed by Xiaobing Zhou

This commit is contained in:
Mingliang Liu 2017-04-12 11:47:34 -07:00
parent 9dfe0b3515
commit 9eebbcf459
5 changed files with 39 additions and 18 deletions

View File

@ -68,7 +68,8 @@ class BPOfferService {
* handshake.
*/
volatile DatanodeRegistration bpRegistration;
private final String nameserviceId;
private final DataNode dn;
/**
@ -118,12 +119,16 @@ class BPOfferService {
mWriteLock.unlock();
}
BPOfferService(List<InetSocketAddress> nnAddrs,
List<InetSocketAddress> lifelineNnAddrs, DataNode dn) {
BPOfferService(
final String nameserviceId,
List<InetSocketAddress> nnAddrs,
List<InetSocketAddress> 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) {
@ -168,6 +173,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 {

View File

@ -264,7 +264,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);
}
@ -483,14 +486,15 @@ class BPServiceActor implements Runnable {
lifelineSender.start();
}
}
private String formatThreadName(String action, InetSocketAddress addr) {
Collection<StorageLocation> 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;
@ -944,8 +948,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() {

View File

@ -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<InetSocketAddress> nnAddrs,
protected BPOfferService createBPOS(
final String nameserviceId,
List<InetSocketAddress> nnAddrs,
List<InetSocketAddress> lifelineNnAddrs) {
return new BPOfferService(nnAddrs, lifelineNnAddrs, dn);
return new BPOfferService(nameserviceId, nnAddrs, lifelineNnAddrs, dn);
}
}

View File

@ -408,7 +408,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.<InetSocketAddress>nCopies(nnMap.size(), null), mockDn);
}

View File

@ -51,7 +51,9 @@ public class TestBlockPoolManager {
bpm = new BlockPoolManager(mockDN){
@Override
protected BPOfferService createBPOS(List<InetSocketAddress> nnAddrs,
protected BPOfferService createBPOS(
final String nameserviceId,
List<InetSocketAddress> nnAddrs,
List<InetSocketAddress> lifelineNnAddrs) {
final int idx = mockIdx++;
doLog("create #" + idx);