From a15354d04ec2c0c263a7cea948b7a5c0df4a2b26 Mon Sep 17 00:00:00 2001 From: Gustav Davidsson Date: Sat, 4 Aug 2018 17:50:01 -0700 Subject: [PATCH] Expose GetTotalTrashSize in SstFileManager interface (#4206) Summary: Hi, it would be great if we could expose this API, so that LogDevice can use it to track the total size of trash files and alarm if it grows too large in relation to disk size. There's probably other customers that would be interested in this as well. :) Pull Request resolved: https://github.com/facebook/rocksdb/pull/4206 Differential Revision: D9115516 Pulled By: gdavidsson fbshipit-source-id: f34993a940e39cb0a0b544ae8298546499b7e047 --- include/rocksdb/sst_file_manager.h | 4 ++++ util/sst_file_manager_impl.cc | 4 ++++ util/sst_file_manager_impl.h | 3 +++ 3 files changed, 11 insertions(+) diff --git a/include/rocksdb/sst_file_manager.h b/include/rocksdb/sst_file_manager.h index 2d3c3be66..1474da955 100644 --- a/include/rocksdb/sst_file_manager.h +++ b/include/rocksdb/sst_file_manager.h @@ -75,6 +75,10 @@ class SstFileManager { // Update trash/DB size ratio where new files will be deleted immediately // thread-safe virtual void SetMaxTrashDBRatio(double ratio) = 0; + + // Return the total size of trash files + // thread-safe + virtual uint64_t GetTotalTrashSize() = 0; }; // Create a new SstFileManager that can be shared among multiple RocksDB diff --git a/util/sst_file_manager_impl.cc b/util/sst_file_manager_impl.cc index ea955e3fa..74164e06a 100644 --- a/util/sst_file_manager_impl.cc +++ b/util/sst_file_manager_impl.cc @@ -162,6 +162,10 @@ void SstFileManagerImpl::SetMaxTrashDBRatio(double r) { return delete_scheduler_.SetMaxTrashDBRatio(r); } +uint64_t SstFileManagerImpl::GetTotalTrashSize() { + return delete_scheduler_.GetTotalTrashSize(); +} + Status SstFileManagerImpl::ScheduleFileDeletion( const std::string& file_path, const std::string& path_to_sync) { return delete_scheduler_.DeleteFile(file_path, path_to_sync); diff --git a/util/sst_file_manager_impl.h b/util/sst_file_manager_impl.h index 73b9cf8b7..90815d44f 100644 --- a/util/sst_file_manager_impl.h +++ b/util/sst_file_manager_impl.h @@ -93,6 +93,9 @@ class SstFileManagerImpl : public SstFileManager { // Update trash/DB size ratio where new files will be deleted immediately virtual void SetMaxTrashDBRatio(double ratio) override; + // Return the total size of trash files + uint64_t GetTotalTrashSize() override; + // Mark file as trash and schedule it's deletion. virtual Status ScheduleFileDeletion(const std::string& file_path, const std::string& dir_to_sync);