private void checkAndFixTableStates()

in hbase-hbck2/src/main/java/org/apache/hbase/hbck1/HBaseFsck.java [2422:2462]


  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) {
          HBCKMetaTableAccessor.deleteTableState(connection, tableName);
          TableState state = HBCKMetaTableAccessor.getTableState(connection, tableName);
          if (state != null) {
            errors.reportError(ErrorReporter.ERROR_CODE.ORPHAN_TABLE_STATE,
                tableName + " unable to delete dangling table state " + tableState);
          }
        } else if (!checkMetaOnly) {
          // dangling table state in meta if checkMetaOnly is false. If checkMetaOnly is
          // true, tableInfo will be null as tablesInfo are not polulated for all tables from hdfs
          errors.reportError(ErrorReporter.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) {
          HBCKMetaTableAccessor.updateTableState(connection, tableName, TableState.State.ENABLED);
          TableState newState = HBCKMetaTableAccessor.getTableState(connection, tableName);
          if (newState == null) {
            errors.reportError(ErrorReporter.ERROR_CODE.NO_TABLE_STATE,
                "Unable to change state for table " + tableName + " in meta ");
          }
        } else {
          errors.reportError(ErrorReporter.ERROR_CODE.NO_TABLE_STATE,
              tableName + " has no state in meta ");
        }
      }
    }
  }