From b9d51b86842b8432d740538c31fd8596f7765f0f Mon Sep 17 00:00:00 2001 From: Akanksha Mahajan Date: Fri, 26 Jun 2020 15:33:51 -0700 Subject: [PATCH] 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 --- file/delete_scheduler.cc | 4 +++- file/delete_scheduler.h | 3 ++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/file/delete_scheduler.cc b/file/delete_scheduler.cc index 5552d1140..337a3986b 100644 --- a/file/delete_scheduler.cc +++ b/file/delete_scheduler.cc @@ -71,6 +71,7 @@ Status DeleteScheduler::DeleteFile(const std::string& file_path, ", total_trash_size %" PRIu64 " max_trash_db_ratio %lf", file_path.c_str(), rate_bytes_per_sec_.load(), total_trash_size_.load(), max_trash_db_ratio_.load()); + InstrumentedMutexLock l(&mu_); RecordTick(stats_.get(), FILES_DELETED_IMMEDIATELY); } return s; @@ -90,12 +91,12 @@ Status DeleteScheduler::DeleteFile(const std::string& file_path, sst_file_manager_->OnDeleteFile(file_path); ROCKS_LOG_INFO(info_log_, "Deleted file %s immediately", trash_file.c_str()); + InstrumentedMutexLock l(&mu_); RecordTick(stats_.get(), FILES_DELETED_IMMEDIATELY); } return s; } - RecordTick(stats_.get(), FILES_MARKED_TRASH); // Update the total trash size uint64_t trash_file_size = 0; 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 { InstrumentedMutexLock l(&mu_); + RecordTick(stats_.get(), FILES_MARKED_TRASH); queue_.emplace(trash_file, dir_to_sync); pending_files_++; if (pending_files_ == 1) { diff --git a/file/delete_scheduler.h b/file/delete_scheduler.h index 59f46eeb7..b2d17a73e 100644 --- a/file/delete_scheduler.h +++ b/file/delete_scheduler.h @@ -84,6 +84,7 @@ class DeleteScheduler { const std::string& path); void SetStatisticsPtr(const std::shared_ptr& stats) { + InstrumentedMutexLock l(&mu_); stats_ = stats; } @@ -105,7 +106,7 @@ class DeleteScheduler { std::atomic total_trash_size_; // Maximum number of bytes that should be deleted per second std::atomic 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_; struct FileAndDir {