1 // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2 // vim: ts=8 sw=2 smarttab
4 * Ceph - scalable distributed file system
6 * Copyright (C) 2004-2006 Sage Weil <sage@newdream.net>
8 * This is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License version 2.1, as published by the Free Software
11 * Foundation. See file COPYING.
17 #include <boost/scoped_ptr.hpp>
18 #include "os/filestore/FileStore.h"
19 #include "global/global_init.h"
20 #include "common/ceph_argparse.h"
21 #include "common/debug.h"
22 #include "test/common/ObjectContents.h"
23 #include "FileStoreTracker.h"
24 #include "kv/KeyValueDB.h"
25 #include "os/ObjectStore.h"
27 void usage(const string &name) {
28 std::cerr << "Usage: " << name << " [new|continue] store_path store_journal db_path"
33 typename T::iterator rand_choose(T &cont) {
34 if (cont.size() == 0) {
37 int index = rand() % cont.size();
38 typename T::iterator retval = cont.begin();
40 for (; index > 0; --index) ++retval;
44 int main(int argc, char **argv) {
45 vector<const char*> args;
46 argv_to_vec(argc, (const char **)argv, args);
48 auto cct = global_init(NULL, args, CEPH_ENTITY_TYPE_CLIENT,
49 CODE_ENVIRONMENT_UTILITY, 0);
50 common_init_finish(g_ceph_context);
51 g_ceph_context->_conf->apply_changes(NULL);
53 std::cerr << "args: " << args << std::endl;
54 if (args.size() < 4) {
59 string store_path(args[1]);
60 string store_dev(args[2]);
61 string db_path(args[3]);
63 bool start_new = false;
64 if (string(args[0]) == string("new")) start_new = true;
66 KeyValueDB *_db = KeyValueDB::create(g_ceph_context, "leveldb", db_path);
67 assert(!_db->create_and_open(std::cerr));
68 boost::scoped_ptr<KeyValueDB> db(_db);
69 boost::scoped_ptr<ObjectStore> store(new FileStore(cct.get(), store_path,
72 ObjectStore::Sequencer osr(__func__);
73 coll_t coll(spg_t(pg_t(0,12),shard_id_t::NO_SHARD));
76 std::cerr << "mkfs" << std::endl;
77 assert(!store->mkfs());
78 ObjectStore::Transaction t;
79 assert(!store->mount());
80 t.create_collection(coll, 0);
81 store->apply_transaction(&osr, std::move(t));
83 assert(!store->mount());
86 FileStoreTracker tracker(store.get(), db.get());
89 for (unsigned i = 0; i < 10; ++i) {
91 stream << "Object_" << i;
92 tracker.verify(coll, stream.str(), true);
93 objects.insert(stream.str());
97 FileStoreTracker::Transaction t;
98 for (unsigned j = 0; j < 100; ++j) {
99 int val = rand() % 100;
101 t.write(coll, *rand_choose(objects));
102 } else if (val < 60) {
103 t.clone(coll, *rand_choose(objects),
104 *rand_choose(objects));
105 } else if (val < 70) {
106 t.remove(coll, *rand_choose(objects));
108 t.clone_range(coll, *rand_choose(objects),
109 *rand_choose(objects));
112 tracker.submit_transaction(t);
113 tracker.verify(coll, *rand_choose(objects));