diff --git a/src/rgw/driver/sfs/sqlite/sqlite_multipart.cc b/src/rgw/driver/sfs/sqlite/sqlite_multipart.cc index c0341b45e3755..7c47f2a6fcb7c 100644 --- a/src/rgw/driver/sfs/sqlite/sqlite_multipart.cc +++ b/src/rgw/driver/sfs/sqlite/sqlite_multipart.cc @@ -344,59 +344,33 @@ bool SQLiteMultipart::abort(const std::string& upload_id) const { return committed; } -static int _mark_complete( - rgw::sal::sfs::sqlite::Storage& storage, const std::string& upload_id -) { - storage.update_all( - set(c(&DBMultipart::state) = MultipartState::COMPLETE, - c(&DBMultipart::state_change_time) = ceph::real_time::clock::now()), - where( - is_equal(&DBMultipart::upload_id, upload_id) and - greater_or_equal(&DBMultipart::state, MultipartState::INIT) and - lesser_or_equal(&DBMultipart::state, MultipartState::INPROGRESS) - ) - ); - return storage.changes(); -} - -bool SQLiteMultipart::mark_complete(const std::string& upload_id) const { - auto storage = conn->get_storage(); - auto committed = storage.transaction([&]() mutable { - auto num_complete = _mark_complete(storage, upload_id); - if (num_complete == 0) { - return false; - } - ceph_assert(num_complete == 1); - return true; - }); - - return committed; -} - bool SQLiteMultipart::mark_complete( const std::string& upload_id, bool* duplicate ) const { ceph_assert(duplicate != nullptr); auto storage = conn->get_storage(); auto committed = storage.transaction([&]() mutable { - auto entries = storage.get_all( - where(is_equal(&DBMultipart::upload_id, upload_id)) + storage.update_all( + set(c(&DBMultipart::state) = MultipartState::COMPLETE, + c(&DBMultipart::state_change_time) = ceph::real_time::clock::now()), + where( + is_equal(&DBMultipart::upload_id, upload_id) and + greater_or_equal(&DBMultipart::state, MultipartState::INIT) and + lesser_or_equal(&DBMultipart::state, MultipartState::INPROGRESS) + ) ); - ceph_assert(entries.size() <= 1); - if (entries.size() == 0) { - return false; - } - auto entry = entries.front(); - if (entry.state == MultipartState::DONE) { - *duplicate = true; - return true; - } - - auto num_complete = _mark_complete(storage, upload_id); - if (num_complete == 0) { - return false; + if (storage.changes() == 0) { + const auto state = storage.select( + columns(&DBMultipart::state), + where(is_equal(&DBMultipart::upload_id, upload_id)) + ); + if (state.size() == 0) { + return false; + } + *duplicate = (std::get<0>(state[0]) >= MultipartState::COMPLETE); + } else { + *duplicate = false; } - ceph_assert(num_complete == 1); return true; }); return committed; diff --git a/src/rgw/driver/sfs/sqlite/sqlite_multipart.h b/src/rgw/driver/sfs/sqlite/sqlite_multipart.h index f837cbfa62145..2e948a885890f 100644 --- a/src/rgw/driver/sfs/sqlite/sqlite_multipart.h +++ b/src/rgw/driver/sfs/sqlite/sqlite_multipart.h @@ -176,15 +176,6 @@ class SQLiteMultipart { */ bool abort(const std::string& upload_id) const; - /** - * @brief Mark an on-going Multipart Upload as being complete. - * - * @param upload_id The Multipart Upload's ID. - * @return true if a multipart upload was marked complete. - * @return false if no multipart upload was found. - */ - bool mark_complete(const std::string& upload_id) const; - /** * @brief Mark an on-going Multipart Upload as being complete. *