summaryrefslogtreecommitdiffstats
path: root/src/cls
diff options
context:
space:
mode:
authorN Balachandran <nibalach@redhat.com>2024-07-22 07:41:17 +0200
committerN Balachandran <nibalach@redhat.com>2024-08-05 15:36:23 +0200
commit3662bc7b3dc3d335cd3a76a6248e6d5d26f3fe34 (patch)
tree4ebae6073e204a551e153bf2699641893a93f317 /src/cls
parentcls/rbd: save group snapshot creation order in a new key (diff)
downloadceph-3662bc7b3dc3d335cd3a76a6248e6d5d26f3fe34.tar.xz
ceph-3662bc7b3dc3d335cd3a76a6248e6d5d26f3fe34.zip
cls/rbd: save max group snap order
Save the last used group snap order value to speed up snapshot creation. Signed-off-by: N Balachandran <nibalach@redhat.com>
Diffstat (limited to 'src/cls')
-rw-r--r--src/cls/rbd/cls_rbd.cc40
1 files changed, 13 insertions, 27 deletions
diff --git a/src/cls/rbd/cls_rbd.cc b/src/cls/rbd/cls_rbd.cc
index 7330db8c6d3..affb986aeff 100644
--- a/src/cls/rbd/cls_rbd.cc
+++ b/src/cls/rbd/cls_rbd.cc
@@ -6899,6 +6899,7 @@ int dir_remove(cls_method_context_t hctx,
static const string RBD_GROUP_SNAP_KEY_PREFIX = "snapshot_";
static const string RBD_GROUP_SNAP_ORDER_KEY_PREFIX = "snap_order_";
+static const string RBD_GROUP_SNAP_MAX_ORDER_KEY = "snap_max_order";
std::string snap_key(const std::string &snap_id) {
ostringstream oss;
@@ -7482,37 +7483,22 @@ int group_snap_set(cls_method_context_t hctx,
return -EEXIST;
}
- std::string last_read = group::snap_order_key("");
- bool more;
uint64_t max_order = 0;
- std::map<string, bufferlist> vals;
- do {
- int r = cls_cxx_map_get_vals(hctx, last_read,
- group::RBD_GROUP_SNAP_ORDER_KEY_PREFIX,
- RBD_MAX_KEYS_READ, &vals, &more);
- if (r < 0) {
- return r;
- }
- for (auto &[key, bl] : vals) {
- auto iter = bl.cbegin();
- uint64_t order;
- try {
- decode(order, iter);
- } catch (const ceph::buffer::error &err) {
- CLS_ERR("error decoding snapshot order: %s", key.c_str());
- return -EIO;
- }
- max_order = std::max(max_order, order);
- }
- if (!vals.empty()) {
- last_read = vals.rbegin()->first;
- } else {
- ceph_assert(!more);
- }
- } while (more);
+
+ r = read_key(hctx, group::RBD_GROUP_SNAP_MAX_ORDER_KEY, &max_order);
+ if (r < 0 && r != -ENOENT) {
+ return r;
+ }
bufferlist bl;
encode(++max_order, bl);
+ r = cls_cxx_map_set_val(hctx, group::RBD_GROUP_SNAP_MAX_ORDER_KEY, &bl);
+ if (r < 0) {
+ CLS_ERR("error setting key: %s : %s",
+ group::RBD_GROUP_SNAP_MAX_ORDER_KEY.c_str(),
+ cpp_strerror(r).c_str());
+ return r;
+ }
r = cls_cxx_map_set_val(hctx, order_key, &bl);
if (r < 0) {
CLS_ERR("error setting key: %s : %s", order_key.c_str(),