/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 | 2.33k | Slice CompactionState::SmallestUserKey() { |
16 | 2.33k | for (const auto& sub_compact_state : sub_compact_states) { |
17 | 2.33k | Slice smallest = sub_compact_state.SmallestUserKey(); |
18 | 2.33k | if (!smallest.empty()) { |
19 | 419 | return smallest; |
20 | 419 | } |
21 | 2.33k | } |
22 | | // If there is no finished output, return an empty slice. |
23 | 1.91k | return Slice{nullptr, 0}; |
24 | 2.33k | } |
25 | | |
26 | 2.33k | Slice CompactionState::LargestUserKey() { |
27 | 3.97k | for (auto it = sub_compact_states.rbegin(); it < sub_compact_states.rend(); |
28 | 2.33k | ++it) { |
29 | 2.33k | Slice largest = it->LargestUserKey(); |
30 | 2.33k | if (!largest.empty()) { |
31 | 695 | return largest; |
32 | 695 | } |
33 | 2.33k | } |
34 | | // If there is no finished output, return an empty slice. |
35 | 1.64k | return Slice{nullptr, 0}; |
36 | 2.33k | } |
37 | | |
38 | | void CompactionState::AggregateCompactionStats( |
39 | | InternalStats::CompactionStatsFull& internal_stats, |
40 | 5.33k | CompactionJobStats& job_stats) { |
41 | 5.33k | for (const auto& sc : sub_compact_states) { |
42 | 5.33k | sc.AggregateCompactionOutputStats(internal_stats); |
43 | 5.33k | job_stats.Add(sc.compaction_job_stats); |
44 | 5.33k | } |
45 | 5.33k | } |
46 | | } // namespace ROCKSDB_NAMESPACE |