Search in sources :

Example 1 with ZKNamespaceManager

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

the class TestAsyncNamespaceAdminApi method setUpBeforeClass.

@BeforeClass
public static void setUpBeforeClass() throws Exception {
    TEST_UTIL.getConfiguration().setInt(START_LOG_ERRORS_AFTER_COUNT_KEY, 0);
    TEST_UTIL.startMiniCluster(1);
    ASYNC_CONN = ConnectionFactory.createAsyncConnection(TEST_UTIL.getConfiguration()).get();
    master = ((MiniHBaseCluster) TEST_UTIL.getHBaseCluster()).getMaster();
    zkNamespaceManager = new ZKNamespaceManager(master.getZooKeeper());
    zkNamespaceManager.start();
    LOG.info("Done initializing cluster");
}
Also used : ZKNamespaceManager(org.apache.hadoop.hbase.ZKNamespaceManager) BeforeClass(org.junit.BeforeClass)

Example 2 with ZKNamespaceManager

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

the class TableNamespaceManager method isTableAvailableAndInitialized.

/**
   * This method checks if the namespace table is assigned and then
   * tries to create its Table reference. If it was already created before, it also makes
   * sure that the connection isn't closed.
   * @return true if the namespace table manager is ready to serve, false otherwise
   */
@SuppressWarnings("deprecation")
public synchronized boolean isTableAvailableAndInitialized() throws IOException {
    // Did we already get a table? If so, still make sure it's available
    if (isTableNamespaceManagerInitialized()) {
        return true;
    }
    // Now check if the table is assigned, if not then fail fast
    if (isTableAssigned() && isTableEnabled()) {
        try {
            boolean initGoodSofar = true;
            nsTable = this.masterServices.getConnection().getTable(TableName.NAMESPACE_TABLE_NAME);
            zkNamespaceManager = new ZKNamespaceManager(masterServices.getZooKeeper());
            zkNamespaceManager.start();
            if (get(nsTable, NamespaceDescriptor.DEFAULT_NAMESPACE.getName()) == null) {
                blockingCreateNamespace(NamespaceDescriptor.DEFAULT_NAMESPACE);
            }
            if (get(nsTable, NamespaceDescriptor.SYSTEM_NAMESPACE.getName()) == null) {
                blockingCreateNamespace(NamespaceDescriptor.SYSTEM_NAMESPACE);
            }
            if (!initGoodSofar) {
                // some required namespace is created asynchronized. We should complete init later.
                return false;
            }
            ResultScanner scanner = nsTable.getScanner(HTableDescriptor.NAMESPACE_FAMILY_INFO_BYTES);
            try {
                for (Result result : scanner) {
                    byte[] val = CellUtil.cloneValue(result.getColumnLatestCell(HTableDescriptor.NAMESPACE_FAMILY_INFO_BYTES, HTableDescriptor.NAMESPACE_COL_DESC_BYTES));
                    NamespaceDescriptor ns = ProtobufUtil.toNamespaceDescriptor(HBaseProtos.NamespaceDescriptor.parseFrom(val));
                    zkNamespaceManager.update(ns);
                }
            } finally {
                scanner.close();
            }
            initialized = true;
            return true;
        } catch (IOException ie) {
            LOG.warn("Caught exception in initializing namespace table manager", ie);
            if (nsTable != null) {
                nsTable.close();
            }
            throw ie;
        }
    }
    return false;
}
Also used : ZKNamespaceManager(org.apache.hadoop.hbase.ZKNamespaceManager) ResultScanner(org.apache.hadoop.hbase.client.ResultScanner) NamespaceDescriptor(org.apache.hadoop.hbase.NamespaceDescriptor) InterruptedIOException(java.io.InterruptedIOException) TimeoutIOException(org.apache.hadoop.hbase.exceptions.TimeoutIOException) DoNotRetryIOException(org.apache.hadoop.hbase.DoNotRetryIOException) IOException(java.io.IOException) Result(org.apache.hadoop.hbase.client.Result)

Aggregations

ZKNamespaceManager (org.apache.hadoop.hbase.ZKNamespaceManager)2 IOException (java.io.IOException)1 InterruptedIOException (java.io.InterruptedIOException)1 DoNotRetryIOException (org.apache.hadoop.hbase.DoNotRetryIOException)1 NamespaceDescriptor (org.apache.hadoop.hbase.NamespaceDescriptor)1 Result (org.apache.hadoop.hbase.client.Result)1 ResultScanner (org.apache.hadoop.hbase.client.ResultScanner)1 TimeoutIOException (org.apache.hadoop.hbase.exceptions.TimeoutIOException)1 BeforeClass (org.junit.BeforeClass)1