From 08cef71783c4cee101d38b25581521b04b9c47af Mon Sep 17 00:00:00 2001 From: sageweil Date: Tue, 13 Nov 2007 01:35:23 +0000 Subject: [PATCH] MMonMap message type, minor client cleanup, monmap cleanup git-svn-id: https://ceph.svn.sf.net/svnroot/ceph@2058 29311d96-e01e-0410-9327-a35deaab8ce9 --- trunk/ceph/client/Client.cc | 6 ++--- trunk/ceph/client/Client.h | 3 +-- trunk/ceph/include/ceph_fs_msgs.h | 1 + trunk/ceph/messages/MMonMap.h | 39 +++++++++++++++++++++++++++++++ trunk/ceph/mon/Elector.cc | 8 +++---- trunk/ceph/mon/MonMap.h | 16 ++++++------- trunk/ceph/mon/Monitor.cc | 10 ++++---- trunk/ceph/mon/Paxos.cc | 4 ++-- trunk/ceph/msg/Message.cc | 9 +++++-- trunk/ceph/newsyn.cc | 6 +---- 10 files changed, 70 insertions(+), 32 deletions(-) create mode 100644 trunk/ceph/messages/MMonMap.h diff --git a/trunk/ceph/client/Client.cc b/trunk/ceph/client/Client.cc index 70ee46f4acf8b..8eaee998e698c 100644 --- a/trunk/ceph/client/Client.cc +++ b/trunk/ceph/client/Client.cc @@ -101,11 +101,10 @@ public: // cons/des -Client::Client(Messenger *m, MonMap *mm, int in) : timer(client_lock) +Client::Client(Messenger *m, MonMap *mm) : timer(client_lock) { // which client am i? whoami = m->get_myname().num(); - my_instance = in; monmap = mm; mounted = false; @@ -1372,7 +1371,7 @@ void Client::_try_mount() { dout(10) << "_try_mount" << dendl; int mon = monmap->pick_mon(); - dout(2) << "sending client_mount to mon" << mon << " as instance " << my_instance << dendl; + dout(2) << "sending client_mount to mon" << mon << dendl; messenger->set_dispatcher(this); messenger->send_message(new MClientMount, monmap->get_inst(mon)); @@ -1397,7 +1396,6 @@ int Client::mount() objecter->init(); _try_mount(); - //messenger->set_dispatcher(this); // FIXME: there is still a race condition here! while (!mdsmap || !osdmap || diff --git a/trunk/ceph/client/Client.h b/trunk/ceph/client/Client.h index 727098906c617..409d2947ae983 100644 --- a/trunk/ceph/client/Client.h +++ b/trunk/ceph/client/Client.h @@ -480,7 +480,6 @@ class Client : public Dispatcher { bool mounted; bool unmounting; Cond mount_cond; - int my_instance; int unsafe_sync_write; public: @@ -656,7 +655,7 @@ protected: friend class SyntheticClient; public: - Client(Messenger *m, MonMap *mm, int i=0); + Client(Messenger *m, MonMap *mm); ~Client(); void tear_down_cache(); diff --git a/trunk/ceph/include/ceph_fs_msgs.h b/trunk/ceph/include/ceph_fs_msgs.h index 05ab1c7b9338a..4d6985e3b68a4 100644 --- a/trunk/ceph/include/ceph_fs_msgs.h +++ b/trunk/ceph/include/ceph_fs_msgs.h @@ -12,6 +12,7 @@ #define CEPH_MSG_PING_ACK 3 /* client <-> monitor */ +#define CEPH_MSG_MON_MAP 4 #define CEPH_MSG_CLIENT_MOUNT 10 #define CEPH_MSG_CLIENT_UNMOUNT 11 #define CEPH_MSG_STATFS 12 diff --git a/trunk/ceph/messages/MMonMap.h b/trunk/ceph/messages/MMonMap.h new file mode 100644 index 0000000000000..e2059fa382756 --- /dev/null +++ b/trunk/ceph/messages/MMonMap.h @@ -0,0 +1,39 @@ +// -*- 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. + * + */ + +#ifndef __MMONMAP_H +#define __MMONMAP_H + +#include "msg/Message.h" + +class MMonMap : public Message { +public: + bufferlist monmapbl; + + MMonMap() : Message(CEPH_MSG_MON_MAP) { } + MMonMap(bufferlist &bl) : Message(CEPH_MSG_MON_MAP) { + monmapbl.claim(bl); + } + + char *get_type_name() { return "mon_map"; } + + void encode_payload() { + payload = monmapbl; + } + void decode_payload() { + monmapbl = payload; + } +}; + +#endif diff --git a/trunk/ceph/mon/Elector.cc b/trunk/ceph/mon/Elector.cc index 4a09b58ab5073..b5fef99042388 100644 --- a/trunk/ceph/mon/Elector.cc +++ b/trunk/ceph/mon/Elector.cc @@ -65,8 +65,8 @@ void Elector::start() acked_me.insert(whoami); // bcast to everyone else - for (int i=0; imonmap->num_mon; ++i) { - if (i == whoami) continue; + for (unsigned i=0; imonmap->size(); ++i) { + if ((int)i == whoami) continue; mon->messenger->send_message(new MMonElection(MMonElection::OP_PROPOSE, epoch), mon->monmap->get_inst(i)); } @@ -119,7 +119,7 @@ void Elector::expire() // did i win? if (electing_me && - acked_me.size() > (unsigned)(mon->monmap->num_mon / 2)) { + acked_me.size() > (unsigned)(mon->monmap->size() / 2)) { // i win victory(); } else { @@ -217,7 +217,7 @@ void Elector::handle_ack(MMonElection *m) dout(5) << " so far i have " << acked_me << dendl; // is that _everyone_? - if (acked_me.size() == (unsigned)mon->monmap->num_mon) { + if (acked_me.size() == mon->monmap->size()) { // if yes, shortcut to election finish victory(); } diff --git a/trunk/ceph/mon/MonMap.h b/trunk/ceph/mon/MonMap.h index c13e41472d608..3b6bad339716d 100644 --- a/trunk/ceph/mon/MonMap.h +++ b/trunk/ceph/mon/MonMap.h @@ -26,38 +26,39 @@ class MonMap { public: epoch_t epoch; // what epoch/version of the monmap ceph_fsid_t fsid; - int32_t num_mon; vector mon_inst; int last_mon; // last mon i talked to - MonMap(int s=0) : epoch(0), num_mon(s), mon_inst(s), last_mon(-1) { + MonMap(int s=0) : epoch(0), mon_inst(s), last_mon(-1) { generate_fsid(); } + unsigned size() { + return mon_inst.size(); + } + void add_mon(entity_inst_t inst) { mon_inst.push_back(inst); - num_mon++; } // pick a mon. // choice should be stable, unless we explicitly ask for a new one. int pick_mon(bool newmon=false) { if (newmon || (last_mon < 0)) { - last_mon = rand() % num_mon; + last_mon = rand() % mon_inst.size(); } return last_mon; } - const entity_inst_t &get_inst(int m) { - assert(m < num_mon); + const entity_inst_t &get_inst(unsigned m) { + assert(m < mon_inst.size()); return mon_inst[m]; } void encode(bufferlist& blist) { ::_encode(epoch, blist); ::_encode(fsid, blist); - ::_encode(num_mon, blist); ::_encode(mon_inst, blist); } @@ -65,7 +66,6 @@ class MonMap { int off = 0; ::_decode(epoch, blist, off); ::_decode(fsid, blist, off); - ::_decode(num_mon, blist, off); ::_decode(mon_inst, blist, off); } diff --git a/trunk/ceph/mon/Monitor.cc b/trunk/ceph/mon/Monitor.cc index f032fb824eb7c..19b4fb09b2b04 100644 --- a/trunk/ceph/mon/Monitor.cc +++ b/trunk/ceph/mon/Monitor.cc @@ -82,8 +82,8 @@ void Monitor::init() reset_tick(); // call election? - if (monmap->num_mon > 1) { - assert(monmap->num_mon != 2); + if (monmap->size() > 1) { + assert(monmap->size() != 2); call_election(); } else { // we're standalone. @@ -114,8 +114,8 @@ void Monitor::shutdown() osdmon->mark_all_down(); // monitors too. - for (int i=0; inum_mon; i++) - if (i != whoami) + for (unsigned i=0; isize(); i++) + if ((int)i != whoami) messenger->send_message(new MGenericMessage(CEPH_MSG_SHUTDOWN), monmap->get_inst(i)); } @@ -142,7 +142,7 @@ void Monitor::shutdown() void Monitor::call_election() { - if (monmap->num_mon == 1) return; + if (monmap->size() == 1) return; dout(10) << "call_election" << dendl; state = STATE_STARTING; diff --git a/trunk/ceph/mon/Paxos.cc b/trunk/ceph/mon/Paxos.cc index c1f4472059ff5..ce15e5d5b4813 100644 --- a/trunk/ceph/mon/Paxos.cc +++ b/trunk/ceph/mon/Paxos.cc @@ -244,7 +244,7 @@ void Paxos::begin(bufferlist& v) // we must already have a majority for this to work. assert(mon->get_quorum().size() == 1 || - num_last > (unsigned)mon->monmap->num_mon/2); + num_last > (unsigned)mon->monmap->size()/2); // and no value, yet. assert(new_value.length() == 0); @@ -345,7 +345,7 @@ void Paxos::handle_accept(MMonPaxos *accept) dout(10) << " now " << accepted << " have accepted" << dendl; // new majority? - if (accepted.size() == (unsigned)mon->monmap->num_mon/2+1) { + if (accepted.size() == (unsigned)mon->monmap->size()/2+1) { // yay, commit! // note: this may happen before the lease is reextended (below) dout(10) << " got majority, committing" << dendl; diff --git a/trunk/ceph/msg/Message.cc b/trunk/ceph/msg/Message.cc index 8f41c4bef9704..872b4414cc273 100644 --- a/trunk/ceph/msg/Message.cc +++ b/trunk/ceph/msg/Message.cc @@ -24,8 +24,6 @@ using namespace std; #include "messages/MPing.h" #include "messages/MPingAck.h" -//#include "messages/MFailure.h" -//#include "messages/MFailureAck.h" #include "messages/MOSDBoot.h" #include "messages/MOSDIn.h" @@ -43,6 +41,8 @@ using namespace std; #include "messages/MOSDPGRemove.h" #include "messages/MOSDPGActivateSet.h" +#include "messages/MMonMap.h" + #include "messages/MClientMount.h" #include "messages/MClientUnmount.h" #include "messages/MClientSession.h" @@ -145,6 +145,10 @@ decode_message(ceph_message_header& env, bufferlist& payload) m = new MPingAck(); break; + case CEPH_MSG_MON_MAP: + m = new MMonMap; + break; + /* case MSG_FAILURE: m = new MFailure(); @@ -199,6 +203,7 @@ decode_message(ceph_message_header& env, bufferlist& payload) m = new MOSDPGActivateSet(); break; + // clients case CEPH_MSG_CLIENT_MOUNT: m = new MClientMount; diff --git a/trunk/ceph/newsyn.cc b/trunk/ceph/newsyn.cc index 4b37591cdca69..4627762536ce5 100644 --- a/trunk/ceph/newsyn.cc +++ b/trunk/ceph/newsyn.cc @@ -344,14 +344,10 @@ int main(int argc, char **argv) map syn;//[start_client]; int nclients = 0; for (int i=0; i