Skip to content

CP-51701: xapi event optimizations #6124

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 4 commits into from
Nov 19, 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
26 changes: 10 additions & 16 deletions ocaml/xapi/xapi_event.ml
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,10 @@ module Token = struct
Printf.sprintf "%020Ld,%020Ld" last last_t
end

let is_lowercase_char c = Char.equal (Char.lowercase_ascii c) c

let is_lowercase str = String.for_all is_lowercase_char str

module Subscription = struct
type t = Class of string | Object of string * string | All

Expand All @@ -67,11 +71,9 @@ module Subscription = struct
(Api_errors.event_subscription_parse_failure, [x])
)

let any = List.fold_left (fun acc x -> acc || x) false

(** [table_matches subs tbl]: true if at least one subscription from [subs] would select some events from [tbl] *)
let table_matches subs tbl =
let tbl = String.lowercase_ascii tbl in
let tbl = if is_lowercase tbl then tbl else String.lowercase_ascii tbl in
let matches = function
| All ->
true
Expand All @@ -80,11 +82,11 @@ module Subscription = struct
| Object (x, _) ->
x = tbl
in
any (List.map matches subs)
List.exists matches subs

(** [event_matches subs ev]: true if at least one subscription from [subs] selects for specified class and object *)
let object_matches subs ty _ref =
let tbl = String.lowercase_ascii ty in
let tbl = if is_lowercase ty then ty else String.lowercase_ascii ty in
let matches = function
| All ->
true
Expand All @@ -93,7 +95,7 @@ module Subscription = struct
| Object (x, y) ->
x = tbl && y = _ref
in
any (List.map matches subs)
List.exists matches subs

(** [event_matches subs ev]: true if at least one subscription from [subs] selects for event [ev] *)
let event_matches subs ev = object_matches subs ev.ty ev.reference
Expand Down Expand Up @@ -540,11 +542,7 @@ let from_inner __context session subs from from_t deadline =
Db_cache_types.Table.fold_over_recent !last_generation
(fun objref {Db_cache_types.Stat.created; modified; deleted} _
(creates, mods, deletes, last) ->
if
Subscription.object_matches subs
(String.lowercase_ascii table)
objref
then
if Subscription.object_matches subs table objref then
let last = max last (max modified deleted) in
(* mtime guaranteed to always be larger than ctime *)
( ( if created > !last_generation then
Expand Down Expand Up @@ -574,11 +572,7 @@ let from_inner __context session subs from from_t deadline =
Db_cache_types.Table.fold_over_deleted !last_generation
(fun objref {Db_cache_types.Stat.created; modified; deleted}
(creates, mods, deletes, last) ->
if
Subscription.object_matches subs
(String.lowercase_ascii table)
objref
then
if Subscription.object_matches subs table objref then
let last = max last (max modified deleted) in
(* mtime guaranteed to always be larger than ctime *)
if created > !last_generation then
Expand Down
Loading