summaryrefslogtreecommitdiff
path: root/src/mon/MonmapMonitor.h
blob: a0fccfd56f25796e11f12fef06a86092333af867 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- 
// vim: ts=8 sw=2 smarttab
/*
 * Ceph - scalable distributed file system
 *
 * Copyright (C) 2009 Sage Weil <sage@newdream.net>
 *
 * This is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License version 2.1, as published by the Free Software 
 * Foundation.  See file COPYING.
 * 
 */

/*
 * The Monmap Monitor is used to track the monitors in the cluster.
 */

#ifndef CEPH_MONMAPMONITOR_H
#define CEPH_MONMAPMONITOR_H

#include <map>
#include <set>

using namespace std;

#include "include/types.h"
#include "msg/Messenger.h"

#include "PaxosService.h"
#include "MonMap.h"
#include "MonitorDBStore.h"
#include "Monitor.h"

class MMonGetMap;
class MMonMap;
class MMonCommand;
class MMonJoin;

class MonmapMonitor : public PaxosService {
 public:
  MonmapMonitor(Monitor *mn, Paxos *p, const string& service_name)
    : PaxosService(mn, p, service_name)
  {
  }
  MonMap pending_map; //the pending map awaiting passage

  void create_initial();

  void update_from_paxos(bool *need_bootstrap);

  void create_pending();

  void encode_pending(MonitorDBStore::Transaction *t);
  // we always encode the full map; we have no use for full versions
  virtual void encode_full(MonitorDBStore::Transaction *t) { }

  void on_active();

  void dump_info(Formatter *f);

  bool preprocess_query(PaxosServiceMessage *m);
  bool prepare_update(PaxosServiceMessage *m);

  bool preprocess_join(MMonJoin *m);
  bool prepare_join(MMonJoin *m);

  bool preprocess_command(MMonCommand *m);
  bool prepare_command(MMonCommand *m);

  void get_health(list<pair<health_status_t,string> >& summary,
		  list<pair<health_status_t,string> > *detail) const;

  int get_monmap(bufferlist &bl);
  int get_monmap(MonMap &m);

  /*
   * Since monitors are pretty
   * important, this implementation will just write 0.0.
   */
  bool should_propose(double& delay);

  void tick();

  struct C_MonmapCommand : public Monitor::C_Command {
    utime_t last_changed;

    C_MonmapCommand(Monitor *_mon, MMonCommand *_m, int r,
                    string s, version_t v, utime_t changed) :
      Monitor::C_Command(_mon, _m, r, s, v),
      last_changed(changed)
    { }

    void finish(int r) {
      int ret = r;
      if (r == -EAGAIN) {
        MonMap m;
        mon->monmon()->get_monmap(m);
        if ((m.get_epoch() == version+1)
            && (m.last_changed == last_changed)) {
          ret = 0;
        }
      }
      Monitor::C_Command::finish(ret);
    }
  };

 private:
  bufferlist monmap_bl;
};


#endif