001/** 002 * 003 * Licensed to the Apache Software Foundation (ASF) under one 004 * or more contributor license agreements. See the NOTICE file 005 * distributed with this work for additional information 006 * regarding copyright ownership. The ASF licenses this file 007 * to you under the Apache License, Version 2.0 (the 008 * "License"); you may not use this file except in compliance 009 * with the License. You may obtain a copy of the License at 010 * 011 * http://www.apache.org/licenses/LICENSE-2.0 012 * 013 * Unless required by applicable law or agreed to in writing, software 014 * distributed under the License is distributed on an "AS IS" BASIS, 015 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 016 * See the License for the specific language governing permissions and 017 * limitations under the License. 018*/ 019 020package org.apache.hadoop.hbase.exceptions; 021 022import java.net.ConnectException; 023 024import org.apache.hadoop.hbase.ServerName; 025import org.apache.yetus.audience.InterfaceAudience; 026 027/** 028 * Thrown when the client believes that we are trying to communicate to has 029 * been repeatedly unresponsive for a while. 030 * 031 * On receiving such an exception. The ConnectionManager will skip all 032 * retries and fast fail the operation. 033 * @deprecated since 2.3.0, and will be removed in 4.0.0. 034 */ 035@Deprecated 036@InterfaceAudience.Public 037public class PreemptiveFastFailException extends ConnectException { 038 private static final long serialVersionUID = 7129103682617007177L; 039 private long failureCount, timeOfFirstFailureMilliSec, timeOfLatestAttemptMilliSec; 040 041 // If set, we guarantee that no modifications went to server 042 private boolean guaranteedClientSideOnly; 043 044 /** 045 * @param count num of consecutive failures 046 * @param timeOfFirstFailureMilliSec when first failure happened 047 * @param timeOfLatestAttemptMilliSec when last attempt happened 048 * @param serverName server we failed to connect to 049 */ 050 public PreemptiveFastFailException(long count, long timeOfFirstFailureMilliSec, 051 long timeOfLatestAttemptMilliSec, ServerName serverName) { 052 super("Exception happened " + count + " times. to" + serverName); 053 this.failureCount = count; 054 this.timeOfFirstFailureMilliSec = timeOfFirstFailureMilliSec; 055 this.timeOfLatestAttemptMilliSec = timeOfLatestAttemptMilliSec; 056 } 057 058 /** 059 * @param count num of consecutive failures 060 * @param timeOfFirstFailureMilliSec when first failure happened 061 * @param timeOfLatestAttemptMilliSec when last attempt happened 062 * @param serverName server we failed to connect to 063 * @param guaranteedClientSideOnly if true, guarantees that no mutations 064 * have been applied on the server 065 */ 066 public PreemptiveFastFailException(long count, long timeOfFirstFailureMilliSec, 067 long timeOfLatestAttemptMilliSec, ServerName serverName, 068 boolean guaranteedClientSideOnly) { 069 super("Exception happened " + count + " times. to" + serverName); 070 this.failureCount = count; 071 this.timeOfFirstFailureMilliSec = timeOfFirstFailureMilliSec; 072 this.timeOfLatestAttemptMilliSec = timeOfLatestAttemptMilliSec; 073 this.guaranteedClientSideOnly = guaranteedClientSideOnly; 074 } 075 076 /** 077 * @return time of the fist failure 078 */ 079 public long getFirstFailureAt() { 080 return timeOfFirstFailureMilliSec; 081 } 082 083 /** 084 * @return time of the latest attempt 085 */ 086 public long getLastAttemptAt() { 087 return timeOfLatestAttemptMilliSec; 088 } 089 090 /** 091 * @return failure count 092 */ 093 public long getFailureCount() { 094 return failureCount; 095 } 096 097 /** 098 * @return true if operation was attempted by server, false otherwise. 099 */ 100 public boolean wasOperationAttemptedByServer() { 101 return false; 102 } 103 104 /** 105 * @return true if we know no mutation made it to the server, false otherwise. 106 */ 107 public boolean isGuaranteedClientSideOnly() { 108 return guaranteedClientSideOnly; 109 } 110}