Search in sources :

Example 6 with MasterNotRunningException

use of org.apache.hadoop.hbase.MasterNotRunningException 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)

Example 7 with MasterNotRunningException

use of org.apache.hadoop.hbase.MasterNotRunningException in project hbase by apache.

the class TestHBaseAdminNoCluster method testMasterOperationIsRetried.

private void testMasterOperationIsRetried(MethodCaller caller) throws Exception {
    Configuration configuration = HBaseConfiguration.create();
    // Set the pause and retry count way down.
    configuration.setLong(HConstants.HBASE_CLIENT_PAUSE, 1);
    final int count = 10;
    configuration.setInt(HConstants.HBASE_CLIENT_RETRIES_NUMBER, count);
    ClusterConnection connection = mock(ClusterConnection.class);
    when(connection.getConfiguration()).thenReturn(configuration);
    MasterKeepAliveConnection masterAdmin = Mockito.mock(MasterKeepAliveConnection.class, new Answer() {

        @Override
        public Object answer(InvocationOnMock invocation) throws Throwable {
            if (invocation.getMethod().getName().equals("close")) {
                return null;
            }
            // all methods will throw an exception
            throw new MasterNotRunningException();
        }
    });
    Mockito.when(connection.getKeepAliveMasterService()).thenReturn(masterAdmin);
    RpcControllerFactory rpcControllerFactory = Mockito.mock(RpcControllerFactory.class);
    Mockito.when(connection.getRpcControllerFactory()).thenReturn(rpcControllerFactory);
    Mockito.when(rpcControllerFactory.newController()).thenReturn(Mockito.mock(HBaseRpcController.class));
    // we need a real retrying caller
    RpcRetryingCallerFactory callerFactory = new RpcRetryingCallerFactory(configuration);
    Mockito.when(connection.getRpcRetryingCallerFactory()).thenReturn(callerFactory);
    Admin admin = null;
    try {
        admin = Mockito.spy(new HBaseAdmin(connection));
        // mock the call to getRegion since in the absence of a cluster (which means the meta
        // is not assigned), getRegion can't function
        Mockito.doReturn(null).when(((HBaseAdmin) admin)).getRegion(Matchers.<byte[]>any());
        try {
            // invoke the HBaseAdmin method
            caller.call(admin);
            fail();
        } catch (RetriesExhaustedException e) {
            LOG.info("Expected fail", e);
        }
        // Assert we were called 'count' times.
        caller.verify(masterAdmin, count);
    } finally {
        if (admin != null) {
            admin.close();
        }
    }
}
Also used : Configuration(org.apache.hadoop.conf.Configuration) HBaseConfiguration(org.apache.hadoop.hbase.HBaseConfiguration) RpcControllerFactory(org.apache.hadoop.hbase.ipc.RpcControllerFactory) Answer(org.mockito.stubbing.Answer) HBaseRpcController(org.apache.hadoop.hbase.ipc.HBaseRpcController) InvocationOnMock(org.mockito.invocation.InvocationOnMock) MasterNotRunningException(org.apache.hadoop.hbase.MasterNotRunningException)

Example 8 with MasterNotRunningException

use of org.apache.hadoop.hbase.MasterNotRunningException in project hbase by apache.

the class HMasterCommandLine method stopMaster.

@SuppressWarnings("resource")
private int stopMaster() {
    Configuration conf = getConf();
    // Don't try more than once
    conf.setInt(HConstants.HBASE_CLIENT_RETRIES_NUMBER, 0);
    try (Connection connection = ConnectionFactory.createConnection(conf)) {
        try (Admin admin = connection.getAdmin()) {
            admin.shutdown();
        } catch (Throwable t) {
            LOG.error("Failed to stop master", t);
            return 1;
        }
    } catch (MasterNotRunningException e) {
        LOG.error("Master not running");
        return 1;
    } catch (ZooKeeperConnectionException e) {
        LOG.error("ZooKeeper not available");
        return 1;
    } catch (IOException e) {
        LOG.error("Got IOException: " + e.getMessage(), e);
        return 1;
    }
    return 0;
}
Also used : Configuration(org.apache.hadoop.conf.Configuration) MasterNotRunningException(org.apache.hadoop.hbase.MasterNotRunningException) Connection(org.apache.hadoop.hbase.client.Connection) ZooKeeperConnectionException(org.apache.hadoop.hbase.ZooKeeperConnectionException) IOException(java.io.IOException) Admin(org.apache.hadoop.hbase.client.Admin)

Example 9 with MasterNotRunningException

use of org.apache.hadoop.hbase.MasterNotRunningException in project hbase by apache.

the class HMaster method createSystemTable.

@Override
public long createSystemTable(final HTableDescriptor hTableDescriptor) throws IOException {
    if (isStopped()) {
        throw new MasterNotRunningException();
    }
    TableName tableName = hTableDescriptor.getTableName();
    if (!(tableName.isSystemTable())) {
        throw new IllegalArgumentException("Only system table creation can use this createSystemTable API");
    }
    HRegionInfo[] newRegions = ModifyRegionUtils.createHRegionInfos(hTableDescriptor, null);
    LOG.info(getClientIdAuditPrefix() + " create " + hTableDescriptor);
    // This special create table is called locally to master.  Therefore, no RPC means no need
    // to use nonce to detect duplicated RPC call.
    long procId = this.procedureExecutor.submitProcedure(new CreateTableProcedure(procedureExecutor.getEnvironment(), hTableDescriptor, newRegions));
    return procId;
}
Also used : HRegionInfo(org.apache.hadoop.hbase.HRegionInfo) TableName(org.apache.hadoop.hbase.TableName) MasterNotRunningException(org.apache.hadoop.hbase.MasterNotRunningException) CreateTableProcedure(org.apache.hadoop.hbase.master.procedure.CreateTableProcedure)

Example 10 with MasterNotRunningException

use of org.apache.hadoop.hbase.MasterNotRunningException in project Solbase by Photobucket.

the class SolbaseIndexerTool method setupTables.

private void setupTables() {
    HBaseAdmin admin;
    try {
        // should be running on the cluster that has zoo.cfg or hbase-site.xml on hadoop/hbase classpath already.
        Configuration conf = HBaseConfiguration.create();
        admin = new HBaseAdmin(conf);
        if (!admin.isTableAvailable(SolbaseUtil.termVectorTable)) {
            SolbaseUtil.createTermVectorTable(null, null, null);
        } else {
        //SolbaseUtil.truncateTable(admin, SolbaseUtil.termVectorTable);
        }
        if (!admin.isTableAvailable(SolbaseUtil.termVectorVersionIDTable)) {
            SolbaseUtil.createTermVectorVersionIDTable();
        } else {
        //SolbaseUtil.truncateTable(admin, SolbaseUtil.termVectorVersionIDTable);
        }
        if (!admin.isTableAvailable(SolbaseUtil.docKeyIdMapTable)) {
            SolbaseUtil.createDocKeyIdMapTable(null, null, null);
        } else {
        //SolbaseUtil.truncateTable(admin, SolbaseUtil.docKeyIdMapTable);
        }
        if (!admin.isTableAvailable(SolbaseUtil.docTable)) {
            SolbaseUtil.createDocTable(null, null, null);
        } else {
        //SolbaseUtil.truncateTable(admin, SolbaseUtil.docTable);
        }
        if (!admin.isTableAvailable(SolbaseUtil.sequenceTable)) {
            SolbaseUtil.createSequenceTable();
        } else {
        //SolbaseUtil.truncateTable(admin, SolbaseUtil.sequenceTable);
        }
        if (!admin.isTableAvailable(SolbaseUtil.uniqChecksumUserMediaTable)) {
            SolbaseUtil.createUniqChecksumUserMediaTable(null, null, null);
        } else {
        //SolbaseUtil.truncateTable(admin, SolbaseUtil.uniqChecksumUserMediaTable);
        }
    } catch (MasterNotRunningException e) {
        e.printStackTrace();
    } catch (ZooKeeperConnectionException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }
}
Also used : HBaseAdmin(org.apache.hadoop.hbase.client.HBaseAdmin) HBaseConfiguration(org.apache.hadoop.hbase.HBaseConfiguration) Configuration(org.apache.hadoop.conf.Configuration) MasterNotRunningException(org.apache.hadoop.hbase.MasterNotRunningException) ZooKeeperConnectionException(org.apache.hadoop.hbase.ZooKeeperConnectionException) IOException(java.io.IOException)

Aggregations

MasterNotRunningException (org.apache.hadoop.hbase.MasterNotRunningException)10 IOException (java.io.IOException)5 ZooKeeperConnectionException (org.apache.hadoop.hbase.ZooKeeperConnectionException)5 Configuration (org.apache.hadoop.conf.Configuration)4 HBaseConfiguration (org.apache.hadoop.hbase.HBaseConfiguration)3 BiMap (com.google.common.collect.BiMap)2 ImmutableBiMap (com.google.common.collect.ImmutableBiMap)2 ImmutableMap (com.google.common.collect.ImmutableMap)2 KeyRange (com.thinkaurelius.titan.diskstorage.keycolumnvalue.KeyRange)2 HashMap (java.util.HashMap)2 LinkedList (java.util.LinkedList)2 Map (java.util.Map)2 NavigableMap (java.util.NavigableMap)2 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)2 ConcurrentMap (java.util.concurrent.ConcurrentMap)2 ServerName (org.apache.hadoop.hbase.ServerName)2 HBaseAdmin (org.apache.hadoop.hbase.client.HBaseAdmin)2 HTable (org.apache.hadoop.hbase.client.HTable)2 HBaseRpcController (org.apache.hadoop.hbase.ipc.HBaseRpcController)2 HColumnDescriptor (org.apache.hadoop.hbase.HColumnDescriptor)1