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 1nLYqq-0000sv-KT for pgsql-hackers@arkaria.postgresql.org; Sat, 19 Feb 2022 23:09:16 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1nLYqp-0003Ly-B7 for pgsql-hackers@arkaria.postgresql.org; Sat, 19 Feb 2022 23:09:15 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1nLYqo-0003Lo-RP for pgsql-hackers@lists.postgresql.org; Sat, 19 Feb 2022 23:09:15 +0000 Received: from mail-pj1-x102b.google.com ([2607:f8b0:4864:20::102b]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1nLYqj-0003AP-AC for pgsql-hackers@lists.postgresql.org; Sat, 19 Feb 2022 23:09:13 +0000 Received: by mail-pj1-x102b.google.com with SMTP id m1-20020a17090a668100b001bc023c6f34so1628898pjj.3 for ; Sat, 19 Feb 2022 15:09:08 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bowt-ie.20210112.gappssmtp.com; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=YIkMOLqjMePWm8jW+0uFq0Gw9YFetipynDBIop/iB1U=; b=UKlXXovyAqgGI52vIDroaX3fpFf5BkF9MpOSbO0lDJzcudWjKZIc4JtT02Elw/tFJs ScAagq3ieFPZ+AKuw8+8bi4M497QlRdbD3csrHAM2d20flVkHWsTADigvKKBWOJMlC4T zzreskowDmPxTXMK//Z3dp53mAjLE/bUpEjEultNXy+uAlDJVoW3SFtGbMJQAa1LN54L 82gVsbg9q6p7Zc99Gu9TIsh9DTCi0shmuavrLPI9NK+HqdW8uQljbCSjb2o34X5Nmiv8 DGsKMrRO4csw+PFkbzU4TAPBljuy/AQ8keI00QZX5sBglAOEROfYxYaBAzSlivs4v2t6 kgGQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=YIkMOLqjMePWm8jW+0uFq0Gw9YFetipynDBIop/iB1U=; b=G2L85jSLiZMWME3Z0/IQA9LdeoG4dUlZNvbrDEcdpwMZ0pJdSFacjqVK03CBKYcVhL w66ziH+NKaanZNSGk7Jf1pDRwG1I5Or+AMQ8MBOP3IxT+t0q2swvNS5lPkg9zN29yfL5 5XX6ALRcPfCPuDgdpXQ4xxDDl3bgsoW2SLwH8okO+O64URD+RqU/0vty2S079ql3lGBe nSly92x6cBppK2+29QuQA9VnBR7AU7gdjGPKFBOxBgDCO3yI240pcZqRTc9UpnKapa7z 4Xcwv6h21IssD/RVQhQ/Ls3JugtYZchPkojsf7NkqDIl30QMsLBWSCSX4N2Wzgg9YuE8 nmtQ== X-Gm-Message-State: AOAM530dFkClNgFz2YS5CF7Et4p7xzG5DllVoefZ0N37v8hyHe8B5SKX F+hB27TKFhVxY25a/3/uY6j9JyHedawVrBcFcnnh6Q== X-Google-Smtp-Source: ABdhPJxNPeiD8ShmFgNQGAAlMCjQfqzCztB7m4a0S1XIikHnnKzRafHmjF4o3VMCnbB5x/IU2V287+WP3W0K9z9sLHk= X-Received: by 2002:a17:90a:2e8a:b0:1b9:a282:12d3 with SMTP id r10-20020a17090a2e8a00b001b9a28212d3mr14877271pjd.2.1645312147674; Sat, 19 Feb 2022 15:09:07 -0800 (PST) MIME-Version: 1.0 References: <20220218221117.ijozsjwaxa6fy5u6@alap3.anarazel.de> In-Reply-To: From: Peter Geoghegan Date: Sat, 19 Feb 2022 15:08:41 -0800 Message-ID: Subject: Re: Removing more vacuumlazy.c special cases, relfrozenxid optimizations To: Andres Freund Cc: Robert Haas , Masahiko Sawada , PostgreSQL Hackers Content-Type: multipart/mixed; boundary="0000000000001b8c1a05d86716a9" List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --0000000000001b8c1a05d86716a9 Content-Type: text/plain; charset="UTF-8" On Fri, Feb 18, 2022 at 5:00 PM Peter Geoghegan wrote: > Another testing strategy occurs to me: we could stress-test the > implementation by simulating an environment where the no-cleanup-lock > path is hit an unusually large number of times, possibly a fixed > percentage of the time (like 1%, 5%), say by making vacuumlazy.c's > ConditionalLockBufferForCleanup() call return false randomly. Now that > we have lazy_scan_noprune for the no-cleanup-lock path (which is as > similar to the regular lazy_scan_prune path as possible), I wouldn't > expect this ConditionalLockBufferForCleanup() testing gizmo to be too > disruptive. I tried this out, using the attached patch. It was quite interesting, even when run against HEAD. I think that I might have found a bug on HEAD, though I'm not really sure. If you modify the patch to simulate conditions under which ConditionalLockBufferForCleanup() fails about 2% of the time, you get much better coverage of lazy_scan_noprune/heap_tuple_needs_freeze, without it being so aggressive as to make "make check-world" fail -- which is exactly what I expected. If you are much more aggressive about it, and make it 50% instead (which you can get just by using the patch as written), then some tests will fail, mostly for reasons that aren't surprising or interesting (e.g. plan changes). This is also what I'd have guessed would happen. However, it gets more interesting. One thing that I did not expect to happen at all also happened (with the current 50% rate of simulated ConditionalLockBufferForCleanup() failure from the patch): if I run "make check" from the pg_surgery directory, then the Postgres backend gets stuck in an infinite loop inside lazy_scan_prune, which has been a symptom of several tricky bugs in the past year (not every time, but usually). Specifically, the VACUUM statement launched by the SQL command "vacuum freeze htab2;" from the file contrib/pg_surgery/sql/heap_surgery.sql, at line 54 leads to this misbehavior. This is a temp table, which is a choice made by the tests specifically because they need to "use a temp table so that vacuum behavior doesn't depend on global xmin". This is convenient way of avoiding spurious regression tests failures (e.g. from autoanalyze), and relies on the GlobalVisTempRels behavior established by Andres' 2020 bugfix commit 94bc27b5. It's quite possible that this is nothing more than a bug in my adversarial gizmo patch -- since I don't think that ConditionalLockBufferForCleanup() can ever fail with a temp buffer (though even that's not completely clear right now). Even if the behavior that I saw does not indicate a bug on HEAD, it still seems informative. At the very least, it wouldn't hurt to Assert() that the target table isn't a temp table inside lazy_scan_noprune, documenting our assumptions around temp tables and ConditionalLockBufferForCleanup(). I haven't actually tried to debug the issue just yet, so take all this with a grain of salt. -- Peter Geoghegan --0000000000001b8c1a05d86716a9 Content-Type: text/plain; charset="US-ASCII"; name="0001-Add-adversarial-ConditionalLockBufferForCleanup-gizm.txt" Content-Disposition: attachment; filename="0001-Add-adversarial-ConditionalLockBufferForCleanup-gizm.txt" Content-Transfer-Encoding: base64 Content-ID: X-Attachment-Id: f_kzugbj2e0 RnJvbSAzZjAxMjgxYWYzYmE4MWIzNTc3N2NiN2Q3MTdmNzZlMDAxZmQzZTEwIE1vbiBTZXAgMTcg MDA6MDA6MDAgMjAwMQpGcm9tOiBQZXRlciBHZW9naGVnYW4gPHBnQGJvd3QuaWU+CkRhdGU6IFNh dCwgMTkgRmViIDIwMjIgMTQ6MDc6MzUgLTA4MDAKU3ViamVjdDogW1BBVENIXSBBZGQgYWR2ZXJz YXJpYWwgQ29uZGl0aW9uYWxMb2NrQnVmZmVyRm9yQ2xlYW51cCgpIGdpem1vIHRvCiB2YWN1dW1s YXp5LmMuCgotLS0KIHNyYy9iYWNrZW5kL2FjY2Vzcy9oZWFwL3ZhY3V1bWxhenkuYyB8IDM2ICsr KysrKysrKysrKysrKysrKysrKysrKysrKy0KIDEgZmlsZSBjaGFuZ2VkLCAzNSBpbnNlcnRpb25z KCspLCAxIGRlbGV0aW9uKC0pCgpkaWZmIC0tZ2l0IGEvc3JjL2JhY2tlbmQvYWNjZXNzL2hlYXAv dmFjdXVtbGF6eS5jIGIvc3JjL2JhY2tlbmQvYWNjZXNzL2hlYXAvdmFjdXVtbGF6eS5jCmluZGV4 IDI0MjUxMWEyMy4uMzFjNmIzNjBlIDEwMDY0NAotLS0gYS9z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