for implementing asock commands.
and add `PGMap::get_pg()` as a helper
Signed-off-by: Kefu Chai <kchai@redhat.com>
epoch_t epoch,
std::unique_ptr<PGCreateInfo> info)
{
- auto [fut, creating] = pg_map.get_pg(pgid, bool(info));
- if (!creating && info) {
- pg_map.set_creating(pgid);
- (void)handle_pg_create_info(std::move(info));
+ if (info) {
+ auto [fut, creating] = pg_map.wait_for_pg(pgid);
+ if (!creating) {
+ pg_map.set_creating(pgid);
+ (void)handle_pg_create_info(std::move(info));
+ }
+ return std::move(fut);
+ } else {
+ return make_ready_blocking_future<Ref<PG>>(pg_map.get_pg(pgid));
}
- return std::move(fut);
}
blocking_future<Ref<PG>> OSD::wait_for_pg(
spg_t pgid)
{
- return pg_map.get_pg(pgid).first;
+ return pg_map.wait_for_pg(pgid).first;
+}
+
+Ref<PG> OSD::get_pg(spg_t pgid)
+{
+ return pg_map.get_pg(pgid);
}
seastar::future<> OSD::prepare_to_stop()
std::unique_ptr<PGCreateInfo> info);
blocking_future<Ref<PG>> wait_for_pg(
spg_t pgid);
+ Ref<PG> get_pg(spg_t pgid);
bool should_restart() const;
seastar::future<> restart();
f->dump_bool("creating", creating);
}
-std::pair<blocking_future<Ref<PG>>, bool> PGMap::get_pg(spg_t pgid, bool wait)
+std::pair<blocking_future<Ref<PG>>, bool> PGMap::wait_for_pg(spg_t pgid)
{
- if (auto pg = pgs.find(pgid); pg != pgs.end()) {
- return make_pair(make_ready_blocking_future<Ref<PG>>(pg->second), true);
- } else if (!wait) {
- return make_pair(make_ready_blocking_future<Ref<PG>>(nullptr), true);
+ if (auto pg = get_pg(pgid)) {
+ return make_pair(make_ready_blocking_future<Ref<PG>>(pg), true);
} else {
auto &state = pgs_creating.emplace(pgid, pgid).first->second;
return make_pair(
}
}
+Ref<PG> PGMap::get_pg(spg_t pgid)
+{
+ if (auto pg = pgs.find(pgid); pg != pgs.end()) {
+ return pg->second;
+ } else {
+ return nullptr;
+ }
+}
+
void PGMap::set_creating(spg_t pgid)
{
logger().debug("Creating {}", pgid);
* Get future for pg with a bool indicating whether it's already being
* created.
*/
- std::pair<blocking_future<Ref<PG>>, bool> get_pg(spg_t pgid, bool wait=true);
+ std::pair<blocking_future<Ref<PG>>, bool> wait_for_pg(spg_t pgid);
+
+ /**
+ * get PG in non-blocking manner
+ */
+ Ref<PG> get_pg(spg_t pgid);
/**
* Set creating