mirror of
https://github.com/wassname/ray.git
synced 2026-08-08 11:25:28 +08:00
[Placement Group] Support Placement Group state table. (#10090)
* Done. * Addressed code review. * Linting. * Fix lint. * Fix lint. * Fix a test. * Lint. * Add a lint sleep to test. * Fix the lint issue. * Fixed doc build error.
This commit is contained in:
@@ -1396,7 +1396,6 @@ Status CoreWorker::KillActor(const ActorID &actor_id, bool force_kill, bool no_r
|
||||
return Status::OK();
|
||||
}
|
||||
|
||||
// SANG-TODO
|
||||
Status CoreWorker::KillActorLocalMode(const ActorID &actor_id) {
|
||||
// KillActor doesn't do anything in local mode. We only remove named actor entry if
|
||||
// exists.
|
||||
|
||||
+10
-1
@@ -737,10 +737,19 @@ class PlacementGroupInfoAccessor {
|
||||
///
|
||||
/// \param placement_group_spec The specification for the placement group creation task.
|
||||
/// \param callback Callback that will be called after the placement group info is
|
||||
/// written to GCS. \return Status
|
||||
/// written to GCS.
|
||||
/// \return Status.
|
||||
virtual Status AsyncCreatePlacementGroup(
|
||||
const PlacementGroupSpecification &placement_group_spec) = 0;
|
||||
|
||||
/// Get a placement group data from GCS asynchronously.
|
||||
///
|
||||
/// \param placement_group_id The id of a placement group to obtain from GCS.
|
||||
/// \return Status.
|
||||
virtual Status AsyncGet(
|
||||
const PlacementGroupID &placement_group_id,
|
||||
const OptionalItemCallback<rpc::PlacementGroupTableData> &callback) = 0;
|
||||
|
||||
protected:
|
||||
PlacementGroupInfoAccessor() = default;
|
||||
};
|
||||
|
||||
@@ -232,5 +232,16 @@ bool GlobalStateAccessor::AddWorkerInfo(const std::string &serialized_string) {
|
||||
return true;
|
||||
}
|
||||
|
||||
std::unique_ptr<std::string> GlobalStateAccessor::GetPlacementGroupInfo(
|
||||
const PlacementGroupID &placement_group_id) {
|
||||
std::unique_ptr<std::string> placement_group_table_data;
|
||||
std::promise<bool> promise;
|
||||
RAY_CHECK_OK(gcs_client_->PlacementGroups().AsyncGet(
|
||||
placement_group_id, TransformForOptionalItemCallback<rpc::PlacementGroupTableData>(
|
||||
placement_group_table_data, promise)));
|
||||
promise.get_future().get();
|
||||
return placement_group_table_data;
|
||||
}
|
||||
|
||||
} // namespace gcs
|
||||
} // namespace ray
|
||||
|
||||
@@ -137,6 +137,15 @@ class GlobalStateAccessor {
|
||||
/// \return Is operation success.
|
||||
bool AddWorkerInfo(const std::string &serialized_string);
|
||||
|
||||
/// Get information of a placement group from GCS Service.
|
||||
///
|
||||
/// \param placement_group The ID of placement group to look up in the GCS Service.
|
||||
/// \return Placement group info. To support multi-language, we serialize each
|
||||
/// PlacementGroupTableData and return the serialized string. Where used, it needs to be
|
||||
/// deserialized with protobuf function.
|
||||
std::unique_ptr<std::string> GetPlacementGroupInfo(
|
||||
const PlacementGroupID &placement_group_id);
|
||||
|
||||
private:
|
||||
/// MultiItem transformation helper in template style.
|
||||
///
|
||||
|
||||
@@ -1462,5 +1462,26 @@ Status ServiceBasedPlacementGroupInfoAccessor::AsyncCreatePlacementGroup(
|
||||
return Status::OK();
|
||||
}
|
||||
|
||||
Status ServiceBasedPlacementGroupInfoAccessor::AsyncGet(
|
||||
const PlacementGroupID &placement_group_id,
|
||||
const OptionalItemCallback<rpc::PlacementGroupTableData> &callback) {
|
||||
RAY_LOG(DEBUG) << "Getting placement group info, placement group id = "
|
||||
<< placement_group_id;
|
||||
rpc::GetPlacementGroupRequest request;
|
||||
request.set_placement_group_id(placement_group_id.Binary());
|
||||
client_impl_->GetGcsRpcClient().GetPlacementGroup(
|
||||
request, [placement_group_id, callback](const Status &status,
|
||||
const rpc::GetPlacementGroupReply &reply) {
|
||||
if (reply.has_placement_group_table_data()) {
|
||||
callback(status, reply.placement_group_table_data());
|
||||
} else {
|
||||
callback(status, boost::none);
|
||||
}
|
||||
RAY_LOG(DEBUG) << "Finished getting placement group info, placement group id = "
|
||||
<< placement_group_id;
|
||||
});
|
||||
return Status::OK();
|
||||
}
|
||||
|
||||
} // namespace gcs
|
||||
} // namespace ray
|
||||
|
||||
@@ -446,6 +446,10 @@ class ServiceBasedPlacementGroupInfoAccessor : public PlacementGroupInfoAccessor
|
||||
Status AsyncCreatePlacementGroup(
|
||||
const PlacementGroupSpecification &placement_group_spec) override;
|
||||
|
||||
Status AsyncGet(
|
||||
const PlacementGroupID &placement_group_id,
|
||||
const OptionalItemCallback<rpc::PlacementGroupTableData> &callback) override;
|
||||
|
||||
private:
|
||||
ServiceBasedGcsClient *client_impl_;
|
||||
};
|
||||
|
||||
@@ -269,6 +269,8 @@ TEST_F(GlobalStateAccessorTest, TestWorkerTable) {
|
||||
ASSERT_EQ(global_state_->GetAllWorkerInfo().size(), 2);
|
||||
}
|
||||
|
||||
// TODO(sang): Add tests after adding asyncAdd
|
||||
|
||||
} // namespace ray
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
|
||||
@@ -1173,6 +1173,8 @@ TEST_F(ServiceBasedGcsClientTest, TestMultiThreadSubAndUnsub) {
|
||||
}
|
||||
}
|
||||
|
||||
// TODO(sang): Add tests after adding asyncAdd
|
||||
|
||||
} // namespace ray
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
|
||||
@@ -174,6 +174,32 @@ void GcsPlacementGroupManager::HandleCreatePlacementGroup(
|
||||
}));
|
||||
}
|
||||
|
||||
void GcsPlacementGroupManager::HandleGetPlacementGroup(
|
||||
const rpc::GetPlacementGroupRequest &request, rpc::GetPlacementGroupReply *reply,
|
||||
rpc::SendReplyCallback send_reply_callback) {
|
||||
PlacementGroupID placement_group_id =
|
||||
PlacementGroupID::FromBinary(request.placement_group_id());
|
||||
RAY_LOG(DEBUG) << "Getting placement group info, placement group id = "
|
||||
<< placement_group_id;
|
||||
|
||||
auto on_done = [placement_group_id, reply, send_reply_callback](
|
||||
const Status &status,
|
||||
const boost::optional<PlacementGroupTableData> &result) {
|
||||
if (result) {
|
||||
reply->mutable_placement_group_table_data()->CopyFrom(*result);
|
||||
}
|
||||
RAY_LOG(DEBUG) << "Finished getting placement group info, placement group id = "
|
||||
<< placement_group_id;
|
||||
GCS_RPC_SEND_REPLY(send_reply_callback, reply, Status::OK());
|
||||
};
|
||||
|
||||
Status status =
|
||||
gcs_table_storage_->PlacementGroupTable().Get(placement_group_id, on_done);
|
||||
if (!status.ok()) {
|
||||
on_done(status, boost::none);
|
||||
}
|
||||
}
|
||||
|
||||
void GcsPlacementGroupManager::RetryCreatingPlacementGroup() {
|
||||
execute_after(io_context_, [this] { SchedulePendingPlacementGroups(); },
|
||||
RayConfig::instance().gcs_create_placement_group_retry_interval_ms());
|
||||
|
||||
@@ -107,6 +107,10 @@ class GcsPlacementGroupManager : public rpc::PlacementGroupInfoHandler {
|
||||
rpc::CreatePlacementGroupReply *reply,
|
||||
rpc::SendReplyCallback send_reply_callback) override;
|
||||
|
||||
void HandleGetPlacementGroup(const rpc::GetPlacementGroupRequest &request,
|
||||
rpc::GetPlacementGroupReply *reply,
|
||||
rpc::SendReplyCallback send_reply_callback) override;
|
||||
|
||||
/// Register placement_group asynchronously.
|
||||
///
|
||||
/// \param request Contains the meta info to create the placement_group.
|
||||
|
||||
@@ -771,6 +771,8 @@ TEST_F(GcsServerTest, TestWorkerInfo) {
|
||||
worker_data->worker_address().worker_id());
|
||||
}
|
||||
|
||||
// TODO(sang): Add tests after adding asyncAdd
|
||||
|
||||
} // namespace ray
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
|
||||
@@ -833,6 +833,12 @@ Status RedisPlacementGroupInfoAccessor::AsyncCreatePlacementGroup(
|
||||
return Status::Invalid("Not implemented");
|
||||
}
|
||||
|
||||
Status RedisPlacementGroupInfoAccessor::AsyncGet(
|
||||
const PlacementGroupID &placement_group_id,
|
||||
const OptionalItemCallback<rpc::PlacementGroupTableData> &callback) {
|
||||
return Status::Invalid("Not implemented");
|
||||
}
|
||||
|
||||
} // namespace gcs
|
||||
|
||||
} // namespace ray
|
||||
|
||||
@@ -478,6 +478,10 @@ class RedisPlacementGroupInfoAccessor : public PlacementGroupInfoAccessor {
|
||||
|
||||
Status AsyncCreatePlacementGroup(
|
||||
const PlacementGroupSpecification &placement_group_spec) override;
|
||||
|
||||
Status AsyncGet(
|
||||
const PlacementGroupID &placement_group_id,
|
||||
const OptionalItemCallback<rpc::PlacementGroupTableData> &callback) override;
|
||||
};
|
||||
|
||||
} // namespace gcs
|
||||
|
||||
@@ -166,9 +166,11 @@ service ActorInfoGcsService {
|
||||
|
||||
// Service for placement group info access.
|
||||
service PlacementGroupInfoGcsService {
|
||||
// Create placement group via gcs service
|
||||
// Create placement group via gcs service.
|
||||
rpc CreatePlacementGroup(CreatePlacementGroupRequest)
|
||||
returns (CreatePlacementGroupReply);
|
||||
// Get placement group information via gcs service.
|
||||
rpc GetPlacementGroup(GetPlacementGroupRequest) returns (GetPlacementGroupReply);
|
||||
}
|
||||
|
||||
message RegisterNodeRequest {
|
||||
@@ -497,6 +499,15 @@ message CreatePlacementGroupReply {
|
||||
GcsStatus status = 1;
|
||||
}
|
||||
|
||||
message GetPlacementGroupRequest {
|
||||
bytes placement_group_id = 1;
|
||||
}
|
||||
|
||||
message GetPlacementGroupReply {
|
||||
GcsStatus status = 1;
|
||||
PlacementGroupTableData placement_group_table_data = 2;
|
||||
}
|
||||
|
||||
enum GcsServiceFailureType {
|
||||
RPC_DISCONNECT = 0;
|
||||
GCS_SERVER_RESTART = 1;
|
||||
|
||||
@@ -251,6 +251,10 @@ class GcsRpcClient {
|
||||
VOID_GCS_RPC_CLIENT_METHOD(PlacementGroupInfoGcsService, CreatePlacementGroup,
|
||||
placement_group_info_grpc_client_, )
|
||||
|
||||
/// Get placement group via GCS Service.
|
||||
VOID_GCS_RPC_CLIENT_METHOD(PlacementGroupInfoGcsService, GetPlacementGroup,
|
||||
placement_group_info_grpc_client_, )
|
||||
|
||||
private:
|
||||
std::function<void(GcsServiceFailureType)> gcs_service_failure_detected_;
|
||||
|
||||
|
||||
@@ -456,6 +456,10 @@ class PlacementGroupInfoGcsServiceHandler {
|
||||
virtual void HandleCreatePlacementGroup(const CreatePlacementGroupRequest &request,
|
||||
CreatePlacementGroupReply *reply,
|
||||
SendReplyCallback send_reply_callback) = 0;
|
||||
|
||||
virtual void HandleGetPlacementGroup(const GetPlacementGroupRequest &request,
|
||||
GetPlacementGroupReply *reply,
|
||||
SendReplyCallback send_reply_callback) = 0;
|
||||
};
|
||||
|
||||
/// The `GrpcService` for `PlacementGroupInfoGcsService`.
|
||||
@@ -475,6 +479,7 @@ class PlacementGroupInfoGrpcService : public GrpcService {
|
||||
const std::unique_ptr<grpc::ServerCompletionQueue> &cq,
|
||||
std::vector<std::unique_ptr<ServerCallFactory>> *server_call_factories) override {
|
||||
PLACEMENT_GROUP_INFO_SERVICE_RPC_HANDLER(CreatePlacementGroup);
|
||||
PLACEMENT_GROUP_INFO_SERVICE_RPC_HANDLER(GetPlacementGroup);
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
Reference in New Issue
Block a user