重试参数
hbase.client.retries.number:失败时重试次数
默认值:
public static int DEFAULT_HBASE_CLIENT_RETRIES_NUMBER = 31;
重试次数能否设置为0呢?
分析源码
@Override
public Result[] get(List<Get> gets) throws IOException {
if (gets.size() == 1) {
return new Result[]{get(gets.get(0))};
}
try {
Object [] r1 = batch((List)gets);
// translate.
Result [] results = new Result[r1.length];
int i=0;
for (Object o : r1) {
// batch ensures if there is a failure we get an exception instead
results[i++] = (Result) o;
}
return results;
} catch (InterruptedException e) {
throw (InterruptedIOException)new InterruptedIOException().initCause(e);
}
}
get(List<Get> gets) 操作根据Get的数量分2种情况1)new Result[]{get(gets.get(0))} 逻辑
后续代码逻辑
org.apache.hadoop.hbase.client.RpcRetryingCaller#callWithRetries(org.apache.hadoop.hbase.client.RetryingCallable<T>, int)
org.apache.hadoop.hbase.client.HConnectionManager.HConnectionImplementation#locateRegionInMeta
2)batch((List)gets) 逻辑
后续代码逻辑
org.apache.hadoop.hbase.client.AsyncProcess#submitAll
org.apache.hadoop.hbase.client.HConnectionManager.HConnectionImplementation#locateRegionInMeta
最终都会执行 locateRegionInMeta 逻辑,分析源码
private HRegionLocation locateRegionInMeta(final TableName parentTable,
final TableName tableName, final byte [] row, boolean useCache,
Object regionLockObject, boolean retry)
throws IOException {
HRegionLocation location;
// If we are supposed to be using the cache, look in the cache to see if
// we already have the region.
// 先查本地缓存
if (useCache) {
location = getCachedLocation(tableName, row);
if (location != null) {
return location;
}
}
// 判断重试次数
int localNumRetries = retry ? numTries : 1;
// build the key of the meta region we should be looking for.
// the extra 9's on the end are necessary to allow "exact" matches
// without knowing the precise region names.
byte [] metaKey = HRegionInfo.createRegionName(tableName, row,
HConstants.NINES, false);
for (int tries = 0; true; tries++) {
//无重试次数直接异常
if (tries >= localNumRetries) {
throw new NoServerForRegionException("Unable to find region for "
+ Bytes.toStringBinary(row) + " after " + numTries + " tries.");
}
............ 省略后续代码
}
}
通过代码可以看出
1)首先从本地缓存获取分区信息(useCache)
2)获取不到,判断重试次数(int localNumRetries = retry ? numTries : 1;)
3)如果重试为0的话, 将不会进行重试,直接报错
如果批量操作3个操作, 报以下异常
org.apache.hadoop.hbase.client.RetriesExhaustedWithDetailsException: Failed 3 actions: NoServerForRegionException: 3 times,
如果批量操作1个操作, 报以下异常
org.apache.hadoop.hbase.client.RetriesExhaustedException: Failed after attempts=1, exceptions:
Wed Jun 12 14:59:08 CST 2019, org.apache.hadoop.hbase.client.RpcRetryingCaller@29a49534, org.apache.hadoop.hbase.client.NoServerForRegionException: Unable to find region for 5332c07ef3a144f24ebea0f029f41a6a after 0 tries.
最终得出结论重试次数不能设置成0!!!!!