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"
20 extent_map imap_from_vector(vector<pair<uint64_t, uint64_t> > &&in)
23 for (auto &&tup: in) {
25 bl.append_zero(tup.second);
26 out.insert(tup.first, bl.length(), bl);
31 extent_map imap_from_iset(const extent_set &set)
34 for (auto &&iter: set) {
36 bl.append_zero(iter.second);
37 out.insert(iter.first, iter.second, bl);
42 extent_set iset_from_vector(vector<pair<uint64_t, uint64_t> > &&in)
45 for (auto &&tup: in) {
46 out.insert(tup.first, tup.second);
51 TEST(extentcache, simple_write)
56 ExtentCache::write_pin pin;
57 c.open_write_pin(pin);
59 auto to_read = iset_from_vector(
60 {{0, 2}, {8, 2}, {20, 2}});
61 auto to_write = iset_from_vector(
63 auto must_read = c.reserve_extents_for_rmw(
64 oid, pin, to_write, to_read);
71 auto got = imap_from_iset(must_read);
72 auto pending_read = to_read;
73 pending_read.subtract(must_read);
75 auto pending = c.get_remaining_extents_for_rmw(
79 ASSERT_TRUE(pending.empty());
81 auto write_map = imap_from_iset(to_write);
87 c.release_write_pin(pin);
90 TEST(extentcache, write_write_overlap)
95 ExtentCache::write_pin pin;
96 c.open_write_pin(pin);
99 auto to_read = iset_from_vector(
100 {{0, 2}, {8, 2}, {20, 2}});
101 auto to_write = iset_from_vector(
103 auto must_read = c.reserve_extents_for_rmw(
104 oid, pin, to_write, to_read);
112 ExtentCache::write_pin pin2;
113 c.open_write_pin(pin2);
114 auto to_read2 = iset_from_vector(
115 {{2, 4}, {10, 4}, {18, 4}});
116 auto to_write2 = iset_from_vector(
117 {{2, 12}, {18, 12}});
118 auto must_read2 = c.reserve_extents_for_rmw(
119 oid, pin2, to_write2, to_read2);
122 iset_from_vector({{10, 4}, {18, 2}}));
126 // complete read for write 1 and start commit
127 auto got = imap_from_iset(must_read);
128 auto pending_read = to_read;
129 pending_read.subtract(must_read);
130 auto pending = c.get_remaining_extents_for_rmw(
134 ASSERT_TRUE(pending.empty());
136 auto write_map = imap_from_iset(to_write);
137 c.present_rmw_update(
144 // complete read for write 2 and start commit
145 auto pending_read2 = to_read2;
146 pending_read2.subtract(must_read2);
147 auto pending2 = c.get_remaining_extents_for_rmw(
153 imap_from_iset(pending_read2));
155 auto write_map2 = imap_from_iset(to_write2);
156 c.present_rmw_update(
163 c.release_write_pin(pin);
167 c.release_write_pin(pin2);
170 TEST(extentcache, write_write_overlap2)
175 ExtentCache::write_pin pin;
176 c.open_write_pin(pin);
179 auto to_read = extent_set();
180 auto to_write = iset_from_vector(
182 auto must_read = c.reserve_extents_for_rmw(
183 oid, pin, to_write, to_read);
191 ExtentCache::write_pin pin2;
192 c.open_write_pin(pin2);
193 auto to_read2 = extent_set();
194 auto to_write2 = iset_from_vector(
196 auto must_read2 = c.reserve_extents_for_rmw(
197 oid, pin2, to_write2, to_read2);
204 ExtentCache::write_pin pin3;
205 c.open_write_pin(pin3);
206 auto to_read3 = iset_from_vector({{659456, 8192}});
207 auto to_write3 = iset_from_vector({{659456, 8192}});
208 auto must_read3 = c.reserve_extents_for_rmw(
209 oid, pin3, to_write3, to_read3);
216 // complete read for write 1 and start commit
217 auto got = imap_from_iset(must_read);
218 auto pending_read = to_read;
219 pending_read.subtract(must_read);
220 auto pending = c.get_remaining_extents_for_rmw(
224 ASSERT_TRUE(pending.empty());
226 auto write_map = imap_from_iset(to_write);
227 c.present_rmw_update(
234 // complete read for write 2 and start commit
235 auto pending_read2 = to_read2;
236 pending_read2.subtract(must_read2);
237 auto pending2 = c.get_remaining_extents_for_rmw(
243 imap_from_iset(pending_read2));
245 auto write_map2 = imap_from_iset(to_write2);
246 c.present_rmw_update(
251 // complete read for write 2 and start commit
252 auto pending_read3 = to_read3;
253 pending_read3.subtract(must_read3);
254 auto pending3 = c.get_remaining_extents_for_rmw(
260 imap_from_iset(pending_read3));
262 auto write_map3 = imap_from_iset(to_write3);
263 c.present_rmw_update(
271 c.release_write_pin(pin);
275 c.release_write_pin(pin2);
279 c.release_write_pin(pin3);