]> git.proxmox.com Git - ceph.git/blame - ceph/src/mon/OSDMonitor.h
bump version to 15.2.1-pve1
[ceph.git] / ceph / src / mon / OSDMonitor.h
CommitLineData
7c673cae
FG
1// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2// vim: ts=8 sw=2 smarttab
3/*
4 * Ceph - scalable distributed file system
5 *
6 * Copyright (C) 2004-2006 Sage Weil <sage@newdream.net>
7 * Copyright (C) 2013,2014 Cloudwatt <libre.licensing@cloudwatt.com>
8 *
9 * Author: Loic Dachary <loic@dachary.org>
10 *
11 * This is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU Lesser General Public
13 * License version 2.1, as published by the Free Software
14 * Foundation. See file COPYING.
15 *
16 */
17
18/* Object Store Device (OSD) Monitor
19 */
20
21#ifndef CEPH_OSDMONITOR_H
22#define CEPH_OSDMONITOR_H
23
24#include <map>
25#include <set>
7c673cae
FG
26
27#include "include/types.h"
11fdf7f2 28#include "include/encoding.h"
7c673cae 29#include "common/simple_cache.hpp"
eafe8130 30#include "common/PriorityCache.h"
7c673cae
FG
31#include "msg/Messenger.h"
32
33#include "osd/OSDMap.h"
34#include "osd/OSDMapMapping.h"
35
36#include "CreatingPGs.h"
37#include "PaxosService.h"
38
39class Monitor;
40class PGMap;
41class MonSession;
42class MOSDMap;
43
44#include "erasure-code/ErasureCodeInterface.h"
45#include "mon/MonOpRequest.h"
28e407b8
AA
46#include <boost/functional/hash.hpp>
47// re-include our assert to clobber the system one; fix dout:
11fdf7f2 48#include "include/ceph_assert.h"
7c673cae 49
7c673cae
FG
50/// information about a particular peer's failure reports for one osd
51struct failure_reporter_t {
52 utime_t failed_since; ///< when they think it failed
53 MonOpRequestRef op; ///< failure op request
54
55 failure_reporter_t() {}
56 explicit failure_reporter_t(utime_t s) : failed_since(s) {}
57 ~failure_reporter_t() { }
58};
59
60/// information about all failure reports for one osd
61struct failure_info_t {
62 map<int, failure_reporter_t> reporters; ///< reporter -> failed_since etc
63 utime_t max_failed_since; ///< most recent failed_since
64
65 failure_info_t() {}
66
67 utime_t get_failed_since() {
68 if (max_failed_since == utime_t() && !reporters.empty()) {
69 // the old max must have canceled; recalculate.
70 for (map<int, failure_reporter_t>::iterator p = reporters.begin();
71 p != reporters.end();
72 ++p)
73 if (p->second.failed_since > max_failed_since)
74 max_failed_since = p->second.failed_since;
75 }
76 return max_failed_since;
77 }
78
79 // set the message for the latest report. return any old op request we had,
80 // if any, so we can discard it.
81 MonOpRequestRef add_report(int who, utime_t failed_since,
82 MonOpRequestRef op) {
83 map<int, failure_reporter_t>::iterator p = reporters.find(who);
84 if (p == reporters.end()) {
91327a77 85 if (max_failed_since != utime_t() && max_failed_since < failed_since)
7c673cae
FG
86 max_failed_since = failed_since;
87 p = reporters.insert(map<int, failure_reporter_t>::value_type(who, failure_reporter_t(failed_since))).first;
88 }
89
90 MonOpRequestRef ret = p->second.op;
91 p->second.op = op;
92 return ret;
93 }
94
95 void take_report_messages(list<MonOpRequestRef>& ls) {
96 for (map<int, failure_reporter_t>::iterator p = reporters.begin();
97 p != reporters.end();
98 ++p) {
99 if (p->second.op) {
100 ls.push_back(p->second.op);
101 p->second.op.reset();
102 }
103 }
104 }
105
106 MonOpRequestRef cancel_report(int who) {
107 map<int, failure_reporter_t>::iterator p = reporters.find(who);
108 if (p == reporters.end())
109 return MonOpRequestRef();
110 MonOpRequestRef ret = p->second.op;
111 reporters.erase(p);
91327a77 112 max_failed_since = utime_t();
7c673cae
FG
113 return ret;
114 }
115};
116
117
118class LastEpochClean {
119 struct Lec {
120 vector<epoch_t> epoch_by_pg;
121 ps_t next_missing = 0;
122 epoch_t floor = std::numeric_limits<epoch_t>::max();
123 void report(ps_t pg, epoch_t last_epoch_clean);
124 };
125 std::map<uint64_t, Lec> report_by_pool;
126public:
127 void report(const pg_t& pg, epoch_t last_epoch_clean);
128 void remove_pool(uint64_t pool);
129 epoch_t get_lower_bound(const OSDMap& latest) const;
130};
131
132
11fdf7f2
TL
133struct osdmap_manifest_t {
134 // all the maps we have pinned -- i.e., won't be removed unless
135 // they are inside a trim interval.
136 set<version_t> pinned;
137
138 osdmap_manifest_t() {}
139
140 version_t get_last_pinned() const
141 {
142 set<version_t>::const_reverse_iterator it = pinned.crbegin();
143 if (it == pinned.crend()) {
144 return 0;
145 }
146 return *it;
147 }
148
149 version_t get_first_pinned() const
150 {
151 set<version_t>::const_iterator it = pinned.cbegin();
152 if (it == pinned.cend()) {
153 return 0;
154 }
155 return *it;
156 }
157
158 bool is_pinned(version_t v) const
159 {
160 return pinned.find(v) != pinned.end();
161 }
162
163 void pin(version_t v)
164 {
165 pinned.insert(v);
166 }
167
168 version_t get_lower_closest_pinned(version_t v) const {
169 set<version_t>::const_iterator p = pinned.lower_bound(v);
170 if (p == pinned.cend()) {
171 return 0;
172 } else if (*p > v) {
173 if (p == pinned.cbegin()) {
174 return 0;
175 }
176 --p;
177 }
178 return *p;
179 }
180
181 void encode(bufferlist& bl) const
182 {
183 ENCODE_START(1, 1, bl);
184 encode(pinned, bl);
185 ENCODE_FINISH(bl);
186 }
187
188 void decode(bufferlist::const_iterator& bl)
189 {
190 DECODE_START(1, bl);
191 decode(pinned, bl);
192 DECODE_FINISH(bl);
193 }
194
195 void decode(bufferlist& bl) {
196 auto p = bl.cbegin();
197 decode(p);
198 }
199
200 void dump(Formatter *f) {
201 f->dump_unsigned("first_pinned", get_first_pinned());
202 f->dump_unsigned("last_pinned", get_last_pinned());
203 f->open_array_section("pinned_maps");
204 for (auto& i : pinned) {
205 f->dump_unsigned("epoch", i);
206 }
207 f->close_section();
208 }
209};
210WRITE_CLASS_ENCODER(osdmap_manifest_t);
211
eafe8130
TL
212class OSDMonitor : public PaxosService,
213 public md_config_obs_t {
7c673cae
FG
214 CephContext *cct;
215
216public:
217 OSDMap osdmap;
218
eafe8130
TL
219 // config observer
220 const char** get_tracked_conf_keys() const override;
221 void handle_conf_change(const ConfigProxy& conf,
222 const std::set<std::string> &changed) override;
7c673cae
FG
223 // [leader]
224 OSDMap::Incremental pending_inc;
225 map<int, bufferlist> pending_metadata;
226 set<int> pending_metadata_rm;
227 map<int, failure_info_t> failure_info;
228 map<int,utime_t> down_pending_out; // osd down -> out
81eedcae 229 bool priority_convert = false;
9f95a23c 230 map<int64_t,set<snapid_t>> pending_pseudo_purged_snaps;
eafe8130
TL
231 std::shared_ptr<PriorityCache::PriCache> rocksdb_binned_kv_cache = nullptr;
232 std::shared_ptr<PriorityCache::Manager> pcm = nullptr;
233 ceph::mutex balancer_lock = ceph::make_mutex("OSDMonitor::balancer_lock");
7c673cae
FG
234
235 map<int,double> osd_weight;
236
28e407b8
AA
237 using osdmap_key_t = std::pair<version_t, uint64_t>;
238 using osdmap_cache_t = SimpleLRU<osdmap_key_t,
239 bufferlist,
240 std::less<osdmap_key_t>,
241 boost::hash<osdmap_key_t>>;
242 osdmap_cache_t inc_osd_cache;
243 osdmap_cache_t full_osd_cache;
7c673cae 244
11fdf7f2
TL
245 bool has_osdmap_manifest;
246 osdmap_manifest_t osdmap_manifest;
247
7c673cae
FG
248 bool check_failures(utime_t now);
249 bool check_failure(utime_t now, int target_osd, failure_info_t& fi);
224ce89b 250 void force_failure(int target_osd, int by);
7c673cae 251
7c673cae
FG
252 bool _have_pending_crush();
253 CrushWrapper &_get_stable_crush();
254 void _get_pending_crush(CrushWrapper& newcrush);
255
256 enum FastReadType {
257 FAST_READ_OFF,
258 FAST_READ_ON,
259 FAST_READ_DEFAULT
260 };
261
494da23a
TL
262 struct CleanUpmapJob : public ParallelPGMapper::Job {
263 CephContext *cct;
264 const OSDMap& osdmap;
265 OSDMap::Incremental& pending_inc;
266 // lock to protect pending_inc form changing
267 // when checking is done
9f95a23c
TL
268 ceph::mutex pending_inc_lock =
269 ceph::make_mutex("CleanUpmapJob::pending_inc_lock");
494da23a
TL
270
271 CleanUpmapJob(CephContext *cct, const OSDMap& om, OSDMap::Incremental& pi)
272 : ParallelPGMapper::Job(&om),
273 cct(cct),
274 osdmap(om),
275 pending_inc(pi) {}
276
277 void process(const vector<pg_t>& to_check) override {
278 vector<pg_t> to_cancel;
279 map<pg_t, mempool::osdmap::vector<pair<int,int>>> to_remap;
280 osdmap.check_pg_upmaps(cct, to_check, &to_cancel, &to_remap);
281 // don't bother taking lock if nothing changes
282 if (!to_cancel.empty() || !to_remap.empty()) {
283 std::lock_guard l(pending_inc_lock);
284 osdmap.clean_pg_upmaps(cct, &pending_inc, to_cancel, to_remap);
285 }
286 }
287
288 void process(int64_t poolid, unsigned ps_begin, unsigned ps_end) override {}
289 void complete() override {}
290 }; // public as this will need to be accessible from TestTestOSDMap.cc
291
7c673cae 292 // svc
11fdf7f2 293public:
7c673cae 294 void create_initial() override;
11fdf7f2 295 void get_store_prefixes(std::set<string>& s) const override;
7c673cae
FG
296
297private:
298 void update_from_paxos(bool *need_bootstrap) override;
299 void create_pending() override; // prepare a new pending
300 void encode_pending(MonitorDBStore::TransactionRef t) override;
301 void on_active() override;
302 void on_restart() override;
303 void on_shutdown() override;
11fdf7f2
TL
304
305 /* osdmap full map prune */
306 void load_osdmap_manifest();
307 bool should_prune() const;
308 void _prune_update_trimmed(
309 MonitorDBStore::TransactionRef tx,
310 version_t first);
311 void prune_init(osdmap_manifest_t& manifest);
312 bool _prune_sanitize_options() const;
313 bool is_prune_enabled() const;
314 bool is_prune_supported() const;
315 bool do_prune(MonitorDBStore::TransactionRef tx);
316
eafe8130
TL
317 // Priority cache control
318 uint32_t mon_osd_cache_size = 0; ///< Number of cached OSDMaps
319 uint64_t rocksdb_cache_size = 0; ///< Cache for kv Db
320 double cache_kv_ratio = 0; ///< Cache ratio dedicated to kv
321 double cache_inc_ratio = 0; ///< Cache ratio dedicated to inc
322 double cache_full_ratio = 0; ///< Cache ratio dedicated to full
323 uint64_t mon_memory_base = 0; ///< Mon base memory for cache autotuning
324 double mon_memory_fragmentation = 0; ///< Expected memory fragmentation
325 uint64_t mon_memory_target = 0; ///< Mon target memory for cache autotuning
326 uint64_t mon_memory_min = 0; ///< Min memory to cache osdmaps
327 bool mon_memory_autotune = false; ///< Cache auto tune setting
328 int register_cache_with_pcm();
329 int _set_cache_sizes();
330 int _set_cache_ratios();
331 void _set_new_cache_sizes();
332 void _set_cache_autotuning();
333 int _update_mon_cache_settings();
334
335 friend struct OSDMemCache;
336 friend struct IncCache;
337 friend struct FullCache;
338
7c673cae
FG
339 /**
340 * we haven't delegated full version stashing to paxosservice for some time
341 * now, making this function useless in current context.
342 */
343 void encode_full(MonitorDBStore::TransactionRef t) override { }
344 /**
345 * do not let paxosservice periodically stash full osdmaps, or we will break our
346 * locally-managed full maps. (update_from_paxos loads the latest and writes them
347 * out going forward from there, but if we just synced that may mean we skip some.)
348 */
349 bool should_stash_full() override {
350 return false;
351 }
352
353 /**
354 * hook into trim to include the oldest full map in the trim transaction
355 *
356 * This ensures that anyone post-sync will have enough to rebuild their
357 * full osdmaps.
358 */
359 void encode_trim_extra(MonitorDBStore::TransactionRef tx, version_t first) override;
360
361 void update_msgr_features();
362 int check_cluster_features(uint64_t features, stringstream &ss);
363 /**
364 * check if the cluster supports the features required by the
365 * given crush map. Outputs the daemons which don't support it
366 * to the stringstream.
367 *
368 * @returns true if the map is passable, false otherwise
369 */
370 bool validate_crush_against_features(const CrushWrapper *newcrush,
371 stringstream &ss);
372 void check_osdmap_subs();
373 void share_map_with_random_osd();
374
9f95a23c
TL
375 ceph::mutex prime_pg_temp_lock =
376 ceph::make_mutex("OSDMonitor::prime_pg_temp_lock");
7c673cae
FG
377 struct PrimeTempJob : public ParallelPGMapper::Job {
378 OSDMonitor *osdmon;
379 PrimeTempJob(const OSDMap& om, OSDMonitor *m)
380 : ParallelPGMapper::Job(&om), osdmon(m) {}
381 void process(int64_t pool, unsigned ps_begin, unsigned ps_end) override {
382 for (unsigned ps = ps_begin; ps < ps_end; ++ps) {
383 pg_t pgid(ps, pool);
384 osdmon->prime_pg_temp(*osdmap, pgid);
385 }
386 }
494da23a 387 void process(const vector<pg_t>& pgs) override {}
7c673cae
FG
388 void complete() override {}
389 };
390 void maybe_prime_pg_temp();
391 void prime_pg_temp(const OSDMap& next, pg_t pgid);
392
393 ParallelPGMapper mapper; ///< for background pg work
394 OSDMapMapping mapping; ///< pg <-> osd mappings
395 unique_ptr<ParallelPGMapper::Job> mapping_job; ///< background mapping job
396 void start_mapping();
397
398 void update_logger();
399
400 void handle_query(PaxosServiceMessage *m);
401 bool preprocess_query(MonOpRequestRef op) override; // true if processed.
402 bool prepare_update(MonOpRequestRef op) override;
403 bool should_propose(double &delay) override;
404
11fdf7f2 405 version_t get_trim_to() const override;
7c673cae
FG
406
407 bool can_mark_down(int o);
408 bool can_mark_up(int o);
409 bool can_mark_out(int o);
410 bool can_mark_in(int o);
411
412 // ...
28e407b8
AA
413 MOSDMap *build_latest_full(uint64_t features);
414 MOSDMap *build_incremental(epoch_t first, epoch_t last, uint64_t features);
7c673cae
FG
415 void send_full(MonOpRequestRef op);
416 void send_incremental(MonOpRequestRef op, epoch_t first);
417public:
418 // @param req an optional op request, if the osdmaps are replies to it. so
419 // @c Monitor::send_reply() can mark_event with it.
420 void send_incremental(epoch_t first, MonSession *session, bool onetime,
421 MonOpRequestRef req = MonOpRequestRef());
422
423private:
424 void print_utilization(ostream &out, Formatter *f, bool tree) const;
425
11fdf7f2 426 bool check_source(MonOpRequestRef op, uuid_d fsid);
7c673cae
FG
427
428 bool preprocess_get_osdmap(MonOpRequestRef op);
429
430 bool preprocess_mark_me_down(MonOpRequestRef op);
431
432 friend class C_AckMarkedDown;
433 bool preprocess_failure(MonOpRequestRef op);
434 bool prepare_failure(MonOpRequestRef op);
435 bool prepare_mark_me_down(MonOpRequestRef op);
436 void process_failures();
437 void take_all_failures(list<MonOpRequestRef>& ls);
438
9f95a23c
TL
439 bool preprocess_mark_me_dead(MonOpRequestRef op);
440 bool prepare_mark_me_dead(MonOpRequestRef op);
441
7c673cae
FG
442 bool preprocess_full(MonOpRequestRef op);
443 bool prepare_full(MonOpRequestRef op);
444
445 bool preprocess_boot(MonOpRequestRef op);
446 bool prepare_boot(MonOpRequestRef op);
447 void _booted(MonOpRequestRef op, bool logit);
448
449 void update_up_thru(int from, epoch_t up_thru);
450 bool preprocess_alive(MonOpRequestRef op);
451 bool prepare_alive(MonOpRequestRef op);
452 void _reply_map(MonOpRequestRef op, epoch_t e);
453
454 bool preprocess_pgtemp(MonOpRequestRef op);
455 bool prepare_pgtemp(MonOpRequestRef op);
456
457 bool preprocess_pg_created(MonOpRequestRef op);
458 bool prepare_pg_created(MonOpRequestRef op);
459
11fdf7f2
TL
460 bool preprocess_pg_ready_to_merge(MonOpRequestRef op);
461 bool prepare_pg_ready_to_merge(MonOpRequestRef op);
462
7c673cae
FG
463 int _check_remove_pool(int64_t pool_id, const pg_pool_t &pool, ostream *ss);
464 bool _check_become_tier(
465 int64_t tier_pool_id, const pg_pool_t *tier_pool,
466 int64_t base_pool_id, const pg_pool_t *base_pool,
467 int *err, ostream *ss) const;
468 bool _check_remove_tier(
469 int64_t base_pool_id, const pg_pool_t *base_pool, const pg_pool_t *tier_pool,
470 int *err, ostream *ss) const;
471
472 int _prepare_remove_pool(int64_t pool, ostream *ss, bool no_fake);
473 int _prepare_rename_pool(int64_t pool, string newname);
474
28e407b8 475 bool enforce_pool_op_caps(MonOpRequestRef op);
7c673cae
FG
476 bool preprocess_pool_op (MonOpRequestRef op);
477 bool preprocess_pool_op_create (MonOpRequestRef op);
478 bool prepare_pool_op (MonOpRequestRef op);
479 bool prepare_pool_op_create (MonOpRequestRef op);
480 bool prepare_pool_op_delete(MonOpRequestRef op);
481 int crush_rename_bucket(const string& srcname,
482 const string& dstname,
483 ostream *ss);
484 void check_legacy_ec_plugin(const string& plugin,
485 const string& profile) const;
486 int normalize_profile(const string& profilename,
487 ErasureCodeProfile &profile,
488 bool force,
489 ostream *ss);
31f18b77
FG
490 int crush_rule_create_erasure(const string &name,
491 const string &profile,
492 int *rule,
493 ostream *ss);
494 int get_crush_rule(const string &rule_name,
495 int *crush_rule,
7c673cae
FG
496 ostream *ss);
497 int get_erasure_code(const string &erasure_code_profile,
498 ErasureCodeInterfaceRef *erasure_code,
499 ostream *ss) const;
31f18b77 500 int prepare_pool_crush_rule(const unsigned pool_type,
7c673cae 501 const string &erasure_code_profile,
31f18b77
FG
502 const string &rule_name,
503 int *crush_rule,
7c673cae
FG
504 ostream *ss);
505 bool erasure_code_profile_in_use(
506 const mempool::osdmap::map<int64_t, pg_pool_t> &pools,
507 const string &profile,
508 ostream *ss);
509 int parse_erasure_code_profile(const vector<string> &erasure_code_profile,
510 map<string,string> *erasure_code_profile_map,
511 ostream *ss);
512 int prepare_pool_size(const unsigned pool_type,
513 const string &erasure_code_profile,
11fdf7f2 514 uint8_t repl_size,
7c673cae
FG
515 unsigned *size, unsigned *min_size,
516 ostream *ss);
517 int prepare_pool_stripe_width(const unsigned pool_type,
518 const string &erasure_code_profile,
519 unsigned *stripe_width,
520 ostream *ss);
3efd9988 521 int check_pg_num(int64_t pool, int pg_num, int size, ostream* ss);
11fdf7f2 522 int prepare_new_pool(string& name,
31f18b77
FG
523 int crush_rule,
524 const string &crush_rule_name,
7c673cae 525 unsigned pg_num, unsigned pgp_num,
11fdf7f2
TL
526 unsigned pg_num_min,
527 uint64_t repl_size,
528 const uint64_t target_size_bytes,
529 const float target_size_ratio,
7c673cae
FG
530 const string &erasure_code_profile,
531 const unsigned pool_type,
532 const uint64_t expected_num_objects,
533 FastReadType fast_read,
9f95a23c 534 const string& pg_autoscale_mode,
7c673cae
FG
535 ostream *ss);
536 int prepare_new_pool(MonOpRequestRef op);
537
3efd9988
FG
538 void set_pool_flags(int64_t pool_id, uint64_t flags);
539 void clear_pool_flags(int64_t pool_id, uint64_t flags);
7c673cae 540 bool update_pools_status();
7c673cae 541
9f95a23c
TL
542 bool _is_removed_snap(int64_t pool_id, snapid_t snapid);
543 bool _is_pending_removed_snap(int64_t pool_id, snapid_t snapid);
544
545 string make_purged_snap_epoch_key(epoch_t epoch);
546 string make_purged_snap_key(int64_t pool, snapid_t snap);
547 string make_purged_snap_key_value(int64_t pool, snapid_t snap, snapid_t num,
11fdf7f2 548 epoch_t epoch, bufferlist *v);
9f95a23c 549
11fdf7f2 550 bool try_prune_purged_snaps();
9f95a23c 551 int lookup_purged_snap(int64_t pool, snapid_t snap,
11fdf7f2
TL
552 snapid_t *begin, snapid_t *end);
553
9f95a23c
TL
554 void insert_purged_snap_update(
555 int64_t pool,
556 snapid_t start, snapid_t end,
557 epoch_t epoch,
558 MonitorDBStore::TransactionRef t);
559
7c673cae
FG
560 bool prepare_set_flag(MonOpRequestRef op, int flag);
561 bool prepare_unset_flag(MonOpRequestRef op, int flag);
562
563 void _pool_op_reply(MonOpRequestRef op,
564 int ret, epoch_t epoch, bufferlist *blp=NULL);
565
566 struct C_Booted : public C_MonOp {
567 OSDMonitor *cmon;
568 bool logit;
569 C_Booted(OSDMonitor *cm, MonOpRequestRef op_, bool l=true) :
570 C_MonOp(op_), cmon(cm), logit(l) {}
571 void _finish(int r) override {
572 if (r >= 0)
573 cmon->_booted(op, logit);
574 else if (r == -ECANCELED)
575 return;
576 else if (r == -EAGAIN)
577 cmon->dispatch(op);
578 else
11fdf7f2 579 ceph_abort_msg("bad C_Booted return value");
7c673cae
FG
580 }
581 };
582
583 struct C_ReplyMap : public C_MonOp {
584 OSDMonitor *osdmon;
585 epoch_t e;
586 C_ReplyMap(OSDMonitor *o, MonOpRequestRef op_, epoch_t ee)
587 : C_MonOp(op_), osdmon(o), e(ee) {}
588 void _finish(int r) override {
589 if (r >= 0)
590 osdmon->_reply_map(op, e);
591 else if (r == -ECANCELED)
592 return;
593 else if (r == -EAGAIN)
594 osdmon->dispatch(op);
595 else
11fdf7f2 596 ceph_abort_msg("bad C_ReplyMap return value");
7c673cae
FG
597 }
598 };
599 struct C_PoolOp : public C_MonOp {
600 OSDMonitor *osdmon;
601 int replyCode;
602 int epoch;
603 bufferlist reply_data;
604 C_PoolOp(OSDMonitor * osd, MonOpRequestRef op_, int rc, int e, bufferlist *rd=NULL) :
605 C_MonOp(op_), osdmon(osd), replyCode(rc), epoch(e) {
606 if (rd)
607 reply_data = *rd;
608 }
609 void _finish(int r) override {
610 if (r >= 0)
611 osdmon->_pool_op_reply(op, replyCode, epoch, &reply_data);
612 else if (r == -ECANCELED)
613 return;
614 else if (r == -EAGAIN)
615 osdmon->dispatch(op);
616 else
11fdf7f2 617 ceph_abort_msg("bad C_PoolOp return value");
7c673cae
FG
618 }
619 };
620
621 bool preprocess_remove_snaps(MonOpRequestRef op);
622 bool prepare_remove_snaps(MonOpRequestRef op);
623
9f95a23c
TL
624 bool preprocess_get_purged_snaps(MonOpRequestRef op);
625
7c673cae 626 int load_metadata(int osd, map<string, string>& m, ostream *err);
31f18b77 627 void count_metadata(const string& field, Formatter *f);
28e407b8
AA
628
629 void reencode_incremental_map(bufferlist& bl, uint64_t features);
630 void reencode_full_map(bufferlist& bl, uint64_t features);
c07f9fc5
FG
631public:
632 void count_metadata(const string& field, map<string,int> *out);
633protected:
7c673cae
FG
634 int get_osd_objectstore_type(int osd, std::string *type);
635 bool is_pool_currently_all_bluestore(int64_t pool_id, const pg_pool_t &pool,
636 ostream *err);
637
638 // when we last received PG stats from each osd
639 map<int,utime_t> last_osd_report;
640 // TODO: use last_osd_report to store the osd report epochs, once we don't
641 // need to upgrade from pre-luminous releases.
642 map<int,epoch_t> osd_epochs;
643 LastEpochClean last_epoch_clean;
644 bool preprocess_beacon(MonOpRequestRef op);
645 bool prepare_beacon(MonOpRequestRef op);
646 epoch_t get_min_last_epoch_clean() const;
647
648 friend class C_UpdateCreatingPGs;
11fdf7f2 649 std::map<int, std::map<epoch_t, std::set<spg_t>>> creating_pgs_by_osd_epoch;
7c673cae
FG
650 std::vector<pg_t> pending_created_pgs;
651 // the epoch when the pg mapping was calculated
652 epoch_t creating_pgs_epoch = 0;
653 creating_pgs_t creating_pgs;
c07f9fc5 654 mutable std::mutex creating_pgs_lock;
7c673cae 655
94b18763
FG
656 creating_pgs_t update_pending_pgs(const OSDMap::Incremental& inc,
657 const OSDMap& nextmap);
31f18b77 658 unsigned scan_for_creating_pgs(
7c673cae
FG
659 const mempool::osdmap::map<int64_t,pg_pool_t>& pools,
660 const mempool::osdmap::set<int64_t>& removed_pools,
661 utime_t modified,
662 creating_pgs_t* creating_pgs) const;
663 pair<int32_t, pg_t> get_parent_pg(pg_t pgid) const;
664 void update_creating_pgs();
665 void check_pg_creates_subs();
c07f9fc5 666 epoch_t send_pg_creates(int osd, Connection *con, epoch_t next) const;
7c673cae 667
31f18b77
FG
668 int32_t _allocate_osd_id(int32_t* existing_id);
669
7c673cae
FG
670public:
671 OSDMonitor(CephContext *cct, Monitor *mn, Paxos *p, const string& service_name);
672
673 void tick() override; // check state, take actions
674
7c673cae
FG
675 bool preprocess_command(MonOpRequestRef op);
676 bool prepare_command(MonOpRequestRef op);
11fdf7f2 677 bool prepare_command_impl(MonOpRequestRef op, const cmdmap_t& cmdmap);
7c673cae 678
31f18b77
FG
679 int validate_osd_create(
680 const int32_t id,
681 const uuid_d& uuid,
682 const bool check_osd_exists,
683 int32_t* existing_id,
684 stringstream& ss);
685 int prepare_command_osd_create(
686 const int32_t id,
687 const uuid_d& uuid,
688 int32_t* existing_id,
689 stringstream& ss);
3a9019d9
FG
690 void do_osd_create(const int32_t id, const uuid_d& uuid,
691 const string& device_class,
692 int32_t* new_id);
31f18b77
FG
693 int prepare_command_osd_purge(int32_t id, stringstream& ss);
694 int prepare_command_osd_destroy(int32_t id, stringstream& ss);
695 int _prepare_command_osd_crush_remove(
696 CrushWrapper &newcrush,
697 int32_t id,
698 int32_t ancestor,
699 bool has_ancestor,
700 bool unlink_only);
701 void do_osd_crush_remove(CrushWrapper& newcrush);
702 int prepare_command_osd_crush_remove(
703 CrushWrapper &newcrush,
704 int32_t id,
705 int32_t ancestor,
706 bool has_ancestor,
707 bool unlink_only);
708 int prepare_command_osd_remove(int32_t id);
709 int prepare_command_osd_new(
710 MonOpRequestRef op,
11fdf7f2 711 const cmdmap_t& cmdmap,
31f18b77
FG
712 const map<string,string>& secrets,
713 stringstream &ss,
714 Formatter *f);
715
11fdf7f2 716 int prepare_command_pool_set(const cmdmap_t& cmdmap,
7c673cae 717 stringstream& ss);
11fdf7f2 718
c07f9fc5 719 int prepare_command_pool_application(const string &prefix,
11fdf7f2 720 const cmdmap_t& cmdmap,
c07f9fc5 721 stringstream& ss);
11fdf7f2
TL
722 int preprocess_command_pool_application(const string &prefix,
723 const cmdmap_t& cmdmap,
724 stringstream& ss,
725 bool *modified);
726 int _command_pool_application(const string &prefix,
727 const cmdmap_t& cmdmap,
728 stringstream& ss,
729 bool *modified,
730 bool preparing);
7c673cae
FG
731
732 bool handle_osd_timeouts(const utime_t &now,
733 std::map<int,utime_t> &last_osd_report);
734
735 void send_latest(MonOpRequestRef op, epoch_t start=0);
736 void send_latest_now_nodelete(MonOpRequestRef op, epoch_t start=0) {
737 op->mark_osdmon_event(__func__);
738 send_incremental(op, start);
739 }
740
741 int get_version(version_t ver, bufferlist& bl) override;
28e407b8
AA
742 int get_version(version_t ver, uint64_t feature, bufferlist& bl);
743
744 int get_version_full(version_t ver, uint64_t feature, bufferlist& bl);
7c673cae 745 int get_version_full(version_t ver, bufferlist& bl) override;
11fdf7f2
TL
746 int get_inc(version_t ver, OSDMap::Incremental& inc);
747 int get_full_from_pinned_map(version_t ver, bufferlist& bl);
7c673cae 748
11fdf7f2
TL
749 epoch_t blacklist(const entity_addrvec_t& av, utime_t until);
750 epoch_t blacklist(entity_addr_t a, utime_t until);
7c673cae
FG
751
752 void dump_info(Formatter *f);
753 int dump_osd_metadata(int osd, Formatter *f, ostream *err);
754 void print_nodes(Formatter *f);
755
756 void check_osdmap_sub(Subscription *sub);
757 void check_pg_creates_sub(Subscription *sub);
758
11fdf7f2
TL
759 void do_application_enable(int64_t pool_id, const std::string &app_name,
760 const std::string &app_key="",
761 const std::string &app_value="");
494da23a
TL
762 void do_set_pool_opt(int64_t pool_id, pool_opts_t::key_t opt,
763 pool_opts_t::value_t);
c07f9fc5 764
7c673cae
FG
765 void add_flag(int flag) {
766 if (!(osdmap.flags & flag)) {
767 if (pending_inc.new_flags < 0)
768 pending_inc.new_flags = osdmap.flags;
769 pending_inc.new_flags |= flag;
770 }
771 }
772
773 void remove_flag(int flag) {
774 if(osdmap.flags & flag) {
775 if (pending_inc.new_flags < 0)
776 pending_inc.new_flags = osdmap.flags;
777 pending_inc.new_flags &= ~flag;
778 }
779 }
81eedcae 780 void convert_pool_priorities(void);
7c673cae
FG
781};
782
783#endif