]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
os/: add try_rename
authorSamuel Just <sjust@redhat.com>
Thu, 28 Jan 2016 22:11:42 +0000 (14:11 -0800)
committerSamuel Just <sjust@redhat.com>
Thu, 25 Feb 2016 19:13:55 +0000 (11:13 -0800)
Similar to collection_move_rename, except we ignore ENOENT and
don't allow different collections.

Signed-off-by: Samuel Just <sjust@redhat.com>
src/os/ObjectStore.h
src/os/Transaction.cc
src/os/bluestore/BlueStore.cc
src/os/filestore/FileStore.cc
src/os/filestore/FileStore.h
src/os/kstore/KStore.cc
src/os/memstore/MemStore.cc
src/tracing/objectstore.tp

index b0b952452ae8bcbcd4fe5d4417708b58e0177eca..95d00416d9de4520416ca615dfa82988386d9f9b 100644 (file)
@@ -408,6 +408,8 @@ public:
 
       OP_SETALLOCHINT = 39,  // cid, oid, object_size, write_size
       OP_COLL_HINT = 40, // cid, type, bl
+
+      OP_TRY_RENAME = 41,   // oldcid, oldoid, newoid
     };
 
     // Transaction hint type
@@ -1415,6 +1417,23 @@ public:
       }
       data.ops++;
     }
+    void try_rename(coll_t cid, const ghobject_t& oldoid,
+                    const ghobject_t& oid) {
+      if (use_tbl) {
+        __u32 op = OP_TRY_RENAME;
+        ::encode(op, tbl);
+        ::encode(cid, tbl);
+        ::encode(oldoid, tbl);
+        ::encode(oid, tbl);
+      } else {
+        Op* _op = _get_next_op();
+        _op->op = OP_TRY_RENAME;
+        _op->cid = _get_coll_id(cid);
+        _op->oid = _get_object_id(oldoid);
+        _op->dest_oid = _get_object_id(oid);
+      }
+      data.ops++;
+    }
 
     // NOTE: Collection attr operations are all DEPRECATED.  new
     // backends need not implement these at all.
index dc8b1ab8acd4edfbed8f853dfda684827318c9f3..a72ab7c701e33e182400b13ce774d2f40e03660d 100644 (file)
@@ -323,6 +323,20 @@ void ObjectStore::Transaction::_build_actions_from_tbl()
       }
       break;
 
+    case Transaction::OP_TRY_RENAME:
+      {
+       coll_t cid;
+       ghobject_t oldoid;
+       ghobject_t newoid;
+
+       ::decode(cid, p);
+       ::decode(oldoid, p);
+       ::decode(newoid, p);
+
+       try_rename(cid, oldoid, newoid);
+      }
+      break;
+
     case Transaction::OP_COLL_SETATTR:
       {
        coll_t cid;
index 31f2bc4da2186f3020e731388d718986755de70d..baf4e06dc9efa0a17e03a02a9613fddb7fb2dbf7 100644 (file)
@@ -4490,6 +4490,17 @@ int BlueStore::_txc_add_transaction(TransContext *txc, Transaction *t)
       }
       break;
 
+    case Transaction::OP_TRY_RENAME:
+      {
+       const ghobject_t& noid = i.get_oid(op->dest_oid);
+       OnodeRef no = c->get_onode(noid, true);
+       r = _rename(txc, c, o, no, noid);
+       if (r == -ENOENT)
+         r = 0;
+       o.reset();
+      }
+      break;
+
     case Transaction::OP_OMAP_CLEAR:
       {
        r = _omap_clear(txc, c, o);
index 548b1d926f75b2285bd5708c9e0ce9e45d7fe23c..6fc62bb7e64df0456cfdd9a648f49e53037d4d32 100644 (file)
@@ -2660,6 +2660,20 @@ void FileStore::_do_transaction(
       }
       break;
 
+    case Transaction::OP_TRY_RENAME:
+      {
+        coll_t oldcid = i.get_cid(op->cid);
+       coll_t newcid = oldcid;
+        ghobject_t oldoid = i.get_oid(op->oid);
+        ghobject_t newoid = i.get_oid(op->dest_oid);
+       _kludge_temp_object_collection(oldcid, oldoid);
+       _kludge_temp_object_collection(newcid, newoid);
+        tracepoint(objectstore, coll_try_rename_enter);
+        r = _collection_move_rename(oldcid, oldoid, newcid, newoid, spos, true);
+        tracepoint(objectstore, coll_try_rename_exit, r);
+      }
+      break;
+
     case Transaction::OP_COLL_SETATTR:
       {
         coll_t cid = i.get_cid(op->cid);
@@ -5071,7 +5085,8 @@ int FileStore::_collection_add(const coll_t& c, const coll_t& oldcid, const ghob
 
 int FileStore::_collection_move_rename(const coll_t& oldcid, const ghobject_t& oldoid,
                                       coll_t c, const ghobject_t& o,
-                                      const SequencerPosition& spos)
+                                      const SequencerPosition& spos,
+                                      bool allow_enoent)
 {
   dout(15) << __func__ << " " << c << "/" << o << " from " << oldcid << "/" << oldoid << dendl;
   int r = 0;
@@ -5103,9 +5118,16 @@ int FileStore::_collection_move_rename(const coll_t& oldcid, const ghobject_t& o
     if (r < 0) {
       // the source collection/object does not exist. If we are replaying, we
       // should be safe, so just return 0 and move on.
-      assert(replaying);
-      dout(10) << __func__ << " " << c << "/" << o << " from "
-              << oldcid << "/" << oldoid << " (dne, continue replay) " << dendl;
+      if (replaying) {
+       dout(10) << __func__ << " " << c << "/" << o << " from "
+                << oldcid << "/" << oldoid << " (dne, continue replay) " << dendl;
+      } else if (allow_enoent) {
+       dout(10) << __func__ << " " << c << "/" << o << " from "
+                << oldcid << "/" << oldoid << " (dne, ignoring enoent)"
+                << dendl;
+      } else {
+       assert(0 == "ERROR: source must exist");
+      }
       return 0;
     }
     if (dstcmp > 0) {      // if dstcmp == 0 the guard already says "in-progress"
index 3e4e11ff1155aef1daf9e50618f393d25c78d10e..a9a67dc7c74a79389a171bc5d241d0139a401bdd 100644 (file)
@@ -675,7 +675,8 @@ public:
                      const SequencerPosition& spos);
   int _collection_move_rename(const coll_t& oldcid, const ghobject_t& oldoid,
                              coll_t c, const ghobject_t& o,
-                             const SequencerPosition& spos);
+                             const SequencerPosition& spos,
+                             bool ignore_enoent = false);
 
   int _set_alloc_hint(const coll_t& cid, const ghobject_t& oid,
                       uint64_t expected_object_size,
index 729cd14edbdf88351423014d88b8e7e32d15a859..a4aa268a12bbd040e83dcde7d021d57191f20ebd 100644 (file)
@@ -2671,6 +2671,17 @@ int KStore::_txc_add_transaction(TransContext *txc, Transaction *t)
       }
       break;
 
+    case Transaction::OP_TRY_RENAME:
+      {
+       const ghobject_t& noid = i.get_oid(op->dest_oid);
+       OnodeRef no = c->get_onode(noid, true);
+       r = _rename(txc, c, o, no, noid);
+       if (r == -ENOENT)
+         r = 0;
+       o.reset();
+      }
+      break;
+
     case Transaction::OP_OMAP_CLEAR:
       {
        r = _omap_clear(txc, c, o);
index 68972dd51dbd7b5a0b448301025e4ce4a90ca46e..345ac20d9817e38e2c40f4f4d27d0947043ec3dc 100644 (file)
@@ -860,6 +860,19 @@ void MemStore::_do_transaction(Transaction& t)
         coll_t newcid = i.get_cid(op->dest_cid);
         ghobject_t newoid = i.get_oid(op->dest_oid);
        r = _collection_move_rename(oldcid, oldoid, newcid, newoid);
+       if (r == -ENOENT)
+         r = 0;
+      }
+      break;
+
+    case Transaction::OP_TRY_RENAME:
+      {
+        coll_t cid = i.get_cid(op->cid);
+        ghobject_t oldoid = i.get_oid(op->oid);
+        ghobject_t newoid = i.get_oid(op->dest_oid);
+       r = _collection_move_rename(cid, oldoid, cid, newoid);
+       if (r == -ENOENT)
+         r = 0;
       }
       break;
 
index 9c8108306ccf62a26388d82a8453711b0bb1f954..d9f76e273d77b1af1c0bbb35116c4e8602f31c3f 100644 (file)
@@ -520,6 +520,19 @@ TRACEPOINT_EVENT(objectstore, coll_move_rename_exit,
     )
 )
 
+TRACEPOINT_EVENT(objectstore, coll_try_rename_enter,
+    TP_ARGS(),
+    TP_FIELDS()
+)
+
+TRACEPOINT_EVENT(objectstore, coll_try_rename_exit,
+    TP_ARGS(
+        int, retval),
+    TP_FIELDS(
+        ctf_integer(int, retval, retval)
+    )
+)
+
 TRACEPOINT_EVENT(objectstore, coll_remove_enter,
     TP_ARGS(
         const char *, osr_name),