internal_stats.h 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697
  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. // Copyright (c) 2011 The LevelDB Authors. All rights reserved.
  7. // Use of this source code is governed by a BSD-style license that can be
  8. // found in the LICENSE file. See the AUTHORS file for names of contributors.
  9. //
  10. #pragma once
  11. #include <map>
  12. #include <string>
  13. #include <vector>
  14. #include "db/version_set.h"
  15. class ColumnFamilyData;
  16. namespace ROCKSDB_NAMESPACE {
  17. class DBImpl;
  18. class MemTableList;
  19. // Config for retrieving a property's value.
  20. struct DBPropertyInfo {
  21. bool need_out_of_mutex;
  22. // gcc had an internal error for initializing union of pointer-to-member-
  23. // functions. Workaround is to populate exactly one of the following function
  24. // pointers with a non-nullptr value.
  25. // @param value Value-result argument for storing the property's string value
  26. // @param suffix Argument portion of the property. For example, suffix would
  27. // be "5" for the property "rocksdb.num-files-at-level5". So far, only
  28. // certain string properties take an argument.
  29. bool (InternalStats::*handle_string)(std::string* value, Slice suffix);
  30. // @param value Value-result argument for storing the property's uint64 value
  31. // @param db Many of the int properties rely on DBImpl methods.
  32. // @param version Version is needed in case the property is retrieved without
  33. // holding db mutex, which is only supported for int properties.
  34. bool (InternalStats::*handle_int)(uint64_t* value, DBImpl* db,
  35. Version* version);
  36. // @param props Map of general properties to populate
  37. bool (InternalStats::*handle_map)(std::map<std::string, std::string>* props);
  38. // handle the string type properties rely on DBImpl methods
  39. // @param value Value-result argument for storing the property's string value
  40. bool (DBImpl::*handle_string_dbimpl)(std::string* value);
  41. };
  42. extern const DBPropertyInfo* GetPropertyInfo(const Slice& property);
  43. #ifndef ROCKSDB_LITE
  44. #undef SCORE
  45. enum class LevelStatType {
  46. INVALID = 0,
  47. NUM_FILES,
  48. COMPACTED_FILES,
  49. SIZE_BYTES,
  50. SCORE,
  51. READ_GB,
  52. RN_GB,
  53. RNP1_GB,
  54. WRITE_GB,
  55. W_NEW_GB,
  56. MOVED_GB,
  57. WRITE_AMP,
  58. READ_MBPS,
  59. WRITE_MBPS,
  60. COMP_SEC,
  61. COMP_CPU_SEC,
  62. COMP_COUNT,
  63. AVG_SEC,
  64. KEY_IN,
  65. KEY_DROP,
  66. TOTAL // total number of types
  67. };
  68. struct LevelStat {
  69. // This what will be L?.property_name in the flat map returned to the user
  70. std::string property_name;
  71. // This will be what we will print in the header in the cli
  72. std::string header_name;
  73. };
  74. class InternalStats {
  75. public:
  76. static const std::map<LevelStatType, LevelStat> compaction_level_stats;
  77. enum InternalCFStatsType {
  78. L0_FILE_COUNT_LIMIT_SLOWDOWNS,
  79. LOCKED_L0_FILE_COUNT_LIMIT_SLOWDOWNS,
  80. MEMTABLE_LIMIT_STOPS,
  81. MEMTABLE_LIMIT_SLOWDOWNS,
  82. L0_FILE_COUNT_LIMIT_STOPS,
  83. LOCKED_L0_FILE_COUNT_LIMIT_STOPS,
  84. PENDING_COMPACTION_BYTES_LIMIT_SLOWDOWNS,
  85. PENDING_COMPACTION_BYTES_LIMIT_STOPS,
  86. WRITE_STALLS_ENUM_MAX,
  87. BYTES_FLUSHED,
  88. BYTES_INGESTED_ADD_FILE,
  89. INGESTED_NUM_FILES_TOTAL,
  90. INGESTED_LEVEL0_NUM_FILES_TOTAL,
  91. INGESTED_NUM_KEYS_TOTAL,
  92. INTERNAL_CF_STATS_ENUM_MAX,
  93. };
  94. enum InternalDBStatsType {
  95. kIntStatsWalFileBytes,
  96. kIntStatsWalFileSynced,
  97. kIntStatsBytesWritten,
  98. kIntStatsNumKeysWritten,
  99. kIntStatsWriteDoneByOther,
  100. kIntStatsWriteDoneBySelf,
  101. kIntStatsWriteWithWal,
  102. kIntStatsWriteStallMicros,
  103. kIntStatsNumMax,
  104. };
  105. InternalStats(int num_levels, Env* env, ColumnFamilyData* cfd)
  106. : db_stats_{},
  107. cf_stats_value_{},
  108. cf_stats_count_{},
  109. comp_stats_(num_levels),
  110. comp_stats_by_pri_(Env::Priority::TOTAL),
  111. file_read_latency_(num_levels),
  112. bg_error_count_(0),
  113. number_levels_(num_levels),
  114. env_(env),
  115. cfd_(cfd),
  116. started_at_(env->NowMicros()) {}
  117. // Per level compaction stats. comp_stats_[level] stores the stats for
  118. // compactions that produced data for the specified "level".
  119. struct CompactionStats {
  120. uint64_t micros;
  121. uint64_t cpu_micros;
  122. // The number of bytes read from all non-output levels
  123. uint64_t bytes_read_non_output_levels;
  124. // The number of bytes read from the compaction output level.
  125. uint64_t bytes_read_output_level;
  126. // Total number of bytes written during compaction
  127. uint64_t bytes_written;
  128. // Total number of bytes moved to the output level
  129. uint64_t bytes_moved;
  130. // The number of compaction input files in all non-output levels.
  131. int num_input_files_in_non_output_levels;
  132. // The number of compaction input files in the output level.
  133. int num_input_files_in_output_level;
  134. // The number of compaction output files.
  135. int num_output_files;
  136. // Total incoming entries during compaction between levels N and N+1
  137. uint64_t num_input_records;
  138. // Accumulated diff number of entries
  139. // (num input entries - num output entires) for compaction levels N and N+1
  140. uint64_t num_dropped_records;
  141. // Number of compactions done
  142. int count;
  143. // Number of compactions done per CompactionReason
  144. int counts[static_cast<int>(CompactionReason::kNumOfReasons)];
  145. explicit CompactionStats()
  146. : micros(0),
  147. cpu_micros(0),
  148. bytes_read_non_output_levels(0),
  149. bytes_read_output_level(0),
  150. bytes_written(0),
  151. bytes_moved(0),
  152. num_input_files_in_non_output_levels(0),
  153. num_input_files_in_output_level(0),
  154. num_output_files(0),
  155. num_input_records(0),
  156. num_dropped_records(0),
  157. count(0) {
  158. int num_of_reasons = static_cast<int>(CompactionReason::kNumOfReasons);
  159. for (int i = 0; i < num_of_reasons; i++) {
  160. counts[i] = 0;
  161. }
  162. }
  163. explicit CompactionStats(CompactionReason reason, int c)
  164. : micros(0),
  165. cpu_micros(0),
  166. bytes_read_non_output_levels(0),
  167. bytes_read_output_level(0),
  168. bytes_written(0),
  169. bytes_moved(0),
  170. num_input_files_in_non_output_levels(0),
  171. num_input_files_in_output_level(0),
  172. num_output_files(0),
  173. num_input_records(0),
  174. num_dropped_records(0),
  175. count(c) {
  176. int num_of_reasons = static_cast<int>(CompactionReason::kNumOfReasons);
  177. for (int i = 0; i < num_of_reasons; i++) {
  178. counts[i] = 0;
  179. }
  180. int r = static_cast<int>(reason);
  181. if (r >= 0 && r < num_of_reasons) {
  182. counts[r] = c;
  183. } else {
  184. count = 0;
  185. }
  186. }
  187. explicit CompactionStats(const CompactionStats& c)
  188. : micros(c.micros),
  189. cpu_micros(c.cpu_micros),
  190. bytes_read_non_output_levels(c.bytes_read_non_output_levels),
  191. bytes_read_output_level(c.bytes_read_output_level),
  192. bytes_written(c.bytes_written),
  193. bytes_moved(c.bytes_moved),
  194. num_input_files_in_non_output_levels(
  195. c.num_input_files_in_non_output_levels),
  196. num_input_files_in_output_level(c.num_input_files_in_output_level),
  197. num_output_files(c.num_output_files),
  198. num_input_records(c.num_input_records),
  199. num_dropped_records(c.num_dropped_records),
  200. count(c.count) {
  201. int num_of_reasons = static_cast<int>(CompactionReason::kNumOfReasons);
  202. for (int i = 0; i < num_of_reasons; i++) {
  203. counts[i] = c.counts[i];
  204. }
  205. }
  206. CompactionStats& operator=(const CompactionStats& c) {
  207. micros = c.micros;
  208. cpu_micros = c.cpu_micros;
  209. bytes_read_non_output_levels = c.bytes_read_non_output_levels;
  210. bytes_read_output_level = c.bytes_read_output_level;
  211. bytes_written = c.bytes_written;
  212. bytes_moved = c.bytes_moved;
  213. num_input_files_in_non_output_levels =
  214. c.num_input_files_in_non_output_levels;
  215. num_input_files_in_output_level = c.num_input_files_in_output_level;
  216. num_output_files = c.num_output_files;
  217. num_input_records = c.num_input_records;
  218. num_dropped_records = c.num_dropped_records;
  219. count = c.count;
  220. int num_of_reasons = static_cast<int>(CompactionReason::kNumOfReasons);
  221. for (int i = 0; i < num_of_reasons; i++) {
  222. counts[i] = c.counts[i];
  223. }
  224. return *this;
  225. }
  226. void Clear() {
  227. this->micros = 0;
  228. this->cpu_micros = 0;
  229. this->bytes_read_non_output_levels = 0;
  230. this->bytes_read_output_level = 0;
  231. this->bytes_written = 0;
  232. this->bytes_moved = 0;
  233. this->num_input_files_in_non_output_levels = 0;
  234. this->num_input_files_in_output_level = 0;
  235. this->num_output_files = 0;
  236. this->num_input_records = 0;
  237. this->num_dropped_records = 0;
  238. this->count = 0;
  239. int num_of_reasons = static_cast<int>(CompactionReason::kNumOfReasons);
  240. for (int i = 0; i < num_of_reasons; i++) {
  241. counts[i] = 0;
  242. }
  243. }
  244. void Add(const CompactionStats& c) {
  245. this->micros += c.micros;
  246. this->cpu_micros += c.cpu_micros;
  247. this->bytes_read_non_output_levels += c.bytes_read_non_output_levels;
  248. this->bytes_read_output_level += c.bytes_read_output_level;
  249. this->bytes_written += c.bytes_written;
  250. this->bytes_moved += c.bytes_moved;
  251. this->num_input_files_in_non_output_levels +=
  252. c.num_input_files_in_non_output_levels;
  253. this->num_input_files_in_output_level +=
  254. c.num_input_files_in_output_level;
  255. this->num_output_files += c.num_output_files;
  256. this->num_input_records += c.num_input_records;
  257. this->num_dropped_records += c.num_dropped_records;
  258. this->count += c.count;
  259. int num_of_reasons = static_cast<int>(CompactionReason::kNumOfReasons);
  260. for (int i = 0; i< num_of_reasons; i++) {
  261. counts[i] += c.counts[i];
  262. }
  263. }
  264. void Subtract(const CompactionStats& c) {
  265. this->micros -= c.micros;
  266. this->cpu_micros -= c.cpu_micros;
  267. this->bytes_read_non_output_levels -= c.bytes_read_non_output_levels;
  268. this->bytes_read_output_level -= c.bytes_read_output_level;
  269. this->bytes_written -= c.bytes_written;
  270. this->bytes_moved -= c.bytes_moved;
  271. this->num_input_files_in_non_output_levels -=
  272. c.num_input_files_in_non_output_levels;
  273. this->num_input_files_in_output_level -=
  274. c.num_input_files_in_output_level;
  275. this->num_output_files -= c.num_output_files;
  276. this->num_input_records -= c.num_input_records;
  277. this->num_dropped_records -= c.num_dropped_records;
  278. this->count -= c.count;
  279. int num_of_reasons = static_cast<int>(CompactionReason::kNumOfReasons);
  280. for (int i = 0; i < num_of_reasons; i++) {
  281. counts[i] -= c.counts[i];
  282. }
  283. }
  284. };
  285. void Clear() {
  286. for (int i = 0; i < kIntStatsNumMax; i++) {
  287. db_stats_[i].store(0);
  288. }
  289. for (int i = 0; i < INTERNAL_CF_STATS_ENUM_MAX; i++) {
  290. cf_stats_count_[i] = 0;
  291. cf_stats_value_[i] = 0;
  292. }
  293. for (auto& comp_stat : comp_stats_) {
  294. comp_stat.Clear();
  295. }
  296. for (auto& h : file_read_latency_) {
  297. h.Clear();
  298. }
  299. cf_stats_snapshot_.Clear();
  300. db_stats_snapshot_.Clear();
  301. bg_error_count_ = 0;
  302. started_at_ = env_->NowMicros();
  303. }
  304. void AddCompactionStats(int level, Env::Priority thread_pri,
  305. const CompactionStats& stats) {
  306. comp_stats_[level].Add(stats);
  307. comp_stats_by_pri_[thread_pri].Add(stats);
  308. }
  309. void IncBytesMoved(int level, uint64_t amount) {
  310. comp_stats_[level].bytes_moved += amount;
  311. }
  312. void AddCFStats(InternalCFStatsType type, uint64_t value) {
  313. cf_stats_value_[type] += value;
  314. ++cf_stats_count_[type];
  315. }
  316. void AddDBStats(InternalDBStatsType type, uint64_t value,
  317. bool concurrent = false) {
  318. auto& v = db_stats_[type];
  319. if (concurrent) {
  320. v.fetch_add(value, std::memory_order_relaxed);
  321. } else {
  322. v.store(v.load(std::memory_order_relaxed) + value,
  323. std::memory_order_relaxed);
  324. }
  325. }
  326. uint64_t GetDBStats(InternalDBStatsType type) {
  327. return db_stats_[type].load(std::memory_order_relaxed);
  328. }
  329. HistogramImpl* GetFileReadHist(int level) {
  330. return &file_read_latency_[level];
  331. }
  332. uint64_t GetBackgroundErrorCount() const { return bg_error_count_; }
  333. uint64_t BumpAndGetBackgroundErrorCount() { return ++bg_error_count_; }
  334. bool GetStringProperty(const DBPropertyInfo& property_info,
  335. const Slice& property, std::string* value);
  336. bool GetMapProperty(const DBPropertyInfo& property_info,
  337. const Slice& property,
  338. std::map<std::string, std::string>* value);
  339. bool GetIntProperty(const DBPropertyInfo& property_info, uint64_t* value,
  340. DBImpl* db);
  341. bool GetIntPropertyOutOfMutex(const DBPropertyInfo& property_info,
  342. Version* version, uint64_t* value);
  343. const std::vector<CompactionStats>& TEST_GetCompactionStats() const {
  344. return comp_stats_;
  345. }
  346. // Store a mapping from the user-facing DB::Properties string to our
  347. // DBPropertyInfo struct used internally for retrieving properties.
  348. static const std::unordered_map<std::string, DBPropertyInfo> ppt_name_to_info;
  349. private:
  350. void DumpDBStats(std::string* value);
  351. void DumpCFMapStats(std::map<std::string, std::string>* cf_stats);
  352. void DumpCFMapStats(
  353. std::map<int, std::map<LevelStatType, double>>* level_stats,
  354. CompactionStats* compaction_stats_sum);
  355. void DumpCFMapStatsByPriority(
  356. std::map<int, std::map<LevelStatType, double>>* priorities_stats);
  357. void DumpCFMapStatsIOStalls(std::map<std::string, std::string>* cf_stats);
  358. void DumpCFStats(std::string* value);
  359. void DumpCFStatsNoFileHistogram(std::string* value);
  360. void DumpCFFileHistogram(std::string* value);
  361. bool HandleBlockCacheStat(Cache** block_cache);
  362. // Per-DB stats
  363. std::atomic<uint64_t> db_stats_[kIntStatsNumMax];
  364. // Per-ColumnFamily stats
  365. uint64_t cf_stats_value_[INTERNAL_CF_STATS_ENUM_MAX];
  366. uint64_t cf_stats_count_[INTERNAL_CF_STATS_ENUM_MAX];
  367. // Per-ColumnFamily/level compaction stats
  368. std::vector<CompactionStats> comp_stats_;
  369. std::vector<CompactionStats> comp_stats_by_pri_;
  370. std::vector<HistogramImpl> file_read_latency_;
  371. // Used to compute per-interval statistics
  372. struct CFStatsSnapshot {
  373. // ColumnFamily-level stats
  374. CompactionStats comp_stats;
  375. uint64_t ingest_bytes_flush; // Bytes written to L0 (Flush)
  376. uint64_t stall_count; // Stall count
  377. // Stats from compaction jobs - bytes written, bytes read, duration.
  378. uint64_t compact_bytes_write;
  379. uint64_t compact_bytes_read;
  380. uint64_t compact_micros;
  381. double seconds_up;
  382. // AddFile specific stats
  383. uint64_t ingest_bytes_addfile; // Total Bytes ingested
  384. uint64_t ingest_files_addfile; // Total number of files ingested
  385. uint64_t ingest_l0_files_addfile; // Total number of files ingested to L0
  386. uint64_t ingest_keys_addfile; // Total number of keys ingested
  387. CFStatsSnapshot()
  388. : ingest_bytes_flush(0),
  389. stall_count(0),
  390. compact_bytes_write(0),
  391. compact_bytes_read(0),
  392. compact_micros(0),
  393. seconds_up(0),
  394. ingest_bytes_addfile(0),
  395. ingest_files_addfile(0),
  396. ingest_l0_files_addfile(0),
  397. ingest_keys_addfile(0) {}
  398. void Clear() {
  399. comp_stats.Clear();
  400. ingest_bytes_flush = 0;
  401. stall_count = 0;
  402. compact_bytes_write = 0;
  403. compact_bytes_read = 0;
  404. compact_micros = 0;
  405. seconds_up = 0;
  406. ingest_bytes_addfile = 0;
  407. ingest_files_addfile = 0;
  408. ingest_l0_files_addfile = 0;
  409. ingest_keys_addfile = 0;
  410. }
  411. } cf_stats_snapshot_;
  412. struct DBStatsSnapshot {
  413. // DB-level stats
  414. uint64_t ingest_bytes; // Bytes written by user
  415. uint64_t wal_bytes; // Bytes written to WAL
  416. uint64_t wal_synced; // Number of times WAL is synced
  417. uint64_t write_with_wal; // Number of writes that request WAL
  418. // These count the number of writes processed by the calling thread or
  419. // another thread.
  420. uint64_t write_other;
  421. uint64_t write_self;
  422. // Total number of keys written. write_self and write_other measure number
  423. // of write requests written, Each of the write request can contain updates
  424. // to multiple keys. num_keys_written is total number of keys updated by all
  425. // those writes.
  426. uint64_t num_keys_written;
  427. // Total time writes delayed by stalls.
  428. uint64_t write_stall_micros;
  429. double seconds_up;
  430. DBStatsSnapshot()
  431. : ingest_bytes(0),
  432. wal_bytes(0),
  433. wal_synced(0),
  434. write_with_wal(0),
  435. write_other(0),
  436. write_self(0),
  437. num_keys_written(0),
  438. write_stall_micros(0),
  439. seconds_up(0) {}
  440. void Clear() {
  441. ingest_bytes = 0;
  442. wal_bytes = 0;
  443. wal_synced = 0;
  444. write_with_wal = 0;
  445. write_other = 0;
  446. write_self = 0;
  447. num_keys_written = 0;
  448. write_stall_micros = 0;
  449. seconds_up = 0;
  450. }
  451. } db_stats_snapshot_;
  452. // Handler functions for getting property values. They use "value" as a value-
  453. // result argument, and return true upon successfully setting "value".
  454. bool HandleNumFilesAtLevel(std::string* value, Slice suffix);
  455. bool HandleCompressionRatioAtLevelPrefix(std::string* value, Slice suffix);
  456. bool HandleLevelStats(std::string* value, Slice suffix);
  457. bool HandleStats(std::string* value, Slice suffix);
  458. bool HandleCFMapStats(std::map<std::string, std::string>* compaction_stats);
  459. bool HandleCFStats(std::string* value, Slice suffix);
  460. bool HandleCFStatsNoFileHistogram(std::string* value, Slice suffix);
  461. bool HandleCFFileHistogram(std::string* value, Slice suffix);
  462. bool HandleDBStats(std::string* value, Slice suffix);
  463. bool HandleSsTables(std::string* value, Slice suffix);
  464. bool HandleAggregatedTableProperties(std::string* value, Slice suffix);
  465. bool HandleAggregatedTablePropertiesAtLevel(std::string* value, Slice suffix);
  466. bool HandleNumImmutableMemTable(uint64_t* value, DBImpl* db,
  467. Version* version);
  468. bool HandleNumImmutableMemTableFlushed(uint64_t* value, DBImpl* db,
  469. Version* version);
  470. bool HandleMemTableFlushPending(uint64_t* value, DBImpl* db,
  471. Version* version);
  472. bool HandleNumRunningFlushes(uint64_t* value, DBImpl* db, Version* version);
  473. bool HandleCompactionPending(uint64_t* value, DBImpl* db, Version* version);
  474. bool HandleNumRunningCompactions(uint64_t* value, DBImpl* db,
  475. Version* version);
  476. bool HandleBackgroundErrors(uint64_t* value, DBImpl* db, Version* version);
  477. bool HandleCurSizeActiveMemTable(uint64_t* value, DBImpl* db,
  478. Version* version);
  479. bool HandleCurSizeAllMemTables(uint64_t* value, DBImpl* db, Version* version);
  480. bool HandleSizeAllMemTables(uint64_t* value, DBImpl* db, Version* version);
  481. bool HandleNumEntriesActiveMemTable(uint64_t* value, DBImpl* db,
  482. Version* version);
  483. bool HandleNumEntriesImmMemTables(uint64_t* value, DBImpl* db,
  484. Version* version);
  485. bool HandleNumDeletesActiveMemTable(uint64_t* value, DBImpl* db,
  486. Version* version);
  487. bool HandleNumDeletesImmMemTables(uint64_t* value, DBImpl* db,
  488. Version* version);
  489. bool HandleEstimateNumKeys(uint64_t* value, DBImpl* db, Version* version);
  490. bool HandleNumSnapshots(uint64_t* value, DBImpl* db, Version* version);
  491. bool HandleOldestSnapshotTime(uint64_t* value, DBImpl* db, Version* version);
  492. bool HandleOldestSnapshotSequence(uint64_t* value, DBImpl* db,
  493. Version* version);
  494. bool HandleNumLiveVersions(uint64_t* value, DBImpl* db, Version* version);
  495. bool HandleCurrentSuperVersionNumber(uint64_t* value, DBImpl* db,
  496. Version* version);
  497. bool HandleIsFileDeletionsEnabled(uint64_t* value, DBImpl* db,
  498. Version* version);
  499. bool HandleBaseLevel(uint64_t* value, DBImpl* db, Version* version);
  500. bool HandleTotalSstFilesSize(uint64_t* value, DBImpl* db, Version* version);
  501. bool HandleLiveSstFilesSize(uint64_t* value, DBImpl* db, Version* version);
  502. bool HandleEstimatePendingCompactionBytes(uint64_t* value, DBImpl* db,
  503. Version* version);
  504. bool HandleEstimateTableReadersMem(uint64_t* value, DBImpl* db,
  505. Version* version);
  506. bool HandleEstimateLiveDataSize(uint64_t* value, DBImpl* db,
  507. Version* version);
  508. bool HandleMinLogNumberToKeep(uint64_t* value, DBImpl* db, Version* version);
  509. bool HandleMinObsoleteSstNumberToKeep(uint64_t* value, DBImpl* db,
  510. Version* version);
  511. bool HandleActualDelayedWriteRate(uint64_t* value, DBImpl* db,
  512. Version* version);
  513. bool HandleIsWriteStopped(uint64_t* value, DBImpl* db, Version* version);
  514. bool HandleEstimateOldestKeyTime(uint64_t* value, DBImpl* db,
  515. Version* version);
  516. bool HandleBlockCacheCapacity(uint64_t* value, DBImpl* db, Version* version);
  517. bool HandleBlockCacheUsage(uint64_t* value, DBImpl* db, Version* version);
  518. bool HandleBlockCachePinnedUsage(uint64_t* value, DBImpl* db,
  519. Version* version);
  520. // Total number of background errors encountered. Every time a flush task
  521. // or compaction task fails, this counter is incremented. The failure can
  522. // be caused by any possible reason, including file system errors, out of
  523. // resources, or input file corruption. Failing when retrying the same flush
  524. // or compaction will cause the counter to increase too.
  525. uint64_t bg_error_count_;
  526. const int number_levels_;
  527. Env* env_;
  528. ColumnFamilyData* cfd_;
  529. uint64_t started_at_;
  530. };
  531. #else
  532. class InternalStats {
  533. public:
  534. enum InternalCFStatsType {
  535. L0_FILE_COUNT_LIMIT_SLOWDOWNS,
  536. LOCKED_L0_FILE_COUNT_LIMIT_SLOWDOWNS,
  537. MEMTABLE_LIMIT_STOPS,
  538. MEMTABLE_LIMIT_SLOWDOWNS,
  539. L0_FILE_COUNT_LIMIT_STOPS,
  540. LOCKED_L0_FILE_COUNT_LIMIT_STOPS,
  541. PENDING_COMPACTION_BYTES_LIMIT_SLOWDOWNS,
  542. PENDING_COMPACTION_BYTES_LIMIT_STOPS,
  543. WRITE_STALLS_ENUM_MAX,
  544. BYTES_FLUSHED,
  545. BYTES_INGESTED_ADD_FILE,
  546. INGESTED_NUM_FILES_TOTAL,
  547. INGESTED_LEVEL0_NUM_FILES_TOTAL,
  548. INGESTED_NUM_KEYS_TOTAL,
  549. INTERNAL_CF_STATS_ENUM_MAX,
  550. };
  551. enum InternalDBStatsType {
  552. kIntStatsWalFileBytes,
  553. kIntStatsWalFileSynced,
  554. kIntStatsBytesWritten,
  555. kIntStatsNumKeysWritten,
  556. kIntStatsWriteDoneByOther,
  557. kIntStatsWriteDoneBySelf,
  558. kIntStatsWriteWithWal,
  559. kIntStatsWriteStallMicros,
  560. kIntStatsNumMax,
  561. };
  562. InternalStats(int /*num_levels*/, Env* /*env*/, ColumnFamilyData* /*cfd*/) {}
  563. struct CompactionStats {
  564. uint64_t micros;
  565. uint64_t cpu_micros;
  566. uint64_t bytes_read_non_output_levels;
  567. uint64_t bytes_read_output_level;
  568. uint64_t bytes_written;
  569. uint64_t bytes_moved;
  570. int num_input_files_in_non_output_levels;
  571. int num_input_files_in_output_level;
  572. int num_output_files;
  573. uint64_t num_input_records;
  574. uint64_t num_dropped_records;
  575. int count;
  576. explicit CompactionStats() {}
  577. explicit CompactionStats(CompactionReason /*reason*/, int /*c*/) {}
  578. explicit CompactionStats(const CompactionStats& /*c*/) {}
  579. void Add(const CompactionStats& /*c*/) {}
  580. void Subtract(const CompactionStats& /*c*/) {}
  581. };
  582. void AddCompactionStats(int /*level*/, Env::Priority /*thread_pri*/,
  583. const CompactionStats& /*stats*/) {}
  584. void IncBytesMoved(int /*level*/, uint64_t /*amount*/) {}
  585. void AddCFStats(InternalCFStatsType /*type*/, uint64_t /*value*/) {}
  586. void AddDBStats(InternalDBStatsType /*type*/, uint64_t /*value*/,
  587. bool /*concurrent */ = false) {}
  588. HistogramImpl* GetFileReadHist(int /*level*/) { return nullptr; }
  589. uint64_t GetBackgroundErrorCount() const { return 0; }
  590. uint64_t BumpAndGetBackgroundErrorCount() { return 0; }
  591. bool GetStringProperty(const DBPropertyInfo& /*property_info*/,
  592. const Slice& /*property*/, std::string* /*value*/) {
  593. return false;
  594. }
  595. bool GetMapProperty(const DBPropertyInfo& /*property_info*/,
  596. const Slice& /*property*/,
  597. std::map<std::string, std::string>* /*value*/) {
  598. return false;
  599. }
  600. bool GetIntProperty(const DBPropertyInfo& /*property_info*/, uint64_t* /*value*/,
  601. DBImpl* /*db*/) const {
  602. return false;
  603. }
  604. bool GetIntPropertyOutOfMutex(const DBPropertyInfo& /*property_info*/,
  605. Version* /*version*/, uint64_t* /*value*/) const {
  606. return false;
  607. }
  608. };
  609. #endif // !ROCKSDB_LITE
  610. } // namespace ROCKSDB_NAMESPACE