Add kOptionsStatistics to GetProperty() (#3966)

Summary:
Add a new DB property to DB::GetProperty(), which returns the option.statistics. Test is updated to pass.
Closes https://github.com/facebook/rocksdb/pull/3966

Differential Revision: D8311139

Pulled By: zhichao-cao

fbshipit-source-id: ea78f4727358c807b0e5a0ea62e09defb10ad9ac
main
zhichao-cao 7 years ago committed by Facebook Github Bot
parent 7b5f7ff0b4
commit 3fbc865cd5
  1. 17
      db/db_impl.cc
  2. 1
      db/db_impl.h
  3. 14
      db/db_properties_test.cc
  4. 114
      db/internal_stats.cc
  5. 5
      db/internal_stats.h
  6. 4
      include/rocksdb/db.h

@ -1845,6 +1845,13 @@ bool DBImpl::GetProperty(ColumnFamilyHandle* column_family,
InstrumentedMutexLock l(&mutex_); InstrumentedMutexLock l(&mutex_);
return cfd->internal_stats()->GetStringProperty(*property_info, property, return cfd->internal_stats()->GetStringProperty(*property_info, property,
value); value);
} else if (property_info->handle_string_dbimpl) {
std::string tmp_value;
bool ret_value = (this->*(property_info->handle_string_dbimpl))(&tmp_value);
if (ret_value) {
*value = tmp_value;
}
return ret_value;
} }
// Shouldn't reach here since exactly one of handle_string and handle_int // Shouldn't reach here since exactly one of handle_string and handle_int
// should be non-nullptr. // should be non-nullptr.
@ -1911,6 +1918,16 @@ bool DBImpl::GetIntPropertyInternal(ColumnFamilyData* cfd,
} }
} }
bool DBImpl::GetPropertyHandleOptionsStatistics(std::string* value) {
assert(value != nullptr);
Statistics* statistics = immutable_db_options_.statistics.get();
if (!statistics) {
return false;
}
*value = statistics->ToString();
return true;
}
#ifndef ROCKSDB_LITE #ifndef ROCKSDB_LITE
Status DBImpl::ResetStats() { Status DBImpl::ResetStats() {
InstrumentedMutexLock l(&mutex_); InstrumentedMutexLock l(&mutex_);

@ -1379,6 +1379,7 @@ class DBImpl : public DB {
bool GetIntPropertyInternal(ColumnFamilyData* cfd, bool GetIntPropertyInternal(ColumnFamilyData* cfd,
const DBPropertyInfo& property_info, const DBPropertyInfo& property_info,
bool is_locked, uint64_t* value); bool is_locked, uint64_t* value);
bool GetPropertyHandleOptionsStatistics(std::string* value);
bool HasPendingManualCompaction(); bool HasPendingManualCompaction();
bool HasExclusiveManualCompaction(); bool HasExclusiveManualCompaction();

@ -252,8 +252,11 @@ TEST_F(DBPropertiesTest, ValidatePropertyInfo) {
ASSERT_TRUE(ppt_name_and_info.first.empty() || ASSERT_TRUE(ppt_name_and_info.first.empty() ||
!isdigit(ppt_name_and_info.first.back())); !isdigit(ppt_name_and_info.first.back()));
ASSERT_TRUE((ppt_name_and_info.second.handle_string == nullptr) != int count = 0;
(ppt_name_and_info.second.handle_int == nullptr)); count += (ppt_name_and_info.second.handle_string == nullptr) ? 0 : 1;
count += (ppt_name_and_info.second.handle_int == nullptr) ? 0 : 1;
count += (ppt_name_and_info.second.handle_string_dbimpl == nullptr) ? 0 : 1;
ASSERT_TRUE(count == 1);
} }
} }
@ -372,6 +375,13 @@ TEST_F(DBPropertiesTest, ReadLatencyHistogramByLevel) {
for (int key = 0; key < key_index; key++) { for (int key = 0; key < key_index; key++) {
Get(Key(key)); Get(Key(key));
} }
// Test for getting immutable_db_options_.statistics
ASSERT_TRUE(dbfull()->GetProperty(dbfull()->DefaultColumnFamily(),
"rocksdb.options-statistics", &prop));
ASSERT_NE(std::string::npos, prop.find("rocksdb.block.cache.miss"));
ASSERT_EQ(std::string::npos, prop.find("rocksdb.db.f.micros"));
ASSERT_TRUE(dbfull()->GetProperty(dbfull()->DefaultColumnFamily(), ASSERT_TRUE(dbfull()->GetProperty(dbfull()->DefaultColumnFamily(),
"rocksdb.cf-file-histogram", &prop)); "rocksdb.cf-file-histogram", &prop));
ASSERT_NE(std::string::npos, prop.find("** Level 0 read latency histogram")); ASSERT_NE(std::string::npos, prop.find("** Level 0 read latency histogram"));

@ -249,6 +249,7 @@ static const std::string estimate_oldest_key_time = "estimate-oldest-key-time";
static const std::string block_cache_capacity = "block-cache-capacity"; static const std::string block_cache_capacity = "block-cache-capacity";
static const std::string block_cache_usage = "block-cache-usage"; static const std::string block_cache_usage = "block-cache-usage";
static const std::string block_cache_pinned_usage = "block-cache-pinned-usage"; static const std::string block_cache_pinned_usage = "block-cache-pinned-usage";
static const std::string options_statistics = "options-statistics";
const std::string DB::Properties::kNumFilesAtLevelPrefix = const std::string DB::Properties::kNumFilesAtLevelPrefix =
rocksdb_prefix + num_files_at_level_prefix; rocksdb_prefix + num_files_at_level_prefix;
@ -332,116 +333,141 @@ const std::string DB::Properties::kBlockCacheUsage =
rocksdb_prefix + block_cache_usage; rocksdb_prefix + block_cache_usage;
const std::string DB::Properties::kBlockCachePinnedUsage = const std::string DB::Properties::kBlockCachePinnedUsage =
rocksdb_prefix + block_cache_pinned_usage; rocksdb_prefix + block_cache_pinned_usage;
const std::string DB::Properties::kOptionsStatistics =
rocksdb_prefix + options_statistics;
const std::unordered_map<std::string, DBPropertyInfo> const std::unordered_map<std::string, DBPropertyInfo>
InternalStats::ppt_name_to_info = { InternalStats::ppt_name_to_info = {
{DB::Properties::kNumFilesAtLevelPrefix, {DB::Properties::kNumFilesAtLevelPrefix,
{false, &InternalStats::HandleNumFilesAtLevel, nullptr, nullptr}}, {false, &InternalStats::HandleNumFilesAtLevel, nullptr, nullptr,
nullptr}},
{DB::Properties::kCompressionRatioAtLevelPrefix, {DB::Properties::kCompressionRatioAtLevelPrefix,
{false, &InternalStats::HandleCompressionRatioAtLevelPrefix, nullptr, {false, &InternalStats::HandleCompressionRatioAtLevelPrefix, nullptr,
nullptr}}, nullptr, nullptr}},
{DB::Properties::kLevelStats, {DB::Properties::kLevelStats,
{false, &InternalStats::HandleLevelStats, nullptr, nullptr}}, {false, &InternalStats::HandleLevelStats, nullptr, nullptr, nullptr}},
{DB::Properties::kStats, {DB::Properties::kStats,
{false, &InternalStats::HandleStats, nullptr, nullptr}}, {false, &InternalStats::HandleStats, nullptr, nullptr, nullptr}},
{DB::Properties::kCFStats, {DB::Properties::kCFStats,
{false, &InternalStats::HandleCFStats, nullptr, {false, &InternalStats::HandleCFStats, nullptr,
&InternalStats::HandleCFMapStats}}, &InternalStats::HandleCFMapStats, nullptr}},
{DB::Properties::kCFStatsNoFileHistogram, {DB::Properties::kCFStatsNoFileHistogram,
{false, &InternalStats::HandleCFStatsNoFileHistogram, nullptr, {false, &InternalStats::HandleCFStatsNoFileHistogram, nullptr, nullptr,
nullptr}}, nullptr}},
{DB::Properties::kCFFileHistogram, {DB::Properties::kCFFileHistogram,
{false, &InternalStats::HandleCFFileHistogram, nullptr, nullptr}}, {false, &InternalStats::HandleCFFileHistogram, nullptr, nullptr,
nullptr}},
{DB::Properties::kDBStats, {DB::Properties::kDBStats,
{false, &InternalStats::HandleDBStats, nullptr, nullptr}}, {false, &InternalStats::HandleDBStats, nullptr, nullptr, nullptr}},
{DB::Properties::kSSTables, {DB::Properties::kSSTables,
{false, &InternalStats::HandleSsTables, nullptr, nullptr}}, {false, &InternalStats::HandleSsTables, nullptr, nullptr, nullptr}},
{DB::Properties::kAggregatedTableProperties, {DB::Properties::kAggregatedTableProperties,
{false, &InternalStats::HandleAggregatedTableProperties, nullptr, {false, &InternalStats::HandleAggregatedTableProperties, nullptr,
nullptr}}, nullptr, nullptr}},
{DB::Properties::kAggregatedTablePropertiesAtLevel, {DB::Properties::kAggregatedTablePropertiesAtLevel,
{false, &InternalStats::HandleAggregatedTablePropertiesAtLevel, {false, &InternalStats::HandleAggregatedTablePropertiesAtLevel,
nullptr, nullptr}}, nullptr, nullptr, nullptr}},
{DB::Properties::kNumImmutableMemTable, {DB::Properties::kNumImmutableMemTable,
{false, nullptr, &InternalStats::HandleNumImmutableMemTable, nullptr}}, {false, nullptr, &InternalStats::HandleNumImmutableMemTable, nullptr,
nullptr}},
{DB::Properties::kNumImmutableMemTableFlushed, {DB::Properties::kNumImmutableMemTableFlushed,
{false, nullptr, &InternalStats::HandleNumImmutableMemTableFlushed, {false, nullptr, &InternalStats::HandleNumImmutableMemTableFlushed,
nullptr}}, nullptr, nullptr}},
{DB::Properties::kMemTableFlushPending, {DB::Properties::kMemTableFlushPending,
{false, nullptr, &InternalStats::HandleMemTableFlushPending, nullptr}}, {false, nullptr, &InternalStats::HandleMemTableFlushPending, nullptr,
nullptr}},
{DB::Properties::kCompactionPending, {DB::Properties::kCompactionPending,
{false, nullptr, &InternalStats::HandleCompactionPending, nullptr}}, {false, nullptr, &InternalStats::HandleCompactionPending, nullptr,
nullptr}},
{DB::Properties::kBackgroundErrors, {DB::Properties::kBackgroundErrors,
{false, nullptr, &InternalStats::HandleBackgroundErrors, nullptr}}, {false, nullptr, &InternalStats::HandleBackgroundErrors, nullptr,
nullptr}},
{DB::Properties::kCurSizeActiveMemTable, {DB::Properties::kCurSizeActiveMemTable,
{false, nullptr, &InternalStats::HandleCurSizeActiveMemTable, {false, nullptr, &InternalStats::HandleCurSizeActiveMemTable, nullptr,
nullptr}}, nullptr}},
{DB::Properties::kCurSizeAllMemTables, {DB::Properties::kCurSizeAllMemTables,
{false, nullptr, &InternalStats::HandleCurSizeAllMemTables, nullptr}}, {false, nullptr, &InternalStats::HandleCurSizeAllMemTables, nullptr,
nullptr}},
{DB::Properties::kSizeAllMemTables, {DB::Properties::kSizeAllMemTables,
{false, nullptr, &InternalStats::HandleSizeAllMemTables, nullptr}}, {false, nullptr, &InternalStats::HandleSizeAllMemTables, nullptr,
nullptr}},
{DB::Properties::kNumEntriesActiveMemTable, {DB::Properties::kNumEntriesActiveMemTable,
{false, nullptr, &InternalStats::HandleNumEntriesActiveMemTable, {false, nullptr, &InternalStats::HandleNumEntriesActiveMemTable,
nullptr}}, nullptr, nullptr}},
{DB::Properties::kNumEntriesImmMemTables, {DB::Properties::kNumEntriesImmMemTables,
{false, nullptr, &InternalStats::HandleNumEntriesImmMemTables, {false, nullptr, &InternalStats::HandleNumEntriesImmMemTables, nullptr,
nullptr}}, nullptr}},
{DB::Properties::kNumDeletesActiveMemTable, {DB::Properties::kNumDeletesActiveMemTable,
{false, nullptr, &InternalStats::HandleNumDeletesActiveMemTable, {false, nullptr, &InternalStats::HandleNumDeletesActiveMemTable,
nullptr}}, nullptr, nullptr}},
{DB::Properties::kNumDeletesImmMemTables, {DB::Properties::kNumDeletesImmMemTables,
{false, nullptr, &InternalStats::HandleNumDeletesImmMemTables, {false, nullptr, &InternalStats::HandleNumDeletesImmMemTables, nullptr,
nullptr}}, nullptr}},
{DB::Properties::kEstimateNumKeys, {DB::Properties::kEstimateNumKeys,
{false, nullptr, &InternalStats::HandleEstimateNumKeys, nullptr}}, {false, nullptr, &InternalStats::HandleEstimateNumKeys, nullptr,
nullptr}},
{DB::Properties::kEstimateTableReadersMem, {DB::Properties::kEstimateTableReadersMem,
{true, nullptr, &InternalStats::HandleEstimateTableReadersMem, {true, nullptr, &InternalStats::HandleEstimateTableReadersMem, nullptr,
nullptr}}, nullptr}},
{DB::Properties::kIsFileDeletionsEnabled, {DB::Properties::kIsFileDeletionsEnabled,
{false, nullptr, &InternalStats::HandleIsFileDeletionsEnabled, {false, nullptr, &InternalStats::HandleIsFileDeletionsEnabled, nullptr,
nullptr}}, nullptr}},
{DB::Properties::kNumSnapshots, {DB::Properties::kNumSnapshots,
{false, nullptr, &InternalStats::HandleNumSnapshots, nullptr}}, {false, nullptr, &InternalStats::HandleNumSnapshots, nullptr,
nullptr}},
{DB::Properties::kOldestSnapshotTime, {DB::Properties::kOldestSnapshotTime,
{false, nullptr, &InternalStats::HandleOldestSnapshotTime, nullptr}}, {false, nullptr, &InternalStats::HandleOldestSnapshotTime, nullptr,
nullptr}},
{DB::Properties::kNumLiveVersions, {DB::Properties::kNumLiveVersions,
{false, nullptr, &InternalStats::HandleNumLiveVersions, nullptr}}, {false, nullptr, &InternalStats::HandleNumLiveVersions, nullptr,
nullptr}},
{DB::Properties::kCurrentSuperVersionNumber, {DB::Properties::kCurrentSuperVersionNumber,
{false, nullptr, &InternalStats::HandleCurrentSuperVersionNumber, {false, nullptr, &InternalStats::HandleCurrentSuperVersionNumber,
nullptr}}, nullptr, nullptr}},
{DB::Properties::kEstimateLiveDataSize, {DB::Properties::kEstimateLiveDataSize,
{true, nullptr, &InternalStats::HandleEstimateLiveDataSize, nullptr}}, {true, nullptr, &InternalStats::HandleEstimateLiveDataSize, nullptr,
nullptr}},
{DB::Properties::kMinLogNumberToKeep, {DB::Properties::kMinLogNumberToKeep,
{false, nullptr, &InternalStats::HandleMinLogNumberToKeep, nullptr}}, {false, nullptr, &InternalStats::HandleMinLogNumberToKeep, nullptr,
nullptr}},
{DB::Properties::kBaseLevel, {DB::Properties::kBaseLevel,
{false, nullptr, &InternalStats::HandleBaseLevel, nullptr}}, {false, nullptr, &InternalStats::HandleBaseLevel, nullptr, nullptr}},
{DB::Properties::kTotalSstFilesSize, {DB::Properties::kTotalSstFilesSize,
{false, nullptr, &InternalStats::HandleTotalSstFilesSize, nullptr}}, {false, nullptr, &InternalStats::HandleTotalSstFilesSize, nullptr,
nullptr}},
{DB::Properties::kLiveSstFilesSize, {DB::Properties::kLiveSstFilesSize,
{false, nullptr, &InternalStats::HandleLiveSstFilesSize, nullptr}}, {false, nullptr, &InternalStats::HandleLiveSstFilesSize, nullptr,
nullptr}},
{DB::Properties::kEstimatePendingCompactionBytes, {DB::Properties::kEstimatePendingCompactionBytes,
{false, nullptr, &InternalStats::HandleEstimatePendingCompactionBytes, {false, nullptr, &InternalStats::HandleEstimatePendingCompactionBytes,
nullptr}}, nullptr, nullptr}},
{DB::Properties::kNumRunningFlushes, {DB::Properties::kNumRunningFlushes,
{false, nullptr, &InternalStats::HandleNumRunningFlushes, nullptr}}, {false, nullptr, &InternalStats::HandleNumRunningFlushes, nullptr,
nullptr}},
{DB::Properties::kNumRunningCompactions, {DB::Properties::kNumRunningCompactions,
{false, nullptr, &InternalStats::HandleNumRunningCompactions, {false, nullptr, &InternalStats::HandleNumRunningCompactions, nullptr,
nullptr}}, nullptr}},
{DB::Properties::kActualDelayedWriteRate, {DB::Properties::kActualDelayedWriteRate,
{false, nullptr, &InternalStats::HandleActualDelayedWriteRate, {false, nullptr, &InternalStats::HandleActualDelayedWriteRate, nullptr,
nullptr}}, nullptr}},
{DB::Properties::kIsWriteStopped, {DB::Properties::kIsWriteStopped,
{false, nullptr, &InternalStats::HandleIsWriteStopped, nullptr}}, {false, nullptr, &InternalStats::HandleIsWriteStopped, nullptr,
nullptr}},
{DB::Properties::kEstimateOldestKeyTime, {DB::Properties::kEstimateOldestKeyTime,
{false, nullptr, &InternalStats::HandleEstimateOldestKeyTime, {false, nullptr, &InternalStats::HandleEstimateOldestKeyTime, nullptr,
nullptr}}, nullptr}},
{DB::Properties::kBlockCacheCapacity, {DB::Properties::kBlockCacheCapacity,
{false, nullptr, &InternalStats::HandleBlockCacheCapacity, nullptr}}, {false, nullptr, &InternalStats::HandleBlockCacheCapacity, nullptr,
nullptr}},
{DB::Properties::kBlockCacheUsage, {DB::Properties::kBlockCacheUsage,
{false, nullptr, &InternalStats::HandleBlockCacheUsage, nullptr}}, {false, nullptr, &InternalStats::HandleBlockCacheUsage, nullptr,
nullptr}},
{DB::Properties::kBlockCachePinnedUsage, {DB::Properties::kBlockCachePinnedUsage,
{false, nullptr, &InternalStats::HandleBlockCachePinnedUsage, {false, nullptr, &InternalStats::HandleBlockCachePinnedUsage, nullptr,
nullptr}}, nullptr}},
{DB::Properties::kOptionsStatistics,
{false, nullptr, nullptr, nullptr,
&DBImpl::GetPropertyHandleOptionsStatistics}},
}; };
const DBPropertyInfo* GetPropertyInfo(const Slice& property) { const DBPropertyInfo* GetPropertyInfo(const Slice& property) {

@ -45,6 +45,10 @@ struct DBPropertyInfo {
// @param props Map of general properties to populate // @param props Map of general properties to populate
bool (InternalStats::*handle_map)(std::map<std::string, std::string>* props); bool (InternalStats::*handle_map)(std::map<std::string, std::string>* props);
// 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);
}; };
extern const DBPropertyInfo* GetPropertyInfo(const Slice& property); extern const DBPropertyInfo* GetPropertyInfo(const Slice& property);
@ -538,7 +542,6 @@ class InternalStats {
bool HandleBlockCacheUsage(uint64_t* value, DBImpl* db, Version* version); bool HandleBlockCacheUsage(uint64_t* value, DBImpl* db, Version* version);
bool HandleBlockCachePinnedUsage(uint64_t* value, DBImpl* db, bool HandleBlockCachePinnedUsage(uint64_t* value, DBImpl* db,
Version* version); Version* version);
// Total number of background errors encountered. Every time a flush task // Total number of background errors encountered. Every time a flush task
// or compaction task fails, this counter is incremented. The failure can // or compaction task fails, this counter is incremented. The failure can
// be caused by any possible reason, including file system errors, out of // be caused by any possible reason, including file system errors, out of

@ -621,6 +621,10 @@ class DB {
// "rocksdb.block-cache-pinned-usage" - returns the memory size for the // "rocksdb.block-cache-pinned-usage" - returns the memory size for the
// entries being pinned. // entries being pinned.
static const std::string kBlockCachePinnedUsage; static const std::string kBlockCachePinnedUsage;
// "rocksdb.options-statistics" - returns multi-line string
// of options.statistics
static const std::string kOptionsStatistics;
}; };
#endif /* ROCKSDB_LITE */ #endif /* ROCKSDB_LITE */

Loading…
Cancel
Save