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