]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
RadosModel: add DeleteOp to test object deletions
authorSamuel Just <samuel.just@dreamhost.com>
Fri, 4 Nov 2011 21:55:36 +0000 (14:55 -0700)
committerSamuel Just <samuel.just@dreamhost.com>
Fri, 4 Nov 2011 21:57:58 +0000 (14:57 -0700)
Signed-off-by: Samuel Just <samuel.just@dreamhost.com>
src/test/osd/Object.h
src/test/osd/RadosModel.h
src/test/osd/TestReadWrite.cc
src/test/osd/TestSnaps.cc

index 59dd0c8b2462eaa04017cd7d5685032dd70c37f2..61f2d9998dba271025b6bc5b3ecac5b695a2a43a 100644 (file)
@@ -276,6 +276,10 @@ public:
     return iterator(*this, this->cont_gen);
   }
 
+  bool deleted() {
+    return !layers.size(); // No layers indicates missing object
+  }
+
   void update(const ContDesc &next);
   bool check(bufferlist &to_check);
   const ContDesc &most_recent();
index 9637a4562479cb5cecefbe53f90821ec6ddb689d..3eba3dbd06df967b68e350635d6bfcf2fbfb2fd3 100644 (file)
@@ -11,6 +11,7 @@
 #include <string>
 #include <string.h>
 #include <stdlib.h>
+#include <errno.h>
 #include <time.h>
 #include "Object.h"
 #include "TestOpStat.h"
@@ -183,6 +184,13 @@ public:
     pool_obj_cont[current_snap].insert(pair<string,ObjectDesc>(oid, new_obj));
   }
 
+  void remove_object(const string &oid)
+  {
+    ObjectDesc new_obj(&cont_gen);
+    pool_obj_cont[current_snap].erase(oid);
+    pool_obj_cont[current_snap].insert(pair<string,ObjectDesc>(oid, new_obj));
+  }
+
   bool find_object(const string &oid, ObjectDesc *contents, int snap = -1) const
   {
     for (map<int, map<string,ObjectDesc> >::const_reverse_iterator i = 
@@ -351,6 +359,81 @@ public:
   }
 };
 
+class DeleteOp : public TestOp {
+public:
+  string oid;
+
+  DeleteOp(RadosTestContext *context,
+          const string &oid,
+          TestOpStat *stat = 0) :
+    TestOp(context, stat), oid(oid)
+  {}
+
+  void _begin()
+  {
+    context->state_lock.Lock();
+    done = 0;
+    stringstream acc;
+
+    ObjectDesc contents(&context->cont_gen);
+    bool present = context->find_object(oid, &contents);
+    if (present) {
+      present = !contents.deleted();
+    }
+
+    context->oid_in_use.insert(oid);
+    if (context->oid_not_in_use.count(oid) != 0) {
+      context->oid_not_in_use.erase(oid);
+    }
+    context->seq_num++;
+
+    context->remove_object(oid);
+
+    vector<uint64_t> snapset(context->snaps.size());
+    int j = 0;
+    for (map<int,uint64_t>::reverse_iterator i = context->snaps.rbegin();
+        i != context->snaps.rend();
+        ++i, ++j) {
+      snapset[j] = i->second;
+    }
+    interval_set<uint64_t> ranges;
+    context->state_lock.Unlock();
+
+    int r = context->io_ctx.selfmanaged_snap_set_write_ctx(context->seq, snapset);
+    if (r) {
+      cerr << "r is " << r << " snapset is " << snapset << " seq is " << context->seq << std::endl;
+      assert(0);
+    }
+
+    r = context->io_ctx.remove(context->prefix+oid);
+    if (r && !(r == -ENOENT && !present)) {
+      cerr << "r is " << r << " while deleting " << oid << " and present is " << present << std::endl;
+      assert(0);
+    }
+
+    context->state_lock.Lock();
+    context->oid_in_use.erase(oid);
+    context->oid_not_in_use.insert(oid);
+    context->state_lock.Unlock();
+    finish();
+  }
+
+  void _finish()
+  {
+    return;
+  }
+
+  bool finished()
+  {
+    return true;
+  }
+
+  string getType()
+  {
+    return "DeleteOp";
+  }
+};
+
 class ReadOp : public TestOp {
 public:
   librados::AioCompletion *completion;
@@ -386,7 +469,8 @@ public:
       context->io_ctx.snap_set_read(context->snaps[snap]);
     }
     context->io_ctx.aio_read(context->prefix+oid, completion,
-                            &result, context->cont_gen.get_length(old_value.most_recent()), 0);
+                            &result,
+                            old_value.deleted() ? 0 : context->cont_gen.get_length(old_value.most_recent()), 0);
     if (snap >= 0) {
       context->io_ctx.snap_set_read(0);
     }
@@ -399,9 +483,12 @@ public:
     context->oid_in_use.erase(oid);
     context->oid_not_in_use.insert(oid);
     if (int err = completion->get_return_value()) {
-      cerr << "Error: oid " << oid << " read returned error code "
-          << err << std::endl;
+      if (!(err == -ENOENT && old_value.deleted())) {
+       cerr << "Error: oid " << oid << " read returned error code "
+            << err << std::endl;
+      }
     } else {
+      assert(!old_value.deleted());
       ContDesc to_check;
       bufferlist::iterator p = result.begin();
       if (!context->cont_gen.read_header(p, to_check)) {
index 400155f2ab4e4677686f64340456673dde0d4c0a..1056eb8dfb612bf00e6a0e40b61ef97264b62559 100644 (file)
@@ -52,16 +52,21 @@ struct ReadWriteGenerator : public TestOpGenerator
       nextop = 0;
       return retval;
     }
-    int switchval = rand() % 100;
+    int switchval = rand() % 110;
     if (switchval < read_percent) {
       string oid = *(rand_choose(context.oid_not_in_use));
       cout << "Reading " << oid << std::endl;
       return new ReadOp(&context, oid, 0);
-    } else {
+    } else if (switchval < 100) {
       string oid = *(rand_choose(context.oid_not_in_use));
       cout << "Writing " << oid << " current snap is "
           << context.current_snap << std::endl;
       return new WriteOp(&context, oid, 0);
+    } else {
+      string oid = *(rand_choose(context.oid_not_in_use));
+      cout << "Deleting " << oid << " current snap is "
+          << context.current_snap << std::endl;
+      return new DeleteOp(&context, oid, 0);
     }
   }
 };
index a73e3371807cb46c32e77371075010442e3aab7c..9aa2b612b16049086a21030b8ed54304864db3d3 100644 (file)
@@ -53,7 +53,7 @@ struct SnapTestGenerator : public TestOpGenerator
       return retval;
     }
                
-    int switchval = rand() % 50;
+    int switchval = rand() % 60;
     if (switchval < 20) {
       string oid = *(rand_choose(context.oid_not_in_use));
       cout << "Reading " << oid << std::endl;
@@ -73,6 +73,11 @@ struct SnapTestGenerator : public TestOpGenerator
       int snap = rand_choose(context.snaps)->first;
       cout << "RemovingSnap " << snap << std::endl;
       return new SnapRemoveOp(&context, snap, stats);
+    } else if (switchval < 57) {
+      string oid = *(rand_choose(context.oid_not_in_use));
+      cout << "Deleting " << oid << " current snap is "
+          << context.current_snap << std::endl;
+      return new DeleteOp(&context, oid, stats);
     } else {
       cout << "Snapping" << std::endl;
       return new SnapCreateOp(&context, stats);