Search in sources :

Example 6 with BufferedMutatorParams

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;
}
Also used : BufferedMutatorParams(org.apache.hadoop.hbase.client.BufferedMutatorParams)

Example 7 with BufferedMutatorParams

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;
}
Also used : BufferedMutator(org.apache.hadoop.hbase.client.BufferedMutator) Connection(org.apache.hadoop.hbase.client.Connection) ArrayList(java.util.ArrayList) IOException(java.io.IOException) Callable(java.util.concurrent.Callable) Put(org.apache.hadoop.hbase.client.Put) RetriesExhaustedWithDetailsException(org.apache.hadoop.hbase.client.RetriesExhaustedWithDetailsException) BufferedMutatorParams(org.apache.hadoop.hbase.client.BufferedMutatorParams) ExecutorService(java.util.concurrent.ExecutorService) Future(java.util.concurrent.Future)

Aggregations

BufferedMutatorParams (org.apache.hadoop.hbase.client.BufferedMutatorParams)7 IOException (java.io.IOException)3 TableName (org.apache.hadoop.hbase.TableName)3 BufferedMutator (org.apache.hadoop.hbase.client.BufferedMutator)2 Put (org.apache.hadoop.hbase.client.Put)2 RetriesExhaustedWithDetailsException (org.apache.hadoop.hbase.client.RetriesExhaustedWithDetailsException)2 ArrayList (java.util.ArrayList)1 Map (java.util.Map)1 NavigableMap (java.util.NavigableMap)1 Callable (java.util.concurrent.Callable)1 ExecutorService (java.util.concurrent.ExecutorService)1 Future (java.util.concurrent.Future)1 AtomicLong (java.util.concurrent.atomic.AtomicLong)1 ExecutorThreadFactory (org.apache.flink.util.concurrent.ExecutorThreadFactory)1 TableNotFoundException (org.apache.hadoop.hbase.TableNotFoundException)1 Connection (org.apache.hadoop.hbase.client.Connection)1