Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1hdGwU-00035d-9l for pgsql-hackers@arkaria.postgresql.org; Tue, 18 Jun 2019 16:26:42 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1hdGwT-0006Hg-2S for pgsql-hackers@arkaria.postgresql.org; Tue, 18 Jun 2019 16:26:41 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1hdGwS-0006Dz-MY for pgsql-hackers@lists.postgresql.org; Tue, 18 Jun 2019 16:26:40 +0000 Received: from mail-qk1-x742.google.com ([2607:f8b0:4864:20::742]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1hdGwQ-0005ar-6Y for pgsql-hackers@lists.postgresql.org; Tue, 18 Jun 2019 16:26:39 +0000 Received: by mail-qk1-x742.google.com with SMTP id p144so8931765qke.11 for ; Tue, 18 Jun 2019 09:26:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=2ndquadrant-com.20150623.gappssmtp.com; s=20150623; h=date:from:to:cc:subject:message-id:mime-version:content-disposition :content-transfer-encoding:in-reply-to:user-agent; bh=v+7VyF8btVwdWmf/TvMLmJ4TgwcmI9Vg/Phfr9en2Rc=; b=ghVMXLHcHbeMFvkzxxTzcYy9pR71Y7uQYGN6WBG3oUOTtmXkOiD75xfQcWtLCJSrbx VwLdHm+Ge/LC+mF08vtDgno4Qg0Ka5x28/RvePrvl+oTeTlGDfuo6o6NtkLvQ3/PUDYB RpAL8879edph8LiTpVzkj6OPnosUDmxfkYTvHEZtG2WJMvFcsWKaKGqPZoku7X+KAZH6 yJ1P3863QNLQOZGzLEm9wziba//+PVXaf/npRgid7z9RZJZojUHNCJkJJNgzKo3ujaNy J/y2Ah840ajM0rc9W0sldTMVlpDMSYlk/ojuGVTHK+rbHGPUZmIqywkZghgeWiLkcHyY +p9w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:mime-version :content-disposition:content-transfer-encoding:in-reply-to :user-agent; bh=v+7VyF8btVwdWmf/TvMLmJ4TgwcmI9Vg/Phfr9en2Rc=; b=ClZFHP7winw+pBRpikkIqe/Xa0Y/MJxH2tUL+GuOIMS94DqIrDYIyydRKdEE6ITOjF liQ085e0lmGpAcRtcE45IVkMOw2jKfcg1SYZYMmaTeaFb8CoP2JKoQN3b4ZAW3iG/CmH Ay+booDfkZbsrcopi/3UVWC4xUnCI1nZ0dGGH0tpWkxY4wKZiWZSwfnnTpctAfPCFCtQ bnwwBNx8eldP8XXxbHQ/b3N4oxAf2wzfcVO6o4JNMplW5lAg2s4xgPd79UCG62Rsw8Sf CdICtQXtrC7QBD/qj4YO0wXrmf3tA9UFw9Xjm2tb1rdoP92Pf74EU2ZYzp7fwZYBycrH vdaw== X-Gm-Message-State: APjAAAX4Jy7gK1kPCur9fgp7DkseCy3fIjtAZTl+ZMHB3P2QQ5xPoOHP m28UG0qH+umGWn9knOBmpM4pzQ== X-Google-Smtp-Source: APXvYqxsiO3JAjWd30js/XSpGL+c9HI9e8JDnV3HM1Ybf4ZnuvcgttgmpJB2mW9PAWrrQ7tYDkHkqQ== X-Received: by 2002:a37:4cd2:: with SMTP id z201mr48145500qka.284.1560875197201; Tue, 18 Jun 2019 09:26:37 -0700 (PDT) Received: from nimloth.alvh.no-ip.org ([190.217.181.124]) by smtp.gmail.com with ESMTPSA id n18sm4253233qtr.28.2019.06.18.09.26.35 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Tue, 18 Jun 2019 09:26:36 -0700 (PDT) Received: by nimloth.alvh.no-ip.org (Postfix, from userid 1000) id ADB5112076F; Tue, 18 Jun 2019 12:26:32 -0400 (-04) Date: Tue, 18 Jun 2019 12:26:32 -0400 From: Alvaro Herrera To: Oleksii Kliukin Cc: Tom Lane , pgsql-hackers@lists.postgresql.org Subject: Re: pgsql: Avoid spurious deadlocks when upgrading a tuple lock Message-ID: <20190618162632.GA9141@alvherre.pgsql> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <20190616190441.GA30993@alvherre.pgsql> User-Agent: Mutt/1.9.4 (2018-02-28) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On 2019-Jun-16, Alvaro Herrera wrote: > So, I'm too lazy today to generate a case that fully reproduces the > deadlock, because you need to stall 's2' a little bit using the > well-known advisory lock trick, but this one hits the code that would > re-initialize the variable. Here's such a case. I was unable to reproduce the condition with a smaller sequence of commands. This one does hit the deadlock when used with the previous code, as expected; with the fixed code (ie. skip_tuple_lock in the outer scope and same lifetime as "first_time") then it works fine, no deadlock. I'm going to push the fixed commit this afternoon, including this as an additional permutation in the spec file. setup { drop table if exists tlu_job; create table tlu_job (id integer primary key, name text); insert into tlu_job values(1, 'a'); } teardown { drop table tlu_job; } session "s0" setup { begin; } step "s0_keyshare" { select id from tlu_job where id = 1 for key share; } step "s0_share" { select id from tlu_job where id = 1 for share; } step "s0_rollback" { rollback; } session "s1" setup { begin; } step "s1_keyshare" { select id from tlu_job where id = 1 for key share; } step "s1_savept_e" { savepoint s1_e; } step "s1_share" { select id from tlu_job where id = 1 for share; } step "s1_savept_f" { savepoint s1_f; } step "s1_fornokeyupd" { select id from tlu_job where id = 1 for no key update; } step "s1_rollback_f" { rollback to s1_f; } step "s1_rollback_e" { rollback to s1_e; } step "s1_rollback" { rollback; } session "s2" setup { begin; } step "s2_keyshare" { select id from tlu_job where id = 1 for key share; } step "s2_fornokeyupd" { select id from tlu_job where id = 1 for no key update; } step "s2_rollback" { rollback; } session "s3" setup { begin; } step "s3_for_update" { select id from tlu_job where id = 1 for update; } step "s3_rollback" { rollback; } permutation "s1_keyshare" "s3_for_update" "s2_keyshare" "s1_savept_e" "s1_share" "s1_savept_f" "s1_fornokeyupd" "s2_fornokeyupd" "s0_keyshare" "s1_rollback_f" "s0_share" "s1_rollback_e" "s1_rollback" "s2_rollback" "s0_rollback" "s3_rollback" -- Álvaro Herrera https://www.2ndQuadrant.com/ PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services