From e352c5dfe125ec69e59fcea51ac472d9dbecea4f Mon Sep 17 00:00:00 2001 From: Jean-Daniel Cryans Date: Fri, 31 Oct 2008 01:31:16 +0000 Subject: [PATCH] HBASE-963 Fix the retries in HTable.flushCommit git-svn-id: https://svn.apache.org/repos/asf/hadoop/hbase/trunk@709320 13f79535-47bb-0310-9956-ffa450edef68 --- CHANGES.txt | 1 + .../hadoop/hbase/client/HConnection.java | 13 ++++ .../hbase/client/HConnectionManager.java | 2 +- .../apache/hadoop/hbase/client/HTable.java | 59 +++---------------- 4 files changed, 24 insertions(+), 51 deletions(-) diff --git a/CHANGES.txt b/CHANGES.txt index 6ed75b85d04..e19c4bc4181 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -55,6 +55,7 @@ Release 0.19.0 - Unreleased HBASE-971 Fix the failing tests on Hudson HBASE-973 [doc] In getting started, make it clear that hbase needs to create its directory in hdfs + HBASE-963 Fix the retries in HTable.flushCommit IMPROVEMENTS HBASE-901 Add a limit to key length, check key and value length on client side diff --git a/src/java/org/apache/hadoop/hbase/client/HConnection.java b/src/java/org/apache/hadoop/hbase/client/HConnection.java index bf4a9929b54..9e3a7b62c21 100644 --- a/src/java/org/apache/hadoop/hbase/client/HConnection.java +++ b/src/java/org/apache/hadoop/hbase/client/HConnection.java @@ -20,11 +20,13 @@ package org.apache.hadoop.hbase.client; import java.io.IOException; +import java.util.ArrayList; import org.apache.hadoop.hbase.HRegionLocation; import org.apache.hadoop.hbase.HServerAddress; import org.apache.hadoop.hbase.HTableDescriptor; import org.apache.hadoop.hbase.MasterNotRunningException; +import org.apache.hadoop.hbase.io.BatchUpdate; import org.apache.hadoop.hbase.ipc.HMasterInterface; import org.apache.hadoop.hbase.ipc.HRegionInterface; @@ -150,4 +152,15 @@ public interface HConnection { */ public T getRegionServerForWithoutRetries(ServerCallable callable) throws IOException, RuntimeException; + + + /** + * Process a batch of rows. Currently it only works for updates until + * HBASE-880 is available. Does the retries. + * @param list A batch of rows to process + * @param tableName The name of the table + * @throws IOException + */ + public void processBatchOfRows(ArrayList list, byte[] tableName) + throws IOException; } \ No newline at end of file diff --git a/src/java/org/apache/hadoop/hbase/client/HConnectionManager.java b/src/java/org/apache/hadoop/hbase/client/HConnectionManager.java index d7f5ee45693..d2d3dc60ba3 100644 --- a/src/java/org/apache/hadoop/hbase/client/HConnectionManager.java +++ b/src/java/org/apache/hadoop/hbase/client/HConnectionManager.java @@ -934,7 +934,7 @@ public class HConnectionManager implements HConstants { return i; } }); - if (index != updates.length - 1) { + if (index != -1) { if (tries == numRetries - 1) { throw new RetriesExhaustedException("Some server", currentRegion, batchUpdate.getRow(), diff --git a/src/java/org/apache/hadoop/hbase/client/HTable.java b/src/java/org/apache/hadoop/hbase/client/HTable.java index 2d1050ef1b2..43da3549062 100644 --- a/src/java/org/apache/hadoop/hbase/client/HTable.java +++ b/src/java/org/apache/hadoop/hbase/client/HTable.java @@ -21,7 +21,6 @@ package org.apache.hadoop.hbase.client; import java.io.IOException; import java.util.ArrayList; -import java.util.Collections; import java.util.Iterator; import java.util.LinkedList; import java.util.List; @@ -1029,60 +1028,20 @@ public class HTable { */ public void flushCommits() throws IOException { try { - // See HBASE-748 for pseudo code of this method - if (writeBuffer.isEmpty()) { - return; - } - Collections.sort(writeBuffer); - List tempUpdates = new ArrayList(); - byte[] currentRegion = connection.getRegionLocation(tableName, - writeBuffer.get(0).getRow(), false).getRegionInfo().getRegionName(); - byte[] region = currentRegion; - boolean isLastRow = false; - for (int i = 0; i < writeBuffer.size(); i++) { - BatchUpdate batchUpdate = writeBuffer.get(i); - tempUpdates.add(batchUpdate); - isLastRow = (i + 1) == writeBuffer.size(); - if (!isLastRow) { - region = connection.getRegionLocation(tableName, - writeBuffer.get(i + 1).getRow(), false).getRegionInfo() - .getRegionName(); - } - if (!Bytes.equals(currentRegion, region) || isLastRow) { - final BatchUpdate[] updates = tempUpdates.toArray(new BatchUpdate[0]); - int index = connection - .getRegionServerForWithoutRetries(new ServerCallable( - connection, tableName, batchUpdate.getRow()) { - public Integer call() throws IOException { - int i = server.batchUpdates(location.getRegionInfo() - .getRegionName(), updates); - return i; - } - }); - if (index != -1) { - // 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(1000); - } catch (InterruptedException e) { - // continue - } - i = i - updates.length + index; - region = connection.getRegionLocation(tableName, - writeBuffer.get(i + 1).getRow(), true).getRegionInfo() - .getRegionName(); - - } - currentRegion = region; - tempUpdates.clear(); - } - } + connection.processBatchOfRows(writeBuffer, tableName); } finally { currentWriteBufferSize = 0; writeBuffer.clear(); } } + + /** + * Release held resources + * + */ + public void close() throws IOException{ + flushCommits(); + } /** * Utility method that checks rows existence, length and columns well