Search in sources :

Example 1 with PhaseTimer

use of io.datarouter.util.timer.PhaseTimer in project datarouter by hotpads.

the class HBaseHandler method moveRegionsToCorrectServer.

/*---------------------------- move handlers ----------------------------*/
@Handler
public Mav moveRegionsToCorrectServer(OptionalInteger pauseBetweenRegionsMs) throws IOException {
    initialize();
    int counter = 0;
    for (DrRegionInfo<?> region : regionList.get().getRegions()) {
        if (!region.isOnCorrectServer()) {
            ++counter;
            PhaseTimer timer = new PhaseTimer("move " + counter + " of " + datarouterWebRequestParams.getTableName());
            String encodedRegionNameString = region.getRegion().getEncodedName();
            String destinationServer = region.getConsistentHashServerName().getServerName();
            hBaseClientManager.getAdmin(datarouterWebRequestParams.getClientId()).move(Bytes.toBytes(encodedRegionNameString), Bytes.toBytes(destinationServer));
            logger.warn(timer.add("HBase moved region " + encodedRegionNameString + " to server " + destinationServer).toString());
        }
        ThreadTool.sleepUnchecked(pauseBetweenRegionsMs.orElse(500));
    }
    // mav.put("message-update", "HBase regions moved to correct server");
    return new MessageMav("HBase regions moved to correct server");
}
Also used : MessageMav(io.datarouter.web.handler.mav.imp.MessageMav) PhaseTimer(io.datarouter.util.timer.PhaseTimer) OptionalString(io.datarouter.web.handler.types.optional.OptionalString) BaseHandler(io.datarouter.web.handler.BaseHandler)

Example 2 with PhaseTimer

use of io.datarouter.util.timer.PhaseTimer 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 3 with PhaseTimer

use of io.datarouter.util.timer.PhaseTimer in project datarouter by hotpads.

the class HBaseCompactionJob method compactRegion.

private void compactRegion(Admin admin, DrRegionInfo<?> region, LongAdder numRegionsTriggeredInTable) {
    numTriggered.increment();
    numRegionsTriggeredInTable.increment();
    PhaseTimer timer = new PhaseTimer("compact " + numRegionsTriggeredInTable + " of " + region.getTableName());
    String encodedRegionNameString = region.getRegion().getEncodedName();
    try {
        admin.majorCompactRegion(region.getRegion().getRegionName());
        Object startKey = region.getStartKeyString();
        // trailing space because expected for formating in timer.toString
        String timerMessage = String.format("major_compact server=%s table=%s region=%s startKey=%s ", region.getServerName(), region.getTableName(), encodedRegionNameString, startKey);
        timer.add(timerMessage);
        logger.warn(timer.toString());
    } catch (Exception e) {
        logger.warn("failed to compact region:{} because of:", encodedRegionNameString, e);
    }
}
Also used : PhaseTimer(io.datarouter.util.timer.PhaseTimer)

Example 4 with PhaseTimer

use of io.datarouter.util.timer.PhaseTimer in project datarouter by hotpads.

the class MultiServletContextListener method contextInitialized.

@Override
public void contextInitialized(ServletContextEvent sce) {
    Counters.inc("bootstrap");
    Counters.inc("bootstrap start");
    PhaseTimer timer = new PhaseTimer();
    listeners.forEach(listener -> {
        listener.contextInitialized(sce);
        timer.add(listener.getClass().getSimpleName());
    });
    logger.warn("startUp {}", timer);
    Counters.inc("bootstrap end");
}
Also used : PhaseTimer(io.datarouter.util.timer.PhaseTimer)

Example 5 with PhaseTimer

use of io.datarouter.util.timer.PhaseTimer in project datarouter by hotpads.

the class SnapshotBenchmark method execute.

public RootBlock execute() {
    var timer = new PhaseTimer("writeSnapshot");
    SnapshotWriteResult result = makeEntryScanner(scannerExec, numInputThreads).apply(entries -> group.writeOps().write(makeSnapshotWriterConfig(), entries, writerExec, () -> false));
    snapshotKey = result.key;
    timer.add("wrote " + NumberFormatter.addCommas(result.optRoot.get().numItems()));
    logger.warn("{} @{}/s", timer, NumberFormatter.addCommas(timer.getItemsPerSecond(numEntries)));
    return result.optRoot.get();
}
Also used : PhaseTimer(io.datarouter.util.timer.PhaseTimer) SnapshotWriteResult(io.datarouter.filesystem.snapshot.group.dto.SnapshotWriteResult)

Aggregations

PhaseTimer (io.datarouter.util.timer.PhaseTimer)41 List (java.util.List)9 ExecutorService (java.util.concurrent.ExecutorService)9 AtomicLong (java.util.concurrent.atomic.AtomicLong)8 SnapshotWriteResult (io.datarouter.filesystem.snapshot.group.dto.SnapshotWriteResult)7 Scanner (io.datarouter.scanner.Scanner)7 Logger (org.slf4j.Logger)7 LoggerFactory (org.slf4j.LoggerFactory)7 ParallelScannerContext (io.datarouter.scanner.ParallelScannerContext)6 SnapshotRecord (io.datarouter.filesystem.snapshot.reader.record.SnapshotRecord)5 SnapshotWriterConfig (io.datarouter.filesystem.snapshot.writer.SnapshotWriterConfig)5 BaseHandler (io.datarouter.web.handler.BaseHandler)5 ArrayList (java.util.ArrayList)5 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)5 Test (org.testng.annotations.Test)5 NumberFormatter (io.datarouter.util.number.NumberFormatter)4 OptionalString (io.datarouter.web.handler.types.optional.OptionalString)4 Inject (javax.inject.Inject)4 ByteTool (io.datarouter.bytes.ByteTool)3 DatarouterFilesystemModuleFactory (io.datarouter.filesystem.DatarouterFilesystemModuleFactory)3