HDFS-10601. Improve log message to include hostname when the NameNode is in safemode. Contributed by Kuhu Shukla.

(cherry picked from commit ba62b50eba)
This commit is contained in:
Kihwal Lee 2017-03-16 11:02:48 -05:00
parent a16ba4296e
commit a264d98017
2 changed files with 30 additions and 1 deletions

View File

@ -109,6 +109,7 @@ import java.io.PrintWriter;
import java.io.StringWriter; import java.io.StringWriter;
import java.lang.management.ManagementFactory; import java.lang.management.ManagementFactory;
import java.net.InetAddress; import java.net.InetAddress;
import java.net.InetSocketAddress;
import java.net.URI; import java.net.URI;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
@ -534,6 +535,7 @@ public class FSNamesystem implements Namesystem, FSNamesystemMBean,
*/ */
private boolean manualSafeMode = false; private boolean manualSafeMode = false;
private boolean resourceLowSafeMode = false; private boolean resourceLowSafeMode = false;
private String nameNodeHostName = null;
/** /**
* Notify that loading of this FSDirectory is complete, and * Notify that loading of this FSDirectory is complete, and
@ -1104,6 +1106,9 @@ public class FSNamesystem implements Namesystem, FSNamesystemMBean,
dir.setINodeAttributeProvider(inodeAttributeProvider); dir.setINodeAttributeProvider(inodeAttributeProvider);
} }
snapshotManager.registerMXBean(); snapshotManager.registerMXBean();
InetSocketAddress serviceAddress = NameNode.getServiceAddress(conf, true);
this.nameNodeHostName = (serviceAddress != null) ?
serviceAddress.getHostName() : "";
} }
/** /**
@ -1371,7 +1376,7 @@ public class FSNamesystem implements Namesystem, FSNamesystemMBean,
private SafeModeException newSafemodeException(String errorMsg) { private SafeModeException newSafemodeException(String errorMsg) {
return new SafeModeException(errorMsg + ". Name node is in safe " + return new SafeModeException(errorMsg + ". Name node is in safe " +
"mode.\n" + getSafeModeTip()); "mode.\n" + getSafeModeTip() + " NamenodeHostName:" + nameNodeHostName);
} }
boolean isPermissionEnabled() { boolean isPermissionEnabled() {

View File

@ -304,6 +304,30 @@ public class TestSafeMode {
} }
} }
@Test
public void testSafeModeExceptionText() throws Exception {
final Path file1 = new Path("/file1");
DFSTestUtil.createFile(fs, file1, 1024, (short)1, 0);
assertTrue("Could not enter SM",
dfs.setSafeMode(SafeModeAction.SAFEMODE_ENTER));
try {
FSRun fsRun = new FSRun() {
@Override
public void run(FileSystem fileSystem) throws IOException {
((DistributedFileSystem)fileSystem).setQuota(file1, 1, 1);
}
};
fsRun.run(fs);
fail("Should not succeed with no exceptions!");
} catch (RemoteException re) {
assertEquals(SafeModeException.class.getName(), re.getClassName());
GenericTestUtils.assertExceptionContains(
NameNode.getServiceAddress(conf, true).getHostName(), re);
} catch (IOException ioe) {
fail("Encountered exception" + " " + StringUtils.stringifyException(ioe));
}
}
/** /**
* Run various fs operations while the NN is in safe mode, * Run various fs operations while the NN is in safe mode,
* assert that they are either allowed or fail as expected. * assert that they are either allowed or fail as expected.