From 0dbae8f0e19dbe1d508ca2ed033f23e2a8f59ce3 Mon Sep 17 00:00:00 2001 From: Viraj Jasani Date: Tue, 17 Sep 2019 17:09:26 +0530 Subject: [PATCH] HBASE-23024 Replace initcause with Constructor arg (#627) Signed-off-by: Peter Somogyi --- .../hbase/DroppedSnapshotException.java | 10 ++++++++ .../exceptions/ConnectionClosedException.java | 9 +++++++ .../ConnectionClosingException.java | 10 ++++++++ .../hbase/ipc/BlockingRpcConnection.java | 2 +- .../hbase/ipc/CallTimeoutException.java | 10 ++++++++ .../org/apache/hadoop/hbase/ipc/IPCUtil.java | 24 +++++++++--------- .../hadoop/hbase/util/CommonFSUtils.java | 6 ++--- .../hadoop/hbase/master/MasterFileSystem.java | 4 +-- .../hadoop/hbase/regionserver/HRegion.java | 6 ++--- .../hbase/snapshot/SnapshotManifestV1.java | 4 +-- .../hbase/snapshot/SnapshotManifestV2.java | 4 +-- .../hbase/snapshot/SnapshotReferenceUtil.java | 4 +-- .../org/apache/hadoop/hbase/util/FSUtils.java | 4 +-- .../hadoop/hbase/util/JVMClusterUtil.java | 8 ++---- .../hadoop/hbase/util/ModifyRegionUtils.java | 4 +-- .../apache/hadoop/hbase/wal/WALSplitter.java | 25 +++++++++++-------- 16 files changed, 79 insertions(+), 55 deletions(-) diff --git a/hbase-client/src/main/java/org/apache/hadoop/hbase/DroppedSnapshotException.java b/hbase-client/src/main/java/org/apache/hadoop/hbase/DroppedSnapshotException.java index 263c4587534..76f374c412f 100644 --- a/hbase-client/src/main/java/org/apache/hadoop/hbase/DroppedSnapshotException.java +++ b/hbase-client/src/main/java/org/apache/hadoop/hbase/DroppedSnapshotException.java @@ -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); + } } diff --git a/hbase-client/src/main/java/org/apache/hadoop/hbase/exceptions/ConnectionClosedException.java b/hbase-client/src/main/java/org/apache/hadoop/hbase/exceptions/ConnectionClosedException.java index c595c1422c7..b479f145a67 100644 --- a/hbase-client/src/main/java/org/apache/hadoop/hbase/exceptions/ConnectionClosedException.java +++ b/hbase-client/src/main/java/org/apache/hadoop/hbase/exceptions/ConnectionClosedException.java @@ -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); + } } diff --git a/hbase-client/src/main/java/org/apache/hadoop/hbase/exceptions/ConnectionClosingException.java b/hbase-client/src/main/java/org/apache/hadoop/hbase/exceptions/ConnectionClosingException.java index 21ecd62024d..ab20cbc9abf 100644 --- a/hbase-client/src/main/java/org/apache/hadoop/hbase/exceptions/ConnectionClosingException.java +++ b/hbase-client/src/main/java/org/apache/hadoop/hbase/exceptions/ConnectionClosingException.java @@ -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; } diff --git a/hbase-client/src/main/java/org/apache/hadoop/hbase/ipc/BlockingRpcConnection.java b/hbase-client/src/main/java/org/apache/hadoop/hbase/ipc/BlockingRpcConnection.java index ee0aeeaad2f..6df2a3946fd 100644 --- a/hbase-client/src/main/java/org/apache/hadoop/hbase/ipc/BlockingRpcConnection.java +++ b/hbase-client/src/main/java/org/apache/hadoop/hbase/ipc/BlockingRpcConnection.java @@ -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); diff --git a/hbase-client/src/main/java/org/apache/hadoop/hbase/ipc/CallTimeoutException.java b/hbase-client/src/main/java/org/apache/hadoop/hbase/ipc/CallTimeoutException.java index 4573c457f6e..d4105a09fa3 100644 --- a/hbase-client/src/main/java/org/apache/hadoop/hbase/ipc/CallTimeoutException.java +++ b/hbase-client/src/main/java/org/apache/hadoop/hbase/ipc/CallTimeoutException.java @@ -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); + } } diff --git a/hbase-client/src/main/java/org/apache/hadoop/hbase/ipc/IPCUtil.java b/hbase-client/src/main/java/org/apache/hadoop/hbase/ipc/IPCUtil.java index 46562c514fb..e9981b3ed7a 100644 --- a/hbase-client/src/main/java/org/apache/hadoop/hbase/ipc/IPCUtil.java +++ b/hbase-client/src/main/java/org/apache/hadoop/hbase/ipc/IPCUtil.java @@ -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); } } diff --git a/hbase-common/src/main/java/org/apache/hadoop/hbase/util/CommonFSUtils.java b/hbase-common/src/main/java/org/apache/hadoop/hbase/util/CommonFSUtils.java index a9b361ce1da..fa916ff3c5b 100644 --- a/hbase-common/src/main/java/org/apache/hadoop/hbase/util/CommonFSUtils.java +++ b/hbase-common/src/main/java/org/apache/hadoop/hbase/util/CommonFSUtils.java @@ -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); } } diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/master/MasterFileSystem.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/master/MasterFileSystem.java index e5443008eb7..21a94956ea6 100644 --- a/hbase-server/src/main/java/org/apache/hadoop/hbase/master/MasterFileSystem.java +++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/master/MasterFileSystem.java @@ -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); diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/HRegion.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/HRegion.java index 29e143c4206..559432769b9 100644 --- a/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/HRegion.java +++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/HRegion.java @@ -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 { diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/snapshot/SnapshotManifestV1.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/snapshot/SnapshotManifestV1.java index 53c59b5e84f..742ac2eedd3 100644 --- a/hbase-server/src/main/java/org/apache/hadoop/hbase/snapshot/SnapshotManifestV1.java +++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/snapshot/SnapshotManifestV1.java @@ -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; } diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/snapshot/SnapshotManifestV2.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/snapshot/SnapshotManifestV2.java index 6f22d9d5e0f..f5b97a07a4d 100644 --- a/hbase-server/src/main/java/org/apache/hadoop/hbase/snapshot/SnapshotManifestV2.java +++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/snapshot/SnapshotManifestV2.java @@ -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; diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/snapshot/SnapshotReferenceUtil.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/snapshot/SnapshotReferenceUtil.java index b157d01e191..bc22e27ddea 100644 --- a/hbase-server/src/main/java/org/apache/hadoop/hbase/snapshot/SnapshotReferenceUtil.java +++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/snapshot/SnapshotReferenceUtil.java @@ -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()); } } } diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/util/FSUtils.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/util/FSUtils.java index f65f980ecd9..b30d3499f21 100644 --- a/hbase-server/src/main/java/org/apache/hadoop/hbase/util/FSUtils.java +++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/util/FSUtils.java @@ -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); } /** diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/util/JVMClusterUtil.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/util/JVMClusterUtil.java index 7518d65a198..5c6ad955fe2 100644 --- a/hbase-server/src/main/java/org/apache/hadoop/hbase/util/JVMClusterUtil.java +++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/util/JVMClusterUtil.java @@ -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); } diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/util/ModifyRegionUtils.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/util/ModifyRegionUtils.java index 79544fbfa92..683d17529e5 100644 --- a/hbase-server/src/main/java/org/apache/hadoop/hbase/util/ModifyRegionUtils.java +++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/util/ModifyRegionUtils.java @@ -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()); } } diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/wal/WALSplitter.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/wal/WALSplitter.java index d96916b3b51..08166d2e034 100644 --- a/hbase-server/src/main/java/org/apache/hadoop/hbase/wal/WALSplitter.java +++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/wal/WALSplitter.java @@ -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); + } + } }