1 /* 2 * Copyright 2021 TiKV Project Authors. 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 * 16 */ 17 18 package org.tikv.common.util; 19 20 import org.tikv.common.log.SlowLog; 21 22 public interface BackOffer { 23 // Back off types. 24 int seconds = 1000; 25 int TSO_MAX_BACKOFF = 5 * seconds; 26 int SCANNER_NEXT_MAX_BACKOFF = 40 * seconds; 27 int BATCH_GET_MAX_BACKOFF = 40 * seconds; 28 int COP_NEXT_MAX_BACKOFF = 40 * seconds; 29 int GET_MAX_BACKOFF = 40 * seconds; 30 int RAWKV_MAX_BACKOFF = 20 * seconds; 31 int PD_INFO_BACKOFF = 5 * seconds; 32 int TIKV_SWITCH_MODE_BACKOFF = seconds; 33 int SPLIT_REGION_BACKOFF = 12000; 34 int SCATTER_REGION_BACKOFF = 30000; 35 int INGEST_BACKOFF = 30000; 36 37 /** 38 * doBackOff sleeps a while base on the BackOffType and records the error message. Will stop until 39 * max back off time exceeded and throw an exception to the caller. 40 */ 41 void doBackOff(BackOffFunction.BackOffFuncType funcType, Exception err); 42 43 /** check if deadline exceeded. */ 44 void checkTimeout(); 45 46 /** 47 * canRetryAfterSleep sleeps a while base on the BackOffType and records the error message. Will 48 * stop until max back off time exceeded and throw an exception to the caller. It will return 49 * false if the total sleep time has exceed some limit condition. 50 */ 51 boolean canRetryAfterSleep(BackOffFunction.BackOffFuncType funcType); 52 53 /** 54 * BackoffWithMaxSleep sleeps a while base on the backoffType and records the error message and 55 * never sleep more than maxSleepMs for each sleep. 56 */ 57 void doBackOffWithMaxSleep( 58 BackOffFunction.BackOffFuncType funcType, long maxSleepMs, Exception err); 59 60 // Back off strategies 61 enum BackOffStrategy { 62 // NoJitter makes the backoff sequence strict exponential. 63 NoJitter, 64 // FullJitter applies random factors to strict exponential. 65 FullJitter, 66 // EqualJitter is also randomized, but prevents very short sleeps. 67 EqualJitter, 68 // DecorrJitter increases the maximum jitter based on the last random value. 69 DecorrJitter 70 } 71 72 SlowLog getSlowLog(); 73 74 Long getClusterId(); 75 }