From 7fe79fa71c3d6907ab09b0cc1be362eea2632c01 Mon Sep 17 00:00:00 2001 From: Andrew Kyle Purtell Date: Thu, 27 Aug 2009 19:40:47 +0000 Subject: [PATCH] HBASE-1780 HTable.flushCommits clears write buffer in finally clause git-svn-id: https://svn.apache.org/repos/asf/hadoop/hbase/trunk@808579 13f79535-47bb-0310-9956-ffa450edef68 --- CHANGES.txt | 1 + .../apache/hadoop/hbase/client/HConnection.java | 2 +- .../hadoop/hbase/client/HConnectionManager.java | 8 +++++--- .../org/apache/hadoop/hbase/client/HTable.java | 15 ++++++++++----- 4 files changed, 17 insertions(+), 9 deletions(-) diff --git a/CHANGES.txt b/CHANGES.txt index 646a67fb08f..5690ba7949c 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -357,6 +357,7 @@ Release 0.20.0 - Unreleased new updates into the 'kvset' (active part) HBASE-1767 test zookeeper broken in trunk and 0.20 branch; broken on hudson too + HBASE-1780 HTable.flushCommits clears write buffer in finally clause IMPROVEMENTS HBASE-1089 Add count of regions on filesystem to master UI; add percentage diff --git a/src/java/org/apache/hadoop/hbase/client/HConnection.java b/src/java/org/apache/hadoop/hbase/client/HConnection.java index 9d960f9221a..10aa41db749 100644 --- a/src/java/org/apache/hadoop/hbase/client/HConnection.java +++ b/src/java/org/apache/hadoop/hbase/client/HConnection.java @@ -189,6 +189,6 @@ public interface HConnection { * @param tableName The name of the table * @throws IOException */ - public void processBatchOfRows(ArrayList list, byte[] tableName) + public int 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 7160a7cfa9f..0b4789f055f 100644 --- a/src/java/org/apache/hadoop/hbase/client/HConnectionManager.java +++ b/src/java/org/apache/hadoop/hbase/client/HConnectionManager.java @@ -997,10 +997,10 @@ public class HConnectionManager implements HConstants { return location; } - public void processBatchOfRows(ArrayList list, byte[] tableName) + public int processBatchOfRows(ArrayList list, byte[] tableName) throws IOException { if (list.isEmpty()) { - return; + return 0; } boolean retryOnlyOne = false; if (list.size() > 1) { @@ -1014,7 +1014,8 @@ public class HConnectionManager implements HConstants { byte [] region = currentRegion; boolean isLastRow = false; Put [] putarray = new Put[0]; - for (int i = 0, tries = 0; i < list.size() && tries < this.numRetries; i++) { + int i, tries; + for (i = 0, tries = 0; i < list.size() && tries < this.numRetries; i++) { Put put = list.get(i); currentPuts.add(put); // If the next Put goes to a new region, then we are to clear @@ -1072,6 +1073,7 @@ public class HConnectionManager implements HConstants { currentPuts.clear(); } } + return i; } void close(boolean stopProxy) { diff --git a/src/java/org/apache/hadoop/hbase/client/HTable.java b/src/java/org/apache/hadoop/hbase/client/HTable.java index 72b56c47e35..6d072436164 100644 --- a/src/java/org/apache/hadoop/hbase/client/HTable.java +++ b/src/java/org/apache/hadoop/hbase/client/HTable.java @@ -54,14 +54,16 @@ import org.apache.hadoop.hbase.util.Writables; /** - * Used to communicate with a single HBase table + * Used to communicate with a single HBase table. + *

+ * This class is not MT safe for writes. */ public class HTable implements HTableInterface { private final HConnection connection; private final byte [] tableName; protected final int scannerTimeout; private volatile HBaseConfiguration configuration; - private ArrayList writeBuffer; + private final ArrayList writeBuffer = new ArrayList(); private long writeBufferSize; private boolean autoFlush; private long currentWriteBufferSize; @@ -121,7 +123,6 @@ public class HTable implements HTableInterface { conf.getInt("hbase.regionserver.lease.period", 60 * 1000); this.configuration = conf; this.connection.locateRegion(tableName, HConstants.EMPTY_START_ROW); - this.writeBuffer = new ArrayList(); this.writeBufferSize = conf.getLong("hbase.client.write.buffer", 2097152); this.autoFlush = true; this.currentWriteBufferSize = 0; @@ -578,11 +579,15 @@ public class HTable implements HTableInterface { * @throws IOException */ public void flushCommits() throws IOException { + int last = 0; try { - connection.processBatchOfRows(writeBuffer, tableName); + last = connection.processBatchOfRows(writeBuffer, tableName); } finally { + writeBuffer.subList(0, last).clear(); currentWriteBufferSize = 0; - writeBuffer.clear(); + for (int i = 0; i < writeBuffer.size(); i++) { + currentWriteBufferSize += writeBuffer.get(i).heapSize(); + } } }