HDFS-8592. SafeModeException never get unwrapped. Contributed by Haohui Mai.

This commit is contained in:
Haohui Mai 2015-06-15 22:07:24 -07:00
parent e8c514373f
commit 32e39d8a29
4 changed files with 14 additions and 8 deletions

View File

@ -895,6 +895,8 @@ Release 2.8.0 - UNRELEASED
HDFS-8607. TestFileCorruption doesn't work as expected. (Walter Su via HDFS-8607. TestFileCorruption doesn't work as expected. (Walter Su via
Arpit Agarwal) Arpit Agarwal)
HDFS-8592. SafeModeException never get unwrapped. (wheat9)
Release 2.7.1 - UNRELEASED Release 2.7.1 - UNRELEASED
INCOMPATIBLE CHANGES INCOMPATIBLE CHANGES

View File

@ -1323,7 +1323,7 @@ public class FSNamesystem implements Namesystem, FSNamesystemMBean,
void checkNameNodeSafeMode(String errorMsg) void checkNameNodeSafeMode(String errorMsg)
throws RetriableException, SafeModeException { throws RetriableException, SafeModeException {
if (isInSafeMode()) { if (isInSafeMode()) {
SafeModeException se = new SafeModeException(errorMsg, safeMode); SafeModeException se = newSafemodeException(errorMsg);
if (haEnabled && haContext != null if (haEnabled && haContext != null
&& haContext.getState().getServiceState() == HAServiceState.ACTIVE && haContext.getState().getServiceState() == HAServiceState.ACTIVE
&& shouldRetrySafeMode(this.safeMode)) { && shouldRetrySafeMode(this.safeMode)) {
@ -1334,6 +1334,11 @@ public class FSNamesystem implements Namesystem, FSNamesystemMBean,
} }
} }
private SafeModeException newSafemodeException(String errorMsg) {
return new SafeModeException(errorMsg + ". Name node is in safe " +
"mode.\n" + safeMode.getTurnOffTip());
}
boolean isPermissionEnabled() { boolean isPermissionEnabled() {
return isPermissionEnabled; return isPermissionEnabled;
} }
@ -1803,8 +1808,8 @@ public class FSNamesystem implements Namesystem, FSNamesystemMBean,
for (LocatedBlock b : ret.blocks.getLocatedBlocks()) { for (LocatedBlock b : ret.blocks.getLocatedBlocks()) {
// if safemode & no block locations yet then throw safemodeException // if safemode & no block locations yet then throw safemodeException
if ((b.getLocations() == null) || (b.getLocations().length == 0)) { if ((b.getLocations() == null) || (b.getLocations().length == 0)) {
SafeModeException se = new SafeModeException( SafeModeException se = newSafemodeException(
"Zero blocklocations for " + src, safeMode); "Zero blocklocations for " + src);
if (haEnabled && haContext != null && if (haEnabled && haContext != null &&
haContext.getState().getServiceState() == HAServiceState.ACTIVE) { haContext.getState().getServiceState() == HAServiceState.ACTIVE) {
throw new RetriableException(se); throw new RetriableException(se);

View File

@ -32,8 +32,7 @@ import org.apache.hadoop.classification.InterfaceStability;
@InterfaceStability.Evolving @InterfaceStability.Evolving
public class SafeModeException extends IOException { public class SafeModeException extends IOException {
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
public SafeModeException(String msg) {
public SafeModeException(String text, FSNamesystem.SafeModeInfo mode ) { super(msg);
super(text + ". Name node is in safe mode.\n" + mode.getTurnOffTip());
} }
} }

View File

@ -295,8 +295,8 @@ public class TestSafeMode {
fail(msg); fail(msg);
} catch (RemoteException re) { } catch (RemoteException re) {
assertEquals(SafeModeException.class.getName(), re.getClassName()); assertEquals(SafeModeException.class.getName(), re.getClassName());
GenericTestUtils.assertExceptionContains( GenericTestUtils.assertExceptionContains("Name node is in safe mode", re);
"Name node is in safe mode", re); } catch (SafeModeException ignored) {
} catch (IOException ioe) { } catch (IOException ioe) {
fail(msg + " " + StringUtils.stringifyException(ioe)); fail(msg + " " + StringUtils.stringifyException(ioe));
} }