Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -276,9 +276,17 @@ public Map<String, IdealState> computeNewIdealStates(ResourceControllerDataProvi
// the target assignment.
newIdealStates.values().parallelStream().forEach(idealState -> {
String resourceName = idealState.getResourceName();
Resource resource = resourceMap.get(resourceName);
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you share with me the path where we are getting assignments, because I see in AssignmentManager.getBestPossibleAssignment(), we are filtering keys not in resource map ?

Also, can we add filtering while creating/getting cached assignments, that way we can even update the assignments and may avoid NPE elsewhere.


// This can happen when a resource is deleted but still exists in cached assignment
if (resource == null) {
LOG.warn("Resource {} not found in current resourceMap. Skipping ideal state calculation.", resourceName);
return;
}

// Adjust the states according to the current state.
ResourceAssignment finalAssignment = _mappingCalculator
.computeBestPossiblePartitionState(clusterData, idealState, resourceMap.get(resourceName),
.computeBestPossiblePartitionState(clusterData, idealState, resource,
currentStateOutput);

// Clean up the state mapping fields. Use the final assignment that is calculated by the
Expand All @@ -291,6 +299,17 @@ public Map<String, IdealState> computeNewIdealStates(ResourceControllerDataProvi
newStateMap == null ? Collections.emptyMap() : newStateMap);
}
});

// Remove any resources from newIdealStates that don't exist in the current resourceMap
// This ensures we don't return stale IdealStates for deleted resources
newIdealStates.keySet().removeIf(resourceName -> {
if (!resourceMap.containsKey(resourceName)) {
LOG.warn("Removing stale resource {} from ideal states as it no longer exists in cluster.", resourceName);
return true;
}
return false;
});

LOG.info("Finish computing new ideal states for resources: {}",
resourceMap.keySet().toString());
return newIdealStates;
Expand Down
Loading