]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
neorados: Improve `cmp_omap` argument structure
authorAdam Emerson <aemerson@redhat.com>
Thu, 10 Aug 2023 03:59:34 +0000 (23:59 -0400)
committerAdam Emerson <aemerson@redhat.com>
Thu, 14 Sep 2023 21:48:00 +0000 (17:48 -0400)
A map from strings to value/op pairs is a bit much and a bit annoying
for what's essentially a list of assertions. Just use a vector.

Also put op in the middle so it matches `cmpxattr`.

Signed-off-by: Adam Emerson <aemerson@redhat.com>
src/include/neorados/RADOS.hpp
src/neorados/RADOS.cc

index 4c8251a16661bb40310c816c34711f7393aa30cd..3f86d4fc25f5e11ae36bc23243f69f80a6d8a14a 100644 (file)
@@ -202,6 +202,12 @@ enum class cmp_op : std::uint8_t {
   lte = 6
 };
 
+struct cmp_assertion {
+  std::string attr;
+  cmp_op op;
+  ceph::buffer::list bl;
+};
+
 namespace alloc_hint {
 enum alloc_hint_t {
   sequential_write = 1,
@@ -308,9 +314,7 @@ public:
   void cmpxattr(std::string_view name, cmp_op op, std::uint64_t val);
   void assert_version(uint64_t ver);
   void assert_exists();
-  void cmp_omap(const boost::container::flat_map<std::string,
-                                                std::pair<ceph::buffer::list,
-                                                          cmp_op>>& assertions);
+  void cmp_omap(const std::vector<cmp_assertion>& assertions);
 
   void exec(std::string_view cls, std::string_view method,
            const ceph::buffer::list& inbl,
@@ -585,15 +589,11 @@ public:
     return std::move(*this);
   }
 
-  ReadOp& cmp_omap(
-    const boost::container::flat_map<
-      std::string, std::pair<ceph::buffer::list, cmp_op>>& assertions) & {
+  ReadOp& cmp_omap(const std::vector<cmp_assertion>& assertions) & {
     Op::cmp_omap(assertions);
     return *this;
   }
-  ReadOp&& cmp_omap(
-    const boost::container::flat_map<
-      std::string, std::pair<ceph::buffer::list, cmp_op>>& assertions) && {
+  ReadOp&& cmp_omap(const std::vector<cmp_assertion>& assertions) && {
     Op::cmp_omap(assertions);
     return std::move(*this);
   }
@@ -969,15 +969,11 @@ public:
     return std::move(*this);
   }
 
-  WriteOp& cmp_omap(
-    const boost::container::flat_map<
-      std::string, std::pair<ceph::buffer::list, cmp_op>>& assertions) & {
+  WriteOp& cmp_omap(const std::vector<cmp_assertion>& assertions) & {
     Op::cmp_omap(assertions);
     return *this;
   }
-  WriteOp&& cmp_omap(
-    const boost::container::flat_map<
-      std::string, std::pair<ceph::buffer::list, cmp_op>>& assertions) && {
+  WriteOp&& cmp_omap(const std::vector<cmp_assertion>& assertions) && {
     Op::cmp_omap(assertions);
     return std::move(*this);
   }
index 082378ff78dff41012d4da4d2dfe8f34e7133e99..d78b7cf71a16a561f4ce3ca9118661c55e7c7377 100644 (file)
@@ -483,13 +483,10 @@ void Op::assert_exists() {
     static_cast<ceph::real_time*>(nullptr),
     static_cast<bs::error_code*>(nullptr));
 }
-void Op::cmp_omap(const bc::flat_map<
-                 std::string, std::pair<cb::list,
-                 cmp_op>>& assertions) {
+void Op::cmp_omap(const std::vector<cmp_assertion>& assertions) {
   buffer::list bl;
   encode(uint32_t(assertions.size()), bl);
-  for (const auto& [key, assertion] : assertions) {
-    const auto& [value, op] = assertion;
+  for (const auto& [key, op, value] : assertions) {
     encode(key, bl);
     encode(value, bl);
     encode(int(op), bl);