1 // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2 // vim: ts=8 sw=2 smarttab
8 #include "crimson/os/futurized_collection.h"
9 #include "crimson/os/futurized_store.h"
12 using std::string_view
;
13 // prefix pgmeta_oid keys with _ so that PGLog::read_log_and_missing() can
15 using crimson::os::FuturizedStore
;
17 PGMeta::PGMeta(FuturizedStore::Shard
& store
, spg_t pgid
)
24 std::optional
<T
> find_value(const FuturizedStore::Shard::omap_values_t
& values
,
27 auto found
= values
.find(key
);
28 if (found
== values
.end()) {
31 auto p
= found
->second
.cbegin();
34 return std::make_optional(std::move(value
));
38 seastar::future
<epoch_t
> PGMeta::get_epoch()
40 return store
.open_collection(coll_t
{pgid
}).then([this](auto ch
) {
41 return store
.omap_get_values(ch
,
42 pgid
.make_pgmeta_oid(),
44 string
{epoch_key
}}).safe_then(
48 auto infover
= find_value
<__u8
>(values
, infover_key
);
51 throw std::runtime_error("incompatible pg meta");
55 auto epoch
= find_value
<epoch_t
>(values
, epoch_key
);
57 return seastar::make_ready_future
<epoch_t
>(*epoch
);
60 FuturizedStore::Shard::read_errorator::assert_all
{
61 "PGMeta::get_epoch: unable to read pgmeta"
66 seastar::future
<std::tuple
<pg_info_t
, PastIntervals
>> PGMeta::load()
68 return store
.open_collection(coll_t
{pgid
}).then([this](auto ch
) {
69 return store
.omap_get_values(ch
,
70 pgid
.make_pgmeta_oid(),
74 string
{fastinfo_key
}});
75 }).safe_then([](auto&& values
) {
78 auto infover
= find_value
<__u8
>(values
, infover_key
);
81 throw std::runtime_error("incompatible pg meta");
86 auto found
= find_value
<pg_info_t
>(values
, info_key
);
88 info
= *std::move(found
);
90 PastIntervals past_intervals
;
92 using biginfo_t
= std::pair
<PastIntervals
, decltype(info
.purged_snaps
)>;
93 auto big_info
= find_value
<biginfo_t
>(values
, biginfo_key
);
95 past_intervals
= std::move(big_info
->first
);
96 info
.purged_snaps
= std::move(big_info
->second
);
99 auto fast_info
= find_value
<pg_fast_info_t
>(values
, fastinfo_key
);
101 fast_info
->try_apply_to(&info
);
104 return seastar::make_ready_future
<std::tuple
<pg_info_t
, PastIntervals
>>(
105 std::make_tuple(std::move(info
), std::move(past_intervals
)));
107 FuturizedStore::Shard::read_errorator::assert_all
{
108 "PGMeta::load: unable to read pgmeta"