]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
paxosservice: consolidate _active and _commit
authorSage Weil <sage@newdream.net>
Fri, 18 Nov 2011 18:35:44 +0000 (10:35 -0800)
committerSage Weil <sage.weil@dreamhost.com>
Sat, 19 Nov 2011 22:30:31 +0000 (14:30 -0800)
Use the same callback for when paxos goes active and for when it commits
something.  The response in both cases is the same.

Signed-off-by: Sage Weil <sage@newdream.net>
src/mon/PaxosService.cc
src/mon/PaxosService.h

index d7133df43fafb06f5158c33112ecd5dab1f7c015..bcba8e98afb874ecbbd6b42f80da00162f1b45df 100644 (file)
@@ -104,21 +104,6 @@ bool PaxosService::should_propose(double& delay)
   return true;
 }
 
-void PaxosService::_commit()
-{
-  dout(7) << "_commit" << dendl;
-  update_from_paxos();   // notify service of new paxos state
-
-  if (mon->is_leader() && paxos->is_active()) {
-    dout(7) << "_commit creating new pending" << dendl;
-    if (!have_pending) {
-      create_pending();
-      have_pending = true;
-    }
-  }
-}
-
-
 void PaxosService::propose_pending()
 {
   dout(10) << "propose_pending" << dendl;
@@ -136,7 +121,7 @@ void PaxosService::propose_pending()
   have_pending = false;
 
   // apply to paxos
-  paxos->wait_for_commit_front(new C_Commit(this));
+  paxos->wait_for_commit_front(new C_Active(this));
   paxos->propose_new_value(bl);
 }
 
@@ -193,6 +178,8 @@ void PaxosService::_active()
     }
   }
 
+  // NOTE: it's possible that this will get called twice if we commit
+  // an old paxos value.  Implementations should be mindful of that.
   if (paxos->is_active())
     on_active();
 }
index de2b9d39e9351a31970c050e92bf53043ae337cc..c8dc93bd7cf72d2690096be96854718d88042fb3 100644 (file)
@@ -45,16 +45,6 @@ protected:
        svc->_active();
     }
   };
-  class C_Commit : public Context {
-    PaxosService *svc;
-  public:
-    C_Commit(PaxosService *s) : svc(s) {}
-    void finish(int r) {
-      if (r >= 0)
-       svc->_commit();
-    }
-  };
-  friend class C_Update;
 
   class C_Propose : public Context {
     PaxosService *ps;
@@ -87,7 +77,6 @@ public:
 
 private:
   void _active();
-  void _commit();
 
 public:
   // i implement and you use
@@ -156,6 +145,8 @@ public:
    * This is called when the Paxos state goes to active.
    * It's a courtesy method if you have things you want/need
    * to do at that time.
+   *
+   * Note that is may get called twice in certain recovery cases.
    */
   virtual void on_active() { }