-
Notifications
You must be signed in to change notification settings - Fork 143
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
avoid race condition in syncup model state refresh and handle NP of I… #2405
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,6 +9,7 @@ | |
import static org.opensearch.ml.common.CommonValue.MASTER_KEY; | ||
import static org.opensearch.ml.common.CommonValue.ML_CONFIG_INDEX; | ||
import static org.opensearch.ml.common.CommonValue.ML_MODEL_INDEX; | ||
import static org.opensearch.ml.utils.RestActionUtils.getAllNodes; | ||
|
||
import java.time.Instant; | ||
import java.util.ArrayList; | ||
|
@@ -41,8 +42,9 @@ | |
import org.opensearch.ml.common.transport.sync.MLSyncUpInput; | ||
import org.opensearch.ml.common.transport.sync.MLSyncUpNodeResponse; | ||
import org.opensearch.ml.common.transport.sync.MLSyncUpNodesRequest; | ||
import org.opensearch.ml.common.transport.undeploy.MLUndeployModelAction; | ||
import org.opensearch.ml.common.transport.undeploy.MLUndeployModelNodesRequest; | ||
import org.opensearch.ml.common.transport.undeploy.MLUndeployModelNodesResponse; | ||
import org.opensearch.ml.common.transport.undeploy.MLUndeployModelsAction; | ||
import org.opensearch.ml.common.transport.undeploy.MLUndeployModelsRequest; | ||
import org.opensearch.ml.engine.encryptor.Encryptor; | ||
import org.opensearch.ml.engine.indices.MLIndicesHandler; | ||
import org.opensearch.search.SearchHit; | ||
|
@@ -97,6 +99,9 @@ public void run() { | |
// gather running model/tasks on nodes | ||
client.execute(MLSyncUpAction.INSTANCE, gatherInfoRequest, ActionListener.wrap(r -> { | ||
List<MLSyncUpNodeResponse> responses = r.getNodes(); | ||
if (r.failures() != null && r.failures().size() != 0) { | ||
log.debug("Received {} failures in the sync up response on nodes", r.failures().size()); | ||
} | ||
// key is model id, value is set of worker node ids | ||
Map<String, Set<String>> modelWorkerNodes = new HashMap<>(); | ||
// key is task id, value is set of worker node ids | ||
|
@@ -143,7 +148,6 @@ public void run() { | |
if (modelWorkerNodes.containsKey(modelId) | ||
&& expiredModelToNodes.get(modelId).size() == modelWorkerNodes.get(modelId).size()) { | ||
// this model has expired in all the nodes | ||
modelWorkerNodes.remove(modelId); | ||
modelsToUndeploy.add(modelId); | ||
} | ||
} | ||
|
@@ -168,37 +172,44 @@ public void run() { | |
MLSyncUpInput syncUpInput = inputBuilder.build(); | ||
MLSyncUpNodesRequest syncUpRequest = new MLSyncUpNodesRequest(allNodes, syncUpInput); | ||
// sync up running model/tasks on nodes | ||
client | ||
.execute( | ||
MLSyncUpAction.INSTANCE, | ||
syncUpRequest, | ||
ActionListener.wrap(re -> { log.debug("sync model routing job finished"); }, ex -> { | ||
log.error("Failed to sync model routing", ex); | ||
}) | ||
); | ||
// Undeploy expired models | ||
undeployExpiredModels(modelsToUndeploy, modelWorkerNodes); | ||
client.execute(MLSyncUpAction.INSTANCE, syncUpRequest, ActionListener.wrap(re -> { | ||
log.debug("sync model routing job finished"); | ||
if (!modelsToUndeploy.isEmpty()) { | ||
// Undeploy expired models | ||
undeployExpiredModels(modelsToUndeploy, modelWorkerNodes, deployingModels); | ||
return; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why return here ? If we have 10 models, There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The refreshModelState is called in the listener of unDeployModels after the expired models are un-deployed. Check the undeployExpiredModels(), So the modelstate will be refreshed anyways. |
||
} | ||
// refresh model status | ||
mlIndicesHandler | ||
.initModelIndexIfAbsent(ActionListener.wrap(res -> { refreshModelState(modelWorkerNodes, deployingModels); }, e -> { | ||
log.error("Failed to init model index", e); | ||
})); | ||
}, ex -> { log.error("Failed to sync model routing", ex); })); | ||
}, e -> { log.error("Failed to sync model routing", e); })); | ||
} | ||
|
||
private void undeployExpiredModels( | ||
Set<String> expiredModels, | ||
Map<String, Set<String>> modelWorkerNodes, | ||
Map<String, Set<String>> deployingModels | ||
) { | ||
String[] targetNodeIds = getAllNodes(clusterService); | ||
MLUndeployModelsRequest mlUndeployModelsRequest = new MLUndeployModelsRequest( | ||
expiredModels.toArray(new String[expiredModels.size()]), | ||
targetNodeIds | ||
); | ||
|
||
client.execute(MLUndeployModelsAction.INSTANCE, mlUndeployModelsRequest, ActionListener.wrap(r -> { | ||
MLUndeployModelNodesResponse mlUndeployModelNodesResponse = r.getResponse(); | ||
if (mlUndeployModelNodesResponse.failures() != null && mlUndeployModelNodesResponse.failures().size() != 0) { | ||
log.debug("Received failures in undeploying expired models", mlUndeployModelNodesResponse.failures()); | ||
} | ||
|
||
// refresh model status | ||
mlIndicesHandler | ||
.initModelIndexIfAbsent(ActionListener.wrap(res -> { refreshModelState(modelWorkerNodes, deployingModels); }, e -> { | ||
log.error("Failed to init model index", e); | ||
})); | ||
}, e -> { log.error("Failed to sync model routing", e); })); | ||
} | ||
|
||
private void undeployExpiredModels(Set<String> expiredModels, Map<String, Set<String>> modelWorkerNodes) { | ||
expiredModels.forEach(modelId -> { | ||
String[] targetNodeIds = modelWorkerNodes.keySet().toArray(new String[0]); | ||
|
||
MLUndeployModelNodesRequest mlUndeployModelNodesRequest = new MLUndeployModelNodesRequest( | ||
targetNodeIds, | ||
new String[] { modelId } | ||
); | ||
client.execute(MLUndeployModelAction.INSTANCE, mlUndeployModelNodesRequest, ActionListener.wrap(r -> { | ||
log.debug("model {} is un_deployed", modelId); | ||
}, e -> { log.error("Failed to undeploy model {}", modelId, e); })); | ||
}); | ||
}, e -> { log.error("Failed to undeploy models {}", expiredModels, e); })); | ||
} | ||
|
||
@VisibleForTesting | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems not very helpful if we don't log the error message
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
updated in the refresh.