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

« back to all changes in this revision

Viewing changes to src/mon/Elector.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:
27
27
#define dout_prefix _prefix(_dout, mon, epoch)
28
28
static ostream& _prefix(std::ostream *_dout, Monitor *mon, epoch_t epoch) {
29
29
  return *_dout << "mon." << mon->name << "@" << mon->rank
30
 
                << (mon->is_starting() ? (const char*)"(starting)":(mon->is_leader() ? (const char*)"(leader)":(mon->is_peon() ? (const char*)"(peon)":(const char*)"(?\?)")))
31
 
                << ".elector(" << epoch << ") ";
 
30
                << "(" << mon->get_state_name()
 
31
                << ").elector(" << epoch << ") ";
32
32
}
33
33
 
34
34
 
56
56
  // clear up some state
57
57
  electing_me = false;
58
58
  acked_me.clear();
59
 
  leader_acked = -1;
60
59
}
61
60
 
62
61
 
63
62
void Elector::start()
64
63
{
 
64
  if (!participating) {
 
65
    dout(0) << "not starting new election -- not participating" << dendl;
 
66
    return;
 
67
  }
65
68
  dout(5) << "start -- can i be leader?" << dendl;
66
69
  
67
70
  // start by trying to elect me
70
73
  start_stamp = ceph_clock_now(g_ceph_context);
71
74
  electing_me = true;
72
75
  acked_me.insert(mon->rank);
 
76
  leader_acked = -1;
73
77
 
74
 
  mon->starting_election();
75
 
  
76
78
  // bcast to everyone else
77
79
  for (unsigned i=0; i<mon->monmap->size(); ++i) {
78
80
    if ((int)i == mon->rank) continue;
180
182
      // a mon just started up, call a new election so they can rejoin!
181
183
      dout(5) << " got propose from old epoch, quorum is " << mon->quorum 
182
184
              << ", " << m->get_source() << " must have just started" << dendl;
183
 
      mon->call_election(false);//start();
 
185
      // we may be active; make sure we reset things in the monitor appropriately.
 
186
      mon->reset();
 
187
      mon->start_election();
184
188
    } else {
185
189
      dout(5) << " ignoring old propose" << dendl;
186
190
      m->put();
195
199
      dout(5) << "no, we already acked " << leader_acked << dendl;
196
200
    } else {
197
201
      // wait, i should win!
198
 
      if (!electing_me)
199
 
        mon->call_election(false);//start();
 
202
      if (!electing_me) {
 
203
        mon->reset();
 
204
        mon->start_election();
 
205
      }
200
206
    }
201
207
  } else {
202
208
    // they would win over me
222
228
  if (m->epoch > epoch) {
223
229
    dout(5) << "woah, that's a newer epoch, i must have rebooted.  bumping and re-starting!" << dendl;
224
230
    bump_epoch(m->epoch);
225
 
    mon->call_election(false);//start();
 
231
    start();
226
232
    m->put();
227
233
    return;
228
234
  }
259
265
  if (m->epoch != epoch + 1) { 
260
266
    dout(5) << "woah, that's a funny epoch, i must have rebooted.  bumping and re-starting!" << dendl;
261
267
    bump_epoch(m->epoch);
262
 
    mon->call_election(true);//start();
 
268
    start();
263
269
    m->put();
264
270
    return;
265
271
  }
283
289
    
284
290
  case MSG_MON_ELECTION:
285
291
    {
 
292
      if (!participating) {
 
293
        m->put();
 
294
        return;
 
295
      }
286
296
      MMonElection *em = (MMonElection*)m;
287
297
 
288
 
      MonMap *peermap = new MonMap(ceph_clock_now(g_ceph_context));
 
298
      // assume an old message encoding would have matched
 
299
      if (em->fsid != mon->monmap->fsid) {
 
300
        dout(0) << " ignoring election msg fsid " << em->fsid << " != " << mon->monmap->fsid << dendl;
 
301
        m->put();
 
302
        return;
 
303
      }
 
304
 
 
305
      MonMap *peermap = new MonMap;
289
306
      peermap->decode(em->monmap_bl);
290
307
      if (peermap->epoch > mon->monmap->epoch) {
291
308
        dout(0) << m->get_source_inst() << " has newer monmap epoch " << peermap->epoch
332
349
  }
333
350
}
334
351
 
335
 
 
336
 
 
337
 
 
 
352
void Elector::start_participating()
 
353
{
 
354
  if (!participating) {
 
355
    participating = true;
 
356
    call_election();
 
357
  }
 
358
}