HBase-client-0.98.4重试参数分析

本文深入探讨了HBase客户端的重试参数设置及其影响,分析了源码中重试次数为0时的行为,指出这将导致直接抛出异常而不再尝试重连,强调了重试次数的重要性。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

 重试参数

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!!!!!

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值