From 40adb2bab79375924f1ee6421c236068eda24d12 Mon Sep 17 00:00:00 2001 From: Nick Brekhus Date: Fri, 13 Sep 2024 14:39:48 -0700 Subject: [PATCH] Fix wraparound in SstFileManager (#13010) Summary: Pull Request resolved: https://github.com/facebook/rocksdb/pull/13010 The OnAddFile cur_compactions_reserved_size_ accounting causes wraparound when re-opening a database with an unowned SstFileManager and during recovery. It was introduced in #4164 which addresses out of space recovery with an unclear purpose. Compaction jobs do this accounting via EnoughRoomForCompaction/OnCompactionCompletion and to my understanding would never reuse a sst file name. Reviewed By: anand1976 Differential Revision: D62535775 fbshipit-source-id: a7c44d6e0a4b5ff74bc47abfe57c32ca6770243d --- file/sst_file_manager_impl.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/file/sst_file_manager_impl.cc b/file/sst_file_manager_impl.cc index 68c74424a2..3f4f48e284 100644 --- a/file/sst_file_manager_impl.cc +++ b/file/sst_file_manager_impl.cc @@ -99,6 +99,7 @@ void SstFileManagerImpl::OnCompactionCompletion(Compaction* c) { size_added_by_compaction += filemeta->fd.GetFileSize(); } } + assert(cur_compactions_reserved_size_ >= size_added_by_compaction); cur_compactions_reserved_size_ -= size_added_by_compaction; } @@ -450,7 +451,6 @@ void SstFileManagerImpl::OnAddFileImpl(const std::string& file_path, // File was added before, we will just update the size total_files_size_ -= tracked_file->second; total_files_size_ += file_size; - cur_compactions_reserved_size_ -= file_size; } else { total_files_size_ += file_size; }