diff --git a/src/.gitignore b/src/.gitignore index f0c358f54c7..879d075f81d 100644 --- a/src/.gitignore +++ b/src/.gitignore @@ -42,6 +42,7 @@ /test_librados_build /test_librgw_build /testsnaps +/testreadwrite /test_stress_watch /multi_stress_watch /test_store diff --git a/src/Makefile.am b/src/Makefile.am index 102f31617de..b70cf190556 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -185,6 +185,10 @@ testsnaps_SOURCES = test/osd/TestSnaps.cc test/osd/TestOpStat.cc test/osd/Object testsnaps_LDADD = librados.la $(LIBGLOBAL_LDA) bin_DEBUGPROGRAMS += testsnaps +testreadwrite_SOURCES = test/osd/TestReadWrite.cc test/osd/TestOpStat.cc test/osd/Object.cc test/osd/RadosModel.cc +testreadwrite_LDADD = librados.la $(LIBGLOBAL_LDA) +bin_DEBUGPROGRAMS += testreadwrite + multi_stress_watch_SOURCES = test/multi_stress_watch.cc test/rados-api/test.cc multi_stress_watch_LDADD = librados.la $(LIBGLOBAL_LDA) bin_DEBUGPROGRAMS += multi_stress_watch diff --git a/src/test/osd/TestReadWrite.cc b/src/test/osd/TestReadWrite.cc new file mode 100644 index 00000000000..400155f2ab4 --- /dev/null +++ b/src/test/osd/TestReadWrite.cc @@ -0,0 +1,114 @@ +// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- +#include "common/Mutex.h" +#include "common/Cond.h" + +#include +#include +#include +#include +#include +#include +#include +#include + +#include "test/osd/RadosModel.h" + +using namespace std; + +TestOp::~TestOp() +{ +} + +TestOpGenerator::~TestOpGenerator() +{ +} + +struct ReadWriteGenerator : public TestOpGenerator +{ + TestOp *nextop; + int op; + int ops; + int objects; + int read_percent; + ReadWriteGenerator(int ops, int objects, int read_percent) : + nextop(0), op(0), ops(ops), objects(objects), read_percent(read_percent) + {} + + + TestOp *next(RadosTestContext &context) + { + op++; + if (op <= objects) { + stringstream oid; + oid << op; + cout << "Writing initial " << oid.str() << std::endl; + return new WriteOp(&context, oid.str()); + } else if (op >= ops) { + return 0; + } + + if (nextop) { + TestOp *retval = nextop; + nextop = 0; + return retval; + } + int switchval = rand() % 100; + 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 { + 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); + } + } +}; + +int main(int argc, char **argv) +{ + int ops = 10000; + int objects = 500; + int read_percent = 50; + int max_in_flight = 16; + int size = 4000000; // 4 MB + if (argc > 1) { + ops = atoi(argv[1]); + } + + if (argc > 2) { + objects = atoi(argv[2]); + } + + if (argc > 3) { + read_percent = atoi(argv[3]); + } + + if (argc > 4) { + max_in_flight = atoi(argv[4]); + } + + if (argc > 5) { + size = atoi(argv[5]); + } + + if (max_in_flight > objects) { + cerr << "Error: max_in_flight must be less than the number of objects" + << std::endl; + return 0; + } + + char *id = getenv("CEPH_CLIENT_ID"); + if (id) cerr << "Client id is: " << id << std::endl; + string pool_name = "data"; + VarLenGenerator cont_gen(size); + RadosTestContext context(pool_name, max_in_flight, cont_gen, id); + + ReadWriteGenerator gen = ReadWriteGenerator(ops, objects, read_percent); + context.loop(&gen); + + context.shutdown(); + cerr << context.errors << " errors." << std::endl; + return 0; +} diff --git a/src/test/osd/TestSnaps.cc b/src/test/osd/TestSnaps.cc index 8f921f22e9f..a73e3371807 100644 --- a/src/test/osd/TestSnaps.cc +++ b/src/test/osd/TestSnaps.cc @@ -103,7 +103,7 @@ int main(int argc, char **argv) } if (max_in_flight > objects) { - cerr << "Error: max_in_flight must be greater than the number of objects" + cerr << "Error: max_in_flight must be less than the number of objects" << std::endl; return 0; }