/Users/deen/code/yugabyte-db/src/yb/rocksdb/util/mutable_cf_options.cc
Line | Count | Source (jump to first uncovered line) |
1 | | // Copyright (c) 2011-present, Facebook, Inc. All rights reserved. |
2 | | // This source code is licensed under the BSD-style license found in the |
3 | | // LICENSE file in the root directory of this source tree. An additional grant |
4 | | // of patent rights can be found in the PATENTS file in the same directory. |
5 | | // |
6 | | // The following only applies to changes made to this file as part of YugaByte development. |
7 | | // |
8 | | // Portions Copyright (c) YugaByte, Inc. |
9 | | // |
10 | | // Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except |
11 | | // in compliance with the License. You may obtain a copy of the License at |
12 | | // |
13 | | // http://www.apache.org/licenses/LICENSE-2.0 |
14 | | // |
15 | | // Unless required by applicable law or agreed to in writing, software distributed under the License |
16 | | // is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express |
17 | | // or implied. See the License for the specific language governing permissions and limitations |
18 | | // under the License. |
19 | | // |
20 | | |
21 | | #include "yb/rocksdb/util/mutable_cf_options.h" |
22 | | |
23 | | #ifndef __STDC_FORMAT_MACROS |
24 | | #define __STDC_FORMAT_MACROS |
25 | | #endif |
26 | | |
27 | | #include <inttypes.h> |
28 | | #include <limits> |
29 | | #include <string> |
30 | | #include "yb/rocksdb/port/port.h" |
31 | | #include "yb/rocksdb/env.h" |
32 | | #include "yb/rocksdb/options.h" |
33 | | #include "yb/rocksdb/immutable_options.h" |
34 | | |
35 | | namespace rocksdb { |
36 | | |
37 | | // Multiple two operands. If they overflow, return op1. |
38 | 2.66M | uint64_t MultiplyCheckOverflow(uint64_t op1, int op2) { |
39 | 2.66M | if (op1 == 0) { |
40 | 0 | return 0; |
41 | 0 | } |
42 | 2.66M | if (op2 <= 0) { |
43 | 0 | return op1; |
44 | 0 | } |
45 | 2.66M | uint64_t casted_op2 = (uint64_t) op2; |
46 | 2.66M | if (std::numeric_limits<uint64_t>::max() / op1 < casted_op2) { |
47 | 2.34k | return op1; |
48 | 2.34k | } |
49 | 2.66M | return op1 * casted_op2; |
50 | 2.66M | } |
51 | | |
52 | | void MutableCFOptions::RefreshDerivedOptions( |
53 | 1.35M | const ImmutableCFOptions& ioptions) { |
54 | 1.35M | max_file_size.resize(ioptions.num_levels); |
55 | 4.89M | for (int i = 0; i < ioptions.num_levels; ++i) { |
56 | 3.54M | if (i == 0 && ioptions.compaction_style == kCompactionStyleUniversal) { |
57 | 988k | max_file_size[i] = ULLONG_MAX; |
58 | 2.55M | } else if (i > 1) { |
59 | 1.82M | max_file_size[i] = MultiplyCheckOverflow(max_file_size[i - 1], |
60 | 1.82M | target_file_size_multiplier); |
61 | 728k | } else { |
62 | 728k | max_file_size[i] = target_file_size_base; |
63 | 728k | } |
64 | 3.54M | } |
65 | 1.35M | } |
66 | | |
67 | 50.3k | uint64_t MutableCFOptions::MaxFileSizeForLevel(int level) const { |
68 | 50.3k | assert(level >= 0); |
69 | 50.3k | assert(level < static_cast<int>(max_file_size.size())); |
70 | 50.3k | return max_file_size[level]; |
71 | 50.3k | } |
72 | | |
73 | 1.01M | uint64_t MutableCFOptions::MaxFileSizeForCompaction() const { |
74 | 1.01M | if (!max_file_size_for_compaction) { |
75 | 110k | return std::numeric_limits<uint64_t>::max(); |
76 | 110k | } |
77 | 904k | return (*max_file_size_for_compaction)(); |
78 | 904k | } |
79 | | |
80 | 18.4k | uint64_t MutableCFOptions::MaxGrandParentOverlapBytes(int level) const { |
81 | 18.4k | return MaxFileSizeForLevel(level) * max_grandparent_overlap_factor; |
82 | 18.4k | } |
83 | 5.41k | uint64_t MutableCFOptions::ExpandedCompactionByteSizeLimit(int level) const { |
84 | 5.41k | return MaxFileSizeForLevel(level) * expanded_compaction_factor; |
85 | 5.41k | } |
86 | | |
87 | 28 | void MutableCFOptions::Dump(Logger* log) const { |
88 | | // Memtable related options |
89 | 28 | RLOG(log, " write_buffer_size: %" ROCKSDB_PRIszt, |
90 | 28 | write_buffer_size); |
91 | 28 | RLOG(log, " max_write_buffer_number: %d", |
92 | 28 | max_write_buffer_number); |
93 | 28 | RLOG(log, " arena_block_size: %" ROCKSDB_PRIszt, |
94 | 28 | arena_block_size); |
95 | 28 | RLOG(log, " memtable_prefix_bloom_bits: %" PRIu32, |
96 | 28 | memtable_prefix_bloom_bits); |
97 | 28 | RLOG(log, " memtable_prefix_bloom_probes: %" PRIu32, |
98 | 28 | memtable_prefix_bloom_probes); |
99 | 28 | RLOG(log, " memtable_prefix_bloom_huge_page_tlb_size: %" ROCKSDB_PRIszt, |
100 | 28 | memtable_prefix_bloom_huge_page_tlb_size); |
101 | 28 | RLOG(log, " max_successive_merges: %" ROCKSDB_PRIszt, |
102 | 28 | max_successive_merges); |
103 | 28 | RLOG(log, " filter_deletes: %d", |
104 | 28 | filter_deletes); |
105 | 28 | RLOG(log, " disable_auto_compactions: %d", |
106 | 28 | disable_auto_compactions); |
107 | 28 | RLOG(log, " soft_pending_compaction_bytes_limit: %" PRIu64, |
108 | 28 | soft_pending_compaction_bytes_limit); |
109 | 28 | RLOG(log, " hard_pending_compaction_bytes_limit: %" PRIu64, |
110 | 28 | hard_pending_compaction_bytes_limit); |
111 | 28 | RLOG(log, " level0_file_num_compaction_trigger: %d", |
112 | 28 | level0_file_num_compaction_trigger); |
113 | 28 | RLOG(log, " level0_slowdown_writes_trigger: %d", |
114 | 28 | level0_slowdown_writes_trigger); |
115 | 28 | RLOG(log, " level0_stop_writes_trigger: %d", |
116 | 28 | level0_stop_writes_trigger); |
117 | 28 | RLOG(log, " max_grandparent_overlap_factor: %d", |
118 | 28 | max_grandparent_overlap_factor); |
119 | 28 | RLOG(log, " expanded_compaction_factor: %d", |
120 | 28 | expanded_compaction_factor); |
121 | 28 | RLOG(log, " source_compaction_factor: %d", |
122 | 28 | source_compaction_factor); |
123 | 28 | RLOG(log, " target_file_size_base: %" PRIu64, |
124 | 28 | target_file_size_base); |
125 | 28 | RLOG(log, " target_file_size_multiplier: %d", |
126 | 28 | target_file_size_multiplier); |
127 | 28 | RLOG(log, " max_bytes_for_level_base: %" PRIu64, |
128 | 28 | max_bytes_for_level_base); |
129 | 28 | RLOG(log, " max_bytes_for_level_multiplier: %d", |
130 | 28 | max_bytes_for_level_multiplier); |
131 | 28 | std::string result; |
132 | 28 | char buf[10]; |
133 | 197 | for (const auto m : max_bytes_for_level_multiplier_additional) { |
134 | 197 | snprintf(buf, sizeof(buf), "%d, ", m); |
135 | 197 | result += buf; |
136 | 197 | } |
137 | 28 | result.resize(result.size() - 2); |
138 | 28 | RLOG(log, "max_bytes_for_level_multiplier_additional: %s", result.c_str()); |
139 | 28 | RLOG(log, " verify_checksums_in_compaction: %d", |
140 | 28 | verify_checksums_in_compaction); |
141 | 28 | RLOG(log, " max_sequential_skip_in_iterations: %" PRIu64, |
142 | 28 | max_sequential_skip_in_iterations); |
143 | 28 | } |
144 | | |
145 | | } // namespace rocksdb |