/src/rocksdb/db/write_stall_stats.cc
Line | Count | Source (jump to first uncovered line) |
1 | | // Copyright (c) Facebook, Inc. and its affiliates. 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 | | #include "db/write_stall_stats.h" |
7 | | |
8 | | namespace ROCKSDB_NAMESPACE { |
9 | 0 | const std::string& InvalidWriteStallHyphenString() { |
10 | 0 | static const std::string kInvalidWriteStallHyphenString = "invalid"; |
11 | 0 | return kInvalidWriteStallHyphenString; |
12 | 0 | } |
13 | | |
14 | 3.43k | const std::string& WriteStallCauseToHyphenString(WriteStallCause cause) { |
15 | 3.43k | static const std::string kMemtableLimit = "memtable-limit"; |
16 | 3.43k | static const std::string kL0FileCountLimit = "l0-file-count-limit"; |
17 | 3.43k | static const std::string kPendingCompactionBytes = "pending-compaction-bytes"; |
18 | 3.43k | static const std::string kWriteBufferManagerLimit = |
19 | 3.43k | "write-buffer-manager-limit"; |
20 | 3.43k | switch (cause) { |
21 | 1.02k | case WriteStallCause::kMemtableLimit: |
22 | 1.02k | return kMemtableLimit; |
23 | 1.02k | case WriteStallCause::kL0FileCountLimit: |
24 | 1.02k | return kL0FileCountLimit; |
25 | 1.02k | case WriteStallCause::kPendingCompactionBytes: |
26 | 1.02k | return kPendingCompactionBytes; |
27 | 359 | case WriteStallCause::kWriteBufferManagerLimit: |
28 | 359 | return kWriteBufferManagerLimit; |
29 | 0 | default: |
30 | 0 | break; |
31 | 3.43k | } |
32 | 0 | return InvalidWriteStallHyphenString(); |
33 | 3.43k | } |
34 | | |
35 | | const std::string& WriteStallConditionToHyphenString( |
36 | 3.43k | WriteStallCondition condition) { |
37 | 3.43k | static const std::string kDelayed = "delays"; |
38 | 3.43k | static const std::string kStopped = "stops"; |
39 | 3.43k | switch (condition) { |
40 | 1.53k | case WriteStallCondition::kDelayed: |
41 | 1.53k | return kDelayed; |
42 | 1.89k | case WriteStallCondition::kStopped: |
43 | 1.89k | return kStopped; |
44 | 0 | default: |
45 | 0 | break; |
46 | 3.43k | } |
47 | 0 | return InvalidWriteStallHyphenString(); |
48 | 3.43k | } |
49 | | |
50 | | InternalStats::InternalCFStatsType InternalCFStat( |
51 | 3.07k | WriteStallCause cause, WriteStallCondition condition) { |
52 | 3.07k | switch (cause) { |
53 | 1.02k | case WriteStallCause::kMemtableLimit: { |
54 | 1.02k | switch (condition) { |
55 | 512 | case WriteStallCondition::kDelayed: |
56 | 512 | return InternalStats::MEMTABLE_LIMIT_DELAYS; |
57 | 512 | case WriteStallCondition::kStopped: |
58 | 512 | return InternalStats::MEMTABLE_LIMIT_STOPS; |
59 | 0 | case WriteStallCondition::kNormal: |
60 | 0 | break; |
61 | 1.02k | } |
62 | 0 | break; |
63 | 1.02k | } |
64 | 1.02k | case WriteStallCause::kL0FileCountLimit: { |
65 | 1.02k | switch (condition) { |
66 | 512 | case WriteStallCondition::kDelayed: |
67 | 512 | return InternalStats::L0_FILE_COUNT_LIMIT_DELAYS; |
68 | 512 | case WriteStallCondition::kStopped: |
69 | 512 | return InternalStats::L0_FILE_COUNT_LIMIT_STOPS; |
70 | 0 | case WriteStallCondition::kNormal: |
71 | 0 | break; |
72 | 1.02k | } |
73 | 0 | break; |
74 | 1.02k | } |
75 | 1.02k | case WriteStallCause::kPendingCompactionBytes: { |
76 | 1.02k | switch (condition) { |
77 | 512 | case WriteStallCondition::kDelayed: |
78 | 512 | return InternalStats::PENDING_COMPACTION_BYTES_LIMIT_DELAYS; |
79 | 512 | case WriteStallCondition::kStopped: |
80 | 512 | return InternalStats::PENDING_COMPACTION_BYTES_LIMIT_STOPS; |
81 | 0 | case WriteStallCondition::kNormal: |
82 | 0 | break; |
83 | 1.02k | } |
84 | 0 | break; |
85 | 1.02k | } |
86 | 0 | default: |
87 | 0 | break; |
88 | 3.07k | } |
89 | 0 | return InternalStats::INTERNAL_CF_STATS_ENUM_MAX; |
90 | 3.07k | } |
91 | | |
92 | | InternalStats::InternalDBStatsType InternalDBStat( |
93 | 710 | WriteStallCause cause, WriteStallCondition condition) { |
94 | 710 | switch (cause) { |
95 | 710 | case WriteStallCause::kWriteBufferManagerLimit: { |
96 | 710 | switch (condition) { |
97 | 355 | case WriteStallCondition::kStopped: |
98 | 355 | return InternalStats::kIntStatsWriteBufferManagerLimitStopsCounts; |
99 | 355 | default: |
100 | 355 | break; |
101 | 710 | } |
102 | 355 | break; |
103 | 710 | } |
104 | 355 | default: |
105 | 0 | break; |
106 | 710 | } |
107 | 355 | return InternalStats::kIntStatsNumMax; |
108 | 710 | } |
109 | | |
110 | 3.43k | bool isCFScopeWriteStallCause(WriteStallCause cause) { |
111 | 3.43k | uint32_t int_cause = static_cast<uint32_t>(cause); |
112 | 3.43k | uint32_t lower_bound = |
113 | 3.43k | static_cast<uint32_t>(WriteStallCause::kCFScopeWriteStallCauseEnumMax) - |
114 | 3.43k | kNumCFScopeWriteStallCauses; |
115 | 3.43k | uint32_t upper_bound = |
116 | 3.43k | static_cast<uint32_t>(WriteStallCause::kCFScopeWriteStallCauseEnumMax) - |
117 | 3.43k | 1; |
118 | 3.43k | return lower_bound <= int_cause && int_cause <= upper_bound; |
119 | 3.43k | } |
120 | | |
121 | 359 | bool isDBScopeWriteStallCause(WriteStallCause cause) { |
122 | 359 | uint32_t int_cause = static_cast<uint32_t>(cause); |
123 | 359 | uint32_t lower_bound = |
124 | 359 | static_cast<uint32_t>(WriteStallCause::kDBScopeWriteStallCauseEnumMax) - |
125 | 359 | kNumDBScopeWriteStallCauses; |
126 | 359 | uint32_t upper_bound = |
127 | 359 | static_cast<uint32_t>(WriteStallCause::kDBScopeWriteStallCauseEnumMax) - |
128 | 359 | 1; |
129 | 359 | return lower_bound <= int_cause && int_cause <= upper_bound; |
130 | 359 | } |
131 | | |
132 | 1.02k | const std::string& WriteStallStatsMapKeys::TotalStops() { |
133 | 1.02k | static const std::string kTotalStops = "total-stops"; |
134 | 1.02k | return kTotalStops; |
135 | 1.02k | } |
136 | | |
137 | 1.02k | const std::string& WriteStallStatsMapKeys::TotalDelays() { |
138 | 1.02k | static const std::string kTotalDelays = "total-delays"; |
139 | 1.02k | return kTotalDelays; |
140 | 1.02k | } |
141 | | |
142 | | const std::string& |
143 | 512 | WriteStallStatsMapKeys::CFL0FileCountLimitDelaysWithOngoingCompaction() { |
144 | 512 | static const std::string ret = |
145 | 512 | "cf-l0-file-count-limit-delays-with-ongoing-compaction"; |
146 | 512 | return ret; |
147 | 512 | } |
148 | | |
149 | | const std::string& |
150 | 512 | WriteStallStatsMapKeys::CFL0FileCountLimitStopsWithOngoingCompaction() { |
151 | 512 | static const std::string ret = |
152 | 512 | "cf-l0-file-count-limit-stops-with-ongoing-compaction"; |
153 | 512 | return ret; |
154 | 512 | } |
155 | | |
156 | | std::string WriteStallStatsMapKeys::CauseConditionCount( |
157 | 3.43k | WriteStallCause cause, WriteStallCondition condition) { |
158 | 3.43k | std::string cause_condition_count_name; |
159 | | |
160 | 3.43k | std::string cause_name; |
161 | 3.43k | if (isCFScopeWriteStallCause(cause) || isDBScopeWriteStallCause(cause)) { |
162 | 3.43k | cause_name = WriteStallCauseToHyphenString(cause); |
163 | 3.43k | } else { |
164 | 0 | assert(false); |
165 | 0 | return ""; |
166 | 0 | } |
167 | | |
168 | 3.43k | const std::string& condition_name = |
169 | 3.43k | WriteStallConditionToHyphenString(condition); |
170 | | |
171 | 3.43k | cause_condition_count_name.reserve(cause_name.size() + 1 + |
172 | 3.43k | condition_name.size()); |
173 | 3.43k | cause_condition_count_name.append(cause_name); |
174 | 3.43k | cause_condition_count_name.append("-"); |
175 | 3.43k | cause_condition_count_name.append(condition_name); |
176 | | |
177 | 3.43k | return cause_condition_count_name; |
178 | 3.43k | } |
179 | | } // namespace ROCKSDB_NAMESPACE |