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
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
|
// -*- 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 Red Hat
*
* 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 <gtest/gtest.h>
#include "osd/ExtentCache.h"
#include <iostream>
extent_map imap_from_vector(vector<pair<uint64_t, uint64_t> > &&in)
{
extent_map out;
for (auto &&tup: in) {
bufferlist bl;
bl.append_zero(tup.second);
out.insert(tup.first, bl.length(), bl);
}
return out;
}
extent_map imap_from_iset(const extent_set &set)
{
extent_map out;
for (auto &&iter: set) {
bufferlist bl;
bl.append_zero(iter.second);
out.insert(iter.first, iter.second, bl);
}
return out;
}
extent_set iset_from_vector(vector<pair<uint64_t, uint64_t> > &&in)
{
extent_set out;
for (auto &&tup: in) {
out.insert(tup.first, tup.second);
}
return out;
}
TEST(extentcache, simple_write)
{
hobject_t oid;
ExtentCache c;
ExtentCache::write_pin pin;
c.open_write_pin(pin);
auto to_read = iset_from_vector(
{{0, 2}, {8, 2}, {20, 2}});
auto to_write = iset_from_vector(
{{0, 10}, {20, 4}});
auto must_read = c.reserve_extents_for_rmw(
oid, pin, to_write, to_read);
ASSERT_EQ(
must_read,
to_read);
c.print(std::cerr);
auto got = imap_from_iset(must_read);
auto pending_read = to_read;
pending_read.subtract(must_read);
auto pending = c.get_remaining_extents_for_rmw(
oid,
pin,
pending_read);
ASSERT_TRUE(pending.empty());
auto write_map = imap_from_iset(to_write);
c.present_rmw_update(
oid,
pin,
write_map);
c.release_write_pin(pin);
}
TEST(extentcache, write_write_overlap)
{
hobject_t oid;
ExtentCache c;
ExtentCache::write_pin pin;
c.open_write_pin(pin);
// start write 1
auto to_read = iset_from_vector(
{{0, 2}, {8, 2}, {20, 2}});
auto to_write = iset_from_vector(
{{0, 10}, {20, 4}});
auto must_read = c.reserve_extents_for_rmw(
oid, pin, to_write, to_read);
ASSERT_EQ(
must_read,
to_read);
c.print(std::cerr);
// start write 2
ExtentCache::write_pin pin2;
c.open_write_pin(pin2);
auto to_read2 = iset_from_vector(
{{2, 4}, {10, 4}, {18, 4}});
auto to_write2 = iset_from_vector(
{{2, 12}, {18, 12}});
auto must_read2 = c.reserve_extents_for_rmw(
oid, pin2, to_write2, to_read2);
ASSERT_EQ(
must_read2,
iset_from_vector({{10, 4}, {18, 2}}));
c.print(std::cerr);
// complete read for write 1 and start commit
auto got = imap_from_iset(must_read);
auto pending_read = to_read;
pending_read.subtract(must_read);
auto pending = c.get_remaining_extents_for_rmw(
oid,
pin,
pending_read);
ASSERT_TRUE(pending.empty());
auto write_map = imap_from_iset(to_write);
c.present_rmw_update(
oid,
pin,
write_map);
c.print(std::cerr);
// complete read for write 2 and start commit
auto pending_read2 = to_read2;
pending_read2.subtract(must_read2);
auto pending2 = c.get_remaining_extents_for_rmw(
oid,
pin2,
pending_read2);
ASSERT_EQ(
pending2,
imap_from_iset(pending_read2));
auto write_map2 = imap_from_iset(to_write2);
c.present_rmw_update(
oid,
pin2,
write_map2);
c.print(std::cerr);
c.release_write_pin(pin);
c.print(std::cerr);
c.release_write_pin(pin2);
}
TEST(extentcache, write_write_overlap2)
{
hobject_t oid;
ExtentCache c;
ExtentCache::write_pin pin;
c.open_write_pin(pin);
// start write 1
auto to_read = extent_set();
auto to_write = iset_from_vector(
{{659456, 4096}});
auto must_read = c.reserve_extents_for_rmw(
oid, pin, to_write, to_read);
ASSERT_EQ(
must_read,
to_read);
c.print(std::cerr);
// start write 2
ExtentCache::write_pin pin2;
c.open_write_pin(pin2);
auto to_read2 = extent_set();
auto to_write2 = iset_from_vector(
{{663552, 4096}});
auto must_read2 = c.reserve_extents_for_rmw(
oid, pin2, to_write2, to_read2);
ASSERT_EQ(
must_read2,
to_read2);
// start write 3
ExtentCache::write_pin pin3;
c.open_write_pin(pin3);
auto to_read3 = iset_from_vector({{659456, 8192}});
auto to_write3 = iset_from_vector({{659456, 8192}});
auto must_read3 = c.reserve_extents_for_rmw(
oid, pin3, to_write3, to_read3);
ASSERT_EQ(
must_read3,
extent_set());
c.print(std::cerr);
// complete read for write 1 and start commit
auto got = imap_from_iset(must_read);
auto pending_read = to_read;
pending_read.subtract(must_read);
auto pending = c.get_remaining_extents_for_rmw(
oid,
pin,
pending_read);
ASSERT_TRUE(pending.empty());
auto write_map = imap_from_iset(to_write);
c.present_rmw_update(
oid,
pin,
write_map);
c.print(std::cerr);
// complete read for write 2 and start commit
auto pending_read2 = to_read2;
pending_read2.subtract(must_read2);
auto pending2 = c.get_remaining_extents_for_rmw(
oid,
pin2,
pending_read2);
ASSERT_EQ(
pending2,
imap_from_iset(pending_read2));
auto write_map2 = imap_from_iset(to_write2);
c.present_rmw_update(
oid,
pin2,
write_map2);
// complete read for write 2 and start commit
auto pending_read3 = to_read3;
pending_read3.subtract(must_read3);
auto pending3 = c.get_remaining_extents_for_rmw(
oid,
pin3,
pending_read3);
ASSERT_EQ(
pending3,
imap_from_iset(pending_read3));
auto write_map3 = imap_from_iset(to_write3);
c.present_rmw_update(
oid,
pin3,
write_map3);
c.print(std::cerr);
c.release_write_pin(pin);
c.print(std::cerr);
c.release_write_pin(pin2);
c.print(std::cerr);
c.release_write_pin(pin3);
}
|