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 
11 #pragma once
12 
13 #include <map>
14 #include <memory>
15 #include <string>
16 #include <vector>
17 
18 #include "cache/cache_entry_roles.h"
19 #include "db/version_set.h"
20 #include "rocksdb/system_clock.h"
21 
22 class ColumnFamilyData;
23 
24 namespace ROCKSDB_NAMESPACE {
25 
26 class DBImpl;
27 class MemTableList;
28 
29 // Config for retrieving a property's value.
30 struct DBPropertyInfo {
31   bool need_out_of_mutex;
32 
33   // gcc had an internal error for initializing union of pointer-to-member-
34   // functions. Workaround is to populate exactly one of the following function
35   // pointers with a non-nullptr value.
36 
37   // @param value Value-result argument for storing the property's string value
38   // @param suffix Argument portion of the property. For example, suffix would
39   //      be "5" for the property "rocksdb.num-files-at-level5". So far, only
40   //      certain string properties take an argument.
41   bool (InternalStats::*handle_string)(std::string* value, Slice suffix);
42 
43   // @param value Value-result argument for storing the property's uint64 value
44   // @param db Many of the int properties rely on DBImpl methods.
45   // @param version Version is needed in case the property is retrieved without
46   //      holding db mutex, which is only supported for int properties.
47   bool (InternalStats::*handle_int)(uint64_t* value, DBImpl* db,
48                                     Version* version);
49 
50   // @param props Map of general properties to populate
51   // @param suffix Argument portion of the property. (see handle_string)
52   bool (InternalStats::*handle_map)(std::map<std::string, std::string>* props,
53                                     Slice suffix);
54 
55   // handle the string type properties rely on DBImpl methods
56   // @param value Value-result argument for storing the property's string value
57   bool (DBImpl::*handle_string_dbimpl)(std::string* value);
58 };
59 
60 extern const DBPropertyInfo* GetPropertyInfo(const Slice& property);
61 
62 #ifndef ROCKSDB_LITE
63 #undef SCORE
64 enum class LevelStatType {
65   INVALID = 0,
66   NUM_FILES,
67   COMPACTED_FILES,
68   SIZE_BYTES,
69   SCORE,
70   READ_GB,
71   RN_GB,
72   RNP1_GB,
73   WRITE_GB,
74   W_NEW_GB,
75   MOVED_GB,
76   WRITE_AMP,
77   READ_MBPS,
78   WRITE_MBPS,
79   COMP_SEC,
80   COMP_CPU_SEC,
81   COMP_COUNT,
82   AVG_SEC,
83   KEY_IN,
84   KEY_DROP,
85   R_BLOB_GB,
86   W_BLOB_GB,
87   TOTAL  // total number of types
88 };
89 
90 struct LevelStat {
91   // This what will be L?.property_name in the flat map returned to the user
92   std::string property_name;
93   // This will be what we will print in the header in the cli
94   std::string header_name;
95 };
96 
97 class InternalStats {
98  public:
99   static const std::map<LevelStatType, LevelStat> compaction_level_stats;
100 
101   enum InternalCFStatsType {
102     L0_FILE_COUNT_LIMIT_SLOWDOWNS,
103     LOCKED_L0_FILE_COUNT_LIMIT_SLOWDOWNS,
104     MEMTABLE_LIMIT_STOPS,
105     MEMTABLE_LIMIT_SLOWDOWNS,
106     L0_FILE_COUNT_LIMIT_STOPS,
107     LOCKED_L0_FILE_COUNT_LIMIT_STOPS,
108     PENDING_COMPACTION_BYTES_LIMIT_SLOWDOWNS,
109     PENDING_COMPACTION_BYTES_LIMIT_STOPS,
110     WRITE_STALLS_ENUM_MAX,
111     BYTES_FLUSHED,
112     BYTES_INGESTED_ADD_FILE,
113     INGESTED_NUM_FILES_TOTAL,
114     INGESTED_LEVEL0_NUM_FILES_TOTAL,
115     INGESTED_NUM_KEYS_TOTAL,
116     INTERNAL_CF_STATS_ENUM_MAX,
117   };
118 
119   enum InternalDBStatsType {
120     kIntStatsWalFileBytes,
121     kIntStatsWalFileSynced,
122     kIntStatsBytesWritten,
123     kIntStatsNumKeysWritten,
124     kIntStatsWriteDoneByOther,
125     kIntStatsWriteDoneBySelf,
126     kIntStatsWriteWithWal,
127     kIntStatsWriteStallMicros,
128     kIntStatsNumMax,
129   };
130 
131   InternalStats(int num_levels, SystemClock* clock, ColumnFamilyData* cfd);
132 
133   // Per level compaction stats.  comp_stats_[level] stores the stats for
134   // compactions that produced data for the specified "level".
135   struct CompactionStats {
136     uint64_t micros;
137     uint64_t cpu_micros;
138 
139     // The number of bytes read from all non-output levels (table files)
140     uint64_t bytes_read_non_output_levels;
141 
142     // The number of bytes read from the compaction output level (table files)
143     uint64_t bytes_read_output_level;
144 
145     // The number of bytes read from blob files
146     uint64_t bytes_read_blob;
147 
148     // Total number of bytes written to table files during compaction
149     uint64_t bytes_written;
150 
151     // Total number of bytes written to blob files during compaction
152     uint64_t bytes_written_blob;
153 
154     // Total number of bytes moved to the output level (table files)
155     uint64_t bytes_moved;
156 
157     // The number of compaction input files in all non-output levels (table
158     // files)
159     int num_input_files_in_non_output_levels;
160 
161     // The number of compaction input files in the output level (table files)
162     int num_input_files_in_output_level;
163 
164     // The number of compaction output files (table files)
165     int num_output_files;
166 
167     // The number of compaction output files (blob files)
168     int num_output_files_blob;
169 
170     // Total incoming entries during compaction between levels N and N+1
171     uint64_t num_input_records;
172 
173     // Accumulated diff number of entries
174     // (num input entries - num output entries) for compaction levels N and N+1
175     uint64_t num_dropped_records;
176 
177     // Number of compactions done
178     int count;
179 
180     // Number of compactions done per CompactionReason
181     int counts[static_cast<int>(CompactionReason::kNumOfReasons)];
182 
CompactionStatsCompactionStats183     explicit CompactionStats()
184         : micros(0),
185           cpu_micros(0),
186           bytes_read_non_output_levels(0),
187           bytes_read_output_level(0),
188           bytes_read_blob(0),
189           bytes_written(0),
190           bytes_written_blob(0),
191           bytes_moved(0),
192           num_input_files_in_non_output_levels(0),
193           num_input_files_in_output_level(0),
194           num_output_files(0),
195           num_output_files_blob(0),
196           num_input_records(0),
197           num_dropped_records(0),
198           count(0) {
199       int num_of_reasons = static_cast<int>(CompactionReason::kNumOfReasons);
200       for (int i = 0; i < num_of_reasons; i++) {
201         counts[i] = 0;
202       }
203     }
204 
CompactionStatsCompactionStats205     explicit CompactionStats(CompactionReason reason, int c)
206         : micros(0),
207           cpu_micros(0),
208           bytes_read_non_output_levels(0),
209           bytes_read_output_level(0),
210           bytes_read_blob(0),
211           bytes_written(0),
212           bytes_written_blob(0),
213           bytes_moved(0),
214           num_input_files_in_non_output_levels(0),
215           num_input_files_in_output_level(0),
216           num_output_files(0),
217           num_output_files_blob(0),
218           num_input_records(0),
219           num_dropped_records(0),
220           count(c) {
221       int num_of_reasons = static_cast<int>(CompactionReason::kNumOfReasons);
222       for (int i = 0; i < num_of_reasons; i++) {
223         counts[i] = 0;
224       }
225       int r = static_cast<int>(reason);
226       if (r >= 0 && r < num_of_reasons) {
227         counts[r] = c;
228       } else {
229         count = 0;
230       }
231     }
232 
CompactionStatsCompactionStats233     explicit CompactionStats(const CompactionStats& c)
234         : micros(c.micros),
235           cpu_micros(c.cpu_micros),
236           bytes_read_non_output_levels(c.bytes_read_non_output_levels),
237           bytes_read_output_level(c.bytes_read_output_level),
238           bytes_read_blob(c.bytes_read_blob),
239           bytes_written(c.bytes_written),
240           bytes_written_blob(c.bytes_written_blob),
241           bytes_moved(c.bytes_moved),
242           num_input_files_in_non_output_levels(
243               c.num_input_files_in_non_output_levels),
244           num_input_files_in_output_level(c.num_input_files_in_output_level),
245           num_output_files(c.num_output_files),
246           num_output_files_blob(c.num_output_files_blob),
247           num_input_records(c.num_input_records),
248           num_dropped_records(c.num_dropped_records),
249           count(c.count) {
250       int num_of_reasons = static_cast<int>(CompactionReason::kNumOfReasons);
251       for (int i = 0; i < num_of_reasons; i++) {
252         counts[i] = c.counts[i];
253       }
254     }
255 
256     CompactionStats& operator=(const CompactionStats& c) {
257       micros = c.micros;
258       cpu_micros = c.cpu_micros;
259       bytes_read_non_output_levels = c.bytes_read_non_output_levels;
260       bytes_read_output_level = c.bytes_read_output_level;
261       bytes_read_blob = c.bytes_read_blob;
262       bytes_written = c.bytes_written;
263       bytes_written_blob = c.bytes_written_blob;
264       bytes_moved = c.bytes_moved;
265       num_input_files_in_non_output_levels =
266           c.num_input_files_in_non_output_levels;
267       num_input_files_in_output_level = c.num_input_files_in_output_level;
268       num_output_files = c.num_output_files;
269       num_output_files_blob = c.num_output_files_blob;
270       num_input_records = c.num_input_records;
271       num_dropped_records = c.num_dropped_records;
272       count = c.count;
273 
274       int num_of_reasons = static_cast<int>(CompactionReason::kNumOfReasons);
275       for (int i = 0; i < num_of_reasons; i++) {
276         counts[i] = c.counts[i];
277       }
278       return *this;
279     }
280 
ClearCompactionStats281     void Clear() {
282       this->micros = 0;
283       this->cpu_micros = 0;
284       this->bytes_read_non_output_levels = 0;
285       this->bytes_read_output_level = 0;
286       this->bytes_read_blob = 0;
287       this->bytes_written = 0;
288       this->bytes_written_blob = 0;
289       this->bytes_moved = 0;
290       this->num_input_files_in_non_output_levels = 0;
291       this->num_input_files_in_output_level = 0;
292       this->num_output_files = 0;
293       this->num_output_files_blob = 0;
294       this->num_input_records = 0;
295       this->num_dropped_records = 0;
296       this->count = 0;
297       int num_of_reasons = static_cast<int>(CompactionReason::kNumOfReasons);
298       for (int i = 0; i < num_of_reasons; i++) {
299         counts[i] = 0;
300       }
301     }
302 
AddCompactionStats303     void Add(const CompactionStats& c) {
304       this->micros += c.micros;
305       this->cpu_micros += c.cpu_micros;
306       this->bytes_read_non_output_levels += c.bytes_read_non_output_levels;
307       this->bytes_read_output_level += c.bytes_read_output_level;
308       this->bytes_read_blob += c.bytes_read_blob;
309       this->bytes_written += c.bytes_written;
310       this->bytes_written_blob += c.bytes_written_blob;
311       this->bytes_moved += c.bytes_moved;
312       this->num_input_files_in_non_output_levels +=
313           c.num_input_files_in_non_output_levels;
314       this->num_input_files_in_output_level +=
315           c.num_input_files_in_output_level;
316       this->num_output_files += c.num_output_files;
317       this->num_output_files_blob += c.num_output_files_blob;
318       this->num_input_records += c.num_input_records;
319       this->num_dropped_records += c.num_dropped_records;
320       this->count += c.count;
321       int num_of_reasons = static_cast<int>(CompactionReason::kNumOfReasons);
322       for (int i = 0; i< num_of_reasons; i++) {
323         counts[i] += c.counts[i];
324       }
325     }
326 
SubtractCompactionStats327     void Subtract(const CompactionStats& c) {
328       this->micros -= c.micros;
329       this->cpu_micros -= c.cpu_micros;
330       this->bytes_read_non_output_levels -= c.bytes_read_non_output_levels;
331       this->bytes_read_output_level -= c.bytes_read_output_level;
332       this->bytes_read_blob -= c.bytes_read_blob;
333       this->bytes_written -= c.bytes_written;
334       this->bytes_written_blob -= c.bytes_written_blob;
335       this->bytes_moved -= c.bytes_moved;
336       this->num_input_files_in_non_output_levels -=
337           c.num_input_files_in_non_output_levels;
338       this->num_input_files_in_output_level -=
339           c.num_input_files_in_output_level;
340       this->num_output_files -= c.num_output_files;
341       this->num_output_files_blob -= c.num_output_files_blob;
342       this->num_input_records -= c.num_input_records;
343       this->num_dropped_records -= c.num_dropped_records;
344       this->count -= c.count;
345       int num_of_reasons = static_cast<int>(CompactionReason::kNumOfReasons);
346       for (int i = 0; i < num_of_reasons; i++) {
347         counts[i] -= c.counts[i];
348       }
349     }
350   };
351 
352   // For use with CacheEntryStatsCollector
353   struct CacheEntryRoleStats {
354     uint64_t cache_capacity = 0;
355     std::string cache_id;
356     std::array<uint64_t, kNumCacheEntryRoles> total_charges;
357     std::array<size_t, kNumCacheEntryRoles> entry_counts;
358     uint32_t collection_count = 0;
359     uint32_t copies_of_last_collection = 0;
360     uint64_t last_start_time_micros_ = 0;
361     uint64_t last_end_time_micros_ = 0;
362 
ClearCacheEntryRoleStats363     void Clear() {
364       // Wipe everything except collection_count
365       uint32_t saved_collection_count = collection_count;
366       *this = CacheEntryRoleStats();
367       collection_count = saved_collection_count;
368     }
369 
370     void BeginCollection(Cache*, SystemClock*, uint64_t start_time_micros);
371     std::function<void(const Slice&, void*, size_t, Cache::DeleterFn)>
372     GetEntryCallback();
373     void EndCollection(Cache*, SystemClock*, uint64_t end_time_micros);
374     void SkippedCollection();
375 
376     std::string ToString(SystemClock* clock) const;
377     void ToMap(std::map<std::string, std::string>* values,
378                SystemClock* clock) const;
379 
380    private:
381     std::unordered_map<Cache::DeleterFn, CacheEntryRole> role_map_;
382     uint64_t GetLastDurationMicros() const;
383   };
384 
Clear()385   void Clear() {
386     for (int i = 0; i < kIntStatsNumMax; i++) {
387       db_stats_[i].store(0);
388     }
389     for (int i = 0; i < INTERNAL_CF_STATS_ENUM_MAX; i++) {
390       cf_stats_count_[i] = 0;
391       cf_stats_value_[i] = 0;
392     }
393     cache_entry_stats.Clear();
394     for (auto& comp_stat : comp_stats_) {
395       comp_stat.Clear();
396     }
397     for (auto& h : file_read_latency_) {
398       h.Clear();
399     }
400     blob_file_read_latency_.Clear();
401     cf_stats_snapshot_.Clear();
402     db_stats_snapshot_.Clear();
403     bg_error_count_ = 0;
404     started_at_ = clock_->NowMicros();
405   }
406 
AddCompactionStats(int level,Env::Priority thread_pri,const CompactionStats & stats)407   void AddCompactionStats(int level, Env::Priority thread_pri,
408                           const CompactionStats& stats) {
409     comp_stats_[level].Add(stats);
410     comp_stats_by_pri_[thread_pri].Add(stats);
411   }
412 
IncBytesMoved(int level,uint64_t amount)413   void IncBytesMoved(int level, uint64_t amount) {
414     comp_stats_[level].bytes_moved += amount;
415   }
416 
AddCFStats(InternalCFStatsType type,uint64_t value)417   void AddCFStats(InternalCFStatsType type, uint64_t value) {
418     cf_stats_value_[type] += value;
419     ++cf_stats_count_[type];
420   }
421 
422   void AddDBStats(InternalDBStatsType type, uint64_t value,
423                   bool concurrent = false) {
424     auto& v = db_stats_[type];
425     if (concurrent) {
426       v.fetch_add(value, std::memory_order_relaxed);
427     } else {
428       v.store(v.load(std::memory_order_relaxed) + value,
429               std::memory_order_relaxed);
430     }
431   }
432 
GetDBStats(InternalDBStatsType type)433   uint64_t GetDBStats(InternalDBStatsType type) {
434     return db_stats_[type].load(std::memory_order_relaxed);
435   }
436 
GetFileReadHist(int level)437   HistogramImpl* GetFileReadHist(int level) {
438     return &file_read_latency_[level];
439   }
440 
GetBlobFileReadHist()441   HistogramImpl* GetBlobFileReadHist() { return &blob_file_read_latency_; }
442 
GetBackgroundErrorCount()443   uint64_t GetBackgroundErrorCount() const { return bg_error_count_; }
444 
BumpAndGetBackgroundErrorCount()445   uint64_t BumpAndGetBackgroundErrorCount() { return ++bg_error_count_; }
446 
447   bool GetStringProperty(const DBPropertyInfo& property_info,
448                          const Slice& property, std::string* value);
449 
450   bool GetMapProperty(const DBPropertyInfo& property_info,
451                       const Slice& property,
452                       std::map<std::string, std::string>* value);
453 
454   bool GetIntProperty(const DBPropertyInfo& property_info, uint64_t* value,
455                       DBImpl* db);
456 
457   bool GetIntPropertyOutOfMutex(const DBPropertyInfo& property_info,
458                                 Version* version, uint64_t* value);
459 
TEST_GetCFStatsValue()460   const uint64_t* TEST_GetCFStatsValue() const { return cf_stats_value_; }
461 
TEST_GetCompactionStats()462   const std::vector<CompactionStats>& TEST_GetCompactionStats() const {
463     return comp_stats_;
464   }
465 
TEST_GetCacheEntryRoleStats()466   const CacheEntryRoleStats& TEST_GetCacheEntryRoleStats() {
467     Status s = CollectCacheEntryStats();
468     if (!s.ok()) {
469       assert(false);
470       cache_entry_stats.Clear();
471     }
472     return cache_entry_stats;
473   }
474 
475   // Store a mapping from the user-facing DB::Properties string to our
476   // DBPropertyInfo struct used internally for retrieving properties.
477   static const std::unordered_map<std::string, DBPropertyInfo> ppt_name_to_info;
478 
479  private:
480   void DumpDBStats(std::string* value);
481   void DumpCFMapStats(std::map<std::string, std::string>* cf_stats);
482   void DumpCFMapStats(
483       const VersionStorageInfo* vstorage,
484       std::map<int, std::map<LevelStatType, double>>* level_stats,
485       CompactionStats* compaction_stats_sum);
486   void DumpCFMapStatsByPriority(
487       std::map<int, std::map<LevelStatType, double>>* priorities_stats);
488   void DumpCFMapStatsIOStalls(std::map<std::string, std::string>* cf_stats);
489   void DumpCFStats(std::string* value);
490   void DumpCFStatsNoFileHistogram(std::string* value);
491   void DumpCFFileHistogram(std::string* value);
492 
493   bool HandleBlockCacheStat(Cache** block_cache);
494 
495   Status CollectCacheEntryStats();
496 
497   // Per-DB stats
498   std::atomic<uint64_t> db_stats_[kIntStatsNumMax];
499   // Per-ColumnFamily stats
500   uint64_t cf_stats_value_[INTERNAL_CF_STATS_ENUM_MAX];
501   uint64_t cf_stats_count_[INTERNAL_CF_STATS_ENUM_MAX];
502   CacheEntryRoleStats cache_entry_stats;
503   // Per-ColumnFamily/level compaction stats
504   std::vector<CompactionStats> comp_stats_;
505   std::vector<CompactionStats> comp_stats_by_pri_;
506   std::vector<HistogramImpl> file_read_latency_;
507   HistogramImpl blob_file_read_latency_;
508 
509   // Used to compute per-interval statistics
510   struct CFStatsSnapshot {
511     // ColumnFamily-level stats
512     CompactionStats comp_stats;
513     uint64_t ingest_bytes_flush;      // Bytes written to L0 (Flush)
514     uint64_t stall_count;             // Stall count
515     // Stats from compaction jobs - bytes written, bytes read, duration.
516     uint64_t compact_bytes_write;
517     uint64_t compact_bytes_read;
518     uint64_t compact_micros;
519     double seconds_up;
520 
521     // AddFile specific stats
522     uint64_t ingest_bytes_addfile;     // Total Bytes ingested
523     uint64_t ingest_files_addfile;     // Total number of files ingested
524     uint64_t ingest_l0_files_addfile;  // Total number of files ingested to L0
525     uint64_t ingest_keys_addfile;      // Total number of keys ingested
526 
CFStatsSnapshotCFStatsSnapshot527     CFStatsSnapshot()
528         : ingest_bytes_flush(0),
529           stall_count(0),
530           compact_bytes_write(0),
531           compact_bytes_read(0),
532           compact_micros(0),
533           seconds_up(0),
534           ingest_bytes_addfile(0),
535           ingest_files_addfile(0),
536           ingest_l0_files_addfile(0),
537           ingest_keys_addfile(0) {}
538 
ClearCFStatsSnapshot539     void Clear() {
540       comp_stats.Clear();
541       ingest_bytes_flush = 0;
542       stall_count = 0;
543       compact_bytes_write = 0;
544       compact_bytes_read = 0;
545       compact_micros = 0;
546       seconds_up = 0;
547       ingest_bytes_addfile = 0;
548       ingest_files_addfile = 0;
549       ingest_l0_files_addfile = 0;
550       ingest_keys_addfile = 0;
551     }
552   } cf_stats_snapshot_;
553 
554   struct DBStatsSnapshot {
555     // DB-level stats
556     uint64_t ingest_bytes;            // Bytes written by user
557     uint64_t wal_bytes;               // Bytes written to WAL
558     uint64_t wal_synced;              // Number of times WAL is synced
559     uint64_t write_with_wal;          // Number of writes that request WAL
560     // These count the number of writes processed by the calling thread or
561     // another thread.
562     uint64_t write_other;
563     uint64_t write_self;
564     // Total number of keys written. write_self and write_other measure number
565     // of write requests written, Each of the write request can contain updates
566     // to multiple keys. num_keys_written is total number of keys updated by all
567     // those writes.
568     uint64_t num_keys_written;
569     // Total time writes delayed by stalls.
570     uint64_t write_stall_micros;
571     double seconds_up;
572 
DBStatsSnapshotDBStatsSnapshot573     DBStatsSnapshot()
574         : ingest_bytes(0),
575           wal_bytes(0),
576           wal_synced(0),
577           write_with_wal(0),
578           write_other(0),
579           write_self(0),
580           num_keys_written(0),
581           write_stall_micros(0),
582           seconds_up(0) {}
583 
ClearDBStatsSnapshot584     void Clear() {
585       ingest_bytes = 0;
586       wal_bytes = 0;
587       wal_synced = 0;
588       write_with_wal = 0;
589       write_other = 0;
590       write_self = 0;
591       num_keys_written = 0;
592       write_stall_micros = 0;
593       seconds_up = 0;
594     }
595   } db_stats_snapshot_;
596 
597   // Handler functions for getting property values. They use "value" as a value-
598   // result argument, and return true upon successfully setting "value".
599   bool HandleNumFilesAtLevel(std::string* value, Slice suffix);
600   bool HandleCompressionRatioAtLevelPrefix(std::string* value, Slice suffix);
601   bool HandleLevelStats(std::string* value, Slice suffix);
602   bool HandleStats(std::string* value, Slice suffix);
603   bool HandleCFMapStats(std::map<std::string, std::string>* compaction_stats,
604                         Slice suffix);
605   bool HandleCFStats(std::string* value, Slice suffix);
606   bool HandleCFStatsNoFileHistogram(std::string* value, Slice suffix);
607   bool HandleCFFileHistogram(std::string* value, Slice suffix);
608   bool HandleDBStats(std::string* value, Slice suffix);
609   bool HandleSsTables(std::string* value, Slice suffix);
610   bool HandleAggregatedTableProperties(std::string* value, Slice suffix);
611   bool HandleAggregatedTablePropertiesAtLevel(std::string* value, Slice suffix);
612   bool HandleAggregatedTablePropertiesMap(
613       std::map<std::string, std::string>* values, Slice suffix);
614   bool HandleAggregatedTablePropertiesAtLevelMap(
615       std::map<std::string, std::string>* values, Slice suffix);
616   bool HandleNumImmutableMemTable(uint64_t* value, DBImpl* db,
617                                   Version* version);
618   bool HandleNumImmutableMemTableFlushed(uint64_t* value, DBImpl* db,
619                                          Version* version);
620   bool HandleMemTableFlushPending(uint64_t* value, DBImpl* db,
621                                   Version* version);
622   bool HandleNumRunningFlushes(uint64_t* value, DBImpl* db, Version* version);
623   bool HandleCompactionPending(uint64_t* value, DBImpl* db, Version* version);
624   bool HandleNumRunningCompactions(uint64_t* value, DBImpl* db,
625                                    Version* version);
626   bool HandleBackgroundErrors(uint64_t* value, DBImpl* db, Version* version);
627   bool HandleCurSizeActiveMemTable(uint64_t* value, DBImpl* db,
628                                    Version* version);
629   bool HandleCurSizeAllMemTables(uint64_t* value, DBImpl* db, Version* version);
630   bool HandleSizeAllMemTables(uint64_t* value, DBImpl* db, Version* version);
631   bool HandleNumEntriesActiveMemTable(uint64_t* value, DBImpl* db,
632                                       Version* version);
633   bool HandleNumEntriesImmMemTables(uint64_t* value, DBImpl* db,
634                                     Version* version);
635   bool HandleNumDeletesActiveMemTable(uint64_t* value, DBImpl* db,
636                                       Version* version);
637   bool HandleNumDeletesImmMemTables(uint64_t* value, DBImpl* db,
638                                     Version* version);
639   bool HandleEstimateNumKeys(uint64_t* value, DBImpl* db, Version* version);
640   bool HandleNumSnapshots(uint64_t* value, DBImpl* db, Version* version);
641   bool HandleOldestSnapshotTime(uint64_t* value, DBImpl* db, Version* version);
642   bool HandleOldestSnapshotSequence(uint64_t* value, DBImpl* db,
643                                     Version* version);
644   bool HandleNumLiveVersions(uint64_t* value, DBImpl* db, Version* version);
645   bool HandleCurrentSuperVersionNumber(uint64_t* value, DBImpl* db,
646                                        Version* version);
647   bool HandleIsFileDeletionsEnabled(uint64_t* value, DBImpl* db,
648                                     Version* version);
649   bool HandleBaseLevel(uint64_t* value, DBImpl* db, Version* version);
650   bool HandleTotalSstFilesSize(uint64_t* value, DBImpl* db, Version* version);
651   bool HandleLiveSstFilesSize(uint64_t* value, DBImpl* db, Version* version);
652   bool HandleEstimatePendingCompactionBytes(uint64_t* value, DBImpl* db,
653                                             Version* version);
654   bool HandleEstimateTableReadersMem(uint64_t* value, DBImpl* db,
655                                      Version* version);
656   bool HandleEstimateLiveDataSize(uint64_t* value, DBImpl* db,
657                                   Version* version);
658   bool HandleMinLogNumberToKeep(uint64_t* value, DBImpl* db, Version* version);
659   bool HandleMinObsoleteSstNumberToKeep(uint64_t* value, DBImpl* db,
660                                         Version* version);
661   bool HandleActualDelayedWriteRate(uint64_t* value, DBImpl* db,
662                                     Version* version);
663   bool HandleIsWriteStopped(uint64_t* value, DBImpl* db, Version* version);
664   bool HandleEstimateOldestKeyTime(uint64_t* value, DBImpl* db,
665                                    Version* version);
666   bool HandleBlockCacheCapacity(uint64_t* value, DBImpl* db, Version* version);
667   bool HandleBlockCacheUsage(uint64_t* value, DBImpl* db, Version* version);
668   bool HandleBlockCachePinnedUsage(uint64_t* value, DBImpl* db,
669                                    Version* version);
670   bool HandleBlockCacheEntryStats(std::string* value, Slice suffix);
671   bool HandleBlockCacheEntryStatsMap(std::map<std::string, std::string>* values,
672                                      Slice suffix);
673   // Total number of background errors encountered. Every time a flush task
674   // or compaction task fails, this counter is incremented. The failure can
675   // be caused by any possible reason, including file system errors, out of
676   // resources, or input file corruption. Failing when retrying the same flush
677   // or compaction will cause the counter to increase too.
678   uint64_t bg_error_count_;
679 
680   const int number_levels_;
681   SystemClock* clock_;
682   ColumnFamilyData* cfd_;
683   uint64_t started_at_;
684 };
685 
686 #else
687 
688 class InternalStats {
689  public:
690   enum InternalCFStatsType {
691     L0_FILE_COUNT_LIMIT_SLOWDOWNS,
692     LOCKED_L0_FILE_COUNT_LIMIT_SLOWDOWNS,
693     MEMTABLE_LIMIT_STOPS,
694     MEMTABLE_LIMIT_SLOWDOWNS,
695     L0_FILE_COUNT_LIMIT_STOPS,
696     LOCKED_L0_FILE_COUNT_LIMIT_STOPS,
697     PENDING_COMPACTION_BYTES_LIMIT_SLOWDOWNS,
698     PENDING_COMPACTION_BYTES_LIMIT_STOPS,
699     WRITE_STALLS_ENUM_MAX,
700     BYTES_FLUSHED,
701     BYTES_INGESTED_ADD_FILE,
702     INGESTED_NUM_FILES_TOTAL,
703     INGESTED_LEVEL0_NUM_FILES_TOTAL,
704     INGESTED_NUM_KEYS_TOTAL,
705     INTERNAL_CF_STATS_ENUM_MAX,
706   };
707 
708   enum InternalDBStatsType {
709     kIntStatsWalFileBytes,
710     kIntStatsWalFileSynced,
711     kIntStatsBytesWritten,
712     kIntStatsNumKeysWritten,
713     kIntStatsWriteDoneByOther,
714     kIntStatsWriteDoneBySelf,
715     kIntStatsWriteWithWal,
716     kIntStatsWriteStallMicros,
717     kIntStatsNumMax,
718   };
719 
InternalStats(int,SystemClock *,ColumnFamilyData *)720   InternalStats(int /*num_levels*/, SystemClock* /*clock*/,
721                 ColumnFamilyData* /*cfd*/) {}
722 
723   struct CompactionStats {
724     uint64_t micros;
725     uint64_t cpu_micros;
726     uint64_t bytes_read_non_output_levels;
727     uint64_t bytes_read_output_level;
728     uint64_t bytes_read_blob;
729     uint64_t bytes_written;
730     uint64_t bytes_written_blob;
731     uint64_t bytes_moved;
732     int num_input_files_in_non_output_levels;
733     int num_input_files_in_output_level;
734     int num_output_files;
735     int num_output_files_blob;
736     uint64_t num_input_records;
737     uint64_t num_dropped_records;
738     int count;
739 
CompactionStatsCompactionStats740     explicit CompactionStats() {}
741 
CompactionStatsCompactionStats742     explicit CompactionStats(CompactionReason /*reason*/, int /*c*/) {}
743 
CompactionStatsCompactionStats744     explicit CompactionStats(const CompactionStats& /*c*/) {}
745 
AddCompactionStats746     void Add(const CompactionStats& /*c*/) {}
747 
SubtractCompactionStats748     void Subtract(const CompactionStats& /*c*/) {}
749   };
750 
AddCompactionStats(int,Env::Priority,const CompactionStats &)751   void AddCompactionStats(int /*level*/, Env::Priority /*thread_pri*/,
752                           const CompactionStats& /*stats*/) {}
753 
IncBytesMoved(int,uint64_t)754   void IncBytesMoved(int /*level*/, uint64_t /*amount*/) {}
755 
AddCFStats(InternalCFStatsType,uint64_t)756   void AddCFStats(InternalCFStatsType /*type*/, uint64_t /*value*/) {}
757 
758   void AddDBStats(InternalDBStatsType /*type*/, uint64_t /*value*/,
759                   bool /*concurrent */ = false) {}
760 
GetFileReadHist(int)761   HistogramImpl* GetFileReadHist(int /*level*/) { return nullptr; }
762 
GetBlobFileReadHist()763   HistogramImpl* GetBlobFileReadHist() { return nullptr; }
764 
GetBackgroundErrorCount()765   uint64_t GetBackgroundErrorCount() const { return 0; }
766 
BumpAndGetBackgroundErrorCount()767   uint64_t BumpAndGetBackgroundErrorCount() { return 0; }
768 
GetStringProperty(const DBPropertyInfo &,const Slice &,std::string *)769   bool GetStringProperty(const DBPropertyInfo& /*property_info*/,
770                          const Slice& /*property*/, std::string* /*value*/) {
771     return false;
772   }
773 
GetMapProperty(const DBPropertyInfo &,const Slice &,std::map<std::string,std::string> *)774   bool GetMapProperty(const DBPropertyInfo& /*property_info*/,
775                       const Slice& /*property*/,
776                       std::map<std::string, std::string>* /*value*/) {
777     return false;
778   }
779 
GetIntProperty(const DBPropertyInfo &,uint64_t *,DBImpl *)780   bool GetIntProperty(const DBPropertyInfo& /*property_info*/, uint64_t* /*value*/,
781                       DBImpl* /*db*/) const {
782     return false;
783   }
784 
GetIntPropertyOutOfMutex(const DBPropertyInfo &,Version *,uint64_t *)785   bool GetIntPropertyOutOfMutex(const DBPropertyInfo& /*property_info*/,
786                                 Version* /*version*/, uint64_t* /*value*/) const {
787     return false;
788   }
789 };
790 #endif  // !ROCKSDB_LITE
791 
792 }  // namespace ROCKSDB_NAMESPACE
793