Skip to content
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

Improve the scan comparison logic #6168

Merged
merged 1 commit into from
Dec 11, 2024
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
23 changes: 21 additions & 2 deletions ocaml/xapi/xapi_sr.ml
Original file line number Diff line number Diff line change
Expand Up @@ -778,15 +778,34 @@ let scan ~__context ~sr =
Db.VDI.get_records_where ~__context
~expr:(Eq (Field "SR", Literal sr'))
in
(* 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)
= []
in
let db_vdis_before = find_vdis () in
let vs, sr_info =
C.SR.scan2 (Ref.string_of task)
(Storage_interface.Sr.of_string sr_uuid)
in
let db_vdis_after = find_vdis () in
if limit > 0 && db_vdis_after <> db_vdis_before then
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 ;
(scan_rec [@tailcall]) (limit - 1)
else if limit = 0 then
) else if limit = 0 then
raise
(Api_errors.Server_error
(Api_errors.internal_error, ["SR.scan retry limit exceeded"])
Expand Down
Loading