Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion db/column_family.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<TableCache>& table_cache_shared_ptr() { return table_cache_; }

// See documentation in compaction_picker.h
// REQUIRES: DB mutex held
Expand Down Expand Up @@ -446,7 +447,7 @@ class ColumnFamilyData {

const bool is_delete_range_supported_;

std::unique_ptr<TableCache> table_cache_;
std::shared_ptr<TableCache> table_cache_;

std::unique_ptr<InternalStats> internal_stats_;

Expand Down
11 changes: 11 additions & 0 deletions db/db_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<TableCache> table_cache;
std::string cf;
~DeleteFileInfo(){
delete file_meta;
}
};

std::unordered_map<uint64_t, DeleteFileInfo> delete_info_map_;
};

extern Options SanitizeOptions(const std::string& db, const Options& src);
Expand Down
25 changes: 20 additions & 5 deletions db/db_impl_files.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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<TableCache> table_cache = fileinfo->table_cache;
std::shared_ptr<const TableProperties> 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);
}
}

Expand Down Expand Up @@ -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) {
Expand Down
5 changes: 4 additions & 1 deletion db/event_helpers.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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<std::shared_ptr<EventListener>>& listeners) {
const std::vector<std::shared_ptr<EventListener>>& listeners,
const std::string cf_name, const TableProperties& table_properties) {
JSONWriter jwriter;
AppendCurrentTime(&jwriter);

Expand All @@ -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);
}
Expand Down
3 changes: 2 additions & 1 deletion db/event_helpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<std::shared_ptr<EventListener>>& listeners);
const std::vector<std::shared_ptr<EventListener>>& listeners,
const std::string cf_name, const TableProperties& table_properties);
static void NotifyOnErrorRecoveryCompleted(
const std::vector<std::shared_ptr<EventListener>>& listeners,
Status bg_error, InstrumentedMutex* db_mutex);
Expand Down
3 changes: 2 additions & 1 deletion db/version_set.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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()));
}
}
}
Expand Down
9 changes: 7 additions & 2 deletions db/version_set.h
Original file line number Diff line number Diff line change
Expand Up @@ -848,10 +848,14 @@ class Version : public SeparateHelper, private LazyBufferState {
struct ObsoleteFileInfo {
FileMetaData* metadata;
std::string path;
std::string cf;
std::shared_ptr<TableCache> 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<TableCache>& _table_cache)
: metadata(f), path(file_path), cf(cf_name_), table_cache(_table_cache) {}

ObsoleteFileInfo(const ObsoleteFileInfo&) = delete;
ObsoleteFileInfo& operator=(const ObsoleteFileInfo&) = delete;
Expand All @@ -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;
}
Expand Down
2 changes: 2 additions & 0 deletions include/rocksdb/listener.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down