/Users/deen/code/yugabyte-db/src/yb/consensus/replicate_msgs_holder.cc
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 | | #include "yb/consensus/replicate_msgs_holder.h" |
15 | | |
16 | | namespace yb { |
17 | | namespace consensus { |
18 | | |
19 | | ReplicateMsgsHolder::ReplicateMsgsHolder( |
20 | | google::protobuf::RepeatedPtrField<ReplicateMsg>* ops, ReplicateMsgs messages, |
21 | | ScopedTrackedConsumption consumption) |
22 | 10.2M | : ops_(ops), messages_(std::move(messages)), consumption_(std::move(consumption)) { |
23 | 10.2M | } |
24 | | |
25 | | ReplicateMsgsHolder::ReplicateMsgsHolder(ReplicateMsgsHolder&& rhs) |
26 | | : ops_(rhs.ops_), messages_(std::move(rhs.messages_)), |
27 | 0 | consumption_(std::move(rhs.consumption_)) { |
28 | 0 | rhs.ops_ = nullptr; |
29 | 0 | } |
30 | | |
31 | 10.2M | void ReplicateMsgsHolder::operator=(ReplicateMsgsHolder&& rhs) { |
32 | 10.2M | Reset(); |
33 | 10.2M | ops_ = rhs.ops_; |
34 | 10.2M | messages_ = std::move(rhs.messages_); |
35 | 10.2M | consumption_ = std::move(rhs.consumption_); |
36 | 10.2M | rhs.ops_ = nullptr; |
37 | 10.2M | } |
38 | | |
39 | 23.6M | ReplicateMsgsHolder::~ReplicateMsgsHolder() { |
40 | 23.6M | Reset(); |
41 | 23.6M | } |
42 | | |
43 | 33.8M | void ReplicateMsgsHolder::Reset() { |
44 | 33.8M | if (ops_) { |
45 | 10.5k | ops_->ExtractSubrange(0, ops_->size(), nullptr /* elements */); |
46 | 10.5k | ops_ = nullptr; |
47 | 10.5k | } |
48 | | |
49 | 33.8M | messages_.clear(); |
50 | 33.8M | consumption_ = ScopedTrackedConsumption(); |
51 | 33.8M | } |
52 | | |
53 | | } // namespace consensus |
54 | | } // namespace yb |