diff --git a/db/column_family.h b/db/column_family.h index 5330f578f1..becd63ec06 100644 --- a/db/column_family.h +++ b/db/column_family.h @@ -268,6 +268,7 @@ class ColumnFamilyData { bool needs_dup_key_check, SequenceNumber earliest_seq); TableCache* table_cache() const { return table_cache_.get(); } + std::shared_ptr& table_cache_shared_ptr() { return table_cache_; } // See documentation in compaction_picker.h // REQUIRES: DB mutex held @@ -446,7 +447,7 @@ class ColumnFamilyData { const bool is_delete_range_supported_; - std::unique_ptr table_cache_; + std::shared_ptr table_cache_; std::unique_ptr internal_stats_; diff --git a/db/db_impl.h b/db/db_impl.h index 66c51a6c3f..5b8937a0d0 100644 --- a/db/db_impl.h +++ b/db/db_impl.h @@ -1862,6 +1862,17 @@ class DBImpl : public DB { ThroughputReporter write_throughput_reporter_; DistributionReporter write_batch_size_reporter_; + + struct DeleteFileInfo{ + FileMetaData* file_meta; + std::shared_ptr table_cache; + std::string cf; + ~DeleteFileInfo(){ + delete file_meta; + } + }; + + std::unordered_map delete_info_map_; }; extern Options SanitizeOptions(const std::string& db, const Options& src); diff --git a/db/db_impl_files.cc b/db/db_impl_files.cc index 1e61fd5c90..8800cc9b70 100644 --- a/db/db_impl_files.cc +++ b/db/db_impl_files.cc @@ -334,9 +334,24 @@ void DBImpl::DeleteObsoleteFileImpl(int job_id, const std::string& fname, file_deletion_status.ToString().c_str()); } if (type == kTableFile) { + + auto iter = delete_info_map_.find(number); + assert(iter != delete_info_map_.end()); + DeleteFileInfo* fileinfo = &iter->second; + FileMetaData* f = fileinfo->file_meta; + std::shared_ptr table_cache = fileinfo->table_cache; + std::shared_ptr tp; + Status s = table_cache->GetTableProperties(env_options_,*f,&tp, nullptr); + + if (f->table_reader_handle) { + table_cache_->Release(f->table_reader_handle); + } + EventHelpers::LogAndNotifyTableFileDeletion( &event_logger_, job_id, number, fname, file_deletion_status, GetName(), - immutable_db_options_.listeners); + immutable_db_options_.listeners, fileinfo->cf, *tp); + + delete_info_map_.erase(number); } } @@ -373,13 +388,13 @@ void DBImpl::PurgeObsoleteFiles(JobContext& state, bool schedule_only) { // We may ignore the dbname when generating the file names. const char* kDumbDbName = ""; for (auto& file : state.sst_delete_files) { + delete_info_map_.emplace( + file.metadata->fd.GetNumber(), + DeleteFileInfo{file.metadata, file.table_cache, file.cf}); + candidate_files.emplace_back(JobContext::CandidateFileInfo{ MakeTableFileName(kDumbDbName, file.metadata->fd.GetNumber()), state.PushPath(file.path)}); - if (file.metadata->table_reader_handle) { - table_cache_->Release(file.metadata->table_reader_handle); - } - file.DeleteMetadata(); } for (auto file_num : state.log_delete_files) { diff --git a/db/event_helpers.cc b/db/event_helpers.cc index c66b1daa91..596b8e0f29 100644 --- a/db/event_helpers.cc +++ b/db/event_helpers.cc @@ -169,7 +169,8 @@ void EventHelpers::LogAndNotifyTableFileDeletion( EventLogger* event_logger, int job_id, uint64_t file_number, const std::string& file_path, const Status& status, const std::string& dbname, - const std::vector>& listeners) { + const std::vector>& listeners, + const std::string cf_name, const TableProperties& table_properties) { JSONWriter jwriter; AppendCurrentTime(&jwriter); @@ -190,6 +191,8 @@ void EventHelpers::LogAndNotifyTableFileDeletion( info.job_id = job_id; info.file_path = file_path; info.status = status; + info.cf_name = cf_name; + info.table_properties = table_properties; for (auto& listener : listeners) { listener->OnTableFileDeleted(info); } diff --git a/db/event_helpers.h b/db/event_helpers.h index 04f683fd88..feb35f5761 100644 --- a/db/event_helpers.h +++ b/db/event_helpers.h @@ -41,7 +41,8 @@ class EventHelpers { EventLogger* event_logger, int job_id, uint64_t file_number, const std::string& file_path, const Status& status, const std::string& db_name, - const std::vector>& listeners); + const std::vector>& listeners, + const std::string cf_name, const TableProperties& table_properties); static void NotifyOnErrorRecoveryCompleted( const std::vector>& listeners, Status bg_error, InstrumentedMutex* db_mutex); diff --git a/db/version_set.cc b/db/version_set.cc index 14c50572ed..eb60ec806b 100644 --- a/db/version_set.cc +++ b/db/version_set.cc @@ -400,7 +400,8 @@ Version::~Version() { uint32_t path_id = f->fd.GetPathId(); assert(path_id < cfd_->ioptions()->cf_paths.size()); vset_->obsolete_files_.push_back( - ObsoleteFileInfo(f, cfd_->ioptions()->cf_paths[path_id].path)); + ObsoleteFileInfo(f, cfd_->ioptions()->cf_paths[path_id].path, + cfd_->GetName(), cfd_->table_cache_shared_ptr())); } } } diff --git a/db/version_set.h b/db/version_set.h index badaaed9c3..cd350e0526 100644 --- a/db/version_set.h +++ b/db/version_set.h @@ -848,10 +848,14 @@ class Version : public SeparateHelper, private LazyBufferState { struct ObsoleteFileInfo { FileMetaData* metadata; std::string path; + std::string cf; + std::shared_ptr table_cache; ObsoleteFileInfo() noexcept : metadata(nullptr) {} - ObsoleteFileInfo(FileMetaData* f, const std::string& file_path) - : metadata(f), path(file_path) {} + ObsoleteFileInfo(FileMetaData* f, const std::string& file_path, + const std::string& cf_name_, + std::shared_ptr& _table_cache) + : metadata(f), path(file_path), cf(cf_name_), table_cache(_table_cache) {} ObsoleteFileInfo(const ObsoleteFileInfo&) = delete; ObsoleteFileInfo& operator=(const ObsoleteFileInfo&) = delete; @@ -864,6 +868,7 @@ struct ObsoleteFileInfo { path = std::move(rhs.path); metadata = rhs.metadata; rhs.metadata = nullptr; + table_cache = std::move(rhs.table_cache); return *this; } diff --git a/include/rocksdb/listener.h b/include/rocksdb/listener.h index 3bffff1c34..70c6bf0799 100644 --- a/include/rocksdb/listener.h +++ b/include/rocksdb/listener.h @@ -196,6 +196,8 @@ struct TableFileDeletionInfo { int job_id; // The status indicating whether the deletion was successful or not. Status status; + std::string cf_name; + TableProperties table_properties; }; struct FileOperationInfo {