Skip to content

Commit

Permalink
CA-398128: Be wary that dates in database lose precision (#6004)
Browse files Browse the repository at this point in the history
Dates converted from unix timestamps have subsecond precision, but dates
serialized in the database do not. This is a change in behaviour
introduced in 233b96b

This fix was supposed to be included in the change, but got lost. No
other users were found that hit this change in behaviour.

Fixes the test about VMs pending guidances being removed when not
needed, job 411209
  • Loading branch information
robhoes authored Sep 18, 2024
2 parents 21620be + 461f602 commit 9ff72f1
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions ocaml/xapi/xapi_xenops.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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)) ;
Expand Down

0 comments on commit 9ff72f1

Please sign in to comment.