YugabyteDB (2.13.1.0-b60, 21121d69985fbf76aa6958d8f04a9bfa936293b5)

Coverage Report

Created: 2022-03-22 16:43

/Users/deen/code/yugabyte-db/src/yb/client/forward_rpc.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_CLIENT_FORWARD_RPC_H_
15
#define YB_CLIENT_FORWARD_RPC_H_
16
17
#include "yb/client/tablet_rpc.h"
18
19
#include "yb/common/common_types.pb.h"
20
21
#include "yb/rpc/rpc_fwd.h"
22
#include "yb/rpc/rpc_context.h"
23
24
namespace yb {
25
namespace client {
26
27
class YBClient;
28
29
namespace internal {
30
31
template <class Req, class Resp>
32
class ForwardRpc : public rpc::Rpc, public TabletRpc {
33
 public:
34
  ForwardRpc(const Req *req, Resp *res, rpc::RpcContext &&context,
35
             YBConsistencyLevel consistency_level,
36
             YBClient *client);
37
38
  virtual ~ForwardRpc();
39
40
  void SendRpc() override;
41
42
  std::string ToString() const override;
43
44
  const RemoteTablet& tablet() const { return *tablet_invoker_.tablet(); }
45
46
0
  const tserver::TabletServerErrorPB* response_error() const override {
47
0
    return res_->has_error() ? &res_->error() : nullptr;
48
0
  }
Unexecuted instantiation: yb::client::internal::ForwardRpc<yb::tserver::WriteRequestPB, yb::tserver::WriteResponsePB>::response_error() const
Unexecuted instantiation: yb::client::internal::ForwardRpc<yb::tserver::ReadRequestPB, yb::tserver::ReadResponsePB>::response_error() const
49
50
 protected:
51
  void Finished(const Status& status) override;
52
53
  void Failed(const Status& status) override;
54
55
  virtual void SendRpcToTserver(int attempt_num) override = 0;
56
57
  virtual bool read_only() const = 0;
58
59
  virtual void PopulateResponse() = 0;
60
61
 protected:
62
  // The request protobuf.
63
  const Req *req_;
64
65
  // The response protobuf.
66
  Resp *res_;
67
68
  // The rpc context for the current rpc.
69
  rpc::RpcContext context_;
70
71
  // The trace buffer.
72
  scoped_refptr<Trace> trace_;
73
74
  MonoTime start_;
75
76
  // The invoker that sends the request to the appropriate tablet server.
77
  TabletInvoker tablet_invoker_;
78
79
  rpc::RpcCommandPtr retained_self_;
80
};
81
82
class ForwardWriteRpc : public ForwardRpc<tserver::WriteRequestPB, tserver::WriteResponsePB> {
83
 public:
84
  explicit ForwardWriteRpc(const tserver::WriteRequestPB *req,
85
                           tserver::WriteResponsePB *resp,
86
                           rpc::RpcContext &&context,
87
                           YBClient *client);
88
89
  virtual ~ForwardWriteRpc();
90
91
 private:
92
  void SendRpcToTserver(int attempt_num) override;
93
94
  void PopulateResponse() override;
95
96
0
  bool read_only() const override {
97
0
    return false;
98
0
  }
99
};
100
101
class ForwardReadRpc : public ForwardRpc<tserver::ReadRequestPB, tserver::ReadResponsePB> {
102
 public:
103
  explicit ForwardReadRpc(const tserver::ReadRequestPB *req,
104
                          tserver::ReadResponsePB *res,
105
                          rpc::RpcContext&& context,
106
                          YBClient *client);
107
108
  virtual ~ForwardReadRpc();
109
110
 private:
111
  void SendRpcToTserver(int attempt_num) override;
112
113
  void PopulateResponse() override;
114
115
0
  bool read_only() const override {
116
0
    return true;
117
0
  }
118
};
119
120
}  // namespace internal
121
}  // namespace client
122
}  // namespace yb
123
124
#endif  // YB_CLIENT_FORWARD_RPC_H_