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(MutableBoolean couldNotCommunicateWithServer) {
082    this.couldNotCommunicateWithServer = couldNotCommunicateWithServer;
083  }
084
085  public void setGuaranteedClientSideOnly(MutableBoolean guaranteedClientSideOnly) {
086    this.guaranteedClientSideOnly = guaranteedClientSideOnly;
087  }
088
089  public void setDidTry(boolean didTry) {
090    this.didTry = didTry;
091  }
092
093  public void setFailureInfo(FailureInfo fInfo) {
094    this.fInfo = fInfo;
095  }
096
097  public void setRetryDespiteFastFailMode(boolean retryDespiteFastFailMode) {
098    this.retryDespiteFastFailMode = retryDespiteFastFailMode;
099  }
100
101  public void setServer(ServerName server) {
102    this.server = server;
103  }
104
105  public void setTries(int tries) {
106    this.tries = tries;
107  }
108
109  @Override
110  public void clear() {
111    server = null;
112    fInfo = null;
113    didTry = false;
114    couldNotCommunicateWithServer.setValue(false);
115    guaranteedClientSideOnly.setValue(false);
116    retryDespiteFastFailMode = false;
117    tries = 0;
118  }
119
120  @Override
121  public FastFailInterceptorContext prepare(RetryingCallable<?> callable) {
122    return prepare(callable, 0);
123  }
124
125  @Override
126  public FastFailInterceptorContext prepare(RetryingCallable<?> callable, int tries) {
127    if (callable instanceof RegionServerCallable) {
128      RegionServerCallable<?, ?> retryingCallable = (RegionServerCallable<?, ?>) callable;
129      server = retryingCallable.getLocation().getServerName();
130    }
131    this.tries = tries;
132    return this;
133  }
134}