Coverage Report

Created: 2026-05-31 07:45

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