]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
fixed htons goof in SimpleMessenger; mkmonmap now works; monitor elector sorta working!
authorsageweil <sageweil@29311d96-e01e-0410-9327-a35deaab8ce9>
Thu, 1 Feb 2007 06:47:48 +0000 (06:47 +0000)
committersageweil <sageweil@29311d96-e01e-0410-9327-a35deaab8ce9>
Thu, 1 Feb 2007 06:47:48 +0000 (06:47 +0000)
git-svn-id: https://ceph.svn.sf.net/svnroot/ceph@1069 29311d96-e01e-0410-9327-a35deaab8ce9

trunk/ceph/messages/MClientBoot.h
trunk/ceph/messages/MMonElectionAck.h
trunk/ceph/messages/MMonElectionPropose.h
trunk/ceph/messages/MMonElectionVictory.h
trunk/ceph/mkmonmap.cc
trunk/ceph/mon/Elector.cc
trunk/ceph/mon/Monitor.cc
trunk/ceph/mon/Monitor.h
trunk/ceph/mon/OSDMonitor.cc
trunk/ceph/msg/SimpleMessenger.cc
trunk/ceph/msg/tcp.h

index 0b73505642d7d39b1b3e969112f3ab50cb57ef0b..460f9f02e27f411050b3fecec7f0bfc8e3063467 100644 (file)
 class MClientBoot : public Message {
 
  public:
-  MClientBoot() : Message(MSG_CLIENT_BOOT) { 
-  }
+  MClientBoot() : Message(MSG_CLIENT_BOOT) { }
 
-  char *get_type_name() { return "Cboot"; }
+  char *get_type_name() { return "ClientBoot"; }
 
-  virtual void decode_payload(crope& s, int& off) {  
-  }
-  virtual void encode_payload(crope& s) {  
-  }
+  void encode_payload() { }
+  void decode_payload() { }
 };
 
 #endif
index 981e2e672a2bf18557f1ec1a6f8c400cbd4cdbcc..2399cca73d60c44f5193a3d0075880b00a7f6e86 100644 (file)
@@ -23,6 +23,9 @@ class MMonElectionAck : public Message {
   MMonElectionAck() : Message(MSG_MON_ELECTION_ACK) {}
   
   virtual char *get_type_name() { return "election_ack"; }
+
+  void encode_payload() {}
+  void decode_payload() {}
 };
 
 #endif
index b8e24499f03ec1c2aadc79b895a74ca69d30376b..d9310f222bc7b1fdfdad52ffd70667a35f2cc288 100644 (file)
@@ -23,6 +23,10 @@ class MMonElectionPropose : public Message {
   MMonElectionPropose() : Message(MSG_MON_ELECTION_PROPOSE) {}
   
   virtual char *get_type_name() { return "election_propose"; }
+
+  void encode_payload() {}
+  void decode_payload() {}
+
 };
 
 #endif
index c1faad63569927274ccc142f550d935cca94de83..8bdbf2f85a3aaa24be343412b982e69687dca30f 100644 (file)
@@ -28,15 +28,13 @@ class MMonElectionVictory : public Message {
   
   virtual char *get_type_name() { return "election_victory"; }
   
-  /*
   void encode_payload() {
-    ::_encode(active_set, payload);
+    //::_encode(active_set, payload);
   }
   void decode_payload() {
-    int off = 0;
-    ::_decode(active_set, payload, off);
+    //int off = 0;
+    //::_decode(active_set, payload, off);
   }
-  */
 };
 
 #endif
index 6d049f4bd7186eda45250c943574d78b2caa14c0..8a3e57fb86b8f171989b1f3381c18e333caddf71 100644 (file)
@@ -62,8 +62,10 @@ bool parse_ip_port(const char *s, tcpaddr_t& tcpaddr)
   }
   
   // copy into inst
+  memset(&tcpaddr, 0, sizeof(addr));
+  tcpaddr.sin_family = AF_INET;
   memcpy((char*)&tcpaddr.sin_addr.s_addr, (char*)addr, 4);
-  tcpaddr.sin_port = port;
+  tcpaddr.sin_port = htons(port);
 
   return true;
 }
@@ -88,6 +90,7 @@ int main(int argc, char **argv)
        cerr << "mkmonmap: invalid ip:port '" << args[i] << "'" << endl;
        return -1;
       }
+      
       entity_inst_t inst;
       inst.set_addr(addr);
       cout << "mkmonmap: mon" << monmap.num_mon << " " << inst << endl;
index 0084a5de9d4177b6569ffe53922d1fb1ae084168..ddb3351d434f1f1843a9ebaf285b54d5ff3e6578 100644 (file)
@@ -10,8 +10,8 @@
 
 #include "config.h"
 #undef dout
-#define  dout(l) if (l<=g_conf.debug || l<=g_conf.debug_mon) cout << "mon" << whoami << " "
-#define  derr(l) if (l<=g_conf.debug || l<=g_conf.debug_mon) cerr << "mon" << whoami << " "
+#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*)"(?\?)"))) << ".elector "
+#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*)"(?\?)"))) << ".elector "
 
 
 void Elector::start()
@@ -38,7 +38,7 @@ void Elector::start()
 
 void Elector::defer(int who)
 {
-  dout(5) << "defer -- i'm deferring to " << who << endl;
+  dout(5) << "defer to " << who << endl;
 
   if (electing_me) {
        acked_me.clear();
@@ -98,6 +98,9 @@ void Elector::expire()
 
 void Elector::victory()
 {
+  leader_acked = -1;
+  electing_me = false;
+
   // tell everyone
   for (unsigned i=0; i<mon->monmap->num_mon; ++i) {
        if (i == whoami) continue;
@@ -112,7 +115,7 @@ void Elector::victory()
 
 void Elector::handle_propose(MMonElectionPropose *m)
 {
-  dout(5) << "propose from " << m->get_source() << endl;
+  dout(5) << "handle_propose from " << m->get_source() << endl;
   int from = m->get_source().num();
 
   if (from > whoami) {
@@ -135,7 +138,7 @@ void Elector::handle_propose(MMonElectionPropose *m)
  
 void Elector::handle_ack(MMonElectionAck *m)
 {
-  dout(5) << "ack from " << m->get_source() << endl;
+  dout(5) << "handle_ack from " << m->get_source() << endl;
   int from = m->get_source().num();
   
   if (electing_me) {
@@ -157,7 +160,7 @@ void Elector::handle_ack(MMonElectionAck *m)
 
 void Elector::handle_victory(MMonElectionVictory *m)
 {
-  dout(5) << "victory from " << m->get_source() << endl;
+  dout(5) << "handle_victory from " << m->get_source() << endl;
   int from = m->get_source().num();
   
   if (from < whoami) {
index 66b7166bec686ceeb0f4c4bb22c2d39357750200..a0bf80de5a3a39b3eec912e27bbd6f11d5d117ad 100644 (file)
@@ -66,9 +66,15 @@ void Monitor::init()
   reset_tick();
 
   // call election?
-  assert(monmap->num_mon != 2);
-  if (monmap->num_mon >= 3) 
+  if (monmap->num_mon > 1) {
+    assert(monmap->num_mon != 2); 
     call_election();
+  } else {
+    // we're standalone.
+    set<int> q;
+    q.insert(whoami);
+    win_election(q);
+  }
 }
 
 void Monitor::shutdown()
@@ -123,7 +129,24 @@ void Monitor::call_election()
   //mdsmon->election_starting();
 }
 
+void Monitor::win_election(set<int>& active) 
+{
+  state = STATE_LEADER;
+  leader = whoami;
+  quorum = active;
+  dout(10) << "win_election, quorum is " << quorum << endl;
+
+  // init
+  osdmon->election_finished();
+  //mdsmon->election_finished();
+} 
 
+void Monitor::lose_election(int l) 
+{
+  state = STATE_PEON;
+  leader = l;
+  dout(10) << "lose_election, leader is mon" << leader << endl;
+}
 
 
 
index 7a800b9fc66c45d62cede34d22d42de67c5dd9a7..b4a30403c86508b983bfafe15aad34df3d419243 100644 (file)
@@ -86,20 +86,13 @@ protected:
   friend class MDSMonitor;
   friend class ClientMonitor;
 
-
   // initiate election
   void call_election();
 
-  // called by Elector when it's finished
-  void win_election(set<int>& active) {
-    leader = whoami;
-    quorum = active;
-    state = STATE_LEADER;
-  } 
-  void lose_election(int l) {
-    state = STATE_PEON;
-    leader = l;
-  }
+  // end election (called by Elector)
+  void win_election(set<int>& q);
+  void lose_election(int l);
+
 
  public:
   Monitor(int w, Messenger *m, MonMap *mm) : 
@@ -114,11 +107,6 @@ protected:
     leader(0),
     osdmon(0), mdsmon(0), clientmon(0)
   {
-    // hack leader, until election works.
-    if (whoami == 0)
-      state = STATE_LEADER;
-    else
-      state = STATE_PEON;
   }
 
 
index 7fafbff48b2f1d58c3437ea2357f53833284ee80..0673c9b8c254df6c068561a7c92946cfe73914c8 100644 (file)
@@ -104,13 +104,6 @@ void OSDMonitor::init()
 
     // set up pending_inc
     pending_inc.epoch = osdmap.get_epoch()+1;
-
-  } else {
-    // FIXME. when elections work!
-    if (mon->is_leader()) {
-      create_initial();
-      issue_leases();
-    }
   }
 }
 
@@ -631,10 +624,18 @@ void OSDMonitor::election_starting()
 
 void OSDMonitor::election_finished()
 {
-  dout(10) << "election_starting" << endl;
+  dout(10) << "election_finished" << endl;
 
   state = STATE_INIT;
 
+  // map?
+  if (osdmap.get_epoch() == 0 &&
+      mon->is_leader()) {
+    create_initial();
+  }
+
+
+
   if (mon->is_leader()) {
     // leader.
     if (mon->monmap->num_mon == 1) {
@@ -644,8 +645,8 @@ void OSDMonitor::election_finished()
   } 
   else if (mon->is_peon()) {
     // peon. send info
-    messenger->send_message(new MMonOSDMapInfo(osdmap.epoch, osdmap.mon_epoch),
-                           MSG_ADDR_MON(mon->leader), mon->monmap->get_inst(mon->leader));
+    //messenger->send_message(new MMonOSDMapInfo(osdmap.epoch, osdmap.mon_epoch),
+    //MSG_ADDR_MON(mon->leader), mon->monmap->get_inst(mon->leader));
   }
   
 }
index f6377e828c77d88bda66bb58da82877834f08992..71e71b6d6bab553b3d03761c48c4eb01306c6b4d 100644 (file)
@@ -66,16 +66,16 @@ int Rank::Accepter::start()
     derr(0) << "accepter.start unable to bind to " << rank.listen_addr << endl;
   assert(rc >= 0);
 
+  // what port did we get?
   socklen_t llen = sizeof(rank.listen_addr);
   getsockname(listen_sd, (sockaddr*)&rank.listen_addr, &llen);
   
-  int myport = rank.listen_addr.sin_port;
+  int myport = ntohs(rank.listen_addr.sin_port);
+  dout(10) << "accepter.start bound to port " << myport << endl;
 
   // listen!
   rc = ::listen(listen_sd, 1000);
   assert(rc >= 0);
-
-  //dout(10) << "accepter.start listening on " << myport << endl;
   
   // my address is...
   char host[100];
@@ -92,7 +92,7 @@ int Rank::Accepter::start()
   memcpy((char *) &my_addr.sin_addr.s_addr, 
          myhostname->h_addr_list[0], 
          myhostname->h_length);
-  my_addr.sin_port = myport;
+  my_addr.sin_port = htons(myport);
   
   rank.listen_addr = my_addr;
   
@@ -209,10 +209,14 @@ int Rank::Pipe::connect()
   assert(rc>=0);
 
   // connect!
-  rc = ::connect(sd, (sockaddr*)&peer_inst.addr, sizeof(myAddr));
-  if (rc < 0) return rc;
+  rc = ::connect(sd, (struct sockaddr*)&peer_inst.addr, sizeof(myAddr));
+  if (rc < 0) {
+    dout(10) << "connect error " << peer_inst
+            << ", " << errno << ": " << strerror(errno) << endl;
+    return rc;
+  }
 
-  // identify peer
+  // identify peer ..... FIXME
   entity_inst_t inst;
   rc = tcp_read(sd, (char*)&inst, sizeof(inst));
   if (inst.rank < 0) 
@@ -378,7 +382,9 @@ void Rank::Pipe::writer()
   if (!server) {
     int rc = connect();
     if (rc < 0) {
-      derr(1) << "pipe(" << peer_inst << ' ' << this << ").writer error connecting" << endl;
+      derr(1) << "pipe(" << peer_inst << ' ' << this << ").writer error connecting, " 
+             << errno << ": " << strerror(errno)
+             << endl;
       done = true;
       list<Message*> out;
       fail(out);
@@ -414,7 +420,9 @@ void Rank::Pipe::writer()
         
         if (write_message(m) < 0) {
           // failed!
-          derr(1) << "pipe(" << peer_inst << ' ' << this << ").writer error sending " << *m << " to " << m->get_dest() << endl;
+          derr(1) << "pipe(" << peer_inst << ' ' << this << ").writer error sending " << *m << " to " << m->get_dest()
+                 << ", " << errno << ": " << strerror(errno)
+                 << endl;
           out.push_front(m);
           fail(out);
           done = true;
index f38388d456a8cadbc26c48557a2a7cf38f3755a2..65043cda8e2ace2607f663c0f5044f4b94f18d89 100644 (file)
@@ -18,7 +18,7 @@ inline ostream& operator<<(ostream& out, const tcpaddr_t &a)
       << (unsigned)addr[1] << "."
       << (unsigned)addr[2] << "."
       << (unsigned)addr[3] << ":"
-      << (int)a.sin_port;
+      << ntohs(a.sin_port);
   return out;
 }