Search in sources :

Example 1 with DrServerInfo

use of io.datarouter.client.hbase.cluster.DrServerInfo in project datarouter by hotpads.

the class HBaseRegionBalancerJob method balanceClient.

// return true if completed balancing
private boolean balanceClient(TaskTracker tracker, ClientId clientId) {
    logger.warn("calculating region movements for client {}", clientId.getName());
    Admin admin = hBaseClientManager.getAdmin(clientId);
    List<HBaseRegionMovement> movements = new ArrayList<>();
    DrServerList serverList = new DrServerList(admin);
    List<String> tableNames = nodes.getTableNamesForClient(clientId.getName());
    Collections.sort(tableNames);
    int tableCounter = 0;
    for (String tableName : tableNames) {
        if (tracker.shouldStop()) {
            return false;
        }
        ++tableCounter;
        PhaseTimer timer = new PhaseTimer("generating movements for table " + tableName + " #" + tableCounter + "/" + tableNames.size());
        List<HBaseRegionMovement> tableMovements = new ArrayList<>();
        PhysicalNode<?, ?, ?> physicalNodeForTable = nodes.getPhysicalNodeForClientAndTable(clientId.getName(), tableName);
        BaseHBaseRegionBalancer balancer = balancerFactory.getBalancerForTable(clientId, tableName);
        DrRegionList regionList;
        try {
            regionList = drRegionListFactory.make(clientId, serverList, tableName, physicalNodeForTable, balancer);
        } catch (Exception e) {
            logger.error("skipping table " + tableName, e);
            continue;
        }
        for (DrRegionInfo<?> region : regionList.getRegions()) {
            if (region.isNotOnAnyServer()) {
                logger.warn("region {} is not currently hosted, so not attempting to move it", region.getRegion().getRegionNameAsString());
                continue;
            }
            if (region.isOnCorrectServer()) {
                continue;
            }
            HBaseRegionMovement movement = new HBaseRegionMovement(tableName, region.getRegion().getEncodedName(), region.getHBaseServerName(), region.getBalancerDestinationHBaseServerName());
            tableMovements.add(movement);
        }
        timer.add("generated " + tableMovements.size() + " movements");
        logger.warn(timer.toString());
        movements.addAll(tableMovements);
    }
    // we calculated all the movements.  now move them
    long iterationStartTimeMs = System.currentTimeMillis();
    Map<ServerName, List<HBaseRegionMovement>> movementsByCurrentServer = HBaseRegionMovement.getByCurrentServer(movements);
    int clusterMovementCounter = 0;
    logger.warn("processing {} total movements", movements.size());
    for (DrServerInfo serverInfo : serverList.getServersSortedByDescendingLoad()) {
        List<HBaseRegionMovement> movementsForServer = movementsByCurrentServer.getOrDefault(serverInfo.getServerName(), List.of());
        logger.warn("expecting {} movements for server {}", movementsForServer.size(), serverInfo.getServerName());
    }
    for (DrServerInfo serverInfo : serverList.getServersSortedByDescendingLoad()) {
        List<HBaseRegionMovement> movementsForServer = movementsByCurrentServer.getOrDefault(serverInfo.getServerName(), List.of());
        logger.warn("processing {} movements for server {}", movementsForServer.size(), serverInfo.getServerName());
        int serverMovementCounter = 0;
        for (HBaseRegionMovement movement : movementsForServer) {
            ++clusterMovementCounter;
            ++serverMovementCounter;
            logger.warn("moving region {}/{} ({}/{}): {}", serverMovementCounter, movementsForServer.size(), clusterMovementCounter, movements.size(), movement);
            try {
                admin.move(movement.getRegionNameBytes(), movement.getDestinationServerNameBytes());
            } catch (Exception ex) {
                // in 0.94, this is UndeclaredThrowableException wrapping other Exceptions
                logger.error("exception moving region, skipping", ex);
            }
            ThreadTool.sleepUnchecked(hbaseSettings.getSleepBetweenRegionMovementMs());
            if (tracker.increment().shouldStop()) {
                return false;
            }
            if (System.currentTimeMillis() - iterationStartTimeMs > RECALCULATE_AFTER_MS) {
                logger.warn("suspending to check for new servers", RECALCULATE_AFTER_MS);
                return false;
            }
        }
        logger.warn("processed {} movements for server {}", serverMovementCounter, serverInfo.getServerName());
    }
    return true;
}
Also used : DrServerInfo(io.datarouter.client.hbase.cluster.DrServerInfo) PhaseTimer(io.datarouter.util.timer.PhaseTimer) ArrayList(java.util.ArrayList) Admin(org.apache.hadoop.hbase.client.Admin) DrServerList(io.datarouter.client.hbase.cluster.DrServerList) DrRegionList(io.datarouter.client.hbase.cluster.DrRegionListFactory.DrRegionList) ServerName(org.apache.hadoop.hbase.ServerName) ArrayList(java.util.ArrayList) DrServerList(io.datarouter.client.hbase.cluster.DrServerList) List(java.util.List) DrRegionList(io.datarouter.client.hbase.cluster.DrRegionListFactory.DrRegionList)

Example 2 with DrServerInfo

use of io.datarouter.client.hbase.cluster.DrServerInfo in project datarouter by hotpads.

the class HBaseHandler method viewHBaseServers.

@Handler
public Mav viewHBaseServers() throws IOException {
    initialize();
    mav.setViewName(files.jsp.admin.datarouter.hbase.hbaseServersJsp);
    ClusterStatus clusterStatus = hBaseClientManager.getAdmin(datarouterWebRequestParams.getClientId()).getClusterStatus();
    mav.put("clusterStatus", clusterStatus);
    Collection<ServerName> serverNames = new TreeSet<>(clusterStatus.getServers());
    List<DrServerInfo> servers = new ArrayList<>();
    for (ServerName serverName : serverNames) {
        ServerLoad serverLoad = clusterStatus.getLoad(serverName);
        servers.add(new DrServerInfo(serverName, serverLoad));
    }
    mav.put("servers", servers);
    return mav;
}
Also used : DrServerInfo(io.datarouter.client.hbase.cluster.DrServerInfo) ServerLoad(org.apache.hadoop.hbase.ServerLoad) TreeSet(java.util.TreeSet) ServerName(org.apache.hadoop.hbase.ServerName) ArrayList(java.util.ArrayList) ClusterStatus(org.apache.hadoop.hbase.ClusterStatus) BaseHandler(io.datarouter.web.handler.BaseHandler)

Example 3 with DrServerInfo

use of io.datarouter.client.hbase.cluster.DrServerInfo in project datarouter by hotpads.

the class ConsistentHashBalancer method buildServerHashRing.

public static SortedMap<Long, ServerName> buildServerHashRing(DrServerList servers, int numBucketsPerNode) {
    SortedMap<Long, ServerName> consistentHashRing = new TreeMap<>();
    for (DrServerInfo server : servers.getServers()) {
        for (int i = 0; i < numBucketsPerNode; ++i) {
            long bucketPosition = HashMethods.longMd5DjbHash(server.getServerName().getHostAndPort() + i);
            consistentHashRing.put(bucketPosition, server.getServerName());
        }
    }
    return consistentHashRing;
}
Also used : DrServerInfo(io.datarouter.client.hbase.cluster.DrServerInfo) ServerName(org.apache.hadoop.hbase.ServerName) TreeMap(java.util.TreeMap)

Aggregations

DrServerInfo (io.datarouter.client.hbase.cluster.DrServerInfo)3 ServerName (org.apache.hadoop.hbase.ServerName)3 ArrayList (java.util.ArrayList)2 DrRegionList (io.datarouter.client.hbase.cluster.DrRegionListFactory.DrRegionList)1 DrServerList (io.datarouter.client.hbase.cluster.DrServerList)1 PhaseTimer (io.datarouter.util.timer.PhaseTimer)1 BaseHandler (io.datarouter.web.handler.BaseHandler)1 List (java.util.List)1 TreeMap (java.util.TreeMap)1 TreeSet (java.util.TreeSet)1 ClusterStatus (org.apache.hadoop.hbase.ClusterStatus)1 ServerLoad (org.apache.hadoop.hbase.ServerLoad)1 Admin (org.apache.hadoop.hbase.client.Admin)1