From 4651dc105780d03f3426b83166afc767c18b6db7 Mon Sep 17 00:00:00 2001 From: Greg Farnum Date: Thu, 8 Oct 2009 16:29:43 -0700 Subject: [PATCH] mon: Add MonmapMonitor source. --- src/mon/MonmapMonitor.cc | 104 +++++++++++++++++++++++++++++++++++++++ src/mon/MonmapMonitor.h | 69 ++++++++++++++++++++++++++ 2 files changed, 173 insertions(+) create mode 100644 src/mon/MonmapMonitor.cc create mode 100644 src/mon/MonmapMonitor.h diff --git a/src/mon/MonmapMonitor.cc b/src/mon/MonmapMonitor.cc new file mode 100644 index 0000000000000..a231ce080771c --- /dev/null +++ b/src/mon/MonmapMonitor.cc @@ -0,0 +1,104 @@ +// -*- 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 + * + * 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 "MonmapMonitor.h" +#include "Monitor.h" +#include "MonitorStore.h" + +#include "messages/MMonAdd.h" +#include "common/Timer.h" + +#include +#include "config.h" + +#define DOUT_SUBSYS mon +#undef dout_prefix +#define dout_prefix _prefix(mon) +static ostream& _prefix(Monitor *mon) { + return *_dout << dbeginl + << "mon" << mon->whoami + << (mon->is_starting() ? (const char*)"(starting)":(mon->is_leader() ? (const char*)"(leader)":(mon->is_peon() ? (const char*)"(peon)":(const char*)"(?\?)"))) + << ".client v" << mon->monmap->epoch << " "; +} + +void MonmapMonitor::create_initial(bufferlist& bl) +{ + //what is this function supposed to do? +} + +bool MonmapMonitor::update_from_paxos() +{ + //check versions to see if there's an update + version_t paxosv = paxos->get_version(); + if (paxosv == mon->monmap->epoch) return true; + assert(paxosv >= mon->monmap->epoch); + + dout(10) << "update_from_paxos paxosv " << paxosv + << ", my v " << mon->monmap->epoch << dendl; + + //read and decode + monmap_bl.clear(); + bool success = paxos->read(paxosv, monmap_bl); + assert(success); + dout(10) << "update_from_paxos got " << paxosv << dendl; + mon->monmap->decode(monmap_bl); + + //save the bufferlist version in the paxos instance as well + paxos->stash_latest(paxosv, monmap_bl); + + return true; +} + +void MonmapMonitor::create_pending() +{ + pending_map = *mon->monmap; + pending_map.epoch++; + dout(10) << "create_pending monmap epoch " << pending_map.epoch << dendl; +} + +void MonmapMonitor::encode_pending(bufferlist& bl) +{ + dout(10) << "encode_pending epoch " << pending_map.epoch << dendl; + + assert(paxos->get_version() + 1 == pending_map.epoch); + pending_map.encode(bl); +} + +bool MonmapMonitor::preprocess_query(PaxosServiceMessage *m) +{ + return false; +} + +bool MonmapMonitor::prepare_update(PaxosServiceMessage *message) +{ + MMonAdd *m = (MMonAdd *) message; + pending_map.add(m->address); + return true; +} + +bool MonmapMonitor::should_propose(double& delay) +{ + delay = 0.0; + return true; +} + +void MonmapMonitor::committed() +{ + //Nothing useful to do here. +} + +void MonmapMonitor::tick() +{ + update_from_paxos(); +} diff --git a/src/mon/MonmapMonitor.h b/src/mon/MonmapMonitor.h new file mode 100644 index 0000000000000..d8ff389e88726 --- /dev/null +++ b/src/mon/MonmapMonitor.h @@ -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) 2009 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. + * + */ + +/* + * The Monmap Monitor is used to track the monitors in the cluster. + */ + +#ifndef __MONMAPMONITOR_H +#define __MONMAPMONITOR_H + +#include +#include + +using namespace std; + +#include "include/types.h" +#include "msg/Messenger.h" + +#include "PaxosService.h" +#include "MonMap.h" + +class MMonGetMap; +class MMonMap; + +class MonmapMonitor : public PaxosService { + public: + MonmapMonitor(Monitor *mn, Paxos *p) : PaxosService(mn, p) {} + MonMap pending_map; //the pending map awaiting passage + + void create_initial(bufferlist& bl); + + bool update_from_paxos(); + + void create_pending(); + + void encode_pending(bufferlist& bl); + + + bool preprocess_query(PaxosServiceMessage *m); + + bool prepare_update(PaxosServiceMessage *m); + + /* + * Since monitors are pretty + * important, this implementation will just write 0.0. + */ + bool should_propose(double& delay); + + void committed(); + + void tick(); + + private: + bufferlist monmap_bl; +}; + + +#endif -- 2.39.5