Search in sources :

Example 6 with Timeout

use of org.apache.hbase.thirdparty.io.netty.util.Timeout in project hbase by apache.

the class TestAsyncBufferMutator method testCancelPeriodicFlushByClose.

@Test
public void testCancelPeriodicFlushByClose() throws InterruptedException, ExecutionException {
    CompletableFuture<?> future;
    Timeout task;
    try (AsyncBufferedMutatorImpl mutator = (AsyncBufferedMutatorImpl) CONN.getBufferedMutatorBuilder(TABLE_NAME).setWriteBufferPeriodicFlush(1, TimeUnit.SECONDS).build()) {
        future = mutator.mutate(new Put(Bytes.toBytes(0)).addColumn(CF, CQ, VALUE));
        task = mutator.periodicFlushTask;
        // we should have scheduled a periodic flush task
        assertNotNull(task);
    }
    assertTrue(task.isCancelled());
    future.get();
    AsyncTable<?> table = CONN.getTable(TABLE_NAME);
    assertArrayEquals(VALUE, table.get(new Get(Bytes.toBytes(0))).get().getValue(CF, CQ));
}
Also used : Timeout(org.apache.hbase.thirdparty.io.netty.util.Timeout) Test(org.junit.Test)

Example 7 with Timeout

use of org.apache.hbase.thirdparty.io.netty.util.Timeout in project hbase by apache.

the class TestAsyncBufferMutator method testCancelPeriodicFlush.

// a bit deep into the implementation
@Test
public void testCancelPeriodicFlush() throws InterruptedException, ExecutionException {
    Put put = new Put(Bytes.toBytes(0)).addColumn(CF, CQ, VALUE);
    try (AsyncBufferedMutatorImpl mutator = (AsyncBufferedMutatorImpl) CONN.getBufferedMutatorBuilder(TABLE_NAME).setWriteBufferPeriodicFlush(1, TimeUnit.SECONDS).setWriteBufferSize(10 * put.heapSize()).build()) {
        List<CompletableFuture<?>> futures = new ArrayList<>();
        futures.add(mutator.mutate(put));
        Timeout task = mutator.periodicFlushTask;
        // we should have scheduled a periodic flush task
        assertNotNull(task);
        for (int i = 1; ; i++) {
            futures.add(mutator.mutate(new Put(Bytes.toBytes(i)).addColumn(CF, CQ, VALUE)));
            if (mutator.periodicFlushTask == null) {
                break;
            }
        }
        assertTrue(task.isCancelled());
        CompletableFuture.allOf(futures.toArray(new CompletableFuture[0])).join();
        AsyncTable<?> table = CONN.getTable(TABLE_NAME);
        for (int i = 0; i < futures.size(); i++) {
            assertArrayEquals(VALUE, table.get(new Get(Bytes.toBytes(i))).get().getValue(CF, CQ));
        }
    }
}
Also used : CompletableFuture(java.util.concurrent.CompletableFuture) Timeout(org.apache.hbase.thirdparty.io.netty.util.Timeout) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 8 with Timeout

use of org.apache.hbase.thirdparty.io.netty.util.Timeout in project hbase by apache.

the class AsyncRegionLocator method withTimeout.

private <T> CompletableFuture<T> withTimeout(CompletableFuture<T> future, long timeoutNs, Supplier<String> timeoutMsg) {
    if (future.isDone() || timeoutNs <= 0) {
        return future;
    }
    Timeout timeoutTask = retryTimer.newTimeout(t -> {
        if (future.isDone()) {
            return;
        }
        future.completeExceptionally(new TimeoutIOException(timeoutMsg.get()));
    }, timeoutNs, TimeUnit.NANOSECONDS);
    FutureUtils.addListener(future, (loc, error) -> {
        if (error != null && error.getClass() != TimeoutIOException.class) {
            // cancel timeout task if we are not completed by it.
            timeoutTask.cancel();
        }
    });
    return future;
}
Also used : Timeout(org.apache.hbase.thirdparty.io.netty.util.Timeout) TimeoutIOException(org.apache.hadoop.hbase.exceptions.TimeoutIOException)

Aggregations

Timeout (org.apache.hbase.thirdparty.io.netty.util.Timeout)8 ArrayList (java.util.ArrayList)4 CompletableFuture (java.util.concurrent.CompletableFuture)4 IOException (java.io.IOException)3 List (java.util.List)3 TimeUnit (java.util.concurrent.TimeUnit)3 Collectors (java.util.stream.Collectors)3 Stream (java.util.stream.Stream)3 Configuration (org.apache.hadoop.conf.Configuration)3 TableName (org.apache.hadoop.hbase.TableName)3 FutureUtils.addListener (org.apache.hadoop.hbase.util.FutureUtils.addListener)3 HashedWheelTimer (org.apache.hbase.thirdparty.io.netty.util.HashedWheelTimer)3 InterfaceAudience (org.apache.yetus.audience.InterfaceAudience)3 Test (org.junit.Test)3 Nullable (edu.umd.cs.findbugs.annotations.Nullable)2 Arrays (java.util.Arrays)2 Collections (java.util.Collections)2 EnumSet (java.util.EnumSet)2 HashMap (java.util.HashMap)2 Map (java.util.Map)2