diff --git a/util/delete_scheduler.cc b/util/delete_scheduler.cc index a8078b94a1374aab2de77f640994833339f60afb..f5ee2844896b81eebf88e2036f849c174e0d03a8 100644 --- a/util/delete_scheduler.cc +++ b/util/delete_scheduler.cc @@ -52,11 +52,12 @@ DeleteScheduler::~DeleteScheduler() { } Status DeleteScheduler::DeleteFile(const std::string& file_path, - const std::string& dir_to_sync) { + const std::string& dir_to_sync, + const bool force_bg) { Status s; - if (rate_bytes_per_sec_.load() <= 0 || + if (rate_bytes_per_sec_.load() <= 0 || (!force_bg && total_trash_size_.load() > - sst_file_manager_->GetTotalSize() * max_trash_db_ratio_.load()) { + sst_file_manager_->GetTotalSize() * max_trash_db_ratio_.load())) { // Rate limiting is disabled or trash size makes up more than // max_trash_db_ratio_ (default 25%) of the total DB size TEST_SYNC_POINT("DeleteScheduler::DeleteFile"); diff --git a/util/delete_scheduler.h b/util/delete_scheduler.h index cbd13ecefd02ea94f6b8b241879b7838bed67ae4..29b70517b6763a9c145370da184808db19195d95 100644 --- a/util/delete_scheduler.h +++ b/util/delete_scheduler.h @@ -46,8 +46,11 @@ class DeleteScheduler { rate_bytes_per_sec_.store(bytes_per_sec); } - // Mark file as trash directory and schedule it's deletion - Status DeleteFile(const std::string& fname, const std::string& dir_to_sync); + // Mark file as trash directory and schedule it's deletion. If force_bg is + // set, it forces the file to always be deleted in the background thread, + // except when rate limiting is disabled + Status DeleteFile(const std::string& fname, const std::string& dir_to_sync, + const bool force_bg = false); // Wait for all files being deleteing in the background to finish or for // destructor to be called. diff --git a/util/file_util.cc b/util/file_util.cc index bf56592efcf9f924b02e99521028f17041a83f7f..3f730f3e8407b6410f7fb42c51354258c595b266 100644 --- a/util/file_util.cc +++ b/util/file_util.cc @@ -89,16 +89,23 @@ Status CreateFile(Env* env, const std::string& destination, Status DeleteSSTFile(const ImmutableDBOptions* db_options, const std::string& fname, const std::string& dir_to_sync) { + return DeleteDBFile(db_options, fname, dir_to_sync, false); +} + +Status DeleteDBFile(const ImmutableDBOptions* db_options, + const std::string& fname, const std::string& dir_to_sync, + const bool force_bg) { #ifndef ROCKSDB_LITE auto sfm = static_cast(db_options->sst_file_manager.get()); if (sfm) { - return sfm->ScheduleFileDeletion(fname, dir_to_sync); + return sfm->ScheduleFileDeletion(fname, dir_to_sync, force_bg); } else { return db_options->env->DeleteFile(fname); } #else (void)dir_to_sync; + (void)force_bg; // SstFileManager is not supported in ROCKSDB_LITE return db_options->env->DeleteFile(fname); #endif diff --git a/util/file_util.h b/util/file_util.h index 5c05c9def6ec99b8b9796f9ccb20b411a85bb615..cd054518e17b651d0fd54481dc282c25d9e6e1ab 100644 --- a/util/file_util.h +++ b/util/file_util.h @@ -25,4 +25,9 @@ extern Status DeleteSSTFile(const ImmutableDBOptions* db_options, const std::string& fname, const std::string& path_to_sync); +extern Status DeleteDBFile(const ImmutableDBOptions* db_options, + const std::string& fname, + const std::string& path_to_sync, + const bool force_bg); + } // namespace rocksdb diff --git a/util/sst_file_manager_impl.cc b/util/sst_file_manager_impl.cc index 0b46b24b1ffc246f2a11961fed22c11f4f1aceb8..733cd9cf60951b3ff8a4b2130b9181cf00489da6 100644 --- a/util/sst_file_manager_impl.cc +++ b/util/sst_file_manager_impl.cc @@ -402,9 +402,11 @@ bool SstFileManagerImpl::CancelErrorRecovery(ErrorHandler* handler) { } Status SstFileManagerImpl::ScheduleFileDeletion( - const std::string& file_path, const std::string& path_to_sync) { + const std::string& file_path, const std::string& path_to_sync, + const bool force_bg) { TEST_SYNC_POINT("SstFileManagerImpl::ScheduleFileDeletion"); - return delete_scheduler_.DeleteFile(file_path, path_to_sync); + return delete_scheduler_.DeleteFile(file_path, path_to_sync, + force_bg); } void SstFileManagerImpl::WaitForEmptyTrash() { diff --git a/util/sst_file_manager_impl.h b/util/sst_file_manager_impl.h index d11035df80cb2c6ee21170eec33d616dfb777b88..211b4fa7160b25e421a3c71f0f95996e6bfbd3ff 100644 --- a/util/sst_file_manager_impl.h +++ b/util/sst_file_manager_impl.h @@ -111,9 +111,12 @@ class SstFileManagerImpl : public SstFileManager { // not guaranteed bool CancelErrorRecovery(ErrorHandler* db); - // Mark file as trash and schedule it's deletion. + // Mark file as trash and schedule it's deletion. If force_bg is set, it + // forces the file to be deleting in the background regardless of DB size, + // except when rate limited delete is disabled virtual Status ScheduleFileDeletion(const std::string& file_path, - const std::string& dir_to_sync); + const std::string& dir_to_sync, + const bool force_bg = false); // Wait for all files being deleteing in the background to finish or for // destructor to be called. diff --git a/utilities/blob_db/blob_db_impl.cc b/utilities/blob_db/blob_db_impl.cc index 19318760bedb0c19c384206ea4e5530ebe447c89..b69947d998f1cbc80cc5061775d18787092df17d 100644 --- a/utilities/blob_db/blob_db_impl.cc +++ b/utilities/blob_db/blob_db_impl.cc @@ -1743,8 +1743,8 @@ std::pair BlobDBImpl::DeleteObsoleteFiles(bool aborted) { bfile->PathName().c_str()); blob_files_.erase(bfile->BlobFileNumber()); - Status s = DeleteSSTFile(&(db_impl_->immutable_db_options()), - bfile->PathName(), blob_dir_); + Status s = DeleteDBFile(&(db_impl_->immutable_db_options()), + bfile->PathName(), blob_dir_, true); if (!s.ok()) { ROCKS_LOG_ERROR(db_options_.info_log, "File failed to be deleted as obsolete %s", @@ -1834,7 +1834,7 @@ Status DestroyBlobDB(const std::string& dbname, const Options& options, uint64_t number; FileType type; if (ParseFileName(f, &number, &type) && type == kBlobFile) { - Status del = DeleteSSTFile(&soptions, blobdir + "/" + f, blobdir); + Status del = DeleteDBFile(&soptions, blobdir + "/" + f, blobdir, true); if (status.ok() && !del.ok()) { status = del; }