Fix for TSAN failure in DeleteScheduler (#7029)

Summary:
TSAN failure caused by setting statistics in SstFileManager and DeleteScheduler.
Pull Request resolved: https://github.com/facebook/rocksdb/pull/7029

Test Plan:
1. make check -j64
           2. COMPILE_WITH_TSAN=1 make check -j64

Reviewed By: siying, zhichao-cao

Differential Revision: D22223418

Pulled By: akankshamahajan15

fbshipit-source-id: c5bf336d711b787908dfeb6166cab4aa2e494d61
main
Akanksha Mahajan 4 years ago committed by Facebook GitHub Bot
parent 1569dc48f5
commit b9d51b8684
  1. 4
      file/delete_scheduler.cc
  2. 3
      file/delete_scheduler.h

@ -71,6 +71,7 @@ Status DeleteScheduler::DeleteFile(const std::string& file_path,
", total_trash_size %" PRIu64 " max_trash_db_ratio %lf", ", total_trash_size %" PRIu64 " max_trash_db_ratio %lf",
file_path.c_str(), rate_bytes_per_sec_.load(), file_path.c_str(), rate_bytes_per_sec_.load(),
total_trash_size_.load(), max_trash_db_ratio_.load()); total_trash_size_.load(), max_trash_db_ratio_.load());
InstrumentedMutexLock l(&mu_);
RecordTick(stats_.get(), FILES_DELETED_IMMEDIATELY); RecordTick(stats_.get(), FILES_DELETED_IMMEDIATELY);
} }
return s; return s;
@ -90,12 +91,12 @@ Status DeleteScheduler::DeleteFile(const std::string& file_path,
sst_file_manager_->OnDeleteFile(file_path); sst_file_manager_->OnDeleteFile(file_path);
ROCKS_LOG_INFO(info_log_, "Deleted file %s immediately", ROCKS_LOG_INFO(info_log_, "Deleted file %s immediately",
trash_file.c_str()); trash_file.c_str());
InstrumentedMutexLock l(&mu_);
RecordTick(stats_.get(), FILES_DELETED_IMMEDIATELY); RecordTick(stats_.get(), FILES_DELETED_IMMEDIATELY);
} }
return s; return s;
} }
RecordTick(stats_.get(), FILES_MARKED_TRASH);
// Update the total trash size // Update the total trash size
uint64_t trash_file_size = 0; uint64_t trash_file_size = 0;
fs_->GetFileSize(trash_file, IOOptions(), &trash_file_size, nullptr); fs_->GetFileSize(trash_file, IOOptions(), &trash_file_size, nullptr);
@ -104,6 +105,7 @@ Status DeleteScheduler::DeleteFile(const std::string& file_path,
// Add file to delete queue // Add file to delete queue
{ {
InstrumentedMutexLock l(&mu_); InstrumentedMutexLock l(&mu_);
RecordTick(stats_.get(), FILES_MARKED_TRASH);
queue_.emplace(trash_file, dir_to_sync); queue_.emplace(trash_file, dir_to_sync);
pending_files_++; pending_files_++;
if (pending_files_ == 1) { if (pending_files_ == 1) {

@ -84,6 +84,7 @@ class DeleteScheduler {
const std::string& path); const std::string& path);
void SetStatisticsPtr(const std::shared_ptr<Statistics>& stats) { void SetStatisticsPtr(const std::shared_ptr<Statistics>& stats) {
InstrumentedMutexLock l(&mu_);
stats_ = stats; stats_ = stats;
} }
@ -105,7 +106,7 @@ class DeleteScheduler {
std::atomic<uint64_t> total_trash_size_; std::atomic<uint64_t> total_trash_size_;
// Maximum number of bytes that should be deleted per second // Maximum number of bytes that should be deleted per second
std::atomic<int64_t> rate_bytes_per_sec_; std::atomic<int64_t> rate_bytes_per_sec_;
// Mutex to protect queue_, pending_files_, bg_errors_, closing_ // Mutex to protect queue_, pending_files_, bg_errors_, closing_, stats_
InstrumentedMutex mu_; InstrumentedMutex mu_;
struct FileAndDir { struct FileAndDir {

Loading…
Cancel
Save