diff --git a/hbase-client/src/main/java/org/apache/hadoop/hbase/client/HTable.java b/hbase-client/src/main/java/org/apache/hadoop/hbase/client/HTable.java index bbf5e78ce9f..8ddd9467037 100644 --- a/hbase-client/src/main/java/org/apache/hadoop/hbase/client/HTable.java +++ b/hbase-client/src/main/java/org/apache/hadoop/hbase/client/HTable.java @@ -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 HTableInterface { 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 HTableInterface { */ @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 HTableInterface { */ @Override public void put(final List puts) throws IOException { - doPut(puts); + for (Put put : puts) { + doPut(put); + } + if (autoFlush) { + flushCommits(); + } } - private void doPut(final List 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(); - } - } - 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 HTableInterface { */ @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 {