From 7a11a43efad3f0bf5d4115d0f595cd0827e52c44 Mon Sep 17 00:00:00 2001 From: Adam Emerson Date: Fri, 10 May 2024 22:27:25 -0400 Subject: [PATCH] rgw: Add neorados functions to RGWObjVersionTracker Signed-off-by: Adam Emerson --- src/rgw/driver/rados/rgw_rados.cc | 29 +++++++++++++++++++++++++++++ src/rgw/rgw_common.h | 19 +++++++++++++++++++ 2 files changed, 48 insertions(+) diff --git a/src/rgw/driver/rados/rgw_rados.cc b/src/rgw/driver/rados/rgw_rados.cc index 162387db5d0..76fec9236dc 100644 --- a/src/rgw/driver/rados/rgw_rados.cc +++ b/src/rgw/driver/rados/rgw_rados.cc @@ -46,6 +46,8 @@ #include "cls/version/cls_version_client.h" #include "osd/osd_types.h" +#include "neorados/cls/version.h" + #include "rgw_tools.h" #include "rgw_coroutine.h" #include "rgw_compression.h" @@ -169,6 +171,33 @@ void RGWObjVersionTracker::prepare_op_for_read(ObjectReadOperation* op) cls_version_read(*op, &read_version); } +void RGWObjVersionTracker::prepare_read(neorados::ReadOp& op) { + namespace version = neorados::cls::version; + auto check_objv = version_for_check(); + + if (check_objv) { + op.exec(version::check(*check_objv, VER_COND_EQ)); + } + + op.exec(version::read(&read_version)); +} + +void RGWObjVersionTracker::prepare_write(neorados::WriteOp& op) { + namespace version = neorados::cls::version; + auto check_objv = version_for_check(); + auto modify_version = version_for_write(); + + if (check_objv) { + op.exec(version::check(*check_objv, VER_COND_EQ)); + } + + if (modify_version) { + op.exec(version::set(*modify_version)); + } else { + op.exec(version::inc()); + } +} + void RGWObjVersionTracker::prepare_op_for_write(ObjectWriteOperation *op) { obj_version* check_objv = version_for_check(); diff --git a/src/rgw/rgw_common.h b/src/rgw/rgw_common.h index 9c50d4a04f1..a7d3bbef624 100644 --- a/src/rgw/rgw_common.h +++ b/src/rgw/rgw_common.h @@ -27,6 +27,8 @@ #include #include "common/dout_fmt.h" +#include "include/neorados/RADOS.hpp" + #include "common/ceph_crypto.h" #include "common/random_string.h" #include "common/tracer.h" @@ -980,6 +982,14 @@ struct RGWObjVersionTracker { /// This function is defined in `rgw_rados.cc` rather than `rgw_common.cc`. void prepare_op_for_read(librados::ObjectReadOperation* op); + /// This function is to be called on any read operation. If we have + /// a non-empty `read_version`, assert on the OSD that the object + /// has the same version. Also reads the version into `read_version`. + /// + /// This function is defined in `rgw_rados.cc` rather than + /// `rgw_common.cc`. + void prepare_read(neorados::ReadOp& op); + /// This function is to be called on any write operation. If we have /// a non-empty read operation, assert on the OSD that the object /// has the same version. If we have a non-empty `write_version`, @@ -989,6 +999,15 @@ struct RGWObjVersionTracker { /// `rgw_common.cc`. void prepare_op_for_write(librados::ObjectWriteOperation* op); + /// This function is to be called on any write operation. If we have + /// a non-empty read operation, assert on the OSD that the object + /// has the same version. If we have a non-empty `write_version`, + /// set the object to it. Otherwise increment the version on the OSD. + /// + /// This function is defined in `rgw_rados.cc` rather than + /// `rgw_common.cc`. + void prepare_write(neorados::WriteOp& op); + /// This function is to be called after the completion of any write /// operation on which `prepare_op_for_write` was called. If we did /// not set the write version explicitly, it increments -- 2.39.5