Source:
private void handleLeaderDoAssignment(boolean cleanUpOrphanConnectorTasks) { 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(); onDatastreamChange(datastreamGroups); _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: completed "); _log.debug("handleLeaderDoAssignment: new assignment: " + newAssignmentsByInstance); if (succeeded) { List<String> instances = new ArrayList<>(liveInstances); instances.add(PAUSED_INSTANCE); _adapter.cleanUpDeadInstanceDataAndOtherUnusedTasks(previousAssignmentByInstance, newAssignmentsByInstance, instances); if (cleanUpOrphanConnectorTasks) { performCleanUpOrphanConnectorTasks(); } _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(cleanUpOrphanConnectorTasks)); leaderDoAssignmentScheduled.set(false); }, _config.getRetryIntervalMs(), TimeUnit.MILLISECONDS); } }

Target:
private void handleLeaderDoAssignment(boolean cleanUpOrphanConnectorTasks) { 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(); onDatastreamChange(datastreamGroups); _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: completed "); _log.debug("handleLeaderDoAssignment: new assignment: " + newAssignmentsByInstance); if (succeeded) { List<String> instances = new ArrayList<>(liveInstances); instances.add(PAUSED_INSTANCE); _adapter.cleanUpDeadInstanceDataAndOtherUnusedTasks(previousAssignmentByInstance, newAssignmentsByInstance, instances); if (cleanUpOrphanConnectorTasks) { performCleanupOrphanConnectorTasks(); } _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(cleanUpOrphanConnectorTasks)); leaderDoAssignmentScheduled.set(false); }, _config.getRetryIntervalMs(), TimeUnit.MILLISECONDS); } }