1 // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2 // vim: ts=8 sw=2 smarttab
6 #include <seastar/core/abort_source.hh>
7 #include <seastar/core/future.hh>
8 #include <seastar/core/shared_future.hh>
9 #include <seastar/core/gate.hh>
10 #include <seastar/core/shared_ptr.hh>
11 #include <seastar/core/shared_future.hh>
12 #include <seastar/core/timer.hh>
14 #include "crimson/common/logclient.h"
15 #include "crimson/common/type_helpers.h"
16 #include "crimson/common/auth_handler.h"
17 #include "crimson/common/gated.h"
18 #include "crimson/admin/admin_socket.h"
19 #include "crimson/common/simple_lru.h"
20 #include "crimson/mgr/client.h"
21 #include "crimson/net/Dispatcher.h"
22 #include "crimson/osd/osdmap_service.h"
23 #include "crimson/osd/pg_shard_manager.h"
24 #include "crimson/osd/osdmap_gate.h"
25 #include "crimson/osd/pg_map.h"
26 #include "crimson/osd/osd_operations/peering_event.h"
28 #include "messages/MOSDOp.h"
29 #include "osd/PeeringState.h"
30 #include "osd/osd_types.h"
31 #include "osd/osd_perf_counters.h"
32 #include "osd/PGPeeringEvent.h"
46 namespace crimson::mon
{
50 namespace crimson::net
{
54 namespace crimson::os
{
58 namespace crimson::osd
{
61 class OSD final
: public crimson::net::Dispatcher
,
62 private crimson::common::AuthHandler
,
63 private crimson::mgr::WithStats
{
66 seastar::abort_source
& abort_source
;
67 seastar::timer
<seastar::lowres_clock
> beacon_timer
;
69 crimson::net::MessengerRef cluster_msgr
;
70 // talk with client/mon/mgr
71 crimson::net::MessengerRef public_msgr
;
74 crimson::net::MessengerRef hb_front_msgr
;
75 crimson::net::MessengerRef hb_back_msgr
;
77 std::unique_ptr
<crimson::mon::Client
> monc
;
78 std::unique_ptr
<crimson::mgr::Client
> mgrc
;
80 // TODO: use a wrapper for ObjectStore
81 OSDMapService::cached_map_t osdmap
;
82 crimson::os::FuturizedStore
& store
;
84 /// _first_ epoch we were marked up (after this process started)
85 epoch_t boot_epoch
= 0;
86 //< epoch we last did a bind to new ip:ports
87 epoch_t bind_epoch
= 0;
88 //< since when there is no more pending pg creates from mon
89 epoch_t last_pg_create_epoch
= 0;
91 ceph::mono_time startup_time
;
93 OSDSuperblock superblock
;
96 std::optional
<seastar::future
<>> ms_dispatch(crimson::net::ConnectionRef
, MessageRef
) final
;
97 void ms_handle_reset(crimson::net::ConnectionRef conn
, bool is_replace
) final
;
98 void ms_handle_remote_reset(crimson::net::ConnectionRef conn
) final
;
100 // mgr::WithStats methods
101 // pg statistics including osd ones
103 uint32_t osd_stat_seq
= 0;
105 seastar::future
<MessageURef
> get_stats() const final
;
107 // AuthHandler methods
108 void handle_authentication(const EntityName
& name
,
109 const AuthCapsInfo
& caps
) final
;
111 crimson::osd::PGShardManager pg_shard_manager
;
113 std::unique_ptr
<Heartbeat
> heartbeat
;
114 seastar::timer
<seastar::lowres_clock
> tick_timer
;
117 seastar::lw_shared_ptr
<crimson::admin::AdminSocket
> asok
;
120 OSD(int id
, uint32_t nonce
,
121 seastar::abort_source
& abort_source
,
122 crimson::os::FuturizedStore
& store
,
123 crimson::net::MessengerRef cluster_msgr
,
124 crimson::net::MessengerRef client_msgr
,
125 crimson::net::MessengerRef hb_front_msgr
,
126 crimson::net::MessengerRef hb_back_msgr
);
129 seastar::future
<> open_meta_coll();
130 static seastar::future
<OSDMeta
> open_or_create_meta_coll(
131 crimson::os::FuturizedStore
&store
133 static seastar::future
<> mkfs(
134 crimson::os::FuturizedStore
&store
,
138 std::string osdspec_affinity
);
140 seastar::future
<> start();
141 seastar::future
<> stop();
143 void dump_status(Formatter
*) const;
144 void print(std::ostream
&) const;
146 /// @return the seq id of the pg stats being sent
147 uint64_t send_pg_stats();
150 static seastar::future
<> _write_superblock(
151 crimson::os::FuturizedStore
&store
,
153 OSDSuperblock superblock
);
154 static seastar::future
<> _write_key_meta(
155 crimson::os::FuturizedStore
&store
157 seastar::future
<> start_boot();
158 seastar::future
<> _preboot(version_t oldest_osdmap
, version_t newest_osdmap
);
159 seastar::future
<> _send_boot();
160 seastar::future
<> _add_me_to_crush();
162 seastar::future
<> osdmap_subscribe(version_t epoch
, bool force_request
);
164 void write_superblock(ceph::os::Transaction
& t
);
165 seastar::future
<> read_superblock();
167 bool require_mon_peer(crimson::net::Connection
*conn
, Ref
<Message
> m
);
169 seastar::future
<> handle_osd_map(crimson::net::ConnectionRef conn
,
171 seastar::future
<> handle_pg_create(crimson::net::ConnectionRef conn
,
172 Ref
<MOSDPGCreate2
> m
);
173 seastar::future
<> handle_osd_op(crimson::net::ConnectionRef conn
,
175 seastar::future
<> handle_rep_op(crimson::net::ConnectionRef conn
,
177 seastar::future
<> handle_rep_op_reply(crimson::net::ConnectionRef conn
,
178 Ref
<MOSDRepOpReply
> m
);
179 seastar::future
<> handle_peering_op(crimson::net::ConnectionRef conn
,
180 Ref
<MOSDPeeringOp
> m
);
181 seastar::future
<> handle_recovery_subreq(crimson::net::ConnectionRef conn
,
182 Ref
<MOSDFastDispatchOp
> m
);
183 seastar::future
<> handle_scrub(crimson::net::ConnectionRef conn
,
185 seastar::future
<> handle_mark_me_down(crimson::net::ConnectionRef conn
,
186 Ref
<MOSDMarkMeDown
> m
);
188 seastar::future
<> committed_osd_maps(version_t first
,
192 seastar::future
<> check_osdmap_features();
194 seastar::future
<> handle_command(crimson::net::ConnectionRef conn
,
196 seastar::future
<> start_asok_admin();
197 seastar::future
<> handle_update_log_missing(crimson::net::ConnectionRef conn
,
198 Ref
<MOSDPGUpdateLogMissing
> m
);
199 seastar::future
<> handle_update_log_missing_reply(
200 crimson::net::ConnectionRef conn
,
201 Ref
<MOSDPGUpdateLogMissingReply
> m
);
203 auto &get_pg_shard_manager() {
204 return pg_shard_manager
;
206 ShardServices
&get_shard_services() {
207 return pg_shard_manager
.get_shard_services();
211 crimson::common::Gated gate
;
213 seastar::promise
<> stop_acked
;
214 void got_stop_ack() {
215 stop_acked
.set_value();
217 seastar::future
<> prepare_to_stop();
218 bool should_restart() const;
219 seastar::future
<> restart();
220 seastar::future
<> shutdown();
221 seastar::future
<> update_heartbeat_peers();
222 friend class PGAdvanceMap
;
225 seastar::future
<> send_beacon();
228 LogClient log_client
;
232 inline std::ostream
& operator<<(std::ostream
& out
, const OSD
& osd
) {
239 #if FMT_VERSION >= 90000
240 template <> struct fmt::formatter
<crimson::osd::OSD
> : fmt::ostream_formatter
{};