]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
crimson/os/cyanstore: implement OP_MERGE_COLLECTION
authorKefu Chai <k.chai@proxmox.com>
Tue, 5 May 2026 06:53:48 +0000 (14:53 +0800)
committerKefu Chai <k.chai@proxmox.com>
Tue, 5 May 2026 11:45:58 +0000 (19:45 +0800)
Add a handler for Transaction::OP_MERGE_COLLECTION in CyanStore's
do_transaction_no_callbacks() and the corresponding _merge_collection()
implementation. Moves all objects from the source collection into the
destination, updates the destination's split_bits, and removes the
source collection from the store's collection map.

Signed-off-by: Kefu Chai <k.chai@proxmox.com>
src/crimson/os/cyanstore/cyan_store.cc
src/crimson/os/cyanstore/cyan_store.h

index 7d5cfa46f5d77db1b454ded0d2e96a2fc75d45e7..be2649e52e7000934274559c410e0cadf8b113c1 100644 (file)
@@ -675,6 +675,13 @@ seastar::future<> CyanStore::Shard::do_transaction_no_callbacks(
         r = _remove_collection(cid);
       }
       break;
+      case Transaction::OP_MERGE_COLLECTION:
+      {
+        coll_t cid = i.get_cid(op->cid);
+        coll_t dest_cid = i.get_cid(op->dest_cid);
+        r = _merge_collection(cid, dest_cid, op->split_bits);
+      }
+      break;
       case Transaction::OP_SETALLOCHINT:
       {
         r = 0;
@@ -1044,6 +1051,29 @@ int CyanStore::Shard::_create_collection(const coll_t& cid, int bits)
   return 0;
 }
 
+int CyanStore::Shard::_merge_collection(
+  const coll_t& cid,
+  const coll_t& dest_cid,
+  int bits)
+{
+  logger().debug("{} cid={} dest_cid={} bits={}", __func__, cid, dest_cid, bits);
+  auto src = _get_collection(cid);
+  if (!src) {
+    return -ENOENT;
+  }
+  auto dest = _get_collection(dest_cid);
+  if (!dest) {
+    return -ENOENT;
+  }
+  for (auto& [oid, obj] : src->object_map) {
+    dest->object_map.emplace(oid, obj);
+    dest->object_hash.emplace(oid, obj);
+  }
+  dest->bits = bits;
+  coll_map.erase(cid);
+  return 0;
+}
+
 int CyanStore::Shard::_remove_collection(const coll_t& cid)
 {
   logger().debug("{} cid={}", __func__, cid);
index 06e1b9fb77cacf72b73432e833a3b52815b5844a..e7f0f1b5d8a0f330fa028daff66de28ffaad1bd8 100644 (file)
@@ -182,6 +182,7 @@ public:
                 std::string_view name);
     int _rm_attrs(const coll_t& cid, const ghobject_t& oid);
     int _create_collection(const coll_t& cid, int bits);
+    int _merge_collection(const coll_t& cid, const coll_t& dest_cid, int bits);
     int _remove_collection(const coll_t& cid);
     boost::intrusive_ptr<Collection> _get_collection(const coll_t& cid);