1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 package org.apache.hadoop.hbase.client;
19
20 import org.apache.commons.logging.Log;
21 import org.apache.commons.logging.LogFactory;
22 import org.apache.hadoop.conf.Configuration;
23 import org.apache.hadoop.hbase.HConstants;
24 import org.apache.hadoop.hbase.classification.InterfaceAudience;
25 import org.apache.hadoop.hbase.util.ReflectionUtils;
26
27
28
29
30 @InterfaceAudience.Private
31 public class RpcRetryingCallerFactory {
32
33
34 public static final String CUSTOM_CALLER_CONF_KEY = "hbase.rpc.callerfactory.class";
35 private static final Log LOG = LogFactory.getLog(RpcRetryingCallerFactory.class);
36 protected final Configuration conf;
37 private final long pause;
38 private final long pauseForCQTBE;
39 private final int retries;
40 private final int rpcTimeout;
41 private final RetryingCallerInterceptor interceptor;
42 private final int startLogErrorsCnt;
43 private final boolean enableBackPressure;
44 private ServerStatisticTracker stats;
45
46 public RpcRetryingCallerFactory(Configuration conf) {
47 this(conf, RetryingCallerInterceptorFactory.NO_OP_INTERCEPTOR);
48 }
49
50 public RpcRetryingCallerFactory(Configuration conf, RetryingCallerInterceptor interceptor) {
51 this.conf = conf;
52 pause = conf.getLong(HConstants.HBASE_CLIENT_PAUSE,
53 HConstants.DEFAULT_HBASE_CLIENT_PAUSE);
54 long configuredPauseForCQTBE = conf.getLong(HConstants.HBASE_CLIENT_PAUSE_FOR_CQTBE, pause);
55 if (configuredPauseForCQTBE < pause) {
56 LOG.warn("The " + HConstants.HBASE_CLIENT_PAUSE_FOR_CQTBE + " setting: "
57 + configuredPauseForCQTBE + " is smaller than " + HConstants.HBASE_CLIENT_PAUSE
58 + ", will use " + pause + " instead.");
59 this.pauseForCQTBE = pause;
60 } else {
61 this.pauseForCQTBE = configuredPauseForCQTBE;
62 }
63 retries = conf.getInt(HConstants.HBASE_CLIENT_RETRIES_NUMBER,
64 HConstants.DEFAULT_HBASE_CLIENT_RETRIES_NUMBER);
65 startLogErrorsCnt = conf.getInt(AsyncProcess.START_LOG_ERRORS_AFTER_COUNT_KEY,
66 AsyncProcess.DEFAULT_START_LOG_ERRORS_AFTER_COUNT);
67 this.interceptor = interceptor;
68 enableBackPressure = conf.getBoolean(HConstants.ENABLE_CLIENT_BACKPRESSURE,
69 HConstants.DEFAULT_ENABLE_CLIENT_BACKPRESSURE);
70 rpcTimeout = conf.getInt(HConstants.HBASE_RPC_TIMEOUT_KEY,HConstants.DEFAULT_HBASE_RPC_TIMEOUT);
71 }
72
73
74
75
76 public void setStatisticTracker(ServerStatisticTracker statisticTracker) {
77 this.stats = statisticTracker;
78 }
79
80
81
82
83 public <T> RpcRetryingCaller<T> newCaller(int rpcTimeout) {
84
85
86 RpcRetryingCaller<T> caller = new RpcRetryingCaller<T>(pause, pauseForCQTBE, retries,
87 interceptor, startLogErrorsCnt, rpcTimeout);
88 return caller;
89 }
90
91
92
93
94 public <T> RpcRetryingCaller<T> newCaller() {
95
96
97 RpcRetryingCaller<T> caller = new RpcRetryingCaller<T>(pause, pauseForCQTBE, retries,
98 interceptor, startLogErrorsCnt, rpcTimeout);
99 return caller;
100 }
101
102 public static RpcRetryingCallerFactory instantiate(Configuration configuration) {
103 return instantiate(configuration, RetryingCallerInterceptorFactory.NO_OP_INTERCEPTOR, null);
104 }
105
106 public static RpcRetryingCallerFactory instantiate(Configuration configuration,
107 ServerStatisticTracker stats) {
108 return instantiate(configuration, RetryingCallerInterceptorFactory.NO_OP_INTERCEPTOR, stats);
109 }
110
111 public static RpcRetryingCallerFactory instantiate(Configuration configuration,
112 RetryingCallerInterceptor interceptor, ServerStatisticTracker stats) {
113 String clazzName = RpcRetryingCallerFactory.class.getName();
114 String rpcCallerFactoryClazz =
115 configuration.get(RpcRetryingCallerFactory.CUSTOM_CALLER_CONF_KEY, clazzName);
116 RpcRetryingCallerFactory factory;
117 if (rpcCallerFactoryClazz.equals(clazzName)) {
118 factory = new RpcRetryingCallerFactory(configuration, interceptor);
119 } else {
120 factory = ReflectionUtils.instantiateWithCustomCtor(
121 rpcCallerFactoryClazz, new Class[] { Configuration.class },
122 new Object[] { configuration });
123 }
124
125
126 factory.setStatisticTracker(stats);
127 return factory;
128 }
129 }