[dbwriter] exponential backoff wait for server start

Summary: When using the database write server process, the parent has to wait for it to fully start up before continuing. Instead of dying after a fixed amount of time, never terminate (external timeouts can take care of that) and use exponential backoff to avoid spamming.

Reviewed By: jvillard

Differential Revision: D23989959

fbshipit-source-id: ff5232c14
master
Nikos Gorogiannis 4 years ago committed by Facebook GitHub Bot
parent 96755539c2
commit b516290b77

@ -363,12 +363,16 @@ module Server = struct
In_channel.close in_channel
let rec retry ~pred ~timeout count =
if count < 0 then false
else if pred () then true
else (
Unix.nanosleep timeout |> ignore ;
retry ~pred ~timeout (count - 1) )
(* wait for socket to appear with 0.1 sec timeout, doubling each time ;
choice of numbers is arbitrary *)
let initial_wait_for_socket_secs = 0.1
let rec wait_for_server_start ~wait_secs =
Unix.nanosleep wait_secs |> ignore ;
if not (socket_exists ()) then (
let wait_secs = 2.0 *. wait_secs in
L.progress "Waiting for Sqlite write daemon to start (%f seconds)@\n" wait_secs ;
wait_for_server_start ~wait_secs )
let start () =
@ -377,10 +381,7 @@ module Server = struct
ForkUtils.protect ~f:server () ;
L.exit 0
| `In_the_parent _child_pid ->
(* wait for socket to appear, try 5 times, with a 0.1 sec timeout each time ;
choice of numbers is completely arbitrary *)
if not (retry ~pred:socket_exists ~timeout:0.1 5) then
L.die InternalError "Sqlite write daemon never started@." ;
wait_for_server_start ~wait_secs:initial_wait_for_socket_secs ;
send Command.Handshake
end

Loading…
Cancel
Save