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.exceptions;
019
020import java.net.ConnectException;
021import org.apache.hadoop.hbase.ServerName;
022import org.apache.yetus.audience.InterfaceAudience;
023
024/**
025 * Thrown when the client believes that we are trying to communicate to has been repeatedly
026 * unresponsive for a while. On receiving such an exception. The ConnectionManager will skip all
027 * retries and fast fail the operation.
028 * @deprecated since 2.3.0, and will be removed in 4.0.0.
029 */
030@Deprecated
031@InterfaceAudience.Public
032public class PreemptiveFastFailException extends ConnectException {
033  private static final long serialVersionUID = 7129103682617007177L;
034  private long failureCount, timeOfFirstFailureMilliSec, timeOfLatestAttemptMilliSec;
035
036  // If set, we guarantee that no modifications went to server
037  private boolean guaranteedClientSideOnly;
038
039  /**
040   * @param count                       num of consecutive failures
041   * @param timeOfFirstFailureMilliSec  when first failure happened
042   * @param timeOfLatestAttemptMilliSec when last attempt happened
043   * @param serverName                  server we failed to connect to
044   */
045  public PreemptiveFastFailException(long count, long timeOfFirstFailureMilliSec,
046    long timeOfLatestAttemptMilliSec, ServerName serverName) {
047    super("Exception happened " + count + " times. to" + serverName);
048    this.failureCount = count;
049    this.timeOfFirstFailureMilliSec = timeOfFirstFailureMilliSec;
050    this.timeOfLatestAttemptMilliSec = timeOfLatestAttemptMilliSec;
051  }
052
053  /**
054   * @param count                       num of consecutive failures
055   * @param timeOfFirstFailureMilliSec  when first failure happened
056   * @param timeOfLatestAttemptMilliSec when last attempt happened
057   * @param serverName                  server we failed to connect to
058   * @param guaranteedClientSideOnly    if true, guarantees that no mutations have been applied on
059   *                                    the server
060   */
061  public PreemptiveFastFailException(long count, long timeOfFirstFailureMilliSec,
062    long timeOfLatestAttemptMilliSec, ServerName serverName, boolean guaranteedClientSideOnly) {
063    super("Exception happened " + count + " times. to" + serverName);
064    this.failureCount = count;
065    this.timeOfFirstFailureMilliSec = timeOfFirstFailureMilliSec;
066    this.timeOfLatestAttemptMilliSec = timeOfLatestAttemptMilliSec;
067    this.guaranteedClientSideOnly = guaranteedClientSideOnly;
068  }
069
070  /** Returns time of the fist failure */
071  public long getFirstFailureAt() {
072    return timeOfFirstFailureMilliSec;
073  }
074
075  /** Returns time of the latest attempt */
076  public long getLastAttemptAt() {
077    return timeOfLatestAttemptMilliSec;
078  }
079
080  /** Returns failure count */
081  public long getFailureCount() {
082    return failureCount;
083  }
084
085  /** Returns true if operation was attempted by server, false otherwise. */
086  public boolean wasOperationAttemptedByServer() {
087    return false;
088  }
089
090  /** Returns true if we know no mutation made it to the server, false otherwise. */
091  public boolean isGuaranteedClientSideOnly() {
092    return guaranteedClientSideOnly;
093  }
094}