Change order for insertion to AddressTokenBalances

vb-test-deadlocks
Victor Baranov 4 years ago
parent 2ddc880a35
commit 5226426d56
  1. 2
      CHANGELOG.md
  2. 8
      apps/explorer/lib/explorer/chain/import/runner/blocks.ex
  3. 1
      apps/indexer/lib/indexer/token_balances.ex

@ -6,6 +6,7 @@
- [#3462](https://github.com/poanetwork/blockscout/pull/3462) - Display price for bridged tokens - [#3462](https://github.com/poanetwork/blockscout/pull/3462) - Display price for bridged tokens
### Fixes ### Fixes
- [#3433](https://github.com/poanetwork/blockscout/pull/3433) - Token balances and rewards tables deadlocks elimination
- [#3494](https://github.com/poanetwork/blockscout/pull/3494), [#3497](https://github.com/poanetwork/blockscout/pull/3497) - Contracts interaction: fix method call with array[] input - [#3494](https://github.com/poanetwork/blockscout/pull/3494), [#3497](https://github.com/poanetwork/blockscout/pull/3497) - Contracts interaction: fix method call with array[] input
- [#3494](https://github.com/poanetwork/blockscout/pull/3494), [#3495](https://github.com/poanetwork/blockscout/pull/3495) - Contracts interaction: fix tuple output display - [#3494](https://github.com/poanetwork/blockscout/pull/3494), [#3495](https://github.com/poanetwork/blockscout/pull/3495) - Contracts interaction: fix tuple output display
- [#3479](https://github.com/poanetwork/blockscout/pull/3479) - Fix working with big numbers in Staking DApp - [#3479](https://github.com/poanetwork/blockscout/pull/3479) - Fix working with big numbers in Staking DApp
@ -56,7 +57,6 @@
- [#3440](https://github.com/poanetwork/blockscout/pull/3440) - Rewrite missing blocks range query - [#3440](https://github.com/poanetwork/blockscout/pull/3440) - Rewrite missing blocks range query
- [#3439](https://github.com/poanetwork/blockscout/pull/3439) - Dark mode color fixes (search, charts) - [#3439](https://github.com/poanetwork/blockscout/pull/3439) - Dark mode color fixes (search, charts)
- [#3437](https://github.com/poanetwork/blockscout/pull/3437) - Fix Postgres Docker container - [#3437](https://github.com/poanetwork/blockscout/pull/3437) - Fix Postgres Docker container
- [#3433](https://github.com/poanetwork/blockscout/pull/3433) - Token balances and rewards tables deadlocks elimination
- [#3428](https://github.com/poanetwork/blockscout/pull/3428) - Fix address tokens search - [#3428](https://github.com/poanetwork/blockscout/pull/3428) - Fix address tokens search
- [#3424](https://github.com/poanetwork/blockscout/pull/3424) - Fix display of long NFT IDs - [#3424](https://github.com/poanetwork/blockscout/pull/3424) - Fix display of long NFT IDs
- [#3422](https://github.com/poanetwork/blockscout/pull/3422) - Fix contract reader: tuple type - [#3422](https://github.com/poanetwork/blockscout/pull/3422) - Fix contract reader: tuple type

@ -344,8 +344,8 @@ defmodule Explorer.Chain.Import.Runner.Blocks do
select: map(tb, [:address_hash, :token_contract_address_hash, :block_number]), select: map(tb, [:address_hash, :token_contract_address_hash, :block_number]),
# Enforce TokenBalance ShareLocks order (see docs: sharelocks.md) # Enforce TokenBalance ShareLocks order (see docs: sharelocks.md)
order_by: [ order_by: [
tb.address_hash,
tb.token_contract_address_hash, tb.token_contract_address_hash,
tb.address_hash,
tb.block_number tb.block_number
], ],
lock: "FOR UPDATE" lock: "FOR UPDATE"
@ -381,8 +381,8 @@ defmodule Explorer.Chain.Import.Runner.Blocks do
select: map(ctb, [:address_hash, :token_contract_address_hash]), select: map(ctb, [:address_hash, :token_contract_address_hash]),
# Enforce CurrentTokenBalance ShareLocks order (see docs: sharelocks.md) # Enforce CurrentTokenBalance ShareLocks order (see docs: sharelocks.md)
order_by: [ order_by: [
ctb.address_hash, ctb.token_contract_address_hash,
ctb.token_contract_address_hash ctb.address_hash
], ],
lock: "FOR UPDATE" lock: "FOR UPDATE"
) )
@ -467,7 +467,7 @@ defmodule Explorer.Chain.Import.Runner.Blocks do
new_current_token_balance_query new_current_token_balance_query
|> repo.all() |> repo.all()
# Enforce CurrentTokenBalance ShareLocks order (see docs: sharelocks.md) # Enforce CurrentTokenBalance ShareLocks order (see docs: sharelocks.md)
|> Enum.sort_by(&{&1.address_hash, &1.token_contract_address_hash}) |> Enum.sort_by(&{&1.token_contract_address_hash, &1.address_hash})
{_total, result} = {_total, result} =
repo.insert_all( repo.insert_all(

@ -57,6 +57,7 @@ defmodule Indexer.TokenBalances do
|> Enum.map(fn {_, grouped_address_token_balances} -> |> Enum.map(fn {_, grouped_address_token_balances} ->
Enum.max_by(grouped_address_token_balances, fn %{block_number: block_number} -> block_number end) Enum.max_by(grouped_address_token_balances, fn %{block_number: block_number} -> block_number end)
end) end)
|> Enum.sort_by(&{&1.token_contract_address_hash, &1.address_hash})
end end
defp set_token_balance_value({:ok, balance}, token_balance) do defp set_token_balance_value({:ok, balance}, token_balance) do

Loading…
Cancel
Save