View Javadoc

1   /**
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  You may obtain a copy of the License at
9    *
10   *     http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing, software
13   * distributed under the License is distributed on an "AS IS" BASIS,
14   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15   * See the License for the specific language governing permissions and
16   * limitations under the License.
17   */
18  package org.apache.hadoop.hbase.client;
19  
20  import org.apache.commons.lang.mutable.MutableBoolean;
21  import org.apache.hadoop.hbase.ServerName;
22  import org.apache.hadoop.hbase.classification.InterfaceAudience;
23  
24  @InterfaceAudience.Private
25  class FastFailInterceptorContext extends
26      RetryingCallerInterceptorContext {
27  
28    // The variable that indicates whether we were able to connect with the server
29    // in the last run
30    private MutableBoolean couldNotCommunicateWithServer = new MutableBoolean(false);
31  
32    // If set, we guarantee that no modifications went to server
33    private MutableBoolean guaranteedClientSideOnly = new MutableBoolean(false);
34  
35    // The variable which indicates whether this was a retry or the first time
36    private boolean didTry = false;
37  
38    // The failure info that is associated with the machine which we are trying to
39    // contact as part of this attempt.
40    private FailureInfo fInfo = null;
41  
42    // Variable indicating that the thread that is currently executing the
43    // operation is in a mode where it would retry instead of failing fast, so
44    // that we can figure out whether making contact with the server is
45    // possible or not.
46    private boolean retryDespiteFastFailMode = false;
47  
48    // The server that would be contacted to successfully complete this operation.
49    private ServerName server;
50  
51    // The number of the retry we are currenty doing.
52    private int tries;
53  
54    public MutableBoolean getCouldNotCommunicateWithServer() {
55      return couldNotCommunicateWithServer;
56    }
57  
58    public MutableBoolean getGuaranteedClientSideOnly() {
59      return guaranteedClientSideOnly;
60    }
61  
62    public FailureInfo getFailureInfo() {
63      return fInfo;
64    }
65  
66    public ServerName getServer() {
67      return server;
68    }
69  
70    public int getTries() {
71      return tries;
72    }
73  
74    public boolean didTry() {
75      return didTry;
76    }
77  
78    public boolean isRetryDespiteFastFailMode() {
79      return retryDespiteFastFailMode;
80    }
81  
82    public void setCouldNotCommunicateWithServer(
83        MutableBoolean couldNotCommunicateWithServer) {
84      this.couldNotCommunicateWithServer = couldNotCommunicateWithServer;
85    }
86  
87    public void setGuaranteedClientSideOnly(MutableBoolean guaranteedClientSideOnly) {
88      this.guaranteedClientSideOnly = guaranteedClientSideOnly;
89    }
90  
91    public void setDidTry(boolean didTry) {
92      this.didTry = didTry;
93    }
94  
95    public void setFailureInfo(FailureInfo fInfo) {
96      this.fInfo = fInfo;
97    }
98  
99    public void setRetryDespiteFastFailMode(boolean retryDespiteFastFailMode) {
100     this.retryDespiteFastFailMode = retryDespiteFastFailMode;
101   }
102 
103   public void setServer(ServerName server) {
104     this.server = server;
105   }
106 
107   public void setTries(int tries) {
108     this.tries = tries;
109   }
110 
111   @Override
112   public void clear() {
113     server = null;
114     fInfo = null;
115     didTry = false;
116     couldNotCommunicateWithServer.setValue(false);
117     guaranteedClientSideOnly.setValue(false);
118     retryDespiteFastFailMode = false;
119     tries = 0;
120   }
121 
122   @Override
123   public FastFailInterceptorContext prepare(RetryingCallable<?> callable) {
124     return prepare(callable, 0);
125   }
126 
127   @Override
128   public FastFailInterceptorContext prepare(RetryingCallable<?> callable,
129       int tries) {
130     if (callable instanceof RegionServerCallable) {
131       RegionServerCallable<?> retryingCallable = (RegionServerCallable<?>) callable;
132       server = retryingCallable.getLocation().getServerName();
133     }
134     this.tries = tries;
135     return this;
136   }
137 }