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

Commit

Permalink
Merge pull request #253 from jecluis/wip-fix-mtime-db-v0.23.0-backport
Browse files Browse the repository at this point in the history
rgw/sfs: upgrade existing db for bucket mtime col (backport to v0.23)
  • Loading branch information
jecluis authored Nov 21, 2023
2 parents c6d4304 + 415414e commit f055fde
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 2 deletions.
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

0 comments on commit f055fde

Please sign in to comment.