Skip to content

Commit

Permalink
CA-375396: Ignore removed fields when redoing writes
Browse files Browse the repository at this point in the history
When loading a database from disk in XML, fields that are marked in the
datamodel as removed are ignored and not written to the in-memory database.
Because some fields that have been marked as removed are still written to, like
host metrics' free memory, they might still be tried to be replayed and they
fail because the row does not exist in the database.

The plan is to change the generation of code from the datamodel which will make
the writes impossible. In the meantime follow the same strategy of the xml
loading: do not replay the writes if the field has been marked as removed

Signed-off-by: Pau Ruiz Safont <[email protected]>
  • Loading branch information
psafont authored Oct 31, 2023
1 parent 67cb444 commit d9b6d21
Showing 1 changed file with 21 additions and 3 deletions.
24 changes: 21 additions & 3 deletions ocaml/database/db_cache.ml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,11 @@ let get = function
| Db_ref.Remote ->
(module Remote_db : DB_ACCESS)

let lifecycle_state_of ~obj fld =
let open Datamodel in
let {fld_states; _} = StringMap.find obj all_lifecycles in
StringMap.find fld fld_states

let apply_delta_to_cache entry db_ref =
let module DB : DB_ACCESS = Local_db in
match entry with
Expand All @@ -46,6 +51,19 @@ let apply_delta_to_cache entry db_ref =
debug "Redoing delete_row %s (%s)" tblname objref ;
DB.delete_row db_ref tblname objref
| Redo_log.WriteField (tblname, objref, fldname, newval) ->
debug "Redoing write_field %s (%s) [%s -> %s]" tblname objref fldname
newval ;
DB.write_field db_ref tblname objref fldname newval
let removed =
try lifecycle_state_of ~obj:tblname fldname = Removed_s
with Not_found ->
warn "no lifetime information about %s.%s, ignoring write_field"
tblname fldname ;
true
in
if not removed then (
debug "Redoing write_field %s (%s) [%s -> %s]" tblname objref fldname
newval ;
DB.write_field db_ref tblname objref fldname newval
) else
info
"Field has been removed from the datamodel, ignoring write_field %s \
(%s) [%s -> %s]"
tblname objref fldname newval

0 comments on commit d9b6d21

Please sign in to comment.