Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Investigate simultaneous updates of data values is not updating at all [ DHIS2-16080 ] #15790

Closed
wants to merge 2 commits into from

Conversation

lucaCambi77
Copy link
Contributor

@lucaCambi77 lucaCambi77 commented Nov 29, 2023

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 existing eventdatavalues field is preloaded. Therefore, if we have a concurrent update we might preload data element values that are no longer valid
2- 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 or jsonb_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:

  • Optimistic locking: hibernate recommends we use the @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 the event table
  • Pessimistic locking. This will eventually result in using the SELECT .. FOR UPDATE syntax which can slow down performances and create deadlocks

Copy link

SonarCloud Quality Gate failed.    Quality Gate failed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 5 Code Smells

0.0% 0.0% Coverage
0.0% 0.0% Duplication

idea Catch issues before they fail your Quality Gate with our IDE extension sonarlint SonarLint

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant