agora inbox for pgsql-hackers@postgresql.org  
help / color / mirror / Atom feed
[PATCH v1 2/3] Give developer a helpful kick in the pants if they change natts in one place but not another
4+ messages / 2 participants
[nested] [flat]

* [PATCH v1 2/3] Give developer a helpful kick in the pants if they change natts in one place but not another
@ 2020-02-07 14:12  Justin Pryzby <pryzbyj@telsasoft.com>
  0 siblings, 0 replies; 4+ messages in thread

From: Justin Pryzby @ 2020-02-07 14:12 UTC (permalink / raw)

---
 src/backend/bootstrap/bootstrap.c | 23 +++++++++++++++++++++++
 1 file changed, 23 insertions(+)

diff --git a/src/backend/bootstrap/bootstrap.c b/src/backend/bootstrap/bootstrap.c
index bfc629c..d5e1888 100644
--- a/src/backend/bootstrap/bootstrap.c
+++ b/src/backend/bootstrap/bootstrap.c
@@ -25,7 +25,9 @@
 #include "access/xlog_internal.h"
 #include "bootstrap/bootstrap.h"
 #include "catalog/index.h"
+#include "catalog/pg_class.h"
 #include "catalog/pg_collation.h"
+#include "catalog/pg_proc.h"
 #include "catalog/pg_type.h"
 #include "common/link-canary.h"
 #include "libpq/pqsignal.h"
@@ -49,6 +51,7 @@
 #include "utils/ps_status.h"
 #include "utils/rel.h"
 #include "utils/relmapper.h"
+#include "utils/syscache.h"
 
 uint32		bootstrap_data_checksum_version = 0;	/* No checksum */
 
@@ -602,6 +605,26 @@ boot_openrel(char *relname)
 	TableScanDesc scan;
 	HeapTuple	tup;
 
+	/* Check that pg_class data is consistent now, rather than failing obscurely later */
+	struct { Oid oid; int natts; }
+		checknatts[] = {
+		{RelationRelationId, Natts_pg_class,},
+		{TypeRelationId, Natts_pg_type,},
+		{AttributeRelationId, Natts_pg_attribute,},
+		{ProcedureRelationId, Natts_pg_proc,},
+	};
+
+	for (int i=0; i<lengthof(checknatts); ++i) {
+		Form_pg_class	classForm;
+		HeapTuple	tuple;
+		tuple = SearchSysCache1(RELOID, ObjectIdGetDatum(checknatts[i].oid));
+		if (!HeapTupleIsValid(tuple))
+			elog(ERROR, "cache lookup failed for relation %u", checknatts[i].oid);
+		classForm = (Form_pg_class) GETSTRUCT(tuple);
+		Assert(checknatts[i].natts == classForm->relnatts);
+		ReleaseSysCache(tuple);
+	}
+
 	if (strlen(relname) >= NAMEDATALEN)
 		relname[NAMEDATALEN - 1] = '\0';
 
-- 
2.7.4


--uc35eWnScqDcQrv5
Content-Type: text/x-diff; charset=us-ascii
Content-Disposition: attachment;
 filename="v1-0003-Make-cluster-a-property-of-table-in-pg_index.patch"



^ permalink  raw  reply  [nested|flat] 4+ messages in thread

* [PATCH v1 2/3] Give developer a helpful kick in the pants if they change natts in one place but not another
@ 2020-02-07 14:12  Justin Pryzby <pryzbyj@telsasoft.com>
  0 siblings, 0 replies; 4+ messages in thread

From: Justin Pryzby @ 2020-02-07 14:12 UTC (permalink / raw)

---
 src/backend/bootstrap/bootstrap.c | 23 +++++++++++++++++++++++
 1 file changed, 23 insertions(+)

diff --git a/src/backend/bootstrap/bootstrap.c b/src/backend/bootstrap/bootstrap.c
index bfc629c..d5e1888 100644
--- a/src/backend/bootstrap/bootstrap.c
+++ b/src/backend/bootstrap/bootstrap.c
@@ -25,7 +25,9 @@
 #include "access/xlog_internal.h"
 #include "bootstrap/bootstrap.h"
 #include "catalog/index.h"
+#include "catalog/pg_class.h"
 #include "catalog/pg_collation.h"
+#include "catalog/pg_proc.h"
 #include "catalog/pg_type.h"
 #include "common/link-canary.h"
 #include "libpq/pqsignal.h"
@@ -49,6 +51,7 @@
 #include "utils/ps_status.h"
 #include "utils/rel.h"
 #include "utils/relmapper.h"
+#include "utils/syscache.h"
 
 uint32		bootstrap_data_checksum_version = 0;	/* No checksum */
 
@@ -602,6 +605,26 @@ boot_openrel(char *relname)
 	TableScanDesc scan;
 	HeapTuple	tup;
 
+	/* Check that pg_class data is consistent now, rather than failing obscurely later */
+	struct { Oid oid; int natts; }
+		checknatts[] = {
+		{RelationRelationId, Natts_pg_class,},
+		{TypeRelationId, Natts_pg_type,},
+		{AttributeRelationId, Natts_pg_attribute,},
+		{ProcedureRelationId, Natts_pg_proc,},
+	};
+
+	for (int i=0; i<lengthof(checknatts); ++i) {
+		Form_pg_class	classForm;
+		HeapTuple	tuple;
+		tuple = SearchSysCache1(RELOID, ObjectIdGetDatum(checknatts[i].oid));
+		if (!HeapTupleIsValid(tuple))
+			elog(ERROR, "cache lookup failed for relation %u", checknatts[i].oid);
+		classForm = (Form_pg_class) GETSTRUCT(tuple);
+		Assert(checknatts[i].natts == classForm->relnatts);
+		ReleaseSysCache(tuple);
+	}
+
 	if (strlen(relname) >= NAMEDATALEN)
 		relname[NAMEDATALEN - 1] = '\0';
 
-- 
2.7.4


--TB36FDmn/VVEgNH/--





^ permalink  raw  reply  [nested|flat] 4+ messages in thread

* [PATCH v1 05/20] make use of XLogRecPtrIsInvalid in xlogreader.c
@ 2025-10-28 05:55  Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
  0 siblings, 0 replies; 4+ messages in thread

From: Bertrand Drouvot @ 2025-10-28 05:55 UTC (permalink / raw)

---
 src/backend/access/transam/xlogreader.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
 100.0% src/backend/access/transam/

diff --git a/src/backend/access/transam/xlogreader.c b/src/backend/access/transam/xlogreader.c
index dcc8d4f9c1b..5e3ebdeacc3 100644
--- a/src/backend/access/transam/xlogreader.c
+++ b/src/backend/access/transam/xlogreader.c
@@ -558,7 +558,7 @@ XLogDecodeNextRecord(XLogReaderState *state, bool nonblocking)
 
 	RecPtr = state->NextRecPtr;
 
-	if (state->DecodeRecPtr != InvalidXLogRecPtr)
+	if (!XLogRecPtrIsInvalid(state->DecodeRecPtr))
 	{
 		/* read the record after the one we just read */
 
-- 
2.34.1


--GBesP7F6OBOA65K/
Content-Type: text/x-diff; charset=us-ascii
Content-Disposition: attachment;
	filename="v1-0006-make-use-of-XLogRecPtrIsInvalid-in-xlogrecovery.c.patch"



^ permalink  raw  reply  [nested|flat] 4+ messages in thread

* [PATCH v1 06/20] make use of XLogRecPtrIsInvalid in xlogrecovery.c
@ 2025-10-28 05:58  Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
  0 siblings, 0 replies; 4+ messages in thread

From: Bertrand Drouvot @ 2025-10-28 05:58 UTC (permalink / raw)

---
 src/backend/access/transam/xlogrecovery.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
 100.0% src/backend/access/transam/

diff --git a/src/backend/access/transam/xlogrecovery.c b/src/backend/access/transam/xlogrecovery.c
index 3e3c4da01a2..eb999584aa9 100644
--- a/src/backend/access/transam/xlogrecovery.c
+++ b/src/backend/access/transam/xlogrecovery.c
@@ -757,9 +757,9 @@ InitWalRecovery(ControlFileData *ControlFile, bool *wasShutdown_ptr,
 		 * end-of-backup record), and we can enter archive recovery directly.
 		 */
 		if (ArchiveRecoveryRequested &&
-			(ControlFile->minRecoveryPoint != InvalidXLogRecPtr ||
+			(!XLogRecPtrIsInvalid(ControlFile->minRecoveryPoint) ||
 			 ControlFile->backupEndRequired ||
-			 ControlFile->backupEndPoint != InvalidXLogRecPtr ||
+			 !XLogRecPtrIsInvalid(ControlFile->backupEndPoint) ||
 			 ControlFile->state == DB_SHUTDOWNED))
 		{
 			InArchiveRecovery = true;
@@ -3151,7 +3151,7 @@ ReadRecord(XLogPrefetcher *xlogprefetcher, int emode,
 	/* Pass through parameters to XLogPageRead */
 	private->fetching_ckpt = fetching_ckpt;
 	private->emode = emode;
-	private->randAccess = (xlogreader->ReadRecPtr == InvalidXLogRecPtr);
+	private->randAccess = (XLogRecPtrIsInvalid(xlogreader->ReadRecPtr));
 	private->replayTLI = replayTLI;
 
 	/* This is the first attempt to read this page. */
@@ -4336,7 +4336,7 @@ XLogFileReadAnyTLI(XLogSegNo segno, XLogSource source)
 		 * Skip scanning the timeline ID that the logfile segment to read
 		 * doesn't belong to
 		 */
-		if (hent->begin != InvalidXLogRecPtr)
+		if (!XLogRecPtrIsInvalid(hent->begin))
 		{
 			XLogSegNo	beginseg = 0;
 
-- 
2.34.1


--GBesP7F6OBOA65K/
Content-Type: text/x-diff; charset=us-ascii
Content-Disposition: attachment;
	filename="v1-0007-make-use-of-XLogRecPtrIsInvalid-in-xlogutils.c.patch"



^ permalink  raw  reply  [nested|flat] 4+ messages in thread


end of thread, other threads:[~2025-10-28 05:58 UTC | newest]

Thread overview: 4+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2020-02-07 14:12 [PATCH v1 2/3] Give developer a helpful kick in the pants if they change natts in one place but not another Justin Pryzby <pryzbyj@telsasoft.com>
2020-02-07 14:12 [PATCH v1 2/3] Give developer a helpful kick in the pants if they change natts in one place but not another Justin Pryzby <pryzbyj@telsasoft.com>
2025-10-28 05:55 [PATCH v1 05/20] make use of XLogRecPtrIsInvalid in xlogreader.c Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2025-10-28 05:58 [PATCH v1 06/20] make use of XLogRecPtrIsInvalid in xlogrecovery.c Bertrand Drouvot <bertranddrouvot.pg@gmail.com>

This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox