@@ -53,21 +53,38 @@ let database_ready_for_clients = ref false (* while this is false, client calls
5353
5454open Db_cache_types
5555
56+ (* * Populate the database from the default connections or the restore db file
57+ (if it is present). Perform an initial flush to the database connections
58+ which were already setup, then delete the restore file. *)
59+ let populate_db backend =
60+ let schema = Datamodel_schema. of_datamodel () in
61+
62+ let output_connections = Db_conn_store. read_db_connections () in
63+ (* If the temporary restore file is present then we must populate from that *)
64+ let restoring = Sys. file_exists Xapi_globs. db_temporary_restore_path in
65+ let input_connections =
66+ if restoring
67+ then [ Parse_db_conf. make Xapi_globs. db_temporary_restore_path ]
68+ else output_connections
69+ in
70+ debug " Attempting to populate database from one of these locations: [%s]"
71+ (String. concat " ; "
72+ (List. map (fun conn -> conn.Parse_db_conf. path) input_connections));
73+ Db_cache_impl. make backend input_connections schema;
74+ Db_cache_impl. sync output_connections (Db_ref. get_database backend);
75+ (* Delete the temporary restore file so that we don't revert to it again at next startup. *)
76+ if restoring then begin
77+ Unixext. unlink_safe Xapi_globs. db_temporary_restore_path;
78+ Unixext. unlink_safe (Xapi_globs. db_temporary_restore_path ^ " .generation" )
79+ end
80+
5681(* * Starts the main database engine: this should be done only on the master node.
5782 The db connections must have been parsed from db.conf file and initialised before this fn is called.
5883 Also this function depends on being able to call API functions through the external interface.
5984*)
6085let start_database_engine () =
61- let schema = Datamodel_schema. of_datamodel () in
62-
63- (* If the temporary restore file is present then we must populate from that *)
64- let connections =
65- if Sys. file_exists Xapi_globs. db_temporary_restore_path
66- then [ Parse_db_conf. make Xapi_globs. db_temporary_restore_path ]
67- else Db_conn_store. read_db_connections () in
6886 let t = Db_backend. make () in
69- Db_cache_impl. make t connections schema;
70- Db_cache_impl. sync connections (Db_ref. get_database t);
87+ populate_db t;
7188
7289 Db_ref. update_database t (Database. register_callback " redo_log" Redo_log. database_callback);
7390 Db_ref. update_database t (Database. register_callback " events" Eventgen. database_callback);
0 commit comments