/Users/deen/code/yugabyte-db/src/yb/rpc/rpc_controller.cc
Line | Count | Source (jump to first uncovered line) |
1 | | // Licensed to the Apache Software Foundation (ASF) under one |
2 | | // or more contributor license agreements. See the NOTICE file |
3 | | // distributed with this work for additional information |
4 | | // regarding copyright ownership. The ASF licenses this file |
5 | | // to you under the Apache License, Version 2.0 (the |
6 | | // "License"); you may not use this file except in compliance |
7 | | // with the License. You may obtain a copy of the License at |
8 | | // |
9 | | // http://www.apache.org/licenses/LICENSE-2.0 |
10 | | // |
11 | | // Unless required by applicable law or agreed to in writing, |
12 | | // software distributed under the License is distributed on an |
13 | | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
14 | | // KIND, either express or implied. See the License for the |
15 | | // specific language governing permissions and limitations |
16 | | // under the License. |
17 | | // |
18 | | // The following only applies to changes made to this file as part of YugaByte development. |
19 | | // |
20 | | // Portions Copyright (c) YugaByte, Inc. |
21 | | // |
22 | | // Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except |
23 | | // in compliance with the License. You may obtain a copy of the License at |
24 | | // |
25 | | // http://www.apache.org/licenses/LICENSE-2.0 |
26 | | // |
27 | | // Unless required by applicable law or agreed to in writing, software distributed under the License |
28 | | // is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express |
29 | | // or implied. See the License for the specific language governing permissions and limitations |
30 | | // under the License. |
31 | | // |
32 | | |
33 | | #include "yb/rpc/rpc_controller.h" |
34 | | |
35 | | #include <mutex> |
36 | | |
37 | | #include <glog/logging.h> |
38 | | |
39 | | #include "yb/rpc/outbound_call.h" |
40 | | |
41 | | #include "yb/util/result.h" |
42 | | |
43 | | namespace yb { namespace rpc { |
44 | | |
45 | 15.3M | RpcController::RpcController() { |
46 | 18.5k | DVLOG(4) << "RpcController " << this << " constructed"; |
47 | 15.3M | } |
48 | | |
49 | 15.2M | RpcController::~RpcController() { |
50 | 18.4E | DVLOG(4) << "RpcController " << this << " destroyed"; |
51 | 15.2M | } |
52 | | |
53 | 16.3k | RpcController::RpcController(RpcController&& rhs) noexcept { |
54 | 16.3k | Swap(&rhs); |
55 | 16.3k | } |
56 | | |
57 | 0 | void RpcController::operator=(RpcController&& rhs) noexcept { |
58 | 0 | Reset(); |
59 | 0 | Swap(&rhs); |
60 | 0 | } |
61 | | |
62 | 16.3k | void RpcController::Swap(RpcController* other) { |
63 | | // Cannot swap RPC controllers while they are in-flight. |
64 | 16.3k | if (call_) { |
65 | 0 | CHECK(finished()); |
66 | 0 | } |
67 | 16.3k | if (other->call_) { |
68 | 0 | CHECK(other->finished()); |
69 | 0 | } |
70 | | |
71 | 16.3k | std::swap(timeout_, other->timeout_); |
72 | 16.3k | std::swap(allow_local_calls_in_curr_thread_, other->allow_local_calls_in_curr_thread_); |
73 | 16.3k | std::swap(call_, other->call_); |
74 | 16.3k | std::swap(invoke_callback_mode_, other->invoke_callback_mode_); |
75 | 16.3k | } |
76 | | |
77 | 11.9M | void RpcController::Reset() { |
78 | 11.9M | std::lock_guard<simple_spinlock> l(lock_); |
79 | 11.9M | if (call_) { |
80 | 10.7M | CHECK(finished()); |
81 | 10.7M | } |
82 | 11.9M | call_.reset(); |
83 | 11.9M | } |
84 | | |
85 | 10.7M | bool RpcController::finished() const { |
86 | 10.7M | if (call_) { |
87 | 10.7M | return call_->IsFinished(); |
88 | 10.7M | } |
89 | 899 | return false; |
90 | 899 | } |
91 | | |
92 | 25.0M | Status RpcController::status() const { |
93 | 25.0M | if (call_) { |
94 | 24.9M | return call_->status(); |
95 | 24.9M | } |
96 | 39.0k | return Status::OK(); |
97 | 39.0k | } |
98 | | |
99 | 10.3M | Status RpcController::thread_pool_failure() const { |
100 | 10.3M | if (call_) { |
101 | 10.3M | return call_->thread_pool_failure(); |
102 | 10.3M | } |
103 | 785 | return Status::OK(); |
104 | 785 | } |
105 | | |
106 | 2.19k | const ErrorStatusPB* RpcController::error_response() const { |
107 | 2.19k | if (call_) { |
108 | 2.19k | return call_->error_pb(); |
109 | 2.19k | } |
110 | 0 | return nullptr; |
111 | 0 | } |
112 | | |
113 | 3.92M | Result<Slice> RpcController::GetSidecar(int idx) const { |
114 | 3.92M | return call_->GetSidecar(idx); |
115 | 3.92M | } |
116 | | |
117 | 3.45M | Result<SidecarPtr> RpcController::GetSidecarPtr(int idx) const { |
118 | 3.45M | return SidecarPtr(call_, VERIFY_RESULT(call_->GetSidecarPtr(idx))); |
119 | 3.45M | } |
120 | | |
121 | 3.60M | Result<SidecarHolder> RpcController::GetSidecarHolder(int idx) const { |
122 | 3.60M | return call_->GetSidecarHolder(idx); |
123 | 3.60M | } |
124 | | |
125 | 25.6M | void RpcController::set_timeout(const MonoDelta& timeout) { |
126 | 25.6M | std::lock_guard<simple_spinlock> l(lock_); |
127 | 25.6M | DCHECK(!call_ || call_->state() == RpcCallState::READY); |
128 | 25.6M | timeout_ = timeout; |
129 | 25.6M | } |
130 | | |
131 | 272k | void RpcController::set_deadline(const MonoTime& deadline) { |
132 | 272k | set_timeout(deadline.GetDeltaSince(MonoTime::Now())); |
133 | 272k | } |
134 | | |
135 | 430k | void RpcController::set_deadline(CoarseTimePoint deadline) { |
136 | 430k | set_timeout(deadline - CoarseMonoClock::now()); |
137 | 430k | } |
138 | | |
139 | 116M | MonoDelta RpcController::timeout() const { |
140 | 116M | std::lock_guard<simple_spinlock> l(lock_); |
141 | 116M | return timeout_; |
142 | 116M | } |
143 | | |
144 | 0 | int32_t RpcController::call_id() const { |
145 | 0 | if (call_) { |
146 | 0 | return call_->call_id(); |
147 | 0 | } |
148 | 0 | return -1; |
149 | 0 | } |
150 | | |
151 | | } // namespace rpc |
152 | | } // namespace yb |