summaryrefslogtreecommitdiff
path: root/src/test/modules/injection_points/regress_injection.c
diff options
context:
space:
mode:
authorNoah Misch <noah@leadboat.com>2025-04-09 07:23:39 -0700
committerNoah Misch <noah@leadboat.com>2025-04-09 07:23:43 -0700
commit42bb4fb7281ec4881c8a9bac14e1ea7206d0e63d (patch)
tree70311128ef029395a8cbc8fda1b4e4589e591d9a /src/test/modules/injection_points/regress_injection.c
parent17a165d60f734b3aa2e495d890f0c4b8324ca629 (diff)
Fix test races between syscache-update-pruned.spec and autovacuum.
This spec fails ~3% of my Valgrind runs, and the spec has failed on Valgrind buildfarm member skink at a similar rate. Two problems contributed to that: - A competing buffer pin triggered VACUUM's lazy_scan_noprune() path, causing "tuples missed: 1 dead from 1 pages not removed due to cleanup lock contention". FREEZE fixes that. - The spec ran lazy VACUUM immediately after VACUUM FULL. The spec implicitly assumed lazy VACUUM prunes the one tuple that VACUUM FULL made dead. First wait for old snapshots, making that assumption reliable. This also adds two forms of defense in depth: - Wait for snapshots using shared catalog pruning rules (VISHORIZON_SHARED). This avoids the removable cutoff moving backward when an XID-bearing autoanalyze process runs in another database. That may never happen in this test, but it's cheap insurance. - Use lazy VACUUM option DISABLE_PAGE_SKIPPING. Commit c2dc1a79767a0f947e1145f82eb65dfe4360d25f did this for a related requirement in other tests, but I suspect FREEZE is necessary and sufficient in all these tests. Back-patch to v17, where the test first appeared. Reported-by: Andres Freund <andres@anarazel.de> Discussion: https://postgr.es/m/sv3taq4e6ea4qckimien3nxp3sz4b6cw6sfcy4nhwl52zpur4g@h6i6tohxmizu Backpatch-through: 17
Diffstat (limited to 'src/test/modules/injection_points/regress_injection.c')
-rw-r--r--src/test/modules/injection_points/regress_injection.c17
1 files changed, 12 insertions, 5 deletions
diff --git a/src/test/modules/injection_points/regress_injection.c b/src/test/modules/injection_points/regress_injection.c
index 422f4168935..7bba1c97d0f 100644
--- a/src/test/modules/injection_points/regress_injection.c
+++ b/src/test/modules/injection_points/regress_injection.c
@@ -17,7 +17,9 @@
#include "access/table.h"
#include "fmgr.h"
#include "miscadmin.h"
+#include "postmaster/autovacuum.h"
#include "storage/procarray.h"
+#include "utils/rel.h"
#include "utils/xid8.h"
/*
@@ -28,11 +30,12 @@
* that. For the causes of backward movement, see
* postgr.es/m/CAEze2Wj%2BV0kTx86xB_YbyaqTr5hnE_igdWAwuhSyjXBYscf5-Q%40mail.gmail.com
* and the header comment for ComputeXidHorizons(). One can assume this
- * doesn't move backward if one arranges for concurrent activity not to reach
- * AbortTransaction() and not to allocate an XID while connected to another
- * database. Non-runningcheck tests can control most concurrent activity,
- * except autovacuum and the isolationtester control connection. Neither
- * allocates XIDs, and AbortTransaction() in those would justify test failure.
+ * doesn't move backward if one (a) passes a shared catalog as the argument
+ * and (b) arranges for concurrent activity not to reach AbortTransaction().
+ * Non-runningcheck tests can control most concurrent activity, except
+ * autovacuum and the isolationtester control connection. AbortTransaction()
+ * in those would justify test failure. Seeing autoanalyze can allocate an
+ * XID in any database, (a) ensures we'll consistently not ignore those XIDs.
*/
PG_FUNCTION_INFO_V1(removable_cutoff);
Datum
@@ -47,6 +50,10 @@ removable_cutoff(PG_FUNCTION_ARGS)
if (!PG_ARGISNULL(0))
rel = table_open(PG_GETARG_OID(0), AccessShareLock);
+ if (!rel->rd_rel->relisshared && autovacuum_start_daemon)
+ elog(WARNING,
+ "removable_cutoff(non-shared-rel) can move backward under autovacuum=on");
+
/*
* No lock or snapshot necessarily prevents oldestXid from advancing past
* "xid" while this function runs. That concerns us only in that we must