]> git.proxmox.com Git - ceph.git/blob - ceph/src/test/bench/testfilestore_backend.cc
add subtree-ish sources for 12.0.3
[ceph.git] / ceph / src / test / bench / testfilestore_backend.cc
1 // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2
3 #include "testfilestore_backend.h"
4 #include "global/global_init.h"
5 #include "os/ObjectStore.h"
6
7
8 TestFileStoreBackend::TestFileStoreBackend(
9 ObjectStore *os, bool write_infos)
10 : os(os), finisher(g_ceph_context), write_infos(write_infos)
11 {
12 finisher.start();
13 }
14
15 void TestFileStoreBackend::write(
16 const string &oid,
17 uint64_t offset,
18 const bufferlist &bl,
19 Context *on_applied,
20 Context *on_commit)
21 {
22 ObjectStore::Transaction *t = new ObjectStore::Transaction;
23 size_t sep = oid.find("/");
24 assert(sep != string::npos);
25 assert(sep + 1 < oid.size());
26 coll_t c;
27 bool valid_coll = c.parse(oid.substr(0, sep));
28 assert(valid_coll);
29 string coll_str = c.to_str();
30
31 if (!osrs.count(coll_str))
32 osrs.insert(make_pair(coll_str, ObjectStore::Sequencer(coll_str)));
33 ObjectStore::Sequencer *osr = &(osrs.find(coll_str)->second);
34
35 hobject_t h(sobject_t(oid.substr(sep+1), 0));
36 h.pool = 0;
37 t->write(c, ghobject_t(h), offset, bl.length(), bl);
38
39 if (write_infos) {
40 bufferlist bl2;
41 for (uint64_t j = 0; j < 128; ++j) bl2.append(0);
42 coll_t meta;
43 hobject_t info(sobject_t(string("info_")+coll_str, 0));
44 t->write(meta, ghobject_t(info), 0, bl2.length(), bl2);
45 }
46
47 os->queue_transaction(
48 osr,
49 std::move(*t),
50 on_applied,
51 on_commit);
52 delete t;
53 }
54
55 void TestFileStoreBackend::read(
56 const string &oid,
57 uint64_t offset,
58 uint64_t length,
59 bufferlist *bl,
60 Context *on_complete)
61 {
62 size_t sep = oid.find("/");
63 assert(sep != string::npos);
64 assert(sep + 1 < oid.size());
65 coll_t c;
66 bool valid_coll = c.parse(oid.substr(0, sep));
67 assert(valid_coll);
68 hobject_t h(sobject_t(oid.substr(sep+1), 0));
69 h.pool = 0;
70 os->read(c, ghobject_t(h), offset, length, *bl);
71 finisher.queue(on_complete);
72 }