Skip to content

Commit

Permalink
CA-70188: Remove invalid pool patches from the database at xapi startup.
Browse files Browse the repository at this point in the history
A pool_patch is valid if either:

- It has been applied to at least one host, or
- Its file exists on the master filesystem.

It neither of these is true, we can delete the pool_patch object.

Signed-off-by: John Else <john.else@citrix.com>
  • Loading branch information
johnelse committed Nov 22, 2012
1 parent 0817d46 commit 8dd205d
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion ocaml/xapi/dbsync_master.ml
Expand Up @@ -183,6 +183,22 @@ let ensure_vm_metrics_records_exist __context =

let ensure_vm_metrics_records_exist_noexn __context = Helpers.log_exn_continue "ensuring VM_metrics flags exist" ensure_vm_metrics_records_exist __context

let destroy_invalid_pool_patches ~__context =
let is_valid_pool_patch patch =
(* If patch has been applied to at least one host, then it is valid. *)
if (Db.Pool_patch.get_host_patches ~__context ~self:patch) <> [] then true
(* If patch hasn't been applied to any host, but we can still apply it, then it is valid. *)
(* File needs to exist in the master's filesystem for us to be able to apply it. *)
else if (Sys.file_exists (Db.Pool_patch.get_filename ~__context ~self:patch)) then true
else false
in
let pool_patches = Db.Pool_patch.get_all ~__context in
List.iter
(fun patch ->
if not (is_valid_pool_patch patch)
then Db.Pool_patch.destroy ~__context ~self:patch)
pool_patches

(* Update the database to reflect current state. Called for both start of day and after
an agent restart. *)
let update_env __context =
Expand Down Expand Up @@ -220,4 +236,5 @@ let update_env __context =
is to just clear the cache, which we do here. *)
Helpers.clear_tools_sr_cache ();

ensure_vm_metrics_records_exist_noexn __context
ensure_vm_metrics_records_exist_noexn __context;
destroy_invalid_pool_patches ~__context

0 comments on commit 8dd205d

Please sign in to comment.