]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
minor mon command handler cleanup
authorsageweil <sageweil@29311d96-e01e-0410-9327-a35deaab8ce9>
Wed, 19 Dec 2007 04:53:48 +0000 (04:53 +0000)
committersageweil <sageweil@29311d96-e01e-0410-9327-a35deaab8ce9>
Wed, 19 Dec 2007 04:53:48 +0000 (04:53 +0000)
git-svn-id: https://ceph.svn.sf.net/svnroot/ceph@2230 29311d96-e01e-0410-9327-a35deaab8ce9

trunk/ceph/mon/MDSMonitor.cc
trunk/ceph/mon/MDSMonitor.h
trunk/ceph/mon/Monitor.cc
trunk/ceph/mon/Monitor.h
trunk/ceph/mon/OSDMonitor.cc
trunk/ceph/mon/OSDMonitor.h
trunk/ceph/mon/Paxos.h
trunk/ceph/mon/PaxosService.h

index 4905a058a2a85518a4c143a0466824ea6b849464..db71d66cb991f872fb945597bf2a60adb1fe21e8 100644 (file)
@@ -22,9 +22,6 @@
 #include "messages/MMDSGetMap.h"
 #include "messages/MMDSBeacon.h"
 
-#include "messages/MMonCommand.h"
-#include "messages/MMonCommandAck.h"
-
 #include "messages/MGenericMessage.h"
 
 
@@ -158,9 +155,6 @@ bool MDSMonitor::preprocess_query(Message *m)
     handle_mds_getmap((MMDSGetMap*)m);
     return true;
 
-  case MSG_MON_COMMAND:
-    return false;
-
   default:
     assert(0);
     delete m;
@@ -258,9 +252,6 @@ bool MDSMonitor::prepare_update(Message *m)
   case MSG_MDS_BEACON:
     return handle_beacon((MMDSBeacon*)m);
     
-  case MSG_MON_COMMAND:
-    return handle_command((MMonCommand*)m);
-
   default:
     assert(0);
     delete m;
@@ -475,14 +466,15 @@ void MDSMonitor::take_over(entity_addr_t addr, int mds)
 
 
 
-bool MDSMonitor::handle_command(MMonCommand *m)
+int MDSMonitor::do_command(vector<string>& cmd, bufferlist& data, 
+                          bufferlist& rdata, string &rs)
 {
   int r = -EINVAL;
   stringstream ss;
 
-  if (m->cmd.size() > 1) {
-    if (m->cmd[1] == "stop" && m->cmd.size() > 2) {
-      int who = atoi(m->cmd[2].c_str());
+  if (cmd.size() > 1) {
+    if (cmd[1] == "stop" && cmd.size() > 2) {
+      int who = atoi(cmd[2].c_str());
       if (mdsmap.is_active(who)) {
        r = 0;
        ss << "telling mds" << who << " to stop";
@@ -492,8 +484,8 @@ bool MDSMonitor::handle_command(MMonCommand *m)
        ss << "mds" << who << " not active (" << mdsmap.get_state_name(mdsmap.get_state(who)) << ")";
       }
     }
-    else if (m->cmd[1] == "set_max_mds" && m->cmd.size() > 2) {
-      pending_mdsmap.max_mds = atoi(m->cmd[2].c_str());
+    else if (cmd[1] == "set_max_mds" && cmd.size() > 2) {
+      pending_mdsmap.max_mds = atoi(cmd[2].c_str());
       r = 0;
       ss << "max_mds = " << pending_mdsmap.max_mds;
     }
@@ -501,13 +493,10 @@ bool MDSMonitor::handle_command(MMonCommand *m)
   if (r == -EINVAL) {
     ss << "unrecognized command";
   } 
-
+  
   // reply
-  string rs;
-  getline(ss,rs);
-  mon->messenger->send_message(new MMonCommandAck(r, rs), m->get_source_inst());
-  delete m;
-  return r >= 0;
+  getline(ss, rs);
+  return r;
 }
 
 
index 76420621d07a29feaa3b7b70f8d2a66036274fec..16b7eba71c8bd0b952d064e9f1250c4d4919dc98 100644 (file)
@@ -72,11 +72,13 @@ class MDSMonitor : public PaxosService {
 
   bool preprocess_beacon(class MMDSBeacon *m);
   bool handle_beacon(class MMDSBeacon *m);
-  bool handle_command(class MMonCommand *m);
   void handle_mds_getmap(MMDSGetMap *m);
 
   void take_over(entity_addr_t addr, int mds);
 
+  int do_command(vector<string>& cmd, bufferlist& data, 
+                bufferlist& rdata, string &rs);
+
   // beacons
   map<entity_addr_t, utime_t> last_beacon;
 
index 0c3dc0452c34d2442559e75c9d972cd2ed64cdfc..cac9dd74922bb1011da53fbd2ed7dc7106320414 100644 (file)
@@ -69,7 +69,6 @@ void Monitor::init()
   pgmon = new PGMonitor(this, &paxos_pgmap);
   
   // init paxos
-  paxos_test.init();
   paxos_osdmap.init();
   paxos_mdsmap.init();
   paxos_clientmap.init();
@@ -148,7 +147,6 @@ void Monitor::call_election()
   state = STATE_STARTING;
   
   // tell paxos
-  paxos_test.election_starting();
   paxos_mdsmap.election_starting();
   paxos_osdmap.election_starting();
   paxos_clientmap.election_starting();
@@ -166,7 +164,6 @@ void Monitor::win_election(epoch_t epoch, set<int>& active)
   dout(10) << "win_election, epoch " << mon_epoch << " quorum is " << quorum << dendl;
   
   // init paxos
-  paxos_test.leader_init();
   paxos_mdsmap.leader_init();
   paxos_osdmap.leader_init();
   paxos_clientmap.leader_init();
@@ -187,7 +184,6 @@ void Monitor::lose_election(epoch_t epoch, int l)
   dout(10) << "lose_election, epoch " << mon_epoch << " leader is mon" << leader << dendl;
   
   // init paxos
-  paxos_test.peon_init();
   paxos_mdsmap.peon_init();
   paxos_osdmap.peon_init();
   paxos_clientmap.peon_init();
@@ -201,37 +197,48 @@ void Monitor::lose_election(epoch_t epoch, int l)
 }
 
 
+int Monitor::do_command(vector<string>& cmd, bufferlist& data, 
+                       bufferlist& rdata, string &rs)
+{
+  if (cmd.empty()) {
+    rs = "no command";
+    return -EINVAL;
+  }
+
+  if (cmd[0] == "stop") {
+    rs = "stopping";
+    do_stop();
+    return 0;
+  }
+  if (cmd[0] == "mds") 
+    return mdsmon->do_command(cmd, data, rdata, rs);
+
+  if (cmd[0] == "osd") 
+    return osdmon->do_command(cmd, data, rdata, rs);
+
+  // huh.
+  rs = "unrecognized subsystem '" + cmd[0] + "'";
+  return -EINVAL;
+}
+
 void Monitor::handle_command(MMonCommand *m)
 {
   dout(0) << "handle_command " << *m << dendl;
   
-  int r = -1;
-  string rs = "unrecognized command";
-  
-  if (!m->cmd.empty()) {
-    if (m->cmd[0] == "stop") {
-      r = 0;
-      rs = "stopping";
-      do_stop();
-    }
-    else if (m->cmd[0] == "mds") {
-      mdsmon->dispatch(m);
-      return;
-    }
-    else if (m->cmd[0] == "osd") {
-      
-    }
-  }
-  
-  // reply
-  messenger->send_message(new MMonCommandAck(r, rs), m->get_source_inst());
+  string rs;         // return string
+  bufferlist rdata;  // return data
+  int rc = do_command(m->cmd, m->get_data(), rdata, rs);
+
+  MMonCommandAck *reply = new MMonCommandAck(rc, rs);
+  reply->set_data(rdata);
+  messenger->send_message(reply, m->get_source_inst());
   delete m;
 }
 
 
 void Monitor::do_stop()
 {
-  dout(0) << "do_stop -- shutting down" << dendl;
+  dout(0) << "do_stop -- initiating shutdown" << dendl;
   stopping = true;
   mdsmon->do_stop();
 }
@@ -304,9 +311,6 @@ void Monitor::dispatch(Message *m)
 
        // send it to the right paxos instance
        switch (pm->machine_id) {
-       case PAXOS_TEST:
-         paxos_test.dispatch(m);
-         break;
        case PAXOS_OSDMAP:
          paxos_osdmap.dispatch(m);
          break;
index bd278a209230877243b331290d4857da07ee0d40..dc06c937a1e6a14ef396d051edede5b7586fbdcd 100644 (file)
@@ -88,7 +88,6 @@ public:
 
 
   // -- paxos --
-  Paxos paxos_test;
   Paxos paxos_mdsmap;
   Paxos paxos_osdmap;
   Paxos paxos_clientmap;
@@ -113,7 +112,8 @@ public:
   void handle_ping_ack(class MPingAck *m);
   void handle_command(class MMonCommand *m);
 
-
+  int do_command(vector<string>& cmd, bufferlist& data, 
+                bufferlist& rdata, string &rs);
 
  public:
   Monitor(int w, Messenger *m, MonMap *mm) : 
@@ -129,7 +129,6 @@ public:
     mon_epoch(0), 
     leader(0),
     
-    paxos_test(this, w, PAXOS_TEST),
     paxos_mdsmap(this, w, PAXOS_MDSMAP),
     paxos_osdmap(this, w, PAXOS_OSDMAP),
     paxos_clientmap(this, w, PAXOS_CLIENTMAP),
index db3bc57841597443e4be7b6c0d89ffaf7a2c6015..693bb1a1dcae6e136476558fd2169ade72a1c686 100644 (file)
@@ -851,3 +851,9 @@ void OSDMonitor::mark_all_down()
 }
 
 
+int OSDMonitor::do_command(vector<string>& cmd, bufferlist& data, 
+                          bufferlist& rdata, string &rs)
+{
+  rs = "unknown command";
+  return -EINVAL;
+}
index c22c007f2d9b61bbd15eed1dd7fa39db7576df4c..bbaf3762b44f05bd33e7aa407f1b97540da2b2e8 100644 (file)
@@ -119,6 +119,9 @@ private:
 
   void tick();  // check state, take actions
 
+  int do_command(vector<string>& cmd, bufferlist& data, 
+                bufferlist& rdata, string &rs);
+
   void mark_all_down();
 
   void send_latest(entity_inst_t i, epoch_t start=0);
index a6d28dd1cea9aa8bf2c4eb94515448d58425dc44..57c0e001495e887a8972e8bd6c6331da34717abb 100644 (file)
@@ -44,6 +44,7 @@ e 12v
  *     "read" their copy of the last committed value.
  *
  * This provides a simple replication substrate that services can be built on top of.
+ * See PaxosService.h
  */
 
 #ifndef __MON_PAXOS_H
index a0f39c7862273a55ab3ee667cf37032f87504f29..234f0bf3c4c4f7846694e6a0999cd423f98674d4 100644 (file)
@@ -89,7 +89,7 @@ public:
   void propose_pending();     // propose current pending as new paxos state
 
   // you implement
-  virtual bool update_from_paxos() = 0;    // assimilate latest paxos state
+  virtual bool update_from_paxos() = 0;    // assimilate latest state from paxos
   virtual void create_pending() = 0;       // [leader] create new pending structures
   virtual void create_initial() = 0;       // [leader] populate pending with initial state (1)
   virtual void encode_pending(bufferlist& bl) = 0; // [leader] finish and encode pending for next paxos state
@@ -99,7 +99,7 @@ public:
   virtual bool prepare_update(Message *m) = 0;
   virtual bool should_propose(double &delay);
 
-  virtual void committed() = 0;
+  virtual void committed() = 0;            // [leader] called after a proposed value commits
 
 };