Skip to content

Commit

Permalink
Add is-file-deletions-enabled property
Browse files Browse the repository at this point in the history
Summary:
Add property 'rocksdb.is-file-deletions-enable'
	 which equals disable_delete_obsole_file_

Test Plan: make all check

Reviewers: sdong

Reviewed By: sdong

Subscribers: leveldb

Differential Revision: https://reviews.facebook.net/D22119
  • Loading branch information
StanislavGlebik committed Aug 26, 2014
1 parent 1755581 commit 9dcb75b
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 3 deletions.
4 changes: 4 additions & 0 deletions db/db_filesnapshot.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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<std::string>& ret,
uint64_t* manifest_file_size,
bool flush_memtable) {
Expand Down
2 changes: 1 addition & 1 deletion db/db_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
1 change: 1 addition & 0 deletions db/db_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<std::string>&,
uint64_t* manifest_file_size,
Expand Down
25 changes: 25 additions & 0 deletions db/db_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}

Expand Down
8 changes: 7 additions & 1 deletion db/internal_stats.cc
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include <inttypes.h>
#include <vector>
#include "db/column_family.h"
#include "db/db_impl.h"

namespace rocksdb {

Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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;
}
Expand Down
5 changes: 4 additions & 1 deletion db/internal_stats.h
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 9dcb75b

Please sign in to comment.