[bugfix](segment cache) Recycle the fds when drop table (#23081)

This commit is contained in:
Lightman
2023-08-18 13:31:34 +08:00
committed by GitHub
parent 2d96d19030
commit 4f7760a5f4
3 changed files with 14 additions and 2 deletions

View File

@ -175,6 +175,8 @@ Status BetaRowset::remove() {
VLOG_NOTICE << "begin to remove files in rowset " << unique_id()
<< ", version:" << start_version() << "-" << end_version()
<< ", tabletid:" << _rowset_meta->tablet_id();
// If the rowset was removed, it need to remove the fds in segment cache directly
SegmentLoader::instance()->erase_segments(SegmentCache::CacheKey(rowset_id()));
auto fs = _rowset_meta->fs();
if (!fs) {
return Status::Error<INIT_FAILED>("get fs failed");

View File

@ -665,8 +665,6 @@ void Tablet::_delete_stale_rowset_by_version(const Version& version) {
return;
}
_tablet_meta->delete_stale_rs_meta_by_version(version);
// If the stale rowset was deleted, it need to remove the fds directly
SegmentLoader::instance()->erase_segments(SegmentCache::CacheKey(rowset_meta->rowset_id()));
VLOG_NOTICE << "delete stale rowset. tablet=" << full_name() << ", version=" << version;
}

View File

@ -549,6 +549,18 @@ Status TabletManager::_drop_tablet_unlocked(TTabletId tablet_id, TReplicaId repl
_remove_tablet_from_partition(to_drop_tablet);
tablet_map_t& tablet_map = _get_tablet_map(tablet_id);
tablet_map.erase(tablet_id);
{
std::shared_lock rlock(to_drop_tablet->get_header_lock());
static auto recycle_segment_cache = [](const auto& rowset_map) {
for (auto& [_, rowset] : rowset_map) {
// If the tablet was deleted, it need to remove all rowsets fds directly
SegmentLoader::instance()->erase_segments(
SegmentCache::CacheKey(rowset->rowset_id()));
}
};
recycle_segment_cache(to_drop_tablet->rowset_map());
recycle_segment_cache(to_drop_tablet->stale_rowset_map());
}
if (!keep_files) {
// drop tablet will update tablet meta, should lock
std::lock_guard<std::shared_mutex> wrlock(to_drop_tablet->get_header_lock());