appuio / appuio-cloud-reporting

Reporting for APPUiO Cloud
BSD 3-Clause "New" or "Revised" License
0 stars 1 forks source link

Make upsert non-row-locking #17

Closed bastjan closed 2 years ago

bastjan commented 2 years ago

Allows running many reports in parallel and reduces the chances of deadlocks.

Checklist

bastjan commented 2 years ago

How does this change ensure that all parallel reports are able to commit their changes at the end? For example, what happens when two reports (in parallel) create a new category?

It still can happen if two reports create a category at the same time. But it will happen way less frequently. With the old upsert the row was locked for every fact update. Now just if a new category/tenant is created.

The transactions are serialized with RW locks. If report A commits fast enough to not trigger the deadlock detection report B sees the row in existing.

PostgeSQL has deadlock detection we can tune if we see deadlocks often because of the long transaction times.