summaryrefslogtreecommitdiffstats
path: root/src/crimson/os/seastore/seastore.h
blob: f53ad97dcc5185fbac7f14c63cd8cf6288beb52a (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
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
// vim: ts=8 sw=2 smarttab

#pragma once

#include <string>
#include <unordered_map>
#include <map>
#include <typeinfo>
#include <vector>

#include <optional>
#include <seastar/core/future.hh>

#include "include/uuid.h"

#include "os/Transaction.h"
#include "crimson/os/futurized_collection.h"
#include "crimson/os/futurized_store.h"
#include "crimson/os/seastore/transaction.h"
#include "crimson/os/seastore/onode_manager.h"
#include "crimson/os/seastore/omap_manager.h"
#include "crimson/os/seastore/collection_manager.h"

namespace crimson::os::seastore {

class SeastoreCollection;
class Onode;
using OnodeRef = boost::intrusive_ptr<Onode>;
class TransactionManager;

class SeaStore final : public FuturizedStore {
  uuid_d osd_fsid;

public:

  SeaStore(
    TransactionManagerRef tm,
    CollectionManagerRef cm,
    OnodeManagerRef om
  ) : transaction_manager(std::move(tm)),
      collection_manager(std::move(cm)),
      onode_manager(std::move(om)) {}

  ~SeaStore();
    
  seastar::future<> stop() final;
  seastar::future<> mount() final;
  seastar::future<> umount() final;

  seastar::future<> mkfs(uuid_d new_osd_fsid) final;
  seastar::future<store_statfs_t> stat() const final;

  read_errorator::future<ceph::bufferlist> read(
    CollectionRef c,
    const ghobject_t& oid,
    uint64_t offset,
    size_t len,
    uint32_t op_flags = 0) final;
  read_errorator::future<ceph::bufferlist> readv(
    CollectionRef c,
    const ghobject_t& oid,
    interval_set<uint64_t>& m,
    uint32_t op_flags = 0) final;
  get_attr_errorator::future<ceph::bufferlist> get_attr(
    CollectionRef c,
    const ghobject_t& oid,
    std::string_view name) const final;
  get_attrs_ertr::future<attrs_t> get_attrs(
    CollectionRef c,
    const ghobject_t& oid) final;

  seastar::future<struct stat> stat(
    CollectionRef c,
    const ghobject_t& oid) final;

  read_errorator::future<omap_values_t> omap_get_values(
    CollectionRef c,
    const ghobject_t& oid,
    const omap_keys_t& keys) final;

  /// Retrieves paged set of values > start (if present)
  using omap_get_values_ret_bare_t = std::tuple<bool, omap_values_t>;
  using omap_get_values_ret_t = read_errorator::future<
    omap_get_values_ret_bare_t>;
  omap_get_values_ret_t omap_get_values(
    CollectionRef c,           ///< [in] collection
    const ghobject_t &oid,     ///< [in] oid
    const std::optional<std::string> &start ///< [in] start, empty for begin
    ) final; ///< @return <done, values> values.empty() iff done

  read_errorator::future<bufferlist> omap_get_header(
    CollectionRef c,
    const ghobject_t& oid) final;

  seastar::future<std::tuple<std::vector<ghobject_t>, ghobject_t>> list_objects(
    CollectionRef c,
    const ghobject_t& start,
    const ghobject_t& end,
    uint64_t limit) const final;

  seastar::future<CollectionRef> create_new_collection(const coll_t& cid) final;
  seastar::future<CollectionRef> open_collection(const coll_t& cid) final;
  seastar::future<std::vector<coll_t>> list_collections() final;

  seastar::future<> do_transaction(
    CollectionRef ch,
    ceph::os::Transaction&& txn) final;

  seastar::future<OmapIteratorRef> get_omap_iterator(
    CollectionRef ch,
    const ghobject_t& oid) final;
  seastar::future<std::map<uint64_t, uint64_t>> fiemap(
    CollectionRef ch,
    const ghobject_t& oid,
    uint64_t off,
    uint64_t len) final;

  seastar::future<> write_meta(const std::string& key,
		  const std::string& value) final;
  seastar::future<std::tuple<int, std::string>> read_meta(const std::string& key) final;
  uuid_d get_fsid() const final;

  unsigned get_max_attr_name_length() const final {
    return 256;
  }

private:
  struct internal_context_t {
    CollectionRef ch;
    ceph::os::Transaction ext_transaction;

    internal_context_t(
      CollectionRef ch,
      ceph::os::Transaction &&_ext_transaction)
      : ch(ch), ext_transaction(std::move(_ext_transaction)),
	iter(ext_transaction.begin()) {}

    TransactionRef transaction;
    std::vector<OnodeRef> onodes;

    ceph::os::Transaction::iterator iter;

    void reset(TransactionRef &&t) {
      transaction = std::move(t);
      onodes.clear();
      iter = ext_transaction.begin();
    }
  };

  static void on_error(ceph::os::Transaction &t);

  template <typename F>
  auto repeat_with_internal_context(
    CollectionRef ch,
    ceph::os::Transaction &&t,
    F &&f) {
    return seastar::do_with(
      internal_context_t{ ch, std::move(t) },
      std::forward<F>(f),
      [this](auto &ctx, auto &f) {
	return repeat_eagain([&]() {
	  ctx.reset(transaction_manager->create_transaction());
	  return std::invoke(f, ctx);
	}).handle_error(
	  crimson::ct_error::eagain::pass_further{},
	  crimson::ct_error::all_same_way([&ctx](auto e) {
	    on_error(ctx.ext_transaction);
	  })
	);
      });
  }

  template <typename Ret, typename F>
  auto repeat_with_onode(
    CollectionRef ch,
    const ghobject_t &oid,
    F &&f) {
    return seastar::do_with(
      oid,
      Ret{},
      TransactionRef(),
      OnodeRef(),
      std::forward<F>(f),
      [=](auto &oid, auto &ret, auto &t, auto &onode, auto &f) {
	return repeat_eagain([&, this] {
	  t = transaction_manager->create_transaction();
	  return onode_manager->get_onode(
	    *t, oid
	  ).safe_then([&, this](auto onode_ret) {
	    onode = std::move(onode_ret);
	    return f(*t, *onode);
	  }).safe_then([&ret](auto _ret) {
	    ret = _ret;
	  });
	}).safe_then([&ret] {
	  return seastar::make_ready_future<Ret>(ret);
	});
      });
  }


  template <typename Ret, typename F>
  auto repeat_with_onode(
    CollectionRef ch,
    const ghobject_t &oid,
    F &&f) const {
    return seastar::do_with(
      oid,
      Ret{},
      TransactionRef(),
      OnodeRef(),
      std::forward<F>(f),
      [=](auto &oid, auto &ret, auto &t, auto &onode, auto &f) {
	return repeat_eagain([&, this] {
	  t = transaction_manager->create_transaction();
	  return onode_manager->get_onode(
	    *t, oid
	  ).safe_then([&, this](auto onode_ret) {
	    onode = std::move(onode_ret);
	    return f(*t, *onode);
	  }).safe_then([&ret](auto _ret) {
	    ret = _ret;
	  });
	}).safe_then([&ret] {
	  return seastar::make_ready_future<Ret>(ret);
	});
      });
  }


  friend class SeaStoreOmapIterator;
  omap_get_values_ret_t omap_list(
    CollectionRef ch,
    const ghobject_t &oid,
    const std::optional<string> &_start,
    OMapManager::omap_list_config_t config);
  OMapManager::omap_list_ret _omap_list(
    const omap_root_le_t& omap_root,
    Transaction& t,
    const std::optional<std::string>& start,
    OMapManager::omap_list_config_t config);

  TransactionManagerRef transaction_manager;
  CollectionManagerRef collection_manager;
  OnodeManagerRef onode_manager;

  using tm_ertr = TransactionManager::base_ertr;
  using tm_ret = tm_ertr::future<>;
  tm_ret _do_transaction_step(
    internal_context_t &ctx,
    CollectionRef &col,
    std::vector<OnodeRef> &onodes,
    ceph::os::Transaction::iterator &i);

  tm_ret _remove(
    internal_context_t &ctx,
    OnodeRef &onode);
  tm_ret _touch(
    internal_context_t &ctx,
    OnodeRef &onode);
  tm_ret _write(
    internal_context_t &ctx,
    OnodeRef &onode,
    uint64_t offset, size_t len,
    ceph::bufferlist &&bl,
    uint32_t fadvise_flags);
  tm_ret _omap_set_values(
    internal_context_t &ctx,
    OnodeRef &onode,
    std::map<std::string, ceph::bufferlist> &&aset);
  tm_ret _omap_set_header(
    internal_context_t &ctx,
    OnodeRef &onode,
    ceph::bufferlist &&header);
  tm_ret _omap_rmkeys(
    internal_context_t &ctx,
    OnodeRef &onode,
    omap_keys_t &&aset);
  tm_ret _omap_rmkeyrange(
    internal_context_t &ctx,
    OnodeRef &onode,
    std::string first,
    std::string last);
  tm_ret _truncate(
    internal_context_t &ctx,
    OnodeRef &onode, uint64_t size);
  tm_ret _setattrs(
    internal_context_t &ctx,
    OnodeRef &onode,
    std::map<std::string,bufferlist>&& aset);
  tm_ret _create_collection(
    internal_context_t &ctx,
    const coll_t& cid, int bits);
  tm_ret _remove_collection(
    internal_context_t &ctx,
    const coll_t& cid);
  using omap_set_kvs_ret = tm_ertr::future<>;
  omap_set_kvs_ret __omap_set_kvs(
    const omap_root_le_t& omap_root,
    Transaction& t,
    omap_root_le_t& mutable_omap_root,
    std::map<std::string, ceph::bufferlist>&& kvs);

  boost::intrusive_ptr<SeastoreCollection> _get_collection(const coll_t& cid);
};

}