Search in sources :

Example 1 with TableState

use of org.apache.hadoop.hbase.client.TableState in project hbase by apache.

the class MasterRpcServices method getTableState.

@Override
public GetTableStateResponse getTableState(RpcController controller, GetTableStateRequest request) throws ServiceException {
    try {
        master.checkServiceStarted();
        TableName tableName = ProtobufUtil.toTableName(request.getTableName());
        TableState.State state = master.getTableStateManager().getTableState(tableName);
        GetTableStateResponse.Builder builder = GetTableStateResponse.newBuilder();
        builder.setTableState(new TableState(tableName, state).convert());
        return builder.build();
    } catch (IOException e) {
        throw new ServiceException(e);
    }
}
Also used : TableName(org.apache.hadoop.hbase.TableName) ServiceException(org.apache.hadoop.hbase.shaded.com.google.protobuf.ServiceException) IOException(java.io.IOException) DoNotRetryIOException(org.apache.hadoop.hbase.DoNotRetryIOException) GetTableStateResponse(org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProtos.GetTableStateResponse) TableState(org.apache.hadoop.hbase.client.TableState)

Example 2 with TableState

use of org.apache.hadoop.hbase.client.TableState in project hbase by apache.

the class HBaseTestingUtility method findLastTableState.

@Nullable
public TableState findLastTableState(final TableName table) throws IOException {
    final AtomicReference<TableState> lastTableState = new AtomicReference<>(null);
    MetaTableAccessor.Visitor visitor = new MetaTableAccessor.Visitor() {

        @Override
        public boolean visit(Result r) throws IOException {
            if (!Arrays.equals(r.getRow(), table.getName()))
                return false;
            TableState state = MetaTableAccessor.getTableState(r);
            if (state != null)
                lastTableState.set(state);
            return true;
        }
    };
    MetaTableAccessor.scanMeta(connection, null, null, MetaTableAccessor.QueryType.TABLE, Integer.MAX_VALUE, visitor);
    return lastTableState.get();
}
Also used : AtomicReference(java.util.concurrent.atomic.AtomicReference) TableState(org.apache.hadoop.hbase.client.TableState) Result(org.apache.hadoop.hbase.client.Result) Nullable(edu.umd.cs.findbugs.annotations.Nullable)

Example 3 with TableState

use of org.apache.hadoop.hbase.client.TableState in project hbase by apache.

the class HBaseFsck method generatePuts.

/**
   * Generate set of puts to add to new meta.  This expects the tables to be
   * clean with no overlaps or holes.  If there are any problems it returns null.
   *
   * @return An array list of puts to do in bulk, null if tables have problems
   */
private ArrayList<Put> generatePuts(SortedMap<TableName, TableInfo> tablesInfo) throws IOException {
    ArrayList<Put> puts = new ArrayList<>();
    boolean hasProblems = false;
    for (Entry<TableName, TableInfo> e : tablesInfo.entrySet()) {
        TableName name = e.getKey();
        // skip "hbase:meta"
        if (name.compareTo(TableName.META_TABLE_NAME) == 0) {
            continue;
        }
        TableInfo ti = e.getValue();
        puts.add(MetaTableAccessor.makePutFromTableState(new TableState(ti.tableName, TableState.State.ENABLED)));
        for (Entry<byte[], Collection<HbckInfo>> spl : ti.sc.getStarts().asMap().entrySet()) {
            Collection<HbckInfo> his = spl.getValue();
            int sz = his.size();
            if (sz != 1) {
                // problem
                LOG.error("Split starting at " + Bytes.toStringBinary(spl.getKey()) + " had " + sz + " regions instead of exactly 1.");
                hasProblems = true;
                continue;
            }
            // add the row directly to meta.
            HbckInfo hi = his.iterator().next();
            // hi.metaEntry;
            HRegionInfo hri = hi.getHdfsHRI();
            Put p = MetaTableAccessor.makePutFromRegionInfo(hri);
            puts.add(p);
        }
    }
    return hasProblems ? null : puts;
}
Also used : ArrayList(java.util.ArrayList) Put(org.apache.hadoop.hbase.client.Put) HRegionInfo(org.apache.hadoop.hbase.HRegionInfo) TableName(org.apache.hadoop.hbase.TableName) Collection(java.util.Collection) TableState(org.apache.hadoop.hbase.client.TableState)

Example 4 with TableState

use of org.apache.hadoop.hbase.client.TableState in project hbase by apache.

the class HBaseFsck method checkAndFixTableStates.

/**
   * Check and fix table states, assumes full info available:
   * - tableInfos
   * - empty tables loaded
   */
private void checkAndFixTableStates() throws IOException {
    // first check dangling states
    for (Entry<TableName, TableState> entry : tableStates.entrySet()) {
        TableName tableName = entry.getKey();
        TableState tableState = entry.getValue();
        TableInfo tableInfo = tablesInfo.get(tableName);
        if (isTableIncluded(tableName) && !tableName.isSystemTable() && tableInfo == null) {
            if (fixMeta) {
                MetaTableAccessor.deleteTableState(connection, tableName);
                TableState state = MetaTableAccessor.getTableState(connection, tableName);
                if (state != null) {
                    errors.reportError(ERROR_CODE.ORPHAN_TABLE_STATE, tableName + " unable to delete dangling table state " + tableState);
                }
            } else {
                errors.reportError(ERROR_CODE.ORPHAN_TABLE_STATE, tableName + " has dangling table state " + tableState);
            }
        }
    }
    // check that all tables have states
    for (TableName tableName : tablesInfo.keySet()) {
        if (isTableIncluded(tableName) && !tableStates.containsKey(tableName)) {
            if (fixMeta) {
                MetaTableAccessor.updateTableState(connection, tableName, TableState.State.ENABLED);
                TableState newState = MetaTableAccessor.getTableState(connection, tableName);
                if (newState == null) {
                    errors.reportError(ERROR_CODE.NO_TABLE_STATE, "Unable to change state for table " + tableName + " in meta ");
                }
            } else {
                errors.reportError(ERROR_CODE.NO_TABLE_STATE, tableName + " has no state in meta ");
            }
        }
    }
}
Also used : TableName(org.apache.hadoop.hbase.TableName) TableState(org.apache.hadoop.hbase.client.TableState)

Example 5 with TableState

use of org.apache.hadoop.hbase.client.TableState in project hbase by apache.

the class MetaTableAccessor method getTableStates.

/**
   * Fetch table states from META table
   * @param conn connection to use
   * @return map {tableName -&gt; state}
   * @throws IOException
   */
public static Map<TableName, TableState> getTableStates(Connection conn) throws IOException {
    final Map<TableName, TableState> states = new LinkedHashMap<>();
    Visitor collector = new Visitor() {

        @Override
        public boolean visit(Result r) throws IOException {
            TableState state = getTableState(r);
            if (state != null)
                states.put(state.getTableName(), state);
            return true;
        }
    };
    fullScanTables(conn, collector);
    return states;
}
Also used : LinkedHashMap(java.util.LinkedHashMap) TableState(org.apache.hadoop.hbase.client.TableState) Result(org.apache.hadoop.hbase.client.Result)

Aggregations

TableState (org.apache.hadoop.hbase.client.TableState)6 TableName (org.apache.hadoop.hbase.TableName)3 Result (org.apache.hadoop.hbase.client.Result)3 Nullable (edu.umd.cs.findbugs.annotations.Nullable)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 Collection (java.util.Collection)1 LinkedHashMap (java.util.LinkedHashMap)1 AtomicReference (java.util.concurrent.atomic.AtomicReference)1 DoNotRetryIOException (org.apache.hadoop.hbase.DoNotRetryIOException)1 HRegionInfo (org.apache.hadoop.hbase.HRegionInfo)1 Put (org.apache.hadoop.hbase.client.Put)1 ServiceException (org.apache.hadoop.hbase.shaded.com.google.protobuf.ServiceException)1 GetTableStateResponse (org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProtos.GetTableStateResponse)1