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

[Core] Cancel lease requests before returning a PG bundle #45919

Merged
merged 9 commits into from
Jun 16, 2024

Conversation

jjyao
Copy link
Collaborator

@jjyao jjyao commented Jun 13, 2024

Why are these changes needed?

To successfully return a PG bundle (CancelResourceReserve and ReleaseUnusedBundles), the bundle resource needs to be completely free (i.e. total == available). To make sure that, raylet will first destroy leased workers that are currently using the PG bundle resources so that these bundle resources can be freed. However this alone cannot guarantee that all bundle resources will be freed since a lease request that's popping worker also already acquires the bundle resources so we need to cancel these lease requests as well to free the bundle resources.

After this PR, we don't need the retry in #42942.

Related issue number

Closes #45642

Checks

  • I've signed off every commit(by using the -s flag, i.e., git commit -s) in this PR.
  • I've run scripts/format.sh to lint the changes in this PR.
  • I've included any doc changes needed for https://docs.ray.io/en/master/.
    • I've added any new APIs to the API Reference. For example, if I added a
      method in Tune, I've added it in doc/source/tune/api/ under the
      corresponding .rst file.
  • I've made sure the tests are passing. Note that there might be a few flaky tests, see the recent failures at https://flakey-tests.ray.io/
  • Testing Strategy
    • Unit tests
    • Release tests
    • This PR is not tested :(

Comment on lines 686 to 695
// Cancel lease requests related to unused bundles
cluster_task_manager_->CancelTasks(
[&](const RayTask &task) {
const auto bundle_id = task.GetTaskSpecification().PlacementGroupBundleId();
return !bundle_id.first.IsNil() && 0 == in_use_bundles.count(bundle_id);
},
rpc::RequestWorkerLeaseReply::SCHEDULING_CANCELLED_INTENDED,
"The task is cancelled because it uses placement group bundles that are not "
"registered to GCS. It can happen upon GCS restart.");

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Actual fix.

Comment on lines 1902 to 1910
// Cancel lease requests related to the placement group to be removed.
cluster_task_manager_->CancelTasks(
[&](const RayTask &task) {
const auto bundle_id = task.GetTaskSpecification().PlacementGroupBundleId();
return bundle_id.first == bundle_spec.PlacementGroupId();
},
rpc::RequestWorkerLeaseReply::SCHEDULING_CANCELLED_PLACEMENT_GROUP_REMOVED,
"");

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Actual fix.

@jjyao jjyao added the go add ONLY when ready to merge, run all tests label Jun 13, 2024
Signed-off-by: Jiajun Yao <[email protected]>
@jjyao jjyao marked this pull request as ready for review June 13, 2024 17:19
@jjyao jjyao requested a review from a team as a code owner June 13, 2024 17:19
@rynewang
Copy link
Contributor

Side comment: we found multiple similar cases, in that when we want to kill all workers under a predicate (e.g. job died, root detached actor died, pg died, ...), we have to do it multiple places:

  • NodeManager::leased_workers_
  • WorkerPool::PopWorkerCallbackInternal
  • WorkerPool::InvokePopWorkerCallbackForProcess
  • WorkerPool::KillIdleWorker

I wonder if we can have a unified mechanism to do the killing for all...

@@ -233,6 +233,7 @@ void CoreWorkerProcessImpl::InitializeSystemConfig() {
thread.join();

RayConfig::instance().initialize(promise.get_future().get());
ray::asio::testing::init();
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 makes sure we can set testing_asio_delay_us env var through _system_configs

src/ray/raylet/local_task_manager.cc Show resolved Hide resolved
@jjyao jjyao requested a review from rynewang June 14, 2024 18:59
src/ray/raylet/local_task_manager.cc Show resolved Hide resolved
src/ray/util/container_util.h Show resolved Hide resolved
@jjyao jjyao enabled auto-merge (squash) June 16, 2024 04:22
@jjyao jjyao merged commit f0f52fa into ray-project:master Jun 16, 2024
7 checks passed
@jjyao jjyao deleted the jjyao/pgg branch June 17, 2024 02:26
can-anyscale added a commit that referenced this pull request Jun 17, 2024
@can-anyscale
Copy link
Collaborator

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
go add ONLY when ready to merge, run all tests
Projects
None yet
4 participants