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 java.util.concurrent.atomic.AtomicBoolean;
021import java.util.concurrent.atomic.AtomicLong;
022
023import org.apache.yetus.audience.InterfaceAudience;
024
025/**
026 * Keeps track of repeated failures to any region server. Multiple threads manipulate the contents
027 * of this thread.
028 *
029 * Access to the members is guarded by the concurrent nature of the members inherently.
030 * 
031 */
032@InterfaceAudience.Private
033class FailureInfo {
034  // The number of consecutive failures.
035  final AtomicLong numConsecutiveFailures = new AtomicLong();
036  // The time when the server started to become unresponsive
037  // Once set, this would never be updated.
038  final long timeOfFirstFailureMilliSec;
039  // The time when the client last tried to contact the server.
040  // This is only updated by one client at a time
041  volatile long timeOfLatestAttemptMilliSec;
042  // Used to keep track of concurrent attempts to contact the server.
043  // In Fast fail mode, we want just one client thread to try to connect
044  // the rest of the client threads will fail fast.
045  final AtomicBoolean exclusivelyRetringInspiteOfFastFail = new AtomicBoolean(false);
046
047  @Override
048  public String toString() {
049    return "FailureInfo: numConsecutiveFailures = "
050        + numConsecutiveFailures + " timeOfFirstFailureMilliSec = "
051        + timeOfFirstFailureMilliSec + " timeOfLatestAttemptMilliSec = "
052        + timeOfLatestAttemptMilliSec
053        + " exclusivelyRetringInspiteOfFastFail  = "
054        + exclusivelyRetringInspiteOfFastFail.get();
055  }
056
057  FailureInfo(long firstFailureTime) {
058    this.timeOfFirstFailureMilliSec = firstFailureTime;
059  }
060}