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