hbase-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From nkey...@apache.org
Subject svn commit: r1457688 - /hbase/trunk/hbase-client/src/main/java/org/apache/hadoop/hbase/client/HTable.java
Date Mon, 18 Mar 2013 09:49:02 GMT
Author: nkeywal
Date: Mon Mar 18 09:49:01 2013
New Revision: 1457688

URL: http://svn.apache.org/r1457688
Log:
HBASE-8128 HTable#put improvements

Modified:
    hbase/trunk/hbase-client/src/main/java/org/apache/hadoop/hbase/client/HTable.java

Modified: hbase/trunk/hbase-client/src/main/java/org/apache/hadoop/hbase/client/HTable.java
URL: http://svn.apache.org/viewvc/hbase/trunk/hbase-client/src/main/java/org/apache/hadoop/hbase/client/HTable.java?rev=1457688&r1=1457687&r2=1457688&view=diff
==============================================================================
--- hbase/trunk/hbase-client/src/main/java/org/apache/hadoop/hbase/client/HTable.java (original)
+++ hbase/trunk/hbase-client/src/main/java/org/apache/hadoop/hbase/client/HTable.java Mon
Mar 18 09:49:01 2013
@@ -57,7 +57,6 @@ import java.io.Closeable;
 import java.io.IOException;
 import java.io.InterruptedIOException;
 import java.util.ArrayList;
-import java.util.Arrays;
 import java.util.Collections;
 import java.util.HashMap;
 import java.util.List;
@@ -130,7 +129,6 @@ public class HTable implements HTableInt
   private ExecutorService pool;  // For Multi
   private boolean closed;
   private int operationTimeout;
-  private static final int DOPUT_WB_CHECK = 10;    // i.e., doPut checks the writebuffer
every X Puts.
   private final boolean cleanupPoolOnClose; // shutdown the pool in close()
   private final boolean cleanupConnectionOnClose; // close the connection in close()
 
@@ -668,7 +666,10 @@ public class HTable implements HTableInt
    */
   @Override
   public void put(final Put put) throws IOException {
-    doPut(Arrays.asList(put));
+    doPut(put);
+    if (autoFlush) {
+      flushCommits();
+    }
   }
 
   /**
@@ -676,23 +677,19 @@ public class HTable implements HTableInt
    */
   @Override
   public void put(final List<Put> puts) throws IOException {
-    doPut(puts);
-  }
-
-  private void doPut(final List<Put> puts) throws IOException {
-    int n = 0;
     for (Put put : puts) {
-      validatePut(put);
-      writeBuffer.add(put);
-      currentWriteBufferSize += put.heapSize();
-
-      // we need to periodically see if the writebuffer is full instead of waiting until
the end of the List
-      n++;
-      if (n % DOPUT_WB_CHECK == 0 && currentWriteBufferSize > writeBufferSize)
{
-        flushCommits();
-      }
+      doPut(put);
+    }
+    if (autoFlush) {
+      flushCommits();
     }
-    if (autoFlush || currentWriteBufferSize > writeBufferSize) {
+  }
+
+  private void doPut(Put put) throws IOException{
+    validatePut(put);
+    writeBuffer.add(put);
+    currentWriteBufferSize += put.heapSize();
+    if (currentWriteBufferSize > writeBufferSize) {
       flushCommits();
     }
   }
@@ -1021,6 +1018,11 @@ public class HTable implements HTableInt
    */
   @Override
   public void flushCommits() throws IOException {
+    if (writeBuffer.isEmpty()){
+      // Early exit: we can be called on empty buffers.
+      return;
+    }
+
     Object[] results = new Object[writeBuffer.size()];
     boolean success = false;
     try {



Mime
View raw message