Skip to content

Commit

Permalink
CA-394343: Change the type of Xapi_globs.host_assumed_dead_interval t…
Browse files Browse the repository at this point in the history
…o Mtime.Span.t

This commit changes the type of Xapi_globs.host_assumed_dead_interval
from float to Mtime.Span.t. This makes the usage of this global
variable easier.

Signed-off-by: Pau Ruiz Safont <[email protected]>
Signed-off-by: Ming Lu <[email protected]>
  • Loading branch information
minglumlu committed Jun 21, 2024
1 parent 2676044 commit a9b5612
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 7 deletions.
5 changes: 2 additions & 3 deletions ocaml/xapi/db_gc.ml
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,6 @@ let detect_clock_skew ~__context host skew =
let check_host_liveness ~__context =
(* CA-16351: when performing the initial GC pass on first boot there won't be a localhost *)
let localhost = try Helpers.get_localhost ~__context with _ -> Ref.null in
let n = int_of_float !Xapi_globs.host_assumed_dead_interval in
let assumed = Mtime.Span.(n * s) in
let check_host host =
if host <> localhost then
try
Expand All @@ -97,7 +95,8 @@ let check_host_liveness ~__context =
)
in
let elapsed = Mtime_clock.count last_seen in
if Mtime.Span.compare elapsed assumed < 0 then
if Mtime.Span.compare elapsed !Xapi_globs.host_assumed_dead_interval < 0
then
(* From the heartbeat PoV the host looks alive. We try to (i) minimise database sets; and (ii)
avoid toggling the host back to live if it has been marked as shutting_down. *)
with_lock Xapi_globs.hosts_which_are_shutting_down_m (fun () ->
Expand Down
24 changes: 20 additions & 4 deletions ocaml/xapi/xapi_globs.ml
Original file line number Diff line number Diff line change
Expand Up @@ -707,7 +707,7 @@ let snapshot_with_quiesce_timeout = ref 600.
let host_heartbeat_interval = ref 30.

(* If we haven't heard a heartbeat from a host for this interval then the host is assumed dead *)
let host_assumed_dead_interval = ref 600.0
let host_assumed_dead_interval = ref Mtime.Span.(10 * min)

(* If a session has a last_active older than this we delete it *)
let inactive_session_timeout = ref 86400. (* 24 hrs in seconds *)
Expand Down Expand Up @@ -951,7 +951,10 @@ let ignore_vtpm_unimplemented = ref false

let evacuation_batch_size = ref 10

type xapi_globs_spec_ty = Float of float ref | Int of int ref
type xapi_globs_spec_ty =
| Float of float ref
| Int of int ref
| TimeSpanOfFloat of Mtime.Span.t ref

let extauth_ad_backend = ref "winbind"

Expand Down Expand Up @@ -1061,7 +1064,7 @@ let xapi_globs_spec =
; ("wait_memory_target_timeout", Float wait_memory_target_timeout)
; ("snapshot_with_quiesce_timeout", Float snapshot_with_quiesce_timeout)
; ("host_heartbeat_interval", Float host_heartbeat_interval)
; ("host_assumed_dead_interval", Float host_assumed_dead_interval)
; ("host_assumed_dead_interval", TimeSpanOfFloat host_assumed_dead_interval)
; ("fuse_time", Float Constants.fuse_time)
; ("db_restore_fuse_time", Float Constants.db_restore_fuse_time)
; ("inactive_session_timeout", Float inactive_session_timeout)
Expand Down Expand Up @@ -1120,13 +1123,26 @@ let options_of_xapi_globs_spec =
List.map
(fun (name, ty) ->
( name
, (match ty with Float x -> Arg.Set_float x | Int x -> Arg.Set_int x)
, ( match ty with
| Float x ->
Arg.Set_float x
| Int x ->
Arg.Set_int x
| TimeSpanOfFloat x ->
Arg.Float
(fun y ->
let y' = Float.to_int (1000. *. y) in
x := Mtime.Span.(y' * ms)
)
)
, (fun () ->
match ty with
| Float x ->
string_of_float !x
| Int x ->
string_of_int !x
| TimeSpanOfFloat x ->
Fmt.to_to_string Mtime.Span.pp !x
)
, Printf.sprintf "Set the value of '%s'" name
)
Expand Down

0 comments on commit a9b5612

Please sign in to comment.