You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hbase.apache.org by ap...@apache.org on 2009/08/27 21:37:52 UTC

svn commit: r808577 - in /hadoop/hbase/branches/0.20: CHANGES.txt src/java/org/apache/hadoop/hbase/client/HConnection.java src/java/org/apache/hadoop/hbase/client/HConnectionManager.java src/java/org/apache/hadoop/hbase/client/HTable.java

Author: apurtell
Date: Thu Aug 27 19:37:51 2009
New Revision: 808577

URL: http://svn.apache.org/viewvc?rev=808577&view=rev
Log:
HBASE-1780 HTable.flushCommits clears write buffer in finally clause

Modified:
    hadoop/hbase/branches/0.20/CHANGES.txt
    hadoop/hbase/branches/0.20/src/java/org/apache/hadoop/hbase/client/HConnection.java
    hadoop/hbase/branches/0.20/src/java/org/apache/hadoop/hbase/client/HConnectionManager.java
    hadoop/hbase/branches/0.20/src/java/org/apache/hadoop/hbase/client/HTable.java

Modified: hadoop/hbase/branches/0.20/CHANGES.txt
URL: http://svn.apache.org/viewvc/hadoop/hbase/branches/0.20/CHANGES.txt?rev=808577&r1=808576&r2=808577&view=diff
==============================================================================
--- hadoop/hbase/branches/0.20/CHANGES.txt (original)
+++ hadoop/hbase/branches/0.20/CHANGES.txt Thu Aug 27 19:37:51 2009
@@ -333,6 +333,7 @@
    HBASE-1793  [Regression] HTable.get/getRow with a ts is broken
    HBASE-1698  Review documentation for o.a.h.h.mapreduce
    HBASE-1798  [Regression] Unable to delete a row in the future
+   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/branches/0.20/src/java/org/apache/hadoop/hbase/client/HConnection.java
URL: http://svn.apache.org/viewvc/hadoop/hbase/branches/0.20/src/java/org/apache/hadoop/hbase/client/HConnection.java?rev=808577&r1=808576&r2=808577&view=diff
==============================================================================
--- hadoop/hbase/branches/0.20/src/java/org/apache/hadoop/hbase/client/HConnection.java (original)
+++ hadoop/hbase/branches/0.20/src/java/org/apache/hadoop/hbase/client/HConnection.java Thu Aug 27 19:37:51 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/branches/0.20/src/java/org/apache/hadoop/hbase/client/HConnectionManager.java
URL: http://svn.apache.org/viewvc/hadoop/hbase/branches/0.20/src/java/org/apache/hadoop/hbase/client/HConnectionManager.java?rev=808577&r1=808576&r2=808577&view=diff
==============================================================================
--- hadoop/hbase/branches/0.20/src/java/org/apache/hadoop/hbase/client/HConnectionManager.java (original)
+++ hadoop/hbase/branches/0.20/src/java/org/apache/hadoop/hbase/client/HConnectionManager.java Thu Aug 27 19:37:51 2009
@@ -998,10 +998,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) {
@@ -1015,7 +1015,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
@@ -1073,6 +1074,7 @@
           currentPuts.clear();
         }
       }
+      return i;
     }
 
     void close(boolean stopProxy) {

Modified: hadoop/hbase/branches/0.20/src/java/org/apache/hadoop/hbase/client/HTable.java
URL: http://svn.apache.org/viewvc/hadoop/hbase/branches/0.20/src/java/org/apache/hadoop/hbase/client/HTable.java?rev=808577&r1=808576&r2=808577&view=diff
==============================================================================
--- hadoop/hbase/branches/0.20/src/java/org/apache/hadoop/hbase/client/HTable.java (original)
+++ hadoop/hbase/branches/0.20/src/java/org/apache/hadoop/hbase/client/HTable.java Thu Aug 27 19:37:51 2009
@@ -55,13 +55,15 @@
 
 /**
  * Used to communicate with a single HBase table
+ * <p>
+ * This class is not MT safe for writing.
  */
 public class HTable {
   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,14 +579,18 @@
    * @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();
+      }
     }
   }
-   
+
   /**
    * Release held resources
    * 
@@ -683,14 +688,6 @@
     }
   }
 
-  /**
-   * Get the write buffer 
-   * @return the current write buffer
-   */
-  public ArrayList<Put> getWriteBuffer() {
-    return writeBuffer;
-  }
-
   // Old API. Pre-hbase-880, hbase-1304.
   
   /**