Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1jLfhR-0003Wn-Mv for pgsql-hackers@arkaria.postgresql.org; Tue, 07 Apr 2020 04:18:57 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1jLfhQ-0006qn-IY for pgsql-hackers@arkaria.postgresql.org; Tue, 07 Apr 2020 04:18:56 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1jLfhQ-0006qg-48 for pgsql-hackers@lists.postgresql.org; Tue, 07 Apr 2020 04:18:56 +0000 Received: from mail-pf1-x441.google.com ([2607:f8b0:4864:20::441]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1jLfhN-0000g7-3q for pgsql-hackers@postgresql.org; Tue, 07 Apr 2020 04:18:55 +0000 Received: by mail-pf1-x441.google.com with SMTP id c20so205146pfi.7 for ; Mon, 06 Apr 2020 21:18:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=leadboat.com; s=google; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=u/17G68fZzbc3aDbYoRECFhLwi/pSliLAm89JKC8Y/g=; b=W5d6ql/3MFXUM1Q9nsqyAWzH0jLpjqjurdntZzHpoOuGmChRJXrze6/lJex+UuHzMn 9ykO+uEl1jcx/zJUca+4YrCJsHcDE2voYN6ROW2fyWx6ASsILjRfH2VGQLd1B8O4Syds 6phPTSCyM2MeRTqqNksv8+PNjoBsjpcWivKUs= 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:user-agent; bh=u/17G68fZzbc3aDbYoRECFhLwi/pSliLAm89JKC8Y/g=; b=cSMfInS+t5XTLC+PnSMdhDS0/zzJUw7LFNd4gItv5k2fq9hb6Q+5WLb/kdaeGMgMwL XOz1K3odhwRoJuulioAXDm7mROxpUFU3nr+ur7gqW+gBxO8eVFyHAY0b0i9iBtaTGlb3 DFh1AaCj9KQqnD1N3FdOpyXKdriswFQoQjAZGpG2cCtqmdaUs8LJu1UgW8FxvCYBLafX +nSQkvIX7jdWaFsHLaMRVoqld8znySNtjI9XC1rlR+DceKmXfrJ/53cVnNAqdoIXN6vl ESBmw/V+B1AjDaGPSlhMIYM1g+DgMcn6Irf8lU5qWFktdmvlv4AIsSOGmyM8MfhVEYCh VnsQ== X-Gm-Message-State: AGi0PubCwrPqpqx1Y6B5CmscfLNxB8bLCPDI1yyEq1YFosmRH/9WvqVz kr3OW2kzKxNfQkbQCPsf//RK9Q== X-Google-Smtp-Source: APiQypKnMAYFFxBbIWUXpXyRQfZo1ENtQpuHWRndzlmRp2i0ZDrBmRl9JA5+dY0SiDcSirZRoXiywQ== X-Received: by 2002:a63:180c:: with SMTP id y12mr182330pgl.104.1586233130931; Mon, 06 Apr 2020 21:18:50 -0700 (PDT) Received: from rfd.leadboat.com (108-233-125-46.lightspeed.sntcca.sbcglobal.net. [108.233.125.46]) by smtp.gmail.com with ESMTPSA id y3sm6193733pfy.6.2020.04.06.21.18.49 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 06 Apr 2020 21:18:49 -0700 (PDT) Date: Mon, 6 Apr 2020 21:18:47 -0700 From: Noah Misch To: Tom Lane Cc: Tomas Vondra , pgsql-hackers@postgresql.org Subject: Re: Spurious "apparent wraparound" via SimpleLruTruncate() rounding Message-ID: <20200407041847.GA519993@rfd.leadboat.com> References: <20190202083822.GC32531@gust.leadboat.com> <20190214072623.GA1139206@rfd.leadboat.com> <20200105003355.n2atv7thx7dqiqbt@development> <20200105011916.GC2270238@rfd.leadboat.com> <2271.1584655492@sss.pgh.pa.us> <20200322083452.GB1918808@rfd.leadboat.com> <13116.1585168951@sss.pgh.pa.us> <20200330052809.GB2324620@rfd.leadboat.com> <1959.1586198769@sss.pgh.pa.us> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1959.1586198769@sss.pgh.pa.us> User-Agent: Mutt/1.5.24 (2015-08-30) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On Mon, Apr 06, 2020 at 02:46:09PM -0400, Tom Lane wrote: > Noah Misch writes: > > On Wed, Mar 25, 2020 at 04:42:31PM -0400, Tom Lane wrote: > >> So I think what we're actually trying to accomplish here is to > >> ensure that instead of deleting up to half of the SLRU space > >> before the cutoff, we delete up to half-less-one-segment. > >> Maybe it should be half-less-two-segments, just to provide some > >> cushion against edge cases. Reading the first comment in > >> SetTransactionIdLimit makes one not want to trust too much in > >> arguments based on the exact value of xidWrapLimit, while for > >> the other SLRUs it was already unclear whether the edge cases > >> were exactly right. > > > That could be interesting insurance. While it would be sad for us to miss an > > edge case and print "must be vacuumed within 2 transactions" when wrap has > > already happened, reaching that message implies the DBA burned ~1M XIDs, all > > in single-user mode. More plausible is FreezeMultiXactId() overrunning the > > limit by tens of segments. Hence, if we do buy this insurance, let's skip far > > more segments. For example, instead of unlinking segments representing up to > > 2^31 past XIDs, we could divide that into an upper half that we unlink and a > > lower half. The lower half will stay in place; eventually, XID consumption > > will overwrite it. Truncation behavior won't change until the region of CLOG > > for pre-oldestXact XIDs exceeds 256 MiB. Beyond that threshold, > > vac_truncate_clog() will unlink the upper 256 MiB and leave the rest. CLOG > > maximum would rise from 512 MiB to 768 MiB. Would that be worthwhile? > > Hmm. I'm not particularly concerned about the disk-space-consumption > angle, but I do wonder about whether we'd be sacrificing the ability to > recover cleanly from a situation that the code does let you get into. > However, as long as we're sure that the system will ultimately reuse/ > recycle a not-deleted old segment file without complaint, it's hard to > find much fault with your proposal. That is the trade-off. By distancing ourselves from the wraparound edge cases, we'll get more segment recycling (heretofore an edge case). Fortunately, recycling doesn't change behavior as you approach some limit; it works or it doesn't. > Temporarily wasting some disk > space is a lot more palatable than corrupting data, and these code > paths are necessarily not terribly well tested. So +1 for more > insurance. Okay, I'll give that a try. I expect this will replace the PagePrecedes callback with a PageDiff callback such that PageDiff(a, b) < 0 iff PagePrecedes(a, b). PageDiff callbacks shall distribute return values uniformly in [INT_MIN,INT_MAX]. SimpleLruTruncate() will unlink segments where INT_MIN/2 < PageDiff(candidate, cutoff) < 0.