Source:
private void handleLeaderDoAssignment() { boolean succeeded = true; List<String> liveInstances = Collections.emptyList(); Map<String, Set<DatastreamTask>> previousAssignmentByInstance = Collections.emptyMap(); Map<String, List<DatastreamTask>> newAssignmentsByInstance = Collections.emptyMap(); try { List<DatastreamGroup> datastreamGroups = fetchDatastreamGroups(); _log.debug("handleLeaderDoAssignment: final datastreams for task assignment: {}", datastreamGroups); liveInstances = _adapter.getLiveInstances(); previousAssignmentByInstance = _adapter.getAllAssignedDatastreamTasks(); newAssignmentsByInstance = performAssignment(liveInstances, previousAssignmentByInstance, datastreamGroups); _adapter.updateAllAssignments(newAssignmentsByInstance); } catch (RuntimeException e) { _log.error("handleLeaderDoAssignment: runtime Exception while updating Zookeeper.", e); succeeded = false; } _log.info("handleLeaderDoAssignment: new assignment: " + newAssignmentsByInstance); if (succeeded) { List<String> instances = new ArrayList<>(liveInstances); instances.add(PAUSED_INSTANCE); _adapter.cleanupDeadInstanceAssignments(instances); _adapter.cleanupOldUnusedTasks(previousAssignmentByInstance, newAssignmentsByInstance); _dynamicMetricsManager.createOrUpdateMeter(MODULE, NUM_REBALANCES, 1); } if (!succeeded && !leaderDoAssignmentScheduled.get()) { _log.info("Schedule retry for leader assigning tasks"); _dynamicMetricsManager.createOrUpdateMeter(MODULE, "handleLeaderDoAssignment", NUM_RETRIES, 1); leaderDoAssignmentScheduled.set(true); _executor.schedule(() -> { _eventQueue.put(CoordinatorEvent.createLeaderDoAssignmentEvent()); leaderDoAssignmentScheduled.set(false); }, _config.getRetryIntervalMs(), TimeUnit.MILLISECONDS); } }

Target:
private void handleLeaderDoAssignment() { boolean succeeded = true; List<String> liveInstances = Collections.emptyList(); Map<String, Set<DatastreamTask>> previousAssignmentByInstance = Collections.emptyMap(); Map<String, List<DatastreamTask>> newAssignmentsByInstance = Collections.emptyMap(); try { List<DatastreamGroup> datastreamGroups = fetchDatastreamGroups(); _log.debug("handleLeaderDoAssignment: final datastreams for task assignment: {}", datastreamGroups); liveInstances = _adapter.getLiveInstances(); previousAssignmentByInstance = _adapter.getAllAssignedDatastreamTasks(); newAssignmentsByInstance = performAssignment(liveInstances, previousAssignmentByInstance, datastreamGroups); _adapter.updateAllAssignments(newAssignmentsByInstance); } catch (RuntimeException e) { _log.error("handleLeaderDoAssignment: runtime exception.", e); succeeded = false; } _log.info("handleLeaderDoAssignment: new assignment: " + newAssignmentsByInstance); if (succeeded) { List<String> instances = new ArrayList<>(liveInstances); instances.add(PAUSED_INSTANCE); _adapter.cleanupDeadInstanceAssignments(instances); _adapter.cleanupOldUnusedTasks(previousAssignmentByInstance, newAssignmentsByInstance); _dynamicMetricsManager.createOrUpdateMeter(MODULE, NUM_REBALANCES, 1); } if (!succeeded && !leaderDoAssignmentScheduled.get()) { _log.info("Schedule retry for leader assigning tasks"); _dynamicMetricsManager.createOrUpdateMeter(MODULE, "handleLeaderDoAssignment", NUM_RETRIES, 1); leaderDoAssignmentScheduled.set(true); _executor.schedule(() -> { _eventQueue.put(CoordinatorEvent.createLeaderDoAssignmentEvent()); leaderDoAssignmentScheduled.set(false); }, _config.getRetryIntervalMs(), TimeUnit.MILLISECONDS); } }