diff --git a/be/src/olap/tablet_manager.cpp b/be/src/olap/tablet_manager.cpp index a7982bdf471588..176dbfe6a34574 100755 --- a/be/src/olap/tablet_manager.cpp +++ b/be/src/olap/tablet_manager.cpp @@ -615,10 +615,6 @@ OLAPStatus TabletManager::drop_tablets_on_error_root_path( ++it; } } - - if (_tablet_map[tablet_id].table_arr.empty()) { - _tablet_map.erase(tablet_id); - } } } @@ -923,7 +919,18 @@ OLAPStatus TabletManager::report_all_tablets_info(std::map* OLAPStatus TabletManager::start_trash_sweep() { ReadLock rlock(&_tablet_map_lock); - for (const auto& item : _tablet_map) { + std::vector tablets_to_clean; + for (auto& item : _tablet_map) { + // try to clean empty item + if (item.second.table_arr.empty()) { + // try to get schema change lock if could get schema change lock, then nobody + // own the lock could remove the item + // it will core if schema change thread may hold the lock and this thread will deconstruct lock + if (item.second.schema_change_lock.trylock() == OLAP_SUCCESS) { + item.second.schema_change_lock.unlock(); + tablets_to_clean.push_back(item.first); + } + } for (TabletSharedPtr tablet : item.second.table_arr) { if (tablet == nullptr) { continue; @@ -931,6 +938,13 @@ OLAPStatus TabletManager::start_trash_sweep() { tablet->delete_expired_inc_rowsets(); } } + // clean empty tablet id item + for (const auto& tablet_id_to_clean : tablets_to_clean) { + if (_tablet_map[tablet_id_to_clean].table_arr.empty()) { + _tablet_map.erase(tablet_id_to_clean); + } + } + auto it = _shutdown_tablets.begin(); for (; it != _shutdown_tablets.end();) { // check if the meta has the tablet info and its state is shutdown @@ -1247,10 +1261,6 @@ OLAPStatus TabletManager::_drop_tablet_directly_unlocked( } } - if (_tablet_map[tablet_id].table_arr.empty()) { - _tablet_map.erase(tablet_id); - } - res = dropped_tablet->deregister_tablet_from_dir(); if (res != OLAP_SUCCESS) { LOG(WARNING) << "fail to unregister from root path. " diff --git a/fe/src/main/java/org/apache/doris/common/Config.java b/fe/src/main/java/org/apache/doris/common/Config.java index 8cf5fdd204ef94..ed56b31c8adbb3 100644 --- a/fe/src/main/java/org/apache/doris/common/Config.java +++ b/fe/src/main/java/org/apache/doris/common/Config.java @@ -436,8 +436,9 @@ public class Config extends ConfigBase { * After dropping database(table/partition), you can recover it by using RECOVER stmt. * And this specifies the maximal data retention time. After time, the data will be deleted permanently. */ + // TODO(ygl): temp modify it for test !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! @ConfField(mutable = true, masterOnly = true) - public static long catalog_trash_expire_second = 86400L; // 1day + public static long catalog_trash_expire_second = 10L; // 1day /* * Maximal bytes that a single broker scanner will read. * Do not set this if you know what you are doing.