From 20279705ad64a99f79ed752db145912e049aa20f Mon Sep 17 00:00:00 2001 From: sageweil Date: Thu, 14 Jun 2007 21:58:36 +0000 Subject: [PATCH] * forgot this git-svn-id: https://ceph.svn.sf.net/svnroot/ceph@1421 29311d96-e01e-0410-9327-a35deaab8ce9 --- trunk/ceph/mon/PaxosService.cc | 69 ++++++++++++++++++++++++++++++++++ 1 file changed, 69 insertions(+) create mode 100644 trunk/ceph/mon/PaxosService.cc diff --git a/trunk/ceph/mon/PaxosService.cc b/trunk/ceph/mon/PaxosService.cc new file mode 100644 index 0000000000000..021981b7b148b --- /dev/null +++ b/trunk/ceph/mon/PaxosService.cc @@ -0,0 +1,69 @@ +// -*- 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 + * + * 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. + * + */ + +#include "PaxosService.h" +#include "common/Clock.h" +#include "Monitor.h" + + + +#include "config.h" +#undef dout +#define dout(l) if (l<=g_conf.debug || l<=g_conf.debug_mon) cout << g_clock.now() << " mon" << mon->whoami << (mon->is_starting() ? (const char*)"(starting)":(mon->is_leader() ? (const char*)"(leader)":(mon->is_peon() ? (const char*)"(peon)":(const char*)"(?\?)"))) << "." << get_paxos_name(paxos->machine_id) << " " +#define derr(l) if (l<=g_conf.debug || l<=g_conf.debug_mon) cerr << g_clock.now() << " mon" << mon->whoami << (mon->is_starting() ? (const char*)"(starting)":(mon->is_leader() ? (const char*)"(leader)":(mon->is_peon() ? (const char*)"(peon)":(const char*)"(?\?)"))) << "." << get_paxos_name(paxos->machine_id) << " " + + + +void PaxosService::dispatch(Message *m) +{ + dout(10) << "dispatch " << *m << " from " << m->get_source_inst() << endl; + + // make sure our map is readable and up to date + if (!paxos->is_readable() || + !update_from_paxos()) { + dout(10) << " waiting for paxos -> readable" << endl; + paxos->wait_for_readable(new C_RetryMessage(this, m)); + return; + } + + // preprocess + if (preprocess_update(m)) + return; // easy! + + // leader? + if (!mon->is_leader()) { + // fw to leader + dout(10) << " fw to leader mon" << mon->get_leader() << endl; + mon->messenger->send_message(m, mon->monmap->get_inst(mon->get_leader())); + return; + } + + // writeable? + if (!paxos->is_writeable()) { + dout(10) << " waiting for paxos -> writeable" << endl; + paxos->wait_for_writeable(new C_RetryMessage(this, m)); + return; + } + + prepare_update(m); + + // do it now (for now!) *** + propose_pending(); +} + +void PaxosService::election_finished() +{ + if (mon->is_leader() && g_conf.mkfs) + create_initial(); +} -- 2.39.5