Skip to content

Commit e583a5d

Browse files
committed
CA-416351: Slave shutdown timeout
Before shutting down, xapi calls `xapi_pre_shutdown` to execute several pre-shutdown scripts, which require the current host's UUID as a parameter. Currently, xapi obtains this UUID in a redundant manner: 1. It retrieves the UUID from the local inventory file. 2. It queries the database for the host's reference using the UUID. 3. It queries the database again for the host's UUID using the reference obtained in step 2. Steps 2 and 3 are unnecessary since the UUID is already available from step 1. Moreover, when the master stops, the slave fails to query the database, increasing xapi shutdown times on the slave. The solution is to directly use the UUID obtained in step 1, eliminating the redundant database queries. Signed-off-by: Bengang Yuan <[email protected]>
1 parent 4f80ccf commit e583a5d

File tree

2 files changed

+14
-15
lines changed

2 files changed

+14
-15
lines changed

ocaml/xapi/xapi_hooks.ml

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -102,22 +102,21 @@ let execute_hook ~__context ~script_name ~args ~reason =
102102
)
103103
scripts
104104

105-
let execute_vm_hook ~__context ~reason ~vm =
106-
let vmuuid = Db.VM.get_uuid ~__context ~self:vm in
107-
execute_hook ~__context ~args:["-vmuuid"; vmuuid] ~reason
105+
let execute_vm_hook ~__context ~reason ~vm_uuid =
106+
execute_hook ~__context ~args:["-vmuuid"; vm_uuid] ~reason
108107

109-
let execute_host_hook ~__context ~reason ~host =
110-
let uuid = Db.Host.get_uuid ~__context ~self:host in
111-
execute_hook ~__context ~args:["-hostuuid"; uuid] ~reason
108+
let execute_host_hook ~__context ~reason ~host_uuid =
109+
execute_hook ~__context ~args:["-hostuuid"; host_uuid] ~reason
112110

113111
let execute_pool_hook ~__context ~reason =
114112
execute_hook ~__context ~args:[] ~reason
115113

116114
let host_pre_declare_dead ~__context ~host ~reason =
117115
info "Running host pre declare dead hook for %s" (Ref.string_of host) ;
118116
(* this could use power fencing *)
117+
let host_uuid = Db.Host.get_uuid ~__context ~self:host in
119118
execute_host_hook ~__context ~script_name:scriptname__host_pre_declare_dead
120-
~reason ~host ;
119+
~reason ~host_uuid ;
121120
if String.equal reason reason__dbdestroy then
122121
log_and_ignore_exn (fun () ->
123122
(* declare it as dead to the clustering daemon if any *)
@@ -132,11 +131,10 @@ let host_pre_declare_dead ~__context ~host ~reason =
132131
()
133132
)
134133

135-
let xapi_pre_shutdown ~__context ~host ~reason =
136-
info "%s Running xapi pre shutdown hooks for %s" __FUNCTION__
137-
(Ref.string_of host) ;
134+
let xapi_pre_shutdown ~__context ~host_uuid ~reason =
135+
info "%s Running xapi pre shutdown hooks for %s" __FUNCTION__ host_uuid ;
138136
execute_host_hook ~__context ~script_name:scriptname__xapi_pre_shutdown
139-
~reason ~host
137+
~reason ~host_uuid
140138

141139
(* Called when host died -- !! hook code in here to abort outstanding forwarded ops *)
142140
let internal_host_dead_hook __context host =
@@ -159,8 +157,9 @@ let internal_host_dead_hook __context host =
159157
let host_post_declare_dead ~__context ~host ~reason =
160158
(* Cancel outstanding tasks first-- should release necessary locks *)
161159
internal_host_dead_hook __context host ;
160+
let host_uuid = Db.Host.get_uuid ~__context ~self:host in
162161
execute_host_hook ~__context ~script_name:scriptname__host_post_declare_dead
163-
~reason ~host
162+
~reason ~host_uuid
164163

165164
let pool_ha_overcommitted_hook ~__context =
166165
execute_pool_hook ~__context ~script_name:scriptname__pool_ha_overcommitted

ocaml/xapi/xapi_host.ml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -793,9 +793,9 @@ let restart_agent ~__context ~host:_ =
793793
)
794794

795795
let shutdown_agent ~__context =
796-
debug "Host.restart_agent: Host agent will shutdown in 1s!!!!" ;
797-
let localhost = Helpers.get_localhost ~__context in
798-
Xapi_hooks.xapi_pre_shutdown ~__context ~host:localhost
796+
debug "Host.shutdown_agent: Host agent will shutdown in 1s!!!!" ;
797+
let host_uuid = Helpers.get_localhost_uuid () in
798+
Xapi_hooks.xapi_pre_shutdown ~__context ~host_uuid
799799
~reason:Xapi_hooks.reason__clean_shutdown ;
800800
Xapi_fuse.light_fuse_and_dont_restart ~fuse_length:1. ()
801801

0 commit comments

Comments
 (0)