internal_stats.h 22.9 KB
Newer Older
1
//  Copyright (c) 2011-present, Facebook, Inc.  All rights reserved.
S
Siying Dong 已提交
2 3 4
//  This source code is licensed under both the GPLv2 (found in the
//  COPYING file in the root directory) and Apache 2.0 License
//  (found in the LICENSE.Apache file in the root directory).
I
Igor Canadi 已提交
5 6 7 8 9 10 11
//
// Copyright (c) 2011 The LevelDB Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. See the AUTHORS file for names of contributors.
//

#pragma once
12
#include <map>
I
Igor Canadi 已提交
13
#include <string>
14 15 16
#include <vector>

#include "db/version_set.h"
I
Igor Canadi 已提交
17

18 19
class ColumnFamilyData;

I
Igor Canadi 已提交
20
namespace rocksdb {
21

22
class DBImpl;
S
Siying Dong 已提交
23
class MemTableList;
24

25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44
// Config for retrieving a property's value.
struct DBPropertyInfo {
  bool need_out_of_mutex;

  // gcc had an internal error for initializing union of pointer-to-member-
  // functions. Workaround is to populate exactly one of the following function
  // pointers with a non-nullptr value.

  // @param value Value-result argument for storing the property's string value
  // @param suffix Argument portion of the property. For example, suffix would
  //      be "5" for the property "rocksdb.num-files-at-level5". So far, only
  //      certain string properties take an argument.
  bool (InternalStats::*handle_string)(std::string* value, Slice suffix);

  // @param value Value-result argument for storing the property's uint64 value
  // @param db Many of the int properties rely on DBImpl methods.
  // @param version Version is needed in case the property is retrieved without
  //      holding db mutex, which is only supported for int properties.
  bool (InternalStats::*handle_int)(uint64_t* value, DBImpl* db,
                                    Version* version);
45 46 47

  // @param props Map of general properties to populate
  bool (InternalStats::*handle_map)(std::map<std::string, std::string>* props);
48 49 50 51

  // handle the string type properties rely on DBImpl methods
  // @param value Value-result argument for storing the property's string value
  bool (DBImpl::*handle_string_dbimpl)(std::string* value);
52 53
};

54
extern const DBPropertyInfo* GetPropertyInfo(const Slice& property);
55 56

#ifndef ROCKSDB_LITE
T
Tomas Kolda 已提交
57
#undef SCORE
58 59 60 61
enum class LevelStatType {
  INVALID = 0,
  NUM_FILES,
  COMPACTED_FILES,
62
  SIZE_BYTES,
63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87
  SCORE,
  READ_GB,
  RN_GB,
  RNP1_GB,
  WRITE_GB,
  W_NEW_GB,
  MOVED_GB,
  WRITE_AMP,
  READ_MBPS,
  WRITE_MBPS,
  COMP_SEC,
  COMP_COUNT,
  AVG_SEC,
  KEY_IN,
  KEY_DROP,
  TOTAL  // total number of types
};

struct LevelStat {
  // This what will be L?.property_name in the flat map returned to the user
  std::string property_name;
  // This will be what we will print in the header in the cli
  std::string header_name;
};

I
Igor Canadi 已提交
88 89
class InternalStats {
 public:
90 91
  static const std::map<LevelStatType, LevelStat> compaction_level_stats;

92
  enum InternalCFStatsType {
93 94 95 96 97 98 99 100
    L0_FILE_COUNT_LIMIT_SLOWDOWNS,
    LOCKED_L0_FILE_COUNT_LIMIT_SLOWDOWNS,
    MEMTABLE_LIMIT_STOPS,
    MEMTABLE_LIMIT_SLOWDOWNS,
    L0_FILE_COUNT_LIMIT_STOPS,
    LOCKED_L0_FILE_COUNT_LIMIT_STOPS,
    PENDING_COMPACTION_BYTES_LIMIT_SLOWDOWNS,
    PENDING_COMPACTION_BYTES_LIMIT_STOPS,
I
Igor Canadi 已提交
101
    WRITE_STALLS_ENUM_MAX,
102
    BYTES_FLUSHED,
103
    BYTES_INGESTED_ADD_FILE,
104 105 106
    INGESTED_NUM_FILES_TOTAL,
    INGESTED_LEVEL0_NUM_FILES_TOTAL,
    INGESTED_NUM_KEYS_TOTAL,
107
    INTERNAL_CF_STATS_ENUM_MAX,
I
Igor Canadi 已提交
108 109
  };

110 111 112 113
  enum InternalDBStatsType {
    WAL_FILE_BYTES,
    WAL_FILE_SYNCED,
    BYTES_WRITTEN,
S
sdong 已提交
114
    NUMBER_KEYS_WRITTEN,
115 116 117
    WRITE_DONE_BY_OTHER,
    WRITE_DONE_BY_SELF,
    WRITE_WITH_WAL,
S
sdong 已提交
118
    WRITE_STALL_MICROS,
119 120 121
    INTERNAL_DB_STATS_ENUM_MAX,
  };

122
  InternalStats(int num_levels, Env* env, ColumnFamilyData* cfd)
123 124 125
      : db_stats_{},
        cf_stats_value_{},
        cf_stats_count_{},
126
        comp_stats_(num_levels),
127
        file_read_latency_(num_levels),
128
        bg_error_count_(0),
I
Igor Canadi 已提交
129 130
        number_levels_(num_levels),
        env_(env),
131
        cfd_(cfd),
132
        started_at_(env->NowMicros()) {}
I
Igor Canadi 已提交
133

134
  // Per level compaction stats.  comp_stats_[level] stores the stats for
I
Igor Canadi 已提交
135 136 137 138
  // compactions that produced data for the specified "level".
  struct CompactionStats {
    uint64_t micros;

139 140
    // The number of bytes read from all non-output levels
    uint64_t bytes_read_non_output_levels;
I
Igor Canadi 已提交
141

142 143
    // The number of bytes read from the compaction output level.
    uint64_t bytes_read_output_level;
I
Igor Canadi 已提交
144

145
    // Total number of bytes written during compaction
146
    uint64_t bytes_written;
I
Igor Canadi 已提交
147

148
    // Total number of bytes moved to the output level
149 150
    uint64_t bytes_moved;

151 152
    // The number of compaction input files in all non-output levels.
    int num_input_files_in_non_output_levels;
I
Igor Canadi 已提交
153

154 155
    // The number of compaction input files in the output level.
    int num_input_files_in_output_level;
I
Igor Canadi 已提交
156

157 158
    // The number of compaction output files.
    int num_output_files;
I
Igor Canadi 已提交
159

160
    // Total incoming entries during compaction between levels N and N+1
S
sdong 已提交
161
    uint64_t num_input_records;
162 163 164

    // Accumulated diff number of entries
    // (num input entries - num output entires) for compaction  levels N and N+1
S
sdong 已提交
165
    uint64_t num_dropped_records;
166

I
Igor Canadi 已提交
167 168 169
    // Number of compactions done
    int count;

170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191
    // Number of compactions done per CompactionReason
    int counts[static_cast<int>(CompactionReason::kNumOfReasons)];

    explicit CompactionStats()
        : micros(0),
          bytes_read_non_output_levels(0),
          bytes_read_output_level(0),
          bytes_written(0),
          bytes_moved(0),
          num_input_files_in_non_output_levels(0),
          num_input_files_in_output_level(0),
          num_output_files(0),
          num_input_records(0),
          num_dropped_records(0),
          count(0) {
      int num_of_reasons = static_cast<int>(CompactionReason::kNumOfReasons);
      for (int i = 0; i < num_of_reasons; i++) {
        counts[i] = 0;
      }
    }

    explicit CompactionStats(CompactionReason reason, int c)
I
Igor Canadi 已提交
192
        : micros(0),
193 194
          bytes_read_non_output_levels(0),
          bytes_read_output_level(0),
I
Igor Canadi 已提交
195
          bytes_written(0),
196
          bytes_moved(0),
197 198 199
          num_input_files_in_non_output_levels(0),
          num_input_files_in_output_level(0),
          num_output_files(0),
200 201
          num_input_records(0),
          num_dropped_records(0),
202 203 204 205 206 207 208 209 210 211 212 213
          count(c) {
      int num_of_reasons = static_cast<int>(CompactionReason::kNumOfReasons);
      for (int i = 0; i < num_of_reasons; i++) {
        counts[i] = 0;
      }
      int r = static_cast<int>(reason);
      if (r >= 0 && r < num_of_reasons) {
        counts[r] = c;
      } else {
        count = 0;
      }
    }
I
Igor Canadi 已提交
214

215 216
    explicit CompactionStats(const CompactionStats& c)
        : micros(c.micros),
217 218
          bytes_read_non_output_levels(c.bytes_read_non_output_levels),
          bytes_read_output_level(c.bytes_read_output_level),
219
          bytes_written(c.bytes_written),
220
          bytes_moved(c.bytes_moved),
221 222 223 224 225
          num_input_files_in_non_output_levels(
              c.num_input_files_in_non_output_levels),
          num_input_files_in_output_level(
              c.num_input_files_in_output_level),
          num_output_files(c.num_output_files),
226 227
          num_input_records(c.num_input_records),
          num_dropped_records(c.num_dropped_records),
228 229 230 231 232 233
          count(c.count) {
      int num_of_reasons = static_cast<int>(CompactionReason::kNumOfReasons);
      for (int i = 0; i < num_of_reasons; i++) {
        counts[i] = c.counts[i];
      }
    }
234

S
Siying Dong 已提交
235 236 237 238 239 240 241 242 243 244 245 246
    void Clear() {
      this->micros = 0;
      this->bytes_read_non_output_levels = 0;
      this->bytes_read_output_level = 0;
      this->bytes_written = 0;
      this->bytes_moved = 0;
      this->num_input_files_in_non_output_levels = 0;
      this->num_input_files_in_output_level = 0;
      this->num_output_files = 0;
      this->num_input_records = 0;
      this->num_dropped_records = 0;
      this->count = 0;
247 248 249 250
      int num_of_reasons = static_cast<int>(CompactionReason::kNumOfReasons);
      for (int i = 0; i < num_of_reasons; i++) {
        counts[i] = 0;
      }
S
Siying Dong 已提交
251 252
    }

I
Igor Canadi 已提交
253 254
    void Add(const CompactionStats& c) {
      this->micros += c.micros;
255 256
      this->bytes_read_non_output_levels += c.bytes_read_non_output_levels;
      this->bytes_read_output_level += c.bytes_read_output_level;
I
Igor Canadi 已提交
257
      this->bytes_written += c.bytes_written;
258
      this->bytes_moved += c.bytes_moved;
259 260 261 262 263
      this->num_input_files_in_non_output_levels +=
          c.num_input_files_in_non_output_levels;
      this->num_input_files_in_output_level +=
          c.num_input_files_in_output_level;
      this->num_output_files += c.num_output_files;
264 265
      this->num_input_records += c.num_input_records;
      this->num_dropped_records += c.num_dropped_records;
L
Lei Jin 已提交
266
      this->count += c.count;
267 268 269 270
      int num_of_reasons = static_cast<int>(CompactionReason::kNumOfReasons);
      for (int i = 0; i< num_of_reasons; i++) {
        counts[i] += c.counts[i];
      }
I
Igor Canadi 已提交
271
    }
272 273 274

    void Subtract(const CompactionStats& c) {
      this->micros -= c.micros;
275 276
      this->bytes_read_non_output_levels -= c.bytes_read_non_output_levels;
      this->bytes_read_output_level -= c.bytes_read_output_level;
277
      this->bytes_written -= c.bytes_written;
278
      this->bytes_moved -= c.bytes_moved;
279 280 281 282 283
      this->num_input_files_in_non_output_levels -=
          c.num_input_files_in_non_output_levels;
      this->num_input_files_in_output_level -=
          c.num_input_files_in_output_level;
      this->num_output_files -= c.num_output_files;
284 285
      this->num_input_records -= c.num_input_records;
      this->num_dropped_records -= c.num_dropped_records;
286
      this->count -= c.count;
287 288 289 290
      int num_of_reasons = static_cast<int>(CompactionReason::kNumOfReasons);
      for (int i = 0; i < num_of_reasons; i++) {
        counts[i] -= c.counts[i];
      }
291
    }
I
Igor Canadi 已提交
292 293
  };

S
Siying Dong 已提交
294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313
  void Clear() {
    for (int i = 0; i < INTERNAL_DB_STATS_ENUM_MAX; i++) {
      db_stats_[i].store(0);
    }
    for (int i = 0; i < INTERNAL_CF_STATS_ENUM_MAX; i++) {
      cf_stats_count_[i] = 0;
      cf_stats_value_[i] = 0;
    }
    for (auto& comp_stat : comp_stats_) {
      comp_stat.Clear();
    }
    for (auto& h : file_read_latency_) {
      h.Clear();
    }
    cf_stats_snapshot_.Clear();
    db_stats_snapshot_.Clear();
    bg_error_count_ = 0;
    started_at_ = env_->NowMicros();
  }

I
Igor Canadi 已提交
314
  void AddCompactionStats(int level, const CompactionStats& stats) {
315
    comp_stats_[level].Add(stats);
I
Igor Canadi 已提交
316 317
  }

318 319 320 321
  void IncBytesMoved(int level, uint64_t amount) {
    comp_stats_[level].bytes_moved += amount;
  }

322 323 324
  void AddCFStats(InternalCFStatsType type, uint64_t value) {
    cf_stats_value_[type] += value;
    ++cf_stats_count_[type];
I
Igor Canadi 已提交
325 326
  }

327 328
  void AddDBStats(InternalDBStatsType type, uint64_t value,
                  bool concurrent = false) {
329
    auto& v = db_stats_[type];
330 331 332 333 334 335
    if (concurrent) {
      v.fetch_add(value, std::memory_order_relaxed);
    } else {
      v.store(v.load(std::memory_order_relaxed) + value,
              std::memory_order_relaxed);
    }
336 337 338 339
  }

  uint64_t GetDBStats(InternalDBStatsType type) {
    return db_stats_[type].load(std::memory_order_relaxed);
I
Igor Canadi 已提交
340 341
  }

342 343 344 345
  HistogramImpl* GetFileReadHist(int level) {
    return &file_read_latency_[level];
  }

346 347 348 349
  uint64_t GetBackgroundErrorCount() const { return bg_error_count_; }

  uint64_t BumpAndGetBackgroundErrorCount() { return ++bg_error_count_; }

350 351 352
  bool GetStringProperty(const DBPropertyInfo& property_info,
                         const Slice& property, std::string* value);

353 354
  bool GetMapProperty(const DBPropertyInfo& property_info,
                      const Slice& property,
355
                      std::map<std::string, std::string>* value);
356

357 358
  bool GetIntProperty(const DBPropertyInfo& property_info, uint64_t* value,
                      DBImpl* db);
I
Igor Canadi 已提交
359

360 361
  bool GetIntPropertyOutOfMutex(const DBPropertyInfo& property_info,
                                Version* version, uint64_t* value);
362

363 364 365 366
  const std::vector<CompactionStats>& TEST_GetCompactionStats() const {
    return comp_stats_;
  }

367 368 369
  // Store a mapping from the user-facing DB::Properties string to our
  // DBPropertyInfo struct used internally for retrieving properties.
  static const std::unordered_map<std::string, DBPropertyInfo> ppt_name_to_info;
370

I
Igor Canadi 已提交
371
 private:
372
  void DumpDBStats(std::string* value);
373
  void DumpCFMapStats(std::map<std::string, std::string>* cf_stats);
374
  void DumpCFMapStats(
375 376
      std::map<int, std::map<LevelStatType, double>>* level_stats,
      CompactionStats* compaction_stats_sum);
377
  void DumpCFMapStatsIOStalls(std::map<std::string, std::string>* cf_stats);
378
  void DumpCFStats(std::string* value);
379 380
  void DumpCFStatsNoFileHistogram(std::string* value);
  void DumpCFFileHistogram(std::string* value);
381

Y
Yi Wu 已提交
382 383
  bool HandleBlockCacheStat(Cache** block_cache);

384
  // Per-DB stats
385
  std::atomic<uint64_t> db_stats_[INTERNAL_DB_STATS_ENUM_MAX];
386
  // Per-ColumnFamily stats
387 388
  uint64_t cf_stats_value_[INTERNAL_CF_STATS_ENUM_MAX];
  uint64_t cf_stats_count_[INTERNAL_CF_STATS_ENUM_MAX];
389 390
  // Per-ColumnFamily/level compaction stats
  std::vector<CompactionStats> comp_stats_;
391
  std::vector<HistogramImpl> file_read_latency_;
I
Igor Canadi 已提交
392 393

  // Used to compute per-interval statistics
394 395 396
  struct CFStatsSnapshot {
    // ColumnFamily-level stats
    CompactionStats comp_stats;
397
    uint64_t ingest_bytes_flush;      // Bytes written to L0 (Flush)
398
    uint64_t stall_count;             // Stall count
399 400 401 402 403
    // Stats from compaction jobs - bytes written, bytes read, duration.
    uint64_t compact_bytes_write;
    uint64_t compact_bytes_read;
    uint64_t compact_micros;
    double seconds_up;
404

405 406 407 408 409 410
    // AddFile specific stats
    uint64_t ingest_bytes_addfile;     // Total Bytes ingested
    uint64_t ingest_files_addfile;     // Total number of files ingested
    uint64_t ingest_l0_files_addfile;  // Total number of files ingested to L0
    uint64_t ingest_keys_addfile;      // Total number of keys ingested

411
    CFStatsSnapshot()
412
        : ingest_bytes_flush(0),
413 414 415 416
          stall_count(0),
          compact_bytes_write(0),
          compact_bytes_read(0),
          compact_micros(0),
417 418 419 420 421
          seconds_up(0),
          ingest_bytes_addfile(0),
          ingest_files_addfile(0),
          ingest_l0_files_addfile(0),
          ingest_keys_addfile(0) {}
S
Siying Dong 已提交
422 423 424 425 426 427 428 429 430 431 432 433 434 435

    void Clear() {
      comp_stats.Clear();
      ingest_bytes_flush = 0;
      stall_count = 0;
      compact_bytes_write = 0;
      compact_bytes_read = 0;
      compact_micros = 0;
      seconds_up = 0;
      ingest_bytes_addfile = 0;
      ingest_files_addfile = 0;
      ingest_l0_files_addfile = 0;
      ingest_keys_addfile = 0;
    }
436 437 438 439 440 441 442 443
  } cf_stats_snapshot_;

  struct DBStatsSnapshot {
    // DB-level stats
    uint64_t ingest_bytes;            // Bytes written by user
    uint64_t wal_bytes;               // Bytes written to WAL
    uint64_t wal_synced;              // Number of times WAL is synced
    uint64_t write_with_wal;          // Number of writes that request WAL
I
Igor Canadi 已提交
444 445
    // These count the number of writes processed by the calling thread or
    // another thread.
446 447
    uint64_t write_other;
    uint64_t write_self;
S
sdong 已提交
448 449 450 451 452
    // Total number of keys written. write_self and write_other measure number
    // of write requests written, Each of the write request can contain updates
    // to multiple keys. num_keys_written is total number of keys updated by all
    // those writes.
    uint64_t num_keys_written;
S
sdong 已提交
453 454
    // Total time writes delayed by stalls.
    uint64_t write_stall_micros;
455 456 457 458 459 460 461 462 463
    double seconds_up;

    DBStatsSnapshot()
        : ingest_bytes(0),
          wal_bytes(0),
          wal_synced(0),
          write_with_wal(0),
          write_other(0),
          write_self(0),
464
          num_keys_written(0),
S
sdong 已提交
465
          write_stall_micros(0),
466
          seconds_up(0) {}
S
Siying Dong 已提交
467 468 469 470 471 472 473 474 475 476 477 478

    void Clear() {
      ingest_bytes = 0;
      wal_bytes = 0;
      wal_synced = 0;
      write_with_wal = 0;
      write_other = 0;
      write_self = 0;
      num_keys_written = 0;
      write_stall_micros = 0;
      seconds_up = 0;
    }
479
  } db_stats_snapshot_;
I
Igor Canadi 已提交
480

481 482 483
  // Handler functions for getting property values. They use "value" as a value-
  // result argument, and return true upon successfully setting "value".
  bool HandleNumFilesAtLevel(std::string* value, Slice suffix);
484
  bool HandleCompressionRatioAtLevelPrefix(std::string* value, Slice suffix);
485 486
  bool HandleLevelStats(std::string* value, Slice suffix);
  bool HandleStats(std::string* value, Slice suffix);
487
  bool HandleCFMapStats(std::map<std::string, std::string>* compaction_stats);
488
  bool HandleCFStats(std::string* value, Slice suffix);
489 490
  bool HandleCFStatsNoFileHistogram(std::string* value, Slice suffix);
  bool HandleCFFileHistogram(std::string* value, Slice suffix);
491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521
  bool HandleDBStats(std::string* value, Slice suffix);
  bool HandleSsTables(std::string* value, Slice suffix);
  bool HandleAggregatedTableProperties(std::string* value, Slice suffix);
  bool HandleAggregatedTablePropertiesAtLevel(std::string* value, Slice suffix);
  bool HandleNumImmutableMemTable(uint64_t* value, DBImpl* db,
                                  Version* version);
  bool HandleNumImmutableMemTableFlushed(uint64_t* value, DBImpl* db,
                                         Version* version);
  bool HandleMemTableFlushPending(uint64_t* value, DBImpl* db,
                                  Version* version);
  bool HandleNumRunningFlushes(uint64_t* value, DBImpl* db, Version* version);
  bool HandleCompactionPending(uint64_t* value, DBImpl* db, Version* version);
  bool HandleNumRunningCompactions(uint64_t* value, DBImpl* db,
                                   Version* version);
  bool HandleBackgroundErrors(uint64_t* value, DBImpl* db, Version* version);
  bool HandleCurSizeActiveMemTable(uint64_t* value, DBImpl* db,
                                   Version* version);
  bool HandleCurSizeAllMemTables(uint64_t* value, DBImpl* db, Version* version);
  bool HandleSizeAllMemTables(uint64_t* value, DBImpl* db, Version* version);
  bool HandleNumEntriesActiveMemTable(uint64_t* value, DBImpl* db,
                                      Version* version);
  bool HandleNumEntriesImmMemTables(uint64_t* value, DBImpl* db,
                                    Version* version);
  bool HandleNumDeletesActiveMemTable(uint64_t* value, DBImpl* db,
                                      Version* version);
  bool HandleNumDeletesImmMemTables(uint64_t* value, DBImpl* db,
                                    Version* version);
  bool HandleEstimateNumKeys(uint64_t* value, DBImpl* db, Version* version);
  bool HandleNumSnapshots(uint64_t* value, DBImpl* db, Version* version);
  bool HandleOldestSnapshotTime(uint64_t* value, DBImpl* db, Version* version);
  bool HandleNumLiveVersions(uint64_t* value, DBImpl* db, Version* version);
522 523
  bool HandleCurrentSuperVersionNumber(uint64_t* value, DBImpl* db,
                                       Version* version);
524 525 526 527
  bool HandleIsFileDeletionsEnabled(uint64_t* value, DBImpl* db,
                                    Version* version);
  bool HandleBaseLevel(uint64_t* value, DBImpl* db, Version* version);
  bool HandleTotalSstFilesSize(uint64_t* value, DBImpl* db, Version* version);
528
  bool HandleLiveSstFilesSize(uint64_t* value, DBImpl* db, Version* version);
529 530 531 532 533 534
  bool HandleEstimatePendingCompactionBytes(uint64_t* value, DBImpl* db,
                                            Version* version);
  bool HandleEstimateTableReadersMem(uint64_t* value, DBImpl* db,
                                     Version* version);
  bool HandleEstimateLiveDataSize(uint64_t* value, DBImpl* db,
                                  Version* version);
535
  bool HandleMinLogNumberToKeep(uint64_t* value, DBImpl* db, Version* version);
536 537 538
  bool HandleActualDelayedWriteRate(uint64_t* value, DBImpl* db,
                                    Version* version);
  bool HandleIsWriteStopped(uint64_t* value, DBImpl* db, Version* version);
Y
Yi Wu 已提交
539 540
  bool HandleEstimateOldestKeyTime(uint64_t* value, DBImpl* db,
                                   Version* version);
Y
Yi Wu 已提交
541 542 543 544
  bool HandleBlockCacheCapacity(uint64_t* value, DBImpl* db, Version* version);
  bool HandleBlockCacheUsage(uint64_t* value, DBImpl* db, Version* version);
  bool HandleBlockCachePinnedUsage(uint64_t* value, DBImpl* db,
                                   Version* version);
545 546 547 548 549 550 551
  // Total number of background errors encountered. Every time a flush task
  // or compaction task fails, this counter is incremented. The failure can
  // be caused by any possible reason, including file system errors, out of
  // resources, or input file corruption. Failing when retrying the same flush
  // or compaction will cause the counter to increase too.
  uint64_t bg_error_count_;

552
  const int number_levels_;
I
Igor Canadi 已提交
553
  Env* env_;
554
  ColumnFamilyData* cfd_;
S
Siying Dong 已提交
555
  uint64_t started_at_;
I
Igor Canadi 已提交
556 557
};

558 559 560 561 562
#else

class InternalStats {
 public:
  enum InternalCFStatsType {
563 564 565 566 567 568 569 570
    L0_FILE_COUNT_LIMIT_SLOWDOWNS,
    LOCKED_L0_FILE_COUNT_LIMIT_SLOWDOWNS,
    MEMTABLE_LIMIT_STOPS,
    MEMTABLE_LIMIT_SLOWDOWNS,
    L0_FILE_COUNT_LIMIT_STOPS,
    LOCKED_L0_FILE_COUNT_LIMIT_STOPS,
    PENDING_COMPACTION_BYTES_LIMIT_SLOWDOWNS,
    PENDING_COMPACTION_BYTES_LIMIT_STOPS,
571 572
    WRITE_STALLS_ENUM_MAX,
    BYTES_FLUSHED,
573
    BYTES_INGESTED_ADD_FILE,
574 575 576
    INGESTED_NUM_FILES_TOTAL,
    INGESTED_LEVEL0_NUM_FILES_TOTAL,
    INGESTED_NUM_KEYS_TOTAL,
577 578 579 580 581 582 583 584 585 586 587
    INTERNAL_CF_STATS_ENUM_MAX,
  };

  enum InternalDBStatsType {
    WAL_FILE_BYTES,
    WAL_FILE_SYNCED,
    BYTES_WRITTEN,
    NUMBER_KEYS_WRITTEN,
    WRITE_DONE_BY_OTHER,
    WRITE_DONE_BY_SELF,
    WRITE_WITH_WAL,
S
sdong 已提交
588
    WRITE_STALL_MICROS,
589 590 591
    INTERNAL_DB_STATS_ENUM_MAX,
  };

592
  InternalStats(int /*num_levels*/, Env* /*env*/, ColumnFamilyData* /*cfd*/) {}
593 594 595

  struct CompactionStats {
    uint64_t micros;
596 597
    uint64_t bytes_read_non_output_levels;
    uint64_t bytes_read_output_level;
598
    uint64_t bytes_written;
599
    uint64_t bytes_moved;
600 601 602
    int num_input_files_in_non_output_levels;
    int num_input_files_in_output_level;
    int num_output_files;
603 604 605 606
    uint64_t num_input_records;
    uint64_t num_dropped_records;
    int count;

607 608
    explicit CompactionStats() {}

609
    explicit CompactionStats(CompactionReason /*reason*/, int /*c*/) {}
610

611
    explicit CompactionStats(const CompactionStats& /*c*/) {}
612

613
    void Add(const CompactionStats& /*c*/) {}
614

615
    void Subtract(const CompactionStats& /*c*/) {}
616 617
  };

618
  void AddCompactionStats(int /*level*/, const CompactionStats& /*stats*/) {}
619

620
  void IncBytesMoved(int /*level*/, uint64_t /*amount*/) {}
621

622
  void AddCFStats(InternalCFStatsType /*type*/, uint64_t /*value*/) {}
623

624 625
  void AddDBStats(InternalDBStatsType /*type*/, uint64_t /*value*/,
                  bool /*concurrent */ = false) {}
626

627
  HistogramImpl* GetFileReadHist(int /*level*/) { return nullptr; }
628

629 630 631 632
  uint64_t GetBackgroundErrorCount() const { return 0; }

  uint64_t BumpAndGetBackgroundErrorCount() { return 0; }

633 634
  bool GetStringProperty(const DBPropertyInfo& /*property_info*/,
                         const Slice& /*property*/, std::string* /*value*/) {
635 636
    return false;
  }
637

638 639 640
  bool GetMapProperty(const DBPropertyInfo& /*property_info*/,
                      const Slice& /*property*/,
                      std::map<std::string, std::string>* /*value*/) {
641 642 643
    return false;
  }

644 645
  bool GetIntProperty(const DBPropertyInfo& /*property_info*/, uint64_t* /*value*/,
                      DBImpl* /*db*/) const {
646 647
    return false;
  }
648

649 650
  bool GetIntPropertyOutOfMutex(const DBPropertyInfo& /*property_info*/,
                                Version* /*version*/, uint64_t* /*value*/) const {
651 652
    return false;
  }
653 654 655
};
#endif  // !ROCKSDB_LITE

I
Igor Canadi 已提交
656
}  // namespace rocksdb