github-actions[bot] commented on code in PR #16258: URL: https://github.com/apache/doris/pull/16258#discussion_r1090453470
########## be/src/olap/tablet.cpp: ########## @@ -1650,12 +1655,81 @@ Status Tablet::cooldown() { return Status::OK(); } +bool Tablet::get_cooldown_delete_id(TUniqueId* cooldown_delete_id) { + std::unique_lock delete_lock(_cooldown_delete_lock, std::try_to_lock); + if (!delete_lock.owns_lock()) { + LOG(WARNING) << "Failed to own delete_lock. tablet=" << tablet_id(); + return false; + } + if (!_cooldown_delete_flag && _cooldown_delete_files.size() > 0) { + *cooldown_delete_id = _cooldown_delete_id; + return true; + } + return false; +} + +void Tablet::enable_cooldown_flag(const TUniqueId& cooldown_delete_id) { + std::unique_lock delete_lock(_cooldown_delete_lock, std::try_to_lock); + if (!delete_lock.owns_lock()) { + LOG(WARNING) << "Failed to own delete_lock. tablet=" << tablet_id(); + return; + } + if (cooldown_delete_id == _cooldown_delete_id) { + _cooldown_delete_flag = true; + } +} + +Status Tablet::_cooldown_delete_files(io::FileSystemSPtr fs) { + std::unique_lock delete_lock(_cooldown_delete_lock, std::try_to_lock); + if (!delete_lock.owns_lock()) { + LOG(WARNING) << "Failed to own delete_lock. tablet=" << tablet_id(); + return Status::Error<TRY_LOCK_FAILED>(); + } + if (_cooldown_delete_flag) { + for (auto& file_path : _cooldown_delete_files) { + RETURN_IF_ERROR(fs->delete_file(file_path)); + } + _cooldown_delete_flag = false; + _cooldown_delete_files.clear(); + } else { + if (time(NULL) - _last_cooldown_delete_time < config::cooldown_delete_interval_time_sec) { Review Comment: warning: use nullptr [modernize-use-nullptr] ```suggestion ete_files.clear();nullptr ``` ########## be/src/olap/tablet.h: ########## @@ -463,6 +466,13 @@ class Tablet : public BaseTablet { DISALLOW_COPY_AND_ASSIGN(Tablet); + // Used for cooldown delete operation + std::mutex _cooldown_delete_lock; + TUniqueId _cooldown_delete_id; + bool _cooldown_delete_flag = false; + std::vector<Path> _cooldown_delete_files; Review Comment: warning: unknown type name 'Path'; did you mean 'io::Path'? [clang-diagnostic-error] ```suggestion std::vector<io::Path> _cooldown_delete_files; ``` **be/src/io/fs/path.h:24:** 'io::Path' declared here ```cpp using Path = std::filesystem::path; ^ ``` ########## be/src/olap/tablet.h: ########## @@ -463,6 +466,13 @@ DISALLOW_COPY_AND_ASSIGN(Tablet); + // Used for cooldown delete operation + std::mutex _cooldown_delete_lock; + TUniqueId _cooldown_delete_id; + bool _cooldown_delete_flag = false; + std::vector<Path> _cooldown_delete_files; Review Comment: warning: duplicate member '_cooldown_delete_files' [clang-diagnostic-error] ```cpp std::vector<Path> _cooldown_delete_files; ^ ``` **be/src/olap/tablet.h:385:** previous declaration is here ```cpp Status _cooldown_delete_files(io::FileSystemSPtr fs); ^ ``` ########## be/src/olap/tablet.cpp: ########## @@ -1650,12 +1655,81 @@ return Status::OK(); } +bool Tablet::get_cooldown_delete_id(TUniqueId* cooldown_delete_id) { + std::unique_lock delete_lock(_cooldown_delete_lock, std::try_to_lock); + if (!delete_lock.owns_lock()) { + LOG(WARNING) << "Failed to own delete_lock. tablet=" << tablet_id(); + return false; + } + if (!_cooldown_delete_flag && _cooldown_delete_files.size() > 0) { + *cooldown_delete_id = _cooldown_delete_id; + return true; + } + return false; +} + +void Tablet::enable_cooldown_flag(const TUniqueId& cooldown_delete_id) { + std::unique_lock delete_lock(_cooldown_delete_lock, std::try_to_lock); + if (!delete_lock.owns_lock()) { + LOG(WARNING) << "Failed to own delete_lock. tablet=" << tablet_id(); + return; + } + if (cooldown_delete_id == _cooldown_delete_id) { + _cooldown_delete_flag = true; + } +} + +Status Tablet::_cooldown_delete_files(io::FileSystemSPtr fs) { + std::unique_lock delete_lock(_cooldown_delete_lock, std::try_to_lock); + if (!delete_lock.owns_lock()) { + LOG(WARNING) << "Failed to own delete_lock. tablet=" << tablet_id(); + return Status::Error<TRY_LOCK_FAILED>(); + } + if (_cooldown_delete_flag) { + for (auto& file_path : _cooldown_delete_files) { + RETURN_IF_ERROR(fs->delete_file(file_path)); + } + _cooldown_delete_flag = false; + _cooldown_delete_files.clear(); + } else { + if (time(NULL) - _last_cooldown_delete_time < config::cooldown_delete_interval_time_sec) { + return Status::OK(); + } + _cooldown_delete_files.clear(); + _cooldown_delete_id = generate_uuid(); + Path remote_tablet_path = BetaRowset::remote_tablet_path(tablet_id()); + std::vector<Path> segment_files; + RETURN_IF_ERROR(fs->list(remote_tablet_path, &segment_files)); + TabletMetaPB remote_tablet_meta_pb; + RETURN_IF_ERROR(_read_remote_tablet_meta(fs, &remote_tablet_meta_pb)); + std::map<std::string, bool> remote_segment_path_map; + for (auto& rowset_meta_pb : remote_tablet_meta_pb.rs_metas()) { + for (int i = 0; i < rowset_meta_pb.num_segments(); ++i) { + std::string segment_path = BetaRowset::remote_segment_path( + tablet_id(), rowset_meta_pb.rowset_id_v2(), i); + remote_segment_path_map.emplace(segment_path, true); + } + } + for (auto& path : segment_files) { + if (remote_segment_path_map.find(path.native()) != remote_segment_path_map.end()) { + _cooldown_delete_files.emplace_back(path); + } + } + _last_cooldown_delete_time = time(NULL); + } + return Status::OK(); Review Comment: warning: use nullptr [modernize-use-nullptr] ```suggestion delete_time = time(nullptr); ``` -- 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