|
| 1 | +// Copyright 2025 The Ray Authors. |
| 2 | +// |
| 3 | +// Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | +// you may not use this file except in compliance with the License. |
| 5 | +// You may obtain a copy of the License at |
| 6 | +// |
| 7 | +// http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | +// |
| 9 | +// Unless required by applicable law or agreed to in writing, software |
| 10 | +// distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | +// See the License for the specific language governing permissions and |
| 13 | +// limitations under the License. |
| 14 | + |
| 15 | +/* |
| 16 | + * This file defines the gRPC service handlers for the core worker server. |
| 17 | + * |
| 18 | + * core_worker_process should be the only user of this target. If other classes need the |
| 19 | + * CoreWorkerInterface in the future, split it into its own target that does not include |
| 20 | + * the heavyweight gRPC headers.. |
| 21 | + * |
| 22 | + * To add a new RPC handler: |
| 23 | + * - Update core_worker.proto. |
| 24 | + * - Add a virtual method to CoreWorkerService. |
| 25 | + * - Initialize the handler for the method in InitServerCallFactories. |
| 26 | + * - Implement the method in core_worker. |
| 27 | + */ |
| 28 | + |
| 29 | +#pragma once |
| 30 | + |
| 31 | +#include <memory> |
| 32 | +#include <vector> |
| 33 | + |
| 34 | +#include "ray/common/asio/instrumented_io_context.h" |
| 35 | +#include "ray/rpc/grpc_server.h" |
| 36 | +#include "ray/rpc/server_call.h" |
| 37 | +#include "src/ray/protobuf/core_worker.grpc.pb.h" |
| 38 | +#include "src/ray/protobuf/core_worker.pb.h" |
| 39 | + |
| 40 | +namespace ray { |
| 41 | +namespace rpc { |
| 42 | + |
| 43 | +class CoreWorkerServiceHandler : public DelayedServiceHandler { |
| 44 | + public: |
| 45 | + /// Blocks until the service is ready to serve RPCs. |
| 46 | + virtual void WaitUntilInitialized() = 0; |
| 47 | + |
| 48 | + virtual void HandlePushTask(PushTaskRequest request, |
| 49 | + PushTaskReply *reply, |
| 50 | + SendReplyCallback send_reply_callback) = 0; |
| 51 | + |
| 52 | + virtual void HandleActorCallArgWaitComplete(ActorCallArgWaitCompleteRequest request, |
| 53 | + ActorCallArgWaitCompleteReply *reply, |
| 54 | + SendReplyCallback send_reply_callback) = 0; |
| 55 | + |
| 56 | + virtual void HandleRayletNotifyGCSRestart(RayletNotifyGCSRestartRequest request, |
| 57 | + RayletNotifyGCSRestartReply *reply, |
| 58 | + SendReplyCallback send_reply_callback) = 0; |
| 59 | + |
| 60 | + virtual void HandleGetObjectStatus(GetObjectStatusRequest request, |
| 61 | + GetObjectStatusReply *reply, |
| 62 | + SendReplyCallback send_reply_callback) = 0; |
| 63 | + |
| 64 | + virtual void HandleWaitForActorRefDeleted(WaitForActorRefDeletedRequest request, |
| 65 | + WaitForActorRefDeletedReply *reply, |
| 66 | + SendReplyCallback send_reply_callback) = 0; |
| 67 | + |
| 68 | + virtual void HandlePubsubLongPolling(PubsubLongPollingRequest request, |
| 69 | + PubsubLongPollingReply *reply, |
| 70 | + SendReplyCallback send_reply_callback) = 0; |
| 71 | + |
| 72 | + virtual void HandlePubsubCommandBatch(PubsubCommandBatchRequest request, |
| 73 | + PubsubCommandBatchReply *reply, |
| 74 | + SendReplyCallback send_reply_callback) = 0; |
| 75 | + |
| 76 | + virtual void HandleUpdateObjectLocationBatch(UpdateObjectLocationBatchRequest request, |
| 77 | + UpdateObjectLocationBatchReply *reply, |
| 78 | + SendReplyCallback send_reply_callback) = 0; |
| 79 | + virtual void HandleGetObjectLocationsOwner(GetObjectLocationsOwnerRequest request, |
| 80 | + GetObjectLocationsOwnerReply *reply, |
| 81 | + SendReplyCallback send_reply_callback) = 0; |
| 82 | + |
| 83 | + virtual void HandleReportGeneratorItemReturns( |
| 84 | + ReportGeneratorItemReturnsRequest request, |
| 85 | + ReportGeneratorItemReturnsReply *reply, |
| 86 | + SendReplyCallback send_reply_callback) = 0; |
| 87 | + |
| 88 | + virtual void HandleKillActor(KillActorRequest request, |
| 89 | + KillActorReply *reply, |
| 90 | + SendReplyCallback send_reply_callback) = 0; |
| 91 | + |
| 92 | + virtual void HandleCancelTask(CancelTaskRequest request, |
| 93 | + CancelTaskReply *reply, |
| 94 | + SendReplyCallback send_reply_callback) = 0; |
| 95 | + |
| 96 | + virtual void HandleRemoteCancelTask(RemoteCancelTaskRequest request, |
| 97 | + RemoteCancelTaskReply *reply, |
| 98 | + SendReplyCallback send_reply_callback) = 0; |
| 99 | + |
| 100 | + virtual void HandleRegisterMutableObjectReader( |
| 101 | + RegisterMutableObjectReaderRequest request, |
| 102 | + RegisterMutableObjectReaderReply *reply, |
| 103 | + SendReplyCallback send_reply_callback) = 0; |
| 104 | + |
| 105 | + virtual void HandleGetCoreWorkerStats(GetCoreWorkerStatsRequest request, |
| 106 | + GetCoreWorkerStatsReply *reply, |
| 107 | + SendReplyCallback send_reply_callback) = 0; |
| 108 | + |
| 109 | + virtual void HandleLocalGC(LocalGCRequest request, |
| 110 | + LocalGCReply *reply, |
| 111 | + SendReplyCallback send_reply_callback) = 0; |
| 112 | + |
| 113 | + virtual void HandleDeleteObjects(DeleteObjectsRequest request, |
| 114 | + DeleteObjectsReply *reply, |
| 115 | + SendReplyCallback send_reply_callback) = 0; |
| 116 | + |
| 117 | + virtual void HandleSpillObjects(SpillObjectsRequest request, |
| 118 | + SpillObjectsReply *reply, |
| 119 | + SendReplyCallback send_reply_callback) = 0; |
| 120 | + |
| 121 | + virtual void HandleRestoreSpilledObjects(RestoreSpilledObjectsRequest request, |
| 122 | + RestoreSpilledObjectsReply *reply, |
| 123 | + SendReplyCallback send_reply_callback) = 0; |
| 124 | + |
| 125 | + virtual void HandleDeleteSpilledObjects(DeleteSpilledObjectsRequest request, |
| 126 | + DeleteSpilledObjectsReply *reply, |
| 127 | + SendReplyCallback send_reply_callback) = 0; |
| 128 | + |
| 129 | + virtual void HandlePlasmaObjectReady(PlasmaObjectReadyRequest request, |
| 130 | + PlasmaObjectReadyReply *reply, |
| 131 | + SendReplyCallback send_reply_callback) = 0; |
| 132 | + |
| 133 | + virtual void HandleExit(ExitRequest request, |
| 134 | + ExitReply *reply, |
| 135 | + SendReplyCallback send_reply_callback) = 0; |
| 136 | + |
| 137 | + virtual void HandleAssignObjectOwner(AssignObjectOwnerRequest request, |
| 138 | + AssignObjectOwnerReply *reply, |
| 139 | + SendReplyCallback send_reply_callback) = 0; |
| 140 | + |
| 141 | + virtual void HandleNumPendingTasks(NumPendingTasksRequest request, |
| 142 | + NumPendingTasksReply *reply, |
| 143 | + SendReplyCallback send_reply_callback) = 0; |
| 144 | + |
| 145 | + virtual void HandleFreeActorObject(FreeActorObjectRequest request, |
| 146 | + FreeActorObjectReply *reply, |
| 147 | + SendReplyCallback send_reply_callback) = 0; |
| 148 | +}; |
| 149 | + |
| 150 | +class CoreWorkerGrpcService : public GrpcService { |
| 151 | + public: |
| 152 | + CoreWorkerGrpcService(instrumented_io_context &main_service, |
| 153 | + CoreWorkerServiceHandler &service_handler, |
| 154 | + int64_t max_active_rpcs_per_handler) |
| 155 | + : GrpcService(main_service), |
| 156 | + service_handler_(service_handler), |
| 157 | + max_active_rpcs_per_handler_(max_active_rpcs_per_handler) {} |
| 158 | + |
| 159 | + protected: |
| 160 | + grpc::Service &GetGrpcService() override { return service_; } |
| 161 | + |
| 162 | + void InitServerCallFactories( |
| 163 | + const std::unique_ptr<grpc::ServerCompletionQueue> &cq, |
| 164 | + std::vector<std::unique_ptr<ServerCallFactory>> *server_call_factories, |
| 165 | + const ClusterID &cluster_id) override; |
| 166 | + |
| 167 | + private: |
| 168 | + CoreWorkerService::AsyncService service_; |
| 169 | + CoreWorkerServiceHandler &service_handler_; |
| 170 | + int64_t max_active_rpcs_per_handler_; |
| 171 | +}; |
| 172 | + |
| 173 | +} // namespace rpc |
| 174 | +} // namespace ray |
0 commit comments