-
Notifications
You must be signed in to change notification settings - Fork 500
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
Use COPY to speed up ClaimableBalancesChangeProcessor #5086
Comments
We can also use COPY to speed up inserts in the SignersProcessor |
When I switched the claimable balance processor to use FastBatchInsertBuilder,' which uses ‘COPY' instead of 'INSERT,' it worked in my local environment but it failed on the CI pipeline with the following error in json parsing After investigating, I found that the According to the code this issue should occur for Postgres version 9.0 and above and the Postgres version I have locally is 15.4, so technically should have occurred locally. Surprisingly, it worked in the locally because of another bug in the pq library in getting the Postgres server version which caused this check to consistently fail when running locally, preventing the data from being encoded into hex. This also explained the discrepancy in CI failures Postgres versions 9.6.5 (failed) and 10.0 (passed). Although this bug had been fixed for a while, we were still using the older version until a couple of days ago when we updated to the latest version from pq v1.2 to pq v1.10. Since the update, the issue happens both locally and in CI, as expected. We had not seen this issue previously because we don’t use the 'COPY' method elsewhere. |
The pq repo has an open issue for the same error when using COPY with jsonb. |
In #4908 we observed that inserting rows is much faster using the postgres
COPY
command. We can use this property to improve the performance of the ClaimableBalancesChangeProcessor . The ClaimableBalancesChangeProcessor upserts rows into theclaimable_balances
andclaimable_balance_claimants
tables.However, because claimable balances are either created or removed it turns out that we never have to modify existing rows of
claimable_balances
andclaimable_balance_claimants
. The create claimable balance operation creates a claimable balance and the claim operation removes the claimable balance from the ledger. There is no way to mutate a claimable balance once created.This means we can update the ClaimableBalancesChangeProcessor to use COPY to insert into the the
claimable_balances
andclaimable_balance_claimants
tables. We expect that to be faster than the current code which bulk inserts rows into theclaimable_balances
andclaimable_balance_claimants
tables.The text was updated successfully, but these errors were encountered: