Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1eMcRo-0001mb-OP for pgsql-hackers@arkaria.postgresql.org; Wed, 06 Dec 2017 16:21:24 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1eMcRo-0004ok-BF for pgsql-hackers@arkaria.postgresql.org; Wed, 06 Dec 2017 16:21:24 +0000 Received: from makus.postgresql.org ([2001:4800:1501:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1eMcRo-0004oY-1a for pgsql-hackers@lists.postgresql.org; Wed, 06 Dec 2017 16:21:24 +0000 Received: from mail-qt0-x229.google.com ([2607:f8b0:400d:c0d::229]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1eMcRk-00023p-07 for pgsql-hackers@postgresql.org; Wed, 06 Dec 2017 16:21:22 +0000 Received: by mail-qt0-x229.google.com with SMTP id k19so10199450qtj.6 for ; Wed, 06 Dec 2017 08:21:19 -0800 (PST) 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=r7s7/0LpwzwRAPMDyPb31n4oaHd/mYN43cy/zBg/iXg=; b=q7tlnVhyRTsyTg/nNU0DJxxLRW1ctxzH3VFFCUMAgiINKAe6K4s5tLtY3HAILQ1ew9 QWsMzy9aY7Kc6JAiGHhIxjAnjQJ13rR/NBIbLbUbEdQIS/D2+PsoSoUdA3hPCjSeNtJD XyTJj8gKdLg/S1qkErPY1wLHAmB3Q7FtcVZebJCPrJIH9KbLPF/v7GnZUhx/sire2TDe xfsT3l8kivXqmYRSzpCIFGVCw8ghmtujsFiG4/pBHFp3x4LdLQpvt/4lGeTeTO4cp//J jPOZ7RNbe+XvOBqIgT3VzL4ZnUvvHK0l6LLWXY2JeWCrEASMXBeeXM3PL0XB0zFewKNP rKjA== 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=r7s7/0LpwzwRAPMDyPb31n4oaHd/mYN43cy/zBg/iXg=; b=hvlpJzw8SE+TWOl0kLn/NFkpJtE1IBNAq+AIdnGPmoIFgE9CtSoeFwHQXY0wkU5kvy lyQDcrSWbrnbfZYegtn9Z8140sf/LLKfvfbc6MNw4WocqKerFUc6I+L3F0V9DS26+TFP ZOWsM3m7Pm/RV7EjCvMABfFthH5IgrVfnee8FyBEjHvRSfjoTbOWKbRPYUPUXsf3LgTz /ZI5nNHYDSLRX9fzLfdeq14GRflh4sm51XS78RyKXgfls/0+/u3hc/gO7w0INc0SM7g6 TuGjfb6WHe7j0oxfHy1WRqaIzIIZlAZvhpYYzyOfhLQd0dgjuBsoXVc6+D7G5MDhYa4c obeA== X-Gm-Message-State: AKGB3mJTAGn8Gr+YHyEK8DRJqy4sfR9xUIUfweVnFbyso7oAi860rLYZ n9gri8zfv1C/V9cvrL8fAy/ynQ== X-Google-Smtp-Source: AGs4zMYoHdD0R9lERGx6uIJlEjBUOucDb85mEeEnFRZpNmcuQBzD49gef+YfZeEulmKsj/RcP5et4A== X-Received: by 10.200.35.182 with SMTP id q51mr4732419qtq.302.1512577279023; Wed, 06 Dec 2017 08:21:19 -0800 (PST) Received: from alvin.alvh.no-ip.org ([179.57.113.18]) by smtp.gmail.com with ESMTPSA id i23sm1593436qke.88.2017.12.06.08.21.18 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 06 Dec 2017 08:21:18 -0800 (PST) Received: by alvin.alvh.no-ip.org (Postfix, from userid 1000) id 9FA5613E6; Wed, 6 Dec 2017 13:21:15 -0300 (-03) Date: Wed, 6 Dec 2017 13:21:15 -0300 From: Alvaro Herrera To: Andres Freund Cc: "Wood, Dan" , Peter Geoghegan , pgsql-committers@postgresql.org, "Wong, Yi Wen" , Michael Paquier , Robert Haas , Tom Lane , pgsql-hackers@postgresql.org Subject: Re: [HACKERS] [COMMITTERS] pgsql: Fix freezing of a dead HOT-updated tuple Message-ID: <20171206162115.kdsd2fnipyswonir@alvherre.pgsql> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="t7pbxnucgagomw23" Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <20171114030341.movhteyakqeqx5pm@alap3.anarazel.de> User-Agent: NeoMutt/20170306-137-4415bd-dirty (1.8.0) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk --t7pbxnucgagomw23 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit I think you've done a stellar job of identifying what the actual problem was. I like the new (simpler) coding of that portion of HeapTupleSatisfiesVacuum. freeze-the-dead is not listed in isolation_schedule; an easy fix. I confirm that the test crashes with an assertion failure without the code fix, and that it doesn't with it. I think the comparison to OldestXmin should be reversed: if (!TransactionIdPrecedes(xmax, OldestXmin)) return HEAPTUPLE_RECENTLY_DEAD; return HEAPTUPLE_DEAD; This way, an xmax that has exactly the OldestXmin value will return RECENTLY_DEAD rather DEAD, which seems reasonable to me (since OldestXmin value itself is supposed to be still possibly visible to somebody). Also, this way it is consistent with the other comparison to OldestXmin at the bottom of the function. There is no reason for the "else" or the extra braces. Put together, I propose the attached delta for 0001. Your commit message does a poor job of acknowledging prior work on diagnosing the problem starting from Dan's initial test case and patch. I haven't looked at your 0002 yet. -- Álvaro Herrera https://www.2ndQuadrant.com/ PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services --t7pbxnucgagomw23 Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="tweaks.patch" diff --git a/src/backend/utils/time/tqual.c b/src/backend/utils/time/tqual.c index 8be2980116..aab03835d1 100644 --- a/src/backend/utils/time/tqual.c +++ b/src/backend/utils/time/tqual.c @@ -1324,25 +1324,23 @@ HeapTupleSatisfiesVacuum(HeapTuple htup, TransactionId OldestXmin, else if (TransactionIdDidCommit(xmax)) { /* - * The multixact might still be running due to lockers. If the - * updater is below the horizon we have to return DEAD regardless - * - otherwise we could end up with a tuple where the updater has - * to be removed due to the horizon, but is not pruned away. It's - * not a problem to prune that tuple because all the lockers will - * also be present in the newer tuple version. + * The multixact might still be running due to lockers. If the + * updater is below the xid horizon, we have to return DEAD + * regardless -- otherwise we could end up with a tuple where the + * updater has to be removed due to the horizon, but is not pruned + * away. It's not a problem to prune that tuple, because any + * remaining lockers will also be present in newer tuple versions. */ - if (TransactionIdPrecedes(xmax, OldestXmin)) - { - return HEAPTUPLE_DEAD; - } - else + if (!TransactionIdPrecedes(xmax, OldestXmin)) return HEAPTUPLE_RECENTLY_DEAD; + + return HEAPTUPLE_DEAD; } else if (!MultiXactIdIsRunning(HeapTupleHeaderGetRawXmax(tuple), false)) { /* * Not in Progress, Not Committed, so either Aborted or crashed. - * Remove the Xmax. + * Mark the Xmax as invalid. */ SetHintBits(tuple, buffer, HEAP_XMAX_INVALID, InvalidTransactionId); } diff --git a/src/test/isolation/isolation_schedule b/src/test/isolation/isolation_schedule index e41b9164cd..eb566ebb6c 100644 --- a/src/test/isolation/isolation_schedule +++ b/src/test/isolation/isolation_schedule @@ -44,6 +44,7 @@ test: update-locked-tuple test: propagate-lock-delete test: tuplelock-conflict test: tuplelock-update +test: freeze-the-dead test: nowait test: nowait-2 test: nowait-3 --t7pbxnucgagomw23--