From 483eb2f56657e8e7f419ab1a4fab8dce9ade8609 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sat, 27 Apr 2024 20:24:20 +0200 Subject: Adding upstream version 14.2.21. Signed-off-by: Daniel Baumann --- src/test/objectstore/test_idempotent.cc | 119 ++++++++++++++++++++++++++++++++ 1 file changed, 119 insertions(+) create mode 100644 src/test/objectstore/test_idempotent.cc (limited to 'src/test/objectstore/test_idempotent.cc') 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 + * + * 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 +#include +#include +#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::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 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 db(_db); + boost::scoped_ptr 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 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; +} -- cgit v1.2.3