~mathiaz/+junk/ceph-new-pkg-review

« back to all changes in this revision

Viewing changes to src/mon/Elector.h

  • Committer: Mathias Gug
  • Date: 2010-07-29 03:10:42 UTC
  • Revision ID: mathias.gug@canonical.com-20100729031042-n9n8kky962qb4onb
Import ceph_0.21-0ubuntu1 from https://launchpad.net/~clint-fewbar/+archive/ceph/+packages.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- 
 
2
// vim: ts=8 sw=2 smarttab
 
3
/*
 
4
 * Ceph - scalable distributed file system
 
5
 *
 
6
 * Copyright (C) 2004-2006 Sage Weil <sage@newdream.net>
 
7
 *
 
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.
 
12
 * 
 
13
 */
 
14
 
 
15
 
 
16
#ifndef CEPH_MON_ELECTOR_H
 
17
#define CEPH_MON_ELECTOR_H
 
18
 
 
19
#include <map>
 
20
using namespace std;
 
21
 
 
22
#include "include/types.h"
 
23
#include "msg/Message.h"
 
24
 
 
25
#include "include/Context.h"
 
26
 
 
27
#include "common/Timer.h"
 
28
 
 
29
class Monitor;
 
30
 
 
31
 
 
32
class Elector {
 
33
 private:
 
34
  Monitor *mon;
 
35
  int whoami;
 
36
 
 
37
  Context *expire_event;
 
38
 
 
39
  void reset_timer(double plus=0.0);
 
40
  void cancel_timer();
 
41
 
 
42
  epoch_t epoch;   // latest epoch we've seen.  odd == election, even == stable, 
 
43
 
 
44
  // electing me
 
45
  bool     electing_me;
 
46
  utime_t  start_stamp;
 
47
  set<int> acked_me;
 
48
 
 
49
  // electing them
 
50
  int     leader_acked;  // who i've acked
 
51
  utime_t ack_stamp;     // and when
 
52
  
 
53
  void bump_epoch(epoch_t e=0);  // i just saw a larger epoch
 
54
 
 
55
  class C_ElectionExpire : public Context {
 
56
    Elector *elector;
 
57
  public:
 
58
    C_ElectionExpire(Elector *e) : elector(e) { }
 
59
    void finish(int r) {
 
60
      elector->expire();
 
61
    }
 
62
  };
 
63
 
 
64
  void start();   // start an electing me
 
65
  void defer(int who);
 
66
  void expire();  // timer goes off
 
67
  void victory();
 
68
   
 
69
  void handle_propose(class MMonElection *m);
 
70
  void handle_ack(class MMonElection *m);
 
71
  void handle_victory(class MMonElection *m);
 
72
  
 
73
 public:  
 
74
  Elector(Monitor *m, int w) : mon(m), whoami(w),
 
75
                               expire_event(0),
 
76
                               epoch(0),
 
77
                               electing_me(false),
 
78
                               leader_acked(-1) { }
 
79
 
 
80
  void init();
 
81
  void shutdown();
 
82
 
 
83
  void dispatch(Message *m);
 
84
 
 
85
  void call_election() {
 
86
    start();
 
87
  }
 
88
 
 
89
};
 
90
 
 
91
 
 
92
#endif