mirror of
https://github.com/ceph/ceph
synced 2025-01-21 02:31:19 +00:00
* formatting goof
git-svn-id: https://ceph.svn.sf.net/svnroot/ceph@1475 29311d96-e01e-0410-9327-a35deaab8ce9
This commit is contained in:
parent
6ee499da91
commit
34c54d3492
@ -1,252 +1,252 @@
|
||||
// -*- 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) 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.
|
||||
*
|
||||
*/
|
||||
// -*- 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) 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.
|
||||
*
|
||||
*/
|
||||
|
||||
// TODO: missing run() method, which creates the two main timers, refreshTimer and readTimer
|
||||
// TODO: missing run() method, which creates the two main timers, refreshTimer and readTimer
|
||||
|
||||
#include "Monitor.h"
|
||||
#include "Monitor.h"
|
||||
|
||||
#include "osd/OSDMap.h"
|
||||
#include "osd/OSDMap.h"
|
||||
|
||||
#include "MonitorStore.h"
|
||||
#include "MonitorStore.h"
|
||||
|
||||
#include "msg/Message.h"
|
||||
#include "msg/Messenger.h"
|
||||
#include "msg/Message.h"
|
||||
#include "msg/Messenger.h"
|
||||
|
||||
#include "messages/MPing.h"
|
||||
#include "messages/MPingAck.h"
|
||||
#include "messages/MGenericMessage.h"
|
||||
#include "messages/MMonCommand.h"
|
||||
#include "messages/MMonCommandAck.h"
|
||||
#include "messages/MPing.h"
|
||||
#include "messages/MPingAck.h"
|
||||
#include "messages/MGenericMessage.h"
|
||||
#include "messages/MMonCommand.h"
|
||||
#include "messages/MMonCommandAck.h"
|
||||
|
||||
#include "messages/MMonPaxos.h"
|
||||
#include "messages/MMonPaxos.h"
|
||||
|
||||
#include "common/Timer.h"
|
||||
#include "common/Clock.h"
|
||||
#include "common/Timer.h"
|
||||
#include "common/Clock.h"
|
||||
|
||||
#include "OSDMonitor.h"
|
||||
#include "MDSMonitor.h"
|
||||
#include "ClientMonitor.h"
|
||||
#include "OSDMonitor.h"
|
||||
#include "MDSMonitor.h"
|
||||
#include "ClientMonitor.h"
|
||||
|
||||
#include "config.h"
|
||||
#undef dout
|
||||
#define dout(l) if (l<=g_conf.debug || l<=g_conf.debug_mon) cout << g_clock.now() << " mon" << whoami << (is_starting() ? (const char*)"(starting)":(is_leader() ? (const char*)"(leader)":(is_peon() ? (const char*)"(peon)":(const char*)"(?\?)"))) << " "
|
||||
#define derr(l) if (l<=g_conf.debug || l<=g_conf.debug_mon) cerr << g_clock.now() << " mon" << whoami << (is_starting() ? (const char*)"(starting)":(is_leader() ? (const char*)"(leader)":(is_peon() ? (const char*)"(peon)":(const char*)"(?\?)"))) << " "
|
||||
#include "config.h"
|
||||
#undef dout
|
||||
#define dout(l) if (l<=g_conf.debug || l<=g_conf.debug_mon) cout << g_clock.now() << " mon" << whoami << (is_starting() ? (const char*)"(starting)":(is_leader() ? (const char*)"(leader)":(is_peon() ? (const char*)"(peon)":(const char*)"(?\?)"))) << " "
|
||||
#define derr(l) if (l<=g_conf.debug || l<=g_conf.debug_mon) cerr << g_clock.now() << " mon" << whoami << (is_starting() ? (const char*)"(starting)":(is_leader() ? (const char*)"(leader)":(is_peon() ? (const char*)"(peon)":(const char*)"(?\?)"))) << " "
|
||||
|
||||
|
||||
|
||||
void Monitor::init()
|
||||
{
|
||||
lock.Lock();
|
||||
void Monitor::init()
|
||||
{
|
||||
lock.Lock();
|
||||
|
||||
dout(1) << "init" << endl;
|
||||
|
||||
// store
|
||||
char s[80];
|
||||
sprintf(s, "mondata/mon%d", whoami);
|
||||
store = new MonitorStore(s);
|
||||
|
||||
if (g_conf.mkfs)
|
||||
store->mkfs();
|
||||
|
||||
store->mount();
|
||||
|
||||
// create
|
||||
osdmon = new OSDMonitor(this, &paxos_osdmap);
|
||||
mdsmon = new MDSMonitor(this, &paxos_mdsmap);
|
||||
clientmon = new ClientMonitor(this, &paxos_clientmap);
|
||||
|
||||
// init paxos
|
||||
paxos_test.init();
|
||||
paxos_osdmap.init();
|
||||
paxos_mdsmap.init();
|
||||
paxos_clientmap.init();
|
||||
|
||||
// i'm ready!
|
||||
messenger->set_dispatcher(this);
|
||||
|
||||
// start ticker
|
||||
reset_tick();
|
||||
|
||||
// call election?
|
||||
if (monmap->num_mon > 1) {
|
||||
assert(monmap->num_mon != 2);
|
||||
call_election();
|
||||
} else {
|
||||
// we're standalone.
|
||||
set<int> q;
|
||||
q.insert(whoami);
|
||||
win_election(1, q);
|
||||
}
|
||||
|
||||
lock.Unlock();
|
||||
}
|
||||
|
||||
dout(1) << "init" << endl;
|
||||
|
||||
// store
|
||||
char s[80];
|
||||
sprintf(s, "mondata/mon%d", whoami);
|
||||
store = new MonitorStore(s);
|
||||
|
||||
if (g_conf.mkfs)
|
||||
store->mkfs();
|
||||
|
||||
store->mount();
|
||||
|
||||
// create
|
||||
osdmon = new OSDMonitor(this, &paxos_osdmap);
|
||||
mdsmon = new MDSMonitor(this, &paxos_mdsmap);
|
||||
clientmon = new ClientMonitor(this, &paxos_clientmap);
|
||||
|
||||
// init paxos
|
||||
paxos_test.init();
|
||||
paxos_osdmap.init();
|
||||
paxos_mdsmap.init();
|
||||
paxos_clientmap.init();
|
||||
|
||||
// i'm ready!
|
||||
messenger->set_dispatcher(this);
|
||||
|
||||
// start ticker
|
||||
reset_tick();
|
||||
|
||||
// call election?
|
||||
if (monmap->num_mon > 1) {
|
||||
assert(monmap->num_mon != 2);
|
||||
call_election();
|
||||
} else {
|
||||
// we're standalone.
|
||||
set<int> q;
|
||||
q.insert(whoami);
|
||||
win_election(1, q);
|
||||
}
|
||||
|
||||
lock.Unlock();
|
||||
}
|
||||
|
||||
void Monitor::shutdown()
|
||||
{
|
||||
dout(1) << "shutdown" << endl;
|
||||
|
||||
elector.shutdown();
|
||||
|
||||
if (is_leader()) {
|
||||
// stop osds.
|
||||
for (set<int>::iterator it = osdmon->osdmap.get_osds().begin();
|
||||
it != osdmon->osdmap.get_osds().end();
|
||||
it++) {
|
||||
if (osdmon->osdmap.is_down(*it)) continue;
|
||||
dout(10) << "sending shutdown to osd" << *it << endl;
|
||||
messenger->send_message(new MGenericMessage(MSG_SHUTDOWN),
|
||||
osdmon->osdmap.get_inst(*it));
|
||||
}
|
||||
osdmon->mark_all_down();
|
||||
|
||||
// monitors too.
|
||||
for (int i=0; i<monmap->num_mon; i++)
|
||||
if (i != whoami)
|
||||
messenger->send_message(new MGenericMessage(MSG_SHUTDOWN),
|
||||
monmap->get_inst(i));
|
||||
}
|
||||
|
||||
// cancel all events
|
||||
cancel_tick();
|
||||
timer.cancel_all();
|
||||
timer.join();
|
||||
|
||||
// unmount my local storage
|
||||
if (store)
|
||||
delete store;
|
||||
|
||||
// clean up
|
||||
if (osdmon) delete osdmon;
|
||||
if (mdsmon) delete mdsmon;
|
||||
if (clientmon) delete clientmon;
|
||||
|
||||
// die.
|
||||
messenger->shutdown();
|
||||
delete messenger;
|
||||
}
|
||||
void Monitor::shutdown()
|
||||
{
|
||||
dout(1) << "shutdown" << endl;
|
||||
|
||||
elector.shutdown();
|
||||
|
||||
if (is_leader()) {
|
||||
// stop osds.
|
||||
for (set<int>::iterator it = osdmon->osdmap.get_osds().begin();
|
||||
it != osdmon->osdmap.get_osds().end();
|
||||
it++) {
|
||||
if (osdmon->osdmap.is_down(*it)) continue;
|
||||
dout(10) << "sending shutdown to osd" << *it << endl;
|
||||
messenger->send_message(new MGenericMessage(MSG_SHUTDOWN),
|
||||
osdmon->osdmap.get_inst(*it));
|
||||
}
|
||||
osdmon->mark_all_down();
|
||||
|
||||
// monitors too.
|
||||
for (int i=0; i<monmap->num_mon; i++)
|
||||
if (i != whoami)
|
||||
messenger->send_message(new MGenericMessage(MSG_SHUTDOWN),
|
||||
monmap->get_inst(i));
|
||||
}
|
||||
|
||||
// cancel all events
|
||||
cancel_tick();
|
||||
timer.cancel_all();
|
||||
timer.join();
|
||||
|
||||
// unmount my local storage
|
||||
if (store)
|
||||
delete store;
|
||||
|
||||
// clean up
|
||||
if (osdmon) delete osdmon;
|
||||
if (mdsmon) delete mdsmon;
|
||||
if (clientmon) delete clientmon;
|
||||
|
||||
// die.
|
||||
messenger->shutdown();
|
||||
delete messenger;
|
||||
}
|
||||
|
||||
|
||||
void Monitor::call_election()
|
||||
{
|
||||
if (monmap->num_mon == 1) return;
|
||||
void Monitor::call_election()
|
||||
{
|
||||
if (monmap->num_mon == 1) return;
|
||||
|
||||
dout(10) << "call_election" << endl;
|
||||
state = STATE_STARTING;
|
||||
|
||||
// tell paxos
|
||||
paxos_test.election_starting();
|
||||
paxos_mdsmap.election_starting();
|
||||
paxos_osdmap.election_starting();
|
||||
paxos_clientmap.election_starting();
|
||||
|
||||
// call a new election
|
||||
elector.call_election();
|
||||
}
|
||||
|
||||
dout(10) << "call_election" << endl;
|
||||
state = STATE_STARTING;
|
||||
void Monitor::win_election(epoch_t epoch, set<int>& active)
|
||||
{
|
||||
state = STATE_LEADER;
|
||||
leader = whoami;
|
||||
mon_epoch = epoch;
|
||||
quorum = active;
|
||||
dout(10) << "win_election, epoch " << mon_epoch << " quorum is " << quorum << endl;
|
||||
|
||||
// init paxos
|
||||
paxos_test.leader_init();
|
||||
paxos_mdsmap.leader_init();
|
||||
paxos_osdmap.leader_init();
|
||||
paxos_clientmap.leader_init();
|
||||
|
||||
// init
|
||||
osdmon->election_finished();
|
||||
mdsmon->election_finished();
|
||||
clientmon->election_finished();
|
||||
}
|
||||
|
||||
// tell paxos
|
||||
paxos_test.election_starting();
|
||||
paxos_mdsmap.election_starting();
|
||||
paxos_osdmap.election_starting();
|
||||
paxos_clientmap.election_starting();
|
||||
|
||||
// call a new election
|
||||
elector.call_election();
|
||||
}
|
||||
|
||||
void Monitor::win_election(epoch_t epoch, set<int>& active)
|
||||
{
|
||||
state = STATE_LEADER;
|
||||
leader = whoami;
|
||||
mon_epoch = epoch;
|
||||
quorum = active;
|
||||
dout(10) << "win_election, epoch " << mon_epoch << " quorum is " << quorum << endl;
|
||||
|
||||
// init paxos
|
||||
paxos_test.leader_init();
|
||||
paxos_mdsmap.leader_init();
|
||||
paxos_osdmap.leader_init();
|
||||
paxos_clientmap.leader_init();
|
||||
|
||||
// init
|
||||
osdmon->election_finished();
|
||||
mdsmon->election_finished();
|
||||
clientmon->election_finished();
|
||||
}
|
||||
|
||||
void Monitor::lose_election(epoch_t epoch, int l)
|
||||
{
|
||||
state = STATE_PEON;
|
||||
mon_epoch = epoch;
|
||||
leader = l;
|
||||
dout(10) << "lose_election, epoch " << mon_epoch << " leader is mon" << leader << endl;
|
||||
|
||||
// init paxos
|
||||
paxos_test.peon_init();
|
||||
paxos_mdsmap.peon_init();
|
||||
paxos_osdmap.peon_init();
|
||||
paxos_clientmap.peon_init();
|
||||
|
||||
// init
|
||||
osdmon->election_finished();
|
||||
mdsmon->election_finished();
|
||||
clientmon->election_finished();
|
||||
}
|
||||
void Monitor::lose_election(epoch_t epoch, int l)
|
||||
{
|
||||
state = STATE_PEON;
|
||||
mon_epoch = epoch;
|
||||
leader = l;
|
||||
dout(10) << "lose_election, epoch " << mon_epoch << " leader is mon" << leader << endl;
|
||||
|
||||
// init paxos
|
||||
paxos_test.peon_init();
|
||||
paxos_mdsmap.peon_init();
|
||||
paxos_osdmap.peon_init();
|
||||
paxos_clientmap.peon_init();
|
||||
|
||||
// init
|
||||
osdmon->election_finished();
|
||||
mdsmon->election_finished();
|
||||
clientmon->election_finished();
|
||||
}
|
||||
|
||||
|
||||
void Monitor::handle_command(MMonCommand *m)
|
||||
{
|
||||
dout(0) << "handle_command " << *m << endl;
|
||||
|
||||
int r = -1;
|
||||
string rs = "unrecognized command";
|
||||
|
||||
if (!m->cmd.empty()) {
|
||||
if (m->cmd[0] == "stop") {
|
||||
r = 0;
|
||||
rs = "stopping";
|
||||
do_stop();
|
||||
}
|
||||
else if (m->cmd[0] == "mds") {
|
||||
mdsmon->dispatch(m);
|
||||
return;
|
||||
}
|
||||
else if (m->cmd[0] == "osd") {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
// reply
|
||||
messenger->send_message(new MMonCommandAck(r, rs), m->get_source_inst());
|
||||
delete m;
|
||||
}
|
||||
void Monitor::handle_command(MMonCommand *m)
|
||||
{
|
||||
dout(0) << "handle_command " << *m << endl;
|
||||
|
||||
int r = -1;
|
||||
string rs = "unrecognized command";
|
||||
|
||||
if (!m->cmd.empty()) {
|
||||
if (m->cmd[0] == "stop") {
|
||||
r = 0;
|
||||
rs = "stopping";
|
||||
do_stop();
|
||||
}
|
||||
else if (m->cmd[0] == "mds") {
|
||||
mdsmon->dispatch(m);
|
||||
return;
|
||||
}
|
||||
else if (m->cmd[0] == "osd") {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
// reply
|
||||
messenger->send_message(new MMonCommandAck(r, rs), m->get_source_inst());
|
||||
delete m;
|
||||
}
|
||||
|
||||
|
||||
void Monitor::do_stop()
|
||||
{
|
||||
dout(0) << "do_stop -- shutting down" << endl;
|
||||
mdsmon->do_stop();
|
||||
}
|
||||
void Monitor::do_stop()
|
||||
{
|
||||
dout(0) << "do_stop -- shutting down" << endl;
|
||||
mdsmon->do_stop();
|
||||
}
|
||||
|
||||
|
||||
void Monitor::dispatch(Message *m)
|
||||
{
|
||||
lock.Lock();
|
||||
{
|
||||
switch (m->get_type()) {
|
||||
|
||||
// misc
|
||||
case MSG_PING_ACK:
|
||||
handle_ping_ack((MPingAck*)m);
|
||||
break;
|
||||
|
||||
case MSG_SHUTDOWN:
|
||||
if (m->get_source().is_osd())
|
||||
void Monitor::dispatch(Message *m)
|
||||
{
|
||||
lock.Lock();
|
||||
{
|
||||
switch (m->get_type()) {
|
||||
|
||||
// misc
|
||||
case MSG_PING_ACK:
|
||||
handle_ping_ack((MPingAck*)m);
|
||||
break;
|
||||
|
||||
case MSG_SHUTDOWN:
|
||||
if (m->get_source().is_osd())
|
||||
osdmon->dispatch(m);
|
||||
else
|
||||
else
|
||||
handle_shutdown(m);
|
||||
break;
|
||||
|
||||
break;
|
||||
|
||||
case MSG_MON_COMMAND:
|
||||
handle_command((MMonCommand*)m);
|
||||
break;
|
||||
|
Loading…
Reference in New Issue
Block a user