]> git.proxmox.com Git - ceph.git/blame - ceph/src/crimson/osd/osdmap_gate.h
update ceph source to reef 18.1.2
[ceph.git] / ceph / src / crimson / osd / osdmap_gate.h
CommitLineData
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#pragma once
5
6#include <functional>
7#include <map>
8#include <optional>
9
10#include <seastar/core/future.hh>
11#include <seastar/core/shared_future.hh>
12
13#include "include/types.h"
14#include "crimson/osd/osd_operation.h"
15
16namespace ceph {
17 class Formatter;
18}
19
20namespace crimson::osd {
21
22class ShardServices;
23
1e59de90
TL
24enum class OSDMapGateType {
25 OSD,
26 PG,
27};
28
29template <OSDMapGateType OSDMapGateTypeV>
9f95a23c 30class OSDMapGate {
1e59de90
TL
31public:
32 struct OSDMapBlocker : BlockerT<OSDMapBlocker> {
9f95a23c
TL
33 const char * type_name;
34 epoch_t epoch;
35
36 OSDMapBlocker(std::pair<const char *, epoch_t> args)
37 : type_name(args.first), epoch(args.second) {}
38
39 OSDMapBlocker(const OSDMapBlocker &) = delete;
40 OSDMapBlocker(OSDMapBlocker &&) = delete;
41 OSDMapBlocker &operator=(const OSDMapBlocker &) = delete;
42 OSDMapBlocker &operator=(OSDMapBlocker &&) = delete;
43
44 seastar::shared_promise<epoch_t> promise;
45
46 void dump_detail(Formatter *f) const final;
9f95a23c 47 };
1e59de90 48 using Blocker = OSDMapBlocker;
9f95a23c 49
1e59de90 50private:
f67539c2 51 // order the promises in ascending order of the waited osdmap epoch,
9f95a23c 52 // so we can access all the waiters expecting a map whose epoch is less
f67539c2 53 // than or equal to a given epoch
9f95a23c 54 using waiting_peering_t = std::map<epoch_t,
f67539c2 55 OSDMapBlocker>;
9f95a23c
TL
56 const char *blocker_type;
57 waiting_peering_t waiting_peering;
58 epoch_t current = 0;
f67539c2 59 bool stopping = false;
9f95a23c 60public:
1e59de90
TL
61 OSDMapGate(const char *blocker_type)
62 : blocker_type(blocker_type) {}
9f95a23c 63
1e59de90
TL
64 /**
65 * wait_for_map
66 *
67 * Wait for an osdmap whose epoch is greater or equal to given epoch.
68 * If shard_services is non-null, request map if not present.
69 */
70 seastar::future<epoch_t>
71 wait_for_map(
72 typename OSDMapBlocker::BlockingEvent::TriggerI&& trigger,
73 epoch_t epoch,
74 ShardServices *shard_services=nullptr
75 );
9f95a23c 76 void got_map(epoch_t epoch);
f67539c2 77 seastar::future<> stop();
9f95a23c
TL
78};
79
1e59de90
TL
80using OSD_OSDMapGate = OSDMapGate<OSDMapGateType::OSD>;
81using PG_OSDMapGate = OSDMapGate<OSDMapGateType::PG>;
82
9f95a23c 83}