From: Daniel Shelepanov <deniel1495@mail.ru>
To: pgsql-hackers@lists.postgresql.org
Subject: collect_corrupt_items_vacuum.patch
Date: Mon, 04 Apr 2022 11:51:10 +0300
Message-ID: <1649062270.289865713@f403.i.mail.ru> (raw)
Hi hackers!
I’ve been working on this [ https://www.postgresql.org/message-id/flat/cfcca574-6967-c5ab-7dc3-2c82b6723b99%40mail.ru ] bug. Finally, I’ve come up with the patch you can find attached. Basically what is does is rises a PROC_IN_VACUUM flag and resets it afterwards. I know this seems kinda crunchy and I hope you guys will give me some hints on where to continue. This [ https://www.postgresql.org/message-id/20220218175119.7hwv7ksamfjwijbx%40alap3.anarazel.de ] message contains reproduction script. Thank you very much in advance.
Kind regards,
Daniel Shelepanov
Attachments:collect_corrupt_items_vacuum.patch (text/x-diff, 1.4K) downloaddiff --git a/contrib/pg_visibility/pg_visibility.c b/contrib/pg_visibility/pg_visibility.cindex 53aaf61cb94..700ebeaa018 100644--- a/contrib/pg_visibility/pg_visibility.c+++ b/contrib/pg_visibility/pg_visibility.c@@ -18,6 +18,7 @@
#include "funcapi.h"
#include "miscadmin.h"
#include "storage/bufmgr.h"
+#include "storage/proc.h"
#include "storage/procarray.h"
#include "storage/smgr.h"
#include "utils/rel.h"
@@ -562,12 +563,19 @@ collect_corrupt_items(Oid relid, bool all_visible, bool all_frozen)
Buffer vmbuffer = InvalidBuffer;
BufferAccessStrategy bstrategy = GetAccessStrategy(BAS_BULKREAD);
TransactionId OldestXmin = InvalidTransactionId;
+ uint8 oldStatusFlags;
rel = relation_open(relid, AccessShareLock);
/* Only some relkinds have a visibility map */
check_relation_relkind(rel);
+ LWLockAcquire(ProcArrayLock, LW_EXCLUSIVE);+ oldStatusFlags = MyProc->statusFlags;+ MyProc->statusFlags |= PROC_IN_VACUUM;+ ProcGlobal->statusFlags[MyProc->pgxactoff] = MyProc->statusFlags;+ LWLockRelease(ProcArrayLock);+
if (all_visible)
OldestXmin = GetOldestNonRemovableTransactionId(rel);
@@ -722,6 +730,11 @@ collect_corrupt_items(Oid relid, bool all_visible, bool all_frozen)
items->count = items->next;
items->next = 0;
+ LWLockAcquire(ProcArrayLock, LW_EXCLUSIVE);+ MyProc->statusFlags = oldStatusFlags;+ ProcGlobal->statusFlags[MyProc->pgxactoff] = MyProc->statusFlags;+ LWLockRelease(ProcArrayLock);+
return items;
}
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: pgsql-hackers@postgresql.org
Cc: deniel1495@mail.ru, pgsql-hackers@lists.postgresql.org
Subject: Re: collect_corrupt_items_vacuum.patch
In-Reply-To: <1649062270.289865713@f403.i.mail.ru>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox