Add DB Property "rocksdb.current_version_number"

Summary: Add a DB Property "rocksdb.current_version_number" for users to monitor version changes and stale iterators.

Test Plan: Add a unit test.

Reviewers: andrewkr, yhchiang, kradhakrishnan, IslamAbdelRahman

Reviewed By: IslamAbdelRahman

Subscribers: leveldb, dhruba

Differential Revision: https://reviews.facebook.net/D54927
main
sdong 9 years ago
parent b5b1db167a
commit 432f3adf2c
  1. 12
      db/db_properties_test.cc
  2. 11
      db/internal_stats.cc
  3. 2
      db/internal_stats.h
  4. 4
      include/rocksdb/db.h

@ -90,6 +90,18 @@ TEST_F(DBPropertiesTest, Empty) {
} while (ChangeOptions());
}
TEST_F(DBPropertiesTest, CurrentVersionNumber) {
uint64_t v1, v2, v3;
ASSERT_TRUE(dbfull()->GetIntProperty("rocksdb.current_version_number", &v1));
Put("12345678", "");
ASSERT_TRUE(dbfull()->GetIntProperty("rocksdb.current_version_number", &v2));
Flush();
ASSERT_TRUE(dbfull()->GetIntProperty("rocksdb.current_version_number", &v3));
ASSERT_EQ(v1, v2);
ASSERT_GT(v3, v2);
}
TEST_F(DBPropertiesTest, GetAggregatedIntPropertyTest) {
const int kKeySize = 100;
const int kValueSize = 500;

@ -132,6 +132,7 @@ static const std::string is_file_deletions_enabled =
static const std::string num_snapshots = "num-snapshots";
static const std::string oldest_snapshot_time = "oldest-snapshot-time";
static const std::string num_live_versions = "num-live-versions";
static const std::string current_version_number = "current_version_number";
static const std::string estimate_live_data_size = "estimate-live-data-size";
static const std::string base_level = "base-level";
static const std::string total_sst_files_size = "total-sst-files-size";
@ -191,6 +192,8 @@ const std::string DB::Properties::kOldestSnapshotTime =
rocksdb_prefix + oldest_snapshot_time;
const std::string DB::Properties::kNumLiveVersions =
rocksdb_prefix + num_live_versions;
const std::string DB::Properties::kCurrentVersionNumber =
rocksdb_prefix + current_version_number;
const std::string DB::Properties::kEstimateLiveDataSize =
rocksdb_prefix + estimate_live_data_size;
const std::string DB::Properties::kTotalSstFilesSize =
@ -254,6 +257,8 @@ const std::unordered_map<std::string,
{false, nullptr, &InternalStats::HandleOldestSnapshotTime}},
{DB::Properties::kNumLiveVersions,
{false, nullptr, &InternalStats::HandleNumLiveVersions}},
{DB::Properties::kCurrentVersionNumber,
{false, nullptr, &InternalStats::HandleCurrentVersionNumber}},
{DB::Properties::kEstimateLiveDataSize,
{true, nullptr, &InternalStats::HandleEstimateLiveDataSize}},
{DB::Properties::kBaseLevel,
@ -519,6 +524,12 @@ bool InternalStats::HandleNumLiveVersions(uint64_t* value, DBImpl* db,
return true;
}
bool InternalStats::HandleCurrentVersionNumber(uint64_t* value, DBImpl* db,
Version* version) {
*value = cfd_->GetSuperVersionNumber();
return true;
}
bool InternalStats::HandleIsFileDeletionsEnabled(uint64_t* value, DBImpl* db,
Version* version) {
*value = db->IsFileDeletionsEnabled();

@ -328,6 +328,8 @@ class InternalStats {
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);
bool HandleCurrentVersionNumber(uint64_t* value, DBImpl* db,
Version* version);
bool HandleIsFileDeletionsEnabled(uint64_t* value, DBImpl* db,
Version* version);
bool HandleBaseLevel(uint64_t* value, DBImpl* db, Version* version);

@ -444,6 +444,9 @@ class DB {
// by iterators or unfinished compactions.
static const std::string kNumLiveVersions;
// "rocksdb.current-version-number" - returns number of curent LSM version.
static const std::string kCurrentVersionNumber;
// "rocksdb.estimate-live-data-size" - returns an estimate of the amount of
// live data in bytes.
static const std::string kEstimateLiveDataSize;
@ -504,6 +507,7 @@ class DB {
// "rocksdb.num-snapshots"
// "rocksdb.oldest-snapshot-time"
// "rocksdb.num-live-versions"
// "rocksdb.current_version_number"
// "rocksdb.estimate-live-data-size"
// "rocksdb.total-sst-files-size"
// "rocksdb.base-level"

Loading…
Cancel
Save