]> git.apps.os.sepia.ceph.com Git - ceph-ci.git/commitdiff
rgw/dbstore: APIs to handle lc state
authorSoumya Koduri <skoduri@redhat.com>
Mon, 11 Oct 2021 12:55:02 +0000 (18:25 +0530)
committerSoumya Koduri <skoduri@redhat.com>
Thu, 11 Nov 2021 08:14:19 +0000 (13:44 +0530)
Add placeholder APIs to create and store LC related state.

Signed-off-by: Soumya Koduri <skoduri@redhat.com>
src/rgw/rgw_sal.cc
src/rgw/rgw_sal_dbstore.cc
src/rgw/rgw_sal_dbstore.h
src/rgw/store/dbstore/common/dbstore.h
src/rgw/store/dbstore/sqlite/sqliteDB.cc
src/rgw/store/dbstore/sqlite/sqliteDB.h
src/rgw/store/dbstore/tests/dbstore_tests.cc

index a510ae9f07269b45774c18ffe4e97cebe2f4890c..e1eb3bd1e82b3954750e83381296f0032b980dae 100644 (file)
@@ -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<rgw::sal::DBStore *>(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", "");
index bc1934c9df746d5433f9896ebf1a0f50ea5bf333..424a32816d0cb9e2cdf32a30180943bf7b711991 100644 (file)
@@ -1177,7 +1177,7 @@ namespace rgw::sal {
 
   std::unique_ptr<Lifecycle> DBStore::get_lifecycle(void)
   {
-    return 0;
+    return std::make_unique<DBLifecycle>(this);
   }
 
   std::unique_ptr<Completions> 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<LCEntry>& 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<Notification> 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<DBNotification>(obj, event_type);
   }
 
+  RGWLC* DBStore::get_rgwlc(void) {
+    return lc;
+  }
+
   int DBStore::log_usage(const DoutPrefixProvider *dpp, map<rgw_user_bucket, RGWUsageBatch>& 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;
index bb4748520434399fc9af2d1a07b8cde611e30477..8014fe26ceaadc48e253bf9dfb844011d7fe6513 100644 (file)
@@ -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<LCEntry>& 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<User> 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>* user) override;
       virtual int get_user_by_email(const DoutPrefixProvider *dpp, const std::string& email, optional_yield y, std::unique_ptr<User>* user) override;
@@ -486,7 +527,7 @@ protected:
       virtual std::unique_ptr<Completions> get_completions(void) override;
       virtual std::unique_ptr<Notification> 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<rgw_user_bucket, RGWUsageBatch>& usage_info) override;
index 4619ff55d2a9739ee7f69ca59177a6eea1af7907..9cf1b4fd669bbb7355698e6b36e8a767417168c5 100644 (file)
@@ -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("<<type<<") specified" << dendl;
 
@@ -1139,6 +1168,8 @@ class DB {
     const string user_table;
     const string bucket_table;
     const string quota_table;
+    const string lc_head_table;
+    const string lc_entry_table;
     static map<string, class ObjectOp*> 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 &params) = 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;
index b634a846ae522f997ad3f06ac50a74796dc56e7c..389fd0d5fba1e41a9373e83ec2eb0ab555d3c83b 100644 (file)
@@ -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, &params)))
     goto out;
 
-  if ((cb = createQuotaTable(dpp, &params)))
+  if ((cq = createQuotaTable(dpp, &params)))
     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", &params);
+  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", &params);
+  ret = exec(dpp, schema.c_str(), NULL);
+  if (ret) {
+    ldpp_dout(dpp, 0)<<"CreateLCHeadTable failed" << dendl;
+    (void)DeleteLCEntryTable(dpp, &params);
+  }
+  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;
index ce6f2980512fdcd99213e783999f754f8b15733f..5d747f7a57453222f75c78e942d1ff9608c77078 100644 (file)
@@ -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;
index 170d5d48d121d77172ac29d11f851ba8e96a515c..2d02bf24144f2e599d6432962523734f91df1842 100644 (file)
@@ -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;