HBASE-8128 HTable#put improvements

git-svn-id: https://svn.apache.org/repos/asf/hbase/trunk@1457688 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
nkeywal 2013-03-18 09:49:01 +00:00
parent 5d1e0a7055
commit c826a16e5d

View File

@ -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<Put> puts) throws IOException {
doPut(puts);
for (Put put : puts) {
doPut(put);
}
if (autoFlush) {
flushCommits();
}
}
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();
}
}
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 {