MCPcopy Create free account
hub / github.com/baidu/tera / GarbageCollect

Method GarbageCollect

src/tabletnode/tabletnode_impl.cc:937–989  ·  view source on GitHub ↗

* all cached tablets/files: * ------------------------------------------ * | active tablets | inactive tablets | * | | | * | | all | to | * | | inherited | *DELETE* | * | | files | | * ------------------------------------------ */

Source from the content-addressed store, hash-verified

935 * ------------------------------------------
936 */
937void TabletNodeImpl::GarbageCollect() {
938 int64_t start_ms = get_micros();
939 LOG(INFO) << "[gc] start...";
940
941 // get all inherited sst files
942 std::vector<InheritedLiveFiles> table_files;
943 GetInheritedLiveFiles(table_files);
944 std::set<std::string> inherited_files;
945 for (size_t t = 0; t < table_files.size(); ++t) {
946 const InheritedLiveFiles& live = table_files[t];
947 int lg_num = live.lg_live_files_size();
948 for (int lg = 0; lg < lg_num; ++lg) {
949 const LgInheritedLiveFiles& lg_live_files = live.lg_live_files(lg);
950 for (int f = 0; f < lg_live_files.file_number_size(); ++f) {
951 std::string file_path =
952 leveldb::BuildTableFilePath(live.table_name(), lg, lg_live_files.file_number(f));
953 inherited_files.insert(file_path);
954 // file_path : table-name/tablet-xxx/lg-num/xxx.sst
955 VLOG(GC_LOG_LEVEL) << "[gc] inherited live file: " << file_path;
956 }
957 }
958 }
959
960 // get all active tablets
961 std::vector<TabletMeta*> tablet_meta_list;
962 std::set<std::string> active_tablets;
963 tablet_manager_->GetAllTabletMeta(&tablet_meta_list);
964 std::vector<TabletMeta*>::iterator it = tablet_meta_list.begin();
965 for (; it != tablet_meta_list.end(); ++it) {
966 VLOG(GC_LOG_LEVEL) << "[gc] Active Tablet: " << (*it)->path();
967 active_tablets.insert((*it)->path());
968 delete (*it);
969 }
970
971 // collect persistent cache garbage
972 PersistentCacheGarbageCollect(inherited_files, active_tablets);
973
974 // collect flash directories
975 leveldb::FlashEnv* flash_env = (leveldb::FlashEnv*)io::LeveldbFlashEnv();
976 if (flash_env) {
977 const std::vector<std::string>& flash_paths = flash_env->GetFlashPaths();
978 for (size_t d = 0; d < flash_paths.size(); ++d) {
979 std::string flash_dir = flash_paths[d] + FLAGS_tera_tabletnode_path_prefix;
980 GarbageCollectInPath(flash_dir, leveldb::Env::Default(), inherited_files, active_tablets);
981 }
982 }
983
984 // collect memory env
985 leveldb::Env* mem_env = io::LeveldbMemEnv()->CacheEnv();
986 GarbageCollectInPath(FLAGS_tera_tabletnode_path_prefix, mem_env, inherited_files, active_tablets);
987
988 LOG(INFO) << "[gc] finished, time used: " << get_micros() - start_ms << " us.";
989}
990
991void TabletNodeImpl::GarbageCollectInPath(const std::string& path, leveldb::Env* env,
992 const std::set<std::string>& inherited_files,

Callers 2

RunMethod · 0.45

Calls 8

BuildTableFilePathFunction · 0.85
LeveldbFlashEnvFunction · 0.85
LeveldbMemEnvFunction · 0.85
insertMethod · 0.80
get_microsFunction · 0.50
sizeMethod · 0.45
GetAllTabletMetaMethod · 0.45
CacheEnvMethod · 0.45

Tested by

no test coverage detected