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

rgw/sfs: upgrade existing db for bucket mtime col (backport to v0.23) #253

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions src/rgw/driver/sfs/sqlite/dbconn.cc
Original file line number Diff line number Diff line change
Expand Up @@ -355,6 +355,30 @@ static int upgrade_metadata_from_v2(sqlite3* db, std::string* errmsg) {
return 0;
}

static int upgrade_metadata_from_v4(sqlite3* db, std::string* errmsg) {
auto rc = sqlite3_exec(
db,
fmt::format(
"ALTER TABLE {} ADD COLUMN mtime INTEGER NOT NULL DEFAULT 0",
BUCKETS_TABLE
)
.c_str(),
nullptr, nullptr, nullptr
);

if (rc != SQLITE_OK) {
if (errmsg != nullptr) {
*errmsg = fmt::format(
"Error creating column 'mtime' in table '{}': {}", BUCKETS_TABLE,
sqlite3_errmsg(db)
);
}
return -1;
}

return 0;
}

static void upgrade_metadata(
CephContext* cct, StorageRef storage, sqlite3* db
) {
Expand All @@ -372,6 +396,8 @@ static void upgrade_metadata(
rc = upgrade_metadata_from_v1(db, &errmsg);
} else if (cur_version == 2) {
rc = upgrade_metadata_from_v2(db, &errmsg);
} else if (cur_version == 4) {
rc = upgrade_metadata_from_v4(db, &errmsg);
}

if (rc < 0) {
Expand Down
6 changes: 4 additions & 2 deletions src/rgw/driver/sfs/sqlite/dbconn.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
namespace rgw::sal::sfs::sqlite {

/// current db version.
constexpr int SFS_METADATA_VERSION = 4;
constexpr int SFS_METADATA_VERSION = 5;
/// minimum required version to upgrade db.
constexpr int SFS_METADATA_MIN_VERSION = 4;

Expand Down Expand Up @@ -139,7 +139,9 @@ inline auto _make_storage(const std::string& path) {
sqlite_orm::make_column("deleted", &DBBucket::deleted),
sqlite_orm::make_column("bucket_attrs", &DBBucket::bucket_attrs),
sqlite_orm::make_column("object_lock", &DBBucket::object_lock),
sqlite_orm::make_column("mtime", &DBBucket::mtime),
sqlite_orm::make_column(
"mtime", &DBBucket::mtime, sqlite_orm::default_value(0)
),
sqlite_orm::foreign_key(&DBBucket::owner_id)
.references(&DBUser::user_id)
),
Expand Down
Loading