From 461f602b37037ec04a4b6f7a9662c1941ffd841d Mon Sep 17 00:00:00 2001 From: Pau Ruiz Safont Date: Wed, 18 Sep 2024 12:06:42 +0100 Subject: [PATCH] CA-398128: Be wary that dates in database lose precision Dates converted from unix timestamps have subsecond precision, but dates serialized in the database do not. This is a change in behaviour introduced in 233b96ba44b002a27205b0681f35527457b78c2c This fix was supposed to be included in the change, but got lost. No other users were found that hit this change in behaviour. Signed-off-by: Pau Ruiz Safont --- ocaml/xapi/xapi_xenops.ml | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/ocaml/xapi/xapi_xenops.ml b/ocaml/xapi/xapi_xenops.ml index f50e692a555..0cfe9493d1a 100644 --- a/ocaml/xapi/xapi_xenops.ml +++ b/ocaml/xapi/xapi_xenops.ml @@ -2282,13 +2282,15 @@ let update_vm ~__context id = Option.iter (fun (_, state) -> let metrics = Db.VM.get_metrics ~__context ~self in + (* Clamp time to full seconds, stored timestamps do not + have decimals *) let start_time = - Date.of_unix_time state.Vm.last_start_time + Float.floor state.Vm.last_start_time |> Date.of_unix_time in - if - start_time - <> Db.VM_metrics.get_start_time ~__context ~self:metrics - then ( + let expected_time = + Db.VM_metrics.get_start_time ~__context ~self:metrics + in + if Date.is_later ~than:expected_time start_time then ( debug "xenopsd event: Updating VM %s last_start_time <- %s" id Date.(to_rfc3339 (of_unix_time state.Vm.last_start_time)) ;