~ubuntu-branches/ubuntu/raring/ceph/raring

« back to all changes in this revision

Viewing changes to src/mon/PGMonitor.cc

  • Committer: Package Import Robot
  • Author(s): Laszlo Boszormenyi (GCS)
  • Date: 2012-02-05 10:07:38 UTC
  • mfrom: (1.1.7) (0.1.11 sid)
  • Revision ID: package-import@ubuntu.com-20120205100738-00s0bxx93mamy8tk
Tags: 0.41-1
New upstream release.

Show diffs side-by-side

added added

removed removed

Lines of Context:
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"
36
37
 
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 << " ";
50
51
}
51
52
 
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",
 
61
                                  NULL };
60
62
    return KEYS;
61
63
  }
62
64
  virtual void handle_conf_change(const md_config_t *conf,
67
69
};
68
70
 
69
71
PGMonitor::PGMonitor(Monitor *mn, Paxos *p)
70
 
  : PaxosService(mn, p)
 
72
  : PaxosService(mn, p),
 
73
    ratio_lock("PGMonitor::ratio_lock"),
 
74
    need_full_ratio_update(false),
 
75
    need_nearfull_ratio_update(false)
71
76
{
72
77
  ratio_monitor = new RatioMonitor(this);
73
78
  g_conf->add_observer(ratio_monitor);
83
88
 Tick function to update the map based on performance every N seconds
84
89
*/
85
90
 
86
 
void PGMonitor::on_election_start()
 
91
void PGMonitor::on_restart()
87
92
{
88
93
  // clear leader state
89
94
  last_sent_pg_create.clear();
95
100
  if (mon->is_leader()) {
96
101
    check_osd_map(mon->osdmon()->osdmap.epoch);
97
102
  }
 
103
 
 
104
  update_logger();
 
105
}
 
106
 
 
107
void PGMonitor::update_logger()
 
108
{
 
109
  dout(10) << "update_logger" << dendl;
 
110
 
 
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);
 
114
 
 
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());
 
117
 
 
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();
 
121
       ++p) {
 
122
    if (p->second & PG_STATE_ACTIVE) {
 
123
      active++;
 
124
      if (p->second & PG_STATE_CLEAN)
 
125
        active_clean++;
 
126
    }
 
127
    if (p->second & PG_STATE_PEERING)
 
128
      peering++;
 
129
  }
 
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);
 
133
 
 
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);
 
138
}
 
139
 
 
140
void PGMonitor::update_full_ratios(float full_ratio, float nearfull_ratio)
 
141
{
 
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;
 
147
  }
 
148
  if (nearfull_ratio != 0) {
 
149
    new_nearfull_ratio = nearfull_ratio;
 
150
    need_nearfull_ratio_update = true;
 
151
  }
98
152
}
99
153
 
100
154
void PGMonitor::tick() 
103
157
 
104
158
  update_from_paxos();
105
159
  handle_osd_timeouts();
 
160
 
 
161
  if (mon->is_leader()) {
 
162
    ratio_lock.Lock();
 
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;
 
169
        propose = true;
 
170
      }
 
171
    }
 
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;
 
177
        propose = true;
 
178
      }
 
179
    }
 
180
    ratio_lock.Unlock();
 
181
    if (propose) {
 
182
      propose_pending();
 
183
    }
 
184
  }
 
185
 
106
186
  dout(10) << pg_map << dendl;
107
187
}
108
188
 
109
 
void PGMonitor::create_initial(bufferlist& bl)
 
189
void PGMonitor::create_initial()
110
190
{
111
191
  dout(10) << "create_initial -- creating initial map" << dendl;
112
192
}
114
194
bool PGMonitor::update_from_paxos()
115
195
{
116
196
  version_t paxosv = paxos->get_version();
117
 
  if (paxosv == pg_map.version) return true;
 
197
  if (paxosv == pg_map.version)
 
198
    return true;
118
199
  assert(paxosv >= pg_map.version);
119
200
 
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);
124
 
    if (v) {
125
 
      dout(7) << "update_from_paxos startup: got latest latest full pgmap v" << v << dendl;
126
 
      try {
127
 
        PGMap tmp_pg_map;
128
 
        bufferlist::iterator p = latest.begin();
129
 
        tmp_pg_map.decode(p);
130
 
        pg_map = tmp_pg_map;
131
 
      }
132
 
      catch (const std::exception &e) {
133
 
        dout(0) << "PGMonitor::update_from_paxos: error parsing update: "
134
 
                << e.what() << dendl;
135
 
        return false;
136
 
      }
 
203
    version_t v = paxos->get_stashed(latest);
 
204
    dout(7) << "update_from_paxos loading latest full pgmap v" << v << dendl;
 
205
    try {
 
206
      PGMap tmp_pg_map;
 
207
      bufferlist::iterator p = latest.begin();
 
208
      tmp_pg_map.decode(p);
 
209
      pg_map = tmp_pg_map;
 
210
    }
 
211
    catch (const std::exception &e) {
 
212
      dout(0) << "update_from_paxos: error parsing update: "
 
213
              << e.what() << dendl;
 
214
      return false;
137
215
    }
138
216
  } 
139
217
 
151
229
      inc.decode(p);
152
230
    }
153
231
    catch (const std::exception &e) {
154
 
      dout(0) << "PGMonitor::update_from_paxos: error parsing "
 
232
      dout(0) << "update_from_paxos: error parsing "
155
233
              << "incremental update: " << e.what() << dendl;
156
234
      return false;
157
235
    }
187
265
 
188
266
  send_pg_creates();
189
267
 
 
268
  update_logger();
 
269
 
190
270
  return true;
191
271
}
192
272
 
260
340
  }
261
341
}
262
342
 
263
 
void PGMonitor::committed()
264
 
{
265
 
 
266
 
}
267
 
 
268
343
void PGMonitor::handle_statfs(MStatfs *statfs)
269
344
{
270
345
  // check caps
280
355
 
281
356
  dout(10) << "handle_statfs " << *statfs << " from " << statfs->get_orig_source() << dendl;
282
357
 
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;
285
360
    goto out;
286
361
  }
313
388
    goto out;
314
389
  }
315
390
 
316
 
  if (ceph_fsid_compare(&m->fsid, &mon->monmap->fsid)) {
 
391
  if (m->fsid != mon->monmap->fsid) {
317
392
    dout(0) << "preprocess_getpoolstats on fsid " << m->fsid << " != " << mon->monmap->fsid << dendl;
318
393
    goto out;
319
394
  }
395
470
  dout(10) << "prepare_pg_stats " << *stats << " from " << stats->get_orig_source() << dendl;
396
471
  int from = stats->get_orig_source().num();
397
472
 
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;
400
475
    stats->put();
401
476
    return false;
402
477
  }