Search in sources :

Example 1 with IsMasterRunningResponse

use of org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProtos.IsMasterRunningResponse in project hbase by apache.

the class AsyncConnectionImpl method getMasterStub.

CompletableFuture<MasterService.Interface> getMasterStub() {
    MasterService.Interface masterStub = this.masterStub.get();
    if (masterStub == null) {
        for (; ; ) {
            if (this.masterStubMakeFuture.compareAndSet(null, new CompletableFuture<>())) {
                CompletableFuture<MasterService.Interface> future = this.masterStubMakeFuture.get();
                makeMasterStub(future);
            } else {
                CompletableFuture<MasterService.Interface> future = this.masterStubMakeFuture.get();
                if (future != null) {
                    return future;
                }
            }
        }
    }
    for (; ; ) {
        if (masterStubMakeFuture.compareAndSet(null, new CompletableFuture<>())) {
            CompletableFuture<MasterService.Interface> future = masterStubMakeFuture.get();
            HBaseRpcController controller = getRpcController();
            masterStub.isMasterRunning(controller, RequestConverter.buildIsMasterRunningRequest(), new RpcCallback<IsMasterRunningResponse>() {

                @Override
                public void run(IsMasterRunningResponse resp) {
                    if (controller.failed() || resp == null || (resp != null && !resp.getIsMasterRunning())) {
                        makeMasterStub(future);
                    } else {
                        future.complete(masterStub);
                    }
                }
            });
        } else {
            CompletableFuture<MasterService.Interface> future = masterStubMakeFuture.get();
            if (future != null) {
                return future;
            }
        }
    }
}
Also used : HBaseRpcController(org.apache.hadoop.hbase.ipc.HBaseRpcController) IsMasterRunningResponse(org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProtos.IsMasterRunningResponse) MasterService(org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProtos.MasterService)

Example 2 with IsMasterRunningResponse

use of org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProtos.IsMasterRunningResponse in project hbase by apache.

the class AsyncConnectionImpl method makeMasterStub.

private void makeMasterStub(CompletableFuture<MasterService.Interface> future) {
    registry.getMasterAddress().whenComplete((sn, error) -> {
        if (sn == null) {
            String msg = "ZooKeeper available but no active master location found";
            LOG.info(msg);
            this.masterStubMakeFuture.getAndSet(null).completeExceptionally(new MasterNotRunningException(msg));
            return;
        }
        try {
            MasterService.Interface stub = createMasterStub(sn);
            HBaseRpcController controller = getRpcController();
            stub.isMasterRunning(controller, RequestConverter.buildIsMasterRunningRequest(), new RpcCallback<IsMasterRunningResponse>() {

                @Override
                public void run(IsMasterRunningResponse resp) {
                    if (controller.failed() || resp == null || (resp != null && !resp.getIsMasterRunning())) {
                        masterStubMakeFuture.getAndSet(null).completeExceptionally(new MasterNotRunningException("Master connection is not running anymore"));
                    } else {
                        masterStub.set(stub);
                        masterStubMakeFuture.set(null);
                        future.complete(stub);
                    }
                }
            });
        } catch (IOException e) {
            this.masterStubMakeFuture.getAndSet(null).completeExceptionally(new IOException("Failed to create async master stub", e));
        }
    });
}
Also used : HBaseRpcController(org.apache.hadoop.hbase.ipc.HBaseRpcController) IsMasterRunningResponse(org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProtos.IsMasterRunningResponse) MasterNotRunningException(org.apache.hadoop.hbase.MasterNotRunningException) IOException(java.io.IOException) MasterService(org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProtos.MasterService)

Aggregations

HBaseRpcController (org.apache.hadoop.hbase.ipc.HBaseRpcController)2 IsMasterRunningResponse (org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProtos.IsMasterRunningResponse)2 MasterService (org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProtos.MasterService)2 IOException (java.io.IOException)1 MasterNotRunningException (org.apache.hadoop.hbase.MasterNotRunningException)1