Skip to content

Commit fbb7117

Browse files
committed
CP-307958: Use Atomic.t for DB ref
The double ref is not needed, replace it with an Atomic.t No functional change. Signed-off-by: Edwin Török <[email protected]>
1 parent 1cfaab9 commit fbb7117

File tree

6 files changed

+12
-12
lines changed

6 files changed

+12
-12
lines changed

ocaml/database/db_backend.ml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,11 @@ let db_FLUSH_TIMER = 2.0
2121

2222
(* --------------------- Util functions on db datastructures *)
2323

24-
let master_database = ref (Db_cache_types.Database.make Schema.empty)
24+
let master_database = Atomic.make (Db_cache_types.Database.make Schema.empty)
2525

26-
let __test_set_master_database db = master_database := db
26+
let __test_set_master_database db = Atomic.set master_database db
2727

28-
let make () = Db_ref.in_memory (ref master_database)
28+
let make () = Db_ref.in_memory master_database
2929

3030
(* !!! Right now this is called at cache population time. It would probably be preferable to call it on flush time instead, so we
3131
don't waste writes storing non-persistent field values on disk.. At the moment there's not much to worry about, since there are

ocaml/database/db_ref.ml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,22 +12,22 @@
1212
* GNU Lesser General Public License for more details.
1313
*)
1414

15-
type t = In_memory of Db_cache_types.Database.t ref ref | Remote
15+
type t = In_memory of Db_cache_types.Database.t Atomic.t | Remote
1616

1717
exception Database_not_in_memory
1818

19-
let in_memory (rf : Db_cache_types.Database.t ref ref) = In_memory rf
19+
let in_memory (rf : Db_cache_types.Database.t Atomic.t) = In_memory rf
2020

2121
let get_database = function
2222
| In_memory x ->
23-
!(!x)
23+
Atomic.get x
2424
| Remote ->
2525
raise Database_not_in_memory
2626

2727
let update_database t f =
2828
match t with
2929
| In_memory x ->
3030
let d : Db_cache_types.Database.t = f (get_database t) in
31-
!x := d
31+
Atomic.set x d
3232
| Remote ->
3333
raise Database_not_in_memory

ocaml/database/db_ref.mli

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,11 @@
1212
* GNU Lesser General Public License for more details.
1313
*)
1414

15-
type t = In_memory of Db_cache_types.Database.t ref ref | Remote
15+
type t = In_memory of Db_cache_types.Database.t Atomic.t | Remote
1616

1717
exception Database_not_in_memory
1818

19-
val in_memory : Db_cache_types.Database.t ref ref -> t
19+
val in_memory : Db_cache_types.Database.t Atomic.t -> t
2020

2121
val get_database : t -> Db_cache_types.Database.t
2222

ocaml/xapi/pool_db_backup.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ let restore_from_xml __context dry_run (xml_filename : string) =
192192
(Db_xml.From.file (Datamodel_schema.of_datamodel ()) xml_filename)
193193
in
194194
version_check db ;
195-
let db_ref = Db_ref.in_memory (ref (ref db)) in
195+
let db_ref = Db_ref.in_memory (Atomic.make db) in
196196
let new_context = Context.make ~database:db_ref "restore_db" in
197197
prepare_database_for_restore ~old_context:__context ~new_context ;
198198
(* write manifest and unmarshalled db directly to db_temporary_restore_path, so its ready for us on restart *)

ocaml/xapi/xapi_session.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1569,5 +1569,5 @@ let create_from_db_file ~__context ~filename =
15691569
Xapi_database.Db_xml.From.file (Datamodel_schema.of_datamodel ()) filename
15701570
|> Xapi_database.Db_upgrade.generic_database_upgrade
15711571
in
1572-
let db_ref = Some (Xapi_database.Db_ref.in_memory (ref (ref db))) in
1572+
let db_ref = Some (Xapi_database.Db_ref.in_memory (Atomic.make db)) in
15731573
create_readonly_session ~__context ~uname:"db-from-file" ~db_ref

ocaml/xapi/xapi_vdi_helpers.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ let database_ref_of_vdi ~__context ~vdi =
184184
debug "Enabling redo_log with device reason [%s]" device ;
185185
Redo_log.enable_block_existing log device ;
186186
let db = Database.make (Datamodel_schema.of_datamodel ()) in
187-
let db_ref = Xapi_database.Db_ref.in_memory (ref (ref db)) in
187+
let db_ref = Xapi_database.Db_ref.in_memory (Atomic.make db) in
188188
Redo_log_usage.read_from_redo_log log Xapi_globs.foreign_metadata_db db_ref ;
189189
Redo_log.delete log ;
190190
(* Upgrade database to the local schema. *)

0 commit comments

Comments
 (0)