From 4c550fb6b94e083b258829fb0485506b3f30d35d Mon Sep 17 00:00:00 2001 From: Michael Stack Date: Mon, 27 Oct 2008 21:56:42 +0000 Subject: [PATCH] Clean logging little git-svn-id: https://svn.apache.org/repos/asf/hadoop/hbase/trunk@708341 13f79535-47bb-0310-9956-ffa450edef68 --- .../hbase/client/HConnectionManager.java | 70 +++++++++++++++++-- 1 file changed, 65 insertions(+), 5 deletions(-) diff --git a/src/java/org/apache/hadoop/hbase/client/HConnectionManager.java b/src/java/org/apache/hadoop/hbase/client/HConnectionManager.java index d24a4cb9171..d7f5ee45693 100644 --- a/src/java/org/apache/hadoop/hbase/client/HConnectionManager.java +++ b/src/java/org/apache/hadoop/hbase/client/HConnectionManager.java @@ -44,6 +44,7 @@ import org.apache.hadoop.hbase.MasterNotRunningException; import org.apache.hadoop.hbase.RemoteExceptionHandler; import org.apache.hadoop.hbase.TableNotFoundException; import org.apache.hadoop.hbase.client.MetaScanner.MetaScannerVisitor; +import org.apache.hadoop.hbase.io.BatchUpdate; import org.apache.hadoop.hbase.io.Cell; import org.apache.hadoop.hbase.io.RowResult; import org.apache.hadoop.hbase.ipc.HMasterInterface; @@ -777,12 +778,10 @@ public class HConnectionManager implements HConstants { if (rootRegionAddress == null) { try { if (LOG.isDebugEnabled()) { - LOG.debug("Sleeping. Waiting for root region."); + LOG.debug("Sleeping " + getPauseTime(tries) + + "ms, waiting for root region."); } Thread.sleep(getPauseTime(tries)); - if (LOG.isDebugEnabled()) { - LOG.debug("Wake. Retry finding root region."); - } } catch (InterruptedException iex) { // continue } @@ -903,6 +902,67 @@ public class HConnectionManager implements HConstants { } return null; } + + public void processBatchOfRows(ArrayList list, byte[] tableName) + throws IOException { + // See HBASE-748 for pseudo code of this method + if (list.isEmpty()) { + return; + } + Collections.sort(list); + List tempUpdates = new ArrayList(); + byte[] currentRegion = getRegionLocation(tableName, list.get(0).getRow(), + false).getRegionInfo().getRegionName(); + 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(); + } + if (!Bytes.equals(currentRegion, region) || isLastRow) { + final BatchUpdate[] updates = tempUpdates.toArray(new BatchUpdate[0]); + int index = getRegionServerForWithoutRetries(new ServerCallable( + this, tableName, batchUpdate.getRow()) { + public Integer call() throws IOException { + int i = server.batchUpdates(location.getRegionInfo() + .getRegionName(), updates); + return i; + } + }); + if (index != updates.length - 1) { + if (tries == numRetries - 1) { + throw new RetriesExhaustedException("Some server", + currentRegion, batchUpdate.getRow(), + tries, new ArrayList()); + } + if (LOG.isDebugEnabled()) { + LOG.debug("reloading table servers because region " + + "server didn't accept updates "); + } + // Basic waiting time. If many updates are flushed, tests have shown + // that this is barely needed but when commiting 1 update this may + // get retried hundreds of times. + try { + Thread.sleep(getPauseTime(tries)); + tries++; + } catch (InterruptedException e) { + // continue + } + i = i - updates.length + index; + region = getRegionLocation(tableName, list.get(i + 1).getRow(), + true).getRegionInfo().getRegionName(); + + } + currentRegion = region; + tempUpdates.clear(); + } + } + } void close(boolean stopProxy) { if (master != null) { @@ -921,4 +981,4 @@ public class HConnectionManager implements HConstants { } } } -} \ No newline at end of file +}