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/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>
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"
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 OSDMapService
,
63 private crimson::common::AuthHandler
,
64 private crimson::mgr::WithStats
{
68 seastar::timer
<seastar::lowres_clock
> beacon_timer
;
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
;
77 SharedLRU
<epoch_t
, OSDMap
> osdmaps
;
78 SimpleLRU
<epoch_t
, bufferlist
, false> map_bl_cache
;
80 // TODO: use a wrapper for ObjectStore
81 std::unique_ptr
<crimson::os::FuturizedStore
> store
;
82 std::unique_ptr
<OSDMeta
> meta_coll
;
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
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;
95 ceph::mono_time startup_time
;
97 OSDSuperblock superblock
;
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
;
105 // mgr::WithStats methods
106 MessageRef
get_stats() final
;
108 // AuthHandler methods
109 void handle_authentication(const EntityName
& name
,
110 const AuthCapsInfo
& caps
) final
;
112 crimson::osd::ShardServices shard_services
;
114 std::unique_ptr
<Heartbeat
> heartbeat
;
115 seastar::timer
<seastar::lowres_clock
> heartbeat_timer
;
118 seastar::lw_shared_ptr
<crimson::admin::AdminSocket
> asok
;
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
);
128 seastar::future
<> mkfs(uuid_d osd_uuid
, uuid_d cluster_fsid
);
130 seastar::future
<> start();
131 seastar::future
<> stop();
133 void dump_status(Formatter
*) const;
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();
141 seastar::future
<Ref
<PG
>> make_pg(cached_map_t create_map
,
144 seastar::future
<Ref
<PG
>> load_pg(spg_t pgid
);
145 seastar::future
<> load_pgs();
147 epoch_t up_thru_wanted
= 0;
148 seastar::future
<> _send_alive();
150 // OSDMapService methods
151 epoch_t
get_up_epoch() const final
{
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
);
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
<Ref
<PG
>> handle_pg_create_info(
170 std::unique_ptr
<PGCreateInfo
> info
);
172 seastar::future
<> handle_osd_map(crimson::net::Connection
* conn
,
174 seastar::future
<> handle_osd_op(crimson::net::Connection
* conn
,
176 seastar::future
<> handle_rep_op(crimson::net::Connection
* conn
,
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
);
183 seastar::future
<> committed_osd_maps(version_t first
,
187 void check_osdmap_features();
189 seastar::future
<> start_asok_admin();
192 OSDMapGate osdmap_gate
;
194 ShardServices
&get_shard_services() {
195 return shard_services
;
198 seastar::future
<> consume_map(epoch_t epoch
);
204 blocking_future
<Ref
<PG
>> get_or_create_pg(
207 std::unique_ptr
<PGCreateInfo
> info
);
208 blocking_future
<Ref
<PG
>> wait_for_pg(
211 bool should_restart() const;
212 seastar::future
<> restart();
213 seastar::future
<> shutdown();
215 seastar::future
<> send_beacon();
216 seastar::future
<> update_heartbeat_peers();
218 friend class PGAdvanceMap
;