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

Get rid of deadlock in the query to address_current_token_balance table #2933

Conversation

vbaranov
Copy link
Member

@vbaranov vbaranov commented Dec 27, 2019

Motivation

Deadlock detected:

blocked_pid | blocked_user | blocking_pid | blocking_user |
19697 | poa          |         2809 | poa           | SELECT t0."name", t0."symbol", t0."total_supply", t0."decimals", t0."type", t0."cataloged", t0."holder_count", t0."contract_address_hash", t0."inserted_at", t0."updated_at" FROM "tokens" AS t0 WHERE (t0."contract_address_hash" = ANY($1)) ORDER BY t0."contract_address_hash" FOR UPDATE
2809 | poa          |        19697 | poa           | SELECT t0."name", t0."symbol", t0."total_supply", t0."decimals", t0."type", t0."cataloged", t0."holder_count", t0."contract_address_hash", t0."inserted_at", t0."updated_at" FROM "tokens" AS t0 WHERE (t0."contract_address_hash" = ANY($1)) ORDER BY t0."contract_address_hash" FOR UPDATE

This PR should speed up the import of blocks

Changelog

Add a distinct clause in a selection of contract_address_hash from address_current_token_balance table

Otherwise, duplicated contract_address_hashes cause deadlocks in the next series of queries:
SELECT t0.* FROM "tokens" AS t0 WHERE (t0."contract_address_hash" = ANY($1)) ORDER BY t0."contract_address_hash" FOR UPDATE

Checklist for your Pull Request (PR)

@vbaranov vbaranov force-pushed the vb-get-rid-of-deadlock-in-query-to-address_current_token_balance branch from 4191989 to 4e2b629 Compare December 27, 2019 11:58
@vbaranov vbaranov self-assigned this Dec 27, 2019
@vbaranov vbaranov added the ready for review This PR is ready for reviews. label Dec 27, 2019
@coveralls
Copy link

coveralls commented Dec 27, 2019

Pull Request Test Coverage Report for Build abe1ae93-3428-4e87-9735-9130dccef547

  • 0 of 0 changed or added relevant lines in 0 files are covered.
  • 2 unchanged lines in 1 file lost coverage.
  • Overall coverage decreased (-0.01%) to 75.229%

Files with Coverage Reduction New Missed Lines %
apps/block_scout_web/lib/block_scout_web/controllers/chain/market_history_chart_controller.ex 2 71.43%
Totals Coverage Status
Change from base Build 903a5cce-cc23-4282-8868-a2a7df32f12a: -0.01%
Covered Lines: 5333
Relevant Lines: 7089

💛 - Coveralls

@vbaranov vbaranov merged commit c640855 into master Dec 31, 2019
@vbaranov vbaranov deleted the vb-get-rid-of-deadlock-in-query-to-address_current_token_balance branch December 31, 2019 12:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ready for review This PR is ready for reviews.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants