/Users/deen/code/yugabyte-db/src/yb/consensus/replicate_msgs_holder.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_CONSENSUS_REPLICATE_MSGS_HOLDER_H |
15 | | #define YB_CONSENSUS_REPLICATE_MSGS_HOLDER_H |
16 | | |
17 | | #include <google/protobuf/repeated_field.h> |
18 | | |
19 | | #include "yb/consensus/consensus_fwd.h" |
20 | | |
21 | | #include "yb/util/mem_tracker.h" |
22 | | |
23 | | namespace yb { |
24 | | namespace consensus { |
25 | | |
26 | | class ReplicateMsgsHolder { |
27 | | public: |
28 | 13.3M | ReplicateMsgsHolder() : ops_(nullptr) {} |
29 | | |
30 | | explicit ReplicateMsgsHolder( |
31 | | google::protobuf::RepeatedPtrField<ReplicateMsg>* ops, ReplicateMsgs messages, |
32 | | ScopedTrackedConsumption consumption); |
33 | | |
34 | | ReplicateMsgsHolder(ReplicateMsgsHolder&& rhs); |
35 | | void operator=(ReplicateMsgsHolder&& rhs); |
36 | | |
37 | | ReplicateMsgsHolder(const ReplicateMsgsHolder&) = delete; |
38 | | |
39 | | void operator=(const ReplicateMsgsHolder&) = delete; |
40 | | |
41 | | ~ReplicateMsgsHolder(); |
42 | | |
43 | | void Reset(); |
44 | | |
45 | 10.3M | void ReleaseOps() { |
46 | 10.3M | ops_ = nullptr; |
47 | 10.3M | } |
48 | | |
49 | | private: |
50 | | google::protobuf::RepeatedPtrField<ReplicateMsg>* ops_; |
51 | | |
52 | | // Reference-counted pointers to any ReplicateMsgs which are in-flight to the peer. We may have |
53 | | // loaded these messages from the LogCache, in which case we are potentially sharing the same |
54 | | // object as other peers. Since the PB request_ itself can't hold reference counts, this holds |
55 | | // them. |
56 | | ReplicateMsgs messages_; |
57 | | |
58 | | ScopedTrackedConsumption consumption_; |
59 | | }; |
60 | | |
61 | | } // namespace consensus |
62 | | } // namespace yb |
63 | | |
64 | | #endif // YB_CONSENSUS_REPLICATE_MSGS_HOLDER_H |