diff --git a/db/db_impl/db_impl_write.cc b/db/db_impl/db_impl_write.cc index d15165122..fcf34f83f 100644 --- a/db/db_impl/db_impl_write.cc +++ b/db/db_impl/db_impl_write.cc @@ -294,18 +294,19 @@ Status DBImpl::WriteImpl(const WriteOptions& write_options, // We're optimistic, updating the stats before we successfully // commit. That lets us release our leader status early. auto stats = default_cf_internal_stats_; - stats->AddDBStats(InternalStats::NUMBER_KEYS_WRITTEN, total_count, + stats->AddDBStats(InternalStats::kIntStatsNumKeysWritten, total_count, concurrent_update); RecordTick(stats_, NUMBER_KEYS_WRITTEN, total_count); - stats->AddDBStats(InternalStats::BYTES_WRITTEN, total_byte_size, + stats->AddDBStats(InternalStats::kIntStatsBytesWritten, total_byte_size, concurrent_update); RecordTick(stats_, BYTES_WRITTEN, total_byte_size); - stats->AddDBStats(InternalStats::WRITE_DONE_BY_SELF, 1, concurrent_update); + stats->AddDBStats(InternalStats::kIntStatsWriteDoneBySelf, 1, + concurrent_update); RecordTick(stats_, WRITE_DONE_BY_SELF); auto write_done_by_other = write_group.size - 1; if (write_done_by_other > 0) { - stats->AddDBStats(InternalStats::WRITE_DONE_BY_OTHER, write_done_by_other, - concurrent_update); + stats->AddDBStats(InternalStats::kIntStatsWriteDoneByOther, + write_done_by_other, concurrent_update); RecordTick(stats_, WRITE_DONE_BY_OTHER, write_done_by_other); } RecordInHistogram(stats_, BYTES_PER_WRITE, total_byte_size); @@ -503,9 +504,9 @@ Status DBImpl::PipelinedWriteImpl(const WriteOptions& write_options, } auto stats = default_cf_internal_stats_; - stats->AddDBStats(InternalStats::NUMBER_KEYS_WRITTEN, total_count); + stats->AddDBStats(InternalStats::kIntStatsNumKeysWritten, total_count); RecordTick(stats_, NUMBER_KEYS_WRITTEN, total_count); - stats->AddDBStats(InternalStats::BYTES_WRITTEN, total_byte_size); + stats->AddDBStats(InternalStats::kIntStatsBytesWritten, total_byte_size); RecordTick(stats_, BYTES_WRITTEN, total_byte_size); RecordInHistogram(stats_, BYTES_PER_WRITE, total_byte_size); @@ -513,10 +514,10 @@ Status DBImpl::PipelinedWriteImpl(const WriteOptions& write_options, if (w.status.ok() && !write_options.disableWAL) { PERF_TIMER_GUARD(write_wal_time); - stats->AddDBStats(InternalStats::WRITE_DONE_BY_SELF, 1); + stats->AddDBStats(InternalStats::kIntStatsWriteDoneBySelf, 1); RecordTick(stats_, WRITE_DONE_BY_SELF, 1); if (wal_write_group.size > 1) { - stats->AddDBStats(InternalStats::WRITE_DONE_BY_OTHER, + stats->AddDBStats(InternalStats::kIntStatsWriteDoneByOther, wal_write_group.size - 1); RecordTick(stats_, WRITE_DONE_BY_OTHER, wal_write_group.size - 1); } @@ -593,7 +594,7 @@ Status DBImpl::UnorderedWriteMemtable(const WriteOptions& write_options, w.sequence = seq; size_t total_count = WriteBatchInternal::Count(my_batch); InternalStats* stats = default_cf_internal_stats_; - stats->AddDBStats(InternalStats::NUMBER_KEYS_WRITTEN, total_count); + stats->AddDBStats(InternalStats::kIntStatsNumKeysWritten, total_count); RecordTick(stats_, NUMBER_KEYS_WRITTEN, total_count); ColumnFamilyMemTablesImpl column_family_memtables( @@ -703,15 +704,16 @@ Status DBImpl::WriteImplWALOnly( // We're optimistic, updating the stats before we successfully // commit. That lets us release our leader status early. auto stats = default_cf_internal_stats_; - stats->AddDBStats(InternalStats::BYTES_WRITTEN, total_byte_size, + stats->AddDBStats(InternalStats::kIntStatsBytesWritten, total_byte_size, concurrent_update); RecordTick(stats_, BYTES_WRITTEN, total_byte_size); - stats->AddDBStats(InternalStats::WRITE_DONE_BY_SELF, 1, concurrent_update); + stats->AddDBStats(InternalStats::kIntStatsWriteDoneBySelf, 1, + concurrent_update); RecordTick(stats_, WRITE_DONE_BY_SELF); auto write_done_by_other = write_group.size - 1; if (write_done_by_other > 0) { - stats->AddDBStats(InternalStats::WRITE_DONE_BY_OTHER, write_done_by_other, - concurrent_update); + stats->AddDBStats(InternalStats::kIntStatsWriteDoneByOther, + write_done_by_other, concurrent_update); RecordTick(stats_, WRITE_DONE_BY_OTHER, write_done_by_other); } RecordInHistogram(stats_, BYTES_PER_WRITE, total_byte_size); @@ -1043,12 +1045,12 @@ Status DBImpl::WriteToWAL(const WriteThread::WriteGroup& write_group, if (status.ok()) { auto stats = default_cf_internal_stats_; if (need_log_sync) { - stats->AddDBStats(InternalStats::WAL_FILE_SYNCED, 1); + stats->AddDBStats(InternalStats::kIntStatsWalFileSynced, 1); RecordTick(stats_, WAL_FILE_SYNCED); } - stats->AddDBStats(InternalStats::WAL_FILE_BYTES, log_size); + stats->AddDBStats(InternalStats::kIntStatsWalFileBytes, log_size); RecordTick(stats_, WAL_FILE_BYTES, log_size); - stats->AddDBStats(InternalStats::WRITE_WITH_WAL, write_with_wal); + stats->AddDBStats(InternalStats::kIntStatsWriteWithWal, write_with_wal); RecordTick(stats_, WRITE_WITH_WAL, write_with_wal); } return status; @@ -1094,9 +1096,10 @@ Status DBImpl::ConcurrentWriteToWAL(const WriteThread::WriteGroup& write_group, if (status.ok()) { const bool concurrent = true; auto stats = default_cf_internal_stats_; - stats->AddDBStats(InternalStats::WAL_FILE_BYTES, log_size, concurrent); + stats->AddDBStats(InternalStats::kIntStatsWalFileBytes, log_size, + concurrent); RecordTick(stats_, WAL_FILE_BYTES, log_size); - stats->AddDBStats(InternalStats::WRITE_WITH_WAL, write_with_wal, + stats->AddDBStats(InternalStats::kIntStatsWriteWithWal, write_with_wal, concurrent); RecordTick(stats_, WRITE_WITH_WAL, write_with_wal); } @@ -1398,8 +1401,8 @@ Status DBImpl::DelayWrite(uint64_t num_bytes, } assert(!delayed || !write_options.no_slowdown); if (delayed) { - default_cf_internal_stats_->AddDBStats(InternalStats::WRITE_STALL_MICROS, - time_delayed); + default_cf_internal_stats_->AddDBStats( + InternalStats::kIntStatsWriteStallMicros, time_delayed); RecordTick(stats_, STALL_MICROS, time_delayed); } diff --git a/db/internal_stats.cc b/db/internal_stats.cc index 50f6ed2e6..2ddd9122e 100644 --- a/db/internal_stats.cc +++ b/db/internal_stats.cc @@ -954,14 +954,17 @@ void InternalStats::DumpDBStats(std::string* value) { seconds_up, interval_seconds_up); value->append(buf); // Cumulative - uint64_t user_bytes_written = GetDBStats(InternalStats::BYTES_WRITTEN); - uint64_t num_keys_written = GetDBStats(InternalStats::NUMBER_KEYS_WRITTEN); - uint64_t write_other = GetDBStats(InternalStats::WRITE_DONE_BY_OTHER); - uint64_t write_self = GetDBStats(InternalStats::WRITE_DONE_BY_SELF); - uint64_t wal_bytes = GetDBStats(InternalStats::WAL_FILE_BYTES); - uint64_t wal_synced = GetDBStats(InternalStats::WAL_FILE_SYNCED); - uint64_t write_with_wal = GetDBStats(InternalStats::WRITE_WITH_WAL); - uint64_t write_stall_micros = GetDBStats(InternalStats::WRITE_STALL_MICROS); + uint64_t user_bytes_written = + GetDBStats(InternalStats::kIntStatsBytesWritten); + uint64_t num_keys_written = + GetDBStats(InternalStats::kIntStatsNumKeysWritten); + uint64_t write_other = GetDBStats(InternalStats::kIntStatsWriteDoneByOther); + uint64_t write_self = GetDBStats(InternalStats::kIntStatsWriteDoneBySelf); + uint64_t wal_bytes = GetDBStats(InternalStats::kIntStatsWalFileBytes); + uint64_t wal_synced = GetDBStats(InternalStats::kIntStatsWalFileSynced); + uint64_t write_with_wal = GetDBStats(InternalStats::kIntStatsWriteWithWal); + uint64_t write_stall_micros = + GetDBStats(InternalStats::kIntStatsWriteStallMicros); const int kHumanMicrosLen = 32; char human_micros[kHumanMicrosLen]; diff --git a/db/internal_stats.h b/db/internal_stats.h index ebe90d574..24a8d98e6 100644 --- a/db/internal_stats.h +++ b/db/internal_stats.h @@ -109,15 +109,15 @@ class InternalStats { }; enum InternalDBStatsType { - WAL_FILE_BYTES, - WAL_FILE_SYNCED, - BYTES_WRITTEN, - NUMBER_KEYS_WRITTEN, - WRITE_DONE_BY_OTHER, - WRITE_DONE_BY_SELF, - WRITE_WITH_WAL, - WRITE_STALL_MICROS, - INTERNAL_DB_STATS_ENUM_MAX, + kIntStatsWalFileBytes, + kIntStatsWalFileSynced, + kIntStatsBytesWritten, + kIntStatsNumKeysWritten, + kIntStatsWriteDoneByOther, + kIntStatsWriteDoneBySelf, + kIntStatsWriteWithWal, + kIntStatsWriteStallMicros, + kIntStatsNumMax, }; InternalStats(int num_levels, Env* env, ColumnFamilyData* cfd) @@ -322,7 +322,7 @@ class InternalStats { }; void Clear() { - for (int i = 0; i < INTERNAL_DB_STATS_ENUM_MAX; i++) { + for (int i = 0; i < kIntStatsNumMax; i++) { db_stats_[i].store(0); } for (int i = 0; i < INTERNAL_CF_STATS_ENUM_MAX; i++) { @@ -416,7 +416,7 @@ class InternalStats { bool HandleBlockCacheStat(Cache** block_cache); // Per-DB stats - std::atomic db_stats_[INTERNAL_DB_STATS_ENUM_MAX]; + std::atomic db_stats_[kIntStatsNumMax]; // Per-ColumnFamily stats uint64_t cf_stats_value_[INTERNAL_CF_STATS_ENUM_MAX]; uint64_t cf_stats_count_[INTERNAL_CF_STATS_ENUM_MAX]; @@ -615,15 +615,15 @@ class InternalStats { }; enum InternalDBStatsType { - WAL_FILE_BYTES, - WAL_FILE_SYNCED, - BYTES_WRITTEN, - NUMBER_KEYS_WRITTEN, - WRITE_DONE_BY_OTHER, - WRITE_DONE_BY_SELF, - WRITE_WITH_WAL, - WRITE_STALL_MICROS, - INTERNAL_DB_STATS_ENUM_MAX, + kIntStatsWalFileBytes, + kIntStatsWalFileSynced, + kIntStatsBytesWritten, + kIntStatsNumKeysWritten, + kIntStatsWriteDoneByOther, + kIntStatsWriteDoneBySelf, + kIntStatsWriteWithWal, + kIntStatsWriteStallMicros, + kIntStatsNumMax, }; InternalStats(int /*num_levels*/, Env* /*env*/, ColumnFamilyData* /*cfd*/) {}