YugabyteDB (2.13.1.0-b60, 21121d69985fbf76aa6958d8f04a9bfa936293b5)

Coverage Report

Created: 2022-03-22 16:43

/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
14.5M
      replicate_msg_(std::move(replicate_msg)) {
27
14.5M
  DCHECK_NOTNULL(replicate_msg_.get());
28
14.5M
}
29
30
void ConsensusRound::NotifyReplicationFinished(
31
14.5M
    const Status& status, int64_t leader_term, OpIds* applied_op_ids) {
32
14.5M
  callback_->ReplicationFinished(status, leader_term, applied_op_ids);
33
14.5M
}
34
35
5.04M
Status ConsensusRound::CheckBoundTerm(int64_t current_term) const {
36
5.04M
  if (PREDICT_FALSE(bound_term_ != current_term)) {
37
34
    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
34
    return STATUS_FORMAT(Aborted,
42
34
                         "Operation submitted in term $0 cannot be replicated in term $1",
43
34
                         bound_term_, current_term);
44
34
  }
45
5.04M
  return Status::OK();
46
5.04M
}
47
48
6
std::string ConsensusRound::ToString() const {
49
6
  return replicate_msg_->ShortDebugString();
50
6
}
51
52
99.3M
OpId ConsensusRound::id() const {
53
99.3M
  return OpId::FromPB(replicate_msg_->id());
54
99.3M
}
55
56
}  // namespace consensus
57
}  // namespace yb