/src/rocksdb/db/compaction/compaction_state.cc
Line | Count | Source |
1 | | // Copyright (c) Meta Platforms, Inc. and affiliates. |
2 | | // |
3 | | // This source code is licensed under both the GPLv2 (found in the |
4 | | // COPYING file in the root directory) and Apache 2.0 License |
5 | | // (found in the LICENSE.Apache file in the root directory). |
6 | | // |
7 | | // Copyright (c) 2011 The LevelDB Authors. All rights reserved. |
8 | | // Use of this source code is governed by a BSD-style license that can be |
9 | | // found in the LICENSE file. See the AUTHORS file for names of contributors. |
10 | | |
11 | | #include "db/compaction/compaction_state.h" |
12 | | |
13 | | namespace ROCKSDB_NAMESPACE { |
14 | | |
15 | 1.29k | Slice CompactionState::SmallestUserKey() { |
16 | 1.29k | for (const auto& sub_compact_state : sub_compact_states) { |
17 | 1.29k | Slice smallest = sub_compact_state.SmallestUserKey(); |
18 | 1.29k | if (!smallest.empty()) { |
19 | 190 | return smallest; |
20 | 190 | } |
21 | 1.29k | } |
22 | | // If there is no finished output, return an empty slice. |
23 | 1.10k | return Slice{nullptr, 0}; |
24 | 1.29k | } |
25 | | |
26 | 1.29k | Slice CompactionState::LargestUserKey() { |
27 | 2.23k | for (auto it = sub_compact_states.rbegin(); it < sub_compact_states.rend(); |
28 | 1.29k | ++it) { |
29 | 1.29k | Slice largest = it->LargestUserKey(); |
30 | 1.29k | if (!largest.empty()) { |
31 | 352 | return largest; |
32 | 352 | } |
33 | 1.29k | } |
34 | | // If there is no finished output, return an empty slice. |
35 | 941 | return Slice{nullptr, 0}; |
36 | 1.29k | } |
37 | | |
38 | | void CompactionState::AggregateCompactionStats( |
39 | | InternalStats::CompactionStatsFull& compaction_stats, |
40 | 2.16k | CompactionJobStats& compaction_job_stats) { |
41 | 2.16k | for (const auto& sc : sub_compact_states) { |
42 | 2.16k | sc.AggregateCompactionStats(compaction_stats); |
43 | 2.16k | compaction_job_stats.Add(sc.compaction_job_stats); |
44 | 2.16k | } |
45 | 2.16k | } |
46 | | } // namespace ROCKSDB_NAMESPACE |