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 1iWJ8n-0000il-Rv for pgsql-hackers@arkaria.postgresql.org; Sun, 17 Nov 2019 11:54:54 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1iWJ8m-0005ox-KR for pgsql-hackers@arkaria.postgresql.org; Sun, 17 Nov 2019 11:54:52 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from <9erthalion6@gmail.com>) id 1iWJ8m-0005ok-9S for pgsql-hackers@lists.postgresql.org; Sun, 17 Nov 2019 11:54:52 +0000 Received: from mail-ed1-x541.google.com ([2a00:1450:4864:20::541]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from <9erthalion6@gmail.com>) id 1iWJ8k-0001Jq-0Q for pgsql-hackers@postgresql.org; Sun, 17 Nov 2019 11:54:51 +0000 Received: by mail-ed1-x541.google.com with SMTP id t11so5210238eds.13 for ; Sun, 17 Nov 2019 03:54:49 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=BTL8J2ZvrjaE/8eGaNXhwNCU2tSHDE6wUnCvMvLiJro=; b=T3R6mXHohxLRhzuIJfvUjl0SVQWgy/XAfEmXt3SgZDWM2TS9dU9/o1SF+tQ7LFf1QF dF2iOyU3hRK6ffuAPF95ZZDDc9EsYwJg0cBsVVOViW/DS0CAUp0GX67Hp3RFw6pOTqe1 YSbcLw3SIGt6MaVDuKhMVgYx+4NWw7qThebn4iRv3Rig9hkXMmk2In3Q1EbgTTXfwp7z dXj/xqxCe59eNH27n2/EmO0VgRk4okZzuFr1aCJ63xts2FTI8lOwxG+imsDY6rZWCyhw C0WFNHFdjUSmwtUcYxK0tSpCG5f41oJBkQmTSfyYojCoYYruSN14axbty5/D38koBrOz tpYg== 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:references :mime-version:content-disposition:in-reply-to; bh=BTL8J2ZvrjaE/8eGaNXhwNCU2tSHDE6wUnCvMvLiJro=; b=LihgxjROOSLcH5jPIhQj0A20MT1kGKEftY3LX6MqKZLIYuO6+VB2cXL4bvVxEVzbDW Jo7ROT2iiCR/QjurAhORFarduHlrQCI3c2z/WvnNpi6OGPf0EJVmZPQopFWvmM+H5Ul9 BPEKBzqQx3tT5R29izRcv+Rh31ACQ8I8+jwHDmS1BkWPj665a9RFsdTtNlTvHmlEIFKt ZfC7+Bp2NAzQmoOoN8njDTcUAumZR2p3bbbdsV6ZhKxGxqzN0yX4z2qmcVkgTU1m/YVV Y3Fm2uGz1014F10zRQ6+GVw2OCLitcGH8UQAgdFRSRBZ94MIgCwALyGCGnIrXbeTOGyp NjkA== X-Gm-Message-State: APjAAAW+EKrMncsRfDui3IOPArVw3fgTZHK8+qz10Gn/QlYXFqcx6GKF 0Quz/PbwfYXFKwhDknxIEtX1tIFDX54= X-Google-Smtp-Source: APXvYqysI6U6wITCIweBqtAaz+WZURiYoLSJ7PaAJHMK23ExfF09WG/xPpCaFmP/1liVUbWL7auziQ== X-Received: by 2002:a17:906:80d5:: with SMTP id a21mr17624096ejx.114.1573991688907; Sun, 17 Nov 2019 03:54:48 -0800 (PST) Received: from localhost (dslb-188-103-189-084.188.103.pools.vodafone-ip.de. [188.103.189.84]) by smtp.gmail.com with ESMTPSA id p4sm847483edb.67.2019.11.17.03.54.47 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 17 Nov 2019 03:54:47 -0800 (PST) Date: Sun, 17 Nov 2019 12:56:52 +0100 From: Dmitry Dolgov <9erthalion6@gmail.com> To: Noah Misch Cc: Tom Lane , pgsql-hackers@postgresql.org Subject: Re: SimpleLruTruncate() mutual exclusion Message-ID: <20191117115652.doqc77yu7kbrqwmk@localhost> References: <20190218073103.GA1434723@rfd.leadboat.com> <20190628170628.GA1238361@rfd.leadboat.com> <29566.1564419497@sss.pgh.pa.us> <20190801065117.GA2355684@rfd.leadboat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20190801065117.GA2355684@rfd.leadboat.com> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk > On Wed, Jul 31, 2019 at 11:51:17PM -0700, Noah Misch wrote: Hi, > > Also, if I understand the data-loss hazard properly, it's what you > > said in the other thread: the latest_page_number could advance after > > we make our decision about what to truncate, and then maybe we could > > truncate newly-added data. We surely don't want to lock out the > > operations that can advance last_page_number, so how does serializing > > vac_truncate_clog help? > > > > I wonder whether what we need to do is add some state in shared > > memory saying "it is only safe to create pages before here", and > > make SimpleLruZeroPage or its callers check that. The truncation > > logic would advance that value, but only after completing a scan. > > (Oh ..., hmm, maybe the point of serializing truncations is to > > ensure that we know that we can safely advance that?) > > vac_truncate_clog() already records "it is only safe to create pages before > here" in ShmemVariableCache->xidWrapLimit, which it updates after any unlinks. > The trouble comes when two vac_truncate_clog() run in parallel and you get a > sequence of events like this: > > vac_truncate_clog() instance 1 starts, considers segment ABCD eligible to unlink > vac_truncate_clog() instance 2 starts, considers segment ABCD eligible to unlink > vac_truncate_clog() instance 1 unlinks segment ABCD > vac_truncate_clog() instance 1 calls SetTransactionIdLimit() > vac_truncate_clog() instance 1 finishes > some backend calls SimpleLruZeroPage(), creating segment ABCD > vac_truncate_clog() instance 2 unlinks segment ABCD > > Serializing vac_truncate_clog() fixes that. I'm probably missing something, so just wanted to clarify. Do I understand correctly, that thread [1] and this one are independent, and it is assumed in the scenario above that we're at the end of XID space, but not necessarily having rounding issues? I'm a bit confused, since the reproduce script does something about cutoffPage, and I'm not sure if it's important or not. > > Can you post whatever script you used to detect/reproduce the problem > > in the first place? > > I've attached it, but it's pretty hackish. Apply the patch on commit 7170268, > make sure your --bindir is in $PATH, copy "conf-test-pg" to your home > directory, and run "make trunc-check". This incorporates xid-burn > acceleration code that Jeff Janes shared with -hackers at some point. I've tried to use it to understand the problem better, but somehow couldn't reproduce via suggested script. I've applied it to 7170268 (tried also apply rebased to the master with the same results) with the conf-test-pg in place, but after going through all steps there are no errors like: ERROR: could not access status of transaction 2149484247 DETAIL: Could not open file "pg_xact/0801": No such file or directory. Is there anything extra one needs to do to reproduce the problem, maybe adjust delays or something? [1]: https://www.postgresql.org/message-id/flat/20190202083822.GC32531%40gust.leadboat.com