]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
crimson/osd/pg: implement PG::merge_from
authorAishwarya Mathuria <amathuri@redhat.com>
Fri, 9 Jan 2026 07:20:44 +0000 (07:20 +0000)
committerAishwarya Mathuria <amathuri@redhat.com>
Thu, 11 Jun 2026 04:49:14 +0000 (10:19 +0530)
Add PG::merge_from to execute the merge of source PGs into a target PG.
This function builds a transaction to remove source-specifc metadata
objects and merge source collections into the target collection.

Signed-off-by: Aishwarya Mathuria <amathuri@redhat.com>
src/crimson/osd/pg.cc
src/crimson/osd/pg.h

index 837d0e0f9a350b1728324f5eb1ce2f83f3a941ab..a9506994971b845c49ea4195cdc909e5eee506f4 100644 (file)
@@ -2081,4 +2081,42 @@ PG::collect_merge_sources(std::size_t n)
   co_return sources;
 }
 
+void PG::merge_from(
+    merge_source_map_t& sources,
+    PeeringCtx &rctx,
+    unsigned split_bits,
+    const pg_merge_meta_t& last_pg_merge_meta)
+{
+  LOG_PREFIX(PG::merge_from);
+  DEBUG("target {}", get_pgid());
+
+  std::map<spg_t, PeeringState*> source_states;
+  for (auto& [pgid, entry] : sources) {
+    auto& src_pg = entry.second;
+    source_states.emplace(pgid, &src_pg->peering_state);
+  }
+
+  // Updates the target's PeeringState and stats (Synchronous)
+  peering_state.merge_from(source_states, rctx, split_bits, last_pg_merge_meta);
+
+  // We iterate through each source and move its objects into the target collection
+  for (auto& [pgid, entry] : sources) {
+    auto& src_pg = entry.second;
+    auto src_coll = src_pg->get_collection_ref()->get_cid();
+    auto dst_coll = coll_ref->get_cid();
+    DEBUG("merging source {}", pgid);
+
+    // Remove source-specific metadata objects that are no longer needed
+    // now that the collections are being collapsed.
+    rctx.transaction.remove(src_coll, src_pg->get_pgid().make_snapmapper_oid());
+    rctx.transaction.remove(src_coll, src_pg->pgmeta_oid);
+    // Move source collection into target collection.
+    rctx.transaction.merge_collection(src_coll, dst_coll, split_bits);
+  }
+
+  // Adjust the collection and snap_mapper to reflect the
+  // new, smaller PG count (reducing bitmask).
+  rctx.transaction.collection_set_bits(coll_ref->get_cid(), split_bits);
+  snap_mapper.update_bits(split_bits);
+}
 }
index 6e5e47c591c290b9251b714ac786e4794906f121..2e8238fcaf872684ad23bfc9c2a39a426f002eaf 100644 (file)
@@ -586,6 +586,11 @@ public:
   // return them and clear the rendezvous state.  Returns an empty map if
   // reset_merge_rendezvous() breaks the wait (e.g. PG stop or merge cancel).
   seastar::future<merge_source_map_t> collect_merge_sources(std::size_t n);
+  void merge_from(
+      merge_source_map_t& sources,
+      PeeringCtx &rctx,
+      unsigned split_bits,
+      const pg_merge_meta_t& last_pg_merge_meta);
 
   // Drop in-flight handoffs and reset the semaphore.  Call on PG stop or
   // after Seastore cross-shard cancel so a failed try cannot leave stale