leventov commented on a change in pull request #6349: maintenance mode for Historical URL: https://github.com/apache/incubator-druid/pull/6349#discussion_r221367120
########## File path: server/src/main/java/org/apache/druid/server/coordinator/helper/DruidCoordinatorBalancer.java ########## @@ -106,35 +104,76 @@ private void balanceTier( return; } - final List<ServerHolder> toMoveFrom = Lists.newArrayList(servers); - final List<ServerHolder> toMoveTo = Lists.newArrayList(servers); + Map<Boolean, List<ServerHolder>> partitions = servers.stream() + .collect(Collectors.partitioningBy(ServerHolder::isMaintenance)); + final List<ServerHolder> maintenance = partitions.get(true); + final List<ServerHolder> general = partitions.get(false); + log.info("Found %d servers in maintenance, %d general servers", maintenance.size(), general.size()); - if (toMoveTo.size() <= 1) { - log.info("[%s]: One or fewer servers found. Cannot balance.", tier); + if (general.size() == 0) { + log.info("[%s]: 0 general servers found. Cannot balance.", tier); return; } int numSegments = 0; - for (ServerHolder sourceHolder : toMoveFrom) { + for (ServerHolder sourceHolder : servers) { numSegments += sourceHolder.getServer().getSegments().size(); } - if (numSegments == 0) { log.info("No segments found. Cannot balance."); return; } - final BalancerStrategy strategy = params.getBalancerStrategy(); final int maxSegmentsToMove = Math.min(params.getCoordinatorDynamicConfig().getMaxSegmentsToMove(), numSegments); + int priority = params.getCoordinatorDynamicConfig().getMaintenanceModeSegmentsPriority(); + int maintenanceSegmentsToMove = (int) Math.ceil(maxSegmentsToMove * priority / 10.0); + log.info("Balancing %d segments for servers in maintenance mode", maintenanceSegmentsToMove); + Pair<Integer, Integer> maintenanceResult = balanceServers(params, maintenance, general, maintenanceSegmentsToMove); + int generalSegmentsToMove = maxSegmentsToMove - maintenanceResult.lhs; + log.info("Balancing %d segments for servers in general mode", generalSegmentsToMove); + Pair<Integer, Integer> generalResult = balanceServers(params, general, general, generalSegmentsToMove); + Pair<Integer, Integer> result = new Pair( + generalResult.lhs + maintenanceResult.lhs, + generalResult.rhs + maintenanceResult.rhs + ); + + int moved = result.lhs; + int unmoved = result.rhs; + if (unmoved == maxSegmentsToMove) { + // Cluster should be alive and constantly adjusting + log.info("No good moves found in tier [%s]", tier); + } + stats.addToTieredStat("unmovedCount", tier, unmoved); + stats.addToTieredStat("movedCount", tier, moved); + + if (params.getCoordinatorDynamicConfig().emitBalancingStats()) { + final BalancerStrategy strategy = params.getBalancerStrategy(); + strategy.emitStats(tier, stats, Lists.newArrayList(servers)); Review comment: The question is rather, should it still be based on `servers`, as well as prior to your PR? Not on `general`? ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: us...@infra.apache.org With regards, Apache Git Services --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@druid.apache.org For additional commands, e-mail: commits-h...@druid.apache.org