]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
rgw/posix: Implement SQLite lifecycle in POSIXUserDB 69889/head
authorSamarah Uriarte <samarah.uriarte@ibm.com>
Wed, 1 Jul 2026 19:26:25 +0000 (14:26 -0500)
committerSamarah Uriarte <samarah.uriarte@ibm.com>
Wed, 1 Jul 2026 20:55:02 +0000 (15:55 -0500)
Signed-off-by: Samarah Uriarte <samarah.uriarte@ibm.com>
src/rgw/driver/posix/posixDB.h
src/rgw/driver/posix/rgw_sal_posix.cc
src/rgw/driver/posix/rgw_sal_posix.h

index 7aae32ce360e308e6e48ab3d6def253fd8502c89..4c6f1a1df75f65475d45baed4f76853f7dc22c59 100644 (file)
@@ -30,8 +30,6 @@ namespace rgw { namespace store {
 class POSIXUserDB;
 class POSIXAccountDB;
 
-struct POSIXAccountDBOpAccountInfo : DBOpAccountInfo {};
-
 struct POSIXUserDBOpUserInfo : DBOpUserInfo {};
 
 struct POSIXUserDBOpInfo : DBOpInfo {};
@@ -42,6 +40,8 @@ struct POSIXUserDBOpPrepareInfo : DBOpPrepareInfo {};
 
 struct POSIXUserDBOpPrepareParams : DBOpPrepareParams {};
 
+struct POSIXAccountDBOpAccountInfo : DBOpAccountInfo {};
+
 struct POSIXAccountDBOpInfo : DBOpInfo {};
 
 struct POSIXAccountDBOpPrepareInfo : DBOpPrepareInfo {};
@@ -151,6 +151,8 @@ class RemovePOSIXUserOp: public SQLRemoveUser {};
 class POSIXUserDB : public SQLiteDB {
   private:
     const std::string db_name;
+    const std::string lc_head_table;
+    const std::string lc_entry_table;
     rgw::sal::Driver* driver;
 
   protected:
@@ -166,6 +168,8 @@ class POSIXUserDB : public SQLiteDB {
 
     POSIXUserDB(std::string db_name, CephContext *_cct) : SQLiteDB(db_name, _cct),
                db_name(db_name),
+               lc_head_table(db_name+"_lc_head_table"),
+               lc_entry_table(db_name+"_lc_entry_table"),
                cct(_cct),
                dp(_cct, ceph_subsys_rgw, "rgw POSIXUserDBStore backend: ")
                 { DB::set_context(cct); }
@@ -180,7 +184,9 @@ class POSIXUserDB : public SQLiteDB {
     virtual int InitPrepareParams(const DoutPrefixProvider *dpp,
                                   DBOpPrepareParams &p_params,
                                   DBOpParams* params) override { return 0; }
-    virtual int createLCTables(const DoutPrefixProvider *dpp) override { return 0; }
+    virtual int createLCTables(const DoutPrefixProvider *dpp) override { return SQLiteDB::createLCTables(dpp); }
+    const std::string getLCHeadTable() { return lc_head_table; }
+    const std::string getLCEntryTable() { return lc_entry_table; }
 
     virtual int ListAllBuckets(const DoutPrefixProvider *dpp, DBOpParams *params) override { return 0; }
     virtual int ListAllUsers(const DoutPrefixProvider *dpp, DBOpParams *params) override { return 0; }
index 92710d01669166f3184a149b9eb724abb6902890..4530da7db3371d8d2ff3aac18fcdf8683084ac65 100644 (file)
@@ -23,6 +23,7 @@
 #include "include/scope_guard.h"
 #include "common/Clock.h" // for ceph_clock_now()
 #include "common/errno.h"
+#include "rgw_lc.h"
 
 #define dout_subsys ceph_subsys_rgw
 #define dout_context g_ceph_context
@@ -1970,6 +1971,19 @@ int POSIXDriver::initialize(CephContext *cct, const DoutPrefixProvider *dpp)
       }
     }
   }
+
+  lc = new RGWLC();
+  lc->initialize(cct, this);
+
+  if (use_lc_thread) { 
+    ret = userDB->createLCTables(dpp);
+    if (ret < 0) {
+      ldpp_dout(dpp, 0) << "Failed to create LC tables, ret=" << ret << dendl;
+      return ret;
+    }
+    lc->start_processor();
+  }
+
   ldpp_dout(dpp, 20) << "root_fd: " << root_dir->get_fd() << dendl;
   quota_handler = RGWQuotaHandler::generate_handler(dpp, this, true);
 
@@ -2199,6 +2213,11 @@ int POSIXDriver::cluster_stat(RGWClusterStat& stats)
   return 0;
 }
 
+std::unique_ptr<Lifecycle> POSIXDriver::get_lifecycle(void)
+{
+  return std::make_unique<POSIXLifecycle>(this);
+}
+
 std::unique_ptr<Writer> POSIXDriver::get_append_writer(const DoutPrefixProvider *dpp,
                                  optional_yield y,
                                  rgw::sal::Object* _head_obj,
@@ -2941,9 +2960,18 @@ int POSIXBucket::write_attrs(const DoutPrefixProvider* dpp, optional_yield y)
   // Bucket info is stored as an attribute, but not in attrs[]
   bufferlist bl;
   encode(info, bl);
-  Attrs extra_attrs;
+  Attrs orig_attrs, extra_attrs;
   extra_attrs[RGW_POSIX_ATTR_BUCKET_INFO] = bl;
 
+  ret = dir->read_attrs(dpp, y, orig_attrs);
+
+  for (auto attr : orig_attrs) {
+    if (auto found = attrs.find(attr.first); found == attrs.end()) {
+      /* Attribute needs to be erased */
+      remove_x_attr(dpp, y, dir->get_fd(), attr.first, get_name());
+    }
+  }
+
   return dir->write_attrs(dpp, y, attrs, &extra_attrs);
 }
 
@@ -4626,6 +4654,58 @@ int POSIXAtomicWriter::complete(size_t accounted_size, const std::string& etag,
   return 0;
 }
 
+int POSIXLifecycle::get_entry(const DoutPrefixProvider* dpp, optional_yield y,
+                              const std::string& oid, const std::string& marker,
+                              LCEntry& entry)
+{
+  return driver->get_user_db()->get_entry(oid, marker, entry);
+}
+
+int POSIXLifecycle::get_next_entry(const DoutPrefixProvider* dpp, optional_yield y,
+                                  const std::string& oid, const std::string& marker,
+                                   LCEntry& entry)
+{
+  return driver->get_user_db()->get_next_entry(oid, marker, entry);
+}
+
+int POSIXLifecycle::set_entry(const DoutPrefixProvider* dpp, optional_yield y,
+                              const std::string& oid, const LCEntry& entry)
+{
+  return driver->get_user_db()->set_entry(oid, entry);
+}
+
+int POSIXLifecycle::list_entries(const DoutPrefixProvider* dpp, optional_yield y,
+                               const std::string& oid, const std::string& marker,
+                                uint32_t max_entries, std::vector<LCEntry>& entries)
+{
+  return driver->get_user_db()->list_entries(oid, marker, max_entries, entries);
+}
+
+int POSIXLifecycle::rm_entry(const DoutPrefixProvider* dpp, optional_yield y,
+                             const std::string& oid, const LCEntry& entry)
+{
+  return driver->get_user_db()->rm_entry(oid, entry);
+}
+
+int POSIXLifecycle::get_head(const DoutPrefixProvider* dpp, optional_yield y,
+                             const std::string& oid, LCHead& head)
+{
+  return driver->get_user_db()->get_head(oid, head);
+}
+
+int POSIXLifecycle::put_head(const DoutPrefixProvider* dpp, optional_yield y,
+                             const std::string& oid, const LCHead& head)
+{
+  return driver->get_user_db()->put_head(oid, head);
+}
+
+std::unique_ptr<LCSerializer> POSIXLifecycle::get_serializer(const std::string& lock_name,
+                                                             const std::string& oid,
+                                                             const std::string& cookie)
+{
+  return std::make_unique<LCPOSIXSerializer>(driver, oid, lock_name, cookie);
+}
+
 } } // namespace rgw::sal
 
 extern "C" {
index 7779991ee827c6973298fa84bffd58ca88fa2583..6abf0dcb72cbb3328316b9bd48a25ac6f6cf027e 100644 (file)
@@ -24,6 +24,8 @@
 #include "bucket_cache.h"
 #include "posixDB.h"
 
+class RGWLC;
+
 namespace rgw { namespace sal {
 
 class POSIXDriver;
@@ -484,6 +486,8 @@ protected:
   int root_fd;
   RGWSyncModuleInstanceRef sync_module;
   RGWQuotaHandler* quota_handler{nullptr};
+  RGWLC* lc{nullptr};
+  bool use_lc_thread;
 
 public:
   POSIXDriver(CephContext *_cct) : StoreDriver(), cct(_cct), zone(this)
@@ -502,6 +506,11 @@ public:
     cct = _cct;
   }
 
+  POSIXDriver& set_run_lc_thread(bool _use_lc_thread) {
+    use_lc_thread = _use_lc_thread;
+    return *this;
+  }
+
   virtual int initialize(CephContext *cct, const DoutPrefixProvider *dpp);
   virtual const std::string get_name() const override { return "posix"; }
   virtual std::string get_cluster_id(const DoutPrefixProvider* dpp,  optional_yield y) override { return "PLACEHOLDER"; };
@@ -654,7 +663,7 @@ public:
   virtual int get_zonegroup(const std::string& id, std::unique_ptr<ZoneGroup>* zonegroup) override;
   virtual int list_all_zones(const DoutPrefixProvider* dpp, std::list<std::string>& zone_ids) override;
   virtual int cluster_stat(RGWClusterStat& stats) override;
-  virtual std::unique_ptr<Lifecycle> get_lifecycle(void) override { return nullptr; } // TODO: implement
+  virtual std::unique_ptr<Lifecycle> get_lifecycle(void) override;
   virtual std::unique_ptr<Restore> get_restore(void) { return nullptr; }
   virtual bool process_expired_objects(const DoutPrefixProvider *dpp, optional_yield y) override { return 0; }
 
@@ -684,7 +693,7 @@ public:
                                      optional_yield y,
                                      const std::string& topic_queue) override { return -ENOTSUP; }
 
-  virtual RGWLC* get_rgwlc(void) override { return NULL; } // TODO: Lifecycle not currently supported
+  virtual RGWLC* get_rgwlc(void) override { return lc; }
   virtual rgw::restore::Restore* get_rgwrestore(void) { return nullptr; }
   virtual RGWCoroutinesManagerRegistry* get_cr_registry() override { return NULL; }
 
@@ -1434,4 +1443,43 @@ public:
   virtual int unlock(const DoutPrefixProvider* dpp, optional_yield y) override;
 };
 
+class LCPOSIXSerializer : public StoreLCSerializer {
+public:
+  LCPOSIXSerializer(POSIXDriver* driver, const std::string& oid, const std::string& lock_name, const std::string& cookie) {}
+
+  virtual int try_lock(const DoutPrefixProvider* dpp, ceph::timespan dur, optional_yield y) override { return 0; }
+  virtual int unlock(const DoutPrefixProvider* dpp, optional_yield y) override { return 0; }
+};
+
+class POSIXLifecycle : public Lifecycle {
+  POSIXDriver* driver;
+
+public:
+  POSIXLifecycle(POSIXDriver* _driver) : driver(_driver) {}
+  virtual ~POSIXLifecycle() = default;
+
+  virtual int get_entry(const DoutPrefixProvider* dpp, optional_yield y,
+                        const std::string& oid, const std::string& marker,
+                        LCEntry& entry) override;
+  virtual int get_next_entry(const DoutPrefixProvider* dpp, optional_yield y,
+                             const std::string& oid, const std::string& marker,
+                             LCEntry& entry) override;
+  virtual int set_entry(const DoutPrefixProvider* dpp, optional_yield y,
+                        const std::string& oid, const LCEntry& entry) override;
+  virtual int list_entries(const DoutPrefixProvider* dpp, optional_yield y,
+                           const std::string& oid, const std::string& marker,
+                           uint32_t max_entries,
+                           std::vector<LCEntry>& entries) override;
+  virtual int rm_entry(const DoutPrefixProvider* dpp, optional_yield y,
+                       const std::string& oid, const LCEntry& entry) override;
+  virtual int get_head(const DoutPrefixProvider* dpp, optional_yield y,
+                       const std::string& oid, LCHead& head) override;
+  virtual int put_head(const DoutPrefixProvider* dpp, optional_yield y,
+                       const std::string& oid, const LCHead& head) override;
+
+  virtual std::unique_ptr<LCSerializer> get_serializer(const std::string& lock_name,
+                                                       const std::string& oid,
+                                                       const std::string& cookie) override;
+};
+
 } } // namespace rgw::sal