]> git.proxmox.com Git - ceph.git/blob - ceph/src/rocksdb/include/rocksdb/utilities/table_properties_collectors.h
update ceph source to reef 18.1.2
[ceph.git] / ceph / src / rocksdb / include / rocksdb / utilities / table_properties_collectors.h
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 #pragma once
7 #ifndef ROCKSDB_LITE
8 #include <atomic>
9 #include <memory>
10
11 #include "rocksdb/table_properties.h"
12
13 namespace ROCKSDB_NAMESPACE {
14
15 // A factory of a table property collector that marks a SST
16 // file as need-compaction when it observe at least "D" deletion
17 // entries in any "N" consecutive entries or the ratio of tombstone
18 // entries in the whole file >= the specified deletion ratio.
19 class CompactOnDeletionCollectorFactory
20 : public TablePropertiesCollectorFactory {
21 public:
22 // A factory of a table property collector that marks a SST
23 // file as need-compaction when it observe at least "D" deletion
24 // entries in any "N" consecutive entries, or the ratio of tombstone
25 // entries >= deletion_ratio.
26 //
27 // @param sliding_window_size "N"
28 // @param deletion_trigger "D"
29 // @param deletion_ratio, if <= 0 or > 1, disable triggering compaction
30 // based on deletion ratio.
31 CompactOnDeletionCollectorFactory(size_t sliding_window_size,
32 size_t deletion_trigger,
33 double deletion_ratio);
34
35 ~CompactOnDeletionCollectorFactory() {}
36
37 TablePropertiesCollector* CreateTablePropertiesCollector(
38 TablePropertiesCollectorFactory::Context context) override;
39
40 // Change the value of sliding_window_size "N"
41 // Setting it to 0 disables the delete triggered compaction
42 void SetWindowSize(size_t sliding_window_size) {
43 sliding_window_size_.store(sliding_window_size);
44 }
45 size_t GetWindowSize() const { return sliding_window_size_.load(); }
46
47 // Change the value of deletion_trigger "D"
48 void SetDeletionTrigger(size_t deletion_trigger) {
49 deletion_trigger_.store(deletion_trigger);
50 }
51
52 size_t GetDeletionTrigger() const { return deletion_trigger_.load(); }
53 // Change deletion ratio.
54 // @param deletion_ratio, if <= 0 or > 1, disable triggering compaction
55 // based on deletion ratio.
56 void SetDeletionRatio(double deletion_ratio) {
57 deletion_ratio_.store(deletion_ratio);
58 }
59
60 double GetDeletionRatio() const { return deletion_ratio_.load(); }
61 static const char* kClassName() { return "CompactOnDeletionCollector"; }
62 const char* Name() const override { return kClassName(); }
63
64 std::string ToString() const override;
65
66 private:
67 std::atomic<size_t> sliding_window_size_;
68 std::atomic<size_t> deletion_trigger_;
69 std::atomic<double> deletion_ratio_;
70 };
71
72 // Creates a factory of a table property collector that marks a SST
73 // file as need-compaction when it observe at least "D" deletion
74 // entries in any "N" consecutive entries, or the ratio of tombstone
75 // entries >= deletion_ratio.
76 //
77 // @param sliding_window_size "N". Note that this number will be
78 // round up to the smallest multiple of 128 that is no less
79 // than the specified size.
80 // @param deletion_trigger "D". Note that even when "N" is changed,
81 // the specified number for "D" will not be changed.
82 // @param deletion_ratio, if <= 0 or > 1, disable triggering compaction
83 // based on deletion ratio. Disabled by default.
84 extern std::shared_ptr<CompactOnDeletionCollectorFactory>
85 NewCompactOnDeletionCollectorFactory(size_t sliding_window_size,
86 size_t deletion_trigger,
87 double deletion_ratio = 0);
88 } // namespace ROCKSDB_NAMESPACE
89
90 #endif // !ROCKSDB_LITE