YugabyteDB (2.13.1.0-b60, 21121d69985fbf76aa6958d8f04a9bfa936293b5)

Coverage Report

Created: 2022-03-22 16:43

/Users/deen/code/yugabyte-db/src/yb/rpc/binary_call_parser.h
Line
Count
Source
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_BINARY_CALL_PARSER_H
15
#define YB_RPC_BINARY_CALL_PARSER_H
16
17
#include "yb/util/mem_tracker.h"
18
#include "yb/util/net/socket.h"
19
#include "yb/util/strongly_typed_bool.h"
20
21
#include "yb/rpc/rpc_fwd.h"
22
#include "yb/rpc/call_data.h"
23
24
namespace yb {
25
namespace rpc {
26
27
YB_STRONGLY_TYPED_BOOL(IncludeHeader);
28
YB_STRONGLY_TYPED_BOOL(SkipEmptyMessages);
29
30
// Listener of BinaryCallParser, invoked when call is parsed.
31
class BinaryCallParserListener {
32
 public:
33
  virtual CHECKED_STATUS HandleCall(const ConnectionPtr& connection, CallData* call_data) = 0;
34
 protected:
35
3.25M
  ~BinaryCallParserListener() {}
36
};
37
38
// Utility class to parse binary calls with fixed length header.
39
class BinaryCallParser {
40
 public:
41
  explicit BinaryCallParser(const MemTrackerPtr& parent_tracker,
42
                            size_t header_size, size_t size_offset, size_t max_message_length,
43
                            IncludeHeader include_header, SkipEmptyMessages skip_empty_messages,
44
                            BinaryCallParserListener* listener);
45
46
  // If tracker_for_throttle is not nullptr - throttle big requests when tracker_for_throttle
47
  // (or any of its ancestors) exceeds soft memory limit.
48
  Result<ProcessCallsResult> Parse(const rpc::ConnectionPtr& connection, const IoVecs& data,
49
                                   ReadBufferFull read_buffer_full,
50
                                   const MemTrackerPtr* tracker_for_throttle);
51
52
 private:
53
  MemTrackerPtr buffer_tracker_;
54
  std::vector<char> call_header_buffer_;
55
  ScopedTrackedConsumption call_data_consumption_;
56
  CallData call_data_;
57
  const size_t size_offset_;
58
  const size_t max_message_length_;
59
  const IncludeHeader include_header_;
60
  const SkipEmptyMessages skip_empty_messages_;
61
  BinaryCallParserListener* const listener_;
62
};
63
64
// Returns whether we should throttle RPC call based on its size and memory consumption.
65
// Uses specified throttle_message when logging a warning about throttling an RPC call.
66
bool ShouldThrottleRpc(
67
    const MemTrackerPtr& throttle_tracker, ssize_t call_data_size, const char* throttle_message);
68
69
} // namespace rpc
70
} // namespace yb
71
72
#endif // YB_RPC_BINARY_CALL_PARSER_H