# HG changeset patch # User David Scott # Date 1259595420 0 # Node ID 019aa574738a5b334ae20c313c2a640570162569 # Parent a64d476f8d96662d660837a81435d142cbdc9a6a CA-35165: Clean up xapi startup log messages, particularly those to do with the 'localdb'. Add a Localdb.get_with_default [key] [default] function as an alternative to the exception-throwing Localdb.get. Signed-off-by: David Scott diff -r a64d476f8d96 -r 019aa574738a ocaml/xapi/localdb.ml --- a/ocaml/xapi/localdb.ml Mon Nov 30 15:36:58 2009 +0000 +++ b/ocaml/xapi/localdb.ml Mon Nov 30 15:37:00 2009 +0000 @@ -37,7 +37,7 @@ finally (fun () -> of_db (Xmlm.make_input (`Channel ic)); loaded := true) (fun () -> close_in ic); - Hashtbl.iter (fun k v -> debug "loaded %s -> %s" k v) db + Hashtbl.iter (fun k v -> debug "%s = %s" k v) db with | Unix.Unix_error (Unix.ENOENT, _, _) -> debug "Local database %s doesn't currently exist. Continuing." Xapi_globs.local_database @@ -61,6 +61,11 @@ Hashtbl.find db key with Not_found -> raise (Missing_key key) ) + +let get_with_default (key: string) (default: string) = + try + get key + with Missing_key _ -> default (* Returns true if a change was made and should be flushed *) let put_one (key: string) (v: string) = diff -r a64d476f8d96 -r 019aa574738a ocaml/xapi/localdb.mli --- a/ocaml/xapi/localdb.mli Mon Nov 30 15:36:58 2009 +0000 +++ b/ocaml/xapi/localdb.mli Mon Nov 30 15:37:00 2009 +0000 @@ -21,6 +21,10 @@ (** Retrieves a value *) val get: string -> string +(** [get_with_default key default] returns the value associated with [key], + or [default] if the key is missing. *) +val get_with_default: string -> string -> string + (** Inserts a value into the database, only returns when the insertion has been persisted. *) val put: string -> string -> unit diff -r a64d476f8d96 -r 019aa574738a ocaml/xapi/xapi.ml --- a/ocaml/xapi/xapi.ml Mon Nov 30 15:36:58 2009 +0000 +++ b/ocaml/xapi/xapi.ml Mon Nov 30 15:37:00 2009 +0000 @@ -322,11 +322,11 @@ (* Make sure the local database can be read *) let init_local_database () = (try - let enabled = Localdb.get Constants.ha_armed in - debug "%s = %s" Constants.ha_armed enabled; + let (_: string) = Localdb.get Constants.ha_armed in + () with Localdb.Missing_key _ -> Localdb.put Constants.ha_armed "false"; - debug "Missing %s key, assuming 'false'" Constants.ha_armed); + debug "%s = 'false' (by default)" Constants.ha_armed); (* Add the local session check hook *) Session_check.check_local_session_hook := Some (Xapi_local_session.local_session_hook); (* Resynchronise the master_scripts flag if this is the first start since system boot *) @@ -420,7 +420,7 @@ let start_redo_log () = try if Pool_role.is_master () && - bool_of_string (Localdb.get Constants.redo_log_enabled) && + bool_of_string (Localdb.get_with_default Constants.redo_log_enabled "false") && not (bool_of_string (Localdb.get Constants.ha_armed)) then begin debug "Redo log was enabled when shutting down, so restarting it";