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
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
|
// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
// vim: ts=8 sw=2 smarttab
#pragma once
#include <map>
#include <optional>
#include <string>
#include <typeinfo>
#include <unordered_map>
#include <vector>
#include <seastar/core/future.hh>
#include <seastar/core/lowres_clock.hh>
#include <seastar/core/metrics_types.hh>
#include "include/uuid.h"
#include "os/Transaction.h"
#include "crimson/common/throttle.h"
#include "crimson/os/futurized_collection.h"
#include "crimson/os/futurized_store.h"
#include "crimson/os/seastore/device.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"
#include "crimson/os/seastore/object_data_handler.h"
namespace crimson::os::seastore {
class Onode;
using OnodeRef = boost::intrusive_ptr<Onode>;
class TransactionManager;
enum class op_type_t : uint8_t {
DO_TRANSACTION = 0,
READ,
WRITE,
GET_ATTR,
GET_ATTRS,
STAT,
OMAP_GET_VALUES,
OMAP_GET_VALUES2,
MAX
};
class SeastoreCollection final : public FuturizedCollection {
public:
template <typename... T>
SeastoreCollection(T&&... args) :
FuturizedCollection(std::forward<T>(args)...) {}
seastar::shared_mutex ordering_lock;
};
/**
* col_obj_ranges_t
*
* Represents the two ghobject_t ranges spanned by a PG collection.
* Temp objects will be within [temp_begin, temp_end) and normal objects
* will be in [obj_begin, obj_end).
*/
struct col_obj_ranges_t {
ghobject_t temp_begin;
ghobject_t temp_end;
ghobject_t obj_begin;
ghobject_t obj_end;
};
class SeaStore final : public FuturizedStore {
public:
using base_ertr = TransactionManager::base_ertr;
using base_iertr = TransactionManager::base_iertr;
class MDStore {
public:
using write_meta_ertr = base_ertr;
using write_meta_ret = write_meta_ertr::future<>;
virtual write_meta_ret write_meta(
const std::string &key,
const std::string &val
) = 0;
using read_meta_ertr = base_ertr;
using read_meta_ret = write_meta_ertr::future<std::optional<std::string>>;
virtual read_meta_ret read_meta(const std::string &key) = 0;
virtual ~MDStore() {}
};
using MDStoreRef = std::unique_ptr<MDStore>;
class Shard : public FuturizedStore::Shard {
public:
Shard(
std::string root,
Device* device,
bool is_test);
~Shard() = default;
seastar::future<struct stat> stat(
CollectionRef c,
const ghobject_t& oid) 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;
base_errorator::future<bool> exists(
CollectionRef c,
const ghobject_t& oid) 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;
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)
read_errorator::future<omap_values_paged_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
get_attr_errorator::future<bufferlist> omap_get_header(
CollectionRef c,
const ghobject_t& oid) final;
/// std::get<1>(ret) returns end if and only if the listing has listed all
/// the items within the range, otherwise it returns the next key to be listed.
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<> set_collection_opts(CollectionRef c,
const pool_opts_t& opts) final;
seastar::future<> do_transaction_no_callbacks(
CollectionRef ch,
ceph::os::Transaction&& txn) final;
/* Note, flush() machinery must go through the same pipeline
* stages and locks as do_transaction. */
seastar::future<> flush(CollectionRef ch) final;
read_errorator::future<fiemap_ret_t> fiemap(
CollectionRef ch,
const ghobject_t& oid,
uint64_t off,
uint64_t len) final;
unsigned get_max_attr_name_length() const final {
return 256;
}
// only exposed to SeaStore
public:
seastar::future<> umount();
// init managers and mount transaction_manager
seastar::future<> mount_managers();
void set_secondaries(Device& sec_dev) {
secondaries.emplace_back(&sec_dev);
}
seastar::future<std::vector<coll_core_t>> list_collections();
seastar::future<> write_meta(const std::string& key,
const std::string& value);
seastar::future<std::string> get_default_device_class();
store_statfs_t stat() const;
uuid_d get_fsid() const;
seastar::future<> mkfs_managers();
void init_managers();
double reset_report_interval() const;
device_stats_t get_device_stats(bool report_detail, double seconds) const;
shard_stats_t get_io_stats(bool report_detail, double seconds) const;
cache_stats_t get_cache_stats(bool report_detail, double seconds) const;
private:
struct internal_context_t {
CollectionRef ch;
ceph::os::Transaction ext_transaction;
internal_context_t(
CollectionRef ch,
ceph::os::Transaction &&_ext_transaction,
TransactionRef &&transaction)
: ch(ch), ext_transaction(std::move(_ext_transaction)),
transaction(std::move(transaction)),
iter(ext_transaction.begin()) {}
TransactionRef transaction;
ceph::os::Transaction::iterator iter;
std::chrono::steady_clock::time_point begin_timestamp = std::chrono::steady_clock::now();
void reset_preserve_handle(TransactionManager &tm) {
tm.reset_transaction_preserve_handle(*transaction);
iter = ext_transaction.begin();
}
};
TransactionManager::read_extent_iertr::future<std::optional<unsigned>>
get_coll_bits(CollectionRef ch, Transaction &t) const;
static void on_error(ceph::os::Transaction &t);
template <typename F>
auto repeat_with_internal_context(
CollectionRef ch,
ceph::os::Transaction &&t,
Transaction::src_t src,
const char* tname,
op_type_t op_type,
F &&f) {
// The below repeat_io_num requires MUTATE
assert(src == Transaction::src_t::MUTATE);
return seastar::do_with(
internal_context_t(
ch, std::move(t),
transaction_manager->create_transaction(src, tname)),
std::forward<F>(f),
[this, op_type](auto &ctx, auto &f) {
assert(shard_stats.starting_io_num);
--(shard_stats.starting_io_num);
++(shard_stats.waiting_collock_io_num);
return ctx.transaction->get_handle().take_collection_lock(
static_cast<SeastoreCollection&>(*(ctx.ch)).ordering_lock
).then([this] {
assert(shard_stats.waiting_collock_io_num);
--(shard_stats.waiting_collock_io_num);
++(shard_stats.waiting_throttler_io_num);
return throttler.get(1);
}).then([&, this] {
assert(shard_stats.waiting_throttler_io_num);
--(shard_stats.waiting_throttler_io_num);
++(shard_stats.processing_inlock_io_num);
return repeat_eagain([&, this] {
++(shard_stats.repeat_io_num);
ctx.reset_preserve_handle(*transaction_manager);
return std::invoke(f, ctx);
}).handle_error(
crimson::ct_error::all_same_way([&ctx](auto e) {
on_error(ctx.ext_transaction);
return seastar::now();
})
);
}).then([this, op_type, &ctx] {
add_latency_sample(op_type,
std::chrono::steady_clock::now() - ctx.begin_timestamp);
}).finally([this] {
throttler.put();
});
});
}
template <typename Ret, typename F>
auto repeat_with_onode(
CollectionRef ch,
const ghobject_t &oid,
Transaction::src_t src,
const char* tname,
op_type_t op_type,
F &&f) const {
auto begin_time = std::chrono::steady_clock::now();
return seastar::do_with(
oid, Ret{}, std::forward<F>(f),
[this, ch, src, op_type, begin_time, tname
](auto &oid, auto &ret, auto &f)
{
return repeat_eagain([&, this, ch, src, tname] {
assert(src == Transaction::src_t::READ);
++(shard_stats.repeat_read_num);
return transaction_manager->with_transaction_intr(
src,
tname,
[&, this, ch, tname](auto& t)
{
LOG_PREFIX(SeaStoreS::repeat_with_onode);
SUBDEBUGT(seastore, "{} cid={} oid={} ...",
t, tname, ch->get_cid(), oid);
return onode_manager->get_onode(t, oid
).si_then([&](auto onode) {
return seastar::do_with(std::move(onode), [&](auto& onode) {
return f(t, *onode);
});
}).si_then([&ret](auto _ret) {
ret = _ret;
});
});
}).safe_then([&ret, op_type, begin_time, this] {
const_cast<Shard*>(this)->add_latency_sample(op_type,
std::chrono::steady_clock::now() - begin_time);
return seastar::make_ready_future<Ret>(ret);
});
});
}
using omap_list_bare_ret = OMapManager::omap_list_bare_ret;
using omap_list_ret = OMapManager::omap_list_ret;
omap_list_ret omap_list(
Onode& onode,
const omap_root_le_t& omap_root,
Transaction& t,
const std::optional<std::string>& start,
OMapManager::omap_list_config_t config) const;
using _omap_get_value_iertr = base_iertr::extend<
crimson::ct_error::enodata
>;
using _omap_get_value_ret = _omap_get_value_iertr::future<ceph::bufferlist>;
_omap_get_value_ret _omap_get_value(
Transaction &t,
omap_root_t &&root,
std::string_view key) const;
base_iertr::future<omap_values_t> _omap_get_values(
Transaction &t,
omap_root_t &&root,
const omap_keys_t &keys) const;
friend class SeaStoreOmapIterator;
base_iertr::future<ceph::bufferlist> _read(
Transaction& t,
Onode& onode,
uint64_t offset,
std::size_t len,
uint32_t op_flags);
_omap_get_value_ret _get_attr(
Transaction& t,
Onode& onode,
std::string_view name) const;
base_iertr::future<attrs_t> _get_attrs(
Transaction& t,
Onode& onode);
seastar::future<struct stat> _stat(
Transaction& t,
Onode& onode,
const ghobject_t& oid);
base_iertr::future<omap_values_t> do_omap_get_values(
Transaction& t,
Onode& onode,
const omap_keys_t& keys);
base_iertr::future<omap_values_paged_t> do_omap_get_values(
Transaction& t,
Onode& onode,
const std::optional<std::string>& start);
base_iertr::future<fiemap_ret_t> _fiemap(
Transaction &t,
Onode &onode,
uint64_t off,
uint64_t len) const;
using tm_iertr = base_iertr;
using tm_ret = tm_iertr::future<>;
tm_ret _do_transaction_step(
internal_context_t &ctx,
CollectionRef &col,
std::vector<OnodeRef> &onodes,
std::vector<OnodeRef> &d_onodes,
ceph::os::Transaction::iterator &i);
tm_ret _remove_omaps(
internal_context_t &ctx,
OnodeRef &onode,
omap_root_t &&omap_root);
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);
enum class omap_type_t : uint8_t {
XATTR = 0,
OMAP,
NUM_TYPES
};
tm_ret _clone_omaps(
internal_context_t &ctx,
OnodeRef &onode,
OnodeRef &d_onode,
const omap_type_t otype);
tm_ret _clone(
internal_context_t &ctx,
OnodeRef &onode,
OnodeRef &d_onode);
tm_ret _rename(
internal_context_t &ctx,
OnodeRef &onode,
OnodeRef &d_onode);
tm_ret _zero(
internal_context_t &ctx,
OnodeRef &onode,
objaddr_t offset, extent_len_t len);
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_clear(
internal_context_t &ctx,
OnodeRef &onode);
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 _rmattr(
internal_context_t &ctx,
OnodeRef &onode,
std::string name);
tm_ret _rmattrs(
internal_context_t &ctx,
OnodeRef &onode);
tm_ret _xattr_rmattr(
internal_context_t &ctx,
OnodeRef &onode,
std::string &&name);
tm_ret _xattr_clear(
internal_context_t &ctx,
OnodeRef &onode);
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_iertr::future<omap_root_t>;
omap_set_kvs_ret _omap_set_kvs(
const OnodeRef &onode,
const omap_root_le_t& omap_root,
Transaction& t,
std::map<std::string, ceph::bufferlist>&& kvs);
boost::intrusive_ptr<SeastoreCollection> _get_collection(const coll_t& cid);
static constexpr auto LAT_MAX = static_cast<std::size_t>(op_type_t::MAX);
struct {
std::array<seastar::metrics::histogram, LAT_MAX> op_lat;
} stats;
seastar::metrics::histogram& get_latency(
op_type_t op_type) {
assert(static_cast<std::size_t>(op_type) < stats.op_lat.size());
return stats.op_lat[static_cast<std::size_t>(op_type)];
}
void add_latency_sample(op_type_t op_type,
std::chrono::steady_clock::duration dur) {
seastar::metrics::histogram& lat = get_latency(op_type);
lat.sample_count++;
lat.sample_sum += std::chrono::duration_cast<std::chrono::milliseconds>(dur).count();
}
private:
std::string root;
Device* device;
const uint32_t max_object_size;
bool is_test;
std::vector<Device*> secondaries;
TransactionManagerRef transaction_manager;
CollectionManagerRef collection_manager;
OnodeManagerRef onode_manager;
common::Throttle throttler;
seastar::metrics::metric_group metrics;
void register_metrics();
mutable shard_stats_t shard_stats;
mutable seastar::lowres_clock::time_point last_tp =
seastar::lowres_clock::time_point::min();
mutable shard_stats_t last_shard_stats;
};
public:
SeaStore(
const std::string& root,
MDStoreRef mdstore);
~SeaStore();
seastar::future<> start() final;
seastar::future<> stop() final;
mount_ertr::future<> mount() final;
seastar::future<> umount() final;
mkfs_ertr::future<> mkfs(uuid_d new_osd_fsid) final;
seastar::future<store_statfs_t> stat() const final;
seastar::future<store_statfs_t> pool_statfs(int64_t pool_id) const final;
seastar::future<> report_stats() final;
uuid_d get_fsid() const final {
ceph_assert(seastar::this_shard_id() == primary_core);
return shard_stores.local().get_fsid();
}
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;
seastar::future<std::vector<coll_core_t>> list_collections() final;
seastar::future<std::string> get_default_device_class() final;
FuturizedStore::Shard& get_sharded_store() final {
return shard_stores.local();
}
static col_obj_ranges_t
get_objs_range(CollectionRef ch, unsigned bits);
// for test
public:
mount_ertr::future<> test_mount();
mkfs_ertr::future<> test_mkfs(uuid_d new_osd_fsid);
DeviceRef get_primary_device_ref() {
return std::move(device);
}
seastar::future<> test_start(DeviceRef dev);
private:
seastar::future<> write_fsid(uuid_d new_osd_fsid);
seastar::future<> prepare_meta(uuid_d new_osd_fsid);
seastar::future<> set_secondaries();
private:
std::string root;
MDStoreRef mdstore;
DeviceRef device;
std::vector<DeviceRef> secondaries;
seastar::sharded<SeaStore::Shard> shard_stores;
mutable seastar::lowres_clock::time_point last_tp =
seastar::lowres_clock::time_point::min();
mutable std::vector<device_stats_t> shard_device_stats;
mutable std::vector<shard_stats_t> shard_io_stats;
mutable std::vector<cache_stats_t> shard_cache_stats;
};
std::unique_ptr<SeaStore> make_seastore(
const std::string &device);
std::unique_ptr<SeaStore> make_test_seastore(
SeaStore::MDStoreRef mdstore);
}
|