MCPcopy Create free account
hub / github.com/Oneflow-Inc/oneflow / HandleRpcs

Method HandleRpcs

oneflow/core/control/rpc_server.cpp:29–63  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

27}
28
29void RpcServer::HandleRpcs() {
30 EnqueueRequests();
31
32 void* tag = nullptr;
33 bool ok = false;
34 // NOTE(chengcheng): The is_shutdown bool flag make sure that 'ok = false' occurs ONLY after
35 // cq_->Shutdown() for security check.
36 bool is_shutdown = false;
37 // NOTE(chengcheng): The final end is that cq_->Next() get false and cq_ is empty with no item.
38 while (cq_->Next(&tag, &ok)) {
39 auto call = static_cast<CtrlCallIf*>(tag);
40 if (!ok) {
41 // NOTE(chengcheng): After call grpc_server_->Shutdown() and cq_->Shutdown(),
42 // there will trigger some cancel tag items on each RPC. And cq_->Next() can get these tag
43 // with ok = false. Then delete the tag with CtrlCallIf pointer for recovery.
44 CHECK(is_shutdown);
45 CHECK(call);
46 delete call;
47 continue;
48 }
49 if (call) {
50 call->Process();
51 } else {
52 // NOTE(chengcheng): A null `call` indicates that this is the shutdown alarm.
53 CHECK(!is_shutdown);
54 is_shutdown = true;
55 grpc_server_->Shutdown();
56 cq_->Shutdown();
57
58 // NOTE(chengcheng): You CANNOT use code 'break;' in this block because that
59 // there still be items in the cq_.
60 // 'break;'
61 }
62 }
63}
64
65void RpcServer::Init() {
66 Add([this](CtrlCall<CtrlMethod::kLoadServer>* call) { OnLoadServer(call); });

Callers

nothing calls this directly

Calls 3

ProcessMethod · 0.80
ShutdownMethod · 0.80
NextMethod · 0.45

Tested by

no test coverage detected