Java 类org.apache.hadoop.hbase.ZKNamespaceManager 实例源码

项目:hbase    文件:TestAsyncNamespaceAdminApi.java   
@BeforeClass
public static void setUpBeforeClass() throws Exception {
  TEST_UTIL.getConfiguration().setInt(HConstants.HBASE_RPC_TIMEOUT_KEY, 60000);
  TEST_UTIL.getConfiguration().setInt(HConstants.HBASE_CLIENT_OPERATION_TIMEOUT, 120000);
  TEST_UTIL.getConfiguration().setInt(HConstants.HBASE_CLIENT_RETRIES_NUMBER, 2);
  TEST_UTIL.getConfiguration().setInt(START_LOG_ERRORS_AFTER_COUNT_KEY, 0);
  TEST_UTIL.startMiniCluster(1);
  ASYNC_CONN = ConnectionFactory.createAsyncConnection(TEST_UTIL.getConfiguration()).get();
  master = TEST_UTIL.getHBaseCluster().getMaster();
  zkNamespaceManager = new ZKNamespaceManager(master.getZooKeeper());
  zkNamespaceManager.start();
  LOG.info("Done initializing cluster");
}
项目:ditb    文件:TableNamespaceManager.java   
/**
 * This method checks if the namespace table is assigned and then
 * tries to create its HTable. 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
 * @throws IOException
 */
@SuppressWarnings("deprecation")
public synchronized boolean isTableAvailableAndInitialized() throws IOException {
  // Did we already get a table? If so, still make sure it's available
  if (initialized) {
    this.nsTable = this.masterServices.getConnection().getTable(TableName.NAMESPACE_TABLE_NAME);
    return true;
  }

  // Now check if the table is assigned, if not then fail fast
  if (isTableAssigned()) {
    try {
      nsTable = this.masterServices.getConnection().getTable(TableName.NAMESPACE_TABLE_NAME);
      zkNamespaceManager = new ZKNamespaceManager(masterServices.getZooKeeper());
      zkNamespaceManager.start();

      if (get(nsTable, NamespaceDescriptor.DEFAULT_NAMESPACE.getName()) == null) {
        create(nsTable, NamespaceDescriptor.DEFAULT_NAMESPACE);
      }
      if (get(nsTable, NamespaceDescriptor.SYSTEM_NAMESPACE.getName()) == null) {
        create(nsTable, NamespaceDescriptor.SYSTEM_NAMESPACE);
      }

      ResultScanner scanner = nsTable.getScanner(HTableDescriptor.NAMESPACE_FAMILY_INFO_BYTES);
      try {
        for (Result result : scanner) {
          byte[] val =  CellUtil.cloneValue(result.getColumnLatest(
              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;
}
项目:pbase    文件:TableNamespaceManager.java   
/**
 * This method checks if the namespace table is assigned and then
 * tries to create its HTable. 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
 * @throws IOException
 */
@SuppressWarnings("deprecation")
public synchronized boolean isTableAvailableAndInitialized() throws IOException {
  // Did we already get a table? If so, still make sure it's available
  if (initialized) {
    this.nsTable = this.masterServices.getConnection().getTable(TableName.NAMESPACE_TABLE_NAME);
    return true;
  }

  // Now check if the table is assigned, if not then fail fast
  if (isTableAssigned()) {
    try {
      nsTable = this.masterServices.getConnection().getTable(TableName.NAMESPACE_TABLE_NAME);
      zkNamespaceManager = new ZKNamespaceManager(masterServices.getZooKeeper());
      zkNamespaceManager.start();

      if (get(nsTable, NamespaceDescriptor.DEFAULT_NAMESPACE.getName()) == null) {
        create(nsTable, NamespaceDescriptor.DEFAULT_NAMESPACE);
      }
      if (get(nsTable, NamespaceDescriptor.SYSTEM_NAMESPACE.getName()) == null) {
        create(nsTable, NamespaceDescriptor.SYSTEM_NAMESPACE);
      }

      ResultScanner scanner = nsTable.getScanner(HTableDescriptor.NAMESPACE_FAMILY_INFO_BYTES);
      try {
        for (Result result : scanner) {
          byte[] val =  CellUtil.cloneValue(result.getColumnLatest(
              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;
}
项目:HIndex    文件:TableNamespaceManager.java   
/**
 * This method checks if the namespace table is assigned and then
 * tries to create its HTable. 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
 * @throws IOException
 */
@SuppressWarnings("deprecation")
public synchronized boolean isTableAvailableAndInitialized() throws IOException {
  // Did we already get a table? If so, still make sure it's available
  if (initialized) {
    if (nsTable.getConnection().isClosed()) {
      nsTable = new HTable(conf, TableName.NAMESPACE_TABLE_NAME);
    }
    return true;
  }

  // Now check if the table is assigned, if not then fail fast
  if (isTableAssigned()) {
    try {
      nsTable = new HTable(conf, TableName.NAMESPACE_TABLE_NAME);
      zkNamespaceManager = new ZKNamespaceManager(masterServices.getZooKeeper());
      zkNamespaceManager.start();

      if (get(nsTable, NamespaceDescriptor.DEFAULT_NAMESPACE.getName()) == null) {
        create(nsTable, NamespaceDescriptor.DEFAULT_NAMESPACE);
      }
      if (get(nsTable, NamespaceDescriptor.SYSTEM_NAMESPACE.getName()) == null) {
        create(nsTable, NamespaceDescriptor.SYSTEM_NAMESPACE);
      }

      ResultScanner scanner = nsTable.getScanner(HTableDescriptor.NAMESPACE_FAMILY_INFO_BYTES);
      try {
        for (Result result : scanner) {
          byte[] val =  CellUtil.cloneValue(result.getColumnLatest(
              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;
}
项目:hbase    文件:TableNamespaceManager.java   
/**
 * 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;
}
项目:PyroDB    文件:TableNamespaceManager.java   
/**
 * This method checks if the namespace table is assigned and then
 * tries to create its HTable. 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
 * @throws IOException
 */
@SuppressWarnings("deprecation")
public synchronized boolean isTableAvailableAndInitialized() throws IOException {
  // Did we already get a table? If so, still make sure it's available
  if (initialized) {
    if (nsTable.getConnection().isClosed()) {
      nsTable = new HTable(conf, TableName.NAMESPACE_TABLE_NAME);
    }
    return true;
  }

  // Now check if the table is assigned, if not then fail fast
  if (isTableAssigned()) {
    try {
      nsTable = new HTable(conf, TableName.NAMESPACE_TABLE_NAME);
      zkNamespaceManager = new ZKNamespaceManager(masterServices.getZooKeeper());
      zkNamespaceManager.start();

      if (get(nsTable, NamespaceDescriptor.DEFAULT_NAMESPACE.getName()) == null) {
        create(nsTable, NamespaceDescriptor.DEFAULT_NAMESPACE);
      }
      if (get(nsTable, NamespaceDescriptor.SYSTEM_NAMESPACE.getName()) == null) {
        create(nsTable, NamespaceDescriptor.SYSTEM_NAMESPACE);
      }

      ResultScanner scanner = nsTable.getScanner(HTableDescriptor.NAMESPACE_FAMILY_INFO_BYTES);
      try {
        for (Result result : scanner) {
          byte[] val =  CellUtil.cloneValue(result.getColumnLatest(
              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;
}
项目:c5    文件:TableNamespaceManager.java   
/**
 * This method checks if the namespace table is assigned and then
 * tries to create its HTable. 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
 * @throws IOException
 */
@SuppressWarnings("deprecation")
public synchronized boolean isTableAvailableAndInitialized() throws IOException {
  // Did we already get a table? If so, still make sure it's available
  if (initialized) {
    if (nsTable.getConnection().isClosed()) {
      nsTable = new HTable(conf, TableName.NAMESPACE_TABLE_NAME);
    }
    return true;
  }

  // Now check if the table is assigned, if not then fail fast
  if (isTableAssigned()) {
    try {
      nsTable = new HTable(conf, TableName.NAMESPACE_TABLE_NAME);
      zkNamespaceManager = new ZKNamespaceManager(masterServices.getZooKeeper());
      zkNamespaceManager.start();

      if (get(nsTable, NamespaceDescriptor.DEFAULT_NAMESPACE.getName()) == null) {
        create(nsTable, NamespaceDescriptor.DEFAULT_NAMESPACE);
      }
      if (get(nsTable, NamespaceDescriptor.SYSTEM_NAMESPACE.getName()) == null) {
        create(nsTable, NamespaceDescriptor.SYSTEM_NAMESPACE);
      }

      ResultScanner scanner = nsTable.getScanner(HTableDescriptor.NAMESPACE_FAMILY_INFO_BYTES);
      try {
        for (Result result : scanner) {
          byte[] val =  CellUtil.cloneValue(result.getColumnLatest(
              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;
}