33
33
#include "common/Timer.h"
34
34
#include "common/Formatter.h"
35
35
#include "common/ceph_argparse.h"
36
#include "common/perf_counters.h"
37
38
#include "osd/osd_types.h"
38
39
#include "osd/PG.h" // yuck
45
46
#define dout_prefix _prefix(_dout, mon, pg_map)
46
47
static ostream& _prefix(std::ostream *_dout, Monitor *mon, PGMap& pg_map) {
47
48
return *_dout << "mon." << mon->name << "@" << mon->rank
48
<< (mon->is_starting() ? (const char*)"(starting)":(mon->is_leader() ? (const char*)"(leader)":(mon->is_peon() ? (const char*)"(peon)":(const char*)"(?\?)")))
49
<< ".pg v" << pg_map.version << " ";
49
<< "(" << mon->get_state_name()
50
<< ").pg v" << pg_map.version << " ";
52
53
class RatioMonitor : public md_config_obs_t {
56
57
virtual ~RatioMonitor() {}
57
58
virtual const char **get_tracked_conf_keys() const {
58
59
static const char *KEYS[] = { "mon_osd_full_ratio",
59
"mon_osd_nearfull_ratio", NULL };
60
"mon_osd_nearfull_ratio",
62
64
virtual void handle_conf_change(const md_config_t *conf,
69
71
PGMonitor::PGMonitor(Monitor *mn, Paxos *p)
72
: PaxosService(mn, p),
73
ratio_lock("PGMonitor::ratio_lock"),
74
need_full_ratio_update(false),
75
need_nearfull_ratio_update(false)
72
77
ratio_monitor = new RatioMonitor(this);
73
78
g_conf->add_observer(ratio_monitor);
95
100
if (mon->is_leader()) {
96
101
check_osd_map(mon->osdmon()->osdmap.epoch);
107
void PGMonitor::update_logger()
109
dout(10) << "update_logger" << dendl;
111
mon->cluster_logger->set(l_cluster_osd_kb, pg_map.osd_sum.kb);
112
mon->cluster_logger->set(l_cluster_osd_kb_used, pg_map.osd_sum.kb_used);
113
mon->cluster_logger->set(l_cluster_osd_kb_avail, pg_map.osd_sum.kb_avail);
115
mon->cluster_logger->set(l_cluster_num_pool, pg_map.pg_pool_sum.size());
116
mon->cluster_logger->set(l_cluster_num_pg, pg_map.pg_stat.size());
118
unsigned active = 0, active_clean = 0, peering = 0;
119
for (hash_map<int,int>::iterator p = pg_map.num_pg_by_state.begin();
120
p != pg_map.num_pg_by_state.end();
122
if (p->second & PG_STATE_ACTIVE) {
124
if (p->second & PG_STATE_CLEAN)
127
if (p->second & PG_STATE_PEERING)
130
mon->cluster_logger->set(l_cluster_num_pg_active_clean, active_clean);
131
mon->cluster_logger->set(l_cluster_num_pg_active, active);
132
mon->cluster_logger->set(l_cluster_num_pg_peering, peering);
134
mon->cluster_logger->set(l_cluster_num_object, pg_map.pg_sum.stats.sum.num_objects);
135
mon->cluster_logger->set(l_cluster_num_object_degraded, pg_map.pg_sum.stats.sum.num_objects_degraded);
136
mon->cluster_logger->set(l_cluster_num_object_unfound, pg_map.pg_sum.stats.sum.num_objects_unfound);
137
mon->cluster_logger->set(l_cluster_num_bytes, pg_map.pg_sum.stats.sum.num_bytes);
140
void PGMonitor::update_full_ratios(float full_ratio, float nearfull_ratio)
142
Mutex::Locker l(ratio_lock);
143
dout(10) << "update_full_ratios full " << full_ratio << " nearfull " << nearfull_ratio << dendl;
144
if (full_ratio != 0) {
145
new_full_ratio = full_ratio;
146
need_full_ratio_update = true;
148
if (nearfull_ratio != 0) {
149
new_nearfull_ratio = nearfull_ratio;
150
need_nearfull_ratio_update = true;
100
154
void PGMonitor::tick()
104
158
update_from_paxos();
105
159
handle_osd_timeouts();
161
if (mon->is_leader()) {
163
bool propose = false;
164
if (need_full_ratio_update) {
165
dout(10) << "tick need full ratio update " << new_full_ratio << dendl;
166
need_full_ratio_update = false;
167
if (pg_map.full_ratio != new_full_ratio) {
168
pending_inc.full_ratio = new_full_ratio;
172
if (need_nearfull_ratio_update) {
173
dout(10) << "tick need nearfull ratio update " << new_nearfull_ratio << dendl;
174
need_nearfull_ratio_update = false;
175
if (pg_map.nearfull_ratio != new_nearfull_ratio) {
176
pending_inc.nearfull_ratio = new_nearfull_ratio;
106
186
dout(10) << pg_map << dendl;
109
void PGMonitor::create_initial(bufferlist& bl)
189
void PGMonitor::create_initial()
111
191
dout(10) << "create_initial -- creating initial map" << dendl;
114
194
bool PGMonitor::update_from_paxos()
116
196
version_t paxosv = paxos->get_version();
117
if (paxosv == pg_map.version) return true;
197
if (paxosv == pg_map.version)
118
199
assert(paxosv >= pg_map.version);
120
if (pg_map.version == 0 && paxosv > 1) {
121
// starting up: load latest
201
if (pg_map.version != paxos->get_stashed_version()) {
122
202
bufferlist latest;
123
version_t v = paxos->get_latest(latest);
125
dout(7) << "update_from_paxos startup: got latest latest full pgmap v" << v << dendl;
128
bufferlist::iterator p = latest.begin();
129
tmp_pg_map.decode(p);
132
catch (const std::exception &e) {
133
dout(0) << "PGMonitor::update_from_paxos: error parsing update: "
134
<< e.what() << dendl;
203
version_t v = paxos->get_stashed(latest);
204
dout(7) << "update_from_paxos loading latest full pgmap v" << v << dendl;
207
bufferlist::iterator p = latest.begin();
208
tmp_pg_map.decode(p);
211
catch (const std::exception &e) {
212
dout(0) << "update_from_paxos: error parsing update: "
213
<< e.what() << dendl;
281
356
dout(10) << "handle_statfs " << *statfs << " from " << statfs->get_orig_source() << dendl;
283
if (ceph_fsid_compare(&statfs->fsid, &mon->monmap->fsid)) {
358
if (statfs->fsid != mon->monmap->fsid) {
284
359
dout(0) << "handle_statfs on fsid " << statfs->fsid << " != " << mon->monmap->fsid << dendl;
395
470
dout(10) << "prepare_pg_stats " << *stats << " from " << stats->get_orig_source() << dendl;
396
471
int from = stats->get_orig_source().num();
398
if (ceph_fsid_compare(&stats->fsid, &mon->monmap->fsid)) {
399
dout(0) << "handle_statfs on fsid " << stats->fsid << " != " << mon->monmap->fsid << dendl;
473
if (stats->fsid != mon->monmap->fsid) {
474
dout(0) << "prepare_pg_stats on fsid " << stats->fsid << " != " << mon->monmap->fsid << dendl;