diff --git a/hbase-client/src/main/java/org/apache/hadoop/hbase/client/FastFailInterceptorContext.java b/hbase-client/src/main/java/org/apache/hadoop/hbase/client/FastFailInterceptorContext.java index 9eb56bc..3cbdfb3 100644 --- a/hbase-client/src/main/java/org/apache/hadoop/hbase/client/FastFailInterceptorContext.java +++ b/hbase-client/src/main/java/org/apache/hadoop/hbase/client/FastFailInterceptorContext.java @@ -27,8 +27,10 @@ class FastFailInterceptorContext extends // The variable that indicates whether we were able to connect with the server // in the last run - private MutableBoolean couldNotCommunicateWithServer = new MutableBoolean( - false); + private MutableBoolean couldNotCommunicateWithServer = new MutableBoolean(false); + + // If set, we guarantee that no modifications went to server + private MutableBoolean guaranteedClientSideOnly = new MutableBoolean(false); // The variable which indicates whether this was a retry or the first time private boolean didTry = false; @@ -53,6 +55,10 @@ class FastFailInterceptorContext extends return couldNotCommunicateWithServer; } + public MutableBoolean getGuaranteedClientSideOnly() { + return guaranteedClientSideOnly; + } + public FailureInfo getFailureInfo() { return fInfo; } @@ -78,6 +84,10 @@ class FastFailInterceptorContext extends this.couldNotCommunicateWithServer = couldNotCommunicateWithServer; } + public void setGuaranteedClientSideOnly(MutableBoolean guaranteedClientSideOnly) { + this.guaranteedClientSideOnly = guaranteedClientSideOnly; + } + public void setDidTry(boolean didTry) { this.didTry = didTry; } @@ -103,6 +113,7 @@ class FastFailInterceptorContext extends fInfo = null; didTry = false; couldNotCommunicateWithServer.setValue(false); + guaranteedClientSideOnly.setValue(false); retryDespiteFastFailMode = false; tries = 0; } diff --git a/hbase-client/src/main/java/org/apache/hadoop/hbase/client/PreemptiveFastFailInterceptor.java b/hbase-client/src/main/java/org/apache/hadoop/hbase/client/PreemptiveFastFailInterceptor.java index ce21ee9..a457623 100644 --- a/hbase-client/src/main/java/org/apache/hadoop/hbase/client/PreemptiveFastFailInterceptor.java +++ b/hbase-client/src/main/java/org/apache/hadoop/hbase/client/PreemptiveFastFailInterceptor.java @@ -39,6 +39,7 @@ import org.apache.hadoop.hbase.ServerName; import org.apache.hadoop.hbase.classification.InterfaceAudience; import org.apache.hadoop.hbase.exceptions.ConnectionClosingException; import org.apache.hadoop.hbase.exceptions.PreemptiveFastFailException; +import org.apache.hadoop.hbase.ipc.CallTimeoutException; import org.apache.hadoop.hbase.ipc.FailedServerException; import org.apache.hadoop.hbase.util.EnvironmentEdgeManager; import org.apache.hadoop.ipc.RemoteException; @@ -124,7 +125,8 @@ class PreemptiveFastFailInterceptor extends RetryingCallerInterceptor { throw new PreemptiveFastFailException( context.getFailureInfo().numConsecutiveFailures.get(), context.getFailureInfo().timeOfFirstFailureMilliSec, - context.getFailureInfo().timeOfLatestAttemptMilliSec, context.getServer()); + context.getFailureInfo().timeOfLatestAttemptMilliSec, context.getServer(), + context.getGuaranteedClientSideOnly().isTrue()); } } context.setDidTry(true); @@ -133,7 +135,8 @@ class PreemptiveFastFailInterceptor extends RetryingCallerInterceptor { public void handleFailure(FastFailInterceptorContext context, Throwable t) throws IOException { handleThrowable(t, context.getServer(), - context.getCouldNotCommunicateWithServer()); + context.getCouldNotCommunicateWithServer(), + context.getGuaranteedClientSideOnly()); } public void updateFailureInfo(FastFailInterceptorContext context) { @@ -172,11 +175,13 @@ class PreemptiveFastFailInterceptor extends RetryingCallerInterceptor { } public void handleThrowable(Throwable t1, ServerName serverName, - MutableBoolean couldNotCommunicateWithServer) throws IOException { + MutableBoolean couldNotCommunicateWithServer, + MutableBoolean guaranteedClientSideOnly) throws IOException { Throwable t2 = translateException(t1); boolean isLocalException = !(t2 instanceof RemoteException); if (isLocalException && isConnectionException(t2)) { couldNotCommunicateWithServer.setValue(true); + guaranteedClientSideOnly.setValue((t2 instanceof CallTimeoutException)); handleFailureToServer(serverName, t2); } } @@ -228,7 +233,7 @@ class PreemptiveFastFailInterceptor extends RetryingCallerInterceptor { return (e instanceof SocketTimeoutException || e instanceof ConnectException || e instanceof ClosedChannelException || e instanceof SyncFailedException || e instanceof EOFException - || e instanceof TimeoutException + || e instanceof TimeoutException || e instanceof CallTimeoutException || e instanceof ConnectionClosingException || e instanceof FailedServerException); } diff --git a/hbase-client/src/main/java/org/apache/hadoop/hbase/exceptions/PreemptiveFastFailException.java b/hbase-client/src/main/java/org/apache/hadoop/hbase/exceptions/PreemptiveFastFailException.java index 51c960d..44cfce8 100644 --- a/hbase-client/src/main/java/org/apache/hadoop/hbase/exceptions/PreemptiveFastFailException.java +++ b/hbase-client/src/main/java/org/apache/hadoop/hbase/exceptions/PreemptiveFastFailException.java @@ -38,6 +38,9 @@ import org.apache.hadoop.hbase.ServerName; private static final long serialVersionUID = 7129103682617007177L; private long failureCount, timeOfFirstFailureMilliSec, timeOfLatestAttemptMilliSec; + // If set, we guarantee that no modifications went to server + private boolean guaranteedClientSideOnly; + /** * @param count * @param timeOfFirstFailureMilliSec @@ -52,6 +55,23 @@ import org.apache.hadoop.hbase.ServerName; this.timeOfLatestAttemptMilliSec = timeOfLatestAttemptMilliSec; } + /** + * @param count + * @param timeOfFirstFailureMilliSec + * @param timeOfLatestAttemptMilliSec + * @param serverName + * @param guaranteedClientSideOnly + */ + public PreemptiveFastFailException(long count, long timeOfFirstFailureMilliSec, + long timeOfLatestAttemptMilliSec, ServerName serverName, + boolean guaranteedClientSideOnly) { + super("Exception happened " + count + " times. to" + serverName); + this.failureCount = count; + this.timeOfFirstFailureMilliSec = timeOfFirstFailureMilliSec; + this.timeOfLatestAttemptMilliSec = timeOfLatestAttemptMilliSec; + this.guaranteedClientSideOnly = guaranteedClientSideOnly; + } + public long getFirstFailureAt() { return timeOfFirstFailureMilliSec; } @@ -67,4 +87,8 @@ import org.apache.hadoop.hbase.ServerName; public boolean wasOperationAttemptedByServer() { return false; } + + public boolean isGuaranteedClientSideOnly() { + return guaranteedClientSideOnly; + } } \ No newline at end of file