]> git.proxmox.com Git - ceph.git/blob - ceph/src/crimson/osd/osd.h
64f19aac1f7bcf59b4d54cbafe338d4f5489b714
[ceph.git] / ceph / src / crimson / osd / osd.h
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 <seastar/core/future.hh>
7 #include <seastar/core/shared_future.hh>
8 #include <seastar/core/gate.hh>
9 #include <seastar/core/shared_ptr.hh>
10 #include <seastar/core/shared_future.hh>
11 #include <seastar/core/timer.hh>
12
13 #include "crimson/common/type_helpers.h"
14 #include "crimson/common/auth_handler.h"
15 #include "crimson/admin/admin_socket.h"
16 #include "crimson/admin/osd_admin.h"
17 #include "crimson/common/simple_lru.h"
18 #include "crimson/common/shared_lru.h"
19 #include "crimson/mgr/client.h"
20 #include "crimson/net/Dispatcher.h"
21 #include "crimson/osd/chained_dispatchers.h"
22 #include "crimson/osd/osdmap_service.h"
23 #include "crimson/osd/state.h"
24 #include "crimson/osd/shard_services.h"
25 #include "crimson/osd/osdmap_gate.h"
26 #include "crimson/osd/pg_map.h"
27 #include "crimson/osd/osd_operations/peering_event.h"
28
29 #include "osd/PeeringState.h"
30 #include "osd/osd_types.h"
31 #include "osd/osd_perf_counters.h"
32 #include "osd/PGPeeringEvent.h"
33
34 class MOSDMap;
35 class MOSDOp;
36 class MOSDRepOpReply;
37 class MOSDRepOp;
38 class OSDMap;
39 class OSDMeta;
40 class Heartbeat;
41
42 namespace ceph::os {
43 class Transaction;
44 }
45
46 namespace crimson::mon {
47 class Client;
48 }
49
50 namespace crimson::net {
51 class Messenger;
52 }
53
54 namespace crimson::os {
55 class FuturizedStore;
56 }
57
58 namespace crimson::osd {
59 class PG;
60
61 class OSD final : public crimson::net::Dispatcher,
62 private OSDMapService,
63 private crimson::common::AuthHandler,
64 private crimson::mgr::WithStats {
65 seastar::gate gate;
66 const int whoami;
67 const uint32_t nonce;
68 seastar::timer<seastar::lowres_clock> beacon_timer;
69 // talk with osd
70 crimson::net::MessengerRef cluster_msgr;
71 // talk with client/mon/mgr
72 crimson::net::MessengerRef public_msgr;
73 ChainedDispatchers dispatchers;
74 std::unique_ptr<crimson::mon::Client> monc;
75 std::unique_ptr<crimson::mgr::Client> mgrc;
76
77 SharedLRU<epoch_t, OSDMap> osdmaps;
78 SimpleLRU<epoch_t, bufferlist, false> map_bl_cache;
79 cached_map_t osdmap;
80 // TODO: use a wrapper for ObjectStore
81 std::unique_ptr<crimson::os::FuturizedStore> store;
82 std::unique_ptr<OSDMeta> meta_coll;
83
84 OSDState state;
85
86 /// _first_ epoch we were marked up (after this process started)
87 epoch_t boot_epoch = 0;
88 /// _most_recent_ epoch we were marked up
89 epoch_t up_epoch = 0;
90 //< epoch we last did a bind to new ip:ports
91 epoch_t bind_epoch = 0;
92 //< since when there is no more pending pg creates from mon
93 epoch_t last_pg_create_epoch = 0;
94
95 ceph::mono_time startup_time;
96
97 OSDSuperblock superblock;
98
99 // Dispatcher methods
100 seastar::future<> ms_dispatch(crimson::net::Connection* conn, MessageRef m) final;
101 seastar::future<> ms_handle_connect(crimson::net::ConnectionRef conn) final;
102 seastar::future<> ms_handle_reset(crimson::net::ConnectionRef conn) final;
103 seastar::future<> ms_handle_remote_reset(crimson::net::ConnectionRef conn) final;
104
105 // mgr::WithStats methods
106 MessageRef get_stats() final;
107
108 // AuthHandler methods
109 void handle_authentication(const EntityName& name,
110 const AuthCapsInfo& caps) final;
111
112 crimson::osd::ShardServices shard_services;
113
114 std::unique_ptr<Heartbeat> heartbeat;
115 seastar::timer<seastar::lowres_clock> heartbeat_timer;
116
117 // admin-socket
118 seastar::lw_shared_ptr<crimson::admin::AdminSocket> asok;
119
120 public:
121 OSD(int id, uint32_t nonce,
122 crimson::net::MessengerRef cluster_msgr,
123 crimson::net::MessengerRef client_msgr,
124 crimson::net::MessengerRef hb_front_msgr,
125 crimson::net::MessengerRef hb_back_msgr);
126 ~OSD() final;
127
128 seastar::future<> mkfs(uuid_d osd_uuid, uuid_d cluster_fsid);
129
130 seastar::future<> start();
131 seastar::future<> stop();
132
133 void dump_status(Formatter*) const;
134
135 private:
136 seastar::future<> start_boot();
137 seastar::future<> _preboot(version_t oldest_osdmap, version_t newest_osdmap);
138 seastar::future<> _send_boot();
139 seastar::future<> _add_me_to_crush();
140
141 seastar::future<Ref<PG>> make_pg(cached_map_t create_map,
142 spg_t pgid,
143 bool do_create);
144 seastar::future<Ref<PG>> load_pg(spg_t pgid);
145 seastar::future<> load_pgs();
146
147 epoch_t up_thru_wanted = 0;
148 seastar::future<> _send_alive();
149
150 // OSDMapService methods
151 epoch_t get_up_epoch() const final {
152 return up_epoch;
153 }
154 seastar::future<cached_map_t> get_map(epoch_t e) final;
155 cached_map_t get_map() const final;
156 seastar::future<std::unique_ptr<OSDMap>> load_map(epoch_t e);
157 seastar::future<bufferlist> load_map_bl(epoch_t e);
158 void store_map_bl(ceph::os::Transaction& t,
159 epoch_t e, bufferlist&& bl);
160 seastar::future<> store_maps(ceph::os::Transaction& t,
161 epoch_t start, Ref<MOSDMap> m);
162 seastar::future<> osdmap_subscribe(version_t epoch, bool force_request);
163
164 void write_superblock(ceph::os::Transaction& t);
165 seastar::future<> read_superblock();
166
167 bool require_mon_peer(crimson::net::Connection *conn, Ref<Message> m);
168
169 seastar::future<Ref<PG>> handle_pg_create_info(
170 std::unique_ptr<PGCreateInfo> info);
171
172 seastar::future<> handle_osd_map(crimson::net::Connection* conn,
173 Ref<MOSDMap> m);
174 seastar::future<> handle_osd_op(crimson::net::Connection* conn,
175 Ref<MOSDOp> m);
176 seastar::future<> handle_rep_op(crimson::net::Connection* conn,
177 Ref<MOSDRepOp> m);
178 seastar::future<> handle_rep_op_reply(crimson::net::Connection* conn,
179 Ref<MOSDRepOpReply> m);
180 seastar::future<> handle_peering_op(crimson::net::Connection* conn,
181 Ref<MOSDPeeringOp> m);
182
183 seastar::future<> committed_osd_maps(version_t first,
184 version_t last,
185 Ref<MOSDMap> m);
186
187 void check_osdmap_features();
188
189 seastar::future<> start_asok_admin();
190
191 public:
192 OSDMapGate osdmap_gate;
193
194 ShardServices &get_shard_services() {
195 return shard_services;
196 }
197
198 seastar::future<> consume_map(epoch_t epoch);
199
200 private:
201 PGMap pg_map;
202
203 public:
204 blocking_future<Ref<PG>> get_or_create_pg(
205 spg_t pgid,
206 epoch_t epoch,
207 std::unique_ptr<PGCreateInfo> info);
208 blocking_future<Ref<PG>> wait_for_pg(
209 spg_t pgid);
210
211 bool should_restart() const;
212 seastar::future<> restart();
213 seastar::future<> shutdown();
214
215 seastar::future<> send_beacon();
216 seastar::future<> update_heartbeat_peers();
217
218 friend class PGAdvanceMap;
219 };
220
221 }