From: Samuel Just Date: Thu, 28 Jan 2016 22:11:42 +0000 (-0800) Subject: os/: add try_rename X-Git-Tag: v10.1.0~277^2~2 X-Git-Url: http://git.apps.os.sepia.ceph.com/?a=commitdiff_plain;h=b8e584313659f2a41214fb52783f584c18940dc9;p=ceph.git os/: add try_rename Similar to collection_move_rename, except we ignore ENOENT and don't allow different collections. Signed-off-by: Samuel Just --- diff --git a/src/os/ObjectStore.h b/src/os/ObjectStore.h index b0b952452ae8b..95d00416d9de4 100644 --- a/src/os/ObjectStore.h +++ b/src/os/ObjectStore.h @@ -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. diff --git a/src/os/Transaction.cc b/src/os/Transaction.cc index dc8b1ab8acd4e..a72ab7c701e33 100644 --- a/src/os/Transaction.cc +++ b/src/os/Transaction.cc @@ -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; diff --git a/src/os/bluestore/BlueStore.cc b/src/os/bluestore/BlueStore.cc index 31f2bc4da2186..baf4e06dc9efa 100644 --- a/src/os/bluestore/BlueStore.cc +++ b/src/os/bluestore/BlueStore.cc @@ -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); diff --git a/src/os/filestore/FileStore.cc b/src/os/filestore/FileStore.cc index 548b1d926f75b..6fc62bb7e64df 100644 --- a/src/os/filestore/FileStore.cc +++ b/src/os/filestore/FileStore.cc @@ -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" diff --git a/src/os/filestore/FileStore.h b/src/os/filestore/FileStore.h index 3e4e11ff1155a..a9a67dc7c74a7 100644 --- a/src/os/filestore/FileStore.h +++ b/src/os/filestore/FileStore.h @@ -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, diff --git a/src/os/kstore/KStore.cc b/src/os/kstore/KStore.cc index 729cd14edbdf8..a4aa268a12bbd 100644 --- a/src/os/kstore/KStore.cc +++ b/src/os/kstore/KStore.cc @@ -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); diff --git a/src/os/memstore/MemStore.cc b/src/os/memstore/MemStore.cc index 68972dd51dbd7..345ac20d9817e 100644 --- a/src/os/memstore/MemStore.cc +++ b/src/os/memstore/MemStore.cc @@ -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; diff --git a/src/tracing/objectstore.tp b/src/tracing/objectstore.tp index 9c8108306ccf6..d9f76e273d77b 100644 --- a/src/tracing/objectstore.tp +++ b/src/tracing/objectstore.tp @@ -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),