Source:
<code>public DruidCoordinatorRuntimeParams run(DruidCoordinatorRuntimeParams params) { int startingLeaderGen = coordinator.getLeaderGeneration(); CoordinatorStats stats = new CoordinatorStats(); DruidCluster cluster = params.getDruidCluster(); if (cluster.isEmpty()) { log.warn("Uh... I have no servers. Not assigning anything..."); return params; } for (String tier : cluster.getTierNames()) { replicatorThrottler.updateReplicationState(tier); replicatorThrottler.updateTerminationState(tier); } DruidCoordinatorRuntimeParams paramsWithReplicationManager = params.buildFromExisting() .withReplicationManager(replicatorThrottler) .build(); DateTime now = new DateTime(); DatabaseRuleManager databaseRuleManager = paramsWithReplicationManager.getDatabaseRuleManager(); for (DataSegment segment : paramsWithReplicationManager.getAvailableSegments()) { List<Rule> rules = databaseRuleManager.getRulesWithDefault(segment.getDataSource()); boolean foundMatchingRule = false; for (Rule rule : rules) { if (rule.appliesTo(segment, now)) { <START> if (coordinator.getLeaderGeneration() == startingLeaderGen) { <END> stats.accumulate(rule.run(coordinator, paramsWithReplicationManager, segment)); } foundMatchingRule = true; break; } } if (!foundMatchingRule) { log.makeAlert( "Unable to find a matching rule for dataSource[%s]", segment.getDataSource() ) .addData("segment", segment.getIdentifier()) .emit(); } } return paramsWithReplicationManager.buildFromExisting() .withCoordinatorStats(stats) .build(); }</code><technical_language>I this'll fix stuff, foundMatchingRule end false alerts get triggered. bail out do if leader generation is wrongy. startingLeaderGen set commencing running of runnables, if a race here. runnables start in general, leadership switch off/on, this runnable run realize is part of aborted leadership run</technical_language>

Target:
public DruidCoordinatorRuntimeParams run(DruidCoordinatorRuntimeParams params) { CoordinatorStats stats = new CoordinatorStats(); DruidCluster cluster = params.getDruidCluster(); if (cluster.isEmpty()) { log.warn("Uh... I have no servers. Not assigning anything..."); return params; } for (String tier : cluster.getTierNames()) { replicatorThrottler.updateReplicationState(tier); replicatorThrottler.updateTerminationState(tier); } DruidCoordinatorRuntimeParams paramsWithReplicationManager = params.buildFromExisting() .withReplicationManager(replicatorThrottler) .build(); DateTime now = new DateTime(); DatabaseRuleManager databaseRuleManager = paramsWithReplicationManager.getDatabaseRuleManager(); for (DataSegment segment : paramsWithReplicationManager.getAvailableSegments()) { List<Rule> rules = databaseRuleManager.getRulesWithDefault(segment.getDataSource()); if (!coordinator.isValidRun()) { throw new ISE("Leader change occurred during rule run. Bailing out."); } boolean foundMatchingRule = false; for (Rule rule : rules) { if (rule.appliesTo(segment, now)) { stats.accumulate(rule.run(coordinator, paramsWithReplicationManager, segment)); foundMatchingRule = true; break; } } if (!foundMatchingRule) { log.makeAlert( "Unable to find a matching rule for dataSource[%s]", segment.getDataSource() ) .addData("segment", segment.getIdentifier()) .emit(); } } return paramsWithReplicationManager.buildFromExisting() .withCoordinatorStats(stats) .build(); }