]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
ceph_test_rados: test is_dirty, undirty
authorSage Weil <sage@inktank.com>
Sat, 7 Dec 2013 22:56:10 +0000 (14:56 -0800)
committerSage Weil <sage@inktank.com>
Sat, 14 Dec 2013 00:35:57 +0000 (16:35 -0800)
Signed-off-by: Sage Weil <sage@inktank.com>
src/test/osd/Object.h
src/test/osd/RadosModel.h
src/test/osd/TestRados.cc

index 09f0a5f2e4cb057c6c10224541949bcd389ef1e2..70a1ebb02e6230e7a9aff9a417ffee0086ae6b86 100644 (file)
@@ -239,12 +239,14 @@ public:
 
 class ObjectDesc {
 public:
-  ObjectDesc(ContentsGenerator *cont_gen) : 
-    exists(false), tmap(false), version(0), layers(), cont_gen(cont_gen) {};
-  ObjectDesc(const ContDesc &init, ContentsGenerator *cont_gen) : 
-    exists(false), tmap(false), version(0), layers(), cont_gen(cont_gen) {
+  ObjectDesc(ContentsGenerator *cont_gen)
+    : exists(false), tmap(false), dirty(false),
+      version(0), layers(), cont_gen(cont_gen) {}
+  ObjectDesc(const ContDesc &init, ContentsGenerator *cont_gen)
+    : exists(false), tmap(false), dirty(false),
+      version(0), layers(), cont_gen(cont_gen) {
     layers.push_front(init);
-  };
+  }
 
   class iterator {
   public:
@@ -313,6 +315,7 @@ public:
   bufferlist header;
   bool exists;
   bool tmap;
+  bool dirty;
   bufferlist tmap_contents;
   uint64_t version;
 private:
index 0c58827cd4473aa4c2698ca90472487e8e1c4700..d55f7c0cdff7d23beafd22eb2195e1d90bf6fe0e 100644 (file)
@@ -53,7 +53,9 @@ enum TestOpType {
   TEST_OP_TMAPPUT,
   TEST_OP_WATCH,
   TEST_OP_COPY_FROM,
-  TEST_OP_HIT_SET_LIST
+  TEST_OP_HIT_SET_LIST,
+  TEST_OP_UNDIRTY,
+  TEST_OP_IS_DIRTY
 };
 
 class TestWatchContext : public librados::WatchCtx {
@@ -411,7 +413,8 @@ public:
     pool_obj_cont[current_snap].insert(pair<string,ObjectDesc>(oid, contents));
   }
 
-  void update_object_version(const string &oid, uint64_t version)
+  void update_object_version(const string &oid, uint64_t version,
+                            bool dirty = true)
   {
     for (map<int, map<string,ObjectDesc> >::reverse_iterator i = 
           pool_obj_cont.rbegin();
@@ -420,7 +423,11 @@ public:
       map<string,ObjectDesc>::iterator j = i->second.find(oid);
       if (j != i->second.end()) {
        j->second.version = version;
-       cout << __func__ << " oid " << oid << " v " << version << " " << j->second.most_recent() << std::endl;
+       j->second.dirty = dirty;
+       cout << __func__ << " oid " << oid
+            << " v " << version << " " << j->second.most_recent()
+            << " " << (dirty ? "dirty" : "clean")
+            << std::endl;
        break;
       }
     }
@@ -1610,6 +1617,138 @@ public:
   }
 };
 
+class UndirtyOp : public TestOp {
+public:
+  librados::AioCompletion *completion;
+  librados::ObjectWriteOperation op;
+  string oid;
+
+  UndirtyOp(int n,
+           RadosTestContext *context,
+           const string &oid,
+           TestOpStat *stat = 0)
+    : TestOp(n, context, stat),
+      completion(NULL),
+      oid(oid)
+  {}
+
+  void _begin()
+  {
+    context->state_lock.Lock();
+    pair<TestOp*, TestOp::CallbackInfo*> *cb_arg =
+      new pair<TestOp*, TestOp::CallbackInfo*>(this,
+                                              new TestOp::CallbackInfo(0));
+    completion = context->rados.aio_create_completion((void *) cb_arg,
+                                                     &write_callback, 0);
+
+    context->oid_in_use.insert(oid);
+    context->oid_not_in_use.erase(oid);
+    context->state_lock.Unlock();
+
+    op.undirty();
+    int r = context->io_ctx.aio_operate(context->prefix+oid, completion,
+                                       &op, 0);
+    assert(!r);
+  }
+
+  void _finish(CallbackInfo *info)
+  {
+    context->state_lock.Lock();
+    assert(!done);
+    assert(completion->is_complete());
+    context->oid_in_use.erase(oid);
+    context->oid_not_in_use.insert(oid);
+    context->update_object_version(oid, completion->get_version64(), false);
+    context->kick();
+    done = true;
+    context->state_lock.Unlock();
+  }
+
+  bool finished()
+  {
+    return done;
+  }
+
+  string getType()
+  {
+    return "UndirtyOp";
+  }
+};
+
+class IsDirtyOp : public TestOp {
+public:
+  librados::AioCompletion *completion;
+  librados::ObjectReadOperation op;
+  string oid;
+  bool dirty;
+  ObjectDesc old_value;
+
+  IsDirtyOp(int n,
+           RadosTestContext *context,
+           const string &oid,
+           TestOpStat *stat = 0)
+    : TestOp(n, context, stat),
+      completion(NULL),
+      oid(oid),
+      dirty(false),
+      old_value(&context->cont_gen)
+  {}
+
+  void _begin()
+  {
+    context->state_lock.Lock();
+
+    assert(context->find_object(oid, &old_value)); // FIXME snap?
+
+    pair<TestOp*, TestOp::CallbackInfo*> *cb_arg =
+      new pair<TestOp*, TestOp::CallbackInfo*>(this,
+                                              new TestOp::CallbackInfo(0));
+    completion = context->rados.aio_create_completion((void *) cb_arg,
+                                                     &write_callback, 0);
+
+    context->oid_in_use.insert(oid);
+    context->oid_not_in_use.erase(oid);
+    context->state_lock.Unlock();
+
+    op.is_dirty(&dirty, NULL);
+    int r = context->io_ctx.aio_operate(context->prefix+oid, completion,
+                                       &op, 0);
+    assert(!r);
+  }
+
+  void _finish(CallbackInfo *info)
+  {
+    context->state_lock.Lock();
+    assert(!done);
+    assert(completion->is_complete());
+    context->oid_in_use.erase(oid);
+    context->oid_not_in_use.insert(oid);
+
+    int r = completion->get_return_value();
+    if (r == 0) {
+      cout << num << ":  " << (dirty ? "dirty" : "clean") << std::endl;
+      assert(old_value.has_contents());
+      assert(dirty == old_value.dirty);
+    } else {
+      cout << num << ":  got " << r << std::endl;
+      assert(r == -ENOENT);
+    }
+    context->kick();
+    done = true;
+    context->state_lock.Unlock();
+  }
+
+  bool finished()
+  {
+    return done;
+  }
+
+  string getType()
+  {
+    return "IsDirtyOp";
+  }
+};
+
 
 
 #endif
index e95f43371b4d7e7a07548e88af1222712af71060..e1b17b747d6c2bf2651b651377958b0fd289cd7d 100644 (file)
@@ -169,6 +169,20 @@ private:
        return new HitSetListOp(m_op, &context, hash, m_stats);
       }
 
+    case TEST_OP_UNDIRTY:
+      {
+       oid = *(rand_choose(context.oid_not_in_use));
+       cout << "undirty oid " << oid << std::endl;
+       return new UndirtyOp(m_op, &context, oid, m_stats);
+      }
+
+    case TEST_OP_IS_DIRTY:
+      {
+       oid = *(rand_choose(context.oid_not_in_use));
+       cout << "is_dirty oid " << oid << std::endl;
+       return new IsDirtyOp(m_op, &context, oid, m_stats);
+      }
+
     default:
       cerr << "Invalid op type " << type << std::endl;
       assert(0);
@@ -211,6 +225,8 @@ int main(int argc, char **argv)
     { TEST_OP_WATCH, "watch" },
     { TEST_OP_COPY_FROM, "copy_from" },
     { TEST_OP_HIT_SET_LIST, "hit_set_list" },
+    { TEST_OP_IS_DIRTY, "is_dirty" },
+    { TEST_OP_UNDIRTY, "undirty" },
     { TEST_OP_READ /* grr */, NULL },
   };