YugabyteDB (2.13.0.0-b42, bfc6a6643e7399ac8a0e81d06a3ee6d6571b33ab)

Coverage Report

Created: 2022-03-09 17:30

/Users/deen/code/yugabyte-db/src/yb/rpc/connection_context.h
Line
Count
Source (jump to first uncovered line)
1
// Copyright (c) YugaByte, Inc.
2
//
3
// Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
4
// in compliance with the License.  You may obtain a copy of the License at
5
//
6
// http://www.apache.org/licenses/LICENSE-2.0
7
//
8
// Unless required by applicable law or agreed to in writing, software distributed under the License
9
// is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
10
// or implied.  See the License for the specific language governing permissions and limitations
11
// under the License.
12
//
13
14
#ifndef YB_RPC_CONNECTION_CONTEXT_H
15
#define YB_RPC_CONNECTION_CONTEXT_H
16
17
#include <ev++.h>
18
19
#include "yb/rpc/rpc_fwd.h"
20
#include "yb/rpc/rpc_introspection.pb.h"
21
22
#include "yb/util/net/socket.h"
23
#include "yb/util/strongly_typed_bool.h"
24
25
namespace yb {
26
27
class MemTracker;
28
29
namespace rpc {
30
31
typedef std::function<void()> IdleListener;
32
33
struct ProcessCallsResult {
34
  size_t consumed = 0;
35
  Slice buffer;
36
  size_t bytes_to_skip = 0;
37
38
  std::string ToString() const;
39
};
40
41
// ConnectionContext class is used by connection for doing protocol
42
// specific logic.
43
class ConnectionContext {
44
 public:
45
621k
  virtual ~ConnectionContext() {}
46
47
  // Split data into separate calls and invoke them.
48
  // Returns number of processed bytes.
49
  virtual Result<ProcessCallsResult> ProcessCalls(
50
      const ConnectionPtr& connection, const IoVecs& data, ReadBufferFull read_buffer_full) = 0;
51
52
  // Dump information about status of this connection context to protobuf.
53
  virtual void DumpPB(const DumpRunningRpcsRequestPB& req, RpcConnectionPB* resp) = 0;
54
55
  // Checks whether this connection context is idle.
56
  // If reason is supplied, then human-readable description of why the context is not idle is
57
  // appended to it.
58
  virtual bool Idle(std::string* reason_not_idle = nullptr) = 0;
59
60
  // Listen for when context becomes idle.
61
  virtual void ListenIdle(IdleListener listener) = 0;
62
63
  // Shutdown this context.
64
  virtual void Shutdown(const Status& status) = 0;
65
66
  virtual void QueueResponse(const ConnectionPtr& connection, InboundCallPtr call) = 0;
67
68
9.93k
  virtual void SetEventLoop(ev::loop_ref* loop) {}
69
70
314k
  virtual void AssignConnection(const ConnectionPtr& connection) {}
71
72
  virtual void Connected(const ConnectionPtr& connection) = 0;
73
74
  virtual uint64_t ProcessedCallCount() = 0;
75
76
  virtual RpcConnectionPB::StateType State() = 0;
77
78
  virtual StreamReadBuffer& ReadBuffer() = 0;
79
80
  virtual CHECKED_STATUS ReportPendingWriteBytes(size_t bytes_in_queue) = 0;
81
82
  virtual void UpdateLastRead(const ConnectionPtr& connection);
83
84
23.5M
  virtual void UpdateLastWrite(const ConnectionPtr& connection) {}
85
};
86
87
class ConnectionContextBase : public ConnectionContext {
88
 public:
89
  Status ReportPendingWriteBytes(size_t bytes_in_queue) override;
90
};
91
92
class ConnectionContextFactory {
93
 public:
94
  ConnectionContextFactory(
95
      int64_t memory_limit, const std::string& name,
96
      const std::shared_ptr<MemTracker>& parent_mem_tracker);
97
98
  virtual std::unique_ptr<ConnectionContext> Create(size_t receive_buffer_size) = 0;
99
100
0
  const std::shared_ptr<MemTracker>& parent_tracker() {
101
0
    return parent_tracker_;
102
0
  }
103
104
1.23M
  const std::shared_ptr<MemTracker>& buffer_tracker() {
105
1.23M
    return buffer_tracker_;
106
1.23M
  }
107
108
 protected:
109
  ~ConnectionContextFactory();
110
111
  std::shared_ptr<MemTracker> parent_tracker_;
112
  std::shared_ptr<MemTracker> call_tracker_;
113
  std::shared_ptr<MemTracker> buffer_tracker_;
114
};
115
116
template <class ContextType>
117
class ConnectionContextFactoryImpl : public ConnectionContextFactory {
118
 public:
119
  ConnectionContextFactoryImpl(
120
      int64_t memory_limit = 0,
121
      const std::shared_ptr<MemTracker>& parent_mem_tracker = nullptr)
122
      : ConnectionContextFactory(
123
37.5k
          memory_limit, ContextType::Name(), parent_mem_tracker) {}
_ZN2yb3rpc28ConnectionContextFactoryImplINS0_26YBInboundConnectionContextEEC2ExRKNSt3__110shared_ptrINS_10MemTrackerEEE
Line
Count
Source
123
11.6k
          memory_limit, ContextType::Name(), parent_mem_tracker) {}
_ZN2yb3rpc28ConnectionContextFactoryImplINS0_27YBOutboundConnectionContextEEC2ExRKNSt3__110shared_ptrINS_10MemTrackerEEE
Line
Count
Source
123
21.3k
          memory_limit, ContextType::Name(), parent_mem_tracker) {}
_ZN2yb3rpc28ConnectionContextFactoryImplINS_9cqlserver20CQLConnectionContextEEC2ExRKNSt3__110shared_ptrINS_10MemTrackerEEE
Line
Count
Source
123
4.54k
          memory_limit, ContextType::Name(), parent_mem_tracker) {}
124
125
945k
  std::unique_ptr<ConnectionContext> Create(size_t receive_buffer_size) override {
126
945k
    return std::make_unique<ContextType>(receive_buffer_size, buffer_tracker_, call_tracker_);
127
945k
  }
_ZN2yb3rpc28ConnectionContextFactoryImplINS0_26YBInboundConnectionContextEE6CreateEm
Line
Count
Source
125
304k
  std::unique_ptr<ConnectionContext> Create(size_t receive_buffer_size) override {
126
304k
    return std::make_unique<ContextType>(receive_buffer_size, buffer_tracker_, call_tracker_);
127
304k
  }
_ZN2yb3rpc28ConnectionContextFactoryImplINS0_27YBOutboundConnectionContextEE6CreateEm
Line
Count
Source
125
631k
  std::unique_ptr<ConnectionContext> Create(size_t receive_buffer_size) override {
126
631k
    return std::make_unique<ContextType>(receive_buffer_size, buffer_tracker_, call_tracker_);
127
631k
  }
_ZN2yb3rpc28ConnectionContextFactoryImplINS_9cqlserver20CQLConnectionContextEE6CreateEm
Line
Count
Source
125
9.40k
  std::unique_ptr<ConnectionContext> Create(size_t receive_buffer_size) override {
126
9.40k
    return std::make_unique<ContextType>(receive_buffer_size, buffer_tracker_, call_tracker_);
127
9.40k
  }
128
129
4.11k
  virtual ~ConnectionContextFactoryImpl() {}
_ZN2yb3rpc28ConnectionContextFactoryImplINS0_26YBInboundConnectionContextEED2Ev
Line
Count
Source
129
297
  virtual ~ConnectionContextFactoryImpl() {}
_ZN2yb3rpc28ConnectionContextFactoryImplINS0_27YBOutboundConnectionContextEED2Ev
Line
Count
Source
129
3.82k
  virtual ~ConnectionContextFactoryImpl() {}
Unexecuted instantiation: _ZN2yb3rpc28ConnectionContextFactoryImplINS_9cqlserver20CQLConnectionContextEED2Ev
130
};
131
132
template <class ContextType, class... Args>
133
37.3k
std::shared_ptr<ConnectionContextFactory> CreateConnectionContextFactory(Args&&... args) {
134
37.3k
  return std::make_shared<ConnectionContextFactoryImpl<ContextType>>(std::forward<Args>(args)...);
135
37.3k
}
_ZN2yb3rpc30CreateConnectionContextFactoryINS0_26YBInboundConnectionContextEJEEENSt3__110shared_ptrINS0_24ConnectionContextFactoryEEEDpOT0_
Line
Count
Source
133
96
std::shared_ptr<ConnectionContextFactory> CreateConnectionContextFactory(Args&&... args) {
134
96
  return std::make_shared<ConnectionContextFactoryImpl<ContextType>>(std::forward<Args>(args)...);
135
96
}
_ZN2yb3rpc30CreateConnectionContextFactoryINS0_26YBInboundConnectionContextEJxRKNSt3__110shared_ptrINS_10MemTrackerEEEEEENS4_INS0_24ConnectionContextFactoryEEEDpOT0_
Line
Count
Source
133
5.45k
std::shared_ptr<ConnectionContextFactory> CreateConnectionContextFactory(Args&&... args) {
134
5.45k
  return std::make_shared<ConnectionContextFactoryImpl<ContextType>>(std::forward<Args>(args)...);
135
5.45k
}
_ZN2yb3rpc30CreateConnectionContextFactoryINS0_26YBInboundConnectionContextEJRxRKNSt3__110shared_ptrINS_10MemTrackerEEEEEENS5_INS0_24ConnectionContextFactoryEEEDpOT0_
Line
Count
Source
133
6.10k
std::shared_ptr<ConnectionContextFactory> CreateConnectionContextFactory(Args&&... args) {
134
6.10k
  return std::make_shared<ConnectionContextFactoryImpl<ContextType>>(std::forward<Args>(args)...);
135
6.10k
}
_ZN2yb3rpc30CreateConnectionContextFactoryINS_9cqlserver20CQLConnectionContextEJRxNSt3__110shared_ptrINS_10MemTrackerEEEEEENS6_INS0_24ConnectionContextFactoryEEEDpOT0_
Line
Count
Source
133
4.54k
std::shared_ptr<ConnectionContextFactory> CreateConnectionContextFactory(Args&&... args) {
134
4.54k
  return std::make_shared<ConnectionContextFactoryImpl<ContextType>>(std::forward<Args>(args)...);
135
4.54k
}
_ZN2yb3rpc30CreateConnectionContextFactoryINS0_27YBOutboundConnectionContextEJRxRKNSt3__110shared_ptrINS_10MemTrackerEEEEEENS5_INS0_24ConnectionContextFactoryEEEDpOT0_
Line
Count
Source
133
21.1k
std::shared_ptr<ConnectionContextFactory> CreateConnectionContextFactory(Args&&... args) {
134
21.1k
  return std::make_shared<ConnectionContextFactoryImpl<ContextType>>(std::forward<Args>(args)...);
135
21.1k
}
136
137
} // namespace rpc
138
} // namespace yb
139
140
#endif // YB_RPC_CONNECTION_CONTEXT_H