]> xenbits.xensource.com Git - xcp/xen-api.git/commitdiff
SCTX-525: Use fewer RPCs in the VLAN resynchronisation code
authorDavid Scott <dave.scott@eu.citrix.com>
Wed, 26 Jan 2011 17:39:04 +0000 (17:39 +0000)
committerDavid Scott <dave.scott@eu.citrix.com>
Wed, 26 Jan 2011 17:39:04 +0000 (17:39 +0000)
Pool:
* 5 hosts
* 300 VLANs (none in use)
A full xapi restart is reduced from 100s to 82s.

Signed-off-by: David Scott <dave.scott@eu.citrix.com>
ocaml/xapi/sync_networking.ml

index 00972e0c4e97297a91564b0f64e7de26b6fa6821..d2a60d6296e54c838c7bd08f711f29cf2274133f 100644 (file)
@@ -122,25 +122,28 @@ let copy_bonds_from_master ~__context =
    PIF (e.g. if the master has eth0.25 and we don't have eth0) then we do nothing.
 *)
 let copy_vlans_from_master ~__context =
-       Helpers.call_api_functions ~__context (fun rpc session_id ->
-               debug "Resynchronising VLANs";
-
-               let me = !Xapi_globs.localhost_ref in
-               let pool = List.hd (Db.Pool.get_all ~__context) in
-               let master = Db.Pool.get_master ~__context ~self:pool in
-
-               let all_pifs = Db.PIF.get_records_where ~__context ~expr:Db_filter_types.True in
-               let all_master_pifs = List.filter (fun (_, prec) -> prec.API.pIF_host=master) all_pifs in
-               let my_pifs = List.filter (fun (_, pif) -> pif.API.pIF_host=me) all_pifs in
-
-               let master_vlan_pifs = List.filter (fun (_,prec) -> prec.API.pIF_VLAN <> -1L) all_master_pifs in
-               let my_vlan_pifs = List.filter (fun (_,prec) -> prec.API.pIF_VLAN <> -1L) my_pifs in
-
-               let get_network_of_pif_underneath_vlan vlan_pif_ref =
-                       let pif_underneath_vlan = Helpers.get_pif_underneath_vlan ~__context vlan_pif_ref in
-                       let network_of_pif_underneath_vlan = Db.PIF.get_network ~__context ~self:pif_underneath_vlan in
-                       network_of_pif_underneath_vlan
-               in
+      Helpers.call_api_functions ~__context
+                 (fun rpc session_id ->
+                         debug "Resynchronising VLANs";
+                         (* 1. Download data from the master, minimising round-trips *)
+                         let me = !Xapi_globs.localhost_ref in
+                         let pool = Helpers.get_pool ~__context in
+                         let master = Db.Pool.get_master ~__context ~self:pool in
+                         let pifs = Db.PIF.get_all_records ~__context in
+                         let vlans = Db.VLAN.get_all_records ~__context in
+                         (* 2. Make lists and lookup tables *)
+                         let all_master_pifs = List.filter (fun (_, prec) -> prec.API.pIF_host=master) pifs in
+                         let my_pifs = List.filter (fun (_, pif) -> pif.API.pIF_host=me) pifs in
+                         let master_vlan_pifs = List.filter (fun (_,prec) -> prec.API.pIF_VLAN <> -1L) all_master_pifs in
+                         let my_vlan_pifs = List.filter (fun (_,prec) -> prec.API.pIF_VLAN <> -1L) my_pifs in
+
+                         let get_network_of_pif_underneath_vlan vlan_pif_ref =
+                                 let pif_r = List.assoc vlan_pif_ref pifs in
+                                 let vlan = pif_r.API.pIF_VLAN_master_of in
+                                 let vlan_r = List.assoc vlan vlans in
+                                 let pif_underneath_vlan = vlan_r.API.vLAN_tagged_PIF in
+                                 let pif_underneath_vlan_r = List.assoc pif_underneath_vlan pifs in
+                                 pif_underneath_vlan_r.API.pIF_network in
 
                let maybe_create_vlan_pif_for_me (master_pif_ref, master_pif_rec) =
                        (* check to see if I have any existing pif(s) that for the specified device, network, vlan... *)