Coverage Report

Created: 2026-02-14 06:58

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