diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-27 18:24:20 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-27 18:24:20 +0000 |
commit | 483eb2f56657e8e7f419ab1a4fab8dce9ade8609 (patch) | |
tree | e5d88d25d870d5dedacb6bbdbe2a966086a0a5cf /src/test/objectstore/test_idempotent.cc | |
parent | Initial commit. (diff) | |
download | ceph-483eb2f56657e8e7f419ab1a4fab8dce9ade8609.tar.xz ceph-483eb2f56657e8e7f419ab1a4fab8dce9ade8609.zip |
Adding upstream version 14.2.21.upstream/14.2.21upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'src/test/objectstore/test_idempotent.cc')
-rw-r--r-- | src/test/objectstore/test_idempotent.cc | 119 |
1 files changed, 119 insertions, 0 deletions
diff --git a/src/test/objectstore/test_idempotent.cc b/src/test/objectstore/test_idempotent.cc new file mode 100644 index 00000000..c89ea9b7 --- /dev/null +++ b/src/test/objectstore/test_idempotent.cc @@ -0,0 +1,119 @@ +// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- +// vim: ts=8 sw=2 smarttab +/* + * Ceph - scalable distributed file system + * + * Copyright (C) 2004-2006 Sage Weil <sage@newdream.net> + * + * This is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software + * Foundation. See file COPYING. + * + */ + +#include <iostream> +#include <sstream> +#include <boost/scoped_ptr.hpp> +#include "os/filestore/FileStore.h" +#include "global/global_init.h" +#include "common/ceph_argparse.h" +#include "common/debug.h" +#include "test/common/ObjectContents.h" +#include "FileStoreTracker.h" +#include "kv/KeyValueDB.h" +#include "os/ObjectStore.h" + +void usage(const string &name) { + std::cerr << "Usage: " << name << " [new|continue] store_path store_journal db_path" + << std::endl; +} + +template <typename T> +typename T::iterator rand_choose(T &cont) { + if (cont.size() == 0) { + return cont.end(); + } + int index = rand() % cont.size(); + typename T::iterator retval = cont.begin(); + + for (; index > 0; --index) ++retval; + return retval; +} + +int main(int argc, char **argv) { + vector<const char*> args; + argv_to_vec(argc, (const char **)argv, args); + + auto cct = global_init(NULL, args, CEPH_ENTITY_TYPE_CLIENT, + CODE_ENVIRONMENT_UTILITY, + CINIT_FLAG_NO_DEFAULT_CONFIG_FILE); + common_init_finish(g_ceph_context); + cct->_conf.apply_changes(nullptr); + + std::cerr << "args: " << args << std::endl; + if (args.size() < 4) { + usage(argv[0]); + return 1; + } + + string store_path(args[1]); + string store_dev(args[2]); + string db_path(args[3]); + + bool start_new = false; + if (string(args[0]) == string("new")) start_new = true; + + KeyValueDB *_db = KeyValueDB::create(g_ceph_context, "leveldb", db_path); + ceph_assert(!_db->create_and_open(std::cerr)); + boost::scoped_ptr<KeyValueDB> db(_db); + boost::scoped_ptr<ObjectStore> store(new FileStore(cct.get(), store_path, + store_dev)); + + coll_t coll(spg_t(pg_t(0,12),shard_id_t::NO_SHARD)); + ObjectStore::CollectionHandle ch; + + if (start_new) { + std::cerr << "mkfs" << std::endl; + ceph_assert(!store->mkfs()); + ObjectStore::Transaction t; + ceph_assert(!store->mount()); + ch = store->create_new_collection(coll); + t.create_collection(coll, 0); + store->queue_transaction(ch, std::move(t)); + } else { + ceph_assert(!store->mount()); + ch = store->open_collection(coll); + } + + FileStoreTracker tracker(store.get(), db.get()); + + set<string> objects; + for (unsigned i = 0; i < 10; ++i) { + stringstream stream; + stream << "Object_" << i; + tracker.verify(coll, stream.str(), true); + objects.insert(stream.str()); + } + + while (1) { + FileStoreTracker::Transaction t; + for (unsigned j = 0; j < 100; ++j) { + int val = rand() % 100; + if (val < 30) { + t.write(coll, *rand_choose(objects)); + } else if (val < 60) { + t.clone(coll, *rand_choose(objects), + *rand_choose(objects)); + } else if (val < 70) { + t.remove(coll, *rand_choose(objects)); + } else { + t.clone_range(coll, *rand_choose(objects), + *rand_choose(objects)); + } + } + tracker.submit_transaction(t); + tracker.verify(coll, *rand_choose(objects)); + } + return 0; +} |