Skip to content

Commit

Permalink
neorados: Improve cmp_omap argument structure
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
adamemerson committed Dec 7, 2023
1 parent 529674a commit 6fab415
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 20 deletions.
26 changes: 11 additions & 15 deletions src/include/neorados/RADOS.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,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,
Expand Down Expand Up @@ -309,9 +315,7 @@ class Op {
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,
Expand Down Expand Up @@ -586,15 +590,11 @@ class ReadOp final : public Op {
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);
}
Expand Down Expand Up @@ -970,15 +970,11 @@ class WriteOp final : public Op {
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);
}
Expand Down
7 changes: 2 additions & 5 deletions src/neorados/RADOS.cc
Original file line number Diff line number Diff line change
Expand Up @@ -444,13 +444,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);
Expand Down

0 comments on commit 6fab415

Please sign in to comment.