From 12959b372b2585d1bc72a46eb3206498b7111322 Mon Sep 17 00:00:00 2001 From: Soumya Koduri Date: Mon, 11 Oct 2021 18:25:02 +0530 Subject: [PATCH] rgw/dbstore: APIs to handle lc state Add placeholder APIs to create and store LC related state. Signed-off-by: Soumya Koduri --- src/rgw/rgw_sal.cc | 7 +- src/rgw/rgw_sal_dbstore.cc | 65 ++++++++++++++++- src/rgw/rgw_sal_dbstore.h | 45 +++++++++++- src/rgw/store/dbstore/common/dbstore.h | 38 ++++++++++ src/rgw/store/dbstore/sqlite/sqliteDB.cc | 77 +++++++++++++++++++- src/rgw/store/dbstore/sqlite/sqliteDB.h | 5 ++ src/rgw/store/dbstore/tests/dbstore_tests.cc | 8 ++ 7 files changed, 237 insertions(+), 8 deletions(-) diff --git a/src/rgw/rgw_sal.cc b/src/rgw/rgw_sal.cc index a510ae9f072..e1eb3bd1e82 100644 --- a/src/rgw/rgw_sal.cc +++ b/src/rgw/rgw_sal.cc @@ -80,9 +80,10 @@ rgw::sal::Store* StoreManager::init_storage_provider(const DoutPrefixProvider* d #ifdef WITH_RADOSGW_DBSTORE rgw::sal::Store* store = newDBStore(cct); - /* Initialize the dbstore with cct & dpp */ - DB *db = static_cast(store)->getDB(); - db->set_context(cct); + if ((*(rgw::sal::DBStore*)store).set_run_lc_thread(use_lc_thread) + .initialize(cct, dpp) < 0) { + delete store; store = nullptr; + } /* XXX: temporary - create testid user */ rgw_user testid_user("", "testid", ""); diff --git a/src/rgw/rgw_sal_dbstore.cc b/src/rgw/rgw_sal_dbstore.cc index bc1934c9df7..424a32816d0 100644 --- a/src/rgw/rgw_sal_dbstore.cc +++ b/src/rgw/rgw_sal_dbstore.cc @@ -1177,7 +1177,7 @@ namespace rgw::sal { std::unique_ptr DBStore::get_lifecycle(void) { - return 0; + return std::make_unique(this); } std::unique_ptr DBStore::get_completions(void) @@ -1185,6 +1185,49 @@ namespace rgw::sal { return 0; } + int DBLifecycle::get_entry(const std::string& oid, const std::string& marker, + LCEntry& entry) + { + return 0; + } + + int DBLifecycle::get_next_entry(const std::string& oid, std::string& marker, + LCEntry& entry) + { + return 0; + } + + int DBLifecycle::set_entry(const std::string& oid, const LCEntry& entry) + { + return 0; + } + + int DBLifecycle::list_entries(const std::string& oid, const std::string& marker, + uint32_t max_entries, vector& entries) + { + return 0; + } + + int DBLifecycle::rm_entry(const std::string& oid, const LCEntry& entry) + { + return 0; + } + + int DBLifecycle::get_head(const std::string& oid, LCHead& head) + { + return 0; + } + + int DBLifecycle::put_head(const std::string& oid, const LCHead& head) + { + return 0; + } + + LCSerializer* DBLifecycle::get_serializer(const std::string& lock_name, const std::string& oid, const std::string& cookie) + { + return new LCDBSerializer(store, oid, lock_name, cookie); + } + std::unique_ptr DBStore::get_notification(rgw::sal::Object* obj, struct req_state* s, rgw::notify::EventType event_type, const std::string* object_name) @@ -1192,6 +1235,10 @@ namespace rgw::sal { return std::make_unique(obj, event_type); } + RGWLC* DBStore::get_rgwlc(void) { + return lc; + } + int DBStore::log_usage(const DoutPrefixProvider *dpp, map& usage_info) { return 0; @@ -1310,6 +1357,21 @@ namespace rgw::sal { return 0; } + int DBStore::initialize(CephContext *_cct, const DoutPrefixProvider *_dpp) { + int ret = 0; + cct = _cct; + dpp = _dpp; + + lc = new RGWLC(); + lc->initialize(cct, this); + + if (use_lc_thread) { + ret = db->createLCTables(dpp); + lc->start_processor(); + } + + return ret; + } } // namespace rgw::sal extern "C" { @@ -1333,6 +1395,7 @@ extern "C" { store->setDBStoreManager(dbsm); store->setDB(db); db->set_store((rgw::sal::Store*)store); + db->set_context(cct); } return store; diff --git a/src/rgw/rgw_sal_dbstore.h b/src/rgw/rgw_sal_dbstore.h index bb474852043..8014fe26cea 100644 --- a/src/rgw/rgw_sal_dbstore.h +++ b/src/rgw/rgw_sal_dbstore.h @@ -18,6 +18,7 @@ #include "rgw_sal.h" #include "rgw_oidc_provider.h" #include "rgw_role.h" +#include "rgw_lc.h" #include "store/dbstore/common/dbstore.h" #include "store/dbstore/dbstore_mgr.h" @@ -26,6 +27,35 @@ namespace rgw { namespace sal { class DBStore; +class LCDBSerializer : public LCSerializer { + const std::string oid; + +public: + LCDBSerializer(DBStore* store, const std::string& oid, const std::string& lock_name, const std::string& cookie) {} + + virtual int try_lock(const DoutPrefixProvider *dpp, utime_t dur, optional_yield y) override { return 0; } + virtual int unlock() override { + return 0; + } +}; + +class DBLifecycle : public Lifecycle { + DBStore* store; + +public: + DBLifecycle(DBStore* _st) : store(_st) {} + + virtual int get_entry(const std::string& oid, const std::string& marker, LCEntry& entry) override; + virtual int get_next_entry(const std::string& oid, std::string& marker, LCEntry& entry) override; + virtual int set_entry(const std::string& oid, const LCEntry& entry) override; + virtual int list_entries(const std::string& oid, const std::string& marker, + uint32_t max_entries, std::vector& entries) override; + virtual int rm_entry(const std::string& oid, const LCEntry& entry) override; + virtual int get_head(const std::string& oid, LCHead& head) override; + virtual int put_head(const std::string& oid, const LCHead& head) override; + virtual LCSerializer* get_serializer(const std::string& lock_name, const std::string& oid, const std::string& cookie) override; +}; + class DBNotification : public Notification { protected: Object* obj; @@ -461,11 +491,22 @@ protected: string luarocks_path; DBZone zone; RGWSyncModuleInstanceRef sync_module; + RGWLC* lc; + CephContext *cct; + const DoutPrefixProvider *dpp; + bool use_lc_thread; public: - DBStore(): dbsm(nullptr), zone(this) {} + DBStore(): dbsm(nullptr), zone(this), cct(nullptr), dpp(nullptr), + use_lc_thread(false) {} ~DBStore() { delete dbsm; } + DBStore& set_run_lc_thread(bool _use_lc_thread) { + use_lc_thread = _use_lc_thread; + return *this; + } + + int initialize(CephContext *cct, const DoutPrefixProvider *dpp); virtual std::unique_ptr get_user(const rgw_user& u) override; virtual int get_user_by_access_key(const DoutPrefixProvider *dpp, const std::string& key, optional_yield y, std::unique_ptr* user) override; virtual int get_user_by_email(const DoutPrefixProvider *dpp, const std::string& email, optional_yield y, std::unique_ptr* user) override; @@ -486,7 +527,7 @@ protected: virtual std::unique_ptr get_completions(void) override; virtual std::unique_ptr get_notification(rgw::sal::Object* obj, struct req_state* s, rgw::notify::EventType event_type, const std::string* object_name=nullptr) override; - virtual RGWLC* get_rgwlc(void) override { return NULL; } + virtual RGWLC* get_rgwlc(void) override; virtual RGWCoroutinesManagerRegistry* get_cr_registry() override { return NULL; } virtual int log_usage(const DoutPrefixProvider *dpp, map& usage_info) override; diff --git a/src/rgw/store/dbstore/common/dbstore.h b/src/rgw/store/dbstore/common/dbstore.h index 4619ff55d2a..9cf1b4fd669 100644 --- a/src/rgw/store/dbstore/common/dbstore.h +++ b/src/rgw/store/dbstore/common/dbstore.h @@ -127,6 +127,8 @@ struct DBOpParams { /* Below are subject to change */ string objectdata_table; string quota_table; + string lc_head_table; + string lc_entry_table; string obj; }; @@ -292,6 +294,8 @@ struct DBOpPrepareParams { /* below subject to change */ string objectdata_table; string quota_table; + string lc_head_table; + string lc_entry_table; }; struct DBOps { @@ -543,6 +547,24 @@ class DBOp { Enabled Boolean , \ CheckOnRaw Boolean \n);"; + const string CreateLCEntryTableQ = + "CREATE TABLE IF NOT EXISTS '{}' ( \ + LCIndex TEXT NOT NULL, \ + BucketName TEXT NOT NULL , \ + StartTime INTEGER , \ + Status INTEGER, \ + PRIMARY KEY (LCIndex, BucketName), \ + FOREIGN KEY (BucketName) \ + REFERENCES '{}' (BucketName) ON DELETE CASCADE ON UPDATE CASCADE \n);"; + + const string CreateLCHeadTableQ = + "CREATE TABLE IF NOT EXISTS '{}' ( \ + LCIndex TEXT NOT NULL, \ + Marker TEXT, \ + StartDate INTEGER , \ + PRIMARY KEY (LCIndex) \n);"; + + const string DropQ = "DROP TABLE IF EXISTS '{}'"; const string ListAllQ = "SELECT * from '{}'"; @@ -569,6 +591,13 @@ class DBOp { if (!type.compare("Quota")) return fmt::format(CreateQuotaTableQ.c_str(), params->quota_table.c_str()); + if (!type.compare("LCHead")) + return fmt::format(CreateLCHeadTableQ.c_str(), + params->lc_head_table.c_str()); + if (!type.compare("LCEntry")) + return fmt::format(CreateLCEntryTableQ.c_str(), + params->lc_entry_table.c_str(), + params->bucket_table.c_str()); ldout(params->cct, 0) << "Incorrect table type("< objectmap; pthread_mutex_t mutex; // to protect objectmap and other shared // objects if any. This mutex is taken @@ -1161,6 +1192,8 @@ class DB { user_table(db_name+".user.table"), bucket_table(db_name+".bucket.table"), quota_table(db_name+".quota.table"), + lc_head_table(db_name+".lc_head.table"), + lc_entry_table(db_name+".lc_entry.table"), cct(_cct), dp(_cct, dout_subsys, "rgw DBStore backend: ") {} @@ -1170,6 +1203,8 @@ class DB { user_table(db_name+".user.table"), bucket_table(db_name+".bucket.table"), quota_table(db_name+".quota.table"), + lc_head_table(db_name+".lc_head.table"), + lc_entry_table(db_name+".lc_entry.table"), cct(_cct), dp(_cct, dout_subsys, "rgw DBStore backend: ") {} @@ -1180,6 +1215,8 @@ class DB { const string getUserTable() { return user_table; } const string getBucketTable() { return bucket_table; } const string getQuotaTable() { return quota_table; } + const string getLCHeadTable() { return lc_head_table; } + const string getLCEntryTable() { return lc_entry_table; } const string getObjectTable(string bucket) { return db_name+"."+bucket+".object.table"; } const string getObjectDataTable(string bucket) { @@ -1220,6 +1257,7 @@ class DB { virtual int InitializeDBOps(const DoutPrefixProvider *dpp) { return 0; } virtual int FreeDBOps(const DoutPrefixProvider *dpp) { return 0; } virtual int InitPrepareParams(const DoutPrefixProvider *dpp, DBOpPrepareParams ¶ms) = 0; + virtual int createLCTables(const DoutPrefixProvider *dpp) = 0; virtual int ListAllBuckets(const DoutPrefixProvider *dpp, DBOpParams *params) = 0; virtual int ListAllUsers(const DoutPrefixProvider *dpp, DBOpParams *params) = 0; diff --git a/src/rgw/store/dbstore/sqlite/sqliteDB.cc b/src/rgw/store/dbstore/sqlite/sqliteDB.cc index b634a846ae5..389fd0d5fba 100644 --- a/src/rgw/store/dbstore/sqlite/sqliteDB.cc +++ b/src/rgw/store/dbstore/sqlite/sqliteDB.cc @@ -612,7 +612,7 @@ out: int SQLiteDB::createTables(const DoutPrefixProvider *dpp) { int ret = -1; - int cu, cb = -1; + int cu = 0, cb = 0, cq = 0; DBOpParams params = {}; params.user_table = getUserTable(); @@ -624,7 +624,7 @@ int SQLiteDB::createTables(const DoutPrefixProvider *dpp) if ((cb = createBucketTable(dpp, ¶ms))) goto out; - if ((cb = createQuotaTable(dpp, ¶ms))) + if ((cq = createQuotaTable(dpp, ¶ms))) goto out; ret = 0; @@ -720,6 +720,35 @@ int SQLiteDB::createObjectDataTable(const DoutPrefixProvider *dpp, DBOpParams *p return ret; } +int SQLiteDB::createLCTables(const DoutPrefixProvider *dpp) +{ + int ret = -1; + string schema; + DBOpParams params = {}; + + params.lc_entry_table = getLCEntryTable(); + params.lc_head_table = getLCHeadTable(); + params.bucket_table = getBucketTable(); + + schema = CreateTableSchema("LCEntry", ¶ms); + ret = exec(dpp, schema.c_str(), NULL); + if (ret) { + ldpp_dout(dpp, 0)<<"CreateLCEntryTable failed" << dendl; + return ret; + } + ldpp_dout(dpp, 20)<<"CreateLCEntryTable suceeded" << dendl; + + schema = CreateTableSchema("LCHead", ¶ms); + ret = exec(dpp, schema.c_str(), NULL); + if (ret) { + ldpp_dout(dpp, 0)<<"CreateLCHeadTable failed" << dendl; + (void)DeleteLCEntryTable(dpp, ¶ms); + } + ldpp_dout(dpp, 20)<<"CreateLCHeadTable suceeded" << dendl; + + return ret; +} + int SQLiteDB::DeleteUserTable(const DoutPrefixProvider *dpp, DBOpParams *params) { int ret = -1; @@ -784,6 +813,50 @@ int SQLiteDB::DeleteObjectDataTable(const DoutPrefixProvider *dpp, DBOpParams *p return ret; } +int SQLiteDB::DeleteQuotaTable(const DoutPrefixProvider *dpp, DBOpParams *params) +{ + int ret = -1; + string schema; + + schema = DeleteTableSchema(params->quota_table); + + ret = exec(dpp, schema.c_str(), NULL); + if (ret) + ldpp_dout(dpp, 0)<<"DeleteQuotaTable failed " << dendl; + + ldpp_dout(dpp, 20)<<"DeleteQuotaTable suceeded " << dendl; + + return ret; +} + +int SQLiteDB::DeleteLCEntryTable(const DoutPrefixProvider *dpp, DBOpParams *params) +{ + int ret = -1; + string schema; + + schema = DeleteTableSchema(params->lc_entry_table); + ret = exec(dpp, schema.c_str(), NULL); + if (ret) + ldpp_dout(dpp, 0)<<"DeleteLCEntryTable failed " << dendl; + ldpp_dout(dpp, 20)<<"DeleteLCEntryTable suceeded " << dendl; + + return ret; +} + +int SQLiteDB::DeleteLCHeadTable(const DoutPrefixProvider *dpp, DBOpParams *params) +{ + int ret = -1; + string schema; + + schema = DeleteTableSchema(params->lc_head_table); + ret = exec(dpp, schema.c_str(), NULL); + if (ret) + ldpp_dout(dpp, 0)<<"DeleteLCHeadTable failed " << dendl; + ldpp_dout(dpp, 20)<<"DeleteLCHeadTable suceeded " << dendl; + + return ret; +} + int SQLiteDB::ListAllUsers(const DoutPrefixProvider *dpp, DBOpParams *params) { int ret = -1; diff --git a/src/rgw/store/dbstore/sqlite/sqliteDB.h b/src/rgw/store/dbstore/sqlite/sqliteDB.h index ce6f2980512..5d747f7a574 100644 --- a/src/rgw/store/dbstore/sqlite/sqliteDB.h +++ b/src/rgw/store/dbstore/sqlite/sqliteDB.h @@ -55,10 +55,15 @@ class SQLiteDB : public DB, public DBOp{ int createObjectDataTable(const DoutPrefixProvider *dpp, DBOpParams *params); int createQuotaTable(const DoutPrefixProvider *dpp, DBOpParams *params); + int createLCTables(const DoutPrefixProvider *dpp) override; + int DeleteBucketTable(const DoutPrefixProvider *dpp, DBOpParams *params); int DeleteUserTable(const DoutPrefixProvider *dpp, DBOpParams *params); int DeleteObjectTable(const DoutPrefixProvider *dpp, DBOpParams *params); int DeleteObjectDataTable(const DoutPrefixProvider *dpp, DBOpParams *params); + int DeleteQuotaTable(const DoutPrefixProvider *dpp, DBOpParams *params); + int DeleteLCEntryTable(const DoutPrefixProvider *dpp, DBOpParams *params); + int DeleteLCHeadTable(const DoutPrefixProvider *dpp, DBOpParams *params); int ListAllBuckets(const DoutPrefixProvider *dpp, DBOpParams *params) override; int ListAllUsers(const DoutPrefixProvider *dpp, DBOpParams *params) override; diff --git a/src/rgw/store/dbstore/tests/dbstore_tests.cc b/src/rgw/store/dbstore/tests/dbstore_tests.cc index 170d5d48d12..2d02bf24144 100644 --- a/src/rgw/store/dbstore/tests/dbstore_tests.cc +++ b/src/rgw/store/dbstore/tests/dbstore_tests.cc @@ -1030,6 +1030,14 @@ TEST_F(DBStoreTest, InsertTestIDUser) { ASSERT_EQ(ret, 0); } +TEST_F(DBStoreTest, LCTables) { + struct DBOpParams params = GlobalParams; + int ret = -1; + + ret = db->createLCTables(dpp); + ASSERT_EQ(ret, 0); +} + int main(int argc, char **argv) { int ret = -1; -- 2.39.5