HBASE-23024 Replace initcause with Constructor arg (#627)

Signed-off-by: Peter Somogyi <psomogyi@apache.org>
This commit is contained in:
Viraj Jasani 2019-09-17 17:09:26 +05:30 committed by Peter Somogyi
parent 9198525501
commit 0dbae8f0e1
16 changed files with 79 additions and 55 deletions

View File

@ -40,4 +40,14 @@ public class DroppedSnapshotException extends IOException {
public DroppedSnapshotException(String message) {
super(message);
}
/**
* DroppedSnapshotException with cause
*
* @param message the message for this exception
* @param cause the cause for this exception
*/
public DroppedSnapshotException(String message, Throwable cause) {
super(message, cause);
}
}

View File

@ -33,4 +33,13 @@ public class ConnectionClosedException extends HBaseIOException {
super(string);
}
/**
* ConnectionClosedException with cause
*
* @param message the message for this exception
* @param cause the cause for this exception
*/
public ConnectionClosedException(String message, Throwable cause) {
super(message, cause);
}
}

View File

@ -53,5 +53,15 @@ public class ConnectionClosingException extends IOException {
super(string);
}
/**
* ConnectionClosingException with cause
*
* @param message the message for this exception
* @param cause the cause for this exception
*/
public ConnectionClosingException(String message, Throwable cause) {
super(message, cause);
}
private static final long serialVersionUID = -8980028569652624236L;
}

View File

@ -410,7 +410,7 @@ class BlockingRpcConnection extends RpcConnection implements Runnable {
String msg = "Couldn't setup connection for "
+ UserGroupInformation.getLoginUser().getUserName() + " to " + serverPrincipal;
LOG.warn(msg, ex);
throw (IOException) new IOException(msg).initCause(ex);
throw new IOException(msg, ex);
}
} else {
LOG.warn("Exception encountered while connecting to " + "the server : " + ex);

View File

@ -30,4 +30,14 @@ public class CallTimeoutException extends HBaseIOException {
public CallTimeoutException(final String msg) {
super(msg);
}
/**
* CallTimeoutException with cause
*
* @param message the message for this exception
* @param cause the cause for this exception
*/
public CallTimeoutException(final String message, final Throwable cause) {
super(message, cause);
}
}

View File

@ -180,8 +180,8 @@ class IPCUtil {
return (IOException) new SocketTimeoutException(
"Call to " + addr + " failed because " + error).initCause(error);
} else if (error instanceof ConnectionClosingException) {
return (IOException) new ConnectionClosingException(
"Call to " + addr + " failed on local exception: " + error).initCause(error);
return new ConnectionClosingException("Call to " + addr + " failed on local exception: "
+ error, error);
} else if (error instanceof ServerTooBusyException) {
// we already have address in the exception message
return (IOException) error;
@ -195,22 +195,22 @@ class IPCUtil {
| InvocationTargetException | NoSuchMethodException | SecurityException e) {
// just ignore, will just new a DoNotRetryIOException instead below
}
return (IOException) new DoNotRetryIOException(
"Call to " + addr + " failed on local exception: " + error).initCause(error);
return new DoNotRetryIOException("Call to " + addr + " failed on local exception: "
+ error, error);
} else if (error instanceof ConnectionClosedException) {
return (IOException) new ConnectionClosedException(
"Call to " + addr + " failed on local exception: " + error).initCause(error);
return new ConnectionClosedException("Call to " + addr + " failed on local exception: "
+ error, error);
} else if (error instanceof CallTimeoutException) {
return (IOException) new CallTimeoutException(
"Call to " + addr + " failed on local exception: " + error).initCause(error);
return new CallTimeoutException("Call to " + addr + " failed on local exception: "
+ error, error);
} else if (error instanceof ClosedChannelException) {
// ClosedChannelException does not have a constructor which takes a String but it is a
// connection exception so we keep its original type
return (IOException) error;
} else if (error instanceof TimeoutException) {
// TimeoutException is not an IOException, let's convert it to TimeoutIOException.
return (IOException) new TimeoutIOException(
"Call to " + addr + " failed on local exception: " + error).initCause(error);
return new TimeoutIOException("Call to " + addr + " failed on local exception: "
+ error, error);
} else {
// try our best to keep the original exception type
if (error instanceof IOException) {
@ -224,8 +224,8 @@ class IPCUtil {
// just ignore, will just new an IOException instead below
}
}
return (IOException) new HBaseIOException(
"Call to " + addr + " failed on local exception: " + error).initCause(error);
return new HBaseIOException("Call to " + addr + " failed on local exception: "
+ error, error);
}
}

View File

@ -309,10 +309,8 @@ public abstract class CommonFSUtils {
}
return root;
} catch (URISyntaxException e) {
IOException io = new IOException("Root directory path is not a valid " +
"URI -- check your " + HConstants.HBASE_DIR + " configuration");
io.initCause(e);
throw io;
throw new IOException("Root directory path is not a valid " +
"URI -- check your " + HConstants.HBASE_DIR + " configuration", e);
}
}

View File

@ -275,9 +275,7 @@ public class MasterFileSystem {
} catch (DeserializationException de) {
LOG.error(HBaseMarkers.FATAL, "Please fix invalid configuration for "
+ HConstants.HBASE_DIR, de);
IOException ioe = new IOException();
ioe.initCause(de);
throw ioe;
throw new IOException(de);
} catch (IllegalArgumentException iae) {
LOG.error(HBaseMarkers.FATAL, "Please fix invalid configuration for "
+ HConstants.HBASE_DIR + " " + rd.toString(), iae);

View File

@ -2877,8 +2877,7 @@ public class HRegion implements HeapSize, PropagatingConfigurationObserver, Regi
wal.abortCacheFlush(this.getRegionInfo().getEncodedNameAsBytes());
}
DroppedSnapshotException dse = new DroppedSnapshotException("region: " +
Bytes.toStringBinary(getRegionInfo().getRegionName()));
dse.initCause(t);
Bytes.toStringBinary(getRegionInfo().getRegionName()), t);
status.abort("Flush failed: " + StringUtils.stringifyException(t));
// Callers for flushcache() should catch DroppedSnapshotException and abort the region server.
@ -5983,8 +5982,7 @@ public class HRegion implements HeapSize, PropagatingConfigurationObserver, Regi
// is reached, it will throw out an Error. This Error needs to be caught so it can
// go ahead to process the minibatch with lock acquired.
LOG.warn("Error to get row lock for " + Bytes.toStringBinary(row) + ", cause: " + error);
IOException ioe = new IOException();
ioe.initCause(error);
IOException ioe = new IOException(error);
TraceUtil.addTimelineAnnotation("Error getting row lock");
throw ioe;
} finally {

View File

@ -149,9 +149,7 @@ public final class SnapshotManifestV1 {
} catch (InterruptedException e) {
throw new InterruptedIOException(e.getMessage());
} catch (ExecutionException e) {
IOException ex = new IOException();
ex.initCause(e.getCause());
throw ex;
throw new IOException(e.getCause());
}
return regionsManifest;
}

View File

@ -178,9 +178,7 @@ public final class SnapshotManifestV2 {
if(t instanceof InvalidProtocolBufferException) {
throw (InvalidProtocolBufferException)t;
} else {
IOException ex = new IOException("ExecutionException");
ex.initCause(e.getCause());
throw ex;
throw new IOException("ExecutionException", e.getCause());
}
}
return regionsManifest;

View File

@ -231,9 +231,7 @@ public final class SnapshotReferenceUtil {
throw new CorruptedSnapshotException(e.getCause().getMessage(),
ProtobufUtil.createSnapshotDesc(snapshotDesc));
} else {
IOException ex = new IOException();
ex.initCause(e.getCause());
throw ex;
throw new IOException(e.getCause());
}
}
}

View File

@ -266,9 +266,7 @@ public abstract class FSUtils extends CommonFSUtils {
} catch (Exception e) {
LOG.error("file system close failed: ", e);
}
IOException io = new IOException("File system is not available");
io.initCause(exception);
throw io;
throw new IOException("File system is not available", exception);
}
/**

View File

@ -91,9 +91,7 @@ public class JVMClusterUtil {
hrsc.toString() + ((target.getCause() != null)?
target.getCause().getMessage(): ""), target);
} catch (Exception e) {
IOException ioe = new IOException();
ioe.initCause(e);
throw ioe;
throw new IOException(e);
}
return new JVMClusterUtil.RegionServerThread(server, index);
}
@ -136,9 +134,7 @@ public class JVMClusterUtil {
hmc.toString() + ((target.getCause() != null)?
target.getCause().getMessage(): ""), target);
} catch (Exception e) {
IOException ioe = new IOException();
ioe.initCause(e);
throw ioe;
throw new IOException(e);
}
return new JVMClusterUtil.MasterThread(server, index);
}

View File

@ -218,9 +218,7 @@ public abstract class ModifyRegionUtils {
} catch (InterruptedException e) {
throw new InterruptedIOException(e.getMessage());
} catch (ExecutionException e) {
IOException ex = new IOException();
ex.initCause(e.getCause());
throw ex;
throw new IOException(e.getCause());
}
}

View File

@ -377,11 +377,8 @@ public class WALSplitter {
if (!skipErrors || e instanceof InterruptedIOException) {
throw e; // Don't mark the file corrupted if interrupted, or not skipErrors
}
CorruptedLogFileException t =
new CorruptedLogFileException("skipErrors=true Could not open wal " +
path + " ignoring");
t.initCause(e);
throw t;
throw new CorruptedLogFileException("skipErrors=true Could not open wal "
+ path + " ignoring", e);
}
return in;
}
@ -405,11 +402,8 @@ public class WALSplitter {
if (!skipErrors) {
throw e;
}
CorruptedLogFileException t =
new CorruptedLogFileException("skipErrors=true Ignoring exception" + " while parsing wal "
+ path + ". Marking as corrupted");
t.initCause(e);
throw t;
throw new CorruptedLogFileException("skipErrors=true Ignoring exception"
+ " while parsing wal " + path + ". Marking as corrupted", e);
}
}
@ -570,5 +564,16 @@ public class WALSplitter {
CorruptedLogFileException(String s) {
super(s);
}
/**
* CorruptedLogFileException with cause
*
* @param message the message for this exception
* @param cause the cause for this exception
*/
CorruptedLogFileException(String message, Throwable cause) {
super(message, cause);
}
}
}