Browse Source

HDFS-16627. Improve BPServiceActor#register log to add NameNode address. (#4419). Contributed by fanshilun.

slfan1989 2 years ago
parent
commit
02c21ef8c3

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

@@ -816,7 +816,7 @@ class BPServiceActor implements Runnable {
     // off disk - so update the bpRegistration object from that info
     // off disk - so update the bpRegistration object from that info
     DatanodeRegistration newBpRegistration = bpos.createRegistration();
     DatanodeRegistration newBpRegistration = bpos.createRegistration();
 
 
-    LOG.info(this + " beginning handshake with NN");
+    LOG.info("{} beginning handshake with NN: {}.", this, nnAddr);
 
 
     while (shouldRun()) {
     while (shouldRun()) {
       try {
       try {
@@ -826,15 +826,14 @@ class BPServiceActor implements Runnable {
         bpRegistration = newBpRegistration;
         bpRegistration = newBpRegistration;
         break;
         break;
       } catch(EOFException e) {  // namenode might have just restarted
       } catch(EOFException e) {  // namenode might have just restarted
-        LOG.info("Problem connecting to server: " + nnAddr + " :"
-            + e.getLocalizedMessage());
+        LOG.info("Problem connecting to server: {} : {}.", nnAddr, e.getLocalizedMessage());
       } catch(SocketTimeoutException e) {  // namenode is busy
       } catch(SocketTimeoutException e) {  // namenode is busy
-        LOG.info("Problem connecting to server: " + nnAddr);
+        LOG.info("Problem connecting to server: {}.", nnAddr);
       } catch(RemoteException e) {
       } catch(RemoteException e) {
-        LOG.warn("RemoteException in register", e);
+        LOG.warn("RemoteException in register to server: {}.", nnAddr, e);
         throw e;
         throw e;
       } catch(IOException e) {
       } catch(IOException e) {
-        LOG.warn("Problem connecting to server: " + nnAddr);
+        LOG.warn("Problem connecting to server: {}.", nnAddr);
       }
       }
       // Try again in a second
       // Try again in a second
       sleepAndLogInterrupts(1000, "connecting to server");
       sleepAndLogInterrupts(1000, "connecting to server");
@@ -844,7 +843,7 @@ class BPServiceActor implements Runnable {
       throw new IOException("DN shut down before block pool registered");
       throw new IOException("DN shut down before block pool registered");
     }
     }
 
 
-    LOG.info(this + " successfully registered with NN");
+    LOG.info("{} successfully registered with NN: {}.", this, nnAddr);
     bpos.registrationSucceeded(this, bpRegistration);
     bpos.registrationSucceeded(this, bpRegistration);
 
 
     // reset lease id whenever registered to NN.
     // reset lease id whenever registered to NN.

+ 2 - 2
hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/datanode/TestDatanodeRegister.java

@@ -76,7 +76,7 @@ public class TestDatanodeRegister {
     actor = new BPServiceActor("test", "test", INVALID_ADDR, null, mockBPOS);
     actor = new BPServiceActor("test", "test", INVALID_ADDR, null, mockBPOS);
 
 
     fakeNsInfo = mock(NamespaceInfo.class);
     fakeNsInfo = mock(NamespaceInfo.class);
-    // Return a a good software version.
+    // Return a good software version.
     doReturn(VersionInfo.getVersion()).when(fakeNsInfo).getSoftwareVersion();
     doReturn(VersionInfo.getVersion()).when(fakeNsInfo).getSoftwareVersion();
     // Return a good layout version for now.
     // Return a good layout version for now.
     doReturn(HdfsServerConstants.NAMENODE_LAYOUT_VERSION).when(fakeNsInfo)
     doReturn(HdfsServerConstants.NAMENODE_LAYOUT_VERSION).when(fakeNsInfo)
@@ -144,7 +144,7 @@ public class TestDatanodeRegister {
     DataNode dn = new DataNode(conf, locations, null, null);
     DataNode dn = new DataNode(conf, locations, null, null);
     BPOfferService bpos = new BPOfferService("test_ns",
     BPOfferService bpos = new BPOfferService("test_ns",
         Lists.newArrayList("nn0"), Lists.newArrayList(nnADDR),
         Lists.newArrayList("nn0"), Lists.newArrayList(nnADDR),
-        Collections.<InetSocketAddress>nCopies(1, null), dn);
+        Collections.nCopies(1, null), dn);
     DatanodeProtocolClientSideTranslatorPB fakeDnProt =
     DatanodeProtocolClientSideTranslatorPB fakeDnProt =
         mock(DatanodeProtocolClientSideTranslatorPB.class);
         mock(DatanodeProtocolClientSideTranslatorPB.class);
     when(fakeDnProt.versionRequest()).thenReturn(fakeNsInfo);
     when(fakeDnProt.versionRequest()).thenReturn(fakeNsInfo);