]> git.proxmox.com Git - ceph.git/blob - ceph/src/rocksdb/include/rocksdb/universal_compaction.h
update ceph source to reef 18.1.2
[ceph.git] / ceph / src / rocksdb / include / rocksdb / universal_compaction.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
8 #include <climits>
9 #include <cstdint>
10 #include <vector>
11
12 #include "rocksdb/rocksdb_namespace.h"
13
14 namespace ROCKSDB_NAMESPACE {
15
16 //
17 // Algorithm used to make a compaction request stop picking new files
18 // into a single compaction run
19 //
20 enum CompactionStopStyle {
21 kCompactionStopStyleSimilarSize, // pick files of similar size
22 kCompactionStopStyleTotalSize // total size of picked files > next file
23 };
24
25 class CompactionOptionsUniversal {
26 public:
27 // Percentage flexibility while comparing file size. If the candidate file(s)
28 // size is 1% smaller than the next file's size, then include next file into
29 // this candidate set. // Default: 1
30 unsigned int size_ratio;
31
32 // The minimum number of files in a single compaction run. Default: 2
33 unsigned int min_merge_width;
34
35 // The maximum number of files in a single compaction run. Default: UINT_MAX
36 unsigned int max_merge_width;
37
38 // The size amplification is defined as the amount (in percentage) of
39 // additional storage needed to store a single byte of data in the database.
40 // For example, a size amplification of 2% means that a database that
41 // contains 100 bytes of user-data may occupy up to 102 bytes of
42 // physical storage. By this definition, a fully compacted database has
43 // a size amplification of 0%. Rocksdb uses the following heuristic
44 // to calculate size amplification: it assumes that all files excluding
45 // the earliest file contribute to the size amplification.
46 // Default: 200, which means that a 100 byte database could require up to
47 // 300 bytes of storage.
48 unsigned int max_size_amplification_percent;
49
50 // If this option is set to be -1 (the default value), all the output files
51 // will follow compression type specified.
52 //
53 // If this option is not negative, we will try to make sure compressed
54 // size is just above this value. In normal cases, at least this percentage
55 // of data will be compressed.
56 // When we are compacting to a new file, here is the criteria whether
57 // it needs to be compressed: assuming here are the list of files sorted
58 // by generation time:
59 // A1...An B1...Bm C1...Ct
60 // where A1 is the newest and Ct is the oldest, and we are going to compact
61 // B1...Bm, we calculate the total size of all the files as total_size, as
62 // well as the total size of C1...Ct as total_C, the compaction output file
63 // will be compressed iff
64 // total_C / total_size < this percentage
65 // Default: -1
66 int compression_size_percent;
67
68 // The algorithm used to stop picking files into a single compaction run
69 // Default: kCompactionStopStyleTotalSize
70 CompactionStopStyle stop_style;
71
72 // Option to optimize the universal multi level compaction by enabling
73 // trivial move for non overlapping files.
74 // Default: false
75 bool allow_trivial_move;
76
77 // EXPERIMENTAL
78 // If true, try to limit compaction size under max_compaction_bytes.
79 // This might cause higher write amplification, but can prevent some
80 // problem caused by large compactions.
81 // Default: false
82 bool incremental;
83
84 // Default set of parameters
85 CompactionOptionsUniversal()
86 : size_ratio(1),
87 min_merge_width(2),
88 max_merge_width(UINT_MAX),
89 max_size_amplification_percent(200),
90 compression_size_percent(-1),
91 stop_style(kCompactionStopStyleTotalSize),
92 allow_trivial_move(false),
93 incremental(false) {}
94 };
95
96 } // namespace ROCKSDB_NAMESPACE