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

项目:ditb    文件:Canary.java   
private static List<Future<Void>> sniff(final Admin admin, final Sink sink,
    HTableDescriptor tableDesc, ExecutorService executor, TaskType taskType) throws Exception {
  Table table = null;
  try {
    table = admin.getConnection().getTable(tableDesc.getTableName());
  } catch (TableNotFoundException e) {
    return new ArrayList<Future<Void>>();
  }
  List<RegionTask> tasks = new ArrayList<RegionTask>();
  try {
    for (HRegionInfo region : admin.getTableRegions(tableDesc.getTableName())) {
      tasks.add(new RegionTask(admin.getConnection(), region, sink, taskType));
    }
  } finally {
    table.close();
  }
  return executor.invokeAll(tasks);
}
项目:ditb    文件:AssignmentManager.java   
/**
 * Recover the tables that are not fully moved to ENABLED state. These tables
 * are in ENABLING state when the master restarted/switched
 *
 * @throws KeeperException
 * @throws org.apache.hadoop.hbase.TableNotFoundException
 * @throws IOException
 */
private void recoverTableInEnablingState()
    throws KeeperException, IOException, CoordinatedStateException {
  Set<TableName> enablingTables = tableStateManager.
    getTablesInStates(ZooKeeperProtos.Table.State.ENABLING);
  if (enablingTables.size() != 0) {
    for (TableName tableName : enablingTables) {
      // Recover by calling EnableTableHandler
      LOG.info("The table " + tableName
          + " is in ENABLING state.  Hence recovering by moving the table"
          + " to ENABLED state.");
      // enableTable in sync way during master startup,
      // no need to invoke coprocessor
      EnableTableHandler eth = new EnableTableHandler(this.server, tableName,
        this, tableLockManager, true);
      try {
        eth.prepare();
      } catch (TableNotFoundException e) {
        LOG.warn("Table " + tableName + " not found in hbase:meta to recover.");
        continue;
      }
      eth.process();
    }
  }
}
项目:ditb    文件:TestReplicasClient.java   
@Test
public void testFlushSecondary() throws Exception {
  openRegion(hriSecondary);
  try {
    flushRegion(hriSecondary);

    Put p = new Put(row);
    p.add(f, row, row);
    table.put(p);

    flushRegion(hriSecondary);
  } catch (TableNotFoundException expected) {
  } finally {
    Delete d = new Delete(row);
    table.delete(d);
    closeRegion(hriSecondary);
  }
}
项目:ditb    文件:CCIndexAdmin.java   
/**
 * Enable a table, if existed.
 *
 * @param tableName name of table to enable
 * @throws IOException-if a remote or network exception occurs
 */
public void enableTable(TableName tableName) throws IOException {
  HTableDescriptor desc = admin.getTableDescriptor(tableName);
  if (isIndexTable(desc)) {
    throw new TableNotFoundException(tableName);
  }
  IndexTableDescriptor indexDesc = new IndexTableDescriptor(desc);
  if (indexDesc.hasIndex()) {
    for (IndexSpecification indexSpec : indexDesc.getIndexSpecifications()) {
      if (admin.tableExists(indexSpec.getIndexTableName())) {
        admin.enableTable(indexSpec.getIndexTableName());
      } else {
        throw new IndexMissingException(tableName, indexSpec);
      }
    }
  }
  admin.enableTable(tableName);
}
项目:ditb    文件:CCIndexAdmin.java   
/**
 * Disable a table, if existed.
 *
 * @param tableName name of table to disable
 * @throws IOException-if a remote or network exception occurs
 */
public void disableTable(TableName tableName) throws IOException {
  HTableDescriptor desc = admin.getTableDescriptor(tableName);
  if (isIndexTable(desc)) {
    throw new TableNotFoundException(tableName);
  }
  IndexTableDescriptor indexDesc = new IndexTableDescriptor(desc);

  if (indexDesc.hasIndex()) {
    for (IndexSpecification indexSpec : indexDesc.getIndexSpecifications()) {
      if (admin.tableExists(indexSpec.getIndexTableName())) {
        admin.disableTable(indexSpec.getIndexTableName());
      } else {
        throw new IndexMissingException(tableName, indexSpec);
      }
    }
  }
  admin.disableTable(tableName);
}
项目:ditb    文件:CCIndexAdmin.java   
/**
 * @param tableName name of table to check
 * @return true if table is enabled
 * @throws IOException-if a remote or network exception occurs
 */
public boolean isTableEnabled(TableName tableName) throws IOException {
  HTableDescriptor desc = admin.getTableDescriptor(tableName);
  if (isIndexTable(desc)) {
    throw new TableNotFoundException(tableName);
  }
  IndexTableDescriptor indexDesc = new IndexTableDescriptor(desc);

  boolean isenable = admin.isTableEnabled(tableName);

  if (indexDesc.hasIndex()) {
    for (IndexSpecification indexSpec : indexDesc.getIndexSpecifications()) {
      if (admin.tableExists(indexSpec.getIndexTableName())) {
        if (isenable && admin.isTableDisabled(indexSpec.getIndexTableName())) {
          admin.enableTable(indexSpec.getIndexTableName());
        } else if (!isenable && admin.isTableEnabled(indexSpec.getIndexTableName())) {
          admin.disableTable(indexSpec.getIndexTableName());
        }
      } else {
        throw new IndexMissingException(tableName, indexSpec);
      }
    }
  }

  return isenable;
}
项目:ditb    文件:CCIndexAdmin.java   
/**
 * @param tableName name of table to check
 * @return true if table and indexes are all available
 * @throws IOException-if a remote or network exception occurs
 */
public boolean isTableAvailable(TableName tableName) throws IOException {
  HTableDescriptor desc = admin.getTableDescriptor(tableName);
  if (isIndexTable(desc)) {
    throw new TableNotFoundException(tableName);
  }
  IndexTableDescriptor indexDesc = new IndexTableDescriptor(desc);

  if (indexDesc.hasIndex()) {
    for (IndexSpecification indexSpec : indexDesc.getIndexSpecifications()) {
      if (admin.tableExists(indexSpec.getIndexTableName())) {
        if (!admin.isTableAvailable(indexSpec.getIndexTableName())) {
          return false;
        }
      } else {
        throw new IndexMissingException(tableName, indexSpec);
      }
    }
  }

  if (!admin.isTableAvailable(tableName)) {
    return false;
  }
  return true;
}
项目:ditb    文件:HBaseAdmin.java   
static HTableDescriptor getTableDescriptor(final TableName tableName, HConnection connection,
    RpcRetryingCallerFactory rpcCallerFactory, final RpcControllerFactory rpcControllerFactory,
       int operationTimeout) throws TableNotFoundException, IOException {

    if (tableName == null) return null;
    HTableDescriptor htd = executeCallable(new MasterCallable<HTableDescriptor>(connection) {
      @Override
      public HTableDescriptor call(int callTimeout) throws ServiceException {
        PayloadCarryingRpcController controller = rpcControllerFactory.newController();
        controller.setCallTimeout(callTimeout);
        GetTableDescriptorsResponse htds;
        GetTableDescriptorsRequest req =
                RequestConverter.buildGetTableDescriptorsRequest(tableName);
        htds = master.getTableDescriptors(controller, req);

        if (!htds.getTableSchemaList().isEmpty()) {
          return HTableDescriptor.convert(htds.getTableSchemaList().get(0));
        }
        return null;
      }
    }, rpcCallerFactory, operationTimeout);
    if (htd != null) {
      return htd;
    }
    throw new TableNotFoundException(tableName.getNameAsString());
}
项目:ditb    文件:HBaseAdmin.java   
private void waitTableEnabled(final long deadlineTs)
    throws IOException, TimeoutException {
  waitForState(deadlineTs, new WaitForStateCallable() {
    @Override
    public boolean checkState(int tries) throws IOException {
      boolean enabled;
      try {
        enabled = getAdmin().isTableEnabled(tableName);
      } catch (TableNotFoundException tnfe) {
        return false;
      }
      return enabled && getAdmin().isTableAvailable(tableName);
    }

    @Override
    public void throwInterruptedException() throws InterruptedIOException {
      throw new InterruptedIOException("Interrupted when waiting for table to be enabled");
    }

    @Override
    public void throwTimeoutException(long elapsedTime) throws TimeoutException {
      throw new TimeoutException("Table " + tableName + " not yet enabled after " +
          elapsedTime + "msec");
    }
  });
}
项目:ditb    文件:ConnectionManager.java   
/**
 * Connects to the master to get the table descriptor.
 * @param tableName table name
 * @throws IOException if the connection to master fails or if the table
 *  is not found.
 * @deprecated Use {@link Admin#getTableDescriptor(TableName)} instead
 */
@Deprecated
@Override
public HTableDescriptor getHTableDescriptor(final TableName tableName)
throws IOException {
  if (tableName == null) return null;
  MasterKeepAliveConnection master = getKeepAliveMasterService();
  GetTableDescriptorsResponse htds;
  try {
    GetTableDescriptorsRequest req =
      RequestConverter.buildGetTableDescriptorsRequest(tableName);
    htds = master.getTableDescriptors(null, req);
  } catch (ServiceException se) {
    throw ProtobufUtil.getRemoteException(se);
  } finally {
    master.close();
  }
  if (!htds.getTableSchemaList().isEmpty()) {
    return HTableDescriptor.convert(htds.getTableSchemaList().get(0));
  }
  throw new TableNotFoundException(tableName.getNameAsString());
}
项目:flink    文件:HBaseRowInputFormat.java   
private void connectToTable() {

        if (this.conf == null) {
            this.conf = HBaseConfiguration.create();
        }

        try {
            Connection conn = ConnectionFactory.createConnection(conf);
            super.table = (HTable) conn.getTable(TableName.valueOf(tableName));
        } catch (TableNotFoundException tnfe) {
            LOG.error("The table " + tableName + " not found ", tnfe);
            throw new RuntimeException("HBase table '" + tableName + "' not found.", tnfe);
        } catch (IOException ioe) {
            LOG.error("Exception while creating connection to HBase.", ioe);
            throw new RuntimeException("Cannot create connection to HBase.", ioe);
        }
    }
项目:LCIndex-HBase-0.94.16    文件:HConnectionManager.java   
public HTableDescriptor getHTableDescriptor(final byte[] tableName)
throws IOException {
  if (tableName == null || tableName.length == 0) return null;
  if (Bytes.equals(tableName, HConstants.ROOT_TABLE_NAME)) {
    return new UnmodifyableHTableDescriptor(HTableDescriptor.ROOT_TABLEDESC);
  }
  if (Bytes.equals(tableName, HConstants.META_TABLE_NAME)) {
    return HTableDescriptor.META_TABLEDESC;
  }
  List<String> tableNameList = new ArrayList<String>(1);
  tableNameList.add(Bytes.toString(tableName));
  HTableDescriptor[] htds = getHTableDescriptors(tableNameList);
  if (htds != null && htds.length > 0) {
    return htds[0];
  }
  throw new TableNotFoundException(Bytes.toString(tableName));
}
项目:LCIndex-HBase-0.94.16    文件:AssignmentManager.java   
/**
 * Recover the tables that were not fully moved to DISABLED state. These
 * tables are in DISABLING state when the master restarted/switched.
 * 
 * @param disablingTables
 * @return
 * @throws KeeperException
 * @throws TableNotFoundException
 * @throws IOException
 */
private boolean recoverTableInDisablingState(Set<String> disablingTables)
    throws KeeperException, TableNotFoundException, IOException {
  boolean isWatcherCreated = false;
  if (disablingTables.size() != 0) {
    // Create a watcher on the zookeeper node
    ZKUtil.listChildrenAndWatchForNewChildren(watcher,
        watcher.assignmentZNode);
    isWatcherCreated = true;
    for (String tableName : disablingTables) {
      // Recover by calling DisableTableHandler
      LOG.info("The table " + tableName
          + " is in DISABLING state.  Hence recovering by moving the table"
          + " to DISABLED state.");
      new DisableTableHandler(this.master, tableName.getBytes(),
          catalogTracker, this, true).process();
    }
  }
  return isWatcherCreated;
}
项目:LCIndex-HBase-0.94.16    文件:CCIndexAdmin.java   
/**
 * Enable a table, if existed.
 * @param tableName name of table to enable
 * @throws IOException-if a remote or network exception occurs
 */
public void enableTable(byte[] tableName) throws IOException {
  HTableDescriptor desc = admin.getTableDescriptor(tableName);
  if (isIndexTable(desc)) {
    throw new TableNotFoundException(Bytes.toString(tableName));
  }
  IndexTableDescriptor indexDesc = new IndexTableDescriptor(desc);

  if (indexDesc.hasIndex()) {
    for (IndexSpecification indexSpec : indexDesc.getIndexSpecifications()) {
      if (admin.tableExists(indexSpec.getIndexTableName())) {
        admin.enableTable(indexSpec.getIndexTableName());
      } else {
        throw new IndexMissingException(tableName, indexSpec);
      }
    }
  }
  admin.enableTable(tableName);
}
项目:LCIndex-HBase-0.94.16    文件:CCIndexAdmin.java   
/**
 * Disable a table, if existed.
 * @param tableName name of table to disable
 * @throws IOException-if a remote or network exception occurs
 */
public void disableTable(byte[] tableName) throws IOException {
  HTableDescriptor desc = admin.getTableDescriptor(tableName);
  if (isIndexTable(desc)) {
    throw new TableNotFoundException(Bytes.toString(tableName));
  }
  IndexTableDescriptor indexDesc = new IndexTableDescriptor(desc);

  if (indexDesc.hasIndex()) {
    for (IndexSpecification indexSpec : indexDesc.getIndexSpecifications()) {
      if (admin.tableExists(indexSpec.getIndexTableName())) {
        admin.disableTable(indexSpec.getIndexTableName());
      } else {
        throw new IndexMissingException(tableName, indexSpec);
      }
    }
  }
  admin.disableTable(tableName);
}
项目:LCIndex-HBase-0.94.16    文件:CCIndexAdmin.java   
/**
 * @param tableName name of table to check
 * @return true if table is enabled
 * @throws IOException-if a remote or network exception occurs
 */
public boolean isTableEnabled(byte[] tableName) throws IOException {
  HTableDescriptor desc = admin.getTableDescriptor(tableName);
  if (isIndexTable(desc)) {
    throw new TableNotFoundException(Bytes.toString(tableName));
  }
  IndexTableDescriptor indexDesc = new IndexTableDescriptor(desc);

  boolean isenable = admin.isTableEnabled(tableName);

  if (indexDesc.hasIndex()) {
    for (IndexSpecification indexSpec : indexDesc.getIndexSpecifications()) {
      if (admin.tableExists(indexSpec.getIndexTableName())) {
        if (isenable && admin.isTableDisabled(indexSpec.getIndexTableName())) {
          admin.enableTable(indexSpec.getIndexTableName());
        } else if (!isenable && admin.isTableEnabled(indexSpec.getIndexTableName())) {
          admin.disableTable(indexSpec.getIndexTableName());
        }
      } else {
        throw new IndexMissingException(tableName, indexSpec);
      }
    }
  }

  return isenable;
}
项目:LCIndex-HBase-0.94.16    文件:CCIndexAdmin.java   
/**
 * @param tableName name of table to check
 * @return true if table and indexes are all available
 * @throws IOException-if a remote or network exception occurs
 */
public boolean isTableAvailable(byte[] tableName) throws IOException {
  HTableDescriptor desc = admin.getTableDescriptor(tableName);
  if (isIndexTable(desc)) {
    throw new TableNotFoundException(Bytes.toString(tableName));
  }
  IndexTableDescriptor indexDesc = new IndexTableDescriptor(desc);

  if (indexDesc.hasIndex()) {
    for (IndexSpecification indexSpec : indexDesc.getIndexSpecifications()) {
      if (admin.tableExists(indexSpec.getIndexTableName())) {
        if (!admin.isTableAvailable(indexSpec.getIndexTableName())) {
          return false;
        }
      } else {
        throw new IndexMissingException(tableName, indexSpec);
      }
    }
  }

  if (!admin.isTableAvailable(tableName)) {
    return false;
  }
  return true;
}
项目:cloud-bigtable-client    文件:BigtableAdmin.java   
@Override
public HTableDescriptor getTableDescriptor(TableName tableName)
    throws TableNotFoundException, IOException {
  if (tableName == null) {
    return null;
  }

  String bigtableTableName = TableMetadataSetter.getBigtableName(tableName, options);
  GetTableRequest request = GetTableRequest.newBuilder().setName(bigtableTableName).build();

  try {
    return tableAdapter.adapt(bigtableAdminClient.getTable(request));
  } catch (UncheckedExecutionException e) {
    if (e.getCause() != null && e.getCause() instanceof OperationRuntimeException) {
      Status status = ((OperationRuntimeException) e.getCause()).getStatus();
      if (status.getCode() == Status.NOT_FOUND.getCode()) {
        throw new TableNotFoundException(tableName);
      }
    }
    throw new IOException("Failed to getTableDescriptor() on " + tableName, e);
  } catch (Throwable throwable) {
    throw new IOException("Failed to getTableDescriptor() on " + tableName, throwable);
  }
}
项目:pbase    文件:AssignmentManager.java   
/**
 * Recover the tables that are not fully moved to ENABLED state. These tables
 * are in ENABLING state when the master restarted/switched
 *
 * @throws KeeperException
 * @throws org.apache.hadoop.hbase.TableNotFoundException
 * @throws IOException
 */
private void recoverTableInEnablingState()
    throws KeeperException, IOException, CoordinatedStateException {
  Set<TableName> enablingTables = tableStateManager.
    getTablesInStates(ZooKeeperProtos.Table.State.ENABLING);
  if (enablingTables.size() != 0) {
    for (TableName tableName : enablingTables) {
      // Recover by calling EnableTableHandler
      LOG.info("The table " + tableName
          + " is in ENABLING state.  Hence recovering by moving the table"
          + " to ENABLED state.");
      // enableTable in sync way during master startup,
      // no need to invoke coprocessor
      EnableTableHandler eth = new EnableTableHandler(this.server, tableName,
        this, tableLockManager, true);
      try {
        eth.prepare();
      } catch (TableNotFoundException e) {
        LOG.warn("Table " + tableName + " not found in hbase:meta to recover.");
        continue;
      }
      eth.process();
    }
  }
}
项目:pbase    文件:TestReplicasClient.java   
@Test
public void testFlushSecondary() throws Exception {
  openRegion(hriSecondary);
  try {
    flushRegion(hriSecondary);

    Put p = new Put(row);
    p.add(f, row, row);
    table.put(p);

    flushRegion(hriSecondary);
  } catch (TableNotFoundException expected) {
  } finally {
    Delete d = new Delete(row);
    table.delete(d);
    closeRegion(hriSecondary);
  }
}
项目:pbase    文件:ConnectionManager.java   
/**
 * Connects to the master to get the table descriptor.
 *
 * @param tableName table name
 * @throws IOException if the connection to master fails or if the table
 *                     is not found.
 * @deprecated Use {@link Admin#getTableDescriptor(TableName)} instead
 */
@Deprecated
@Override
public HTableDescriptor getHTableDescriptor(final TableName tableName)
        throws IOException {
    if (tableName == null) return null;
    MasterKeepAliveConnection master = getKeepAliveMasterService();
    GetTableDescriptorsResponse htds;
    try {
        GetTableDescriptorsRequest req =
                RequestConverter.buildGetTableDescriptorsRequest(tableName);
        htds = master.getTableDescriptors(null, req);
    } catch (ServiceException se) {
        throw ProtobufUtil.getRemoteException(se);
    } finally {
        master.close();
    }
    if (!htds.getTableSchemaList().isEmpty()) {
        return HTableDescriptor.convert(htds.getTableSchemaList().get(0));
    }
    throw new TableNotFoundException(tableName.getNameAsString());
}
项目:HIndex    文件:AssignmentManager.java   
/**
 * Recover the tables that are not fully moved to ENABLED state. These tables
 * are in ENABLING state when the master restarted/switched
 *
 * @throws KeeperException
 * @throws org.apache.hadoop.hbase.TableNotFoundException
 * @throws IOException
 */
private void recoverTableInEnablingState()
    throws KeeperException, TableNotFoundException, IOException {
  Set<TableName> enablingTables = ZKTable.getEnablingTables(watcher);
  if (enablingTables.size() != 0) {
    for (TableName tableName : enablingTables) {
      // Recover by calling EnableTableHandler
      LOG.info("The table " + tableName
          + " is in ENABLING state.  Hence recovering by moving the table"
          + " to ENABLED state.");
      // enableTable in sync way during master startup,
      // no need to invoke coprocessor
      EnableTableHandler eth = new EnableTableHandler(this.server, tableName,
        catalogTracker, this, tableLockManager, true);
      try {
        eth.prepare();
      } catch (TableNotFoundException e) {
        LOG.warn("Table " + tableName + " not found in hbase:meta to recover.");
        continue;
      }
      eth.process();
    }
  }
}
项目:HIndex    文件:HConnectionManager.java   
/**
 * Connects to the master to get the table descriptor.
 * @param tableName table name
 * @return
 * @throws IOException if the connection to master fails or if the table
 *  is not found.
 */
@Override
public HTableDescriptor getHTableDescriptor(final TableName tableName)
throws IOException {
  if (tableName == null) return null;
  if (tableName.equals(TableName.META_TABLE_NAME)) {
    return HTableDescriptor.META_TABLEDESC;
  }
  MasterKeepAliveConnection master = getKeepAliveMasterService();
  GetTableDescriptorsResponse htds;
  try {
    GetTableDescriptorsRequest req =
      RequestConverter.buildGetTableDescriptorsRequest(tableName);
    htds = master.getTableDescriptors(null, req);
  } catch (ServiceException se) {
    throw ProtobufUtil.getRemoteException(se);
  } finally {
    master.close();
  }
  if (!htds.getTableSchemaList().isEmpty()) {
    return HTableDescriptor.convert(htds.getTableSchemaList().get(0));
  }
  throw new TableNotFoundException(tableName.getNameAsString());
}
项目:IRIndex    文件:HConnectionManager.java   
public HTableDescriptor getHTableDescriptor(final byte[] tableName)
throws IOException {
  if (tableName == null || tableName.length == 0) return null;
  if (Bytes.equals(tableName, HConstants.ROOT_TABLE_NAME)) {
    return new UnmodifyableHTableDescriptor(HTableDescriptor.ROOT_TABLEDESC);
  }
  if (Bytes.equals(tableName, HConstants.META_TABLE_NAME)) {
    return HTableDescriptor.META_TABLEDESC;
  }
  List<String> tableNameList = new ArrayList<String>(1);
  tableNameList.add(Bytes.toString(tableName));
  HTableDescriptor[] htds = getHTableDescriptors(tableNameList);
  if (htds != null && htds.length > 0) {
    return htds[0];
  }
  throw new TableNotFoundException(Bytes.toString(tableName));
}
项目:IRIndex    文件:AssignmentManager.java   
/**
 * Recover the tables that were not fully moved to DISABLED state. These
 * tables are in DISABLING state when the master restarted/switched.
 * 
 * @param disablingTables
 * @return
 * @throws KeeperException
 * @throws TableNotFoundException
 * @throws IOException
 */
private boolean recoverTableInDisablingState(Set<String> disablingTables)
    throws KeeperException, TableNotFoundException, IOException {
  boolean isWatcherCreated = false;
  if (disablingTables.size() != 0) {
    // Create a watcher on the zookeeper node
    ZKUtil.listChildrenAndWatchForNewChildren(watcher,
        watcher.assignmentZNode);
    isWatcherCreated = true;
    for (String tableName : disablingTables) {
      // Recover by calling DisableTableHandler
      LOG.info("The table " + tableName
          + " is in DISABLING state.  Hence recovering by moving the table"
          + " to DISABLED state.");
      new DisableTableHandler(this.master, tableName.getBytes(),
          catalogTracker, this, true).process();
    }
  }
  return isWatcherCreated;
}
项目:hbase    文件:ReplicationSink.java   
/**
 * Do the changes and handle the pool
 * @param tableName table to insert into
 * @param allRows list of actions
 * @throws IOException
 */
protected void batch(TableName tableName, Collection<List<Row>> allRows) throws IOException {
  if (allRows.isEmpty()) {
    return;
  }
  Table table = null;
  try {
    Connection connection = getConnection();
    table = connection.getTable(tableName);
    for (List<Row> rows : allRows) {
      table.batch(rows, null);
    }
  } catch (RetriesExhaustedWithDetailsException rewde) {
    for (Throwable ex : rewde.getCauses()) {
      if (ex instanceof TableNotFoundException) {
        throw new TableNotFoundException("'"+tableName+"'");
      }
    }
  } catch (InterruptedException ix) {
    throw (InterruptedIOException) new InterruptedIOException().initCause(ix);
  } finally {
    if (table != null) {
      table.close();
    }
  }
}
项目:hbase    文件:LoadIncrementalHFiles.java   
/**
 * Perform a bulk load of the given directory into the given pre-existing table. This method is
 * not threadsafe.
 * @param map map of family to List of hfiles
 * @param admin the Admin
 * @param table the table to load into
 * @param regionLocator region locator
 * @param silence true to ignore unmatched column families
 * @param copyFile always copy hfiles if true
 * @throws TableNotFoundException if table does not yet exist
 */
public Map<LoadQueueItem, ByteBuffer> doBulkLoad(Map<byte[], List<Path>> map, final Admin admin,
    Table table, RegionLocator regionLocator, boolean silence, boolean copyFile)
    throws TableNotFoundException, IOException {
  if (!admin.isTableAvailable(regionLocator.getName())) {
    throw new TableNotFoundException("Table " + table.getName() + " is not currently available.");
  }
  // LQI queue does not need to be threadsafe -- all operations on this queue
  // happen in this thread
  Deque<LoadQueueItem> queue = new ArrayDeque<>();
  ExecutorService pool = null;
  SecureBulkLoadClient secureClient = null;
  try {
    prepareHFileQueue(map, table, queue, silence);
    if (queue.isEmpty()) {
      LOG.warn("Bulk load operation did not get any files to load");
      return Collections.emptyMap();
    }
    pool = createExecutorService();
    secureClient = new SecureBulkLoadClient(table.getConfiguration(), table);
    return performBulkLoad(admin, table, regionLocator, queue, pool, secureClient, copyFile);
  } finally {
    cleanup(admin, queue, pool, secureClient);
  }
}
项目:hbase    文件:LoadIncrementalHFiles.java   
/**
 * Perform bulk load on the given table.
 * @param hfofDir the directory that was provided as the output path of a job using
 *          HFileOutputFormat
 * @param tableName the table to load into
 */
public Map<LoadQueueItem, ByteBuffer> run(String hfofDir, TableName tableName)
    throws IOException {
  try (Connection connection = ConnectionFactory.createConnection(getConf());
      Admin admin = connection.getAdmin()) {
    if (!admin.tableExists(tableName)) {
      if (isCreateTable()) {
        createTable(tableName, hfofDir, admin);
      } else {
        String errorMsg = format("Table '%s' does not exist.", tableName);
        LOG.error(errorMsg);
        throw new TableNotFoundException(errorMsg);
      }
    }
    try (Table table = connection.getTable(tableName);
        RegionLocator locator = connection.getRegionLocator(tableName)) {
      return doBulkLoad(new Path(hfofDir), admin, table, locator, isSilence(),
          isAlwaysCopyFiles());
    }
  }
}
项目:hbase    文件:LoadIncrementalHFiles.java   
/**
 * Perform bulk load on the given table.
 * @param family2Files map of family to List of hfiles
 * @param tableName the table to load into
 */
public Map<LoadQueueItem, ByteBuffer> run(Map<byte[], List<Path>> family2Files,
    TableName tableName) throws IOException {
  try (Connection connection = ConnectionFactory.createConnection(getConf());
      Admin admin = connection.getAdmin()) {
    if (!admin.tableExists(tableName)) {
      String errorMsg = format("Table '%s' does not exist.", tableName);
      LOG.error(errorMsg);
      throw new TableNotFoundException(errorMsg);
    }
    try (Table table = connection.getTable(tableName);
        RegionLocator locator = connection.getRegionLocator(tableName)) {
      return doBulkLoad(family2Files, admin, table, locator, isSilence(), isAlwaysCopyFiles());
    }
  }
}
项目:hbase    文件:TableStateManager.java   
/**
 * Set table state to provided but only if table in specified states
 * Caller should lock table on write.
 * @param tableName table to change state for
 * @param newState new state
 * @param states states to check against
 * @return null if succeed or table state if failed
 * @throws IOException
 */
public TableState.State setTableStateIfInStates(TableName tableName,
                                       TableState.State newState,
                                       TableState.State... states)
        throws IOException {
  lock.writeLock().lock();
  try {
    TableState currentState = readMetaState(tableName);
    if (currentState == null) {
      throw new TableNotFoundException(tableName);
    }
    if (currentState.inStates(states)) {
      updateMetaState(tableName, newState);
      return null;
    } else {
      return currentState.getState();
    }
  } finally {
    lock.writeLock().unlock();
  }

}
项目:hbase    文件:TestReplicasClient.java   
@Test
public void testFlushSecondary() throws Exception {
  openRegion(hriSecondary);
  try {
    flushRegion(hriSecondary);

    Put p = new Put(row);
    p.addColumn(f, row, row);
    table.put(p);

    flushRegion(hriSecondary);
  } catch (TableNotFoundException expected) {
  } finally {
    Delete d = new Delete(row);
    table.delete(d);
    closeRegion(hriSecondary);
  }
}
项目:c5    文件:HConnectionManager.java   
/**
 * Connects to the master to get the table descriptor.
 * @param tableName table name
 * @return
 * @throws IOException if the connection to master fails or if the table
 *  is not found.
 */
@Override
public HTableDescriptor getHTableDescriptor(final TableName tableName)
throws IOException {
  if (tableName == null) return null;
  if (tableName.equals(TableName.META_TABLE_NAME)) {
    return HTableDescriptor.META_TABLEDESC;
  }
  MasterKeepAliveConnection master = getKeepAliveMasterService();
  GetTableDescriptorsResponse htds;
  try {
    GetTableDescriptorsRequest req =
      RequestConverter.buildGetTableDescriptorsRequest(tableName);
    htds = master.getTableDescriptors(null, req);
  } catch (ServiceException se) {
    throw ProtobufUtil.getRemoteException(se);
  } finally {
    master.close();
  }
  if (!htds.getTableSchemaList().isEmpty()) {
    return HTableDescriptor.convert(htds.getTableSchemaList().get(0));
  }
  throw new TableNotFoundException(tableName.getNameAsString());
}
项目:hbase    文件:TableOutputFormat.java   
/**
 * Checks if the output table exists and is enabled.
 *
 * @param context  The current context.
 * @throws IOException When the check fails.
 * @throws InterruptedException When the job is aborted.
 * @see OutputFormat#checkOutputSpecs(JobContext)
 */
@Override
public void checkOutputSpecs(JobContext context) throws IOException,
    InterruptedException {

  try (Admin admin = ConnectionFactory.createConnection(getConf()).getAdmin()) {
    TableName tableName = TableName.valueOf(this.conf.get(OUTPUT_TABLE));
    if (!admin.tableExists(tableName)) {
      throw new TableNotFoundException("Can't write, table does not exist:" +
          tableName.getNameAsString());
    }

    if (!admin.isTableEnabled(tableName)) {
      throw new TableNotEnabledException("Can't write, table is not enabled: " +
          tableName.getNameAsString());
    }
  }
}
项目:hbase    文件:HBaseAdmin.java   
static TableDescriptor getTableDescriptor(final TableName tableName, Connection connection,
    RpcRetryingCallerFactory rpcCallerFactory, final RpcControllerFactory rpcControllerFactory,
    int operationTimeout, int rpcTimeout) throws IOException {
  if (tableName == null) return null;
  TableDescriptor td =
      executeCallable(new MasterCallable<TableDescriptor>(connection, rpcControllerFactory) {
    @Override
    protected TableDescriptor rpcCall() throws Exception {
      GetTableDescriptorsRequest req =
          RequestConverter.buildGetTableDescriptorsRequest(tableName);
      GetTableDescriptorsResponse htds = master.getTableDescriptors(getRpcController(), req);
      if (!htds.getTableSchemaList().isEmpty()) {
        return ProtobufUtil.toTableDescriptor(htds.getTableSchemaList().get(0));
      }
      return null;
    }
  }, rpcCallerFactory, operationTimeout, rpcTimeout);
  if (td != null) {
    return td;
  }
  throw new TableNotFoundException(tableName.getNameAsString());
}
项目:PyroDB    文件:ConnectionManager.java   
/**
 * Connects to the master to get the table descriptor.
 * @param tableName table name
 * @return
 * @throws IOException if the connection to master fails or if the table
 *  is not found.
 */
@Override
public HTableDescriptor getHTableDescriptor(final TableName tableName)
throws IOException {
  if (tableName == null) return null;
  if (tableName.equals(TableName.META_TABLE_NAME)) {
    return HTableDescriptor.META_TABLEDESC;
  }
  MasterKeepAliveConnection master = getKeepAliveMasterService();
  GetTableDescriptorsResponse htds;
  try {
    GetTableDescriptorsRequest req =
      RequestConverter.buildGetTableDescriptorsRequest(tableName);
    htds = master.getTableDescriptors(null, req);
  } catch (ServiceException se) {
    throw ProtobufUtil.getRemoteException(se);
  } finally {
    master.close();
  }
  if (!htds.getTableSchemaList().isEmpty()) {
    return HTableDescriptor.convert(htds.getTableSchemaList().get(0));
  }
  throw new TableNotFoundException(tableName.getNameAsString());
}
项目:hbase    文件:HBaseAdmin.java   
protected void waitForTableEnabled(final long deadlineTs)
    throws IOException, TimeoutException {
  waitForState(deadlineTs, new TableWaitForStateCallable() {
    @Override
    public boolean checkState(int tries) throws IOException {
      try {
        if (getAdmin().isTableAvailable(tableName)) {
          return true;
        }
      } catch (TableNotFoundException tnfe) {
        LOG.debug("Table " + tableName.getNameWithNamespaceInclAsString()
            + " was not enabled, sleeping. tries=" + tries);
      }
      return false;
    }
  });
}
项目:hbase    文件:RawAsyncHBaseAdmin.java   
@Override
public CompletableFuture<TableDescriptor> getDescriptor(TableName tableName) {
  CompletableFuture<TableDescriptor> 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.toTableDescriptor(tableSchemas.get(0)));
        } else {
          future.completeExceptionally(new TableNotFoundException(tableName.getNameAsString()));
        }
      });
  return future;
}
项目:hbase    文件:RawAsyncHBaseAdmin.java   
@Override
public CompletableFuture<Boolean> isTableEnabled(TableName tableName) {
  CompletableFuture<Boolean> future = new CompletableFuture<>();
  AsyncMetaTableAccessor.getTableState(metaTable, tableName).whenComplete((state, error) -> {
    if (error != null) {
      future.completeExceptionally(error);
      return;
    }
    if (state.isPresent()) {
      future.complete(state.get().inStates(TableState.State.ENABLED));
    } else {
      future.completeExceptionally(new TableNotFoundException(tableName));
    }
  });
  return future;
}
项目:hbase    文件:RawAsyncHBaseAdmin.java   
@Override
public CompletableFuture<Boolean> isTableDisabled(TableName tableName) {
  CompletableFuture<Boolean> future = new CompletableFuture<>();
  AsyncMetaTableAccessor.getTableState(metaTable, tableName).whenComplete((state, error) -> {
    if (error != null) {
      future.completeExceptionally(error);
      return;
    }
    if (state.isPresent()) {
      future.complete(state.get().inStates(TableState.State.DISABLED));
    } else {
      future.completeExceptionally(new TableNotFoundException(tableName));
    }
  });
  return future;
}
项目:RStore    文件:AssignmentManager.java   
/**
 * Recover the tables that were not fully moved to DISABLED state. These
 * tables are in DISABLING state when the master restarted/switched.
 * 
 * @param disablingTables
 * @return
 * @throws KeeperException
 * @throws TableNotFoundException
 * @throws IOException
 */
private boolean recoverTableInDisablingState(Set<String> disablingTables)
    throws KeeperException, TableNotFoundException, IOException {
  boolean isWatcherCreated = false;
  if (disablingTables.size() != 0) {
    // Create a watcher on the zookeeper node
    ZKUtil.listChildrenAndWatchForNewChildren(watcher,
        watcher.assignmentZNode);
    isWatcherCreated = true;
    for (String tableName : disablingTables) {
      // Recover by calling DisableTableHandler
      LOG.info("The table " + tableName
          + " is in DISABLING state.  Hence recovering by moving the table"
          + " to DISABLED state.");
      new DisableTableHandler(this.master, tableName.getBytes(),
          catalogTracker, this, true).process();
    }
  }
  return isWatcherCreated;
}