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 java.util.concurrent.atomic.AtomicBoolean;
21  import java.util.concurrent.atomic.AtomicLong;
22  
23  import org.apache.hadoop.hbase.classification.InterfaceAudience;
24  
25  /**
26   * Keeps track of repeated failures to any region server. Multiple threads manipulate the contents
27   * of this thread.
28   *
29   * Access to the members is guarded by the concurrent nature of the members inherently.
30   * 
31   */
32  @InterfaceAudience.Private
33  class FailureInfo {
34    // The number of consecutive failures.
35    public final AtomicLong numConsecutiveFailures = new AtomicLong();
36    // The time when the server started to become unresponsive
37    // Once set, this would never be updated.
38    public final long timeOfFirstFailureMilliSec;
39    // The time when the client last tried to contact the server.
40    // This is only updated by one client at a time
41    public volatile long timeOfLatestAttemptMilliSec;
42    // Used to keep track of concurrent attempts to contact the server.
43    // In Fast fail mode, we want just one client thread to try to connect
44    // the rest of the client threads will fail fast.
45    public final AtomicBoolean exclusivelyRetringInspiteOfFastFail = new AtomicBoolean(
46        false);
47  
48    @Override
49    public String toString() {
50      return "FailureInfo: numConsecutiveFailures = "
51          + numConsecutiveFailures + " timeOfFirstFailureMilliSec = "
52          + timeOfFirstFailureMilliSec + " timeOfLatestAttemptMilliSec = "
53          + timeOfLatestAttemptMilliSec
54          + " exclusivelyRetringInspiteOfFastFail  = "
55          + exclusivelyRetringInspiteOfFastFail.get();
56    }
57  
58    FailureInfo(long firstFailureTime) {
59      this.timeOfFirstFailureMilliSec = firstFailureTime;
60    }
61  }