Skip to content
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

Fix model delete failed after model undeployed #2613

Closed

Conversation

zane-neo
Copy link
Collaborator

@zane-neo zane-neo commented Jul 5, 2024

Description

When deleting a model, we need to check the model status by querying the model index: https://github.com/opensearch-project/ml-commons/blob/main/plugin/src/main/java/org/opensearch/ml/action/models/DeleteModelTransportAction.java#L108, which means when undepdeloying model response returns, we have to make sure the model status in index is updated to DELETED.

But in UndeployModelTransportAction there's no such guarantee, when updating the model index: https://github.com/opensearch-project/ml-commons/blob/main/plugin/src/main/java/org/opensearch/ml/action/undeploy/TransportUndeployModelAction.java#L192, the response returns almost at the same time when the each node's undeploy finished: https://github.com/opensearch-project/OpenSearch/blob/main/server/src/main/java/org/opensearch/action/support/nodes/TransportNodesAction.java#L315. Which means updating index and response to client run in parallel, so this issue happens occasionally.

So we need a mechanism to guarantee only when the update model index is completed, the response to client get run by adding a countdownlatch to block the response client action when updating index. This is safe to block since this newResponse method runs in a threadpool instead of the event loop threads. I also changed the threadpool to model deploy threadpool which is dedicated for deploy/undeploy model instead of management threadpool.

Issues Resolved

#2419
#2560

Check List

  • New functionality includes testing.
    • All tests pass
  • New functionality has been documented.
    • New functionality has javadoc added
  • Commits are signed per the DCO using --signoff

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
For more information on following Developer Certificate of Origin and signing off your commits, please check here.

@peterzhuamazon
Copy link
Member

Please rebase to take changes from #2627. Thanks.

@zane-neo zane-neo force-pushed the model-delete-after-undeploy branch from 2e02989 to a6cc76e Compare July 12, 2024 00:29
@zane-neo zane-neo temporarily deployed to ml-commons-cicd-env July 12, 2024 00:29 — with GitHub Actions Inactive
@zane-neo zane-neo temporarily deployed to ml-commons-cicd-env July 12, 2024 00:30 — with GitHub Actions Inactive
@zane-neo zane-neo temporarily deployed to ml-commons-cicd-env July 12, 2024 01:27 — with GitHub Actions Inactive
@Hailong-am
Copy link
Contributor

what's the root cause?

@zane-neo
Copy link
Collaborator Author

what's the root cause?

Added more details in the description.

@Zhangxunmt
Copy link
Collaborator

Which flaky IT is fixed from this change?

@@ -7,13 +7,16 @@

import static org.opensearch.ml.common.CommonValue.ML_MODEL_INDEX;
import static org.opensearch.ml.common.CommonValue.UNDEPLOYED;
import static org.opensearch.ml.plugin.MachineLearningPlugin.DEPLOY_THREAD_POOL;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Is it possible that multiple Undeploy actions blocking the Deploy_Thread_Pool will cause "Deploy" to fail?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Most of cases, the update index completes immediately which means there's no actual blocking here. In edge cases, if the update completes relatively slow, the requests will be queued. In a more edge case, the queue is full, then the deploy model will fail. But this usually mean the system is not in a correct status(updating index taking too long time). Also this failure is recoverable which doesn't seem a critical issue.

}
if (countDownLatch.getCount() != 0) {
try {
boolean success = countDownLatch.await(1000, TimeUnit.MILLISECONDS);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Is this 1 second too large? In most cases the update index happen pretty fast.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This is a at most value, if the update index happens within 1s, the await will break immediately after it's done. If update takes more than 1s, then await waits at most 1s to break.

Copy link
Collaborator

Choose a reason for hiding this comment

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

This will block current thread, which not recommended. We saw issues several times for such blocking thread code

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

If you're not blocking event loop thread, it's safe.

@zane-neo
Copy link
Collaborator Author

Which flaky IT is fixed from this change?

Check this issue: #2560

@ylwu-amzn
Copy link
Collaborator

@zane-neo I remember we have add immediate refresh policy . Why that can't work?

@zane-neo
Copy link
Collaborator Author

@zane-neo I remember we have add immediate refresh policy . Why that can't work?

Please check the description, simply put, this is a race condition issue that updating document and responding to user happens at the same time, no sequence guarantee.

@zane-neo
Copy link
Collaborator Author

zane-neo commented Aug 7, 2024

Checked again on the issue, this fix is not fixing the root cause. When using a script like below to reproduce the issue:

reg_res = client.post('localhost:9200/_plugins/_ml/models/_register', register_model_payload)
model_id = extract_model_id(reg_res)
deploy_res = client.post('localhost:9200/_plugins/_ml/models/{model_id}/_load')
undeploy_res = client.post('localhost:9200/_plugins/_ml/models/{model_id}/_unload')
delete_res = client.post('localhost:9200/_plugins/_ml/models/{model_id}')

This issue can be reproduce occasionally, but if adding time.sleep(1) after deploy_res returned, the issue can't be reproduced anymore.
The reason is deploy model is in an async approach and when client received the response, the model status in index is not guaranteed to deployed, this doesn't have a simple fix since a lot of files are involved in deploy flow.

This issue is not able to reproduced easily on local, so will add logs in the delete model action to clearly show the model status when it's not in a deletable status, and closing this PR now.

@zane-neo zane-neo closed this Aug 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants