Search in sources :

Example 51 with RegionInfo

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

the class HMaster method waitForNamespaceOnline.

/**
 * Check hbase:namespace table is assigned. If not, startup will hang looking for the ns table
 * <p/>
 * This is for rolling upgrading, later we will migrate the data in ns table to the ns family of
 * meta table. And if this is a new cluster, this method will return immediately as there will be
 * no namespace table/region.
 * @return True if namespace table is up/online.
 */
private boolean waitForNamespaceOnline() throws IOException {
    TableState nsTableState = MetaTableAccessor.getTableState(getConnection(), TableName.NAMESPACE_TABLE_NAME);
    if (nsTableState == null || nsTableState.isDisabled()) {
        // or this is a new deploy which does not have a namespace table from the beginning.
        return true;
    }
    List<RegionInfo> ris = this.assignmentManager.getRegionStates().getRegionsOfTable(TableName.NAMESPACE_TABLE_NAME);
    if (ris.isEmpty()) {
        // maybe this will not happen any more, but anyway, no harm to add a check here...
        return true;
    }
    // Else there are namespace regions up in meta. Ensure they are assigned before we go on.
    for (RegionInfo ri : ris) {
        if (!isRegionOnline(ri)) {
            return false;
        }
    }
    return true;
}
Also used : RegionInfo(org.apache.hadoop.hbase.client.RegionInfo) TableState(org.apache.hadoop.hbase.client.TableState)

Example 52 with RegionInfo

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

the class HMaster method balanceOrUpdateMetrics.

/**
 *  Trigger a normal balance, see {@link HMaster#balance()} . If the balance is not executed
 *  this time, the metrics related to the balance will be updated.
 *
 *  When balance is running, related metrics will be updated at the same time. But if some
 *  checking logic failed and cause the balancer exit early, we lost the chance to update
 *  balancer metrics. This will lead to user missing the latest balancer info.
 */
public BalanceResponse balanceOrUpdateMetrics() throws IOException {
    synchronized (this.balancer) {
        BalanceResponse response = balance();
        if (!response.isBalancerRan()) {
            Map<TableName, Map<ServerName, List<RegionInfo>>> assignments = this.assignmentManager.getRegionStates().getAssignmentsForBalancer(this.tableStateManager, this.serverManager.getOnlineServersList());
            for (Map<ServerName, List<RegionInfo>> serverMap : assignments.values()) {
                serverMap.keySet().removeAll(this.serverManager.getDrainingServersList());
            }
            this.balancer.updateBalancerLoadInfo(assignments);
        }
        return response;
    }
}
Also used : TableName(org.apache.hadoop.hbase.TableName) BalanceResponse(org.apache.hadoop.hbase.client.BalanceResponse) ServerName(org.apache.hadoop.hbase.ServerName) RegionInfo(org.apache.hadoop.hbase.client.RegionInfo) LinkedList(java.util.LinkedList) ArrayList(java.util.ArrayList) List(java.util.List) Map(java.util.Map) HashMap(java.util.HashMap)

Example 53 with RegionInfo

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

the class HMaster method move.

// Public so can be accessed by tests. Blocks until move is done.
// Replace with an async implementation from which you can get
// a success/failure result.
@InterfaceAudience.Private
public void move(final byte[] encodedRegionName, byte[] destServerName) throws IOException {
    RegionState regionState = assignmentManager.getRegionStates().getRegionState(Bytes.toString(encodedRegionName));
    RegionInfo hri;
    if (regionState != null) {
        hri = regionState.getRegion();
    } else {
        throw new UnknownRegionException(Bytes.toStringBinary(encodedRegionName));
    }
    ServerName dest;
    List<ServerName> exclude = hri.getTable().isSystemTable() ? assignmentManager.getExcludedServersForSystemTable() : new ArrayList<>(1);
    if (destServerName != null && exclude.contains(ServerName.valueOf(Bytes.toString(destServerName)))) {
        LOG.info(Bytes.toString(encodedRegionName) + " can not move to " + Bytes.toString(destServerName) + " because the server is in exclude list");
        destServerName = null;
    }
    if (destServerName == null || destServerName.length == 0) {
        LOG.info("Passed destination servername is null/empty so " + "choosing a server at random");
        exclude.add(regionState.getServerName());
        final List<ServerName> destServers = this.serverManager.createDestinationServersList(exclude);
        dest = balancer.randomAssignment(hri, destServers);
        if (dest == null) {
            LOG.debug("Unable to determine a plan to assign " + hri);
            return;
        }
    } else {
        ServerName candidate = ServerName.valueOf(Bytes.toString(destServerName));
        dest = balancer.randomAssignment(hri, Lists.newArrayList(candidate));
        if (dest == null) {
            LOG.debug("Unable to determine a plan to assign " + hri);
            return;
        }
        // TODO: deal with table on master for rs group.
        if (dest.equals(serverName)) {
            // To avoid unnecessary region moving later by balancer. Don't put user
            // regions on master.
            LOG.debug("Skipping move of region " + hri.getRegionNameAsString() + " to avoid unnecessary region moving later by load balancer," + " because it should not be on master");
            return;
        }
    }
    if (dest.equals(regionState.getServerName())) {
        LOG.debug("Skipping move of region " + hri.getRegionNameAsString() + " because region already assigned to the same server " + dest + ".");
        return;
    }
    // Now we can do the move
    RegionPlan rp = new RegionPlan(hri, regionState.getServerName(), dest);
    assert rp.getDestination() != null : rp.toString() + " " + dest;
    try {
        checkInitialized();
        if (this.cpHost != null) {
            this.cpHost.preMove(hri, rp.getSource(), rp.getDestination());
        }
        TransitRegionStateProcedure proc = this.assignmentManager.createMoveRegionProcedure(rp.getRegionInfo(), rp.getDestination());
        if (conf.getBoolean(WARMUP_BEFORE_MOVE, DEFAULT_WARMUP_BEFORE_MOVE)) {
            // Warmup the region on the destination before initiating the move.
            // A region server could reject the close request because it either does not
            // have the specified region or the region is being split.
            LOG.info(getClientIdAuditPrefix() + " move " + rp + ", warming up region on " + rp.getDestination());
            warmUpRegion(rp.getDestination(), hri);
        }
        LOG.info(getClientIdAuditPrefix() + " move " + rp + ", running balancer");
        Future<byte[]> future = ProcedureSyncWait.submitProcedure(this.procedureExecutor, proc);
        try {
            // Is this going to work? Will we throw exception on error?
            // TODO: CompletableFuture rather than this stunted Future.
            future.get();
        } catch (InterruptedException | ExecutionException e) {
            throw new HBaseIOException(e);
        }
        if (this.cpHost != null) {
            this.cpHost.postMove(hri, rp.getSource(), rp.getDestination());
        }
    } catch (IOException ioe) {
        if (ioe instanceof HBaseIOException) {
            throw (HBaseIOException) ioe;
        }
        throw new HBaseIOException(ioe);
    }
}
Also used : HBaseIOException(org.apache.hadoop.hbase.HBaseIOException) UnknownRegionException(org.apache.hadoop.hbase.UnknownRegionException) RegionInfo(org.apache.hadoop.hbase.client.RegionInfo) IOException(java.io.IOException) DoNotRetryIOException(org.apache.hadoop.hbase.DoNotRetryIOException) HBaseIOException(org.apache.hadoop.hbase.HBaseIOException) InterruptedIOException(java.io.InterruptedIOException) TransitRegionStateProcedure(org.apache.hadoop.hbase.master.assignment.TransitRegionStateProcedure) ServerName(org.apache.hadoop.hbase.ServerName) ExecutionException(java.util.concurrent.ExecutionException)

Example 54 with RegionInfo

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

the class HMaster method createSystemTable.

@Override
public long createSystemTable(final TableDescriptor tableDescriptor) throws IOException {
    if (isStopped()) {
        throw new MasterNotRunningException();
    }
    TableName tableName = tableDescriptor.getTableName();
    if (!(tableName.isSystemTable())) {
        throw new IllegalArgumentException("Only system table creation can use this createSystemTable API");
    }
    RegionInfo[] newRegions = ModifyRegionUtils.createRegionInfos(tableDescriptor, null);
    LOG.info(getClientIdAuditPrefix() + " create " + tableDescriptor);
    // This special create table is called locally to master.  Therefore, no RPC means no need
    // to use nonce to detect duplicated RPC call.
    long procId = this.procedureExecutor.submitProcedure(new CreateTableProcedure(procedureExecutor.getEnvironment(), tableDescriptor, newRegions));
    return procId;
}
Also used : TableName(org.apache.hadoop.hbase.TableName) MasterNotRunningException(org.apache.hadoop.hbase.MasterNotRunningException) RegionInfo(org.apache.hadoop.hbase.client.RegionInfo) CreateTableProcedure(org.apache.hadoop.hbase.master.procedure.CreateTableProcedure)

Example 55 with RegionInfo

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

the class HMaster method recommissionRegionServer.

/**
 * Remove decommission marker (previously called 'draining') from a region server to allow regions
 * assignments. Load regions onto the server asynchronously if a list of regions is given
 * @param server Region server to remove decommission marker from.
 */
public void recommissionRegionServer(final ServerName server, final List<byte[]> encodedRegionNames) throws IOException {
    // Remove the server from decommissioned (draining) server list.
    String parentZnode = getZooKeeper().getZNodePaths().drainingZNode;
    String node = ZNodePaths.joinZNode(parentZnode, server.getServerName());
    try {
        ZKUtil.deleteNodeFailSilent(getZooKeeper(), node);
    } catch (KeeperException ke) {
        throw new HBaseIOException(this.zooKeeper.prefix("Unable to recommission '" + server.getServerName() + "'."), ke);
    }
    this.serverManager.removeServerFromDrainList(server);
    // Load the regions onto the server if we are given a list of regions.
    if (encodedRegionNames == null || encodedRegionNames.isEmpty()) {
        return;
    }
    if (!this.serverManager.isServerOnline(server)) {
        return;
    }
    for (byte[] encodedRegionName : encodedRegionNames) {
        RegionState regionState = assignmentManager.getRegionStates().getRegionState(Bytes.toString(encodedRegionName));
        if (regionState == null) {
            LOG.warn("Unknown region " + Bytes.toStringBinary(encodedRegionName));
            continue;
        }
        RegionInfo hri = regionState.getRegion();
        if (server.equals(regionState.getServerName())) {
            LOG.info("Skipping move of region " + hri.getRegionNameAsString() + " because region already assigned to the same server " + server + ".");
            continue;
        }
        RegionPlan rp = new RegionPlan(hri, regionState.getServerName(), server);
        this.assignmentManager.moveAsync(rp);
    }
}
Also used : HBaseIOException(org.apache.hadoop.hbase.HBaseIOException) RegionInfo(org.apache.hadoop.hbase.client.RegionInfo) KeeperException(org.apache.zookeeper.KeeperException)

Aggregations

RegionInfo (org.apache.hadoop.hbase.client.RegionInfo)824 Test (org.junit.Test)416 TableName (org.apache.hadoop.hbase.TableName)311 ServerName (org.apache.hadoop.hbase.ServerName)191 ArrayList (java.util.ArrayList)175 IOException (java.io.IOException)174 TableDescriptor (org.apache.hadoop.hbase.client.TableDescriptor)174 Path (org.apache.hadoop.fs.Path)141 List (java.util.List)118 HashMap (java.util.HashMap)90 Table (org.apache.hadoop.hbase.client.Table)90 Map (java.util.Map)81 Put (org.apache.hadoop.hbase.client.Put)81 Configuration (org.apache.hadoop.conf.Configuration)80 HRegion (org.apache.hadoop.hbase.regionserver.HRegion)67 TreeMap (java.util.TreeMap)66 Result (org.apache.hadoop.hbase.client.Result)59 FileSystem (org.apache.hadoop.fs.FileSystem)58 Cell (org.apache.hadoop.hbase.Cell)50 Scan (org.apache.hadoop.hbase.client.Scan)46