]>
git.proxmox.com Git - ceph.git/blob - ceph/src/test/osd/test_extent_cache.cc
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) 2016 Red Hat
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.
16 #include <gtest/gtest.h>
17 #include "osd/ExtentCache.h"
22 extent_map
imap_from_vector(vector
<pair
<uint64_t, uint64_t> > &&in
)
25 for (auto &&tup
: in
) {
27 bl
.append_zero(tup
.second
);
28 out
.insert(tup
.first
, bl
.length(), bl
);
33 extent_map
imap_from_iset(const extent_set
&set
)
36 for (auto &&iter
: set
) {
38 bl
.append_zero(iter
.second
);
39 out
.insert(iter
.first
, iter
.second
, bl
);
44 extent_set
iset_from_vector(vector
<pair
<uint64_t, uint64_t> > &&in
)
47 for (auto &&tup
: in
) {
48 out
.insert(tup
.first
, tup
.second
);
53 TEST(extentcache
, simple_write
)
58 ExtentCache::write_pin pin
;
59 c
.open_write_pin(pin
);
61 auto to_read
= iset_from_vector(
62 {{0, 2}, {8, 2}, {20, 2}});
63 auto to_write
= iset_from_vector(
65 auto must_read
= c
.reserve_extents_for_rmw(
66 oid
, pin
, to_write
, to_read
);
73 auto got
= imap_from_iset(must_read
);
74 auto pending_read
= to_read
;
75 pending_read
.subtract(must_read
);
77 auto pending
= c
.get_remaining_extents_for_rmw(
81 ASSERT_TRUE(pending
.empty());
83 auto write_map
= imap_from_iset(to_write
);
89 c
.release_write_pin(pin
);
92 TEST(extentcache
, write_write_overlap
)
97 ExtentCache::write_pin pin
;
98 c
.open_write_pin(pin
);
101 auto to_read
= iset_from_vector(
102 {{0, 2}, {8, 2}, {20, 2}});
103 auto to_write
= iset_from_vector(
105 auto must_read
= c
.reserve_extents_for_rmw(
106 oid
, pin
, to_write
, to_read
);
114 ExtentCache::write_pin pin2
;
115 c
.open_write_pin(pin2
);
116 auto to_read2
= iset_from_vector(
117 {{2, 4}, {10, 4}, {18, 4}});
118 auto to_write2
= iset_from_vector(
119 {{2, 12}, {18, 12}});
120 auto must_read2
= c
.reserve_extents_for_rmw(
121 oid
, pin2
, to_write2
, to_read2
);
124 iset_from_vector({{10, 4}, {18, 2}}));
128 // complete read for write 1 and start commit
129 auto got
= imap_from_iset(must_read
);
130 auto pending_read
= to_read
;
131 pending_read
.subtract(must_read
);
132 auto pending
= c
.get_remaining_extents_for_rmw(
136 ASSERT_TRUE(pending
.empty());
138 auto write_map
= imap_from_iset(to_write
);
139 c
.present_rmw_update(
146 // complete read for write 2 and start commit
147 auto pending_read2
= to_read2
;
148 pending_read2
.subtract(must_read2
);
149 auto pending2
= c
.get_remaining_extents_for_rmw(
155 imap_from_iset(pending_read2
));
157 auto write_map2
= imap_from_iset(to_write2
);
158 c
.present_rmw_update(
165 c
.release_write_pin(pin
);
169 c
.release_write_pin(pin2
);
172 TEST(extentcache
, write_write_overlap2
)
177 ExtentCache::write_pin pin
;
178 c
.open_write_pin(pin
);
181 auto to_read
= extent_set();
182 auto to_write
= iset_from_vector(
184 auto must_read
= c
.reserve_extents_for_rmw(
185 oid
, pin
, to_write
, to_read
);
193 ExtentCache::write_pin pin2
;
194 c
.open_write_pin(pin2
);
195 auto to_read2
= extent_set();
196 auto to_write2
= iset_from_vector(
198 auto must_read2
= c
.reserve_extents_for_rmw(
199 oid
, pin2
, to_write2
, to_read2
);
206 ExtentCache::write_pin pin3
;
207 c
.open_write_pin(pin3
);
208 auto to_read3
= iset_from_vector({{659456, 8192}});
209 auto to_write3
= iset_from_vector({{659456, 8192}});
210 auto must_read3
= c
.reserve_extents_for_rmw(
211 oid
, pin3
, to_write3
, to_read3
);
218 // complete read for write 1 and start commit
219 auto got
= imap_from_iset(must_read
);
220 auto pending_read
= to_read
;
221 pending_read
.subtract(must_read
);
222 auto pending
= c
.get_remaining_extents_for_rmw(
226 ASSERT_TRUE(pending
.empty());
228 auto write_map
= imap_from_iset(to_write
);
229 c
.present_rmw_update(
236 // complete read for write 2 and start commit
237 auto pending_read2
= to_read2
;
238 pending_read2
.subtract(must_read2
);
239 auto pending2
= c
.get_remaining_extents_for_rmw(
245 imap_from_iset(pending_read2
));
247 auto write_map2
= imap_from_iset(to_write2
);
248 c
.present_rmw_update(
253 // complete read for write 2 and start commit
254 auto pending_read3
= to_read3
;
255 pending_read3
.subtract(must_read3
);
256 auto pending3
= c
.get_remaining_extents_for_rmw(
262 imap_from_iset(pending_read3
));
264 auto write_map3
= imap_from_iset(to_write3
);
265 c
.present_rmw_update(
273 c
.release_write_pin(pin
);
277 c
.release_write_pin(pin2
);
281 c
.release_write_pin(pin3
);