summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSage Weil <sage@inktank.com>2013-09-03 13:51:31 -0700
committerSage Weil <sage@inktank.com>2013-09-03 15:48:30 -0700
commit996af2d8fd8e60bcdce8e9408249b974521de24e (patch)
treef7aa45c0c301d5c3bbf205126914ec7117619af5
parented6807919897e92144ac798b17922784f53d4608 (diff)
downloadceph-996af2d8fd8e60bcdce8e9408249b974521de24e.tar.gz
ceph_test_rados: test COPY_FROM
Signed-off-by: Sage Weil <sage@inktank.com>
-rw-r--r--src/test/osd/RadosModel.h94
-rw-r--r--src/test/osd/TestRados.cc10
2 files changed, 102 insertions, 2 deletions
diff --git a/src/test/osd/RadosModel.h b/src/test/osd/RadosModel.h
index c545d9a29b8..b9967d7af50 100644
--- a/src/test/osd/RadosModel.h
+++ b/src/test/osd/RadosModel.h
@@ -48,7 +48,8 @@ enum TestOpType {
TEST_OP_SETATTR,
TEST_OP_RMATTR,
TEST_OP_TMAPPUT,
- TEST_OP_WATCH
+ TEST_OP_WATCH,
+ TEST_OP_COPY_FROM
};
class TestWatchContext : public librados::WatchCtx {
@@ -396,6 +397,12 @@ public:
pool_obj_cont[current_snap].insert(pair<string,ObjectDesc>(oid, new_obj));
}
+ void update_object_full(const string &oid, const ObjectDesc &contents)
+ {
+ pool_obj_cont.rbegin()->second.erase(oid);
+ pool_obj_cont.rbegin()->second.insert(pair<string,ObjectDesc>(oid, contents));
+ }
+
void update_object_version(const string &oid, uint64_t version)
{
for (map<int, map<string,ObjectDesc> >::reverse_iterator i =
@@ -1378,4 +1385,89 @@ public:
}
};
+class CopyFromOp : public TestOp {
+public:
+ string oid, oid_src;
+ ObjectDesc src_value;
+ librados::ObjectWriteOperation op;
+ librados::AioCompletion *comp;
+ int snap;
+ bool done;
+ tid_t tid;
+ CopyFromOp(RadosTestContext *context,
+ const string &oid,
+ const string &oid_src,
+ TestOpStat *stat)
+ : TestOp(context, stat), oid(oid), oid_src(oid_src),
+ src_value(&context->cont_gen),
+ comp(NULL), done(false), tid(0)
+ {}
+
+ void _begin()
+ {
+ ContDesc cont;
+ {
+ Mutex::Locker l(context->state_lock);
+ cont = ContDesc(context->seq_num, context->current_snap,
+ context->seq_num, "");
+ context->oid_in_use.insert(oid);
+ context->oid_not_in_use.erase(oid);
+ context->oid_in_use.insert(oid_src);
+ context->oid_not_in_use.erase(oid_src);
+ }
+
+ // choose source snap
+ if (0 && !(rand() % 4) && !context->snaps.empty()) {
+ snap = rand_choose(context->snaps)->first;
+ } else {
+ snap = -1;
+ }
+ context->find_object(oid_src, &src_value, snap);
+
+ string src = context->prefix+oid_src;
+ op.copy_from(src.c_str(), context->io_ctx, src_value.version);
+
+ pair<TestOp*, TestOp::CallbackInfo*> *cb_arg =
+ new pair<TestOp*, TestOp::CallbackInfo*>(this,
+ new TestOp::CallbackInfo(0));
+ comp = context->rados.aio_create_completion((void*) cb_arg, &write_callback,
+ NULL);
+ tid = context->io_ctx.aio_operate(context->prefix+oid, comp, &op);
+ }
+
+ void _finish(CallbackInfo *info)
+ {
+ Mutex::Locker l(context->state_lock);
+ done = true;
+ int r;
+ assert(comp->is_complete());
+ cout << "finishing copy_from tid " << tid << " to " << context->prefix + oid << std::endl;
+ if ((r = comp->get_return_value())) {
+ if (!(r == -ENOENT && src_value.deleted())) {
+ cerr << "Error: oid " << oid << " copy_from " << oid_src << " returned error code "
+ << r << std::endl;
+ }
+ } else {
+ context->update_object_full(oid, src_value);
+ context->update_object_version(oid, comp->get_version());
+ }
+ context->oid_in_use.erase(oid);
+ context->oid_not_in_use.insert(oid);
+ context->oid_in_use.erase(oid_src);
+ context->oid_not_in_use.insert(oid_src);
+ context->kick();
+ }
+
+ bool finished()
+ {
+ return done;
+ }
+
+ string getType()
+ {
+ return "TmapPutOp";
+ }
+};
+
+
#endif
diff --git a/src/test/osd/TestRados.cc b/src/test/osd/TestRados.cc
index 6ac661c0629..1deee23aa2c 100644
--- a/src/test/osd/TestRados.cc
+++ b/src/test/osd/TestRados.cc
@@ -84,7 +84,7 @@ private:
TestOp *gen_op(RadosTestContext &context, TestOpType type)
{
- string oid;
+ string oid, oid2;
cout << "oids not in use " << context.oid_not_in_use.size() << std::endl;
assert(context.oid_not_in_use.size());
switch (type) {
@@ -152,6 +152,13 @@ private:
<< " current snap is " << context.current_snap << std::endl;
return new WatchOp(&context, oid, m_stats);
+ case TEST_OP_COPY_FROM:
+ oid = *(rand_choose(context.oid_not_in_use));
+ oid2 = *(rand_choose(context.oid_not_in_use));
+ cout << "copy_from " << oid << " from " << oid2
+ << " current snap is " << context.current_snap << std::endl;
+ return new CopyFromOp(&context, oid, oid2, m_stats);
+
default:
cerr << "Invalid op type " << type << std::endl;
assert(0);
@@ -192,6 +199,7 @@ int main(int argc, char **argv)
{ TEST_OP_RMATTR, "rmattr" },
{ TEST_OP_TMAPPUT, "tmapput" },
{ TEST_OP_WATCH, "watch" },
+ { TEST_OP_COPY_FROM, "copy_from" },
{ TEST_OP_READ /* grr */, NULL },
};