1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
|
// -*- 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) 2016 Casey Bodley <cbodley@redhat.com>
*
* 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 "os/ObjectStore.h"
#include <gtest/gtest.h>
#include "common/Clock.h"
#include "include/utime.h"
#include <boost/tuple/tuple.hpp>
using namespace std;
TEST(Transaction, MoveConstruct)
{
auto a = ObjectStore::Transaction{};
a.nop();
ASSERT_FALSE(a.empty());
// move-construct in b
auto b = std::move(a);
ASSERT_TRUE(a.empty());
ASSERT_FALSE(b.empty());
}
TEST(Transaction, MoveAssign)
{
auto a = ObjectStore::Transaction{};
a.nop();
ASSERT_FALSE(a.empty());
auto b = ObjectStore::Transaction{};
b = std::move(a); // move-assign to b
ASSERT_TRUE(a.empty());
ASSERT_FALSE(b.empty());
}
TEST(Transaction, CopyConstruct)
{
auto a = ObjectStore::Transaction{};
a.nop();
ASSERT_FALSE(a.empty());
auto b = a; // copy-construct in b
ASSERT_FALSE(a.empty());
ASSERT_FALSE(b.empty());
}
TEST(Transaction, CopyAssign)
{
auto a = ObjectStore::Transaction{};
a.nop();
ASSERT_FALSE(a.empty());
auto b = ObjectStore::Transaction{};
b = a; // copy-assign to b
ASSERT_FALSE(a.empty());
ASSERT_FALSE(b.empty());
}
TEST(Transaction, Swap)
{
auto a = ObjectStore::Transaction{};
a.nop();
ASSERT_FALSE(a.empty());
auto b = ObjectStore::Transaction{};
std::swap(a, b); // swap a and b
ASSERT_TRUE(a.empty());
ASSERT_FALSE(b.empty());
}
ObjectStore::Transaction generate_transaction()
{
auto a = ObjectStore::Transaction{};
a.nop();
coll_t cid;
object_t obj("test_name");
snapid_t snap(0);
hobject_t hoid(obj, "key", snap, 0, 0, "nspace");
ghobject_t oid(hoid);
coll_t acid;
object_t aobj("another_test_name");
snapid_t asnap(0);
hobject_t ahoid(obj, "another_key", snap, 0, 0, "another_nspace");
ghobject_t aoid(hoid);
std::set<string> keys;
keys.insert("any_1");
keys.insert("any_2");
keys.insert("any_3");
bufferlist bl;
bl.append_zero(4096);
a.write(cid, oid, 1, 4096, bl, 0);
a.omap_setkeys(acid, aoid, bl);
a.omap_rmkeys(cid, aoid, keys);
a.touch(acid, oid);
return a;
}
TEST(Transaction, MoveRangesDelSrcObj)
{
auto t = ObjectStore::Transaction{};
t.nop();
coll_t c(spg_t(pg_t(1,2), shard_id_t::NO_SHARD));
ghobject_t o1(hobject_t("obj", "", 123, 456, -1, ""));
ghobject_t o2(hobject_t("obj2", "", 123, 456, -1, ""));
vector<std::pair<uint64_t, uint64_t>> move_info = {
make_pair(1, 5),
make_pair(10, 5)
};
t.touch(c, o1);
bufferlist bl;
bl.append("some data");
t.write(c, o1, 1, bl.length(), bl);
t.write(c, o1, 10, bl.length(), bl);
t.clone(c, o1, o2);
bl.append("some other data");
t.write(c, o2, 1, bl.length(), bl);
}
TEST(Transaction, GetNumBytes)
{
auto a = ObjectStore::Transaction{};
a.nop();
ASSERT_TRUE(a.get_encoded_bytes() == a.get_encoded_bytes_test());
coll_t cid;
object_t obj("test_name");
snapid_t snap(0);
hobject_t hoid(obj, "key", snap, 0, 0, "nspace");
ghobject_t oid(hoid);
coll_t acid;
object_t aobj("another_test_name");
snapid_t asnap(0);
hobject_t ahoid(obj, "another_key", snap, 0, 0, "another_nspace");
ghobject_t aoid(hoid);
std::set<string> keys;
keys.insert("any_1");
keys.insert("any_2");
keys.insert("any_3");
bufferlist bl;
bl.append_zero(4096);
a.write(cid, oid, 1, 4096, bl, 0);
ASSERT_TRUE(a.get_encoded_bytes() == a.get_encoded_bytes_test());
a.omap_setkeys(acid, aoid, bl);
ASSERT_TRUE(a.get_encoded_bytes() == a.get_encoded_bytes_test());
a.omap_rmkeys(cid, aoid, keys);
ASSERT_TRUE(a.get_encoded_bytes() == a.get_encoded_bytes_test());
a.touch(acid, oid);
ASSERT_TRUE(a.get_encoded_bytes() == a.get_encoded_bytes_test());
}
void bench_num_bytes(bool legacy)
{
const int max = 2500000;
auto a = generate_transaction();
if (legacy) {
cout << "get_encoded_bytes_test: ";
} else {
cout << "get_encoded_bytes: ";
}
utime_t start = ceph_clock_now();
if (legacy) {
for (int i = 0; i < max; ++i) {
a.get_encoded_bytes_test();
}
} else {
for (int i = 0; i < max; ++i) {
a.get_encoded_bytes();
}
}
utime_t end = ceph_clock_now();
cout << max << " encodes in " << (end - start) << std::endl;
}
TEST(Transaction, GetNumBytesBenchLegacy)
{
bench_num_bytes(true);
}
TEST(Transaction, GetNumBytesBenchCurrent)
{
bench_num_bytes(false);
}
|