Index: src/java/org/apache/hadoop/hbase/client/HConnectionManager.java =================================================================== --- src/java/org/apache/hadoop/hbase/client/HConnectionManager.java (revision 730806) +++ src/java/org/apache/hadoop/hbase/client/HConnectionManager.java (working copy) @@ -880,24 +880,71 @@ return; } boolean retryOnlyOne = false; + int tries = 0; Collections.sort(list); List tempUpdates = new ArrayList(); - byte [] currentRegion = getRegionLocation(tableName, list.get(0).getRow(), - false).getRegionInfo().getRegionName(); + byte [] currentRegion = null; + ArrayList throwables = new ArrayList(); + while (currentRegion == null && tries < numRetries) { + try { + HRegionLocation location = + getRegionLocation(tableName, list.get(0).getRow(), false); + if (location != null) { + currentRegion = location.getRegionInfo().getRegionName(); + break; + } + } catch (Throwable t) { + throwables.add(t); + } + tries++; + long sleepTime = getPauseTime(tries); + try { + Thread.sleep(sleepTime); + } catch (InterruptedException e) { + // continue + } + } + if (currentRegion == null) { + throw new RetriesExhaustedException("Some server", + HConstants.EMPTY_BYTE_ARRAY, list.get(0).getRow(), + tries, throwables); + } byte [] region = currentRegion; boolean isLastRow = false; - int tries = 0; for (int i = 0; i < list.size() && tries < numRetries; i++) { BatchUpdate batchUpdate = list.get(i); tempUpdates.add(batchUpdate); isLastRow = (i + 1) == list.size(); if (!isLastRow) { - region = getRegionLocation(tableName, list.get(i + 1).getRow(), false) - .getRegionInfo().getRegionName(); + region = null; + throwables.clear(); + while (region == null && tries < numRetries) { + try { + HRegionLocation location = + getRegionLocation(tableName, list.get(i + 1).getRow(), false); + if (location != null) { + region = location.getRegionInfo().getRegionName(); + break; + } + } catch (Throwable t) { + throwables.add(t); + } + tries++; + try { + Thread.sleep(getPauseTime(tries)); + } catch (InterruptedException e) { + // continue + } + } + if (region == null) { + throw new RetriesExhaustedException("Some server", + HConstants.EMPTY_BYTE_ARRAY, list.get(i+1).getRow(), + tries, throwables); + } } if (!Bytes.equals(currentRegion, region) || isLastRow || retryOnlyOne) { final BatchUpdate[] updates = tempUpdates.toArray(new BatchUpdate[0]); - int index = getRegionServerForWithoutRetries(new ServerCallable( + int index = getRegionServerWithRetries(new ServerCallable( this, tableName, batchUpdate.getRow()) { public Integer call() throws IOException { int i = server.batchUpdates(location.getRegionInfo() @@ -926,8 +973,31 @@ } i = i - updates.length + index; retryOnlyOne = true; - region = getRegionLocation(tableName, list.get(i + 1).getRow(), - true).getRegionInfo().getRegionName(); + throwables.clear(); + region = null; + while (region == null && tries < numRetries) { + try { + HRegionLocation location = getRegionLocation(tableName, + list.get(i + 1).getRow(), true); + if (location != null) { + region = location.getRegionInfo().getRegionName(); + break; + } + } catch (Throwable t) { + throwables.add(t); + } + tries++; + try { + Thread.sleep(getPauseTime(tries)); + } catch (InterruptedException e) { + // continue + } + } + if (region == null) { + throw new RetriesExhaustedException("Some server", + HConstants.EMPTY_BYTE_ARRAY, list.get(i+1).getRow(), + tries, throwables); + } } else { retryOnlyOne = false;