Source:
<code>protected void processEvent(ClusterEvent event, ResourcesStateMap resourcesStateMap) throws Exception { _eventId = event.getEventId(); HelixManager manager = event.getAttribute(AttributeName.helixmanager.name()); BaseControllerDataProvider cache = event.getAttribute(AttributeName.ControllerDataProvider.name()); Map<String, Resource> resourceMap = event.getAttribute(AttributeName.RESOURCES_TO_REBALANCE.name()); CurrentStateOutput currentStateOutput = event.getAttribute(AttributeName.CURRENT_STATE.name()); <START> Map<String, Map<String, Message>> pendingMessagesToCleanUp = new HashMap<>(); <END> if (manager == null || cache == null || resourceMap == null || currentStateOutput == null || resourcesStateMap == null) { throw new StageException("Missing attributes in event:" + event + ". Requires HelixManager|DataCache|RESOURCES|CURRENT_STATE|INTERMEDIATE_STATE"); } Map<String, LiveInstance> liveInstances = cache.getLiveInstances(); Map<String, String> sessionIdMap = new HashMap<>(); for (LiveInstance liveInstance : liveInstances.values()) { sessionIdMap.put(liveInstance.getInstanceName(), liveInstance.getEphemeralOwner()); } MessageOutput output = new MessageOutput(); for (Resource resource : resourceMap.values()) { try { generateMessage(resource, cache, resourcesStateMap, currentStateOutput, manager, sessionIdMap, event.getEventType(), output, pendingMessagesToCleanUp); } catch (HelixException ex) { LogUtil.logError(logger, _eventId, "Failed to generate message for resource " + resource.getResourceName(), ex); } } if (!pendingMessagesToCleanUp.isEmpty()) { schedulePendingMessageCleanUp(pendingMessagesToCleanUp, cache.getAsyncTasksThreadPool(), manager.getHelixDataAccessor(), currentStateOutput.getStaleMessageMap()); } event.addAttribute(AttributeName.MESSAGES_ALL.name(), output); }</code><technical_language>Takes a while figure out. call messagesToCleanup now, right</technical_language>

Target:
protected void processEvent(ClusterEvent event, ResourcesStateMap resourcesStateMap) throws Exception { _eventId = event.getEventId(); HelixManager manager = event.getAttribute(AttributeName.helixmanager.name()); BaseControllerDataProvider cache = event.getAttribute(AttributeName.ControllerDataProvider.name()); Map<String, Resource> resourceMap = event.getAttribute(AttributeName.RESOURCES_TO_REBALANCE.name()); CurrentStateOutput currentStateOutput = event.getAttribute(AttributeName.CURRENT_STATE.name()); Map<String, Map<String, Message>> messagesToCleanUp = new HashMap<>(); if (manager == null || cache == null || resourceMap == null || currentStateOutput == null || resourcesStateMap == null) { throw new StageException("Missing attributes in event:" + event + ". Requires HelixManager|DataCache|RESOURCES|CURRENT_STATE|INTERMEDIATE_STATE"); } Map<String, LiveInstance> liveInstances = cache.getLiveInstances(); Map<String, String> sessionIdMap = new HashMap<>(); for (LiveInstance liveInstance : liveInstances.values()) { sessionIdMap.put(liveInstance.getInstanceName(), liveInstance.getEphemeralOwner()); } MessageOutput output = new MessageOutput(); for (Resource resource : resourceMap.values()) { try { generateMessage(resource, cache, resourcesStateMap, currentStateOutput, manager, sessionIdMap, event.getEventType(), output, messagesToCleanUp); } catch (HelixException ex) { LogUtil.logError(logger, _eventId, "Failed to generate message for resource " + resource.getResourceName(), ex); } } if (!messagesToCleanUp.isEmpty()) { schedulePendingMessageCleanUp(messagesToCleanUp, cache.getAsyncTasksThreadPool(), manager.getHelixDataAccessor()); } event.addAttribute(AttributeName.MESSAGES_ALL.name(), output); }