/src/rocksdb/db/compaction/compaction_picker_fifo.h
Line | Count | Source |
1 | | // Copyright (c) 2011-present, Facebook, Inc. All rights reserved. |
2 | | // This source code is licensed under both the GPLv2 (found in the |
3 | | // COPYING file in the root directory) and Apache 2.0 License |
4 | | // (found in the LICENSE.Apache file in the root directory). |
5 | | // |
6 | | // Copyright (c) 2011 The LevelDB Authors. All rights reserved. |
7 | | // Use of this source code is governed by a BSD-style license that can be |
8 | | // found in the LICENSE file. See the AUTHORS file for names of contributors. |
9 | | |
10 | | #pragma once |
11 | | |
12 | | #include "db/compaction/compaction_picker.h" |
13 | | |
14 | | namespace ROCKSDB_NAMESPACE { |
15 | | class FIFOCompactionPicker : public CompactionPicker { |
16 | | public: |
17 | | FIFOCompactionPicker(const ImmutableOptions& ioptions, |
18 | | const InternalKeyComparator* icmp) |
19 | 0 | : CompactionPicker(ioptions, icmp) {} |
20 | | |
21 | | Compaction* PickCompaction( |
22 | | const std::string& cf_name, const MutableCFOptions& mutable_cf_options, |
23 | | const MutableDBOptions& mutable_db_options, |
24 | | const std::vector<SequenceNumber>& /* existing_snapshots */, |
25 | | const SnapshotChecker* /* snapshot_checker */, |
26 | | VersionStorageInfo* version, LogBuffer* log_buffer, |
27 | | const std::string& /* full_history_ts_low */, |
28 | | bool /* require_max_output_level*/ = false) override; |
29 | | |
30 | | Compaction* PickCompactionForCompactRange( |
31 | | const std::string& cf_name, const MutableCFOptions& mutable_cf_options, |
32 | | const MutableDBOptions& mutable_db_options, VersionStorageInfo* vstorage, |
33 | | int input_level, int output_level, |
34 | | const CompactRangeOptions& compact_range_options, |
35 | | const InternalKey* begin, const InternalKey* end, |
36 | | InternalKey** compaction_end, bool* manual_conflict, |
37 | | uint64_t max_file_num_to_ignore, const std::string& trim_ts, |
38 | | const std::string& full_history_ts_low) override; |
39 | | |
40 | | // The maximum allowed output level. Always returns 0. |
41 | 0 | int MaxOutputLevel() const override { return 0; } |
42 | | |
43 | | bool NeedsCompaction(const VersionStorageInfo* vstorage) const override; |
44 | | |
45 | | private: |
46 | | Compaction* PickTTLCompaction(const std::string& cf_name, |
47 | | const MutableCFOptions& mutable_cf_options, |
48 | | const MutableDBOptions& mutable_db_options, |
49 | | VersionStorageInfo* version, |
50 | | LogBuffer* log_buffer); |
51 | | |
52 | | Compaction* PickSizeCompaction(const std::string& cf_name, |
53 | | const MutableCFOptions& mutable_cf_options, |
54 | | const MutableDBOptions& mutable_db_options, |
55 | | VersionStorageInfo* version, |
56 | | LogBuffer* log_buffer); |
57 | | |
58 | | // Intra-L0 compaction: merges small L0 files to reduce file count. |
59 | | // Dispatches between two strategies based on configuration: |
60 | | // - use_kv_ratio_compaction = true: PickRatioBasedIntraL0Compaction |
61 | | // (BlobDB-optimized) |
62 | | // - use_kv_ratio_compaction = false: PickCostBasedIntraL0Compaction |
63 | | // (original) |
64 | | // Only active when allow_compaction = true. |
65 | | Compaction* PickIntraL0Compaction(const std::string& cf_name, |
66 | | const MutableCFOptions& mutable_cf_options, |
67 | | const MutableDBOptions& mutable_db_options, |
68 | | VersionStorageInfo* vstorage, |
69 | | LogBuffer* log_buffer); |
70 | | |
71 | | // Capacity-derived intra-L0 compaction for BlobDB workloads. |
72 | | // Uses the observed SST/blob ratio to compute a target file size, |
73 | | // producing uniform files for predictable FIFO trimming. |
74 | | // Called from PickIntraL0Compaction when use_kv_ratio_compaction = true. |
75 | | Compaction* PickRatioBasedIntraL0Compaction( |
76 | | const std::string& cf_name, const MutableCFOptions& mutable_cf_options, |
77 | | const MutableDBOptions& mutable_db_options, VersionStorageInfo* vstorage, |
78 | | LogBuffer* log_buffer); |
79 | | |
80 | | // Will pick one file to compact at a time, starting from the oldest file. |
81 | | Compaction* PickTemperatureChangeCompaction( |
82 | | const std::string& cf_name, const MutableCFOptions& mutable_cf_options, |
83 | | const MutableDBOptions& mutable_db_options, VersionStorageInfo* vstorage, |
84 | | LogBuffer* log_buffer) const; |
85 | | }; |
86 | | } // namespace ROCKSDB_NAMESPACE |