001/**
002 * Licensed to the Apache Software Foundation (ASF) under one
003 * or more contributor license agreements.  See the NOTICE file
004 * distributed with this work for additional information
005 * regarding copyright ownership.  The ASF licenses this file
006 * to you under the Apache License, Version 2.0 (the
007 * "License"); you may not use this file except in compliance
008 * with the License.  You may obtain a copy of the License at
009 *
010 *     http://www.apache.org/licenses/LICENSE-2.0
011 *
012 * Unless required by applicable law or agreed to in writing, software
013 * distributed under the License is distributed on an "AS IS" BASIS,
014 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
015 * See the License for the specific language governing permissions and
016 * limitations under the License.
017 */
018package org.apache.hadoop.hbase.client;
019
020import org.apache.commons.lang3.mutable.MutableBoolean;
021import org.apache.hadoop.hbase.ServerName;
022import org.apache.yetus.audience.InterfaceAudience;
023
024@InterfaceAudience.Private
025class FastFailInterceptorContext extends RetryingCallerInterceptorContext {
026
027  // The variable that indicates whether we were able to connect with the server
028  // in the last run
029  private MutableBoolean couldNotCommunicateWithServer = new MutableBoolean(false);
030
031  // If set, we guarantee that no modifications went to server
032  private MutableBoolean guaranteedClientSideOnly = new MutableBoolean(false);
033
034  // The variable which indicates whether this was a retry or the first time
035  private boolean didTry = false;
036
037  // The failure info that is associated with the machine which we are trying to
038  // contact as part of this attempt.
039  private FailureInfo fInfo = null;
040
041  // Variable indicating that the thread that is currently executing the
042  // operation is in a mode where it would retry instead of failing fast, so
043  // that we can figure out whether making contact with the server is
044  // possible or not.
045  private boolean retryDespiteFastFailMode = false;
046
047  // The server that would be contacted to successfully complete this operation.
048  private ServerName server;
049
050  // The number of the retry we are currenty doing.
051  private int tries;
052
053  public MutableBoolean getCouldNotCommunicateWithServer() {
054    return couldNotCommunicateWithServer;
055  }
056
057  public MutableBoolean getGuaranteedClientSideOnly() {
058    return guaranteedClientSideOnly;
059  }
060
061  public FailureInfo getFailureInfo() {
062    return fInfo;
063  }
064
065  public ServerName getServer() {
066    return server;
067  }
068
069  public int getTries() {
070    return tries;
071  }
072
073  public boolean didTry() {
074    return didTry;
075  }
076
077  public boolean isRetryDespiteFastFailMode() {
078    return retryDespiteFastFailMode;
079  }
080
081  public void setCouldNotCommunicateWithServer(
082      MutableBoolean couldNotCommunicateWithServer) {
083    this.couldNotCommunicateWithServer = couldNotCommunicateWithServer;
084  }
085
086  public void setGuaranteedClientSideOnly(MutableBoolean guaranteedClientSideOnly) {
087    this.guaranteedClientSideOnly = guaranteedClientSideOnly;
088  }
089
090  public void setDidTry(boolean didTry) {
091    this.didTry = didTry;
092  }
093
094  public void setFailureInfo(FailureInfo fInfo) {
095    this.fInfo = fInfo;
096  }
097
098  public void setRetryDespiteFastFailMode(boolean retryDespiteFastFailMode) {
099    this.retryDespiteFastFailMode = retryDespiteFastFailMode;
100  }
101
102  public void setServer(ServerName server) {
103    this.server = server;
104  }
105
106  public void setTries(int tries) {
107    this.tries = tries;
108  }
109
110  @Override
111  public void clear() {
112    server = null;
113    fInfo = null;
114    didTry = false;
115    couldNotCommunicateWithServer.setValue(false);
116    guaranteedClientSideOnly.setValue(false);
117    retryDespiteFastFailMode = false;
118    tries = 0;
119  }
120
121  @Override
122  public FastFailInterceptorContext prepare(RetryingCallable<?> callable) {
123    return prepare(callable, 0);
124  }
125
126  @Override
127  public FastFailInterceptorContext prepare(RetryingCallable<?> callable, int tries) {
128    if (callable instanceof RegionServerCallable) {
129      RegionServerCallable<?, ?> retryingCallable = (RegionServerCallable<?, ?>) callable;
130      server = retryingCallable.getLocation().getServerName();
131    }
132    this.tries = tries;
133    return this;
134  }
135}