Skip to content

Check that there are no changes during SR.scan #6413

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 23 additions & 14 deletions ocaml/xapi/xapi_sr.ml
Original file line number Diff line number Diff line change
Expand Up @@ -757,6 +757,11 @@ let update_vdis ~__context ~sr db_vdis vdi_infos =

(* Perform a scan of this locally-attached SR *)
let scan ~__context ~sr =
let module RefSet = Set.Make (struct
type t = [`VDI] Ref.t

let compare = Ref.compare
end) in
let open Storage_access in
let task = Context.get_task_id __context in
let module C = Storage_interface.StorageAPI (Idl.Exn.GenClient (struct
Expand All @@ -781,9 +786,21 @@ let scan ~__context ~sr =
(* It is sufficient to just compare the refs in two db_vdis, as this
is what update_vdis uses to determine what to delete *)
let vdis_ref_equal db_vdi1 db_vdi2 =
Listext.List.set_difference (List.map fst db_vdi1)
(List.map fst db_vdi2)
= []
let refs1 = RefSet.of_list (List.map fst db_vdi1) in
let refs2 = RefSet.of_list (List.map fst db_vdi2) in
if RefSet.equal refs1 refs2 then
true
else
let log_diff label a b =
RefSet.diff a b
|> RefSet.elements
|> List.map Ref.string_of
|> String.concat " "
|> debug "%s: VDIs %s during scan: %s" __FUNCTION__ label
in
log_diff "removed" refs1 refs2 ;
log_diff "added" refs2 refs1 ;
false
in
let db_vdis_before = find_vdis () in
let vs, sr_info =
Expand All @@ -793,21 +810,13 @@ let scan ~__context ~sr =
let db_vdis_after = find_vdis () in
if limit > 0 && not (vdis_ref_equal db_vdis_before db_vdis_after)
then (
debug
"%s detected db change while scanning, before scan vdis %s, \
after scan vdis %s, retry limit left %d"
__FUNCTION__
(List.map (fun (_, v) -> v.vDI_uuid) db_vdis_before
|> String.concat ","
)
(List.map (fun (_, v) -> v.vDI_uuid) db_vdis_after
|> String.concat ","
)
limit ;
debug "%s detected db change while scanning, retry limit left %d"
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As we report the VDIs that have been added or removed in vdis_ref_equal I think it is ok to remove the dump of the two lists (before and after).

__FUNCTION__ limit ;
(scan_rec [@tailcall]) (limit - 1)
) else if limit = 0 then
Helpers.internal_error "SR.scan retry limit exceeded"
else (
debug "%s no change detected, updating VDIs" __FUNCTION__ ;
update_vdis ~__context ~sr db_vdis_after vs ;
let virtual_allocation =
List.fold_left
Expand Down
Loading