2007-02-01 05:43:23 +00:00
|
|
|
// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
|
|
|
|
/*
|
|
|
|
* Ceph - scalable distributed file system
|
|
|
|
*
|
|
|
|
* Copyright (C) 2004-2006 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.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
#ifndef __MONITOR_H
|
|
|
|
#define __MONITOR_H
|
|
|
|
|
|
|
|
#include "include/types.h"
|
|
|
|
#include "msg/Messenger.h"
|
|
|
|
|
|
|
|
#include "MonMap.h"
|
|
|
|
#include "Elector.h"
|
2007-02-08 04:42:13 +00:00
|
|
|
#include "Paxos.h"
|
|
|
|
|
2007-02-01 05:43:23 +00:00
|
|
|
|
|
|
|
class ObjectStore;
|
|
|
|
class OSDMonitor;
|
|
|
|
class MDSMonitor;
|
|
|
|
class ClientMonitor;
|
|
|
|
|
|
|
|
class Monitor : public Dispatcher {
|
|
|
|
protected:
|
|
|
|
// me
|
|
|
|
int whoami;
|
|
|
|
Messenger *messenger;
|
|
|
|
Mutex lock;
|
|
|
|
|
|
|
|
MonMap *monmap;
|
|
|
|
|
|
|
|
// timer.
|
|
|
|
Context *tick_timer;
|
|
|
|
Cond tick_timer_cond;
|
|
|
|
void cancel_tick();
|
|
|
|
void reset_tick();
|
|
|
|
friend class C_Mon_Tick;
|
|
|
|
|
|
|
|
// my local store
|
|
|
|
ObjectStore *store;
|
|
|
|
|
|
|
|
const static int INO_ELECTOR = 1;
|
|
|
|
const static int INO_MON_MAP = 2;
|
|
|
|
const static int INO_OSD_MAP = 10;
|
|
|
|
const static int INO_OSD_INC_MAP = 11;
|
|
|
|
const static int INO_MDS_MAP = 20;
|
|
|
|
|
|
|
|
// elector
|
|
|
|
Elector elector;
|
|
|
|
friend class Elector;
|
|
|
|
|
|
|
|
epoch_t mon_epoch; // monitor epoch (election instance)
|
|
|
|
set<int> quorum; // current active set of monitors (if !starting)
|
|
|
|
|
|
|
|
//void call_election();
|
|
|
|
|
2007-02-08 04:42:13 +00:00
|
|
|
// paxos
|
|
|
|
Paxos test_paxos;
|
|
|
|
friend class Paxos;
|
|
|
|
|
|
|
|
|
2007-02-01 05:43:23 +00:00
|
|
|
// monitor state
|
|
|
|
const static int STATE_STARTING = 0; // electing
|
|
|
|
const static int STATE_LEADER = 1;
|
|
|
|
const static int STATE_PEON = 2;
|
|
|
|
int state;
|
|
|
|
|
|
|
|
int leader; // current leader (to best of knowledge)
|
|
|
|
utime_t last_called_election; // [starting] last time i called an election
|
|
|
|
|
|
|
|
bool is_starting() { return state == STATE_STARTING; }
|
|
|
|
bool is_leader() { return state == STATE_LEADER; }
|
|
|
|
bool is_peon() { return state == STATE_PEON; }
|
|
|
|
|
|
|
|
// my public services
|
|
|
|
OSDMonitor *osdmon;
|
|
|
|
MDSMonitor *mdsmon;
|
|
|
|
ClientMonitor *clientmon;
|
|
|
|
|
|
|
|
// messages
|
|
|
|
void handle_shutdown(Message *m);
|
|
|
|
void handle_ping_ack(class MPingAck *m);
|
|
|
|
|
|
|
|
friend class OSDMonitor;
|
|
|
|
friend class MDSMonitor;
|
|
|
|
friend class ClientMonitor;
|
|
|
|
|
|
|
|
// initiate election
|
|
|
|
void call_election();
|
|
|
|
|
2007-02-08 03:29:55 +00:00
|
|
|
// end election (called by Elector)
|
|
|
|
void win_election(set<int>& q);
|
|
|
|
void lose_election(int l);
|
|
|
|
|
2007-02-01 05:43:23 +00:00
|
|
|
|
2007-02-08 04:42:13 +00:00
|
|
|
|
2007-02-01 05:43:23 +00:00
|
|
|
public:
|
|
|
|
Monitor(int w, Messenger *m, MonMap *mm) :
|
|
|
|
whoami(w),
|
|
|
|
messenger(m),
|
|
|
|
monmap(mm),
|
|
|
|
tick_timer(0),
|
|
|
|
store(0),
|
|
|
|
elector(this, w),
|
|
|
|
mon_epoch(0),
|
2007-02-08 04:42:13 +00:00
|
|
|
|
|
|
|
test_paxos(this, w, 0), // machine 0 == test paxos
|
|
|
|
|
2007-02-01 05:43:23 +00:00
|
|
|
state(STATE_STARTING),
|
|
|
|
leader(0),
|
|
|
|
osdmon(0), mdsmon(0), clientmon(0)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void init();
|
|
|
|
void shutdown();
|
|
|
|
void dispatch(Message *m);
|
|
|
|
void tick(Context *timer);
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|