From a33f027662bd3582c290be3b28e30cab3d313a36 Mon Sep 17 00:00:00 2001 From: yangce Date: Tue, 28 Mar 2017 09:40:47 +0800 Subject: [PATCH 1/2] Remove orphan entry in namespace (#887) --- src/flags.cc | 1 + src/nameserver/namespace.cc | 13 +++++++++++++ 2 files changed, 14 insertions(+) diff --git a/src/flags.cc b/src/flags.cc index 77d8102b..ee7e511c 100644 --- a/src/flags.cc +++ b/src/flags.cc @@ -41,6 +41,7 @@ DEFINE_int32(blockmapping_bucket_num, 19, "Partation num of blockmapping"); DEFINE_int32(blockmapping_working_thread_num, 5, "Working thread num of blockmapping"); DEFINE_int32(block_id_allocation_size, 10000, "Block id allocatoin size"); DEFINE_bool(check_orphan, false, "Check orphan entry in RebuildBlockMap"); +DEFINE_bool(remove_orphan_entry, false, "Remove orphan entry in RebuildBlockMap"); // ha DEFINE_string(ha_strategy, "master_slave", "[master_slave, raft, none]"); diff --git a/src/nameserver/namespace.cc b/src/nameserver/namespace.cc index 76c3db04..915ba95c 100644 --- a/src/nameserver/namespace.cc +++ b/src/nameserver/namespace.cc @@ -25,6 +25,7 @@ DECLARE_int32(default_replica_num); DECLARE_int32(block_id_allocation_size); DECLARE_int32(snapshot_step); DECLARE_bool(check_orphan); +DECLARE_bool(remove_orphan_entry); const int64_t kRootEntryid = 1; @@ -726,6 +727,18 @@ bool NameSpace::RebuildBlockMap(std::function callback) } } LOG(INFO, "Check orphan done, %lu entries", orphan_entrys.size()); + if (FLAGS_remove_orphan_entry) { + for (std::vector >::iterator it = + orphan_entrys.begin(); it != orphan_entrys.end(); ++it) { + int64_t entry_id; + std::string name; + DecodingStoreKey((*it).first, &entry_id, &name); + FileInfo file_info; + file_info.ParseFromArray((*it).second.data(), (*it).second.size()); + db_->Delete(leveldb::WriteOptions(), (*it).first); + LOG(INFO, "Remove orphan entry E%ld", entry_id); + } + } } delete it; return true; From 85c9c3db1078f11c11f495d5ca1eaf714a273d0d Mon Sep 17 00:00:00 2001 From: yangce Date: Tue, 28 Mar 2017 09:55:09 +0800 Subject: [PATCH 2/2] Make code more clear (#887) --- src/nameserver/namespace.cc | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/src/nameserver/namespace.cc b/src/nameserver/namespace.cc index 915ba95c..d5ea3520 100644 --- a/src/nameserver/namespace.cc +++ b/src/nameserver/namespace.cc @@ -728,14 +728,13 @@ bool NameSpace::RebuildBlockMap(std::function callback) } LOG(INFO, "Check orphan done, %lu entries", orphan_entrys.size()); if (FLAGS_remove_orphan_entry) { - for (std::vector >::iterator it = - orphan_entrys.begin(); it != orphan_entrys.end(); ++it) { + for (auto& it : orphan_entrys) { int64_t entry_id; std::string name; - DecodingStoreKey((*it).first, &entry_id, &name); + DecodingStoreKey(it.first, &entry_id, &name); FileInfo file_info; - file_info.ParseFromArray((*it).second.data(), (*it).second.size()); - db_->Delete(leveldb::WriteOptions(), (*it).first); + file_info.ParseFromArray(it.second.data(), it.second.size()); + db_->Delete(leveldb::WriteOptions(), it.first); LOG(INFO, "Remove orphan entry E%ld", entry_id); } }