summaryrefslogtreecommitdiffstats
path: root/src/crimson/osd/object_context_loader.h
blob: 3ab7f6ad80fdc70dba90372c882c439f90351eb9 (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
#pragma once

#include <seastar/core/future.hh>
#include "crimson/common/errorator.h"
#include "crimson/osd/object_context.h"
#include "crimson/osd/pg_backend.h"

namespace crimson::osd {
class ObjectContextLoader {
public:
  using obc_accessing_list_t = boost::intrusive::list<
    ObjectContext,
    ObjectContext::obc_accessing_option_t>;

  ObjectContextLoader(
    ObjectContextRegistry& _obc_services,
    PGBackend& _backend,
    DoutPrefixProvider& dpp)
    : obc_registry{_obc_services},
      backend{_backend},
      dpp{dpp}
    {}

  using load_obc_ertr = crimson::errorator<
    crimson::ct_error::enoent,
    crimson::ct_error::object_corrupted>;
  using load_obc_iertr =
    ::crimson::interruptible::interruptible_errorator<
      ::crimson::osd::IOInterruptCondition,
      load_obc_ertr>;

  using with_obc_func_t =
    std::function<load_obc_iertr::future<> (ObjectContextRef)>;

  using with_both_obc_func_t =
    std::function<load_obc_iertr::future<> (ObjectContextRef, ObjectContextRef)>;

  // Use this variant by default
  template<RWState::State State>
  load_obc_iertr::future<> with_obc(hobject_t oid,
                                    with_obc_func_t&& func);

  // Use this variant in the case where the head object
  // obc is already locked and only the clone obc is needed.
  // Avoid nesting with_head_obc() calls by using with_clone_obc()
  // with an already locked head.
  template<RWState::State State>
  load_obc_iertr::future<> with_clone_obc_only(ObjectContextRef head,
                                               hobject_t oid,
                                               with_obc_func_t&& func);

  // Use this variant in the case where both the head
  // object *and* the matching clone object are being used
  // in func.
  template<RWState::State State>
  load_obc_iertr::future<> with_clone_obc_direct(
    hobject_t oid,
    with_both_obc_func_t&& func);

  load_obc_iertr::future<> reload_obc(ObjectContext& obc) const;

  void notify_on_change(bool is_primary);

private:
  ObjectContextRegistry& obc_registry;
  PGBackend& backend;
  DoutPrefixProvider& dpp;
  obc_accessing_list_t obc_set_accessing;

  template<RWState::State State>
  load_obc_iertr::future<> with_clone_obc(hobject_t oid,
                                          with_obc_func_t&& func);

  template<RWState::State State>
  load_obc_iertr::future<> with_head_obc(ObjectContextRef obc,
                                         bool existed,
                                         with_obc_func_t&& func);

  template<RWState::State State>
  load_obc_iertr::future<ObjectContextRef>
  get_or_load_obc(ObjectContextRef obc,
                  bool existed);

  load_obc_iertr::future<ObjectContextRef>
  load_obc(ObjectContextRef obc);
};
}