/Users/deen/code/yugabyte-db/src/yb/consensus/consensus_round.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 | | #include "yb/consensus/consensus_round.h" |
14 | | |
15 | | #include "yb/consensus/consensus.pb.h" |
16 | | #include "yb/util/status.h" |
17 | | #include "yb/util/status_format.h" |
18 | | #include "yb/util/status_log.h" |
19 | | |
20 | | namespace yb { |
21 | | namespace consensus { |
22 | | |
23 | | ConsensusRound::ConsensusRound(Consensus* consensus, |
24 | | ReplicateMsgPtr replicate_msg) |
25 | | : consensus_(consensus), |
26 | 7.90M | replicate_msg_(std::move(replicate_msg)) { |
27 | 7.90M | DCHECK_NOTNULL(replicate_msg_.get()); |
28 | 7.90M | } |
29 | | |
30 | | void ConsensusRound::NotifyReplicationFinished( |
31 | 7.90M | const Status& status, int64_t leader_term, OpIds* applied_op_ids) { |
32 | 7.90M | callback_->ReplicationFinished(status, leader_term, applied_op_ids); |
33 | 7.90M | } |
34 | | |
35 | 2.70M | Status ConsensusRound::CheckBoundTerm(int64_t current_term) const { |
36 | 2.70M | if (PREDICT_FALSE(bound_term_ != current_term)) { |
37 | 2 | if (bound_term_ == OpId::kUnknownTerm) { |
38 | 0 | return STATUS_FORMAT( |
39 | 0 | Aborted, "Attempt to submit operation with unbound term, current term: $0", current_term); |
40 | 0 | } |
41 | 2 | return STATUS_FORMAT(Aborted, |
42 | 2 | "Operation submitted in term $0 cannot be replicated in term $1", |
43 | 2 | bound_term_, current_term); |
44 | 2 | } |
45 | 2.70M | return Status::OK(); |
46 | 2.70M | } |
47 | | |
48 | 4 | std::string ConsensusRound::ToString() const { |
49 | 4 | return replicate_msg_->ShortDebugString(); |
50 | 4 | } |
51 | | |
52 | 53.8M | OpId ConsensusRound::id() const { |
53 | 53.8M | return OpId::FromPB(replicate_msg_->id()); |
54 | 53.8M | } |
55 | | |
56 | | } // namespace consensus |
57 | | } // namespace yb |