public
Created

Get a HTableInterface from HTablePool with autoFlush disabled (not needed in newer HBase versions, needed in 0.92.x).

  • Download Gist
HTablePoolHelper.java
Java
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
// HBase bug 5728: setAutoFlush(boolean) is missing from HTableInterface.
// Solution: custom HTableInterfaceFactory (suggestion from the HBase user mailing-list)
HTablePool pool = new HTablePool(conf, Integer.MAX_VALUE, new HTableInterfaceFactory() {
@Override
public HTableInterface createHTableInterface(Configuration config, byte[] tableName) {
try {
HTable table = new HTable(config, tableName);
 
// Don't send out any RPC calls until the buffer is full to prevent generating one
// call per operation.
table.setAutoFlush(false);
return table;
} catch (IOException ioe) {
throw new RuntimeException(ioe);
}
}
 
@Override
public void releaseHTableInterface(HTableInterface table) throws IOException {
// Do nothing. Required stub.
}
});
 
return pool;

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.