From f016475f1dd4f27b132a4f56db60674de928da83 Mon Sep 17 00:00:00 2001 From: Luke Imhoff Date: Mon, 7 Jan 2019 13:08:16 -0600 Subject: [PATCH] Order derive_tranactions_forks SELECT to match transaction inserts Fixes #1311 Prevent deadlocks due to order in the `SELECT transaction` for `Explorer.Chain.Import.Runner.Blocks.derived_transaction_forks` differing from order in `Explorer.Chain.Import.Runner.Transactions.insert` by sorting both by hash ascending. --- apps/explorer/lib/explorer/chain/import/runner/blocks.ex | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/apps/explorer/lib/explorer/chain/import/runner/blocks.ex b/apps/explorer/lib/explorer/chain/import/runner/blocks.ex index 0412324a8f..9371571532 100644 --- a/apps/explorer/lib/explorer/chain/import/runner/blocks.ex +++ b/apps/explorer/lib/explorer/chain/import/runner/blocks.ex @@ -129,7 +129,10 @@ defmodule Explorer.Chain.Import.Runner.Blocks do transaction.hash, type(^inserted_at, transaction.inserted_at), type(^updated_at, transaction.updated_at) - ] + ], + # order so that row ShareLocks are grabbed in a consistent order with + # `Explorer.Chain.Import.Runner.Transactions.insert` + order_by: transaction.hash ) {select_sql, parameters} = SQL.to_sql(:all, repo, query)