Use repeatable read for pnl tick generation. (backport #2578) #2580
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.
Changelist
By default all transactions in postgres use the
read committed
isolation level. This means that anySELECT
within a transaction will only see data that was committed before the select was run. However, this means thatSELECT
s within a transaction done at different times may see different data. This is an issue for the PnL task which gets data from thetransfers
table and theperpetual_positions
table to determine the PnL snapshot of a subaccount, as there can be a race condition between reading the transfers and perpetual positions ifender
is updating both tables.Instead we should use the
repeatable read
transaction isolation level, that guarantees within a transaction allSELECT
s will read the same snapshot of data. We only use this for the read-only transaction in the pnl task to ensure no rollbacks / retries need to be added.Transaction isolation level reference
Test Plan
Unit tests, running in a deployed environment.
Author/Reviewer Checklist
state-breaking
label.indexer-postgres-breaking
label.PrepareProposal
orProcessProposal
, manually add the labelproposal-breaking
.feature:[feature-name]
.backport/[branch-name]
.refactor
,chore
,bug
.Summary by CodeRabbit
New Features
Bug Fixes
This is an automatic backport of pull request #2578 done by [Mergify](https://mergify.com).