From a073cf35d6c511c51bdefbf87f16cb1e72a058db Mon Sep 17 00:00:00 2001 From: Xu Peng Date: Thu, 23 May 2019 20:35:59 +0800 Subject: [PATCH] feat(db): add archive files in meta part 2 Former-commit-id: 76ce47cc2f152d569251b084030c3b747a8f50ff --- cpp/src/db/DBMetaImpl.cpp | 49 ++++++++++++++++++--------------------- 1 file changed, 23 insertions(+), 26 deletions(-) diff --git a/cpp/src/db/DBMetaImpl.cpp b/cpp/src/db/DBMetaImpl.cpp index e506f14e..8341a7a9 100644 --- a/cpp/src/db/DBMetaImpl.cpp +++ b/cpp/src/db/DBMetaImpl.cpp @@ -508,43 +508,40 @@ Status DBMetaImpl::discard_files_of_size(long to_discard_size) { } try { auto selected = ConnectorPtr->select(columns(&GroupFileSchema::id, - &GroupFileSchema::file_type, &GroupFileSchema::rows), where(c(&GroupFileSchema::file_type) != (int)GroupFileSchema::TO_DELETE), order_by(&GroupFileSchema::id), limit(10)); + std::vector ids; + + for (auto& file : selected) { + if (to_discard_size <= 0) break; + GroupFileSchema group_file; + group_file.id = std::get<0>(file); + group_file.rows = std::get<1>(file); + ids.push_back(group_file.id); + to_discard_size -= group_file.rows; + } + + if (ids.size() == 0) { + return Status::OK(); + } + + ConnectorPtr->update_all( + set( + c(&GroupFileSchema::file_type) = (int)GroupFileSchema::TO_DELETE + ), + where( + in(&GroupFileSchema::id, ids) + )); - /* std::map groups; */ - - /* for (auto& file : selected) { */ - /* GroupFileSchema group_file; */ - /* group_file.id = std::get<0>(file); */ - /* group_file.group_id = std::get<1>(file); */ - /* group_file.file_id = std::get<2>(file); */ - /* group_file.file_type = std::get<3>(file); */ - /* group_file.rows = std::get<4>(file); */ - /* group_file.date = std::get<5>(file); */ - /* GetGroupFilePath(group_file); */ - /* auto groupItr = groups.find(group_file.group_id); */ - /* if (groupItr == groups.end()) { */ - /* GroupSchema group_info; */ - /* group_info.group_id = group_file.group_id; */ - /* auto status = get_group_no_lock(group_info); */ - /* if (!status.ok()) { */ - /* return status; */ - /* } */ - /* groups[group_file.group_id] = group_info; */ - /* } */ - /* group_file.dimension = groups[group_file.group_id].dimension; */ - /* files.push_back(group_file); */ - /* } */ } catch (std::exception & e) { LOG(DEBUG) << e.what(); throw e; } - return Status::OK(); + return discard_files_of_size(to_discard_size); } Status DBMetaImpl::update_group_file(GroupFileSchema& group_file) { -- GitLab