]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
MMonMap message type, minor client cleanup, monmap cleanup
authorsageweil <sageweil@29311d96-e01e-0410-9327-a35deaab8ce9>
Tue, 13 Nov 2007 01:35:23 +0000 (01:35 +0000)
committersageweil <sageweil@29311d96-e01e-0410-9327-a35deaab8ce9>
Tue, 13 Nov 2007 01:35:23 +0000 (01:35 +0000)
git-svn-id: https://ceph.svn.sf.net/svnroot/ceph@2058 29311d96-e01e-0410-9327-a35deaab8ce9

trunk/ceph/client/Client.cc
trunk/ceph/client/Client.h
trunk/ceph/include/ceph_fs_msgs.h
trunk/ceph/messages/MMonMap.h [new file with mode: 0644]
trunk/ceph/mon/Elector.cc
trunk/ceph/mon/MonMap.h
trunk/ceph/mon/Monitor.cc
trunk/ceph/mon/Paxos.cc
trunk/ceph/msg/Message.cc
trunk/ceph/newsyn.cc

index 70ee46f4acf8ba285063314b8cd0b92de3171a03..8eaee998e698cdcf27d21ed3a7bb22088f70269c 100644 (file)
@@ -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 || 
index 727098906c6178b07c963c9e5dbc88316c1b29fc..409d2947ae9830a338ad4aa9a3631f93e3c50a32 100644 (file)
@@ -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();   
 
index 05ab1c7b9338ac6cd348029fb89e6de4cb120a1d..4d6985e3b68a406218d5f6cb60cb97f5338311d1 100644 (file)
@@ -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 (file)
index 0000000..e2059fa
--- /dev/null
@@ -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 <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 __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
index 4a09b58ab507359037a12cb61e05b8a7381db34e..b5fef99042388a86e00f7e1477910d78e8bd6cd2 100644 (file)
@@ -65,8 +65,8 @@ void Elector::start()
   acked_me.insert(whoami);
   
   // bcast to everyone else
-  for (int i=0; i<mon->monmap->num_mon; ++i) {
-    if (i == whoami) continue;
+  for (unsigned i=0; i<mon->monmap->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();
     }
index c13e41472d608fa0cf4577f1efa80b36ca76d835..3b6bad339716d28528e232ccbfa524b4730ba13f 100644 (file)
@@ -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<entity_inst_t> 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);
   }
 
index f032fb824eb7c4e5b8222b17e33eeff9ae1ef3d4..19b4fb09b2b049a0d9e5b8c50e1d2bdf1c737a98 100644 (file)
@@ -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; i<monmap->num_mon; i++)
-      if (i != whoami)
+    for (unsigned i=0; i<monmap->size(); 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;
index c1f4472059ff50dbf17a752c725770282c549219..ce15e5d5b48131bcabd9115ba45a33f12c1045dd 100644 (file)
@@ -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;
index 8f41c4bef97047a6b34446d5d50beab6ebc682bf..872b4414cc273159e35cd0ee61e075e74fa92b39 100644 (file)
@@ -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;
index 4b37591cdca693a85261bf869fbe2158d656f6e0..4627762536ce5965f041d9cdd18b2b413f70ae49 100644 (file)
@@ -344,14 +344,10 @@ int main(int argc, char **argv)
   map<int,SyntheticClient *> syn;//[start_client];
   int nclients = 0;
   for (int i=0; i<start_client; i++) {
-    //if (mpirank != start_mds + start_osd + i % client_nodes) continue;
-    //int node = g_conf.ms_skip_rank0+start_mds + skip_osd + i / clients_per_node;
     int node = g_conf.ms_skip_rank0+start_mds + skip_osd + i % client_nodes;
     if (mpirank != node) continue;
     clientlist.insert(i);
-    client[i] = new Client(rank.register_entity(entity_name_t(entity_name_t::TYPE_CLIENT, -1-i)),
-                          monmap, 
-                          i+1);
+    client[i] = new Client(rank.register_entity(entity_name_t(entity_name_t::TYPE_CLIENT, -1)), monmap);
     syn[i] = new SyntheticClient(client[i]);
     
     started++;