Search in sources :

Example 31 with TableName

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

the class RegionPlacementMaintainer method getNewAssignmentPlan.

public FavoredNodesPlan getNewAssignmentPlan() throws IOException {
    // Get the current region assignment snapshot by scanning from the META
    SnapshotOfRegionAssignmentFromMeta assignmentSnapshot = this.getRegionAssignmentSnapshot();
    // Get the region locality map
    Map<String, Map<String, Float>> regionLocalityMap = null;
    if (this.enforceLocality) {
        regionLocalityMap = FSUtils.getRegionDegreeLocalityMappingFromFS(conf);
    }
    // Initialize the assignment plan
    FavoredNodesPlan plan = new FavoredNodesPlan();
    // Get the table to region mapping
    Map<TableName, List<HRegionInfo>> tableToRegionMap = assignmentSnapshot.getTableToRegionMap();
    LOG.info("Start to generate the new assignment plan for the " + +tableToRegionMap.keySet().size() + " tables");
    for (TableName table : tableToRegionMap.keySet()) {
        try {
            if (!this.targetTableSet.isEmpty() && !this.targetTableSet.contains(table)) {
                continue;
            }
            // TODO: maybe run the placement in parallel for each table
            genAssignmentPlan(table, assignmentSnapshot, regionLocalityMap, plan, USE_MUNKRES_FOR_PLACING_SECONDARY_AND_TERTIARY);
        } catch (Exception e) {
            LOG.error("Get some exceptions for placing primary region server" + "for table " + table + " because " + e);
        }
    }
    LOG.info("Finish to generate the new assignment plan for the " + +tableToRegionMap.keySet().size() + " tables");
    return plan;
}
Also used : TableName(org.apache.hadoop.hbase.TableName) ArrayList(java.util.ArrayList) List(java.util.List) FavoredNodesPlan(org.apache.hadoop.hbase.favored.FavoredNodesPlan) HashMap(java.util.HashMap) Map(java.util.Map) TreeMap(java.util.TreeMap) IOException(java.io.IOException) ParseException(org.apache.commons.cli.ParseException)

Example 32 with TableName

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

the class RegionPlacementMaintainer method getRegionsMovement.

/**
   * Return how many regions will move per table since their primary RS will
   * change
   *
   * @param newPlan - new AssignmentPlan
   * @return how many primaries will move per table
   */
public Map<TableName, Integer> getRegionsMovement(FavoredNodesPlan newPlan) throws IOException {
    Map<TableName, Integer> movesPerTable = new HashMap<>();
    SnapshotOfRegionAssignmentFromMeta snapshot = this.getRegionAssignmentSnapshot();
    Map<TableName, List<HRegionInfo>> tableToRegions = snapshot.getTableToRegionMap();
    FavoredNodesPlan oldPlan = snapshot.getExistingAssignmentPlan();
    Set<TableName> tables = snapshot.getTableSet();
    for (TableName table : tables) {
        int movedPrimaries = 0;
        if (!this.targetTableSet.isEmpty() && !this.targetTableSet.contains(table)) {
            continue;
        }
        List<HRegionInfo> regions = tableToRegions.get(table);
        for (HRegionInfo region : regions) {
            List<ServerName> oldServers = oldPlan.getFavoredNodes(region);
            List<ServerName> newServers = newPlan.getFavoredNodes(region);
            if (oldServers != null && newServers != null) {
                ServerName oldPrimary = oldServers.get(0);
                ServerName newPrimary = newServers.get(0);
                if (oldPrimary.compareTo(newPrimary) != 0) {
                    movedPrimaries++;
                }
            }
        }
        movesPerTable.put(table, movedPrimaries);
    }
    return movesPerTable;
}
Also used : HashMap(java.util.HashMap) FavoredNodesPlan(org.apache.hadoop.hbase.favored.FavoredNodesPlan) HRegionInfo(org.apache.hadoop.hbase.HRegionInfo) TableName(org.apache.hadoop.hbase.TableName) ServerName(org.apache.hadoop.hbase.ServerName) ArrayList(java.util.ArrayList) List(java.util.List)

Example 33 with TableName

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

the class RegionPlacementMaintainer method verifyRegionPlacement.

/**
   * Verify the region placement is consistent with the assignment plan
   * @param isDetailMode
   * @return reports
   * @throws IOException
   */
public List<AssignmentVerificationReport> verifyRegionPlacement(boolean isDetailMode) throws IOException {
    System.out.println("Start to verify the region assignment and " + "generate the verification report");
    // Get the region assignment snapshot
    SnapshotOfRegionAssignmentFromMeta snapshot = this.getRegionAssignmentSnapshot();
    // Get all the tables
    Set<TableName> tables = snapshot.getTableSet();
    // Get the region locality map
    Map<String, Map<String, Float>> regionLocalityMap = null;
    if (this.enforceLocality == true) {
        regionLocalityMap = FSUtils.getRegionDegreeLocalityMappingFromFS(conf);
    }
    List<AssignmentVerificationReport> reports = new ArrayList<>();
    // Iterate all the tables to fill up the verification report
    for (TableName table : tables) {
        if (!this.targetTableSet.isEmpty() && !this.targetTableSet.contains(table)) {
            continue;
        }
        AssignmentVerificationReport report = new AssignmentVerificationReport();
        report.fillUp(table, snapshot, regionLocalityMap);
        report.print(isDetailMode);
        reports.add(report);
    }
    return reports;
}
Also used : TableName(org.apache.hadoop.hbase.TableName) ArrayList(java.util.ArrayList) HashMap(java.util.HashMap) Map(java.util.Map) TreeMap(java.util.TreeMap)

Example 34 with TableName

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

the class MasterRpcServices method getSchemaAlterStatus.

/**
   * Get the number of regions of the table that have been updated by the alter.
   *
   * @return Pair indicating the number of regions updated Pair.getFirst is the
   *         regions that are yet to be updated Pair.getSecond is the total number
   *         of regions of the table
   * @throws ServiceException
   */
@Override
public GetSchemaAlterStatusResponse getSchemaAlterStatus(RpcController controller, GetSchemaAlterStatusRequest req) throws ServiceException {
    // TODO: currently, we query using the table name on the client side. this
    // may overlap with other table operations or the table operation may
    // have completed before querying this API. We need to refactor to a
    // transaction system in the future to avoid these ambiguities.
    TableName tableName = ProtobufUtil.toTableName(req.getTableName());
    try {
        master.checkInitialized();
        Pair<Integer, Integer> pair = master.getAssignmentManager().getReopenStatus(tableName);
        GetSchemaAlterStatusResponse.Builder ret = GetSchemaAlterStatusResponse.newBuilder();
        ret.setYetToUpdateRegions(pair.getFirst());
        ret.setTotalRegions(pair.getSecond());
        return ret.build();
    } catch (IOException ioe) {
        throw new ServiceException(ioe);
    }
}
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) GetSchemaAlterStatusResponse(org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProtos.GetSchemaAlterStatusResponse)

Example 35 with TableName

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

the class AssignmentManager method rebuildUserRegions.

/**
   * Rebuild the list of user regions and assignment information.
   * Updates regionstates with findings as we go through list of regions.
   * @return set of servers not online that hosted some regions according to a scan of hbase:meta
   * @throws IOException
   */
Set<ServerName> rebuildUserRegions() throws IOException, KeeperException {
    Set<TableName> disabledOrEnablingTables = tableStateManager.getTablesInStates(TableState.State.DISABLED, TableState.State.ENABLING);
    Set<TableName> disabledOrDisablingOrEnabling = tableStateManager.getTablesInStates(TableState.State.DISABLED, TableState.State.DISABLING, TableState.State.ENABLING);
    // Region assignment from META
    List<Result> results = MetaTableAccessor.fullScanRegions(server.getConnection());
    // Get any new but slow to checkin region server that joined the cluster
    Set<ServerName> onlineServers = serverManager.getOnlineServers().keySet();
    // Set of offline servers to be returned
    Set<ServerName> offlineServers = new HashSet<>();
    // Iterate regions in META
    for (Result result : results) {
        if (result == null && LOG.isDebugEnabled()) {
            LOG.debug("null result from meta - ignoring but this is strange.");
            continue;
        }
        // keep a track of replicas to close. These were the replicas of the originally
        // unmerged regions. The master might have closed them before but it mightn't
        // maybe because it crashed.
        PairOfSameType<HRegionInfo> p = MetaTableAccessor.getMergeRegions(result);
        if (p.getFirst() != null && p.getSecond() != null) {
            int numReplicas = getNumReplicas(server, p.getFirst().getTable());
            for (HRegionInfo merge : p) {
                for (int i = 1; i < numReplicas; i++) {
                    replicasToClose.add(RegionReplicaUtil.getRegionInfoForReplica(merge, i));
                }
            }
        }
        RegionLocations rl = MetaTableAccessor.getRegionLocations(result);
        if (rl == null) {
            continue;
        }
        HRegionLocation[] locations = rl.getRegionLocations();
        if (locations == null) {
            continue;
        }
        for (HRegionLocation hrl : locations) {
            if (hrl == null)
                continue;
            HRegionInfo regionInfo = hrl.getRegionInfo();
            if (regionInfo == null)
                continue;
            int replicaId = regionInfo.getReplicaId();
            State state = RegionStateStore.getRegionState(result, replicaId);
            // but it couldn't maybe because it crashed
            if (replicaId == 0 && state.equals(State.SPLIT)) {
                for (HRegionLocation h : locations) {
                    replicasToClose.add(h.getRegionInfo());
                }
            }
            ServerName lastHost = hrl.getServerName();
            ServerName regionLocation = RegionStateStore.getRegionServer(result, replicaId);
            regionStates.createRegionState(regionInfo, state, regionLocation, lastHost);
            if (!regionStates.isRegionInState(regionInfo, State.OPEN)) {
                // Region is not open (either offline or in transition), skip
                continue;
            }
            TableName tableName = regionInfo.getTable();
            if (!onlineServers.contains(regionLocation)) {
                // Region is located on a server that isn't online
                offlineServers.add(regionLocation);
            } else if (!disabledOrEnablingTables.contains(tableName)) {
                // Region is being served and on an active server
                // add only if region not in disabled or enabling table
                regionStates.regionOnline(regionInfo, regionLocation);
                balancer.regionOnline(regionInfo, regionLocation);
            }
            // this will be used in rolling restarts
            if (!disabledOrDisablingOrEnabling.contains(tableName) && !getTableStateManager().isTableState(tableName, TableState.State.ENABLED)) {
                setEnabledTable(tableName);
            }
        }
    }
    return offlineServers;
}
Also used : RegionLocations(org.apache.hadoop.hbase.RegionLocations) Result(org.apache.hadoop.hbase.client.Result) HRegionInfo(org.apache.hadoop.hbase.HRegionInfo) TableName(org.apache.hadoop.hbase.TableName) HRegionLocation(org.apache.hadoop.hbase.HRegionLocation) State(org.apache.hadoop.hbase.master.RegionState.State) TableState(org.apache.hadoop.hbase.client.TableState) RegionOpeningState(org.apache.hadoop.hbase.regionserver.RegionOpeningState) ServerName(org.apache.hadoop.hbase.ServerName) HashSet(java.util.HashSet)

Aggregations

TableName (org.apache.hadoop.hbase.TableName)1033 Test (org.junit.Test)695 HTableDescriptor (org.apache.hadoop.hbase.HTableDescriptor)257 Table (org.apache.hadoop.hbase.client.Table)228 IOException (java.io.IOException)225 HRegionInfo (org.apache.hadoop.hbase.HRegionInfo)215 HColumnDescriptor (org.apache.hadoop.hbase.HColumnDescriptor)203 Result (org.apache.hadoop.hbase.client.Result)125 ArrayList (java.util.ArrayList)120 Put (org.apache.hadoop.hbase.client.Put)118 Path (org.apache.hadoop.fs.Path)113 Connection (org.apache.hadoop.hbase.client.Connection)103 Scan (org.apache.hadoop.hbase.client.Scan)98 ResultScanner (org.apache.hadoop.hbase.client.ResultScanner)89 ServerName (org.apache.hadoop.hbase.ServerName)85 Admin (org.apache.hadoop.hbase.client.Admin)85 Cell (org.apache.hadoop.hbase.Cell)77 HashMap (java.util.HashMap)75 Delete (org.apache.hadoop.hbase.client.Delete)66 InterruptedIOException (java.io.InterruptedIOException)63