eldenmoon commented on code in PR #27693: URL: https://github.com/apache/doris/pull/27693#discussion_r1408011267
########## be/src/olap/tablet_manager.cpp: ########## @@ -1040,119 +1028,155 @@ Status TabletManager::build_all_report_tablets_info(std::map<TTabletId, TTablet> } Status TabletManager::start_trash_sweep() { + std::unique_lock<std::mutex> lock(_gc_tablets_lock, std::defer_lock); + if (!lock.try_lock()) { + return Status::OK(); + } + SCOPED_CONSUME_MEM_TRACKER(_mem_tracker); + for_each_tablet([](const TabletSharedPtr& tablet) { tablet->delete_expired_stale_rowset(); }, + filter_all_tablets); + + std::list<TabletSharedPtr>::iterator last_it; { - for_each_tablet( - [](const TabletSharedPtr& tablet) { tablet->delete_expired_stale_rowset(); }, - filter_all_tablets); + std::shared_lock rdlock(_shutdown_tablets_lock); + last_it = _shutdown_tablets.begin(); + if (last_it == _shutdown_tablets.end()) { + return Status::OK(); + } } - int32_t clean_num = 0; - do { -#ifndef BE_TEST - sleep(1); -#endif - clean_num = 0; - // should get write lock here, because it will remove tablet from shut_down_tablets - // and get tablet will access shut_down_tablets - { - std::lock_guard<std::shared_mutex> wrlock1(_shutdown_tablets_lock); - std::lock_guard<std::shared_mutex> wrlock2(_shutdown_deleting_tablets_lock); - for (const auto& tablet : _shutdown_tablets) { - _shutdown_deleting_tablets.push_back(tablet); + auto get_batch_tablets = [this, &last_it](int limit) { + std::vector<TabletSharedPtr> batch_tablets; + std::lock_guard<std::shared_mutex> wrdlock(_shutdown_tablets_lock); + while (last_it != _shutdown_tablets.end() && batch_tablets.size() < limit) { + // it means current tablet is referenced by other thread + if (last_it->use_count() > 1) { Review Comment: what if tablet is referenced during `_move_tablet_to_trash`, will the query being correct? -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: commits-unsubscr...@doris.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@doris.apache.org For additional commands, e-mail: commits-h...@doris.apache.org