From 283c55720db4ee890db395ea33b7efd36126e5b6 Mon Sep 17 00:00:00 2001 From: plat1ko Date: Mon, 12 Jun 2023 21:05:09 +0800 Subject: [PATCH] [bug](cooldown) Fix the issue of unused remote files not being deleted (#19785) --- be/src/io/fs/s3_file_system.cpp | 4 +--- be/src/olap/tablet.cpp | 16 ++++++++-------- be/src/olap/tablet_manager.cpp | 2 +- 3 files changed, 10 insertions(+), 12 deletions(-) diff --git a/be/src/io/fs/s3_file_system.cpp b/be/src/io/fs/s3_file_system.cpp index 51cd474238..312799d140 100644 --- a/be/src/io/fs/s3_file_system.cpp +++ b/be/src/io/fs/s3_file_system.cpp @@ -320,13 +320,11 @@ Status S3FileSystem::list_impl(const Path& dir, bool only_file, std::vectorsecond.first; auto& files = it->second.second; + std::vector paths; + paths.reserve(files.size()); // delete unused files LOG(INFO) << "delete unused files. root_path=" << fs->root_path() << " tablet_id=" << id; - io::Path dir("data/" + std::to_string(id)); + io::Path dir = remote_tablet_path(id); for (auto& file : files) { - auto delete_path = dir / io::Path(file.file_name); - LOG(INFO) << "delete unused file: " << delete_path.native(); + auto file_path = dir / file.file_name; + LOG(INFO) << "delete unused file: " << file_path.native(); + paths.push_back(std::move(file_path)); } - std::vector file_names; - for (auto& info : files) { - file_names.emplace_back(info.file_name); - } - st = fs->batch_delete(file_names); + st = fs->batch_delete(paths); if (!st.ok()) { LOG(WARNING) << "failed to delete unused files, tablet_id=" << id << " : " << st; } + buffer.erase(it); } } }; diff --git a/be/src/olap/tablet_manager.cpp b/be/src/olap/tablet_manager.cpp index 085159b7ae..5d2bdee60d 100644 --- a/be/src/olap/tablet_manager.cpp +++ b/be/src/olap/tablet_manager.cpp @@ -856,7 +856,7 @@ Status TabletManager::load_tablet_from_dir(DataDir* store, TTabletId tablet_id, } TabletMetaSharedPtr tablet_meta(new TabletMeta()); - if (tablet_meta->create_from_file(header_path) != Status::OK()) { + if (!tablet_meta->create_from_file(header_path).ok()) { LOG(WARNING) << "fail to load tablet_meta. file_path=" << header_path; return Status::Error(); }