~ubuntu-branches/ubuntu/quantal/ceph/quantal

« back to all changes in this revision

Viewing changes to src/mon/MonmapMonitor.cc

  • Committer: Package Import Robot
  • Author(s): James Page
  • Date: 2012-07-16 09:56:24 UTC
  • mfrom: (0.3.11)
  • mto: This revision was merged to the branch mainline in revision 17.
  • Revision ID: package-import@ubuntu.com-20120716095624-azr2w4hbhei1rxmx
Tags: upstream-0.48
ImportĀ upstreamĀ versionĀ 0.48

Show diffs side-by-side

added added

removed removed

Lines of Context:
27
27
 
28
28
#include <sstream>
29
29
#include "common/config.h"
 
30
#include "include/assert.h"
30
31
 
31
32
#define dout_subsys ceph_subsys_mon
32
33
#undef dout_prefix
39
40
 
40
41
void MonmapMonitor::create_initial()
41
42
{
42
 
  bufferlist bl;
43
 
  mon->store->get_bl_ss(bl, "mkfs", "monmap");
44
 
  pending_map.decode(bl);
45
 
  dout(10) << "create_initial set fed epoch " << pending_map.epoch << dendl;
46
 
  assert(pending_map.epoch == 0);   // fix mkfs()
 
43
  dout(10) << "create_initial using current monmap" << dendl;
 
44
  pending_map = *mon->monmap;
47
45
  pending_map.epoch = 1;
48
46
}
49
47
 
102
100
 
103
101
  assert(mon->monmap->epoch + 1 == pending_map.epoch ||
104
102
         pending_map.epoch == 1);  // special case mkfs!
105
 
  pending_map.encode(bl);
 
103
  pending_map.encode(bl, mon->get_quorum_features());
 
104
}
 
105
 
 
106
void MonmapMonitor::on_active()
 
107
{
 
108
  if (paxos->get_version() >= 1 && !mon->has_ever_joined) {
 
109
    // make note of the fact that i was, once, part of the quorum.
 
110
    dout(10) << "noting that i was, once, part of an active quorum." << dendl;
 
111
    mon->store->put_int(1, "joined");
 
112
    mon->has_ever_joined = true;
 
113
  }
 
114
 
 
115
  if (mon->is_leader())
 
116
    mon->clog.info() << "monmap " << *mon->monmap << "\n";
106
117
}
107
118
 
108
119
bool MonmapMonitor::preprocess_query(PaxosServiceMessage *m)
126
137
  bufferlist rdata;
127
138
  stringstream ss;
128
139
 
 
140
  MonSession *session = m->get_session();
 
141
  if (!session ||
 
142
      (!session->caps.get_allow_all() &&
 
143
       !session->caps.check_privileges(PAXOS_MONMAP, MON_CAP_R) &&
 
144
       !mon->_allowed_command(session, m->cmd))) {
 
145
    mon->reply_command(m, -EACCES, "access denied", paxos->get_version());
 
146
    return true;
 
147
  }
 
148
 
129
149
  vector<const char*> args;
130
150
  for (unsigned i = 1; i < m->cmd.size(); i++)
131
151
    args.push_back(m->cmd[i].c_str());
133
153
  if (m->cmd.size() > 1) {
134
154
    if (m->cmd[1] == "stat") {
135
155
      mon->monmap->print_summary(ss);
136
 
      ss << ", election epoch " << mon->get_epoch() << ", quorum " << mon->get_quorum();
 
156
      ss << ", election epoch " << mon->get_epoch() << ", quorum " << mon->get_quorum()
 
157
         << " " << mon->get_quorum_names();
137
158
      r = 0;
138
159
    }
139
160
    else if (m->cmd.size() == 2 && m->cmd[1] == "getmap") {
140
 
      mon->monmap->encode(rdata);
 
161
      mon->monmap->encode(rdata, CEPH_FEATURES_ALL);
141
162
      r = 0;
142
163
      ss << "got latest monmap";
143
164
    }
268
289
  stringstream ss;
269
290
  string rs;
270
291
  int err = -EINVAL;
 
292
 
 
293
  MonSession *session = m->get_session();
 
294
  if (!session ||
 
295
      (!session->caps.get_allow_all() &&
 
296
       !session->caps.check_privileges(PAXOS_MONMAP, MON_CAP_R) &&
 
297
       !mon->_allowed_command(session, m->cmd))) {
 
298
    mon->reply_command(m, -EACCES, "access denied", paxos->get_version());
 
299
    return true;
 
300
  }
 
301
 
271
302
  if (m->cmd.size() > 1) {
272
303
    if (m->cmd.size() == 4 && m->cmd[1] == "add") {
273
304
      string name = m->cmd[2];
279
310
        ss << "addr " << m->cmd[3] << "does not parse";
280
311
        goto out;
281
312
      }
 
313
 
 
314
      if (addr.get_port() == 0) {
 
315
        ss << "port defaulted to " << CEPH_MON_PORT;
 
316
        addr.set_port(CEPH_MON_PORT);
 
317
      }
 
318
 
282
319
      if (pending_map.contains(addr) ||
283
320
          pending_map.contains(name)) {
284
321
        err = -EEXIST;
 
322
        if (!ss.str().empty())
 
323
          ss << "; ";
285
324
        ss << "mon " << name << " " << addr << " already exists";
286
325
        goto out;
287
326
      }
325
364
{
326
365
  dout(10) << "preprocess_join " << join->name << " at " << join->addr << dendl;
327
366
 
328
 
  if (pending_map.contains(join->name)) {
 
367
  MonSession *session = join->get_session();
 
368
  if (!session ||
 
369
      (!session->caps.get_allow_all() &&
 
370
       !session->caps.check_privileges(PAXOS_MONMAP, MON_CAP_ALL))) {
 
371
    dout(10) << " insufficient caps" << dendl;
 
372
    join->put();
 
373
    return true;
 
374
  }
 
375
 
 
376
  if (pending_map.contains(join->name) && !pending_map.get_addr(join->name).is_blank_ip()) {
329
377
    dout(10) << " already have " << join->name << dendl;
330
378
    join->put();
331
379
    return true;
332
380
  }
333
 
  if (pending_map.contains(join->addr)) {
 
381
  if (pending_map.contains(join->addr) && pending_map.get_name(join->addr) == join->name) {
334
382
    dout(10) << " already have " << join->addr << dendl;
335
383
    join->put();
336
384
    return true;
339
387
}
340
388
bool MonmapMonitor::prepare_join(MMonJoin *join)
341
389
{
342
 
  dout(0) << "adding " << join->name << " at " << join->addr << " to monitor cluster" << dendl;
 
390
  dout(0) << "adding/updating " << join->name << " at " << join->addr << " to monitor cluster" << dendl;
 
391
  if (pending_map.contains(join->name))
 
392
    pending_map.remove(join->name);
 
393
  if (pending_map.contains(join->addr))
 
394
    pending_map.remove(pending_map.get_name(join->addr));
343
395
  pending_map.add(join->name, join->addr);
344
396
  pending_map.last_changed = ceph_clock_now(g_ceph_context);
345
397
  join->put();
364
416
  int actual = mon->get_quorum().size();
365
417
  if (actual < max) {
366
418
    ostringstream ss;
367
 
    ss << (max-actual) << " mons down, quorum " << mon->get_quorum();
 
419
    ss << (max-actual) << " mons down, quorum " << mon->get_quorum() << " " << mon->get_quorum_names();
368
420
    summary.push_back(make_pair(HEALTH_WARN, ss.str()));
369
421
    if (detail) {
370
422
      set<int> q = mon->get_quorum();