]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph-ci.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>
Fri, 16 Jan 2026 12:09:09 +0000 (17:39 +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 ef66a891aea556e23bc07d8e15b8565c7ffa6ec3..39ad9b1c17f3d41e1ac0fa4e1b99bc370e636be1 100644 (file)
@@ -1795,4 +1795,40 @@ bool PG::check_in_progress_op(
       reqid, version, user_version, return_code, op_returns));
 }
 
+void PG::merge_from(
+    std::map<spg_t, crimson::local_shared_foreign_ptr<Ref<PG>>>& 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, src_pg] : sources) {
+    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, src_pg] : sources) {
+    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 c05b5e6900cacfb626d9f6f9f54b54ec5d786df0..d21c601b9e4d62d53ab1688b6f1b0a6c371fe901 100644 (file)
@@ -418,6 +418,12 @@ public:
   std::pair<ghobject_t, bool>
   do_delete_work(ceph::os::Transaction &t, ghobject_t _next) final;
 
+  void merge_from(
+      std::map<spg_t, crimson::local_shared_foreign_ptr<Ref<PG>>>& sources,
+      PeeringCtx &rctx,
+      unsigned split_bits,
+      const pg_merge_meta_t& last_pg_merge_meta);
+
   void clear_ready_to_merge() final {
     LOG_PREFIX(PG::clear_ready_to_merge);
     SUBDEBUGDPP(osd, "", *this);
@@ -1025,6 +1031,7 @@ private:
   bool can_discard_replica_op(const Message& m, epoch_t m_map_epoch) const;
   bool can_discard_op(const MOSDOp& m) const;
   void context_registry_on_change();
+
   bool is_missing_object(const hobject_t& soid) const {
     return get_local_missing().is_missing(soid);
   }