From bc111ba32828e2352f37a6bd73e954e51e85258d Mon Sep 17 00:00:00 2001 From: xxy <3237539022@qq.com> Date: Thu, 5 Dec 2024 14:09:00 +0800 Subject: [PATCH] gc deadlock --- db/db_impl.cc | 30 +++++++++++++++++++----------- test/test.cpp | 5 +++-- 2 files changed, 22 insertions(+), 13 deletions(-) diff --git a/db/db_impl.cc b/db/db_impl.cc index cb52517..231e29c 100644 --- a/db/db_impl.cc +++ b/db/db_impl.cc @@ -1703,7 +1703,7 @@ Status DBImpl::ReadValueLog(uint64_t file_id, uint64_t offset, Slice* key, // Open the file in binary mode for reading std::ifstream inFile(file_name_, std::ios::in | std::ios::binary); if (!inFile.is_open()) { - std::cerr << "Failed to open file: " << file_name_ << " for reading!" + std::cerr << "Failed to open file: " << file_name_ << " for read valuelog!" << std::endl; return Status::Corruption("Failed to open file for reading!"); } @@ -1826,6 +1826,7 @@ void DBImpl::GarbageCollect() { fs::is_regular_file(fs::status(cur_log_file)) && IsValueLogFile(cur_log_file.path().filename().string())) { std::string valuelog_name = cur_log_file.path().string(); + std::cout << valuelog_name << std::endl; uint64_t cur_log_number = GetValueLogID(valuelog_name); std::cout << "check point 1" << std::endl; uint64_t new_log_number = versions_->NewFileNumber(); @@ -1851,6 +1852,8 @@ void DBImpl::GarbageCollect() { } uint64_t current_offset = 0; + uint64_t tmp_offset = 0; + int cnt=0; std::cout << "check point 3" << std::endl; @@ -1858,14 +1861,16 @@ void DBImpl::GarbageCollect() { // Open the file in binary mode for reading std::ifstream cur_valuelog(valuelog_name, std::ios::in | std::ios::binary); if (!cur_valuelog.is_open()) { - std::cerr << "Failed to open file: " << valuelog_name << " for reading!" + std::cerr << "Failed to open file: " << valuelog_name << " for reading cur_valuelog!" << std::endl; continue; } while (true) { + tmp_offset=current_offset; ++cnt; - std::cout << cnt << std::endl; + std::cout << cnt <<" "< values; - for(int i=0;i<500000;i++){ + for(int i=0;i<5000;i++){ std::string key=std::to_string(i); std::string value; for(int j=0;j<1000;j++){ @@ -212,7 +212,8 @@ TEST(Test, Garbage_Collect_TEST) { db->TEST_GarbageCollect(); std::cout<<"finish gc"<Get(readOptions,key,&value);