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.
15 #include <gtest/gtest.h>
16 #include "osd/PGTransaction.h"
17 #include "osd/ECTransaction.h"
19 #include "test/unit.cc"
21 struct mydpp : public DoutPrefixProvider {
22 string gen_prefix() const override { return "foo"; }
23 CephContext *get_cct() const override { return g_ceph_context; }
24 unsigned get_subsys() const override { return ceph_subsys_osd; }
27 #define dout_context g_ceph_context
29 TEST(ectransaction, two_writes_separated)
32 PGTransactionUPtr t(new PGTransaction);
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);
40 ECUtil::stripe_info_t sinfo(2, 8192);
41 auto plan = ECTransaction::get_write_plan(
44 [&](const hobject_t &i) {
45 ECUtil::HashInfoRef ref(new ECUtil::HashInfo(1));
49 generic_derr << "to_read " << plan.to_read << dendl;
50 generic_derr << "will_write " << plan.will_write << dendl;
52 ASSERT_EQ(0u, plan.to_read.size());
53 ASSERT_EQ(1u, plan.will_write.size());
56 TEST(ectransaction, two_writes_nearby)
59 PGTransactionUPtr t(new PGTransaction);
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);
70 auto plan = ECTransaction::get_write_plan(
73 [&](const hobject_t &i) {
74 ECUtil::HashInfoRef ref(new ECUtil::HashInfo(1));
78 generic_derr << "to_read " << plan.to_read << dendl;
79 generic_derr << "will_write " << plan.will_write << dendl;
81 ASSERT_EQ(0u, plan.to_read.size());
82 ASSERT_EQ(1u, plan.will_write.size());
85 TEST(ectransaction, many_writes)
88 PGTransactionUPtr t(new PGTransaction);
94 ECUtil::stripe_info_t sinfo(2, 8192);
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);
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);
111 auto plan = ECTransaction::get_write_plan(
114 [&](const hobject_t &i) {
115 ECUtil::HashInfoRef ref(new ECUtil::HashInfo(1));
119 generic_derr << "to_read " << plan.to_read << dendl;
120 generic_derr << "will_write " << plan.will_write << dendl;
122 ASSERT_EQ(0u, plan.to_read.size());
123 ASSERT_EQ(1u, plan.will_write.size());