From: David Scott Date: Wed, 26 Jan 2011 17:39:05 +0000 (+0000) Subject: Remove the installation_uuid from the database manifest (since it duplicated informat... X-Git-Url: http://xenbits.xensource.com/gitweb?a=commitdiff_plain;h=0cc1187f459ced1825dbb48228f4ef48599c0d95;p=xcp%2Fxen-api.git Remove the installation_uuid from the database manifest (since it duplicated information already in the database) Signed-off-by: David Scott --- diff --git a/ocaml/database/db_backend.ml b/ocaml/database/db_backend.ml index 3ae53a88..a8931409 100644 --- a/ocaml/database/db_backend.ml +++ b/ocaml/database/db_backend.ml @@ -199,35 +199,30 @@ let post_restore_hook manifest = let my_installation_uuid = Xapi_inventory.lookup Xapi_inventory._installation_uuid in let my_control_uuid = Xapi_inventory.lookup Xapi_inventory._control_domain_uuid in - let uuid_of_master_in_db = manifest.Db_cache_types.installation_uuid in - let uuid_of_master_dom0_in_db = manifest.Db_cache_types.control_domain_uuid in - - let find_row_by_uuid uuid tbl = - let rs = get_rowlist tbl in - try Some (List.find (fun r->(lookup_field_in_row r uuid_fname)=uuid) rs) - with e -> (debug "find_row_by_uuid 'uuid=%s' failed: %s" - uuid (Printexc.to_string e); - None) in - - let master_host_record = find_row_by_uuid uuid_of_master_in_db (lookup_table_in_cache cache "host") in - let master_dom0_record = find_row_by_uuid uuid_of_master_dom0_in_db (lookup_table_in_cache cache "VM") in - - (* update master host record in db, so it has my installation uuid from my inventory file *) - begin - match master_host_record with - None -> debug "Not updating host record" - | Some mhr -> - (set_field_in_row mhr uuid_fname my_installation_uuid; - let _ref = lookup_field_in_row mhr reference_fname in - Ref_index.update_uuid _ref my_installation_uuid) + let not_found = "" in + (* Look up the pool master: *) + let pools = lookup_table_in_cache cache Db_names.pool in + let master = fold_over_rows (fun _ref r acc -> lookup_field_in_row r Db_names.master) pools not_found in + if master = not_found + then debug "No master record to update" + else begin + + let mhr = find_row cache Db_names.host master in + set_field_in_row mhr uuid_fname my_installation_uuid; + let _ref = lookup_field_in_row mhr reference_fname in + Ref_index.update_uuid _ref my_installation_uuid end; - (* update master dom0 record in db, so it has my control domain uuid from my inventory file in dom0 *) - begin - match master_dom0_record with - None -> debug "Not updating dom0 record" - | Some mhr -> - (set_field_in_row mhr uuid_fname my_control_uuid; - let _ref = lookup_field_in_row mhr reference_fname in - Ref_index.update_uuid _ref my_control_uuid) + + (* Look up the pool master's control domain: *) + let vms = lookup_table_in_cache cache Db_names.vm in + let master_dom0 = fold_over_rows (fun _ref r acc -> if lookup_field_in_row r Db_names.resident_on = master && (lookup_field_in_row r Db_names.is_control_domain = "true") then _ref else acc) vms not_found in + if master_dom0 = not_found + then debug "No master control domain record to update" + else begin + + let mdr = find_row cache Db_names.vm master_dom0 in + set_field_in_row mdr uuid_fname my_control_uuid; + let _ref = lookup_field_in_row mdr reference_fname in + Ref_index.update_uuid _ref my_control_uuid end; debug "post_restore_hook executed" diff --git a/ocaml/database/db_cache_types.ml b/ocaml/database/db_cache_types.ml index d22fc2b0..be4bacf0 100644 --- a/ocaml/database/db_cache_types.ml +++ b/ocaml/database/db_cache_types.ml @@ -28,7 +28,6 @@ let string_of_structured_op op = match op with type db_dump_manifest = { - installation_uuid : string; control_domain_uuid : string; pool_conf : string; pool_token : string; @@ -44,7 +43,6 @@ type db_dump_manifest = let gen_manifest gen_count = { - installation_uuid = Xapi_inventory.lookup Xapi_inventory._installation_uuid; control_domain_uuid = Xapi_inventory.lookup Xapi_inventory._control_domain_uuid; pool_conf = Unixext.string_of_file Xapi_globs.pool_config_file; pool_token = Unixext.string_of_file Xapi_globs.pool_secret_path; diff --git a/ocaml/database/db_cache_types.mli b/ocaml/database/db_cache_types.mli index 3e16b6d8..70ef3559 100644 --- a/ocaml/database/db_cache_types.mli +++ b/ocaml/database/db_cache_types.mli @@ -23,7 +23,6 @@ type where_record = { } type structured_op_t = AddSet | RemoveSet | AddMap | RemoveMap type db_dump_manifest = { - installation_uuid : string; control_domain_uuid : string; pool_conf : string; pool_token : string; diff --git a/ocaml/database/db_names.ml b/ocaml/database/db_names.ml index 7f5d0d26..f1db3939 100644 --- a/ocaml/database/db_names.ml +++ b/ocaml/database/db_names.ml @@ -42,5 +42,7 @@ let scheduled_to_be_resident_on = "scheduled_to_be_resident_on" let domid = "domid" let ha_always_run = "ha_always_run" let host = "host" +let pool = "pool" +let master = "master" let bios_strings = "bios_strings" let protection_policy = "protection_policy" diff --git a/ocaml/database/db_xml.ml b/ocaml/database/db_xml.ml index 0418e46b..8cdefca2 100644 --- a/ocaml/database/db_xml.ml +++ b/ocaml/database/db_xml.ml @@ -22,7 +22,6 @@ exception Unmarshall_error of string let name x = ("", x) (* no namespace *) let make_tag n attrs : Xmlm.tag = (name n), List.map (fun (k, v) -> name k, v) attrs -let _installation_uuid = "installation_uuid" let _control_domain_uuid = "control_domain_uuid" let _pool_conf = "pool_conf" let _pool_token = "pool_token" @@ -66,7 +65,6 @@ module To = struct (* Write out a manifest *) let manifest (output: Xmlm.output) (manifest: db_dump_manifest) : unit = Xmlm.output output (`El_start (make_tag "manifest" [])); - string output _installation_uuid manifest.installation_uuid; string output _control_domain_uuid manifest.control_domain_uuid; string output _pool_conf manifest.pool_conf; string output _pool_token manifest.pool_token; @@ -144,7 +142,6 @@ module From = struct let (cache, _, manifest) = f (create_empty_cache (), create_empty_table (), []) in (* Manifest is actually a record *) let manifest = { - installation_uuid = List.assoc _installation_uuid manifest; control_domain_uuid = List.assoc _control_domain_uuid manifest; pool_conf = List.assoc _pool_conf manifest; pool_token = List.assoc _pool_token manifest; diff --git a/ocaml/xapi/pool_db_backup.ml b/ocaml/xapi/pool_db_backup.ml index 531a63a1..b8bab249 100644 --- a/ocaml/xapi/pool_db_backup.ml +++ b/ocaml/xapi/pool_db_backup.ml @@ -29,7 +29,7 @@ let octet_stream = "Content-Type: application/octet-stream" (* CA-18377: The smallest database that is compatible with the Miami database schema. *) let minimally_compliant_miami_database = - "
" + "
" (** Write the database dump out to a file/socket *) let write_database (s: Unix.file_descr) ~__context = @@ -64,16 +64,17 @@ let restore_from_xml __context dry_run (xml_filename: string) = let hosts = lookup_table_in_cache unmarshalled_db "host" in let uuid_to_ref = fold_over_rows (fun _ref r acc -> (lookup_field_in_row r "uuid", _ref)::acc) hosts [] in - (* This should never happen by construction: *) - if not(List.mem_assoc manifest.Db_cache_types.installation_uuid uuid_to_ref) - then failwith "Master host's UUID not present in the backup file"; - let master = List.assoc manifest.Db_cache_types.installation_uuid uuid_to_ref in + + (* Look up the pool master: *) + let pools = lookup_table_in_cache unmarshalled_db Datamodel._pool in + let master = fold_over_rows (fun _ref r acc -> lookup_field_in_row r "master") pools "" in + (* Remove all slaves from the database *) let hosts' = create_empty_table () in iter_over_rows (fun _ref r -> if _ref = master then set_row_in_table hosts' master r) hosts; set_table_in_cache unmarshalled_db "host" hosts'; debug "All hosts: [ %s ]" (String.concat "; " (List.map fst uuid_to_ref)); - debug "Previous master: %s" manifest.Db_cache_types.installation_uuid; + debug "Previous master: %s" master; (* Rewrite this host's PIFs' MAC addresses based on device name. *) diff --git a/ocaml/xapi/redo_log_usage.ml b/ocaml/xapi/redo_log_usage.ml index 1d075f00..36c8bcfe 100644 --- a/ocaml/xapi/redo_log_usage.ml +++ b/ocaml/xapi/redo_log_usage.ml @@ -91,8 +91,8 @@ let read_from_redo_log staging_path = raise NoGeneration | Some generation -> (* Write the in-memory cache to the file *) - let db_cache_manifest = Db_cache_types.gen_manifest generation in - Db_xml.To.file staging_path (db_cache_manifest, Db_backend.cache); + let manifest = Db_cache_types.gen_manifest generation in + Db_xml.To.file staging_path (manifest, Db_backend.cache); Unixext.write_string_to_file (staging_path ^ ".generation") (Generation.to_string generation) end with _ -> () (* it's just a best effort. if we can't read from the log, then don't worry. *)