diff --git a/src/rgw/driver/sfs/sqlite/dbconn.cc b/src/rgw/driver/sfs/sqlite/dbconn.cc index be6743d058f02d..1a335022213d5e 100644 --- a/src/rgw/driver/sfs/sqlite/dbconn.cc +++ b/src/rgw/driver/sfs/sqlite/dbconn.cc @@ -13,6 +13,7 @@ */ #include "dbconn.h" +#include #include #include @@ -121,6 +122,7 @@ DBConn::DBConn(CephContext* _cct) storage_pool_mutex(), cct(_cct), profile_enabled(_cct->_conf.get_val("rgw_sfs_sqlite_profile")) { + maybe_rename_database_file(); sqlite3_config(SQLITE_CONFIG_LOG, &sqlite_error_callback, cct); // get_storage() relies on there already being an entry in the pool // for the main thread (i.e. the thread that created the DBConn). @@ -414,4 +416,24 @@ void DBConn::maybe_upgrade_metadata() { } } +void DBConn::maybe_rename_database_file() const { + if (std::filesystem::exists(getLegacyDBPath(cct)) && + !std::filesystem::exists(getDBPath(cct))) { + lsubdout(cct, rgw_sfs, SFS_LOG_STARTUP) + << fmt::format( + "Found legacy database file {}. Moving to new filename {}", + getLegacyDBPath(cct), getDBPath(cct) + ) + << dendl; + std::error_code ec; + std::filesystem::rename(getLegacyDBPath(cct), getDBPath(cct), ec); + if (ec) { + ceph_abort_msg(fmt::format( + "Error renaming legacy database file {} -> {}: {}", + getLegacyDBPath(cct), getDBPath(cct), ec.message() + )); + } + } +} + } // namespace rgw::sal::sfs::sqlite diff --git a/src/rgw/driver/sfs/sqlite/dbconn.h b/src/rgw/driver/sfs/sqlite/dbconn.h index 55fd905bab5333..0bc9fe64f5737f 100644 --- a/src/rgw/driver/sfs/sqlite/dbconn.h +++ b/src/rgw/driver/sfs/sqlite/dbconn.h @@ -41,6 +41,7 @@ constexpr int SFS_METADATA_VERSION = 4; /// minimum required version to upgrade db. constexpr int SFS_METADATA_MIN_VERSION = 4; +constexpr std::string_view LEGACY_DB_FILENAME = "s3gw.db"; constexpr std::string_view DB_FILENAME = "sfs.db"; constexpr std::string_view DB_WAL_FILENAME = "sfs.db-wal"; @@ -297,8 +298,16 @@ class DBConn { return db_path.string(); } + static std::string getLegacyDBPath(CephContext* cct) { + auto rgw_sfs_path = cct->_conf.get_val("rgw_sfs_data_path"); + auto db_path = + std::filesystem::path(rgw_sfs_path) / std::string(LEGACY_DB_FILENAME); + return db_path.string(); + } + void check_metadata_is_compatible() const; void maybe_upgrade_metadata(); + void maybe_rename_database_file() const; }; using DBConnRef = std::shared_ptr;