add cfh deletion started listener
Summary: add ColumnFamilyHandleDeletionStarted listener which can be called when user deletes handler. Test Plan: ./listener_test Reviewers: yiwu, IslamAbdelRahman, sdong, andrewkr Reviewed By: andrewkr Subscribers: andrewkr, dhruba, leveldb Differential Revision: https://reviews.facebook.net/D60717
This commit is contained in:
parent
da5a9a65c1
commit
0a1bd9c509
@ -45,6 +45,11 @@ ColumnFamilyHandleImpl::ColumnFamilyHandleImpl(
|
||||
|
||||
ColumnFamilyHandleImpl::~ColumnFamilyHandleImpl() {
|
||||
if (cfd_ != nullptr) {
|
||||
#ifndef ROCKSDB_LITE
|
||||
for (auto& listener : cfd_->ioptions()->listeners) {
|
||||
listener->OnColumnFamilyHandleDeletionStarted(this);
|
||||
}
|
||||
#endif // ROCKSDB_LITE
|
||||
// Job id == 0 means that this is not our background process, but rather
|
||||
// user thread
|
||||
JobContext job_context(0);
|
||||
|
@ -754,8 +754,43 @@ TEST_F(EventListenerTest, MemTableSealedListenerTest) {
|
||||
ASSERT_OK(Flush());
|
||||
}
|
||||
}
|
||||
} // namespace rocksdb
|
||||
|
||||
class ColumnFamilyHandleDeletionStartedListener : public EventListener {
|
||||
private:
|
||||
std::vector<std::string> cfs_;
|
||||
int counter;
|
||||
|
||||
public:
|
||||
explicit ColumnFamilyHandleDeletionStartedListener(
|
||||
const std::vector<std::string>& cfs)
|
||||
: cfs_(cfs), counter(0) {
|
||||
cfs_.insert(cfs_.begin(), kDefaultColumnFamilyName);
|
||||
}
|
||||
void OnColumnFamilyHandleDeletionStarted(
|
||||
ColumnFamilyHandle* handle) override {
|
||||
ASSERT_EQ(cfs_[handle->GetID()], handle->GetName());
|
||||
counter++;
|
||||
}
|
||||
int getCounter() { return counter; }
|
||||
};
|
||||
|
||||
TEST_F(EventListenerTest, ColumnFamilyHandleDeletionStartedListenerTest) {
|
||||
std::vector<std::string> cfs{"pikachu", "eevee", "Mewtwo"};
|
||||
auto listener =
|
||||
std::make_shared<ColumnFamilyHandleDeletionStartedListener>(cfs);
|
||||
Options options;
|
||||
options.create_if_missing = true;
|
||||
options.listeners.push_back(listener);
|
||||
CreateAndReopenWithCF(cfs, options);
|
||||
ASSERT_EQ(handles_.size(), 4);
|
||||
delete handles_[3];
|
||||
delete handles_[2];
|
||||
delete handles_[1];
|
||||
handles_.resize(1);
|
||||
ASSERT_EQ(listener->getCounter(), 3);
|
||||
}
|
||||
|
||||
} // namespace rocksdb
|
||||
|
||||
#endif // ROCKSDB_LITE
|
||||
|
||||
|
@ -18,6 +18,7 @@ typedef std::unordered_map<std::string, std::shared_ptr<const TableProperties>>
|
||||
TablePropertiesCollection;
|
||||
|
||||
class DB;
|
||||
class ColumnFamilyHandle;
|
||||
class Status;
|
||||
struct CompactionJobStats;
|
||||
enum CompressionType : unsigned char;
|
||||
@ -265,7 +266,7 @@ class EventListener {
|
||||
// returned value.
|
||||
virtual void OnTableFileCreationStarted(
|
||||
const TableFileCreationBriefInfo& /*info*/) {}
|
||||
|
||||
|
||||
// A call-back function for RocksDB which will be called before
|
||||
// a memtable is made immutable.
|
||||
//
|
||||
@ -279,6 +280,17 @@ class EventListener {
|
||||
virtual void OnMemTableSealed(
|
||||
const MemTableInfo& /*info*/) {}
|
||||
|
||||
// A call-back function for RocksDB which will be called before
|
||||
// a column family handle is deleted.
|
||||
//
|
||||
// Note that the this function must be implemented in a way such that
|
||||
// it should not run for an extended period of time before the function
|
||||
// returns. Otherwise, RocksDB may be blocked.
|
||||
// @param handle is a pointer to the column family handle to be deleted
|
||||
// which will become a dangling pointer after the deletion.
|
||||
virtual void OnColumnFamilyHandleDeletionStarted(ColumnFamilyHandle* handle) {
|
||||
}
|
||||
|
||||
virtual ~EventListener() {}
|
||||
};
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user