Skip to content

Commit

Permalink
HBASE-23024 Replace initcause with Constructor arg (#627)
Browse files Browse the repository at this point in the history
Signed-off-by: Peter Somogyi <[email protected]>
  • Loading branch information
virajjasani authored and petersomogyi committed Sep 17, 2019
1 parent 9198525 commit 0dbae8f
Show file tree
Hide file tree
Showing 16 changed files with 79 additions and 55 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,14 @@ public DroppedSnapshotException() {
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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,13 @@ public ConnectionClosedException(String string) {
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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -53,5 +53,15 @@ public ConnectionClosingException(String string) {
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;
}
Original file line number Diff line number Diff line change
Expand Up @@ -410,7 +410,7 @@ public Object run() throws IOException, InterruptedException {
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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
24 changes: 12 additions & 12 deletions hbase-client/src/main/java/org/apache/hadoop/hbase/ipc/IPCUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -180,8 +180,8 @@ static IOException wrapException(InetSocketAddress addr, Throwable error) {
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;
Expand All @@ -195,22 +195,22 @@ static IOException wrapException(InetSocketAddress addr, Throwable error) {
| 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) {
Expand All @@ -224,8 +224,8 @@ static IOException wrapException(InetSocketAddress addr, Throwable error) {
// 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);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -309,10 +309,8 @@ public static Path validateRootPath(Path root) throws IOException {
}
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);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -275,9 +275,7 @@ private Path checkRootDir(final Path rd, final Configuration c, final FileSystem
} 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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2877,8 +2877,7 @@ protected FlushResultImpl internalFlushCacheAndCommit(WAL wal, MonitoredTask sta
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.
Expand Down Expand Up @@ -5983,8 +5982,7 @@ protected RowLock getRowLockInternal(byte[] row, boolean readLock, final RowLock
// 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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,9 +149,7 @@ public SnapshotRegionManifest call() throws IOException {
} 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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -178,9 +178,7 @@ public SnapshotRegionManifest call() throws IOException {
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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -231,9 +231,7 @@ public static void concurrentVisitReferencedFiles(final Configuration conf, fina
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());
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -266,9 +266,7 @@ public static void checkFileSystemAvailable(final FileSystem fs)
} 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);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,9 +91,7 @@ public static JVMClusterUtil.RegionServerThread createRegionServerThread(final C
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);
}
Expand Down Expand Up @@ -136,9 +134,7 @@ public static JVMClusterUtil.MasterThread createMasterThread(final Configuration
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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -218,9 +218,7 @@ public Void call() throws IOException {
} 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());
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -377,11 +377,8 @@ protected Reader getReader(FileStatus file, boolean skipErrors, CancelableProgre
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;
}
Expand All @@ -405,11 +402,8 @@ static private Entry getNextLogLine(Reader in, Path path, boolean skipErrors)
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);
}
}

Expand Down Expand Up @@ -570,5 +564,16 @@ static class CorruptedLogFileException extends Exception {
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);
}

}
}

0 comments on commit 0dbae8f

Please sign in to comment.