From: Haomai Wang Date: Fri, 21 Feb 2014 13:36:48 +0000 (+0800) Subject: Implement collection_rename interface in KeyValueStore X-Git-Tag: v0.78~130^2~8 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=ec8a4193448153c50e41358eb53c274687f9990e;p=ceph.git Implement collection_rename interface in KeyValueStore Signed-off-by: Haomai Wang --- diff --git a/src/os/KeyValueStore.cc b/src/os/KeyValueStore.cc index 65f1fd1d8262..7096cc9349b2 100644 --- a/src/os/KeyValueStore.cc +++ b/src/os/KeyValueStore.cc @@ -2518,7 +2518,57 @@ int KeyValueStore::_collection_rename(const coll_t &cid, const coll_t &ncid, { dout(10) << __func__ << " origin cid " << cid << " new cid " << ncid << dendl; - return -EOPNOTSUPP; + + StripObjectMap::StripObjectHeader *header; + + r = t.lookup_cached_header(get_coll_for_coll(), + make_ghobject_for_coll(ncid), + &header, false); + if (r == 0) { + dout(2) << __func__ << ": " << ncid << " DNE" << dendl; + return -EEXIST; + } + + int r = t.lookup_cached_header(get_coll_for_coll(), + make_ghobject_for_coll(cid), + &header, false); + if (r < 0) { + dout(2) << __func__ << ": " << cid << " DNE" << dendl; + return 0; + } + + vector objects; + ghobject_t next, current; + int move_size = 0; + while (1) { + collection_list_partial(cid, current, get_ideal_list_min(), + get_ideal_list_max(), 0, &objects, &next); + + dout(20) << __func__ << cid << "objects size: " << objects.size() + << dendl; + + if (objects.empty()) + break; + + for (vector::iterator i = objects.begin(); + i != objects.end(); ++i) { + if (i->match(bits, rem)) { + if (_collection_move_rename(cid, *i, ncid, *i, t) < 0) { + return -1; + } + move_size++; + } + } + + objects.clear(); + current = next; + } + + t.rename_buffer(*header, get_coll_for_coll(), make_ghobject_for_coll(ncid)); + + dout(10) << __func__ << " origin cid " << cid << " new cid " << ncid + << dendl; + return 0; } int KeyValueStore::list_collections(vector& ls)