use of org.apache.hadoop.hbase.client.BufferedMutatorParams in project pinpoint by naver.
the class BufferedMutatorWriter method newBufferedMutatorParams.
private BufferedMutatorParams newBufferedMutatorParams(TableName tableName) {
BufferedMutatorParams params = new BufferedMutatorParams(tableName);
params.writeBufferSize(configuration.getWriteBufferSize());
params.setWriteBufferPeriodicFlushTimeoutMs(configuration.getWriteBufferPeriodicFlushTimerTickMs());
params.setWriteBufferPeriodicFlushTimerTickMs(configuration.getWriteBufferPeriodicFlushTimerTickMs());
params.pool(this.sharedPool);
// params.listener(this::onException);
return params;
}
use of org.apache.hadoop.hbase.client.BufferedMutatorParams in project hbase by apache.
the class BufferedMutatorExample method run.
@Override
public int run(String[] args) throws InterruptedException, ExecutionException, TimeoutException {
/**
* a callback invoked when an asynchronous write fails.
*/
final BufferedMutator.ExceptionListener listener = new BufferedMutator.ExceptionListener() {
@Override
public void onException(RetriesExhaustedWithDetailsException e, BufferedMutator mutator) {
for (int i = 0; i < e.getNumExceptions(); i++) {
LOG.info("Failed to sent put " + e.getRow(i) + ".");
}
}
};
BufferedMutatorParams params = new BufferedMutatorParams(TABLE).listener(listener);
//
try (final Connection conn = ConnectionFactory.createConnection(getConf());
final BufferedMutator mutator = conn.getBufferedMutator(params)) {
/**
* worker pool that operates on BufferedTable instances
*/
final ExecutorService workerPool = Executors.newFixedThreadPool(POOL_SIZE);
List<Future<Void>> futures = new ArrayList<>(TASK_COUNT);
for (int i = 0; i < TASK_COUNT; i++) {
futures.add(workerPool.submit(new Callable<Void>() {
@Override
public Void call() throws Exception {
//
// step 2: each worker sends edits to the shared BufferedMutator instance. They all use
// the same backing buffer, call-back "listener", and RPC executor pool.
//
Put p = new Put(Bytes.toBytes("someRow"));
p.addColumn(FAMILY, Bytes.toBytes("someQualifier"), Bytes.toBytes("some value"));
mutator.mutate(p);
// this worker's edits are sent before exiting the Callable
return null;
}
}));
}
//
for (Future<Void> f : futures) {
f.get(5, TimeUnit.MINUTES);
}
workerPool.shutdown();
} catch (IOException e) {
// exception while creating/destroying Connection or BufferedMutator
LOG.info("exception while creating/destroying Connection or BufferedMutator", e);
}
// invoked from here.
return 0;
}
Aggregations