YugabyteDB (2.13.1.0-b60, 21121d69985fbf76aa6958d8f04a9bfa936293b5)

Coverage Report

Created: 2022-03-22 16:43

/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
3.26M
  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
11.5k
  virtual void SetEventLoop(ev::loop_ref* loop) {}
69
70
620k
  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
80.7M
  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
4.18M
  const std::shared_ptr<MemTracker>& buffer_tracker() {
105
4.18M
    return buffer_tracker_;
106
4.18M
  }
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
58.9k
          memory_limit, ContextType::Name(), parent_mem_tracker) {}
yb::rpc::ConnectionContextFactoryImpl<yb::rpc::YBInboundConnectionContext>::ConnectionContextFactoryImpl(long long, std::__1::shared_ptr<yb::MemTracker> const&)
Line
Count
Source
123
17.4k
          memory_limit, ContextType::Name(), parent_mem_tracker) {}
yb::rpc::ConnectionContextFactoryImpl<yb::rpc::YBOutboundConnectionContext>::ConnectionContextFactoryImpl(long long, std::__1::shared_ptr<yb::MemTracker> const&)
Line
Count
Source
123
35.3k
          memory_limit, ContextType::Name(), parent_mem_tracker) {}
yb::rpc::ConnectionContextFactoryImpl<yb::cqlserver::CQLConnectionContext>::ConnectionContextFactoryImpl(long long, std::__1::shared_ptr<yb::MemTracker> const&)
Line
Count
Source
123
6.11k
          memory_limit, ContextType::Name(), parent_mem_tracker) {}
124
125
3.76M
  std::unique_ptr<ConnectionContext> Create(size_t receive_buffer_size) override {
126
3.76M
    return std::make_unique<ContextType>(receive_buffer_size, buffer_tracker_, call_tracker_);
127
3.76M
  }
yb::rpc::ConnectionContextFactoryImpl<yb::rpc::YBInboundConnectionContext>::Create(unsigned long)
Line
Count
Source
125
616k
  std::unique_ptr<ConnectionContext> Create(size_t receive_buffer_size) override {
126
616k
    return std::make_unique<ContextType>(receive_buffer_size, buffer_tracker_, call_tracker_);
127
616k
  }
yb::rpc::ConnectionContextFactoryImpl<yb::rpc::YBOutboundConnectionContext>::Create(unsigned long)
Line
Count
Source
125
3.13M
  std::unique_ptr<ConnectionContext> Create(size_t receive_buffer_size) override {
126
3.13M
    return std::make_unique<ContextType>(receive_buffer_size, buffer_tracker_, call_tracker_);
127
3.13M
  }
yb::rpc::ConnectionContextFactoryImpl<yb::cqlserver::CQLConnectionContext>::Create(unsigned long)
Line
Count
Source
125
10.0k
  std::unique_ptr<ConnectionContext> Create(size_t receive_buffer_size) override {
126
10.0k
    return std::make_unique<ContextType>(receive_buffer_size, buffer_tracker_, call_tracker_);
127
10.0k
  }
128
129
9.04k
  virtual ~ConnectionContextFactoryImpl() {}
yb::rpc::ConnectionContextFactoryImpl<yb::rpc::YBInboundConnectionContext>::~ConnectionContextFactoryImpl()
Line
Count
Source
129
339
  virtual ~ConnectionContextFactoryImpl() {}
yb::rpc::ConnectionContextFactoryImpl<yb::rpc::YBOutboundConnectionContext>::~ConnectionContextFactoryImpl()
Line
Count
Source
129
8.70k
  virtual ~ConnectionContextFactoryImpl() {}
Unexecuted instantiation: yb::rpc::ConnectionContextFactoryImpl<yb::cqlserver::CQLConnectionContext>::~ConnectionContextFactoryImpl()
130
};
131
132
template <class ContextType, class... Args>
133
58.7k
std::shared_ptr<ConnectionContextFactory> CreateConnectionContextFactory(Args&&... args) {
134
58.7k
  return std::make_shared<ConnectionContextFactoryImpl<ContextType>>(std::forward<Args>(args)...);
135
58.7k
}
std::__1::shared_ptr<yb::rpc::ConnectionContextFactory> yb::rpc::CreateConnectionContextFactory<yb::rpc::YBInboundConnectionContext, long long&, std::__1::shared_ptr<yb::MemTracker> const&>(long long&, std::__1::shared_ptr<yb::MemTracker> const&)
Line
Count
Source
133
9.27k
std::shared_ptr<ConnectionContextFactory> CreateConnectionContextFactory(Args&&... args) {
134
9.27k
  return std::make_shared<ConnectionContextFactoryImpl<ContextType>>(std::forward<Args>(args)...);
135
9.27k
}
std::__1::shared_ptr<yb::rpc::ConnectionContextFactory> yb::rpc::CreateConnectionContextFactory<yb::rpc::YBOutboundConnectionContext, long long&, std::__1::shared_ptr<yb::MemTracker> const&>(long long&, std::__1::shared_ptr<yb::MemTracker> const&)
Line
Count
Source
133
35.1k
std::shared_ptr<ConnectionContextFactory> CreateConnectionContextFactory(Args&&... args) {
134
35.1k
  return std::make_shared<ConnectionContextFactoryImpl<ContextType>>(std::forward<Args>(args)...);
135
35.1k
}
std::__1::shared_ptr<yb::rpc::ConnectionContextFactory> yb::rpc::CreateConnectionContextFactory<yb::rpc::YBInboundConnectionContext, long long, std::__1::shared_ptr<yb::MemTracker> const&>(long long&&, std::__1::shared_ptr<yb::MemTracker> const&)
Line
Count
Source
133
8.07k
std::shared_ptr<ConnectionContextFactory> CreateConnectionContextFactory(Args&&... args) {
134
8.07k
  return std::make_shared<ConnectionContextFactoryImpl<ContextType>>(std::forward<Args>(args)...);
135
8.07k
}
std::__1::shared_ptr<yb::rpc::ConnectionContextFactory> yb::rpc::CreateConnectionContextFactory<yb::rpc::YBInboundConnectionContext>()
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
}
std::__1::shared_ptr<yb::rpc::ConnectionContextFactory> yb::rpc::CreateConnectionContextFactory<yb::cqlserver::CQLConnectionContext, long long&, std::__1::shared_ptr<yb::MemTracker> >(long long&, std::__1::shared_ptr<yb::MemTracker>&&)
Line
Count
Source
133
6.11k
std::shared_ptr<ConnectionContextFactory> CreateConnectionContextFactory(Args&&... args) {
134
6.11k
  return std::make_shared<ConnectionContextFactoryImpl<ContextType>>(std::forward<Args>(args)...);
135
6.11k
}
136
137
} // namespace rpc
138
} // namespace yb
139
140
#endif // YB_RPC_CONNECTION_CONTEXT_H