YugabyteDB (2.13.0.0-b42, bfc6a6643e7399ac8a0e81d06a3ee6d6571b33ab)

Coverage Report

Created: 2022-03-09 17:30

/Users/deen/code/yugabyte-db/src/yb/tablet/operations/history_cutoff_operation.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/tablet/operations/history_cutoff_operation.h"
15
16
#include "yb/consensus/consensus_round.h"
17
18
#include "yb/docdb/consensus_frontier.h"
19
20
#include "yb/rocksdb/db.h"
21
22
#include "yb/tablet/tablet.h"
23
#include "yb/tablet/tablet_retention_policy.h"
24
25
#include "yb/util/logging.h"
26
27
namespace yb {
28
namespace tablet {
29
30
template <>
31
void RequestTraits<consensus::HistoryCutoffPB>::SetAllocatedRequest(
32
0
    consensus::ReplicateMsg* replicate, consensus::HistoryCutoffPB* request) {
33
0
  replicate->set_allocated_history_cutoff(request);
34
0
}
35
36
template <>
37
consensus::HistoryCutoffPB* RequestTraits<consensus::HistoryCutoffPB>::MutableRequest(
38
0
    consensus::ReplicateMsg* replicate) {
39
0
  return replicate->mutable_history_cutoff();
40
0
}
41
42
0
Status HistoryCutoffOperation::Apply(int64_t leader_term) {
43
0
  HybridTime history_cutoff(request()->history_cutoff());
44
45
0
  VLOG_WITH_PREFIX(2) << "History cutoff replicated " << op_id() << ": " << history_cutoff;
46
47
0
  history_cutoff = tablet()->RetentionPolicy()->UpdateCommittedHistoryCutoff(history_cutoff);
48
0
  auto regular_db = tablet()->doc_db().regular;
49
0
  if (regular_db) {
50
0
    rocksdb::WriteBatch batch;
51
0
    docdb::ConsensusFrontiers frontiers;
52
0
    frontiers.Largest().set_history_cutoff(history_cutoff);
53
0
    batch.SetFrontiers(&frontiers);
54
0
    rocksdb::WriteOptions options;
55
0
    RETURN_NOT_OK(regular_db->Write(options, &batch));
56
0
  }
57
0
  return Status::OK();
58
0
}
59
60
0
Status HistoryCutoffOperation::Prepare() {
61
0
  VLOG_WITH_PREFIX(2) << "Prepare";
62
0
  return Status::OK();
63
0
}
64
65
0
Status HistoryCutoffOperation::DoReplicated(int64_t leader_term, Status* complete_status) {
66
0
  VLOG_WITH_PREFIX(2) << "Replicated";
67
68
0
  return Apply(leader_term);
69
0
}
70
71
0
Status HistoryCutoffOperation::DoAborted(const Status& status) {
72
0
  return status;
73
0
}
74
75
} // namespace tablet
76
} // namespace yb