Source:
public void run() { ListeningExecutorService balancerExec = null; try { synchronized (lock) { if (!coordLeaderSelector.isLeader()) { log.info("LEGGO MY EGGO. [%s] is leader.", coordLeaderSelector.getCurrentLeader()); stopBeingLeader(); return; } } List<Boolean> allStarted = Arrays.asList( segmentsMetadata.isPollingDatabasePeriodically(), serverInventoryView.isStarted() ); for (Boolean aBoolean : allStarted) { if (!aBoolean) { log.error("InventoryManagers not started[%s]", allStarted); stopBeingLeader(); return; } } balancerExec = MoreExecutors.listeningDecorator(Execs.multiThreaded( getDynamicConfigs().getBalancerComputeThreads(), "coordinator-cost-balancer-%s" )); BalancerStrategy balancerStrategy = factory.createBalancerStrategy(balancerExec); DataSourcesSnapshot dataSourcesSnapshot = segmentsMetadata.getSnapshotOfDataSourcesWithAllUsedSegments(); DruidCoordinatorRuntimeParams params = DruidCoordinatorRuntimeParams .newBuilder() .withDatabaseRuleManager(metadataRuleManager) .withStartTimeNanos(startTimeNanos) .withSnapshotOfDataSourcesWithAllUsedSegments(dataSourcesSnapshot) .withDynamicConfigs(getDynamicConfigs()) .withCompactionConfig(getCompactionConfig()) .withEmitter(emitter) .withBalancerStrategy(balancerStrategy) .build(); for (CoordinatorDuty duty : duties) { if (coordLeaderSelector.isLeader() && startingLeaderCounter == coordLeaderSelector.localTerm()) { params = duty.run(params); if (params == null) { return; } } } } catch (Exception e) { log.makeAlert(e, "Caught exception, ignoring so that schedule keeps going.").emit(); } finally { if (balancerExec != null) { balancerExec.shutdownNow(); } } }

Target:
public void run() { ListeningExecutorService balancerExec = null; try { synchronized (lock) { if (!coordLeaderSelector.isLeader()) { log.info("LEGGO MY EGGO. [%s] is leader.", coordLeaderSelector.getCurrentLeader()); stopBeingLeader(); return; } } List<Boolean> allStarted = Arrays.asList( segmentsMetadataManager.isPollingDatabasePeriodically(), serverInventoryView.isStarted() ); for (Boolean aBoolean : allStarted) { if (!aBoolean) { log.error("InventoryManagers not started[%s]", allStarted); stopBeingLeader(); return; } } balancerExec = MoreExecutors.listeningDecorator(Execs.multiThreaded( getDynamicConfigs().getBalancerComputeThreads(), "coordinator-cost-balancer-%s" )); BalancerStrategy balancerStrategy = factory.createBalancerStrategy(balancerExec); DataSourcesSnapshot dataSourcesSnapshot = segmentsMetadataManager.getSnapshotOfDataSourcesWithAllUsedSegments(); DruidCoordinatorRuntimeParams params = DruidCoordinatorRuntimeParams .newBuilder() .withDatabaseRuleManager(metadataRuleManager) .withStartTimeNanos(startTimeNanos) .withSnapshotOfDataSourcesWithAllUsedSegments(dataSourcesSnapshot) .withDynamicConfigs(getDynamicConfigs()) .withCompactionConfig(getCompactionConfig()) .withEmitter(emitter) .withBalancerStrategy(balancerStrategy) .build(); for (CoordinatorDuty duty : duties) { if (coordLeaderSelector.isLeader() && startingLeaderCounter == coordLeaderSelector.localTerm()) { params = duty.run(params); if (params == null) { return; } } } } catch (Exception e) { log.makeAlert(e, "Caught exception, ignoring so that schedule keeps going.").emit(); } finally { if (balancerExec != null) { balancerExec.shutdownNow(); } } }