summaryrefslogtreecommitdiffstats
path: root/src/test/osd/test_ec_transaction.cc
blob: 98669667a777266a4f4120dfd79e4a0563ac0895 (plain)
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
// -*- 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/PGTransaction.h"
#include "osd/ECTransaction.h"

#include "test/unit.cc"

struct mydpp : public DoutPrefixProvider {
  std::ostream& gen_prefix(std::ostream& out) const override { return out << "foo"; }
  CephContext *get_cct() const override { return g_ceph_context; }
  unsigned get_subsys() const override { return ceph_subsys_osd; }
} dpp;

#define dout_context g_ceph_context

TEST(ectransaction, two_writes_separated)
{
  hobject_t h;
  PGTransactionUPtr t(new PGTransaction);
  bufferlist a, b;
  t->create(h);
  a.append_zero(565760);
  t->write(h, 0, a.length(), a, 0);
  b.append_zero(2437120);
  t->write(h, 669856, b.length(), b, 0);

  ECUtil::stripe_info_t sinfo(2, 8192);
  auto plan = ECTransaction::get_write_plan(
    sinfo,
    std::move(t),
    [&](const hobject_t &i) {
      ECUtil::HashInfoRef ref(new ECUtil::HashInfo(1));
      return ref;
    },
    &dpp);
  generic_derr << "to_read " << plan.to_read << dendl;
  generic_derr << "will_write " << plan.will_write << dendl;

  ASSERT_EQ(0u, plan.to_read.size());
  ASSERT_EQ(1u, plan.will_write.size());
}

TEST(ectransaction, two_writes_nearby)
{
  hobject_t h;
  PGTransactionUPtr t(new PGTransaction);
  bufferlist a, b;
  t->create(h);

  // two nearby writes, both partly touching the same 8192-byte stripe
  ECUtil::stripe_info_t sinfo(2, 8192);
  a.append_zero(565760);
  t->write(h, 0, a.length(), a, 0);
  b.append_zero(2437120);
  t->write(h, 569856, b.length(), b, 0);

  auto plan = ECTransaction::get_write_plan(
    sinfo,
    std::move(t),
    [&](const hobject_t &i) {
      ECUtil::HashInfoRef ref(new ECUtil::HashInfo(1));
      return ref;
    },
    &dpp);
  generic_derr << "to_read " << plan.to_read << dendl;
  generic_derr << "will_write " << plan.will_write << dendl;

  ASSERT_EQ(0u, plan.to_read.size());
  ASSERT_EQ(1u, plan.will_write.size());
}

TEST(ectransaction, many_writes)
{
  hobject_t h;
  PGTransactionUPtr t(new PGTransaction);
  bufferlist a, b;
  a.append_zero(512);
  b.append_zero(4096);
  t->create(h);

  ECUtil::stripe_info_t sinfo(2, 8192);
  // write 2801664~512
  // write 2802176~512
  // write 2802688~512
  // write 2803200~512
  t->write(h, 2801664, a.length(), a, 0);
  t->write(h, 2802176, a.length(), a, 0);
  t->write(h, 2802688, a.length(), a, 0);
  t->write(h, 2803200, a.length(), a, 0);

  // write 2805760~4096
  // write 2809856~4096
  // write 2813952~4096
  t->write(h, 2805760, b.length(), b, 0);
  t->write(h, 2809856, b.length(), b, 0);
  t->write(h, 2813952, b.length(), b, 0);

  auto plan = ECTransaction::get_write_plan(
    sinfo,
    std::move(t),
    [&](const hobject_t &i) {
      ECUtil::HashInfoRef ref(new ECUtil::HashInfo(1));
      return ref;
    },
    &dpp);
  generic_derr << "to_read " << plan.to_read << dendl;
  generic_derr << "will_write " << plan.will_write << dendl;

  ASSERT_EQ(0u, plan.to_read.size());
  ASSERT_EQ(1u, plan.will_write.size());
}