diff --git a/db/db_filesnapshot.cc b/db/db_filesnapshot.cc index 5286ca782..4185a40ca 100644 --- a/db/db_filesnapshot.cc +++ b/db/db_filesnapshot.cc @@ -66,6 +66,10 @@ Status DBImpl::EnableFileDeletions(bool force) { return Status::OK(); } +int DBImpl::IsFileDeletionsEnabled() const { + return disable_delete_obsolete_files_; +} + Status DBImpl::GetLiveFiles(std::vector& ret, uint64_t* manifest_file_size, bool flush_memtable) { diff --git a/db/db_impl.cc b/db/db_impl.cc index cd972bf6f..a123467ae 100644 --- a/db/db_impl.cc +++ b/db/db_impl.cc @@ -4468,7 +4468,7 @@ bool DBImpl::GetIntPropertyInternal(ColumnFamilyHandle* column_family, if (!need_out_of_mutex) { MutexLock l(&mutex_); - return cfd->internal_stats()->GetIntProperty(property_type, value); + return cfd->internal_stats()->GetIntProperty(property_type, value, this); } else { SuperVersion* sv = GetAndRefSuperVersion(cfd); diff --git a/db/db_impl.h b/db/db_impl.h index 5e0d8ffda..086ac9fd4 100644 --- a/db/db_impl.h +++ b/db/db_impl.h @@ -127,6 +127,7 @@ class DBImpl : public DB { #ifndef ROCKSDB_LITE virtual Status DisableFileDeletions(); virtual Status EnableFileDeletions(bool force); + virtual int IsFileDeletionsEnabled() const; // All the returned filenames start with "/" virtual Status GetLiveFiles(std::vector&, uint64_t* manifest_file_size, diff --git a/db/db_test.cc b/db/db_test.cc index 6a9bc116e..6dbbcb988 100644 --- a/db/db_test.cc +++ b/db/db_test.cc @@ -1149,6 +1149,31 @@ TEST(DBTest, Empty) { ASSERT_EQ("v1", Get(1, "foo")); env_->delay_sstable_sync_.Release_Store(nullptr); // Release sync calls + + ASSERT_OK(db_->DisableFileDeletions()); + ASSERT_TRUE( + dbfull()->GetProperty("rocksdb.is-file-deletions-enabled", &num)); + ASSERT_EQ("1", num); + + ASSERT_OK(db_->DisableFileDeletions()); + ASSERT_TRUE( + dbfull()->GetProperty("rocksdb.is-file-deletions-enabled", &num)); + ASSERT_EQ("2", num); + + ASSERT_OK(db_->DisableFileDeletions()); + ASSERT_TRUE( + dbfull()->GetProperty("rocksdb.is-file-deletions-enabled", &num)); + ASSERT_EQ("3", num); + + ASSERT_OK(db_->EnableFileDeletions(false)); + ASSERT_TRUE( + dbfull()->GetProperty("rocksdb.is-file-deletions-enabled", &num)); + ASSERT_EQ("2", num); + + ASSERT_OK(db_->EnableFileDeletions()); + ASSERT_TRUE( + dbfull()->GetProperty("rocksdb.is-file-deletions-enabled", &num)); + ASSERT_EQ("0", num); } while (ChangeOptions()); } diff --git a/db/internal_stats.cc b/db/internal_stats.cc index 839e3d61d..34eb99781 100644 --- a/db/internal_stats.cc +++ b/db/internal_stats.cc @@ -11,6 +11,7 @@ #include #include #include "db/column_family.h" +#include "db/db_impl.h" namespace rocksdb { @@ -133,6 +134,8 @@ DBPropertyType GetPropertyType(const Slice& property, bool* is_int_property, } else if (in == "estimate-table-readers-mem") { *need_out_of_mutex = true; return kEstimatedUsageByTableReaders; + } else if (in == "is-file-deletions-enabled") { + return kIsFileDeletionEnabled; } return kUnknown; } @@ -215,7 +218,7 @@ bool InternalStats::GetStringProperty(DBPropertyType property_type, } bool InternalStats::GetIntProperty(DBPropertyType property_type, - uint64_t* value) const { + uint64_t* value, DBImpl* db) const { Version* current = cfd_->current(); switch (property_type) { @@ -254,6 +257,9 @@ bool InternalStats::GetIntProperty(DBPropertyType property_type, cfd_->imm()->current()->GetTotalNumEntries() + current->GetEstimatedActiveKeys(); return true; + case kIsFileDeletionEnabled: + *value = db->IsFileDeletionsEnabled(); + return true; default: return false; } diff --git a/db/internal_stats.h b/db/internal_stats.h index 3c1bc2995..2e04f24e7 100644 --- a/db/internal_stats.h +++ b/db/internal_stats.h @@ -42,6 +42,8 @@ enum DBPropertyType : uint32_t { // the immutable mem tables. kEstimatedNumKeys, // Estimated total number of keys in the database. kEstimatedUsageByTableReaders, // Estimated memory by table readers. + kIsFileDeletionEnabled, // Equals disable_delete_obsolete_files_, + // 0 means file deletions enabled }; extern DBPropertyType GetPropertyType(const Slice& property, @@ -197,7 +199,8 @@ class InternalStats { bool GetStringProperty(DBPropertyType property_type, const Slice& property, std::string* value); - bool GetIntProperty(DBPropertyType property_type, uint64_t* value) const; + bool GetIntProperty(DBPropertyType property_type, uint64_t* value, + DBImpl* db) const; bool GetIntPropertyOutOfMutex(DBPropertyType property_type, Version* version, uint64_t* value) const;