summaryrefslogtreecommitdiffstats
path: root/src/common/io_exerciser/EcIoSequence.cc
blob: 611920c96e0f682bdaed7d622f03554bae836812 (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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
#include "EcIoSequence.h"

#include <memory>

using IoOp = ceph::io_exerciser::IoOp;
using Sequence = ceph::io_exerciser::Sequence;
using IoSequence = ceph::io_exerciser::IoSequence;
using EcIoSequence = ceph::io_exerciser::EcIoSequence;
using ReadInjectSequence = ceph::io_exerciser::ReadInjectSequence;

bool EcIoSequence::is_supported(Sequence sequence) const { return true; }

std::unique_ptr<IoSequence> EcIoSequence::generate_sequence(
    Sequence sequence, std::pair<int, int> obj_size_range, int k, int m,
    int seed) {
  switch (sequence) {
    case Sequence::SEQUENCE_SEQ0:
      [[fallthrough]];
    case Sequence::SEQUENCE_SEQ1:
      [[fallthrough]];
    case Sequence::SEQUENCE_SEQ2:
      [[fallthrough]];
    case Sequence::SEQUENCE_SEQ3:
      [[fallthrough]];
    case Sequence::SEQUENCE_SEQ4:
      [[fallthrough]];
    case Sequence::SEQUENCE_SEQ5:
      [[fallthrough]];
    case Sequence::SEQUENCE_SEQ6:
      [[fallthrough]];
    case Sequence::SEQUENCE_SEQ7:
      [[fallthrough]];
    case Sequence::SEQUENCE_SEQ8:
      [[fallthrough]];
    case Sequence::SEQUENCE_SEQ9:
      return std::make_unique<ReadInjectSequence>(obj_size_range, seed,
                                                  sequence, k, m);
    case Sequence::SEQUENCE_SEQ10:
      return std::make_unique<Seq10>(obj_size_range, seed, k, m);
    default:
      ceph_abort_msg("Unrecognised sequence");
  }
}

EcIoSequence::EcIoSequence(std::pair<int, int> obj_size_range, int seed)
    : IoSequence(obj_size_range, seed),
      setup_inject(false),
      clear_inject(false),
      shard_to_inject(std::nullopt) {}

void EcIoSequence::select_random_data_shard_to_inject_read_error(int k, int m) {
  shard_to_inject = rng(k - 1);
  setup_inject = true;
}

void EcIoSequence::select_random_data_shard_to_inject_write_error(int k,
                                                                  int m) {
  // Write errors do not support injecting to the primary OSD
  shard_to_inject = rng(1, k - 1);
  setup_inject = true;
}

void EcIoSequence::select_random_shard_to_inject_read_error(int k, int m) {
  shard_to_inject = rng(k + m - 1);
  setup_inject = true;
}

void EcIoSequence::select_random_shard_to_inject_write_error(int k, int m) {
  // Write errors do not support injecting to the primary OSD
  shard_to_inject = rng(1, k + m - 1);
  setup_inject = true;
}

void EcIoSequence::generate_random_read_inject_type() {
  inject_op_type = static_cast<InjectOpType>(
      rng(static_cast<int>(InjectOpType::ReadEIO),
          static_cast<int>(InjectOpType::ReadMissingShard)));
}

void EcIoSequence::generate_random_write_inject_type() {
  inject_op_type = static_cast<InjectOpType>(
      rng(static_cast<int>(InjectOpType::WriteFailAndRollback),
          static_cast<int>(InjectOpType::WriteOSDAbort)));
}

ceph::io_exerciser::ReadInjectSequence::ReadInjectSequence(
    std::pair<int, int> obj_size_range, int seed, Sequence s, int k, int m)
    : EcIoSequence(obj_size_range, seed) {
  child_sequence = IoSequence::generate_sequence(s, obj_size_range, seed);
  select_random_data_shard_to_inject_read_error(k, m);
  generate_random_read_inject_type();
}

Sequence ceph::io_exerciser::ReadInjectSequence::get_id() const {
  return child_sequence->get_id();
}

std::string ceph::io_exerciser::ReadInjectSequence::get_name() const {
  return child_sequence->get_name() +
         " running with read errors injected on shard " +
         std::to_string(*shard_to_inject);
}

std::unique_ptr<IoOp> ReadInjectSequence::next() {
  step++;

  if (nextOp) {
    std::unique_ptr<IoOp> retOp = nullptr;
    nextOp.swap(retOp);
    return retOp;
  }

  std::unique_ptr<IoOp> childOp = child_sequence->next();

  switch (childOp->getOpType()) {
    case OpType::Remove:
      nextOp.swap(childOp);
      switch (inject_op_type) {
        case InjectOpType::ReadEIO:
          return ClearReadErrorInjectOp::generate(*shard_to_inject, 0);
        case InjectOpType::ReadMissingShard:
          return ClearReadErrorInjectOp::generate(*shard_to_inject, 1);
        case InjectOpType::WriteFailAndRollback:
          return ClearWriteErrorInjectOp::generate(*shard_to_inject, 0);
        case InjectOpType::WriteOSDAbort:
          return ClearWriteErrorInjectOp::generate(*shard_to_inject, 3);
        case InjectOpType::None:
          [[fallthrough]];
        default:
          ceph_abort_msg("Unsupported operation");
      }
      break;
    case OpType::Create:
      switch (inject_op_type) {
        case InjectOpType::ReadEIO:
          nextOp = InjectReadErrorOp::generate(
              *shard_to_inject, 0, 0, std::numeric_limits<uint64_t>::max());
          break;
        case InjectOpType::ReadMissingShard:
          nextOp = InjectReadErrorOp::generate(
              *shard_to_inject, 1, 0, std::numeric_limits<uint64_t>::max());
          break;
        case InjectOpType::WriteFailAndRollback:
          nextOp = InjectWriteErrorOp::generate(
              *shard_to_inject, 0, 0, std::numeric_limits<uint64_t>::max());
          break;
        case InjectOpType::WriteOSDAbort:
          nextOp = InjectWriteErrorOp::generate(
              *shard_to_inject, 3, 0, std::numeric_limits<uint64_t>::max());
          break;
        case InjectOpType::None:
          [[fallthrough]];
        default:
          ceph_abort_msg("Unsupported operation");
      }
      break;
    default:
      // Do nothing in default case
      break;
  }

  return childOp;
}

std::unique_ptr<ceph::io_exerciser::IoOp>
ceph::io_exerciser::ReadInjectSequence::_next() {
  ceph_abort_msg(
      "Should not reach this point, "
      "this sequence should only consume complete sequences");

  return DoneOp::generate();
}

ceph::io_exerciser::Seq10::Seq10(std::pair<int, int> obj_size_range, int seed,
                                 int k, int m)
    : EcIoSequence(obj_size_range, seed),
      offset(0),
      length(1),
      inject_error_done(false),
      failed_write_done(false),
      read_done(false),
      successful_write_done(false),
      test_all_lengths(false),  // Only test length(1) due to time constraints
      test_all_sizes(
          false)  // Only test obj_size(rand()) due to time constraints
{
  select_random_shard_to_inject_write_error(k, m);
  // We will inject specifically as part of our sequence in this sequence
  setup_inject = false;
  if (!test_all_sizes) {
    select_random_object_size();
  }
}

Sequence ceph::io_exerciser::Seq10::get_id() const {
  return Sequence::SEQUENCE_SEQ10;
}

std::string ceph::io_exerciser::Seq10::get_name() const {
  return "Sequential writes of length " + std::to_string(length) +
         " with queue depth 1"
         " first injecting a failed write and read it to ensure it rolls back, "
         "then"
         " successfully writing the data and reading the write the ensure it "
         "is applied";
}

std::unique_ptr<ceph::io_exerciser::IoOp> ceph::io_exerciser::Seq10::_next() {
  if (!inject_error_done) {
    inject_error_done = true;
    return InjectWriteErrorOp::generate(*shard_to_inject, 0, 0,
                                        std::numeric_limits<uint64_t>::max());
  } else if (!failed_write_done) {
    failed_write_done = true;
    read_done = false;
    barrier = true;
    return SingleFailedWriteOp::generate(offset, length);
  } else if (failed_write_done && !read_done) {
    read_done = true;
    barrier = true;
    return SingleReadOp::generate(offset, length);
  } else if (!clear_inject_done) {
    clear_inject_done = true;
    return ClearWriteErrorInjectOp::generate(*shard_to_inject, 0);
  } else if (!successful_write_done) {
    successful_write_done = true;
    read_done = false;
    barrier = true;
    return SingleWriteOp::generate(offset, length);
  } else if (successful_write_done && !read_done) {
    read_done = true;
    return SingleReadOp::generate(offset, length);
  } else if (successful_write_done && read_done) {
    offset++;
    inject_error_done = false;
    failed_write_done = false;
    read_done = false;
    clear_inject_done = false;
    successful_write_done = false;

    if (offset + length >= obj_size) {
      if (!test_all_lengths) {
        remove = true;
        done = true;
        return BarrierOp::generate();
      }

      offset = 0;
      length++;
      if (length > obj_size) {
        if (!test_all_sizes) {
          remove = true;
          done = true;
          return BarrierOp::generate();
        }

        length = 1;
        return increment_object_size();
      }
    }

    return BarrierOp::generate();
  } else {
    ceph_abort_msg("Sequence in undefined state. Aborting");
    return DoneOp::generate();
  }
}