Search in sources :

Example 1 with RegionLoad

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

the class StorageClusterStatusResource method get.

@GET
@Produces({ MIMETYPE_TEXT, MIMETYPE_XML, MIMETYPE_JSON, MIMETYPE_PROTOBUF, MIMETYPE_PROTOBUF_IETF })
public Response get(@Context final UriInfo uriInfo) {
    if (LOG.isTraceEnabled()) {
        LOG.trace("GET " + uriInfo.getAbsolutePath());
    }
    servlet.getMetrics().incrementRequests(1);
    try {
        ClusterStatus status = servlet.getAdmin().getClusterStatus();
        StorageClusterStatusModel model = new StorageClusterStatusModel();
        model.setRegions(status.getRegionsCount());
        model.setRequests(status.getRequestsCount());
        model.setAverageLoad(status.getAverageLoad());
        for (ServerName info : status.getServers()) {
            ServerLoad load = status.getLoad(info);
            StorageClusterStatusModel.Node node = model.addLiveNode(info.getHostname() + ":" + Integer.toString(info.getPort()), info.getStartcode(), load.getUsedHeapMB(), load.getMaxHeapMB());
            node.setRequests(load.getNumberOfRequests());
            for (RegionLoad region : load.getRegionsLoad().values()) {
                node.addRegion(region.getName(), region.getStores(), region.getStorefiles(), region.getStorefileSizeMB(), region.getMemStoreSizeMB(), region.getStorefileIndexSizeMB(), region.getReadRequestsCount(), region.getWriteRequestsCount(), region.getRootIndexSizeKB(), region.getTotalStaticIndexSizeKB(), region.getTotalStaticBloomSizeKB(), region.getTotalCompactingKVs(), region.getCurrentCompactedKVs());
            }
        }
        for (ServerName name : status.getDeadServerNames()) {
            model.addDeadNode(name.toString());
        }
        ResponseBuilder response = Response.ok(model);
        response.cacheControl(cacheControl);
        servlet.getMetrics().incrementSucessfulGetRequests(1);
        return response.build();
    } catch (IOException e) {
        servlet.getMetrics().incrementFailedGetRequests(1);
        return Response.status(Response.Status.SERVICE_UNAVAILABLE).type(MIMETYPE_TEXT).entity("Unavailable" + CRLF).build();
    }
}
Also used : ServerLoad(org.apache.hadoop.hbase.ServerLoad) RegionLoad(org.apache.hadoop.hbase.RegionLoad) ServerName(org.apache.hadoop.hbase.ServerName) StorageClusterStatusModel(org.apache.hadoop.hbase.rest.model.StorageClusterStatusModel) IOException(java.io.IOException) ResponseBuilder(javax.ws.rs.core.Response.ResponseBuilder) ClusterStatus(org.apache.hadoop.hbase.ClusterStatus) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 2 with RegionLoad

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

the class MergeTableRegionsProcedure method MoveRegionsToSameRS.

/**
   * Move all regions to the same region server
   * @param env MasterProcedureEnv
   * @return whether target regions hosted by the same RS
   * @throws IOException
   */
private boolean MoveRegionsToSameRS(final MasterProcedureEnv env) throws IOException {
    // Make sure regions are on the same regionserver before send merge
    // regions request to region server.
    //
    boolean onSameRS = isRegionsOnTheSameServer(env);
    if (!onSameRS) {
        // Note: the following logic assumes that we only have 2 regions to merge.  In the future,
        // if we want to extend to more than 2 regions, the code needs to modify a little bit.
        //
        RegionStates regionStates = getAssignmentManager(env).getRegionStates();
        ServerName regionLocation2 = regionStates.getRegionServerOfRegion(regionsToMerge[1]);
        RegionLoad loadOfRegionA = getRegionLoad(env, regionLocation, regionsToMerge[0]);
        RegionLoad loadOfRegionB = getRegionLoad(env, regionLocation2, regionsToMerge[1]);
        if (loadOfRegionA != null && loadOfRegionB != null && loadOfRegionA.getRequestsCount() < loadOfRegionB.getRequestsCount()) {
            // switch regionsToMerge[0] and regionsToMerge[1]
            HRegionInfo tmpRegion = this.regionsToMerge[0];
            this.regionsToMerge[0] = this.regionsToMerge[1];
            this.regionsToMerge[1] = tmpRegion;
            ServerName tmpLocation = regionLocation;
            regionLocation = regionLocation2;
            regionLocation2 = tmpLocation;
        }
        long startTime = EnvironmentEdgeManager.currentTime();
        RegionPlan regionPlan = new RegionPlan(regionsToMerge[1], regionLocation2, regionLocation);
        LOG.info("Moving regions to same server for merge: " + regionPlan.toString());
        getAssignmentManager(env).balance(regionPlan);
        do {
            try {
                Thread.sleep(20);
                // Make sure check RIT first, then get region location, otherwise
                // we would make a wrong result if region is online between getting
                // region location and checking RIT
                boolean isRIT = regionStates.isRegionInTransition(regionsToMerge[1]);
                regionLocation2 = regionStates.getRegionServerOfRegion(regionsToMerge[1]);
                onSameRS = regionLocation.equals(regionLocation2);
                if (onSameRS || !isRIT) {
                    // RegionInTransition any more
                    break;
                }
            } catch (InterruptedException e) {
                InterruptedIOException iioe = new InterruptedIOException();
                iioe.initCause(e);
                throw iioe;
            }
        } while ((EnvironmentEdgeManager.currentTime() - startTime) <= getTimeout(env));
    }
    return onSameRS;
}
Also used : HRegionInfo(org.apache.hadoop.hbase.HRegionInfo) InterruptedIOException(java.io.InterruptedIOException) RegionLoad(org.apache.hadoop.hbase.RegionLoad) RegionStates(org.apache.hadoop.hbase.master.RegionStates) RegionPlan(org.apache.hadoop.hbase.master.RegionPlan) ServerName(org.apache.hadoop.hbase.ServerName)

Example 3 with RegionLoad

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

the class MergeTableRegionsProcedure method getRegionLoad.

private RegionLoad getRegionLoad(final MasterProcedureEnv env, final ServerName sn, final HRegionInfo hri) {
    ServerManager serverManager = env.getMasterServices().getServerManager();
    ServerLoad load = serverManager.getLoad(sn);
    if (load != null) {
        Map<byte[], RegionLoad> regionsLoad = load.getRegionsLoad();
        if (regionsLoad != null) {
            return regionsLoad.get(hri.getRegionName());
        }
    }
    return null;
}
Also used : ServerManager(org.apache.hadoop.hbase.master.ServerManager) ServerLoad(org.apache.hadoop.hbase.ServerLoad) RegionLoad(org.apache.hadoop.hbase.RegionLoad)

Example 4 with RegionLoad

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

the class StochasticLoadBalancer method updateRegionLoad.

/**
   * Store the current region loads.
   */
private synchronized void updateRegionLoad() {
    // We create a new hashmap so that regions that are no longer there are removed.
    // However we temporarily need the old loads so we can use them to keep the rolling average.
    Map<String, Deque<BalancerRegionLoad>> oldLoads = loads;
    loads = new HashMap<>();
    for (ServerName sn : clusterStatus.getServers()) {
        ServerLoad sl = clusterStatus.getLoad(sn);
        if (sl == null) {
            continue;
        }
        for (Entry<byte[], RegionLoad> entry : sl.getRegionsLoad().entrySet()) {
            Deque<BalancerRegionLoad> rLoads = oldLoads.get(Bytes.toString(entry.getKey()));
            if (rLoads == null) {
                // There was nothing there
                rLoads = new ArrayDeque<>();
            } else if (rLoads.size() >= numRegionLoadsToRemember) {
                rLoads.remove();
            }
            rLoads.add(new BalancerRegionLoad(entry.getValue()));
            loads.put(Bytes.toString(entry.getKey()), rLoads);
        }
    }
    for (CostFromRegionLoadFunction cost : regionLoadFunctions) {
        cost.setLoads(loads);
    }
}
Also used : ServerLoad(org.apache.hadoop.hbase.ServerLoad) RegionLoad(org.apache.hadoop.hbase.RegionLoad) ServerName(org.apache.hadoop.hbase.ServerName) Deque(java.util.Deque) ArrayDeque(java.util.ArrayDeque)

Example 5 with RegionLoad

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

the class RegionSizeCalculator method init.

private void init(RegionLocator regionLocator, Admin admin) throws IOException {
    if (!enabled(admin.getConfiguration())) {
        LOG.info("Region size calculation disabled.");
        return;
    }
    if (regionLocator.getName().isSystemTable()) {
        LOG.info("Region size calculation disabled for system tables.");
        return;
    }
    LOG.info("Calculating region sizes for table \"" + regionLocator.getName() + "\".");
    // Get the servers which host regions of the table
    Set<ServerName> tableServers = getRegionServersOfTable(regionLocator);
    for (ServerName tableServerName : tableServers) {
        Map<byte[], RegionLoad> regionLoads = admin.getRegionLoad(tableServerName, regionLocator.getName());
        for (RegionLoad regionLoad : regionLoads.values()) {
            byte[] regionId = regionLoad.getName();
            long regionSizeBytes = regionLoad.getStorefileSizeMB() * MEGABYTE;
            sizeMap.put(regionId, regionSizeBytes);
            if (LOG.isDebugEnabled()) {
                LOG.debug("Region " + regionLoad.getNameAsString() + " has size " + regionSizeBytes);
            }
        }
    }
    LOG.debug("Region sizes calculated");
}
Also used : RegionLoad(org.apache.hadoop.hbase.RegionLoad) ServerName(org.apache.hadoop.hbase.ServerName)

Aggregations

RegionLoad (org.apache.hadoop.hbase.RegionLoad)15 ServerName (org.apache.hadoop.hbase.ServerName)10 ServerLoad (org.apache.hadoop.hbase.ServerLoad)5 TreeMap (java.util.TreeMap)4 ClusterStatus (org.apache.hadoop.hbase.ClusterStatus)4 HRegionInfo (org.apache.hadoop.hbase.HRegionInfo)3 TableName (org.apache.hadoop.hbase.TableName)3 Map (java.util.Map)2 TableId (co.cask.cdap.data2.util.TableId)1 IOException (java.io.IOException)1 InterruptedIOException (java.io.InterruptedIOException)1 ArrayDeque (java.util.ArrayDeque)1 Deque (java.util.Deque)1 HashMap (java.util.HashMap)1 GET (javax.ws.rs.GET)1 Produces (javax.ws.rs.Produces)1 ResponseBuilder (javax.ws.rs.core.Response.ResponseBuilder)1 HTableDescriptor (org.apache.hadoop.hbase.HTableDescriptor)1 TableNotFoundException (org.apache.hadoop.hbase.TableNotFoundException)1 Admin (org.apache.hadoop.hbase.client.Admin)1