]> git-server-git.apps.pok.os.sepia.ceph.com Git - rocksdb.git/commitdiff
Always delete Blob DB files in the background (#4928)
authoranand76 <anand76@devvm1373.frc2.facebook.com>
Tue, 29 Jan 2019 22:27:30 +0000 (14:27 -0800)
committerSagar Vemuri <svemuri@fb.com>
Thu, 31 Jan 2019 22:19:04 +0000 (14:19 -0800)
Summary:
Blob DB files are not tracked by the SFM, so they currently don't get
deleted in the background. Force them to be deleted in background so
rate limiting can be applied
Pull Request resolved: https://github.com/facebook/rocksdb/pull/4928

Differential Revision: D13854649

Pulled By: anand1976

fbshipit-source-id: 8031ce66842ff0af440c715d886b377983dad7d8

util/delete_scheduler.cc
util/delete_scheduler.h
util/file_util.cc
util/file_util.h
util/sst_file_manager_impl.cc
util/sst_file_manager_impl.h
utilities/blob_db/blob_db_impl.cc

index a8078b94a1374aab2de77f640994833339f60afb..f5ee2844896b81eebf88e2036f849c174e0d03a8 100644 (file)
@@ -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");
index cbd13ecefd02ea94f6b8b241879b7838bed67ae4..29b70517b6763a9c145370da184808db19195d95 100644 (file)
@@ -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.
index bf56592efcf9f924b02e99521028f17041a83f7f..3f730f3e8407b6410f7fb42c51354258c595b266 100644 (file)
@@ -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<SstFileManagerImpl*>(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
index 5c05c9def6ec99b8b9796f9ccb20b411a85bb615..cd054518e17b651d0fd54481dc282c25d9e6e1ab 100644 (file)
@@ -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
index 0b46b24b1ffc246f2a11961fed22c11f4f1aceb8..733cd9cf60951b3ff8a4b2130b9181cf00489da6 100644 (file)
@@ -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() {
index d11035df80cb2c6ee21170eec33d616dfb777b88..211b4fa7160b25e421a3c71f0f95996e6bfbd3ff 100644 (file)
@@ -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.
index a3a93365cd8dd389086b70bff0baff85ceb5ee24..bf46bf6b1c052820b981d72ede0c04bf7024731a 100644 (file)
@@ -1746,8 +1746,8 @@ std::pair<bool, int64_t> 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",
@@ -1837,7 +1837,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;
       }