Skip to content
Browse files

CA-67468: Update VM import task progress regularly.

The GC times out all tasks which are older than 24 hours if they don't
update their progress between each GC sweep, which happens every 30
seconds.

Previously the task would round its progress to a multiple of 1/50,
however this could easily mean that its progress would not be updated
often enough. This change means that a VM import task will update its
progress every ten seconds.

Signed-off-by: John Else <john.else@citrix.com>
  • Loading branch information...
1 parent 899df48 commit a4e50afd6056b178b37a01e98fb71bd9d8647f55 @johnelse committed Jan 26, 2012
Showing with 7 additions and 5 deletions.
  1. +7 −5 ocaml/xapi/stream_vdi.ml
View
12 ocaml/xapi/stream_vdi.ml
@@ -61,26 +61,28 @@ let for_each_vdi __context f prefix_vdis =
type progress =
{ total_size: int64;
mutable transmitted_so_far: int64;
+ mutable time_of_last_update: float;
__context: Context.t
}
(** Create a fresh progress record from a set of VDIs *)
let new_progress_record __context (prefix_vdis: vdi list) =
{ total_size = List.fold_left (fun tot (_,_,s) -> Int64.add tot s) 0L prefix_vdis;
transmitted_so_far = 0L;
+ time_of_last_update = 0.0;
__context = __context }
(** Called every time <n> (uncompressed) bytes have been read or written. Updates
- the task record in the database *)
+ the task record in the database if no update has been sent for 10 seconds. *)
let made_progress __context progress n =
let total_size_MiB = Int64.div progress.total_size 1048576L in
- let old_so_far_MiB = Int64.div progress.transmitted_so_far 1048576L in
progress.transmitted_so_far <- Int64.add progress.transmitted_so_far n;
let so_far_MiB = Int64.div progress.transmitted_so_far 1048576L in
- let old_fraction_complete = Int64.to_float old_so_far_MiB /. (Int64.to_float total_size_MiB) in
let fraction_complete = Int64.to_float so_far_MiB /. (Int64.to_float total_size_MiB) in
- let round x = int_of_float (x *. 50.0) in
- if round old_fraction_complete <> round fraction_complete then begin
+ let now = Unix.time () in
+ let time_since_last_update = now -. progress.time_of_last_update in
+ if time_since_last_update > 10.0 then begin
+ progress.time_of_last_update <- now;
TaskHelper.set_progress progress.__context fraction_complete;
TaskHelper.exn_if_cancelling ~__context;
end

0 comments on commit a4e50af

Please sign in to comment.
Something went wrong with that request. Please try again.