Skip to content

Commit 95ecd22

Browse files
committed
add edge case for models that are marked as not found in cache
There is a code change that requires to check the response of the model undeploy response object to check that the model has been marked as not found on all nodes Signed-off-by: Brian Flores <iflorbri@amazon.com>
1 parent 68ceab3 commit 95ecd22

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

plugin/src/main/java/org/opensearch/ml/action/undeploy/TransportUndeployModelsAction.java

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,12 @@
66
package org.opensearch.ml.action.undeploy;
77

88
import static org.opensearch.ml.common.CommonValue.ML_MODEL_INDEX;
9+
import static org.opensearch.ml.common.CommonValue.NOT_FOUND;
910

1011
import java.time.Instant;
1112
import java.util.Arrays;
1213
import java.util.List;
14+
import java.util.Map;
1315
import java.util.stream.Collectors;
1416

1517
import org.opensearch.ExceptionsHelper;
@@ -198,7 +200,17 @@ private void undeployModels(
198200
* Having this change enables a check that this edge case occurs along with having access to the model id
199201
* allowing us to update the stale model index correctly to `UNDEPLOYED` since no nodes service the model.
200202
*/
201-
if (response.getNodes().isEmpty()) {
203+
boolean modelNotFoundInNodesCache = response.getNodes().stream().allMatch(nodeResponse -> {
204+
Map<String, String> status = nodeResponse.getModelUndeployStatus();
205+
if (status == null) return false;
206+
boolean modelCacheMissForModelIds = Arrays.stream(modelIds).allMatch(modelId -> {
207+
String modelStatus = status.get(modelId);
208+
return modelStatus != null && modelStatus.equalsIgnoreCase(NOT_FOUND);
209+
});
210+
211+
return modelCacheMissForModelIds;
212+
} );
213+
if (response.getNodes().isEmpty() || modelNotFoundInNodesCache) {
202214
bulkSetModelIndexToUndeploy(modelIds, listener, response);
203215
return;
204216
}

0 commit comments

Comments
 (0)