]>
Commit | Line | Data |
---|---|---|
31f18b77 FG |
1 | // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- |
2 | // vim: ts=8 sw=2 smarttab | |
3 | /* | |
4 | * Ceph - scalable distributed file system | |
5 | * | |
6 | * Copyright (C) 2016 Red Hat | |
7 | * | |
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. | |
12 | * | |
13 | */ | |
14 | ||
15 | #include <gtest/gtest.h> | |
16 | #include "osd/PGTransaction.h" | |
17 | #include "osd/ECTransaction.h" | |
18 | ||
19 | #include "test/unit.cc" | |
20 | ||
21 | struct mydpp : public DoutPrefixProvider { | |
11fdf7f2 | 22 | std::ostream& gen_prefix(std::ostream& out) const override { return out << "foo"; } |
31f18b77 FG |
23 | CephContext *get_cct() const override { return g_ceph_context; } |
24 | unsigned get_subsys() const override { return ceph_subsys_osd; } | |
25 | } dpp; | |
26 | ||
27 | #define dout_context g_ceph_context | |
28 | ||
29 | TEST(ectransaction, two_writes_separated) | |
30 | { | |
31 | hobject_t h; | |
32 | PGTransactionUPtr t(new PGTransaction); | |
33 | bufferlist a, b; | |
34 | t->create(h); | |
35 | a.append_zero(565760); | |
36 | t->write(h, 0, a.length(), a, 0); | |
37 | b.append_zero(2437120); | |
38 | t->write(h, 669856, b.length(), b, 0); | |
39 | ||
40 | ECUtil::stripe_info_t sinfo(2, 8192); | |
41 | auto plan = ECTransaction::get_write_plan( | |
42 | sinfo, | |
43 | std::move(t), | |
44 | [&](const hobject_t &i) { | |
45 | ECUtil::HashInfoRef ref(new ECUtil::HashInfo(1)); | |
46 | return ref; | |
47 | }, | |
48 | &dpp); | |
49 | generic_derr << "to_read " << plan.to_read << dendl; | |
50 | generic_derr << "will_write " << plan.will_write << dendl; | |
51 | ||
52 | ASSERT_EQ(0u, plan.to_read.size()); | |
53 | ASSERT_EQ(1u, plan.will_write.size()); | |
54 | } | |
55 | ||
56 | TEST(ectransaction, two_writes_nearby) | |
57 | { | |
58 | hobject_t h; | |
59 | PGTransactionUPtr t(new PGTransaction); | |
60 | bufferlist a, b; | |
61 | t->create(h); | |
62 | ||
63 | // two nearby writes, both partly touching the same 8192-byte stripe | |
64 | ECUtil::stripe_info_t sinfo(2, 8192); | |
65 | a.append_zero(565760); | |
66 | t->write(h, 0, a.length(), a, 0); | |
67 | b.append_zero(2437120); | |
68 | t->write(h, 569856, b.length(), b, 0); | |
69 | ||
70 | auto plan = ECTransaction::get_write_plan( | |
71 | sinfo, | |
72 | std::move(t), | |
73 | [&](const hobject_t &i) { | |
74 | ECUtil::HashInfoRef ref(new ECUtil::HashInfo(1)); | |
75 | return ref; | |
76 | }, | |
77 | &dpp); | |
78 | generic_derr << "to_read " << plan.to_read << dendl; | |
79 | generic_derr << "will_write " << plan.will_write << dendl; | |
80 | ||
81 | ASSERT_EQ(0u, plan.to_read.size()); | |
82 | ASSERT_EQ(1u, plan.will_write.size()); | |
83 | } | |
84 | ||
85 | TEST(ectransaction, many_writes) | |
86 | { | |
87 | hobject_t h; | |
88 | PGTransactionUPtr t(new PGTransaction); | |
89 | bufferlist a, b; | |
90 | a.append_zero(512); | |
91 | b.append_zero(4096); | |
92 | t->create(h); | |
93 | ||
94 | ECUtil::stripe_info_t sinfo(2, 8192); | |
95 | // write 2801664~512 | |
96 | // write 2802176~512 | |
97 | // write 2802688~512 | |
98 | // write 2803200~512 | |
99 | t->write(h, 2801664, a.length(), a, 0); | |
100 | t->write(h, 2802176, a.length(), a, 0); | |
101 | t->write(h, 2802688, a.length(), a, 0); | |
102 | t->write(h, 2803200, a.length(), a, 0); | |
103 | ||
104 | // write 2805760~4096 | |
105 | // write 2809856~4096 | |
106 | // write 2813952~4096 | |
107 | t->write(h, 2805760, b.length(), b, 0); | |
108 | t->write(h, 2809856, b.length(), b, 0); | |
109 | t->write(h, 2813952, b.length(), b, 0); | |
110 | ||
111 | auto plan = ECTransaction::get_write_plan( | |
112 | sinfo, | |
113 | std::move(t), | |
114 | [&](const hobject_t &i) { | |
115 | ECUtil::HashInfoRef ref(new ECUtil::HashInfo(1)); | |
116 | return ref; | |
117 | }, | |
118 | &dpp); | |
119 | generic_derr << "to_read " << plan.to_read << dendl; | |
120 | generic_derr << "will_write " << plan.will_write << dendl; | |
121 | ||
122 | ASSERT_EQ(0u, plan.to_read.size()); | |
123 | ASSERT_EQ(1u, plan.will_write.size()); | |
124 | } |