fix: Investigate simultaneous updates of data values is not updating at all [ DHIS2-16080 ] #15790
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
https://dhis2.atlassian.net/browse/DHIS2-16080
In the old tracker, we have the
/events
endpoint:@PutMapping(value = "/{uid}/{dataElementUid}"
which is supposed to update the event data values although it goes through the generic event update.
There are 2 points about this issue:
1- With the
WorkContextLoader
, info about the existingeventdatavalues
field is preloaded. Therefore, if we have a concurrent update we might preload data element values that are no longer valid2- Apparently, using the spring JdbcTemplate
batchUpdate
the concurrency and wait for the same row update is not working.Solution - Relying on
@Transactional
One possible solution to this issue is to process one data element value at a time inside the JSON.
This is done using the Postgres function
jsonb_update
orjsonb_insert
.@Transactional
should handle the concurrency for us if we use hibernate queries.Alternative solution
An alternative approach to this issue is to use locking. There are 2 possible locking we can use:
@Version
field so we can catch if the row we are updating is the current version or not. This can have a big impact on the current state of theevent
tableSELECT .. FOR UPDATE
syntax which can slow down performances and create deadlocks