diff --git a/fdbserver/KeyValueStoreShardedRocksDB.actor.cpp b/fdbserver/KeyValueStoreShardedRocksDB.actor.cpp index c9a2163130..3fa08aca55 100644 --- a/fdbserver/KeyValueStoreShardedRocksDB.actor.cpp +++ b/fdbserver/KeyValueStoreShardedRocksDB.actor.cpp @@ -8,6 +8,7 @@ #include #include #include +#include #include #include #include @@ -571,6 +572,9 @@ public: ACTOR static Future shardMetricsLogger(std::shared_ptr rState, Future openFuture, ShardManager* shardManager) { + state std::unordered_map>* physicalShards = + shardManager->getAllShards(); + try { wait(openFuture); loop { @@ -581,6 +585,30 @@ public: TraceEvent(SevInfo, "ShardedRocksKVSPhysialShardMetrics") .detail("NumActiveShards", shardManager->numActiveShards()) .detail("TotalPhysicalShards", shardManager->numPhysicalShards()); + + for (auto& [id, shard] : *physicalShards) { + if (!shard->initialized()) { + continue; + } + std::string propValue = ""; + ASSERT(shard->db->GetProperty(shard->cf, rocksdb::DB::Properties::kCFStats, &propValue)); + TraceEvent(SevInfo, "PhysicalShardCFStats").detail("ShardId", id).detail("Detail", propValue); + + // Get compression ratio for each level. + rocksdb::ColumnFamilyMetaData cfMetadata; + shard->db->GetColumnFamilyMetaData(shard->cf, &cfMetadata); + TraceEvent e(SevInfo, "PhysicalShardLevelStats"); + e.detail("ShardId", id); + std::string levelProp; + for (auto it = cfMetadata.levels.begin(); it != cfMetadata.levels.end(); ++it) { + std::string propValue = ""; + ASSERT(shard->db->GetProperty(shard->cf, + rocksdb::DB::Properties::kCompressionRatioAtLevelPrefix + + std::to_string(it->level), + &propValue)); + e.detail("Level" + std::to_string(it->level), std::to_string(it->size) + " " + propValue); + } + } } } catch (Error& e) { if (e.code() != error_code_actor_cancelled) { @@ -1129,7 +1157,7 @@ private: std::shared_ptr stats; // Statistic Output from RocksDB std::vector> tickerStats; - std::vector> propertyStats; + std::vector> intPropertyStats; // Iterator Pool Stats std::unordered_map readIteratorPoolStats; // PerfContext @@ -1248,10 +1276,10 @@ RocksDBMetrics::RocksDBMetrics(UID debugID, std::shared_ptr { "RowCacheHit", rocksdb::ROW_CACHE_HIT, 0 }, { "RowCacheMiss", rocksdb::ROW_CACHE_MISS, 0 }, { "CountIterSkippedKeys", rocksdb::NUMBER_ITER_SKIP, 0 }, + }; - propertyStats = { - // Zhe: TODO Aggregation - { "NumCompactionsRunning", rocksdb::DB::Properties::kNumRunningCompactions }, + + intPropertyStats = { { "NumImmutableMemtables", rocksdb::DB::Properties::kNumImmutableMemTable }, { "NumImmutableMemtablesFlushed", rocksdb::DB::Properties::kNumImmutableMemTableFlushed }, { "IsMemtableFlushPending", rocksdb::DB::Properties::kMemTableFlushPending }, @@ -1260,27 +1288,25 @@ RocksDBMetrics::RocksDBMetrics(UID debugID, std::shared_ptr { "NumRunningCompactions", rocksdb::DB::Properties::kNumRunningCompactions }, { "CumulativeBackgroundErrors", rocksdb::DB::Properties::kBackgroundErrors }, { "CurrentSizeActiveMemtable", rocksdb::DB::Properties::kCurSizeActiveMemTable }, - { "AllMemtablesBytes", rocksdb::DB::Properties::kCurSizeAllMemTables }, // for mem usage + { "AllMemtablesBytes", rocksdb::DB::Properties::kCurSizeAllMemTables }, { "ActiveMemtableBytes", rocksdb::DB::Properties::kSizeAllMemTables }, { "CountEntriesActiveMemtable", rocksdb::DB::Properties::kNumEntriesActiveMemTable }, { "CountEntriesImmutMemtables", rocksdb::DB::Properties::kNumEntriesImmMemTables }, { "CountDeletesActiveMemtable", rocksdb::DB::Properties::kNumDeletesActiveMemTable }, { "CountDeletesImmutMemtables", rocksdb::DB::Properties::kNumDeletesImmMemTables }, { "EstimatedCountKeys", rocksdb::DB::Properties::kEstimateNumKeys }, - { "EstimateSstReaderBytes", rocksdb::DB::Properties::kEstimateTableReadersMem }, // for mem usage + { "EstimateSstReaderBytes", rocksdb::DB::Properties::kEstimateTableReadersMem }, { "CountActiveSnapshots", rocksdb::DB::Properties::kNumSnapshots }, { "OldestSnapshotTime", rocksdb::DB::Properties::kOldestSnapshotTime }, { "CountLiveVersions", rocksdb::DB::Properties::kNumLiveVersions }, { "EstimateLiveDataSize", rocksdb::DB::Properties::kEstimateLiveDataSize }, { "BaseLevel", rocksdb::DB::Properties::kBaseLevel }, { "EstPendCompactBytes", rocksdb::DB::Properties::kEstimatePendingCompactionBytes }, - { "BlockCacheUsage", rocksdb::DB::Properties::kBlockCacheUsage }, // for mem usage - { "BlockCachePinnedUsage", rocksdb::DB::Properties::kBlockCachePinnedUsage }, // for mem usage - }; - std::unordered_map readIteratorPoolStats = { - { "NumReadIteratorsCreated", 0 }, - { "NumTimesReadIteratorsReused", 0 }, + { "BlockCacheUsage", rocksdb::DB::Properties::kBlockCacheUsage }, + { "BlockCachePinnedUsage", rocksdb::DB::Properties::kBlockCachePinnedUsage }, + { "LiveSstFilesSize", rocksdb::DB::Properties::kLiveSstFilesSize }, }; + perfContextMetrics = { { "UserKeyComparisonCount", rocksdb_user_key_comparison_count, {} }, { "BlockCacheHitCount", rocksdb_block_cache_hit_count, {} }, @@ -1403,7 +1429,7 @@ void RocksDBMetrics::logStats(rocksdb::DB* db) { e.detail(name, stat - cumulation); cumulation = stat; } - for (auto& [name, property] : propertyStats) { + for (auto& [name, property] : intPropertyStats) { stat = 0; ASSERT(db->GetAggregatedIntProperty(property, &stat)); e.detail(name, stat);