Author: apurtell
Date: Thu Aug 27 19:40:47 2009
New Revision: 808579
URL: http://svn.apache.org/viewvc?rev=808579&view=rev
Log:
HBASE-1780 HTable.flushCommits clears write buffer in finally clause
Modified:
hadoop/hbase/trunk/CHANGES.txt
hadoop/hbase/trunk/src/java/org/apache/hadoop/hbase/client/HConnection.java
hadoop/hbase/trunk/src/java/org/apache/hadoop/hbase/client/HConnectionManager.java
hadoop/hbase/trunk/src/java/org/apache/hadoop/hbase/client/HTable.java
Modified: hadoop/hbase/trunk/CHANGES.txt
URL:
http://svn.apache.org/viewvc/hadoop/hbase/trunk/CHANGES.txt?rev=808579&r1=808578&r2=808579&view=diff
==============================================================================
--- hadoop/hbase/trunk/CHANGES.txt (original)
+++ hadoop/hbase/trunk/CHANGES.txt Thu Aug 27 19:40:47 2009
@@ -357,6 +357,7 @@
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
Modified:
hadoop/hbase/trunk/src/java/org/apache/hadoop/hbase/client/HConnection.java
URL:
http://svn.apache.org/viewvc/hadoop/hbase/trunk/src/java/org/apache/hadoop/hbase/client/HConnection.java?rev=808579&r1=808578&r2=808579&view=diff
==============================================================================
--- hadoop/hbase/trunk/src/java/org/apache/hadoop/hbase/client/HConnection.java
(original)
+++ hadoop/hbase/trunk/src/java/org/apache/hadoop/hbase/client/HConnection.java
Thu Aug 27 19:40:47 2009
@@ -189,6 +189,6 @@
* @param tableName The name of the table
* @throws IOException
*/
- public void processBatchOfRows(ArrayList<Put> list, byte[] tableName)
+ public int processBatchOfRows(ArrayList<Put> list, byte[] tableName)
throws IOException;
}
\ No newline at end of file
Modified:
hadoop/hbase/trunk/src/java/org/apache/hadoop/hbase/client/HConnectionManager.java
URL:
http://svn.apache.org/viewvc/hadoop/hbase/trunk/src/java/org/apache/hadoop/hbase/client/HConnectionManager.java?rev=808579&r1=808578&r2=808579&view=diff
==============================================================================
---
hadoop/hbase/trunk/src/java/org/apache/hadoop/hbase/client/HConnectionManager.java
(original)
+++
hadoop/hbase/trunk/src/java/org/apache/hadoop/hbase/client/HConnectionManager.java
Thu Aug 27 19:40:47 2009
@@ -997,10 +997,10 @@
return location;
}
- public void processBatchOfRows(ArrayList<Put> list, byte[] tableName)
+ public int processBatchOfRows(ArrayList<Put> list, byte[] tableName)
throws IOException {
if (list.isEmpty()) {
- return;
+ return 0;
}
boolean retryOnlyOne = false;
if (list.size() > 1) {
@@ -1014,7 +1014,8 @@
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 @@
currentPuts.clear();
}
}
+ return i;
}
void close(boolean stopProxy) {
Modified: hadoop/hbase/trunk/src/java/org/apache/hadoop/hbase/client/HTable.java
URL:
http://svn.apache.org/viewvc/hadoop/hbase/trunk/src/java/org/apache/hadoop/hbase/client/HTable.java?rev=808579&r1=808578&r2=808579&view=diff
==============================================================================
--- hadoop/hbase/trunk/src/java/org/apache/hadoop/hbase/client/HTable.java
(original)
+++ hadoop/hbase/trunk/src/java/org/apache/hadoop/hbase/client/HTable.java Thu
Aug 27 19:40:47 2009
@@ -54,14 +54,16 @@
/**
- * Used to communicate with a single HBase table
+ * Used to communicate with a single HBase table.
+ * <p>
+ * 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<Put> writeBuffer;
+ private final ArrayList<Put> writeBuffer = new ArrayList<Put>();
private long writeBufferSize;
private boolean autoFlush;
private long currentWriteBufferSize;
@@ -121,7 +123,6 @@
conf.getInt("hbase.regionserver.lease.period", 60 * 1000);
this.configuration = conf;
this.connection.locateRegion(tableName, HConstants.EMPTY_START_ROW);
- this.writeBuffer = new ArrayList<Put>();
this.writeBufferSize = conf.getLong("hbase.client.write.buffer", 2097152);
this.autoFlush = true;
this.currentWriteBufferSize = 0;
@@ -578,11 +579,15 @@
* @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();
+ }
}
}