Closed mrdnctrk closed 3 weeks ago
Formatting check succeeded!
All modified and coverable lines are covered by tests :white_check_mark:
Please upload report for BASE (
rel_7_6@5fdce4e
). Learn more about missing BASE report.
:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.
In this PR, I am fixing two issues (#6419 and #6420) related to
$reindex
operation withoptimizeStorage
set toALL_VERSIONS
.6419 is about reindex operation not processing all history versions for a resource on postgres, but only a subset. The root cause of this was, when processing versions records we use pagination, and we update the records on each page, before moving on to the next page. The databases like postgres require a sort parameter for pagination to work properly when the underlying dataset gets updated while the pagination happening (postgres seems to return the least recently updated records first but there is no guarantee on the order unless the order by specified explicity). So to fix that I added a sort by parameter to sort the version records by id when paginating through them.
We actually have a test for this functionality but the test uses h2 and the issue doesn't happen for h2. https://github.com/hapifhir/hapi-fhir/blob/7ee941585ba82ad67f55f6f7cc8fcbd2a89a493b/hapi-fhir-jpaserver-test-r4/src/test/java/ca/uhn/fhir/jpa/reindex/ReindexTaskTest.java#L132-L132
UPDATE: Because I changed the prefetch function prefetch even when there is a single resource, I updated some tests for query counts for transactions by reducing the expected number of select queries. In case there is single resource to Update an existing resource in a transaction (there cab be other resources to create, delete etc in the bundle), previously we weren't prefetching but with the change we are prefetching. You can see one example below, where the number of select statements has reduced from 3 to 2 because of prefetch.
before - 3 queries (to get the resource itself, to get the current version ,and to get the token index):
now - 2 queries: ( first query gets the resource together with its current version, the second query gets the token index)