YugabyteDB (2.13.1.0-b60, 21121d69985fbf76aa6958d8f04a9bfa936293b5)

Coverage Report

Created: 2022-03-22 16:43

/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
60.9M
RpcController::RpcController() {
46
60.9M
  DVLOG
(4) << "RpcController " << this << " constructed"30.5k
;
47
60.9M
}
48
49
60.7M
RpcController::~RpcController() {
50
60.7M
  DVLOG
(4) << "RpcController " << this << " destroyed"10.0k
;
51
60.7M
}
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
37.2M
void RpcController::Reset() {
78
37.2M
  std::lock_guard<simple_spinlock> l(lock_);
79
37.2M
  if (call_) {
80
26.6M
    CHECK(finished());
81
26.6M
  }
82
37.2M
  call_.reset();
83
37.2M
}
84
85
26.6M
bool RpcController::finished() const {
86
26.6M
  if (call_) {
87
26.6M
    return call_->IsFinished();
88
26.6M
  }
89
560
  return false;
90
26.6M
}
91
92
84.9M
Status RpcController::status() const {
93
84.9M
  if (call_) {
94
84.8M
    return call_->status();
95
84.8M
  }
96
82.9k
  return Status::OK();
97
84.9M
}
98
99
25.6M
Status RpcController::thread_pool_failure() const {
100
25.6M
  if (call_) {
101
25.6M
    return call_->thread_pool_failure();
102
25.6M
  }
103
2.51k
  return Status::OK();
104
25.6M
}
105
106
268k
const ErrorStatusPB* RpcController::error_response() const {
107
268k
  if (call_) {
108
268k
    return call_->error_pb();
109
268k
  }
110
1
  return nullptr;
111
268k
}
112
113
7.53M
Result<Slice> RpcController::GetSidecar(int idx) const {
114
7.53M
  return call_->GetSidecar(idx);
115
7.53M
}
116
117
10.3M
Result<SidecarPtr> RpcController::GetSidecarPtr(int idx) const {
118
10.3M
  return SidecarPtr(call_, VERIFY_RESULT(call_->GetSidecarPtr(idx)));
119
10.3M
}
120
121
10.6M
Result<SidecarHolder> RpcController::GetSidecarHolder(int idx) const {
122
10.6M
  return call_->GetSidecarHolder(idx);
123
10.6M
}
124
125
86.5M
void RpcController::set_timeout(const MonoDelta& timeout) {
126
86.5M
  std::lock_guard<simple_spinlock> l(lock_);
127
86.5M
  DCHECK(!call_ || call_->state() == RpcCallState::READY);
128
86.5M
  timeout_ = timeout;
129
86.5M
}
130
131
463k
void RpcController::set_deadline(const MonoTime& deadline) {
132
463k
  set_timeout(deadline.GetDeltaSince(MonoTime::Now()));
133
463k
}
134
135
601k
void RpcController::set_deadline(CoarseTimePoint deadline) {
136
601k
  set_timeout(deadline - CoarseMonoClock::now());
137
601k
}
138
139
409M
MonoDelta RpcController::timeout() const {
140
409M
  std::lock_guard<simple_spinlock> l(lock_);
141
409M
  return timeout_;
142
409M
}
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