Search in sources :

Example 51 with CompletableFuture

use of java.util.concurrent.CompletableFuture in project hbase by apache.

the class AsyncHBaseAdmin method getTableDescriptor.

@Override
public CompletableFuture<HTableDescriptor> getTableDescriptor(TableName tableName) {
    CompletableFuture<HTableDescriptor> future = new CompletableFuture<>();
    this.<List<TableSchema>>newMasterCaller().action((controller, stub) -> this.<GetTableDescriptorsRequest, GetTableDescriptorsResponse, List<TableSchema>>call(controller, stub, RequestConverter.buildGetTableDescriptorsRequest(tableName), (s, c, req, done) -> s.getTableDescriptors(c, req, done), (resp) -> resp.getTableSchemaList())).call().whenComplete((tableSchemas, error) -> {
        if (error != null) {
            future.completeExceptionally(error);
            return;
        }
        if (!tableSchemas.isEmpty()) {
            future.complete(ProtobufUtil.convertToHTableDesc(tableSchemas.get(0)));
        } else {
            future.completeExceptionally(new TableNotFoundException(tableName.getNameAsString()));
        }
    });
    return future;
}
Also used : GetSchemaAlterStatusRequest(org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProtos.GetSchemaAlterStatusRequest) Arrays(java.util.Arrays) TableNotFoundException(org.apache.hadoop.hbase.TableNotFoundException) CreateTableResponse(org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProtos.CreateTableResponse) AsyncMetaTableAccessor(org.apache.hadoop.hbase.AsyncMetaTableAccessor) DeleteTableResponse(org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProtos.DeleteTableResponse) HColumnDescriptor(org.apache.hadoop.hbase.HColumnDescriptor) RegionLocations(org.apache.hadoop.hbase.RegionLocations) GetTableDescriptorsResponse(org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProtos.GetTableDescriptorsResponse) IsBalancerEnabledRequest(org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProtos.IsBalancerEnabledRequest) DisableTableResponse(org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProtos.DisableTableResponse) NotServingRegionException(org.apache.hadoop.hbase.NotServingRegionException) GetNamespaceDescriptorRequest(org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProtos.GetNamespaceDescriptorRequest) HTableDescriptor(org.apache.hadoop.hbase.HTableDescriptor) IsBalancerEnabledResponse(org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProtos.IsBalancerEnabledResponse) ForeignExceptionUtil(org.apache.hadoop.hbase.util.ForeignExceptionUtil) DeleteNamespaceRequest(org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProtos.DeleteNamespaceRequest) CreateNamespaceResponse(org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProtos.CreateNamespaceResponse) InterfaceStability(org.apache.hadoop.hbase.classification.InterfaceStability) CreateTableRequest(org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProtos.CreateTableRequest) Pair(org.apache.hadoop.hbase.util.Pair) TruncateTableRequest(org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProtos.TruncateTableRequest) RpcCallback(org.apache.hadoop.hbase.shaded.com.google.protobuf.RpcCallback) ProtobufUtil(org.apache.hadoop.hbase.shaded.protobuf.ProtobufUtil) EnableTableRequest(org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProtos.EnableTableRequest) CloseRegionRequest(org.apache.hadoop.hbase.shaded.protobuf.generated.AdminProtos.CloseRegionRequest) AddColumnResponse(org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProtos.AddColumnResponse) HBaseRpcController(org.apache.hadoop.hbase.ipc.HBaseRpcController) MasterService(org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProtos.MasterService) SetBalancerRunningResponse(org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProtos.SetBalancerRunningResponse) List(java.util.List) BalanceResponse(org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProtos.BalanceResponse) UnknownRegionException(org.apache.hadoop.hbase.UnknownRegionException) ModifyNamespaceRequest(org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProtos.ModifyNamespaceRequest) GetTableNamesRequest(org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProtos.GetTableNamesRequest) BalanceRequest(org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProtos.BalanceRequest) Pattern(java.util.regex.Pattern) LogFactory(org.apache.commons.logging.LogFactory) InterfaceAudience(org.apache.hadoop.hbase.classification.InterfaceAudience) AdminRequestCallerBuilder(org.apache.hadoop.hbase.client.AsyncRpcRetryingCallerFactory.AdminRequestCallerBuilder) MetaTableAccessor(org.apache.hadoop.hbase.MetaTableAccessor) META_TABLE_NAME(org.apache.hadoop.hbase.TableName.META_TABLE_NAME) GetTableDescriptorsRequest(org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProtos.GetTableDescriptorsRequest) ModifyColumnRequest(org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProtos.ModifyColumnRequest) EnableTableResponse(org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProtos.EnableTableResponse) ListNamespaceDescriptorsResponse(org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProtos.ListNamespaceDescriptorsResponse) NamespaceDescriptor(org.apache.hadoop.hbase.NamespaceDescriptor) GetProcedureResultRequest(org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProtos.GetProcedureResultRequest) CompletableFuture(java.util.concurrent.CompletableFuture) AddColumnRequest(org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProtos.AddColumnRequest) DeleteTableRequest(org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProtos.DeleteTableRequest) GetNamespaceDescriptorResponse(org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProtos.GetNamespaceDescriptorResponse) HConstants(org.apache.hadoop.hbase.HConstants) DisableTableRequest(org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProtos.DisableTableRequest) BiConsumer(java.util.function.BiConsumer) LinkedList(java.util.LinkedList) ModifyColumnResponse(org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProtos.ModifyColumnResponse) ServerName(org.apache.hadoop.hbase.ServerName) Bytes(org.apache.hadoop.hbase.util.Bytes) ReadType(org.apache.hadoop.hbase.client.Scan.ReadType) CreateNamespaceRequest(org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProtos.CreateNamespaceRequest) SetBalancerRunningRequest(org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProtos.SetBalancerRunningRequest) TableName(org.apache.hadoop.hbase.TableName) TableSchema(org.apache.hadoop.hbase.shaded.protobuf.generated.HBaseProtos.TableSchema) ModifyNamespaceResponse(org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProtos.ModifyNamespaceResponse) AdminService(org.apache.hadoop.hbase.shaded.protobuf.generated.AdminProtos.AdminService) GetProcedureResultResponse(org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProtos.GetProcedureResultResponse) GetTableNamesResponse(org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProtos.GetTableNamesResponse) IOException(java.io.IOException) MasterRequestCallerBuilder(org.apache.hadoop.hbase.client.AsyncRpcRetryingCallerFactory.MasterRequestCallerBuilder) ListNamespaceDescriptorsRequest(org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProtos.ListNamespaceDescriptorsRequest) RequestConverter(org.apache.hadoop.hbase.shaded.protobuf.RequestConverter) HRegionInfo(org.apache.hadoop.hbase.HRegionInfo) DeleteNamespaceResponse(org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProtos.DeleteNamespaceResponse) TimeUnit(java.util.concurrent.TimeUnit) DeleteColumnRequest(org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProtos.DeleteColumnRequest) GetSchemaAlterStatusResponse(org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProtos.GetSchemaAlterStatusResponse) CloseRegionResponse(org.apache.hadoop.hbase.shaded.protobuf.generated.AdminProtos.CloseRegionResponse) HRegionLocation(org.apache.hadoop.hbase.HRegionLocation) DeleteColumnResponse(org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProtos.DeleteColumnResponse) TruncateTableResponse(org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProtos.TruncateTableResponse) Log(org.apache.commons.logging.Log) TableNotFoundException(org.apache.hadoop.hbase.TableNotFoundException) CompletableFuture(java.util.concurrent.CompletableFuture) TableSchema(org.apache.hadoop.hbase.shaded.protobuf.generated.HBaseProtos.TableSchema) HTableDescriptor(org.apache.hadoop.hbase.HTableDescriptor)

Example 52 with CompletableFuture

use of java.util.concurrent.CompletableFuture in project hbase by apache.

the class AsyncClientScanner method callOpenScanner.

private CompletableFuture<OpenScannerResponse> callOpenScanner(HBaseRpcController controller, HRegionLocation loc, ClientService.Interface stub) {
    CompletableFuture<OpenScannerResponse> future = new CompletableFuture<>();
    try {
        ScanRequest request = RequestConverter.buildScanRequest(loc.getRegionInfo().getRegionName(), scan, scan.getCaching(), false);
        stub.scan(controller, request, resp -> {
            if (controller.failed()) {
                future.completeExceptionally(controller.getFailed());
                return;
            }
            future.complete(new OpenScannerResponse(loc, stub, controller, resp));
        });
    } catch (IOException e) {
        future.completeExceptionally(e);
    }
    return future;
}
Also used : ScanRequest(org.apache.hadoop.hbase.shaded.protobuf.generated.ClientProtos.ScanRequest) CompletableFuture(java.util.concurrent.CompletableFuture) IOException(java.io.IOException)

Example 53 with CompletableFuture

use of java.util.concurrent.CompletableFuture in project hbase by apache.

the class AsyncMetaTableAccessor method getRegion.

public static CompletableFuture<Pair<HRegionInfo, ServerName>> getRegion(RawAsyncTable metaTable, byte[] regionName) {
    CompletableFuture<Pair<HRegionInfo, ServerName>> future = new CompletableFuture<>();
    byte[] row = regionName;
    HRegionInfo parsedInfo = null;
    try {
        parsedInfo = MetaTableAccessor.parseRegionInfoFromRegionName(regionName);
        row = MetaTableAccessor.getMetaKeyForRegion(parsedInfo);
    } catch (Exception parseEx) {
    // Ignore if regionName is a encoded region name.
    }
    final HRegionInfo finalHRI = parsedInfo;
    metaTable.get(new Get(row).addFamily(HConstants.CATALOG_FAMILY)).whenComplete((r, err) -> {
        if (err != null) {
            future.completeExceptionally(err);
            return;
        }
        RegionLocations locations = MetaTableAccessor.getRegionLocations(r);
        HRegionLocation hrl = locations == null ? null : locations.getRegionLocation(finalHRI == null ? 0 : finalHRI.getReplicaId());
        if (hrl == null) {
            future.complete(null);
        } else {
            future.complete(new Pair<>(hrl.getRegionInfo(), hrl.getServerName()));
        }
    });
    return future;
}
Also used : CompletableFuture(java.util.concurrent.CompletableFuture) Get(org.apache.hadoop.hbase.client.Get) IOException(java.io.IOException) DeserializationException(org.apache.hadoop.hbase.exceptions.DeserializationException) Pair(org.apache.hadoop.hbase.util.Pair)

Example 54 with CompletableFuture

use of java.util.concurrent.CompletableFuture in project hbase by apache.

the class AsyncMetaTableAccessor method getTableState.

public static CompletableFuture<Optional<TableState>> getTableState(RawAsyncTable metaTable, TableName tableName) {
    CompletableFuture<Optional<TableState>> future = new CompletableFuture<>();
    Get get = new Get(tableName.getName()).addColumn(getTableFamily(), getStateColumn());
    long time = EnvironmentEdgeManager.currentTime();
    try {
        get.setTimeRange(0, time);
        metaTable.get(get).whenComplete((result, error) -> {
            if (error != null) {
                future.completeExceptionally(error);
                return;
            }
            try {
                future.complete(getTableState(result));
            } catch (IOException e) {
                future.completeExceptionally(e);
            }
        });
    } catch (IOException ioe) {
        future.completeExceptionally(ioe);
    }
    return future;
}
Also used : CompletableFuture(java.util.concurrent.CompletableFuture) Optional(java.util.Optional) Get(org.apache.hadoop.hbase.client.Get) IOException(java.io.IOException)

Example 55 with CompletableFuture

use of java.util.concurrent.CompletableFuture in project crate by crate.

the class PageDownstreamContextTest method testSetBucketOnAKilledCtxReleasesListener.

@Test
public void testSetBucketOnAKilledCtxReleasesListener() throws Exception {
    TestingBatchConsumer consumer = new TestingBatchConsumer();
    PageDownstreamContext ctx = getPageDownstreamContext(consumer, PassThroughPagingIterator.oneShot(), 2);
    ctx.kill(new InterruptedException("killed"));
    CompletableFuture<Void> listenerReleased = new CompletableFuture<>();
    ctx.setBucket(0, Bucket.EMPTY, false, needMore -> listenerReleased.complete(null));
    // Must not timeout
    listenerReleased.get(1, TimeUnit.SECONDS);
}
Also used : CompletableFuture(java.util.concurrent.CompletableFuture) TestingBatchConsumer(io.crate.testing.TestingBatchConsumer) Test(org.junit.Test) CrateUnitTest(io.crate.test.integration.CrateUnitTest)

Aggregations

CompletableFuture (java.util.concurrent.CompletableFuture)490 Test (org.junit.Test)152 ArrayList (java.util.ArrayList)88 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)77 List (java.util.List)75 UUID (java.util.UUID)62 Futures (io.pravega.common.concurrent.Futures)60 Map (java.util.Map)59 ScheduledExecutorService (java.util.concurrent.ScheduledExecutorService)57 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)53 HashMap (java.util.HashMap)52 TimeUnit (java.util.concurrent.TimeUnit)52 Cleanup (lombok.Cleanup)49 Exceptions (io.pravega.common.Exceptions)48 Collectors (java.util.stream.Collectors)48 lombok.val (lombok.val)47 IOException (java.io.IOException)46 Duration (java.time.Duration)46 Slf4j (lombok.extern.slf4j.Slf4j)46 AtomicReference (java.util.concurrent.atomic.AtomicReference)45