Commits

Romain Slootmaekers  committed 2101fd9 Draft

bugfix:lease expiration on slave should be full period, not half

  • Participants
  • Parent commits 9e0a5b7
  • Branches 1.5

Comments (0)

Files changed (5)

File extension/test/server/right/system_tests_preferred.py

     client = Common.get_client()
     master = client.whoMaster()
     NT.assert_equals(pm, master)
+
+    logging.info("master indeed is `%s`", pm)
+    client.dropConnections()
+    del client
     cluster.stopOne(pm)
-    time.sleep(8.0 * Common.lease_duration)
+    delay = 8.0 * Common.lease_duration
+
+    logging.info("stopped master, waiting for things to settle (%fs)", delay)
+    time.sleep(delay)
     client = Common.get_client()
     master2 = client.whoMaster()
     logging.info("master2 = %s",master2)
     NT.assert_equals(True, master2 != pm)
+    logging.info("node %s took over, now restarting preferred master", master2)
     cluster.startOne(pm)
+    logging.info("waiting for things to settle")
     time.sleep(4.0* Common.lease_duration)
     client = Common.get_client()
     master3 = client.whoMaster()

File src/paxos/master.ml

 let master_dictate constants (mo,v,n,i) () =
   let accept_e = EAccept (v,n,i) in
   
-  let start_e = EStartLeaseExpiration (v,n) in
+  let start_e = EStartLeaseExpiration (v,n,false) in
   let mcast_e = EMCast (Accept(n,i,v)) in
   let me = constants.me in
   let others = constants.others in

File src/paxos/multi_paxos_fsm.ml

     | EMCast msg          -> mcast constants msg
     | EAccept (v,n,i)     -> constants.on_accept (v,n,i) 
     | ESend (msg, target) -> constants.send msg constants.me target
-    | EStartLeaseExpiration (v,n) ->
+    | EStartLeaseExpiration (v,n, slave) ->
         begin
           if Value.is_master_set v
-          then start_lease_expiration_thread constants n (constants.lease_expiration / 2) 
+          then 
+            let period = 
+              if slave 
+              then constants.lease_expiration 
+              else constants.lease_expiration / 2 
+            in
+            start_lease_expiration_thread constants n period
           else Lwt.return ()
         end 
     | EStartElectionTimeout n -> start_election_timeout constants n

File src/paxos/multi_paxos_type.ml

   | EMCast  of Mp_msg.MPMessage.t
   | ESend of Mp_msg.MPMessage.t * Messaging.id
   | EAccept of (Value.t * n * i)  
-  | EStartLeaseExpiration of (Value.t * n )
+  | EStartLeaseExpiration of (Value.t * n * bool (* is slave *))
   | EStartElectionTimeout of n
   | EConsensus of (master_option * Value.t * n * i)
   | EGen of (unit -> unit Lwt.t)

File src/paxos/slave.ml

 let time_for_elections constants n' maybe_previous =
   begin
     if constants.store # quiesced () 
-    then false
+    then false, "quiesced"
     else
       begin
 	    let origine,(am,al) = 
 		  ns' origine am (Sn.string_of al) (Sn.string_of now) >>= fun () -> 
         *)
 	    let diff = abs (Int64.to_int (Int64.sub now al)) in
-	    diff >= constants.lease_expiration
+	    diff >= constants.lease_expiration, Printf.sprintf "diff=%i" diff
       end
   end
 
    to receive accepts *)
 let slave_steady_state constants state event =
   let (n,i,previous) = state in
-  let me = constants.me in
   let store = constants.store in
   match event with
     | FromNode (msg,source) ->
                   end 
                   >>= fun _ ->
                   let accept_e = EAccept (v,n,i) in
-                  let start_e = EStartLeaseExpiration(v,n) in
+                  let start_e = EStartLeaseExpiration(v,n, true) in
                   let send_e = ESend(reply, source) in
                   let log_e = ELog (fun () -> 
                     Printf.sprintf "steady_state :: replying with %S" (string_of reply)
         Fsm.return ~sides:[log_e] (Slave_steady_state state)
       end
     | LeaseExpired n' -> 
-      let ns  = (Sn.string_of n) 
-      and ns' = (Sn.string_of n') in
-      if (not (is_election constants || constants.is_learner)) || n' < n
-      then 
-	    begin
-          let log_e = ELog (fun () ->
-	        Printf.sprintf "steady state: ignoring old lease expiration (n'=%s,n=%s)" ns' ns )
-          in
-	      Fsm.return ~sides:[log_e] (Slave_steady_state (n,i,previous))
-	    end
-      else
-	    begin 
-	      let elections_needed = time_for_elections constants n' (Some (previous,Sn.pred i)) in
-	      if elections_needed then
-	        begin
-	          let new_n = update_n constants n in
-              let el_i = Store.get_succ_store_i constants.store in
-              let el_up =
-		        begin
-		          if el_i = (Sn.pred i) 
-		          then Some previous
-		          else None
-		        end
-              in
-              let log_e = ELog (fun () -> "ELECTIONS NEEDED") in
-	          Fsm.return ~sides:[log_e] (Election_suggest (new_n, el_i, el_up ))
-	        end
-	      else
-	        begin
-	          Fsm.return (Slave_steady_state(n,i,previous))
-	        end
-	    end
+        let ns  = (Sn.string_of n) 
+        and ns' = (Sn.string_of n') in
+        if (not (is_election constants || constants.is_learner)) || n' < n
+        then 
+	      begin
+            let log_e = ELog (fun () ->
+	          Printf.sprintf "steady state: ignoring old lease expiration (n'=%s,n=%s)" ns' ns )
+            in
+	        Fsm.return ~sides:[log_e] (Slave_steady_state (n,i,previous))
+	      end
+        else
+	      begin 
+	        let elections_needed, msg = time_for_elections constants n' (Some (previous,Sn.pred i)) in
+	        if elections_needed then
+	          begin
+	            let new_n = update_n constants n in
+                let el_i = Store.get_succ_store_i constants.store in
+                let el_up =
+		          begin
+		            if el_i = (Sn.pred i) 
+		            then Some previous
+		            else None
+		          end
+                in
+                let log_e = ELog (fun () -> "ELECTIONS NEEDED") in
+	            Fsm.return ~sides:[log_e] (Election_suggest (new_n, el_i, el_up ))
+	          end
+	        else
+	          begin
+                let log_e = ELog(fun () -> 
+                  Printf.sprintf 
+                    "slave_steady_state ignoring lease expiration (n'=%s,n=%s) %s" ns' ns msg) 
+                in
+	            Fsm.return ~sides:[log_e] (Slave_steady_state(n,i,previous))
+	          end
+	      end
     | FromClient ufs -> 
         begin
           
 (* a pending slave that has promised a value to a pending master waits
    for an Accept from the master about this *)
 let slave_wait_for_accept constants (n,i, vo, maybe_previous) event =
-  let me = constants.me in
   match event with 
     | FromNode(msg,source) ->
       begin
         Fsm.return ~sides:[log_e] (Slave_wait_for_accept (n,i,vo, maybe_previous))
         end
       else
-        let elections_needed = time_for_elections constants n' maybe_previous in
+        let elections_needed,_ = time_for_elections constants n' maybe_previous in
         if elections_needed then
           begin
             let log_e = ELog (fun () -> "slave_wait_for_accept: Elections needed") in