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.
18 #include <boost/scoped_ptr.hpp>
19 #include "os/filestore/FileStore.h"
20 #include "global/global_init.h"
21 #include "common/ceph_argparse.h"
22 #include "common/debug.h"
23 #include "test/common/ObjectContents.h"
24 #include "FileStoreTracker.h"
25 #include "kv/KeyValueDB.h"
26 #include "os/ObjectStore.h"
30 void usage(const string
&name
) {
31 std::cerr
<< "Usage: " << name
<< " [new|continue] store_path store_journal db_path"
36 typename
T::iterator
rand_choose(T
&cont
) {
37 if (std::empty(cont
)) {
38 return std::end(cont
);
40 return std::next(std::begin(cont
), rand() % cont
.size());
43 int main(int argc
, char **argv
) {
44 auto args
= argv_to_vec(argc
, argv
);
45 auto cct
= global_init(NULL
, args
, CEPH_ENTITY_TYPE_CLIENT
,
46 CODE_ENVIRONMENT_UTILITY
,
47 CINIT_FLAG_NO_DEFAULT_CONFIG_FILE
);
48 common_init_finish(g_ceph_context
);
49 cct
->_conf
.apply_changes(nullptr);
51 std::cerr
<< "args: " << args
<< std::endl
;
52 if (args
.size() < 4) {
57 string
store_path(args
[1]);
58 string
store_dev(args
[2]);
59 string
db_path(args
[3]);
61 bool start_new
= false;
62 if (string(args
[0]) == string("new")) start_new
= true;
64 KeyValueDB
*_db
= KeyValueDB::create(g_ceph_context
, "leveldb", db_path
);
65 ceph_assert(!_db
->create_and_open(std::cerr
));
66 boost::scoped_ptr
<KeyValueDB
> db(_db
);
67 boost::scoped_ptr
<ObjectStore
> store(new FileStore(cct
.get(), store_path
,
70 coll_t
coll(spg_t(pg_t(0,12),shard_id_t::NO_SHARD
));
71 ObjectStore::CollectionHandle ch
;
74 std::cerr
<< "mkfs" << std::endl
;
75 ceph_assert(!store
->mkfs());
76 ObjectStore::Transaction t
;
77 ceph_assert(!store
->mount());
78 ch
= store
->create_new_collection(coll
);
79 t
.create_collection(coll
, 0);
80 store
->queue_transaction(ch
, std::move(t
));
82 ceph_assert(!store
->mount());
83 ch
= store
->open_collection(coll
);
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
));