diff --git a/src/master/tablet_manager.cc b/src/master/tablet_manager.cc index d8049e26c..1c8839024 100644 --- a/src/master/tablet_manager.cc +++ b/src/master/tablet_manager.cc @@ -1175,9 +1175,14 @@ bool Table::TryCollectInheritedFile() { std::vector tablet_files; CollectInheritedFileFromFilesystem(name_, *it, &tablet_files); - for (uint32_t i = 0; i < tablet_files.size(); i++) { + if (tablet_files.empty()) { MutexLock l(&mutex_); - AddInheritedFile(tablet_files[i], false); + AddEmptyDeadTablet(*it); + } else { + for (uint32_t i = 0; i < tablet_files.size(); i++) { + MutexLock l(&mutex_); + AddInheritedFile(tablet_files[i], false); + } } } return dead_tablets.size() > 0; @@ -1300,6 +1305,17 @@ void Table::AddInheritedFile(const TabletFile& file, bool need_ref) { VLOG(10) << "[gc] [" << name_ << "] file " << file << " ref increment to " << file_info.ref; } +void Table::AddEmptyDeadTablet(uint64_t tablet_id) { + mutex_.AssertHeld(); + + if (useful_inh_files_.find(tablet_id) == useful_inh_files_.end()) { + LOG(INFO) << "[gc] [" << name_ << "] new empty dead tablet " + << tablet_id << ", gc disabled"; + gc_disabled_dead_tablets_.insert(tablet_id); + useful_inh_files_[tablet_id]; + } +} + uint64_t Table::CleanObsoleteFile() { leveldb::Env* env = io::LeveldbBaseEnv(); std::string table_path = FLAGS_tera_tabletnode_path_prefix + name_; diff --git a/src/master/tablet_manager.h b/src/master/tablet_manager.h index 1e58d62cf..b11d9461c 100644 --- a/src/master/tablet_manager.h +++ b/src/master/tablet_manager.h @@ -262,6 +262,7 @@ class Table { void EnableDeadTabletGarbageCollect(uint64_t tablet_id); void ReleaseInheritedFile(const TabletFile& file); void AddInheritedFile(const TabletFile& file, bool need_ref); + void AddEmptyDeadTablet(uint64_t tablet_id); uint64_t CleanObsoleteFile(); private: