1 // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2 // vim: ts=8 sw=2 smarttab
4 * Ceph - scalable distributed file system
6 * Copyright (C) 2004-2006 Sage Weil <sage@newdream.net>
8 * This is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License version 2.1, as published by the Free Software
11 * Foundation. See file COPYING.
16 * Placement Group Monitor. Placement Groups are logical sets of objects
17 * that are replicated by the same set of devices.
20 #ifndef CEPH_PGMONITOR_H
21 #define CEPH_PGMONITOR_H
28 #include "PaxosService.h"
29 #include "include/types.h"
30 #include "include/utime.h"
31 #include "common/histogram.h"
32 #include "msg/Messenger.h"
33 #include "mon/MonitorDBStore.h"
36 class MonPGStatService;
37 class PGMonStatService;
39 class PGMonitor : public PaxosService {
41 std::unique_ptr<PGMonStatService> pgservice;
43 bool do_delete = false; ///< propose deleting pgmap data
44 bool did_delete = false; ///< we already deleted pgmap data
47 PGMap::Incremental pending_inc;
49 bool check_all_pgs = false;
51 const char *pgmap_meta_prefix;
52 const char *pgmap_pg_prefix;
53 const char *pgmap_osd_prefix;
55 void create_initial() override;
56 void update_from_paxos(bool *need_bootstrap) override;
57 void upgrade_format() override;
58 void on_upgrade() override;
59 void post_paxos_update() override;
60 void handle_osd_timeouts();
61 void create_pending() override; // prepare a new pending
62 // propose pending update to peers
63 version_t get_trim_to() override;
66 void encode_pending(MonitorDBStore::TransactionRef t) override;
67 void read_pgmap_meta();
68 void read_pgmap_full();
69 void apply_pgmap_delta(bufferlist& bl);
71 bool preprocess_query(MonOpRequestRef op) override; // true if processed.
72 bool prepare_update(MonOpRequestRef op) override;
74 bool preprocess_pg_stats(MonOpRequestRef op);
75 bool pg_stats_have_changed(int from, const MPGStats *stats) const;
76 bool prepare_pg_stats(MonOpRequestRef op);
77 void _updated_stats(MonOpRequestRef op, MonOpRequestRef ack_op);
81 bool preprocess_command(MonOpRequestRef op);
82 bool prepare_command(MonOpRequestRef op);
84 // when we last received PG stats from each osd
85 map<int,utime_t> last_osd_report;
87 epoch_t send_pg_creates(int osd, Connection *con, epoch_t next);
90 PGMonitor(Monitor *mn, Paxos *p, const string& service_name);
91 ~PGMonitor() override;
93 void get_store_prefixes(set<string>& s) override {
94 s.insert(get_service_name());
95 s.insert(pgmap_meta_prefix);
96 s.insert(pgmap_pg_prefix);
97 s.insert(pgmap_osd_prefix);
100 void on_restart() override;
102 /* Courtesy function provided by PaxosService, called when an election
103 * finishes and the cluster goes active. We use it here to make sure we
104 * haven't lost any PGs from new pools. */
105 void on_active() override;
107 bool should_stash_full() override {
108 return false; // never
110 void encode_full(MonitorDBStore::TransactionRef t) override {
111 assert(0 == "unimplemented encode_full");
115 void tick() override; // check state, take actions
117 void check_osd_map(epoch_t epoch);
119 int _warn_slow_request_histogram(const pow2_hist_t& h, string suffix,
120 list<pair<health_status_t,string> >& summary,
121 list<pair<health_status_t,string> > *detail) const;
123 void get_health(list<pair<health_status_t,string> >& summary,
124 list<pair<health_status_t,string> > *detail,
125 CephContext *cct) const override;
126 void check_full_osd_health(
127 list<pair<health_status_t,string> >& summary,
128 list<pair<health_status_t,string> > *detail,
129 const mempool::pgmap::set<int>& s,
130 const char *desc, health_status_t sev) const;
133 bool check_sub(Subscription *sub);
135 MonPGStatService *get_pg_stat_service();
138 // no copying allowed
139 PGMonitor(const PGMonitor &rhs);
140 PGMonitor &operator=(const PGMonitor &rhs);
142 // we don't want to include gtest.h just for FRIEND_TEST
143 friend class pgmonitor_dump_object_stat_sum_0_Test;
144 friend class pgmonitor_dump_object_stat_sum_1_Test;
145 friend class pgmonitor_dump_object_stat_sum_2_Test;