[Placement Group]Add detached support for placement group. (#13582)

This commit is contained in:
DK.Pino
2021-01-27 18:51:26 +08:00
committed by GitHub
parent d2963f4ee1
commit 7f6d326ad8
15 changed files with 209 additions and 21 deletions
+4 -2
View File
@@ -67,8 +67,9 @@ class PlacementGroupSpecBuilder {
PlacementGroupSpecBuilder &SetPlacementGroupSpec(
const PlacementGroupID &placement_group_id, std::string name,
const std::vector<std::unordered_map<std::string, double>> &bundles,
const rpc::PlacementStrategy strategy, const JobID &creator_job_id,
const ActorID &creator_actor_id, bool is_creator_detached_actor) {
const rpc::PlacementStrategy strategy, const bool is_detached,
const JobID &creator_job_id, const ActorID &creator_actor_id,
bool is_creator_detached_actor) {
message_->set_placement_group_id(placement_group_id.Binary());
message_->set_name(name);
message_->set_strategy(strategy);
@@ -82,6 +83,7 @@ class PlacementGroupSpecBuilder {
message_->set_creator_job_dead(is_creator_detached_actor);
message_->set_creator_actor_id(creator_actor_id.Binary());
message_->set_creator_actor_dead(creator_actor_id.IsNil());
message_->set_is_detached(is_detached);
for (size_t i = 0; i < bundles.size(); i++) {
auto resources = bundles[i];
+7 -2
View File
@@ -144,8 +144,11 @@ using PlacementStrategy = rpc::PlacementStrategy;
struct PlacementGroupCreationOptions {
PlacementGroupCreationOptions(
std::string name, PlacementStrategy strategy,
std::vector<std::unordered_map<std::string, double>> bundles)
: name(std::move(name)), strategy(strategy), bundles(std::move(bundles)) {}
std::vector<std::unordered_map<std::string, double>> bundles, bool is_detached)
: name(std::move(name)),
strategy(strategy),
bundles(std::move(bundles)),
is_detached(is_detached) {}
/// The name of the placement group.
const std::string name;
@@ -153,6 +156,8 @@ struct PlacementGroupCreationOptions {
const PlacementStrategy strategy = rpc::PACK;
/// The resource bundles in this placement group.
const std::vector<std::unordered_map<std::string, double>> bundles;
/// Whether to keep the placement group persistent after its creator dead.
const bool is_detached = false;
};
} // namespace ray
+2 -2
View File
@@ -1463,8 +1463,8 @@ Status CoreWorker::CreatePlacementGroup(
builder.SetPlacementGroupSpec(
placement_group_id, placement_group_creation_options.name,
placement_group_creation_options.bundles, placement_group_creation_options.strategy,
worker_context_.GetCurrentJobID(), worker_context_.GetCurrentActorID(),
worker_context_.CurrentActorDetached());
placement_group_creation_options.is_detached, worker_context_.GetCurrentJobID(),
worker_context_.GetCurrentActorID(), worker_context_.CurrentActorDetached());
PlacementGroupSpecification placement_group_spec = builder.Build();
*return_placement_group_id = placement_group_id;
RAY_LOG(INFO) << "Submitting Placement Group creation to GCS: " << placement_group_id;
@@ -201,7 +201,8 @@ inline ray::PlacementGroupCreationOptions ToPlacementGroupCreationOptions(
});
});
return ray::PlacementGroupCreationOptions(JavaStringToNativeString(env, name),
ConvertStrategy(java_strategy), bundles);
ConvertStrategy(java_strategy), bundles,
/*is_detached=*/false);
}
#ifdef __cplusplus
@@ -96,11 +96,15 @@ void GcsPlacementGroup::MarkCreatorActorDead() {
placement_group_table_data_.set_creator_actor_dead(true);
}
bool GcsPlacementGroup::IsPlacementGroupRemovable() const {
return placement_group_table_data_.creator_job_dead() &&
bool GcsPlacementGroup::IsPlacementGroupLifetimeDone() const {
return !IsDetached() && placement_group_table_data_.creator_job_dead() &&
placement_group_table_data_.creator_actor_dead();
}
bool GcsPlacementGroup::IsDetached() const {
return placement_group_table_data_.is_detached();
}
/////////////////////////////////////////////////////////////////////////////////////////
GcsPlacementGroupManager::GcsPlacementGroupManager(
@@ -495,7 +499,7 @@ void GcsPlacementGroupManager::CleanPlacementGroupIfNeededWhenJobDead(
continue;
}
placement_group->MarkCreatorJobDead();
if (placement_group->IsPlacementGroupRemovable()) {
if (placement_group->IsPlacementGroupLifetimeDone()) {
RemovePlacementGroup(placement_group->GetPlacementGroupID(), [](Status status) {});
}
}
@@ -509,7 +513,7 @@ void GcsPlacementGroupManager::CleanPlacementGroupIfNeededWhenActorDead(
continue;
}
placement_group->MarkCreatorActorDead();
if (placement_group->IsPlacementGroupRemovable()) {
if (placement_group->IsPlacementGroupLifetimeDone()) {
RemovePlacementGroup(placement_group->GetPlacementGroupID(), [](Status status) {});
}
}
@@ -61,6 +61,7 @@ class GcsPlacementGroup {
placement_group_spec.creator_job_dead());
placement_group_table_data_.set_creator_actor_dead(
placement_group_spec.creator_actor_dead());
placement_group_table_data_.set_is_detached(placement_group_spec.is_detached());
}
/// Get the immutable PlacementGroupTableData of this placement group.
@@ -107,8 +108,11 @@ class GcsPlacementGroup {
/// Mark that the creator actor of this placement group is dead.
void MarkCreatorActorDead();
/// Return True if the placement group is removable. False otherwise.
bool IsPlacementGroupRemovable() const;
/// Return True if the placement group lifetime is done. False otherwise.
bool IsPlacementGroupLifetimeDone() const;
/// Returns whether or not this is a detached placement group.
bool IsDetached() const;
private:
/// The placement_group meta data which contains the task specification as well as the
+3 -2
View File
@@ -101,8 +101,9 @@ struct Mocker {
PlacementGroupSpecBuilder builder;
auto placement_group_id = PlacementGroupID::FromRandom();
builder.SetPlacementGroupSpec(placement_group_id, name, bundles, strategy, job_id,
actor_id, /* is_creator_detached */ false);
builder.SetPlacementGroupSpec(placement_group_id, name, bundles, strategy,
/* is_detached */ false, job_id, actor_id,
/* is_creator_detached */ false);
return builder.Build();
}
+2
View File
@@ -233,6 +233,8 @@ message PlacementGroupSpec {
bool creator_job_dead = 7;
// Whether or not if the creator actor is dead.
bool creator_actor_dead = 8;
// Whether the placement group is persistent.
bool is_detached = 9;
}
message ObjectReference {
+2
View File
@@ -191,6 +191,8 @@ message PlacementGroupTableData {
bool creator_job_dead = 8;
// Whether or not if the creator actor is dead.
bool creator_actor_dead = 9;
// Whether the placement group is persistent.
bool is_detached = 10;
}
message ScheduleData {