summaryrefslogtreecommitdiffstats
path: root/src/crimson/osd/pg_interval_interrupt_condition.h
blob: a3a0a1edbcf5aa90298199ba9f8461a42c9bcf78 (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
// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:nil -*-
// vim: ts=8 sw=2 smarttab expandtab

#pragma once

#include "include/types.h"
#include "crimson/common/errorator.h"
#include "crimson/common/exception.h"
#include "crimson/common/type_helpers.h"

namespace crimson::osd {

class PG;

class IOInterruptCondition {
public:
  IOInterruptCondition(Ref<PG>& pg);
  ~IOInterruptCondition();

  bool new_interval_created();

  bool is_stopping();

  bool is_primary();

  template <typename Fut>
  std::optional<Fut> may_interrupt() {
    if (new_interval_created()) {
      return seastar::futurize<Fut>::make_exception_future(
        ::crimson::common::actingset_changed(is_primary()));
    }
    if (is_stopping()) {
      return seastar::futurize<Fut>::make_exception_future(
        ::crimson::common::system_shutdown_exception());
    }
    return std::optional<Fut>();
  }

  template <typename T>
  static constexpr bool is_interruption_v =
    std::is_same_v<T, ::crimson::common::actingset_changed>
    || std::is_same_v<T, ::crimson::common::system_shutdown_exception>;

  static bool is_interruption(std::exception_ptr& eptr) {
    return (*eptr.__cxa_exception_type() ==
            typeid(::crimson::common::actingset_changed) ||
            *eptr.__cxa_exception_type() ==
            typeid(::crimson::common::system_shutdown_exception));
  }

private:
  Ref<PG> pg;
  epoch_t e;
};

} // namespace crimson::osd