]>
Commit | Line | Data |
---|---|---|
9f95a23c TL |
1 | // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- |
2 | // vim: ts=8 sw=2 smarttab | |
3 | ||
4 | #include "crimson/osd/pg_map.h" | |
5 | ||
6 | #include "crimson/osd/pg.h" | |
7 | #include "common/Formatter.h" | |
8 | ||
9 | namespace { | |
10 | seastar::logger& logger() { | |
11 | return crimson::get_logger(ceph_subsys_osd); | |
12 | } | |
13 | } | |
14 | ||
20effc67 TL |
15 | using std::make_pair; |
16 | ||
9f95a23c TL |
17 | namespace crimson::osd { |
18 | ||
19 | PGMap::PGCreationState::PGCreationState(spg_t pgid) : pgid(pgid) {} | |
20 | PGMap::PGCreationState::~PGCreationState() {} | |
21 | ||
22 | void PGMap::PGCreationState::dump_detail(Formatter *f) const | |
23 | { | |
24 | f->dump_stream("pgid") << pgid; | |
25 | f->dump_bool("creating", creating); | |
26 | } | |
27 | ||
1e59de90 TL |
28 | PGMap::wait_for_pg_ret |
29 | PGMap::wait_for_pg(PGCreationBlockingEvent::TriggerI&& trigger, spg_t pgid) | |
9f95a23c | 30 | { |
f67539c2 | 31 | if (auto pg = get_pg(pgid)) { |
1e59de90 TL |
32 | return make_pair( |
33 | wait_for_pg_fut(wait_for_pg_ertr::ready_future_marker{}, pg), | |
34 | true); | |
9f95a23c TL |
35 | } else { |
36 | auto &state = pgs_creating.emplace(pgid, pgid).first->second; | |
37 | return make_pair( | |
1e59de90 TL |
38 | wait_for_pg_fut( |
39 | trigger.maybe_record_blocking(state.promise.get_shared_future(), state) | |
40 | ), state.creating); | |
9f95a23c TL |
41 | } |
42 | } | |
43 | ||
1e59de90 TL |
44 | void PGMap::remove_pg(spg_t pgid) { |
45 | ceph_assert(pgs.erase(pgid) == 1); | |
46 | } | |
47 | ||
f67539c2 TL |
48 | Ref<PG> PGMap::get_pg(spg_t pgid) |
49 | { | |
50 | if (auto pg = pgs.find(pgid); pg != pgs.end()) { | |
51 | return pg->second; | |
52 | } else { | |
53 | return nullptr; | |
54 | } | |
55 | } | |
56 | ||
9f95a23c TL |
57 | void PGMap::set_creating(spg_t pgid) |
58 | { | |
59 | logger().debug("Creating {}", pgid); | |
60 | ceph_assert(pgs.count(pgid) == 0); | |
61 | auto pg = pgs_creating.find(pgid); | |
62 | ceph_assert(pg != pgs_creating.end()); | |
63 | ceph_assert(pg->second.creating == false); | |
64 | pg->second.creating = true; | |
65 | } | |
66 | ||
67 | void PGMap::pg_created(spg_t pgid, Ref<PG> pg) | |
68 | { | |
69 | logger().debug("Created {}", pgid); | |
70 | ceph_assert(!pgs.count(pgid)); | |
71 | pgs.emplace(pgid, pg); | |
72 | ||
1e59de90 TL |
73 | auto creating_iter = pgs_creating.find(pgid); |
74 | ceph_assert(creating_iter != pgs_creating.end()); | |
75 | auto promise = std::move(creating_iter->second.promise); | |
76 | pgs_creating.erase(creating_iter); | |
77 | promise.set_value(pg); | |
9f95a23c TL |
78 | } |
79 | ||
80 | void PGMap::pg_loaded(spg_t pgid, Ref<PG> pg) | |
81 | { | |
82 | ceph_assert(!pgs.count(pgid)); | |
83 | pgs.emplace(pgid, pg); | |
84 | } | |
85 | ||
1e59de90 TL |
86 | void PGMap::pg_creation_canceled(spg_t pgid) |
87 | { | |
88 | logger().debug("PGMap::pg_creation_canceled: {}", pgid); | |
89 | ceph_assert(!pgs.count(pgid)); | |
90 | ||
91 | auto creating_iter = pgs_creating.find(pgid); | |
92 | ceph_assert(creating_iter != pgs_creating.end()); | |
93 | auto promise = std::move(creating_iter->second.promise); | |
94 | pgs_creating.erase(creating_iter); | |
95 | promise.set_exception( | |
96 | crimson::ct_error::ecanceled::exception_ptr() | |
97 | ); | |
98 | } | |
99 | ||
9f95a23c TL |
100 | PGMap::~PGMap() {} |
101 | ||
102 | } |