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

CP-52880: Avoid O(N^2) behaviour in Xapi_vdi.update_allowed_operations #6183

Draft
wants to merge 1 commit into
base: feature/perf
Choose a base branch
from
Draft
Show file tree
Hide file tree
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
4 changes: 2 additions & 2 deletions ocaml/xapi/cancel_tasks.ml
Original file line number Diff line number Diff line change
Expand Up @@ -83,14 +83,14 @@ let update_all_allowed_operations ~__context =
in
let vbd_records =
List.map
(fun vbd -> (vbd, Db.VBD.get_record_internal ~__context ~self:vbd))
(fun vbd -> Db.VBD.get_record_internal ~__context ~self:vbd)
all_vbds
in
List.iter
(safe_wrapper "allowed_ops - VDIs" (fun self ->
let relevant_vbds =
List.filter
(fun (_, vbd_record) -> vbd_record.Db_actions.vBD_VDI = self)
(fun vbd_record -> vbd_record.Db_actions.vBD_VDI = self)
vbd_records
in
Xapi_vdi.update_allowed_operations_internal ~__context ~self
Expand Down
38 changes: 21 additions & 17 deletions ocaml/xapi/xapi_vdi.ml
Original file line number Diff line number Diff line change
Expand Up @@ -155,16 +155,14 @@ let check_operation_error ~__context ?sr_records:_ ?(pbd_records = [])
)
)
| Some records ->
List.map snd
(List.filter
(fun (_, vbd_record) ->
vbd_record.Db_actions.vBD_VDI = _ref'
&& (vbd_record.Db_actions.vBD_currently_attached
|| vbd_record.Db_actions.vBD_reserved
)
)
records
List.filter
(fun vbd_record ->
vbd_record.Db_actions.vBD_VDI = _ref'
&& (vbd_record.Db_actions.vBD_currently_attached
|| vbd_record.Db_actions.vBD_reserved
)
)
records
in
let my_active_rw_vbd_records =
List.filter (fun vbd -> vbd.Db_actions.vBD_mode = `RW) my_active_vbd_records
Expand All @@ -183,14 +181,12 @@ let check_operation_error ~__context ?sr_records:_ ?(pbd_records = [])
)
)
| Some records ->
List.map snd
(List.filter
(fun (_, vbd_record) ->
vbd_record.Db_actions.vBD_VDI = _ref'
&& vbd_record.Db_actions.vBD_current_operations <> []
)
records
List.filter
(fun vbd_record ->
vbd_record.Db_actions.vBD_VDI = _ref'
&& vbd_record.Db_actions.vBD_current_operations <> []
)
records
in
(* If the VBD is currently_attached then some operations can still be
performed ie: VDI.clone (if the VM is suspended we have to have the
Expand Down Expand Up @@ -477,10 +473,18 @@ let update_allowed_operations_internal ~__context ~self ~sr_records ~pbd_records
)
in
let all = Db.VDI.get_record_internal ~__context ~self in
let vbd_records =
match vbd_records with
| None ->
all.Db_actions.vDI_VBDs
|> List.rev_map (fun self -> Db.VBD.get_record_internal ~__context ~self)
| Some cached ->
cached (* currently unused *)
in
let allowed =
let check x =
match
check_operation_error ~__context ~sr_records ~pbd_records ?vbd_records
check_operation_error ~__context ~sr_records ~pbd_records ~vbd_records
ha_enabled all self x
with
| Ok () ->
Expand Down
4 changes: 2 additions & 2 deletions ocaml/xapi/xapi_vdi.mli
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ val check_operation_error :
__context:Context.t
-> ?sr_records:'a list
-> ?pbd_records:(API.ref_PBD * API.pBD_t) list
-> ?vbd_records:(API.ref_VBD * Db_actions.vBD_t) list
-> ?vbd_records:Db_actions.vBD_t list
-> bool
-> Db_actions.vDI_t
-> API.ref_VDI
Expand All @@ -40,7 +40,7 @@ val update_allowed_operations_internal :
-> self:[`VDI] API.Ref.t
-> sr_records:'a list
-> pbd_records:(API.ref_PBD * API.pBD_t) list
-> ?vbd_records:(API.ref_VBD * Db_actions.vBD_t) list
-> ?vbd_records:Db_actions.vBD_t list
-> unit
-> unit

Expand Down
Loading