]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
ceph_test_rados: hit hit_set_{list,get} rados operations
authorSage Weil <sage@inktank.com>
Wed, 4 Dec 2013 17:39:26 +0000 (09:39 -0800)
committerSage Weil <sage@inktank.com>
Fri, 6 Dec 2013 22:37:28 +0000 (14:37 -0800)
This will do a list, and then get a random HitSet.

Signed-off-by: Sage Weil <sage@inktank.com>
src/test/osd/RadosModel.h
src/test/osd/TestRados.cc

index 80bcf00a6d785a38900d15532f5b8fdbd0f2aba4..e1114d4cd65e460b1e5ec973e20269718721508b 100644 (file)
@@ -19,6 +19,7 @@
 #include "TestOpStat.h"
 #include "test/librados/test.h"
 #include "common/sharedptr_registry.hpp"
+#include "osd/HitSet.h"
 
 #ifndef RADOSMODEL_H
 #define RADOSMODEL_H
@@ -51,7 +52,8 @@ enum TestOpType {
   TEST_OP_RMATTR,
   TEST_OP_TMAPPUT,
   TEST_OP_WATCH,
-  TEST_OP_COPY_FROM
+  TEST_OP_COPY_FROM,
+  TEST_OP_HIT_SET_LIST
 };
 
 class TestWatchContext : public librados::WatchCtx {
@@ -1357,6 +1359,7 @@ public:
       roll_back_to,
       roll_back_to);
 
+
     cout << "rollback oid " << oid << " to " << roll_back_to << std::endl;
 
     context->roll_back(oid, roll_back_to);
@@ -1531,5 +1534,82 @@ public:
   }
 };
 
+class HitSetListOp : public TestOp {
+  bool done;
+  librados::AioCompletion *comp1, *comp2;
+  uint32_t hash;
+  std::list< std::pair<time_t, time_t> > ls;
+  bufferlist bl;
+
+public:
+  HitSetListOp(int n,
+              RadosTestContext *context,
+              uint32_t hash,
+              TestOpStat *stat = 0)
+    : TestOp(n, context, stat),
+      done(false), comp1(NULL), comp2(NULL),
+      hash(hash)
+  {}
+
+  void _begin()
+  {
+    pair<TestOp*, TestOp::CallbackInfo*> *cb_arg =
+      new pair<TestOp*, TestOp::CallbackInfo*>(this,
+                                              new TestOp::CallbackInfo(0));
+    comp1 = context->rados.aio_create_completion((void*) cb_arg, &write_callback,
+                                                NULL);
+    int r = context->io_ctx.hit_set_list(hash, comp1, &ls);
+    assert(r == 0);
+  }
+
+  void _finish(CallbackInfo *info) {
+    Mutex::Locker l(context->state_lock);
+    if (!comp2) {
+      if (ls.empty()) {
+       cerr << num << ": no hitsets" << std::endl;
+       done = true;
+      } else {
+       cerr << num << ": hitsets are " << ls << std::endl;
+       int r = rand() % ls.size();
+       std::list<pair<time_t,time_t> >::iterator p = ls.begin();
+       while (r--)
+         ++p;
+       pair<TestOp*, TestOp::CallbackInfo*> *cb_arg =
+         new pair<TestOp*, TestOp::CallbackInfo*>(this,
+                                                  new TestOp::CallbackInfo(0));
+       comp2 = context->rados.aio_create_completion((void*) cb_arg, &write_callback,
+                                                    NULL);
+       r = context->io_ctx.hit_set_get(hash, comp2, p->second, &bl);
+       assert(r == 0);
+      }
+    } else {
+      int r = comp2->get_return_value();
+      if (r == 0) {
+       HitSet hitset;
+       bufferlist::iterator p = bl.begin();
+       ::decode(hitset, p);
+       cout << num << ": got hitset of type " << hitset.get_type_name()
+            << " size " << bl.length()
+            << std::endl;
+      } else {
+       // FIXME: we could verify that we did in fact race with a trim...
+       assert(r == -ENOENT);
+      }
+      done = true;
+    }
+
+    context->kick();
+  }
+
+  bool finished() {
+    return done;
+  }
+
+  string getType() {
+    return "HitSetListOp";
+  }
+};
+
+
 
 #endif
index 20a4f8209cc55edc12bec980f2d232b68fa50ff4..e95f43371b4d7e7a07548e88af1222712af71060 100644 (file)
@@ -162,6 +162,13 @@ private:
           << " current snap is " << context.current_snap << std::endl;
       return new CopyFromOp(m_op, &context, oid, oid2, m_stats);
 
+    case TEST_OP_HIT_SET_LIST:
+      {
+       uint32_t hash = rjhash32(rand());
+       cout << "hit_set_list " << hash << std::endl;
+       return new HitSetListOp(m_op, &context, hash, m_stats);
+      }
+
     default:
       cerr << "Invalid op type " << type << std::endl;
       assert(0);
@@ -203,6 +210,7 @@ int main(int argc, char **argv)
     { TEST_OP_TMAPPUT, "tmapput" },
     { TEST_OP_WATCH, "watch" },
     { TEST_OP_COPY_FROM, "copy_from" },
+    { TEST_OP_HIT_SET_LIST, "hit_set_list" },
     { TEST_OP_READ /* grr */, NULL },
   };