1 // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
3 #include "include/buffer.h"
4 #include "kv/KeyValueDB.h"
9 #include "include/memory.h"
10 #include <boost/scoped_ptr.hpp>
14 #include "global/global_context.h"
18 const string CONTROL_PREFIX = "CONTROL";
19 const string PRIMARY_PREFIX = "PREFIX";
20 const int NUM_COPIES = 100;
21 const int NUM_THREADS = 30;
23 string prefix_gen(int i) {
25 ss << PRIMARY_PREFIX << "_" << i << std::endl;
29 int verify(KeyValueDB *db) {
32 map<int, KeyValueDB::Iterator> iterators;
33 for (int i = 0; i < NUM_COPIES; ++i) {
34 iterators[i] = db->get_iterator(prefix_gen(i));
35 iterators[i]->seek_to_first();
37 while (iterators.rbegin()->second->valid()) {
38 for (map<int, KeyValueDB::Iterator>::iterator i = iterators.begin();
41 assert(i->second->valid());
42 assert(i->second->key() == iterators.rbegin()->second->key());
43 bufferlist r = i->second->value();
44 bufferlist l = iterators.rbegin()->second->value();
48 for (map<int, KeyValueDB::Iterator>::iterator i = iterators.begin();
51 assert(!i->second->valid());
57 void *write(void *_db) {
58 KeyValueDB *db = static_cast<KeyValueDB*>(_db);
59 std::cout << "Writing..." << std::endl;
60 for (int i = 0; i < 12000; ++i) {
62 std::cout << "Iteration: " << i << std::endl;
66 key << key_num << std::endl;
67 map<string, bufferlist> to_set;
69 val << i << std::endl;
70 bufferptr bp(val.str().c_str(), val.str().size() + 1);
71 to_set[key.str()].push_back(bp);
73 KeyValueDB::Transaction t = db->get_transaction();
74 for (int j = 0; j < NUM_COPIES; ++j) {
75 t->set(prefix_gen(j), to_set);
77 assert(!db->submit_transaction(t));
83 char *path = getenv("OBJECT_MAP_PATH");
84 boost::scoped_ptr< KeyValueDB > db;
86 std::cerr << "No path found, OBJECT_MAP_PATH undefined" << std::endl;
90 std::cerr << "Using path: " << strpath << std::endl;
91 KeyValueDB *store = KeyValueDB::create(g_ceph_context, "leveldb", strpath);
92 assert(!store->create_and_open(std::cerr));
97 vector<pthread_t> threads(NUM_THREADS);
98 for (vector<pthread_t>::iterator i = threads.begin();
101 pthread_create(&*i, 0, &write, static_cast<void *>(db.get()));
103 for (vector<pthread_t>::iterator i = threads.begin();
107 pthread_join(*i, &tmp);