Skip to content

Commit 9adf2db

Browse files
committed
CP-13493: Thread to update xapi db for physical utilisation of SR
1) This new thread will run on each host. 2) Thread will update physical utilisation only for SR which has SR_STATS capability and sr-master. Signed-off-by: Sharad Yadav <[email protected]>
1 parent e561cf6 commit 9adf2db

File tree

2 files changed

+28
-0
lines changed

2 files changed

+28
-0
lines changed

ocaml/xapi/xapi.ml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -960,6 +960,7 @@ let server_init() =
960960
"writing init complete", [], (fun () -> Helpers.touch_file !Xapi_globs.init_complete);
961961
(* "Synchronising HA state with Pool", [ Startup.NoExnRaising ], Xapi_ha.synchronise_ha_state_with_pool; *)
962962
"Starting DR redo-logs", [ Startup.OnlyMaster; ], start_dr_redo_logs;
963+
"Starting SR physical utilisation scanning", [Startup.OnThread], (Xapi_sr.physical_utilisation_thread ~__context);
963964
"Caching metadata VDIs created by foreign pools.", [ Startup.OnlyMaster; ], cache_metadata_vdis;
964965
"Stats reporting thread", [], Xapi_stats.start;
965966
];

ocaml/xapi/xapi_sr.ml

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,33 @@ let scanning_thread () = Debug.with_thread_named "scanning_thread" (fun () ->
124124
done)
125125
) ()
126126

127+
let sr_cache = ref []
128+
129+
let update_physical_utilisation ~__context =
130+
let srs = Helpers.get_all_plugged_srs ~__context in
131+
(* Remove SRs from sr_cache if they are no more available *)
132+
sr_cache := List.filter (fun sr -> (List.mem sr srs)) !sr_cache;
133+
(* Checks whether SR is sr_master and has SR_STATS capability *)
134+
let is_stats_sr ~__context sr =
135+
let sr_record = Db.SR.get_record_internal ~__context ~self:sr in
136+
if (Smint.(has_capability Sr_stats (Xapi_sr_operations.features_of_sr ~__context sr_record)) &&
137+
(Helpers.i_am_srmaster ~__context ~sr))
138+
then true else false
139+
in
140+
let srs_to_be_added = List.filter (fun sr -> (List.mem sr !sr_cache = false) && (is_stats_sr ~__context sr)) srs in
141+
sr_cache := !sr_cache @ srs_to_be_added;
142+
(* Update the physical utilisation db field of cached SRs *)
143+
List.iter (fun sr ->
144+
let new_value = Rrdd.query_sr_ds ~sr_uuid:(Db.SR.get_uuid ~__context ~self:sr) ~ds_name:"physical_utilisation" in
145+
Db.SR.set_physical_utilisation ~__context ~self:sr ~value:(Int64.of_float new_value)) !sr_cache
146+
147+
let physical_utilisation_thread ~__context () =
148+
while true do
149+
Thread.delay 120. ;
150+
try update_physical_utilisation ~__context
151+
with e -> debug "Exception in SR physical utilisation scanning thread: %s" (Printexc.to_string e)
152+
done
153+
127154
(* introduce, creates a record for the SR in the database. It has no other side effect *)
128155
let introduce ~__context ~uuid ~name_label
129156
~name_description ~_type ~content_type ~shared ~sm_config =

0 commit comments

Comments
 (0)