Each of the attached compiles, which means more than it does in some other languages. I'm fairly confident I haven't messed up. But there's two approaches.
Previously, membership was only automatically reloaded in the db server, not the recon server. Patch sks-mshp-timed.patch makes membership reload independent of whether or not the server's eventloop does anything special, so this sort of oversight can't happen. It's more intrusive, because it changes how membership is stored. Patch sks-mshp-timed2.patch is much simpler and just adds an event handler to reconserver.ml, similar to that in dbserver.ml. There are pros and cons to each. Separately, I believe that the mailsync file was getting reloaded rather often, if the mtime differed from that of the membership file, because the wrong file's mtime was checked. Both patches fix that. Regards, -Phil
diff --git a/membership.ml b/membership.ml --- a/membership.ml +++ b/membership.ml @@ -31,7 +31,7 @@ exception Lookup_failure of string exception Malformed_entry of string exception Empty_line -let membership = ref ([| |],-1.) +let membership = ref ([| |],-1.,-1.) let whitespace = Str.regexp "[ \t]+" @@ -161,6 +161,7 @@ let get_mtime fname = Unix.Unix_error _ -> None let load_membership fname = + let time_now = Unix.time () in let file = open_in fname in protect ~f:(fun () -> let mshp = load_membership_file file in @@ -169,12 +170,12 @@ let load_membership fname = plerror 2 "%s" ("Unable to get mtime for membership. " ^ "Failed to reload.") - | Some mtime -> membership := (mshp,mtime) + | Some mtime -> membership := (mshp,mtime,time_now) ) ~finally:(fun () -> close_in file) let membership_string () = - let (mshp,_) = !membership in + let (mshp,_,_) = !membership in let to_string (addr_list,str) = String.concat " " ( "(" :: ( @@ -185,9 +186,19 @@ let membership_string () = "Membership: " ^ String.concat ~sep:", " strings +let reload_if_old () = + let (mshp,_,last_loaded) = !membership in + let age = Unix.time () -. last_loaded in + if age > !Settings.membership_reload_time then + ( let fname = Lazy.force Settings.membership_file in + load_membership fname; + plerror 5 "%s" (membership_string ()) + ) + let reload_if_changed () = + reload_if_old (); let fname = Lazy.force Settings.membership_file in - let (mshp,old_mtime) = !membership in + let (mshp,old_mtime,_) = !membership in match get_mtime fname with | None -> plerror 2 "%s" ("Unable to get mtime for membership file. " ^ @@ -202,7 +213,7 @@ let get_names () = let mshp = if Sys.file_exists (Lazy.force Settings.membership_file) then ( reload_if_changed (); - let (m,mtime) = !membership in + let (m,mtime,ltime) = !membership in m ) else [| |] @@ -211,14 +222,14 @@ let get_names () = let reset_membership_time () = - let (m,mtime) = !membership in - membership := (m,0.) + let (m,mtime,ltime) = !membership in + membership := (m,0.,0.) let get () = let mshp = if Sys.file_exists (Lazy.force Settings.membership_file) then ( reload_if_changed (); - let (m,mtime) = !membership in + let (m,mtime,ltime) = !membership in m ) else [| |] @@ -238,7 +249,7 @@ let ipmatch_ip_in_socklist ip1 sockaddr_ let test addr = reload_if_changed (); - let (m,mtime) = !membership in + let (m,mtime,ltime) = !membership in let ip = match inet_addr_of_sockaddr addr with | None -> assert false | Some x -> x @@ -282,7 +293,7 @@ let load_mailsync_partners fname = let reload_mailsync_if_changed () = let fname = Lazy.force Settings.mailsync_file in - let (mshp,old_mtime) = !membership in + let (_,old_mtime) = !mailsync_partners in match get_mtime fname with None -> plerror 2 "%s" ("Failed to find mtime, can't decide whether to" ^
diff --git a/membership.ml b/membership.ml --- a/membership.ml +++ b/membership.ml @@ -282,7 +282,7 @@ let load_mailsync_partners fname = let reload_mailsync_if_changed () = let fname = Lazy.force Settings.mailsync_file in - let (mshp,old_mtime) = !membership in + let (mshp,old_mtime) = !mailsync_partners in match get_mtime fname with None -> plerror 2 "%s" ("Failed to find mtime, can't decide whether to" ^ diff --git a/reconserver.ml b/reconserver.ml --- a/reconserver.ml +++ b/reconserver.ml @@ -354,6 +354,8 @@ struct Eventloop.evloop ( [ Eventloop.Event (0.0, Eventloop.Callback catchup) ] @ (Ehandlers.repeat_forever_simple catchup_interval catchup) + @ Ehandlers.repeat_forever_simple !Settings.membership_reload_time + Membership.reset_membership_time @ (if !Settings.gossip then Ehandlers.repeat_forever ~jitter:0.1 (* 10% randomness in delay interval *)
pgpk1ATH1RqOv.pgp
Description: PGP signature
_______________________________________________ Sks-devel mailing list Sks-devel@nongnu.org http://lists.nongnu.org/mailman/listinfo/sks-devel