From: Sage Weil Date: Mon, 18 Jan 2016 16:04:41 +0000 (-0500) Subject: os/bluestore: implement open_collection X-Git-Tag: v10.0.4~153^2~6 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=e81e3c0889a09b60d1b54e89fa39be16d5b516ce;p=ceph.git os/bluestore: implement open_collection Fix up create and remove so that they poison a Collection that gets removed. Signed-off-by: Sage Weil --- diff --git a/src/os/bluestore/BlueStore.cc b/src/os/bluestore/BlueStore.cc index 304a02ac936d..69ff54c9e070 100644 --- a/src/os/bluestore/BlueStore.cc +++ b/src/os/bluestore/BlueStore.cc @@ -634,6 +634,7 @@ BlueStore::Collection::Collection(BlueStore *ns, coll_t c) : store(ns), cid(c), lock("BlueStore::Collection::lock"), + exists(true), onode_map(), enode_set(g_conf->bluestore_onode_map_size) { @@ -2329,6 +2330,11 @@ void BlueStore::_reap_collections() // --------------- // read operations +ObjectStore::CollectionHandle BlueStore::open_collection(const coll_t& cid) +{ + return _get_collection(cid); +} + bool BlueStore::exists(coll_t cid, const ghobject_t& oid) { dout(10) << __func__ << " " << cid << " " << oid << dendl; @@ -6145,6 +6151,7 @@ int BlueStore::_create_collection( r = -EEXIST; goto out; } + assert((*c)->exists); c->reset(new Collection(this, cid)); (*c)->cnode.bits = bits; coll_map[cid] = *c; @@ -6159,7 +6166,7 @@ int BlueStore::_create_collection( } int BlueStore::_remove_collection(TransContext *txc, coll_t cid, - CollectionRef *c) + CollectionRef *c) { dout(15) << __func__ << " " << cid << dendl; int r; @@ -6170,6 +6177,7 @@ int BlueStore::_remove_collection(TransContext *txc, coll_t cid, r = -ENOENT; goto out; } + assert((*c)->exists); pair next; while ((*c)->onode_map.get_next(next.first, &next)) { if (next.second->exists) { @@ -6179,6 +6187,7 @@ int BlueStore::_remove_collection(TransContext *txc, coll_t cid, } coll_map.erase(cid); txc->removed_collections.push_back(*c); + (*c)->exists = false; c->reset(); } txc->t->rmkey(PREFIX_COLL, stringify(cid)); diff --git a/src/os/bluestore/BlueStore.h b/src/os/bluestore/BlueStore.h index cfabfe6f543c..35b44eab9a8e 100644 --- a/src/os/bluestore/BlueStore.h +++ b/src/os/bluestore/BlueStore.h @@ -166,12 +166,14 @@ public: int trim(int max=-1); }; - struct Collection { + struct Collection : public CollectionImpl { BlueStore *store; coll_t cid; bluestore_cnode_t cnode; RWLock lock; + bool exists; + // cache onodes on a per-collection basis to avoid lock // contention. OnodeHashLRU onode_map; @@ -181,6 +183,10 @@ public: OnodeRef get_onode(const ghobject_t& oid, bool create); EnodeRef get_enode(uint32_t hash); + const coll_t &get_cid() override { + return cid; + } + bool contains(const ghobject_t& oid) { if (cid.is_meta()) return oid.hobj.pool == -1; @@ -194,7 +200,7 @@ public: Collection(BlueStore *ns, coll_t c); }; - typedef ceph::shared_ptr CollectionRef; + typedef boost::intrusive_ptr CollectionRef; class OmapIteratorImpl : public ObjectMap::ObjectMapIteratorImpl { CollectionRef c;