]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
osd: feed new pg mapping into state machine
authorSage Weil <sage@newdream.net>
Tue, 3 May 2011 22:31:28 +0000 (15:31 -0700)
committerSage Weil <sage@newdream.net>
Tue, 3 May 2011 22:31:28 +0000 (15:31 -0700)
instead of recalculating it.  Also pass the last map into warm_restart,
while we're at it.  Drop the Reset state constructor and instead repost
the AdvMap event before transitioning.

Signed-off-by: Sage Weil <sage@newdream.net>
src/osd/OSD.cc
src/osd/PG.cc
src/osd/PG.h

index 75cace88af105eac98d2988ac35c1dcb78fced08..a2f2b485ac003e8610feef0d282e1fc63866face 100644 (file)
@@ -3207,9 +3207,12 @@ void OSD::advance_map(ObjectStore::Transaction& t)
     pg_t pgid = it->first;
     PG *pg = it->second;
 
+    vector<int> newup, newacting;
+    osdmap->pg_to_up_acting_osds(pg->info.pgid, newup, newacting);
+
     pg->lock();
     dout(10) << "Scanning pg " << *pg << dendl;
-    pg->handle_advance_map(*osdmap, *lastmap, 0);
+    pg->handle_advance_map(*osdmap, *lastmap, newup, newacting, 0);
     pg->unlock();
   }
 }
index 2bb5db2a21fb571162dfefe52c3a15c066d467b2..942e41c18764e65cbd977bb59de6e6088d8b6c5e 100644 (file)
@@ -3327,14 +3327,9 @@ void PG::fulfill_log(int from, const Query &query)
   }
 }
 
-bool PG::acting_up_affected(OSDMap &osdmap,
-                const OSDMap &lastmap)
+bool PG::acting_up_affected(const vector<int>& newup, const vector<int>& newacting)
 {
-  // get new acting set
-  vector<int> tup, tacting;
-  osdmap.pg_to_up_acting_osds(info.pgid, tup, tacting);
-
-  if (acting != tacting || up != tup) {
+  if (acting != newacting || up != newup) {
     return true;
   } else {
     return false;
@@ -3342,23 +3337,22 @@ bool PG::acting_up_affected(OSDMap &osdmap,
 }
 
 /* Called before initializing peering during advance_map */
-void PG::warm_restart()
+void PG::warm_restart(const OSDMap& lastmap, const vector<int>& newup, const vector<int>& newacting)
 {
-  OSDMap &lastmap = *osd->get_map(osd->osdmap->get_epoch() - 1);
-  OSDMap &osdmap = *osd->osdmap;
+  const OSDMap &osdmap = *osd->osdmap;
+
   // -- there was a change! --
   kick();
 
+  vector<int> oldacting, oldup;
   int oldrole = get_role();
   int oldprimary = get_primary();
-
-  vector<int> oldacting, oldup; //About to get swapped with current (old)
-  osdmap.pg_to_up_acting_osds(info.pgid, oldup, oldacting);
-
-  // update PG
   acting.swap(oldacting);
   up.swap(oldup);
 
+  up = newup;
+  acting = newacting;
+
   int role = osdmap.calc_pg_role(osd->whoami, acting, acting.size());
   set_role(role);
 
@@ -3729,8 +3723,9 @@ boost::statechart::result
 PG::RecoveryState::Started::react(const AdvMap& advmap) {
   dout(10) << "Started advmap" << dendl;
   PG *pg = context< RecoveryMachine >().pg;
-  if (pg->acting_up_affected(advmap.osdmap, advmap.lastmap)) {
+  if (pg->acting_up_affected(advmap.newup, advmap.newacting)) {
     dout(10) << "up or acting affected, transitioning to Reset" << dendl;
+    post_event(advmap);
     return transit< Reset >();
   }
   return discard_event();
@@ -3741,9 +3736,9 @@ boost::statechart::result
 PG::RecoveryState::Reset::react(const AdvMap& advmap) {
   PG *pg = context< RecoveryMachine >().pg;
   dout(10) << "Reset advmap" << dendl;
-  if (pg->acting_up_affected(advmap.osdmap, advmap.lastmap)) {
+  if (pg->acting_up_affected(advmap.newup, advmap.newacting)) {
     dout(10) << "up or acting affected, calling warm_restart again" << dendl;
-    pg->warm_restart();
+    pg->warm_restart(advmap.lastmap, advmap.newup, advmap.newacting);
   }
   return discard_event();
 }
@@ -3757,13 +3752,6 @@ PG::RecoveryState::Reset::react(const ActMap&) {
   }
   return transit< Started >();
 }
-
-PG::RecoveryState::Reset::Reset(my_context ctx) : my_base(ctx) {
-  PG *pg = context< RecoveryMachine >().pg;
-  dout(10) << "Reseting" << dendl;
-  pg->warm_restart();
-  post_event(Initialize());
-}
        
 /*-------Start---------*/
 PG::RecoveryState::Start::Start(my_context ctx) : my_base(ctx) {
@@ -3823,6 +3811,7 @@ PG::RecoveryState::Peering::react(const AdvMap& advmap) {
   dout(10) << "Peering advmap" << dendl;
   if (pg->prior_set_affected(*prior_set.get(), &advmap.osdmap)) {
     dout(1) << "Peering, priors_set_affected, going to Reset" << dendl;
+    post_event(advmap);
     return transit< Reset >();
   }
   return forward_event();
@@ -4288,10 +4277,11 @@ void PG::RecoveryState::handle_query(int from, const PG::Query& q,
 }
 
 void PG::RecoveryState::handle_advance_map(OSDMap &osdmap, OSDMap &lastmap,
+                                          vector<int>& newup, vector<int>& newacting,
                                           RecoveryCtx *rctx)
 {
   start_handle(rctx);
-  machine.process_event(AdvMap(osdmap, lastmap));
+  machine.process_event(AdvMap(osdmap, lastmap, newup, newacting));
   end_handle();
 }
 
index ea03fe9473768376654ba7f8144c20c7a60a0d93..c8b8ca609a8989287e13a6db2fa69bf3533441d9 100644 (file)
@@ -839,8 +839,9 @@ public:
     struct AdvMap : boost::statechart::event< AdvMap > {
       OSDMap &osdmap;
       OSDMap &lastmap;
-      AdvMap(OSDMap &osdmap, OSDMap &lastmap):
-       osdmap(osdmap), lastmap(lastmap) {}
+      vector<int> newup, newacting;
+      AdvMap(OSDMap &osdmap, OSDMap &lastmap, vector<int>& newup, vector<int>& newacting):
+       osdmap(osdmap), lastmap(lastmap), newup(newup), newacting(newacting) {}
     };
 
     struct BacklogComplete : boost::statechart::event< BacklogComplete > {};
@@ -906,15 +907,11 @@ public:
     };
 
     struct Reset :
-      boost::statechart::state< Reset, RecoveryMachine > {
+      boost::statechart::simple_state< Reset, RecoveryMachine > {
       typedef boost::mpl::list <
        boost::statechart::custom_reaction< AdvMap >,
        boost::statechart::custom_reaction< ActMap >
        > reactions;
-
-      /* Entry function for RecoveryMachine.  Should initialize relevant peering
-       * state */
-      Reset(my_context ctx);
       boost::statechart::result react(const AdvMap&);
       boost::statechart::result react(const ActMap&);
     };
@@ -1089,7 +1086,9 @@ public:
                    MOSDPGLog *msg,
                    RecoveryCtx *ctx);
     void handle_query(int from, const PG::Query& q, RecoveryCtx *ctx);
-    void handle_advance_map(OSDMap &osdmap, OSDMap &lastmap, RecoveryCtx *ctx);
+    void handle_advance_map(OSDMap &osdmap, OSDMap &lastmap, 
+                           vector<int>& newup, vector<int>& newacting, 
+                           RecoveryCtx *ctx);
     void handle_activate_map(RecoveryCtx *ctx);
     void handle_backlog_generated(RecoveryCtx *ctx);
     void handle_create(RecoveryCtx *ctx);
@@ -1388,13 +1387,12 @@ public:
   void share_pg_info();
   void share_pg_log(const eversion_t &oldver);
 
-  void warm_restart();
+  void warm_restart(const OSDMap& lastmap, const vector<int>& newup, const vector<int>& newacting);
                    
   void fulfill_info(int from, const Query &query, 
                    pair<int, Info> &notify_info);
   void fulfill_log(int from, const Query &query);
-  bool acting_up_affected(OSDMap &osdmap,
-              const OSDMap &lastmap);
+  bool acting_up_affected(const vector<int>& newup, const vector<int>& newacting);
     
   // recovery bits
   void handle_notify(int from, PG::Info& i, RecoveryCtx *rctx) {
@@ -1412,8 +1410,9 @@ public:
     recovery_state.handle_query(from, q, rctx);
   }
   void handle_advance_map(OSDMap &osdmap, OSDMap &lastmap, 
+                         vector<int>& newup, vector<int>& newacting,
                          RecoveryCtx *rctx) {
-    recovery_state.handle_advance_map(osdmap, lastmap, rctx);
+    recovery_state.handle_advance_map(osdmap, lastmap, newup, newacting, rctx);
   }
   void handle_activate_map(RecoveryCtx *rctx) {
     recovery_state.handle_activate_map(rctx);