From 946bf1784e98489a27c8a36ca51d03f8c1b85839 Mon Sep 17 00:00:00 2001 From: Tim Serong Date: Wed, 13 Sep 2023 17:19:05 +1000 Subject: [PATCH] [experimental] rgw/sfs: use only one sqlite database connection Currently there is one long lived connection to the sqlite database, but also many other threads use their own connections (for some analysis of this, see https://github.com/aquarist-labs/ceph/pull/201). This PR changes all the copies of the storage object to references, which means we're actually only using one db connection now. It's a bit irritating to do this, because it's way too easy to accidentally make a copy if you leave the '&' off :-/ I'd really want to somehow disable copy construction of the Storage object, but I didn't figure out how to do that yet. One interesting effect of this change is that, prior to this commit, the SFS status page only showed SQLite stats for the connection from the status thread, which is not overly helpful. With this commit (all threads using the same connection), the figures from the SQLite stats will actually change over time while s3gw is being used. Note that as we're building with -DSQLITE_THREADSAFE=1, i.e. we're using Serialized mode, it's totally cool to have one connection shared by multiple threads (see https://www.sqlite.org/threadsafe.html) Signed-off-by: Tim Serong --- src/rgw/driver/sfs/sqlite/dbconn.h | 2 +- src/rgw/driver/sfs/sqlite/sqlite_buckets.cc | 24 +++++------ src/rgw/driver/sfs/sqlite/sqlite_lifecycle.cc | 16 +++---- src/rgw/driver/sfs/sqlite/sqlite_list.cc | 4 +- src/rgw/driver/sfs/sqlite/sqlite_multipart.cc | 42 +++++++++---------- src/rgw/driver/sfs/sqlite/sqlite_objects.cc | 10 ++--- src/rgw/driver/sfs/sqlite/sqlite_users.cc | 18 ++++---- src/rgw/driver/sfs/sqlite/sqlite_users.h | 6 +-- .../sfs/sqlite/sqlite_versioned_objects.cc | 36 ++++++++-------- src/rgw/rgw_sal_sfs.cc | 2 +- 10 files changed, 80 insertions(+), 80 deletions(-) diff --git a/src/rgw/driver/sfs/sqlite/dbconn.h b/src/rgw/driver/sfs/sqlite/dbconn.h index ed7da5f8cd945..d2bec57b25c2e 100644 --- a/src/rgw/driver/sfs/sqlite/dbconn.h +++ b/src/rgw/driver/sfs/sqlite/dbconn.h @@ -270,7 +270,7 @@ class DBConn { DBConn(const DBConn&) = delete; DBConn& operator=(const DBConn&) = delete; - inline auto get_storage() const { return storage; } + inline auto& get_storage() { return storage; } static std::string getDBPath(CephContext* cct) { auto rgw_sfs_path = cct->_conf.get_val("rgw_sfs_data_path"); diff --git a/src/rgw/driver/sfs/sqlite/sqlite_buckets.cc b/src/rgw/driver/sfs/sqlite/sqlite_buckets.cc index 42877f50b288c..d2080c9b8aed7 100644 --- a/src/rgw/driver/sfs/sqlite/sqlite_buckets.cc +++ b/src/rgw/driver/sfs/sqlite/sqlite_buckets.cc @@ -40,7 +40,7 @@ std::vector get_rgw_buckets( std::optional SQLiteBuckets::get_bucket( const std::string& bucket_id ) const { - auto storage = conn->get_storage(); + auto& storage = conn->get_storage(); auto bucket = storage.get_pointer(bucket_id); std::optional ret_value; if (bucket) { @@ -52,7 +52,7 @@ std::optional SQLiteBuckets::get_bucket( std::optional> SQLiteBuckets::get_owner( const std::string& bucket_id ) const { - auto storage = conn->get_storage(); + auto& storage = conn->get_storage(); const auto rows = storage.select( columns(&DBUser::user_id, &DBUser::display_name), inner_join(on(is_equal(&DBBucket::owner_id, &DBUser::user_id))), @@ -68,60 +68,60 @@ std::optional> SQLiteBuckets::get_owner( std::vector SQLiteBuckets::get_bucket_by_name( const std::string& bucket_name ) const { - auto storage = conn->get_storage(); + auto& storage = conn->get_storage(); return get_rgw_buckets( storage.get_all(where(c(&DBBucket::bucket_name) = bucket_name)) ); } void SQLiteBuckets::store_bucket(const DBOPBucketInfo& bucket) const { - auto storage = conn->get_storage(); + auto& storage = conn->get_storage(); auto db_bucket = get_db_bucket(bucket); storage.replace(db_bucket); } void SQLiteBuckets::remove_bucket(const std::string& bucket_name) const { - auto storage = conn->get_storage(); + auto& storage = conn->get_storage(); storage.remove(bucket_name); } std::vector SQLiteBuckets::get_bucket_ids() const { - auto storage = conn->get_storage(); + auto& storage = conn->get_storage(); return storage.select(&DBBucket::bucket_name); } std::vector SQLiteBuckets::get_bucket_ids( const std::string& user_id ) const { - auto storage = conn->get_storage(); + auto& storage = conn->get_storage(); return storage.select( &DBBucket::bucket_name, where(c(&DBBucket::owner_id) = user_id) ); } std::vector SQLiteBuckets::get_buckets() const { - auto storage = conn->get_storage(); + auto& storage = conn->get_storage(); return get_rgw_buckets(storage.get_all()); } std::vector SQLiteBuckets::get_buckets( const std::string& user_id ) const { - auto storage = conn->get_storage(); + auto& storage = conn->get_storage(); return get_rgw_buckets( storage.get_all(where(c(&DBBucket::owner_id) = user_id)) ); } std::vector SQLiteBuckets::get_deleted_buckets_ids() const { - auto storage = conn->get_storage(); + auto& storage = conn->get_storage(); return storage.select( &DBBucket::bucket_id, where(c(&DBBucket::deleted) = true) ); } bool SQLiteBuckets::bucket_empty(const std::string& bucket_id) const { - auto storage = conn->get_storage(); + auto& storage = conn->get_storage(); auto num_ids = storage.count( inner_join( on(is_equal(&DBObject::uuid, &DBVersionedObject::object_id)) @@ -138,7 +138,7 @@ bool SQLiteBuckets::bucket_empty(const std::string& bucket_id) const { std::optional SQLiteBuckets::delete_bucket_transact( const std::string& bucket_id, uint max_objects, bool& bucket_deleted ) const { - auto storage = conn->get_storage(); + auto& storage = conn->get_storage(); RetrySQLite retry([&]() { bucket_deleted = false; DBDeletedObjectItems ret_values; diff --git a/src/rgw/driver/sfs/sqlite/sqlite_lifecycle.cc b/src/rgw/driver/sfs/sqlite/sqlite_lifecycle.cc index 1a7b7597367d7..4321083ae4615 100644 --- a/src/rgw/driver/sfs/sqlite/sqlite_lifecycle.cc +++ b/src/rgw/driver/sfs/sqlite/sqlite_lifecycle.cc @@ -19,7 +19,7 @@ namespace rgw::sal::sfs::sqlite { SQLiteLifecycle::SQLiteLifecycle(DBConnRef _conn) : conn(_conn) {} DBOPLCHead SQLiteLifecycle::get_head(const std::string& oid) const { - auto storage = conn->get_storage(); + auto& storage = conn->get_storage(); auto head = storage.get_pointer(oid); DBOPLCHead ret_value; if (head) { @@ -36,19 +36,19 @@ DBOPLCHead SQLiteLifecycle::get_head(const std::string& oid) const { } void SQLiteLifecycle::store_head(const DBOPLCHead& head) const { - auto storage = conn->get_storage(); + auto& storage = conn->get_storage(); storage.replace(head); } void SQLiteLifecycle::remove_head(const std::string& oid) const { - auto storage = conn->get_storage(); + auto& storage = conn->get_storage(); storage.remove(oid); } std::optional SQLiteLifecycle::get_entry( const std::string& oid, const std::string& marker ) const { - auto storage = conn->get_storage(); + auto& storage = conn->get_storage(); auto db_entry = storage.get_pointer(oid, marker); std::optional ret_value; if (db_entry) { @@ -60,7 +60,7 @@ std::optional SQLiteLifecycle::get_entry( std::optional SQLiteLifecycle::get_next_entry( const std::string& oid, const std::string& marker ) const { - auto storage = conn->get_storage(); + auto& storage = conn->get_storage(); auto db_entries = storage.get_all( where( is_equal(&DBOPLCEntry::lc_index, oid) and @@ -77,21 +77,21 @@ std::optional SQLiteLifecycle::get_next_entry( } void SQLiteLifecycle::store_entry(const DBOPLCEntry& entry) const { - auto storage = conn->get_storage(); + auto& storage = conn->get_storage(); storage.replace(entry); } void SQLiteLifecycle::remove_entry( const std::string& oid, const std::string& marker ) const { - auto storage = conn->get_storage(); + auto& storage = conn->get_storage(); storage.remove(oid, marker); } std::vector SQLiteLifecycle::list_entries( const std::string& oid, const std::string& marker, uint32_t max_entries ) const { - auto storage = conn->get_storage(); + auto& storage = conn->get_storage(); return storage.get_all( where( is_equal(&DBOPLCEntry::lc_index, oid) and diff --git a/src/rgw/driver/sfs/sqlite/sqlite_list.cc b/src/rgw/driver/sfs/sqlite/sqlite_list.cc index ca66b0cbabf73..0f9605ce76cff 100644 --- a/src/rgw/driver/sfs/sqlite/sqlite_list.cc +++ b/src/rgw/driver/sfs/sqlite/sqlite_list.cc @@ -39,7 +39,7 @@ bool SQLiteList::objects( // ListBucket does not care about versions/instances. don't populate // key.instance - auto storage = conn->get_storage(); + auto& storage = conn->get_storage(); auto rows = storage.select( columns( &DBObject::name, &DBVersionedObject::mtime, &DBVersionedObject::etag, @@ -103,7 +103,7 @@ bool SQLiteList::versions( ceph_assert(max < std::numeric_limits::max()); const size_t query_limit = max + 1; - auto storage = conn->get_storage(); + auto& storage = conn->get_storage(); auto rows = storage.select( columns( &DBObject::name, &DBVersionedObject::version_id, diff --git a/src/rgw/driver/sfs/sqlite/sqlite_multipart.cc b/src/rgw/driver/sfs/sqlite/sqlite_multipart.cc index 0d08993245063..a4f7038fcc280 100644 --- a/src/rgw/driver/sfs/sqlite/sqlite_multipart.cc +++ b/src/rgw/driver/sfs/sqlite/sqlite_multipart.cc @@ -35,7 +35,7 @@ std::optional> SQLiteMultipart::list_multiparts( const std::string& marker, const std::string& delim, const int& max_uploads, bool* is_truncated ) const { - auto storage = conn->get_storage(); + auto& storage = conn->get_storage(); auto bucket_entries = storage.get_all( where(is_equal(&DBBucket::bucket_name, bucket_name)) @@ -56,7 +56,7 @@ std::vector SQLiteMultipart::list_multiparts_by_bucket_id( const std::string& marker, const std::string& /*delim*/, const int& max_uploads, bool* is_truncated, bool get_all ) const { - auto storage = conn->get_storage(); + auto& storage = conn->get_storage(); auto start_state = get_all ? MultipartState::NONE : MultipartState::INIT; auto end_state = @@ -90,7 +90,7 @@ std::vector SQLiteMultipart::list_multiparts_by_bucket_id( int SQLiteMultipart::abort_multiparts_by_bucket_id(const std::string& bucket_id ) const { - auto storage = conn->get_storage(); + auto& storage = conn->get_storage(); uint64_t num_changes = 0; storage.transaction([&]() mutable { storage.update_all( @@ -110,7 +110,7 @@ int SQLiteMultipart::abort_multiparts_by_bucket_id(const std::string& bucket_id } int SQLiteMultipart::abort_multiparts(const std::string& bucket_name) const { - auto storage = conn->get_storage(); + auto& storage = conn->get_storage(); auto bucket_ids_vec = storage.select( &DBBucket::bucket_id, where(is_equal(&DBBucket::bucket_name, bucket_name)) ); @@ -129,7 +129,7 @@ std::optional SQLiteMultipart::get_multipart( return std::nullopt; } - auto storage = conn->get_storage(); + auto& storage = conn->get_storage(); auto entries = storage.get_all( where(is_equal(&DBMultipart::upload_id, upload_id)) ); @@ -143,7 +143,7 @@ std::optional SQLiteMultipart::get_multipart( std::optional SQLiteMultipart::get_multipart(int id) const { ceph_assert(id >= 0); - auto storage = conn->get_storage(); + auto& storage = conn->get_storage(); auto entries = storage.get_all(where(is_equal(&DBMultipart::id, id))); ceph_assert(entries.size() <= 1); // primary key @@ -155,7 +155,7 @@ std::optional SQLiteMultipart::get_multipart(int id) const { } uint SQLiteMultipart::insert(const DBMultipart& mp) const { - auto storage = conn->get_storage(); + auto& storage = conn->get_storage(); return storage.insert(mp); } @@ -163,7 +163,7 @@ std::vector SQLiteMultipart::list_parts( const std::string& upload_id, int num_parts, int marker, int* next_marker, bool* truncated ) const { - auto storage = conn->get_storage(); + auto& storage = conn->get_storage(); std::vector db_entries; db_entries = storage.get_all( where( @@ -194,7 +194,7 @@ std::vector SQLiteMultipart::list_parts( std::vector SQLiteMultipart::get_parts( const std::string& upload_id ) const { - auto storage = conn->get_storage(); + auto& storage = conn->get_storage(); auto db_entries = storage.get_all( where(is_equal(&DBMultipartPart::upload_id, upload_id)), order_by(&DBMultipartPart::part_num) @@ -205,7 +205,7 @@ std::vector SQLiteMultipart::get_parts( std::optional SQLiteMultipart::get_part( const std::string& upload_id, uint32_t part_num ) const { - auto storage = conn->get_storage(); + auto& storage = conn->get_storage(); auto entries = storage.get_all(where( is_equal(&DBMultipartPart::upload_id, upload_id) and is_equal(&DBMultipartPart::part_num, part_num) @@ -220,7 +220,7 @@ std::optional SQLiteMultipart::get_part( std::optional SQLiteMultipart::create_or_reset_part( const std::string& upload_id, uint32_t part_num, std::string* error_str ) const { - auto storage = conn->get_storage(); + auto& storage = conn->get_storage(); std::optional entry = std::nullopt; storage.transaction([&]() mutable { @@ -298,7 +298,7 @@ bool SQLiteMultipart::finish_part( const std::string& upload_id, uint32_t part_num, const std::string& etag, uint64_t bytes_written ) const { - auto storage = conn->get_storage(); + auto& storage = conn->get_storage(); bool committed = storage.transaction([&]() mutable { storage.update_all( set(c(&DBMultipartPart::etag) = etag, @@ -319,7 +319,7 @@ bool SQLiteMultipart::finish_part( } bool SQLiteMultipart::abort(const std::string& upload_id) const { - auto storage = conn->get_storage(); + auto& storage = conn->get_storage(); auto committed = storage.transaction([&]() mutable { storage.update_all( set(c(&DBMultipart::state) = MultipartState::ABORTED, @@ -357,7 +357,7 @@ static int _mark_complete( } bool SQLiteMultipart::mark_complete(const std::string& upload_id) const { - auto storage = conn->get_storage(); + auto& storage = conn->get_storage(); auto committed = storage.transaction([&]() mutable { auto num_complete = _mark_complete(storage, upload_id); if (num_complete == 0) { @@ -374,7 +374,7 @@ bool SQLiteMultipart::mark_complete( const std::string& upload_id, bool* duplicate ) const { ceph_assert(duplicate != nullptr); - auto storage = conn->get_storage(); + auto& storage = conn->get_storage(); auto committed = storage.transaction([&]() mutable { auto entries = storage.get_all( where(is_equal(&DBMultipart::upload_id, upload_id)) @@ -400,7 +400,7 @@ bool SQLiteMultipart::mark_complete( } bool SQLiteMultipart::mark_aggregating(const std::string& upload_id) const { - auto storage = conn->get_storage(); + auto& storage = conn->get_storage(); auto committed = storage.transaction([&]() mutable { storage.update_all( set(c(&DBMultipart::state) = MultipartState::AGGREGATING, @@ -422,7 +422,7 @@ bool SQLiteMultipart::mark_aggregating(const std::string& upload_id) const { } bool SQLiteMultipart::mark_done(const std::string& upload_id) const { - auto storage = conn->get_storage(); + auto& storage = conn->get_storage(); auto committed = storage.transaction([&]() mutable { storage.update_all( set(c(&DBMultipart::state) = MultipartState::DONE, @@ -443,7 +443,7 @@ bool SQLiteMultipart::mark_done(const std::string& upload_id) const { } void SQLiteMultipart::remove_parts(const std::string& upload_id) const { - auto storage = conn->get_storage(); + auto& storage = conn->get_storage(); storage.remove_all( where(c(&DBMultipartPart::upload_id) = upload_id) ); @@ -452,7 +452,7 @@ void SQLiteMultipart::remove_parts(const std::string& upload_id) const { void SQLiteMultipart::remove_multiparts_by_bucket_id( const std::string& bucket_id ) const { - auto storage = conn->get_storage(); + auto& storage = conn->get_storage(); storage.remove_all(where(c(&DBMultipart::bucket_id) = bucket_id) ); } @@ -462,7 +462,7 @@ SQLiteMultipart::remove_multiparts_by_bucket_id_transact( const std::string& bucket_id, uint max_items ) const { DBDeletedMultipartItems ret_parts; - auto storage = conn->get_storage(); + auto& storage = conn->get_storage(); RetrySQLite retry([&]() { auto transaction = storage.transaction_guard(); // get first the list of parts to be deleted up to max_items @@ -528,7 +528,7 @@ std::optional SQLiteMultipart::remove_done_or_aborted_multiparts_transact(uint max_items ) const { DBDeletedMultipartItems ret_parts; - auto storage = conn->get_storage(); + auto& storage = conn->get_storage(); RetrySQLite retry([&]() { auto transaction = storage.transaction_guard(); // get first the list of parts to be deleted up to max_items diff --git a/src/rgw/driver/sfs/sqlite/sqlite_objects.cc b/src/rgw/driver/sfs/sqlite/sqlite_objects.cc index 46e45524a5d32..18101ff8a6567 100644 --- a/src/rgw/driver/sfs/sqlite/sqlite_objects.cc +++ b/src/rgw/driver/sfs/sqlite/sqlite_objects.cc @@ -23,14 +23,14 @@ SQLiteObjects::SQLiteObjects(DBConnRef _conn) : conn(_conn) {} std::vector SQLiteObjects::get_objects(const std::string& bucket_id ) const { - auto storage = conn->get_storage(); + auto& storage = conn->get_storage(); return storage.get_all( where(is_equal(&DBObject::bucket_id, bucket_id)) ); } std::optional SQLiteObjects::get_object(const uuid_d& uuid) const { - auto storage = conn->get_storage(); + auto& storage = conn->get_storage(); auto object = storage.get_pointer(uuid.to_string()); std::optional ret_value; if (object) { @@ -42,7 +42,7 @@ std::optional SQLiteObjects::get_object(const uuid_d& uuid) const { std::optional SQLiteObjects::get_object( const std::string& bucket_id, const std::string& object_name ) const { - auto storage = conn->get_storage(); + auto& storage = conn->get_storage(); auto objects = storage.get_all(where( is_equal(&DBObject::bucket_id, bucket_id) and is_equal(&DBObject::name, object_name) @@ -57,12 +57,12 @@ std::optional SQLiteObjects::get_object( } void SQLiteObjects::store_object(const DBObject& object) const { - auto storage = conn->get_storage(); + auto& storage = conn->get_storage(); storage.replace(object); } void SQLiteObjects::remove_object(const uuid_d& uuid) const { - auto storage = conn->get_storage(); + auto& storage = conn->get_storage(); storage.remove(uuid); } diff --git a/src/rgw/driver/sfs/sqlite/sqlite_users.cc b/src/rgw/driver/sfs/sqlite/sqlite_users.cc index bbc49647d8a78..6574035ff8ab4 100644 --- a/src/rgw/driver/sfs/sqlite/sqlite_users.cc +++ b/src/rgw/driver/sfs/sqlite/sqlite_users.cc @@ -26,7 +26,7 @@ SQLiteUsers::SQLiteUsers(DBConnRef _conn) : conn(_conn) {} std::optional SQLiteUsers::get_user(const std::string& userid ) const { - auto storage = conn->get_storage(); + auto& storage = conn->get_storage(); auto user = storage.get_pointer(userid); std::optional ret_value; if (user) { @@ -49,7 +49,7 @@ std::optional SQLiteUsers::get_user_by_email( std::optional SQLiteUsers::get_user_by_access_key( const std::string& key ) const { - auto storage = conn->get_storage(); + auto& storage = conn->get_storage(); auto user_id = _get_user_id_by_access_key(storage, key); std::optional ret_value; if (user_id.has_value()) { @@ -62,19 +62,19 @@ std::optional SQLiteUsers::get_user_by_access_key( } std::vector SQLiteUsers::get_user_ids() const { - auto storage = conn->get_storage(); + auto& storage = conn->get_storage(); return storage.select(&DBUser::user_id); } void SQLiteUsers::store_user(const DBOPUserInfo& user) const { - auto storage = conn->get_storage(); + auto& storage = conn->get_storage(); auto db_user = get_db_user(user); storage.replace(db_user); _store_access_keys(storage, user); } void SQLiteUsers::remove_user(const std::string& userid) const { - auto storage = conn->get_storage(); + auto& storage = conn->get_storage(); _remove_access_keys(storage, userid); storage.remove(userid); } @@ -82,7 +82,7 @@ void SQLiteUsers::remove_user(const std::string& userid) const { template std::vector SQLiteUsers::get_users_by(Args... args) const { std::vector users_return; - auto storage = conn->get_storage(); + auto& storage = conn->get_storage(); auto users = storage.get_all(args...); for (auto& user : users) { users_return.push_back(get_rgw_user(user)); @@ -91,7 +91,7 @@ std::vector SQLiteUsers::get_users_by(Args... args) const { } void SQLiteUsers::_store_access_keys( - rgw::sal::sfs::sqlite::Storage storage, const DBOPUserInfo& user + rgw::sal::sfs::sqlite::Storage& storage, const DBOPUserInfo& user ) const { // remove existing keys for the user (in case any of them had changed) _remove_access_keys(storage, user.uinfo.user_id.id); @@ -104,13 +104,13 @@ void SQLiteUsers::_store_access_keys( } void SQLiteUsers::_remove_access_keys( - rgw::sal::sfs::sqlite::Storage storage, const std::string& userid + rgw::sal::sfs::sqlite::Storage& storage, const std::string& userid ) const { storage.remove_all(where(c(&DBAccessKey::user_id) = userid)); } std::optional SQLiteUsers::_get_user_id_by_access_key( - rgw::sal::sfs::sqlite::Storage storage, const std::string& key + rgw::sal::sfs::sqlite::Storage& storage, const std::string& key ) const { auto keys = storage.get_all(where(c(&DBAccessKey::access_key) = key)); diff --git a/src/rgw/driver/sfs/sqlite/sqlite_users.h b/src/rgw/driver/sfs/sqlite/sqlite_users.h index 5d2ac7aa14d44..6789146c95df8 100644 --- a/src/rgw/driver/sfs/sqlite/sqlite_users.h +++ b/src/rgw/driver/sfs/sqlite/sqlite_users.h @@ -41,13 +41,13 @@ class SQLiteUsers { std::vector get_users_by(Args... args) const; void _store_access_keys( - rgw::sal::sfs::sqlite::Storage storage, const DBOPUserInfo& user + rgw::sal::sfs::sqlite::Storage& storage, const DBOPUserInfo& user ) const; void _remove_access_keys( - rgw::sal::sfs::sqlite::Storage storage, const std::string& userid + rgw::sal::sfs::sqlite::Storage& storage, const std::string& userid ) const; std::optional _get_user_id_by_access_key( - rgw::sal::sfs::sqlite::Storage storage, const std::string& key + rgw::sal::sfs::sqlite::Storage& storage, const std::string& key ) const; }; diff --git a/src/rgw/driver/sfs/sqlite/sqlite_versioned_objects.cc b/src/rgw/driver/sfs/sqlite/sqlite_versioned_objects.cc index 626035b2e3bff..95dc8885be389 100644 --- a/src/rgw/driver/sfs/sqlite/sqlite_versioned_objects.cc +++ b/src/rgw/driver/sfs/sqlite/sqlite_versioned_objects.cc @@ -34,7 +34,7 @@ SQLiteVersionedObjects::SQLiteVersionedObjects(DBConnRef _conn) : conn(_conn) {} std::optional SQLiteVersionedObjects::get_versioned_object( uint id, bool filter_deleted ) const { - auto storage = conn->get_storage(); + auto& storage = conn->get_storage(); auto object = storage.get_pointer(id); std::optional ret_value; if (object) { @@ -48,7 +48,7 @@ std::optional SQLiteVersionedObjects::get_versioned_object( std::optional SQLiteVersionedObjects::get_versioned_object( const std::string& version_id, bool filter_deleted ) const { - auto storage = conn->get_storage(); + auto& storage = conn->get_storage(); auto versioned_objects = storage.get_all( where(c(&DBVersionedObject::version_id) = version_id) ); @@ -79,7 +79,7 @@ SQLiteVersionedObjects::get_committed_versioned_object( DBObjectsListItems SQLiteVersionedObjects::list_last_versioned_objects( const std::string& bucket_id ) const { - auto storage = conn->get_storage(); + auto& storage = conn->get_storage(); auto results = storage.select( columns( &DBObject::uuid, &DBObject::name, &DBVersionedObject::version_id, @@ -104,21 +104,21 @@ DBObjectsListItems SQLiteVersionedObjects::list_last_versioned_objects( uint SQLiteVersionedObjects::insert_versioned_object( const DBVersionedObject& object ) const { - auto storage = conn->get_storage(); + auto& storage = conn->get_storage(); return storage.insert(object); } void SQLiteVersionedObjects::store_versioned_object( const DBVersionedObject& object ) const { - auto storage = conn->get_storage(); + auto& storage = conn->get_storage(); storage.update(object); } bool SQLiteVersionedObjects::store_versioned_object_if_state( const DBVersionedObject& object, std::vector allowed_states ) const { - auto storage = conn->get_storage(); + auto& storage = conn->get_storage(); auto transaction = storage.transaction_guard(); transaction.commit_on_destroy = true; storage.update_all( @@ -146,7 +146,7 @@ bool SQLiteVersionedObjects:: store_versioned_object_delete_committed_transact_if_state( const DBVersionedObject& object, std::vector allowed_states ) const { - auto storage = conn->get_storage(); + auto& storage = conn->get_storage(); RetrySQLite retry([&]() { auto transaction = storage.transaction_guard(); storage.update_all( @@ -192,14 +192,14 @@ bool SQLiteVersionedObjects:: } void SQLiteVersionedObjects::remove_versioned_object(uint id) const { - auto storage = conn->get_storage(); + auto& storage = conn->get_storage(); storage.remove(id); } std::vector SQLiteVersionedObjects::get_versioned_object_ids( bool filter_deleted ) const { - auto storage = conn->get_storage(); + auto& storage = conn->get_storage(); if (filter_deleted) { return storage.select( &DBVersionedObject::id, @@ -214,7 +214,7 @@ std::vector SQLiteVersionedObjects::get_versioned_object_ids( std::vector SQLiteVersionedObjects::get_versioned_object_ids( const uuid_d& object_id, bool filter_deleted ) const { - auto storage = conn->get_storage(); + auto& storage = conn->get_storage(); auto uuid = object_id.to_string(); if (filter_deleted) { return storage.select( @@ -233,7 +233,7 @@ std::vector SQLiteVersionedObjects::get_versioned_object_ids( std::vector SQLiteVersionedObjects::get_versioned_objects( const uuid_d& object_id, bool filter_deleted ) const { - auto storage = conn->get_storage(); + auto& storage = conn->get_storage(); auto uuid = object_id.to_string(); if (filter_deleted) { return storage.get_all( @@ -253,7 +253,7 @@ std::optional SQLiteVersionedObjects::get_last_versioned_object( const uuid_d& object_id, bool filter_deleted ) const { - auto storage = conn->get_storage(); + auto& storage = conn->get_storage(); std::vector>> max_commit_time_ids; // we are looking for the ids that match the object_id with the highest @@ -298,7 +298,7 @@ SQLiteVersionedObjects::delete_version_and_get_previous_transact( const uuid_d& object_id, uint id ) const { try { - auto storage = conn->get_storage(); + auto& storage = conn->get_storage(); auto transaction = storage.transaction_guard(); std::optional ret_value = std::nullopt; storage.remove(id); @@ -337,7 +337,7 @@ uint SQLiteVersionedObjects::add_delete_marker_transact( uint ret_id{0}; added = false; try { - auto storage = conn->get_storage(); + auto& storage = conn->get_storage(); auto transaction = storage.transaction_guard(); auto last_version_select = storage.get_all( where( @@ -383,7 +383,7 @@ SQLiteVersionedObjects::get_committed_versioned_object_specific_version( const std::string& bucket_id, const std::string& object_name, const std::string& version_id ) const { - auto storage = conn->get_storage(); + auto& storage = conn->get_storage(); auto ids = storage.select( &DBVersionedObject::id, inner_join( @@ -416,7 +416,7 @@ SQLiteVersionedObjects::get_committed_versioned_object_last_version( ) const { // we don't have a version_id, so return the last available one that is // committed - auto storage = conn->get_storage(); + auto& storage = conn->get_storage(); std::optional ret_value = std::nullopt; auto last_version_id = storage.select( &DBVersionedObject::id, @@ -450,7 +450,7 @@ SQLiteVersionedObjects::create_new_versioned_object_transact( const std::string& bucket_id, const std::string& object_name, const std::string& version_id ) const { - auto storage = conn->get_storage(); + auto& storage = conn->get_storage(); RetrySQLite retry([&]() { auto transaction = storage.transaction_guard(); auto objs = storage.select( @@ -492,7 +492,7 @@ std::optional SQLiteVersionedObjects::remove_deleted_versions_transact(uint max_objects ) const { DBDeletedObjectItems ret_objs; - auto storage = conn->get_storage(); + auto& storage = conn->get_storage(); RetrySQLite retry([&]() { auto transaction = storage.transaction_guard(); // get first the list of objects to be deleted up to max_objects diff --git a/src/rgw/rgw_sal_sfs.cc b/src/rgw/rgw_sal_sfs.cc index ae4123125d1e5..738c92001be6c 100644 --- a/src/rgw/rgw_sal_sfs.cc +++ b/src/rgw/rgw_sal_sfs.cc @@ -400,7 +400,7 @@ http::status SFSStatusPage::render(std::ostream& os) { << " locked=" << ceph_mutex_is_locked(sfs->buckets_map_lock) << "\n"; os << "\n"; - auto db = sfs->db_conn->get_storage(); + auto& db = sfs->db_conn->get_storage(); sqlite3* sqlite_db = sfs->db_conn->first_sqlite_conn; os << "

SQLite

\n"