Skip to content

Commit

Permalink
CA-373551: register for host events rather than task in events_from_xapi
Browse files Browse the repository at this point in the history
A recent change registered for events on the task that was used by the
events_from_xapi thread in xapi_xenops. This is so that the event loop
can be woken up by injecting an event into this task, without the need
to logout its session (as previously done). The problem is that this
introduced a task in the DB that is forever "pending", which has
unwanted side-effects. For example, it gets GC'ed after 24 hours, and
also gets destroyed if the coordinator is restarted.

Switch to registering the host object for the localhost instead, which
should be more stable.

Signed-off-by: Rob Hoes <[email protected]>
  • Loading branch information
robhoes committed Dec 12, 2022
1 parent cde2822 commit 6568cab
Showing 1 changed file with 6 additions and 7 deletions.
13 changes: 6 additions & 7 deletions ocaml/xapi/xapi_xenops.ml
Original file line number Diff line number Diff line change
Expand Up @@ -3207,10 +3207,9 @@ end
(* XXX: PR-1255: we also want to only listen for events on VMs and fields we care about *)
let events_from_xapi () =
let open Event_types in
Server_helpers.exec_with_new_task ~task_in_database:true "xapi events"
(fun __context ->
let task = Context.get_task_id __context |> Ref.string_of in
Server_helpers.exec_with_new_task "xapi events" (fun __context ->
let localhost = Helpers.get_localhost ~__context in
let localhost' = Ref.string_of localhost in
let token = ref "" in
let stop = ref false in
while not !stop do
Expand All @@ -3223,8 +3222,8 @@ let events_from_xapi () =
injection" ;
try
let _ =
XenAPI.Event.inject ~rpc ~session_id ~_class:"task"
~_ref:task
XenAPI.Event.inject ~rpc ~session_id ~_class:"host"
~_ref:localhost'
in
()
with e ->
Expand Down Expand Up @@ -3252,7 +3251,7 @@ let events_from_xapi () =
error "events_from_xapi: extra items in the cache: [ %s ]"
(String.concat "; " (StringSet.elements extra_in_cache)) ;
let classes =
Printf.sprintf "task/%s" task
Printf.sprintf "host/%s" localhost'
:: List.map
(fun x -> Printf.sprintf "VM/%s" (Ref.string_of x))
resident_VMs
Expand Down Expand Up @@ -3310,7 +3309,7 @@ let events_from_xapi () =
raise e
)
)
| {ty= "task"; reference= t; _} when t = task ->
| {ty= "host"; reference= t; _} when t = localhost' ->
debug
"Woken event thread: updating list of event \
subscriptions" ;
Expand Down

0 comments on commit 6568cab

Please sign in to comment.