]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
ObjectCacher: keep track of outstanding reads on an object
authorJosh Durgin <josh.durgin@inktank.com>
Sat, 9 Mar 2013 01:49:27 +0000 (17:49 -0800)
committerJosh Durgin <josh.durgin@inktank.com>
Mon, 11 Mar 2013 22:44:32 +0000 (15:44 -0700)
Reads always use C_ReadFinish as a callback (and they are the only
user of this callback). Keep an xlist of these for each object, so
they can remove themselves as they finish. To prevent racing requests
and with discard removing objects from the cache, clear the xlist in
the object destructor, so if the Object is still valid the set_item
will still be on the list.

Make the ObjectCacher constructor take an Object* instead of the pool
and object id, which are derived from the Object* anyway.

Signed-off-by: Josh Durgin <josh.durgin@inktank.com>
src/osdc/ObjectCacher.cc
src/osdc/ObjectCacher.h

index 8d9269314f8e4f39ee4d0538a0e3cc06942d76db..c583b4c2491671b910089d4c2774afe84dfea973 100644 (file)
@@ -594,8 +594,8 @@ void ObjectCacher::bh_read(BufferHead *bh)
   mark_rx(bh);
 
   // finisher
-  C_ReadFinish *onfinish = new C_ReadFinish(this, bh->ob->oloc.pool,
-                                            bh->ob->get_soid(), bh->start(), bh->length());
+  C_ReadFinish *onfinish = new C_ReadFinish(this, bh->ob,
+                                           bh->start(), bh->length());
 
   ObjectSet *oset = bh->ob->oset;
 
index 5200dd90209ee302478dfb58353e21129f149aa3..a49afe44ad7efa962e10d1323031329cace3db99 100644 (file)
@@ -45,6 +45,7 @@ class ObjectCacher {
   CephContext *cct;
   class Object;
   class ObjectSet;
+  class C_ReadFinish;
 
   typedef void (*flush_set_callback_t) (void *p, ObjectSet *oset);
 
@@ -182,6 +183,7 @@ class ObjectCacher {
     int dirty_or_tx;
 
     map< tid_t, list<Context*> > waitfor_commit;
+    xlist<C_ReadFinish*> reads;
 
   public:
     Object(const Object& other);
@@ -198,6 +200,7 @@ class ObjectCacher {
       os->objects.push_back(&set_item);
     }
     ~Object() {
+      reads.clear();
       assert(ref == 0);
       assert(data.empty());
       assert(dirty_or_tx == 0);
@@ -453,12 +456,21 @@ class ObjectCacher {
     sobject_t oid;
     loff_t start;
     uint64_t length;
+    xlist<C_ReadFinish*>::item set_item;
+
   public:
     bufferlist bl;
-    C_ReadFinish(ObjectCacher *c, int _poolid, sobject_t o, loff_t s, uint64_t l) :
-      oc(c), poolid(_poolid), oid(o), start(s), length(l) {}
+    C_ReadFinish(ObjectCacher *c, Object *ob, loff_t s, uint64_t l) :
+      oc(c), poolid(ob->oloc.pool), oid(ob->get_soid()), start(s), length(l),
+      set_item(this) {
+      ob->reads.push_back(&set_item);
+    }
+
     void finish(int r) {
       oc->bh_read_finish(poolid, oid, start, length, bl, r);
+      // object destructor clears the list
+      if (set_item.is_on_list())
+       set_item.remove_myself();
     }
   };