Skip to content

Commit 5f754cb

Browse files
committed
CA-171948: Add a parameter to allow the db add_to_map to be idempotent
Signed-off-by: Jon Ludlam <[email protected]>
1 parent f58b9f3 commit 5f754cb

File tree

3 files changed

+4
-4
lines changed

3 files changed

+4
-4
lines changed

ocaml/database/db_cache_impl.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,7 @@ let process_structured_field_locked t (key,value) tblname fld objref proc_fn_sel
257257
| AddMap ->
258258
begin
259259
try
260-
add_to_map key value existing_str
260+
add_to_map false key value existing_str
261261
with Duplicate ->
262262
error "Duplicate key in set or map: table %s; field %s; ref %s; key %s" tblname fld objref key;
263263
raise (Duplicate_key (tblname,fld,objref,key));

ocaml/database/db_cache_types.ml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -350,9 +350,9 @@ let remove_from_set key t =
350350
Schema.Value.Set (List.filter (fun x -> x <> key) t)
351351

352352
exception Duplicate
353-
let add_to_map key value t =
353+
let add_to_map idempotent key value t =
354354
let t = Schema.Value.Unsafe_cast.pairs t in
355-
if List.mem_assoc key t && List.assoc key t <> value then raise Duplicate;
355+
if List.mem_assoc key t && (not idempotent || List.assoc key t <> value) then raise Duplicate;
356356
Schema.Value.Pairs ((key, value) :: List.filter (fun (k, _) -> k <> key) t)
357357

358358
let remove_from_map key t =

ocaml/database/db_cache_types.mli

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ end
146146
exception Duplicate
147147
val add_to_set : string -> Schema.Value.t -> Schema.Value.t
148148
val remove_from_set : string -> Schema.Value.t -> Schema.Value.t
149-
val add_to_map : string -> string -> Schema.Value.t -> Schema.Value.t
149+
val add_to_map : bool -> string -> string -> Schema.Value.t -> Schema.Value.t
150150
val remove_from_map : string -> Schema.Value.t -> Schema.Value.t
151151

152152
val set_field : string -> string -> string -> Schema.Value.t -> Database.t -> Database.t

0 commit comments

Comments
 (0)