Merge pull request #69889 from samarahu/standalone-lifecycle-sqlite

rgw/posix: Implement SQLite lifecycle in POSIXUserDB

Reviewed-by: Daniel Gryniewicz <dang1@ibm.com>
This commit is contained in:
Samarah Uriarte 2026-07-07 08:30:31 -05:00 committed by GitHub
commit d7f2fba919
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 140 additions and 6 deletions

View 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; }

View 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
@ -2074,6 +2075,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);
@ -2303,6 +2317,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,
@ -3045,9 +3064,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);
}
@ -4734,6 +4762,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" {

View File

@ -24,6 +24,8 @@
#include "bucket_cache.h"
#include "posixDB.h"
class RGWLC;
namespace rgw { namespace sal {
class POSIXDriver;
@ -486,6 +488,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)
@ -504,6 +508,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"; };
@ -656,7 +665,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; }
@ -686,7 +695,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; }
@ -1438,4 +1447,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