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