/Users/deen/code/yugabyte-db/src/yb/tablet/tablet_peer_mm_ops.cc
Line | Count | Source (jump to first uncovered line) |
1 | | // Licensed to the Apache Software Foundation (ASF) under one |
2 | | // or more contributor license agreements. See the NOTICE file |
3 | | // distributed with this work for additional information |
4 | | // regarding copyright ownership. The ASF licenses this file |
5 | | // to you under the Apache License, Version 2.0 (the |
6 | | // "License"); you may not use this file except in compliance |
7 | | // with the License. You may obtain a copy of the License at |
8 | | // |
9 | | // http://www.apache.org/licenses/LICENSE-2.0 |
10 | | // |
11 | | // Unless required by applicable law or agreed to in writing, |
12 | | // software distributed under the License is distributed on an |
13 | | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
14 | | // KIND, either express or implied. See the License for the |
15 | | // specific language governing permissions and limitations |
16 | | // under the License. |
17 | | // |
18 | | // The following only applies to changes made to this file as part of YugaByte development. |
19 | | // |
20 | | // Portions Copyright (c) YugaByte, Inc. |
21 | | // |
22 | | // Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except |
23 | | // in compliance with the License. You may obtain a copy of the License at |
24 | | // |
25 | | // http://www.apache.org/licenses/LICENSE-2.0 |
26 | | // |
27 | | // Unless required by applicable law or agreed to in writing, software distributed under the License |
28 | | // is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express |
29 | | // or implied. See the License for the specific language governing permissions and limitations |
30 | | // under the License. |
31 | | // |
32 | | |
33 | | #include "yb/tablet/tablet_peer_mm_ops.h" |
34 | | |
35 | | #include <algorithm> |
36 | | #include <map> |
37 | | #include <mutex> |
38 | | #include <string> |
39 | | |
40 | | #include <gflags/gflags.h> |
41 | | |
42 | | #include "yb/tablet/maintenance_manager.h" |
43 | | #include "yb/tablet/tablet.h" |
44 | | #include "yb/tablet/tablet_peer.h" |
45 | | |
46 | | #include "yb/util/metrics.h" |
47 | | #include "yb/util/logging.h" |
48 | | |
49 | | METRIC_DEFINE_gauge_uint32(table, log_gc_running, |
50 | | "Log GCs Running", |
51 | | yb::MetricUnit::kOperations, |
52 | | "Number of log GC operations currently running."); |
53 | | METRIC_DEFINE_coarse_histogram(table, log_gc_duration, |
54 | | "Log GC Duration", |
55 | | yb::MetricUnit::kMilliseconds, |
56 | | "Time spent garbage collecting the logs."); |
57 | | |
58 | | namespace yb { |
59 | | namespace tablet { |
60 | | |
61 | | using std::map; |
62 | | using strings::Substitute; |
63 | | |
64 | | // |
65 | | // LogGCOp. |
66 | | // |
67 | | |
68 | | LogGCOp::LogGCOp(TabletPeer* tablet_peer) |
69 | | : MaintenanceOp( |
70 | | StringPrintf("LogGCOp(%s)", tablet_peer->tablet()->tablet_id().c_str()), |
71 | | MaintenanceOp::LOW_IO_USAGE), |
72 | | tablet_peer_(tablet_peer), |
73 | | log_gc_duration_( |
74 | | METRIC_log_gc_duration.Instantiate(tablet_peer->tablet()->GetTableMetricsEntity())), |
75 | | log_gc_running_( |
76 | | METRIC_log_gc_running.Instantiate(tablet_peer->tablet()->GetTableMetricsEntity(), 0)), |
77 | 150k | sem_(1) {} |
78 | | |
79 | 50.4M | void LogGCOp::UpdateStats(MaintenanceOpStats* stats) { |
80 | 50.4M | int64_t retention_size = 0; |
81 | | |
82 | 50.4M | auto status = tablet_peer_->GetGCableDataSize(&retention_size); |
83 | 50.4M | if (!status.ok()) { |
84 | 600 | YB_LOG_EVERY_N_SECS(WARNING, 1) |
85 | 139 | << tablet_peer_->LogPrefix() |
86 | 139 | << "failed to get GC-able data size: " << status; |
87 | 600 | return; |
88 | 600 | } |
89 | 50.4M | stats->set_logs_retained_bytes(retention_size); |
90 | 50.4M | stats->set_runnable(sem_.GetValue() == 1); |
91 | 50.4M | } |
92 | | |
93 | 11 | bool LogGCOp::Prepare() { |
94 | 11 | return sem_.try_lock(); |
95 | 11 | } |
96 | | |
97 | 11 | void LogGCOp::Perform() { |
98 | 11 | CHECK(!sem_.try_lock()); |
99 | | |
100 | 11 | Status s = tablet_peer_->RunLogGC(); |
101 | 11 | if (!s.ok()) { |
102 | 0 | s = s.CloneAndPrepend("Unexpected error while running Log GC from TabletPeer"); |
103 | 0 | LOG(ERROR) << s.ToString(); |
104 | 0 | } |
105 | | |
106 | 11 | sem_.unlock(); |
107 | 11 | } |
108 | | |
109 | 11 | scoped_refptr<Histogram> LogGCOp::DurationHistogram() const { |
110 | 11 | return log_gc_duration_; |
111 | 11 | } |
112 | | |
113 | 22 | scoped_refptr<AtomicGauge<uint32_t> > LogGCOp::RunningGauge() const { |
114 | 22 | return log_gc_running_; |
115 | 22 | } |
116 | | |
117 | | } // namespace tablet |
118 | | } // namespace yb |