Skip to content
This repository has been archived by the owner on Jan 3, 2024. It is now read-only.

Commit

Permalink
rgw/sfs: Rename legacy database filename to new if exists on startup
Browse files Browse the repository at this point in the history
Signed-off-by: Marcel Lauhoff <marcel.lauhoff@suse.com>
  • Loading branch information
Marcel Lauhoff committed Nov 13, 2023
1 parent 69c0648 commit 68c6dea
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
22 changes: 22 additions & 0 deletions src/rgw/driver/sfs/sqlite/dbconn.cc
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
*/
#include "dbconn.h"

#include <ceph_assert.h>
#include <sqlite3.h>

#include <filesystem>
Expand Down Expand Up @@ -121,6 +122,7 @@ DBConn::DBConn(CephContext* _cct)
storage_pool_mutex(),
cct(_cct),
profile_enabled(_cct->_conf.get_val<bool>("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).
Expand Down Expand Up @@ -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
9 changes: 9 additions & 0 deletions src/rgw/driver/sfs/sqlite/dbconn.h
Original file line number Diff line number Diff line change
Expand Up @@ -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";

Expand Down Expand Up @@ -297,8 +298,16 @@ class DBConn {
return db_path.string();
}

static std::string getLegacyDBPath(CephContext* cct) {
auto rgw_sfs_path = cct->_conf.get_val<std::string>("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<DBConn>;
Expand Down

0 comments on commit 68c6dea

Please sign in to comment.