]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
os/memstore: add merge_delete
authorManali Kulkarni <Manali.Kulkarni@sandisk.com>
Tue, 27 Sep 2016 14:23:54 +0000 (10:23 -0400)
committerSage Weil <sage@redhat.com>
Tue, 27 Sep 2016 15:56:44 +0000 (11:56 -0400)
Signed-off-by: Manali Kulkarni <Manali.Kulkarni@sandisk.com>
src/os/memstore/MemStore.cc
src/os/memstore/MemStore.h

index 2910a4986c5a513adc05aa886d9a3e5e565ac74b..8158259ba74fade7990c666a67d832f067aa8197 100644 (file)
@@ -840,6 +840,17 @@ void MemStore::_do_transaction(Transaction& t)
       }
       break;
 
+    case Transaction::OP_MERGE_DELETE:
+      {
+        coll_t cid = i.get_cid(op->cid);
+        ghobject_t oid = i.get_oid(op->oid);
+        ghobject_t noid = i.get_oid(op->dest_oid);
+        vector<boost::tuple<uint64_t, uint64_t, uint64_t>> move_info;
+        i.decode_move_info(move_info);
+        r = _move_ranges_destroy_src(cid, oid, noid, move_info);
+      }
+      break;
+
     case Transaction::OP_MKCOLL:
       {
         coll_t cid = i.get_cid(op->cid);
@@ -1237,6 +1248,43 @@ int MemStore::_clone_range(const coll_t& cid, const ghobject_t& oldoid,
   return len;
 }
 
+/* Move contents of src object according to move_info to base object.
+ * Once the move_info is traversed completely, delete the src object.
+ */
+int MemStore::_move_ranges_destroy_src(const coll_t& cid, const ghobject_t& srcoid,
+                          const ghobject_t& baseoid,
+                          const vector<boost::tuple<uint64_t, uint64_t, uint64_t> > move_info)
+{
+  dout(10) << __func__ << " " << cid << " "  << srcoid << " -> "  << baseoid << dendl;
+  CollectionRef c = get_collection(cid);
+  if (!c)
+    return -ENOENT;
+
+  ObjectRef oo = c->get_object(srcoid);
+  if (!oo)
+    return -ENOENT;
+  ObjectRef no = c->get_or_create_object(baseoid);
+
+  for (unsigned i = 0; i < move_info.size(); ++i) {
+      uint64_t srcoff = move_info[i].get<0>();
+      uint64_t dstoff = move_info[i].get<1>();
+      uint64_t len = move_info[i].get<2>();
+
+      if (srcoff >= oo->get_size())
+        return 0;
+      if (srcoff + len >= oo->get_size())
+        len = oo->get_size() - srcoff;
+
+      const ssize_t old_size = no->get_size();
+      no->clone(oo.get(), srcoff, len, dstoff);
+      used_bytes += (no->get_size() - old_size);
+  }
+
+// delete the src object
+  _remove(cid, srcoid);
+  return 0;
+}
+
 int MemStore::_omap_clear(const coll_t& cid, const ghobject_t &oid)
 {
   dout(10) << __func__ << " " << cid << " " << oid << dendl;
index 7864af3effcfd2a91a0c3cd7be1abe5ba8f4290a..35015fe2b70de03aa0006a94e6592a5b2f006da7 100644 (file)
@@ -216,6 +216,9 @@ private:
   int _clone_range(const coll_t& cid, const ghobject_t& oldoid,
                   const ghobject_t& newoid,
                   uint64_t srcoff, uint64_t len, uint64_t dstoff);
+  int _move_ranges_destroy_src(const coll_t& cid, const ghobject_t& oldoid,
+                  const ghobject_t& newoid,
+                  const vector<boost::tuple<uint64_t, uint64_t, uint64_t> > move_info);
   int _omap_clear(const coll_t& cid, const ghobject_t &oid);
   int _omap_setkeys(const coll_t& cid, const ghobject_t &oid, bufferlist& aset_bl);
   int _omap_rmkeys(const coll_t& cid, const ghobject_t &oid, bufferlist& keys_bl);