public inbox for [email protected]  
help / color / mirror / Atom feed
[PATCH 06/10] Make XlogReadTwoPhaseData not use callback but call the function directly
6+ messages / 2 participants
[nested] [flat]

* [PATCH 06/10] Make XlogReadTwoPhaseData not use callback but call the function directly
@ 2019-04-18 06:02  Kyotaro Horiguchi <[email protected]>
  0 siblings, 0 replies; 6+ messages in thread

From: Kyotaro Horiguchi @ 2019-04-18 06:02 UTC (permalink / raw)

This patch replaces the call to the callback in XlogReadTwoPhaseData
with direct call to the original function. Then invalidate the
parameters callback and private for XLogReaderAllocate.
---
 src/backend/access/transam/twophase.c          | 8 ++------
 src/backend/access/transam/xlogutils.c         | 8 +++++---
 src/backend/replication/logical/logicalfuncs.c | 8 ++++++--
 src/include/access/xlogutils.h                 | 5 +----
 4 files changed, 14 insertions(+), 15 deletions(-)

diff --git a/src/backend/access/transam/twophase.c b/src/backend/access/transam/twophase.c
index 6feca69126..f6d48368fe 100644
--- a/src/backend/access/transam/twophase.c
+++ b/src/backend/access/transam/twophase.c
@@ -1386,8 +1386,7 @@ XlogReadTwoPhaseData(XLogRecPtr lsn, char **buf, int *len)
 	XLogReaderState *xlogreader;
 	char	   *errormsg;
 
-	xlogreader = XLogReaderAllocate(wal_segment_size, &read_local_xlog_page,
-									NULL);
+	xlogreader = XLogReaderAllocate(wal_segment_size, NULL, NULL);
 	if (!xlogreader)
 		ereport(ERROR,
 				(errcode(ERRCODE_OUT_OF_MEMORY),
@@ -1396,10 +1395,7 @@ XlogReadTwoPhaseData(XLogRecPtr lsn, char **buf, int *len)
 
 	while (XLogReadRecord(xlogreader, lsn, &record, &errormsg) ==
 		   XLREAD_NEED_DATA)
-			xlogreader->read_page(xlogreader,
-								  xlogreader->loadPagePtr, xlogreader->loadLen,
-								  xlogreader->currRecPtr, xlogreader->readBuf,
-								  &xlogreader->readPageTLI);
+		read_local_xlog_page(xlogreader);
 
 	if (record == NULL)
 		ereport(ERROR,
diff --git a/src/backend/access/transam/xlogutils.c b/src/backend/access/transam/xlogutils.c
index c853e1f0e3..fd461f16fc 100644
--- a/src/backend/access/transam/xlogutils.c
+++ b/src/backend/access/transam/xlogutils.c
@@ -908,10 +908,12 @@ XLogReadDetermineTimeline(XLogReaderState *state, XLogRecPtr wantPage, uint32 wa
  * loop for now.
  */
 void
-read_local_xlog_page(XLogReaderState *state, XLogRecPtr targetPagePtr,
-					 int reqLen, XLogRecPtr targetRecPtr, char *cur_page,
-					 TimeLineID *pageTLI)
+read_local_xlog_page(XLogReaderState *state)
 {
+	XLogRecPtr	targetPagePtr = state->loadPagePtr;
+	int			reqLen		  = state->loadLen;
+	char	   *cur_page	  = state->readBuf;
+	TimeLineID *pageTLI		  = &state->readPageTLI;
 	XLogRecPtr	read_upto,
 				loc;
 	int			count;
diff --git a/src/backend/replication/logical/logicalfuncs.c b/src/backend/replication/logical/logicalfuncs.c
index 4d09255504..240a375d8f 100644
--- a/src/backend/replication/logical/logicalfuncs.c
+++ b/src/backend/replication/logical/logicalfuncs.c
@@ -118,8 +118,12 @@ void
 logical_read_local_xlog_page(XLogReaderState *state, XLogRecPtr targetPagePtr,
 							 int reqLen, XLogRecPtr targetRecPtr, char *cur_page, TimeLineID *pageTLI)
 {
-	read_local_xlog_page(state, targetPagePtr, reqLen,
-						 targetRecPtr, cur_page, pageTLI);
+	Assert(targetPagePtr == state->loadPagePtr &&
+		   reqLen == state->loadLen &&
+		   targetRecPtr == state->currRecPtr &&
+		   cur_page == state->readBuf &&
+		   pageTLI == &state->readPageTLI);
+	read_local_xlog_page(state);
 }
 
 /*
diff --git a/src/include/access/xlogutils.h b/src/include/access/xlogutils.h
index be0c79d18c..9724ce20b8 100644
--- a/src/include/access/xlogutils.h
+++ b/src/include/access/xlogutils.h
@@ -47,10 +47,7 @@ extern Buffer XLogReadBufferExtended(RelFileNode rnode, ForkNumber forknum,
 extern Relation CreateFakeRelcacheEntry(RelFileNode rnode);
 extern void FreeFakeRelcacheEntry(Relation fakerel);
 
-extern void	read_local_xlog_page(XLogReaderState *state,
-								 XLogRecPtr targetPagePtr, int reqLen,
-								 XLogRecPtr targetRecPtr, char *cur_page,
-								 TimeLineID *pageTLI);
+extern void read_local_xlog_page(XLogReaderState *state);
 
 extern void XLogReadDetermineTimeline(XLogReaderState *state,
 									  XLogRecPtr wantPage, uint32 wantLength);
-- 
2.16.3


----Next_Part(Wed_Jul_10_13_18_10_2019_842)--
Content-Type: Text/X-Patch; charset=us-ascii
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
 filename="v4-0007-Make-logical-rep-stuff-not-use-callback-but-call-the.patch"



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

* [PATCH 1/1] work-in-progress: fix pg_upgrade output
@ 2023-08-02 17:20  Nathan Bossart <[email protected]>
  0 siblings, 0 replies; 6+ messages in thread

From: Nathan Bossart @ 2023-08-02 17:20 UTC (permalink / raw)

---
 src/bin/pg_upgrade/util.c | 14 +++++---------
 1 file changed, 5 insertions(+), 9 deletions(-)

diff --git a/src/bin/pg_upgrade/util.c b/src/bin/pg_upgrade/util.c
index 21ba4c8f12..bea6d7289d 100644
--- a/src/bin/pg_upgrade/util.c
+++ b/src/bin/pg_upgrade/util.c
@@ -50,10 +50,10 @@ end_progress_output(void)
 	if (log_opts.isatty)
 	{
 		printf("\r");
-		pg_log(PG_REPORT_NONL, "%-*s", MESSAGE_WIDTH, "");
+		pg_log(PG_REPORT_NONL, "%-*s\r  ", MESSAGE_WIDTH, "");
 	}
 	else if (log_opts.verbose)
-		pg_log(PG_REPORT_NONL, "%-*s", MESSAGE_WIDTH, "");
+		pg_log(PG_REPORT_NONL, "  ");
 }
 
 /*
@@ -114,9 +114,6 @@ cleanup_output_dirs(void)
  * prep_status
  *
  *	Displays a message that describes an operation we are about to begin.
- *	We pad the message out to MESSAGE_WIDTH characters so that all of the
- *	"ok" and "failed" indicators line up nicely.  (Overlength messages
- *	will be truncated, so don't get too verbose.)
  *
  *	A typical sequence would look like this:
  *		prep_status("about to flarb the next %d files", fileCount);
@@ -135,8 +132,7 @@ prep_status(const char *fmt,...)
 	vsnprintf(message, sizeof(message), fmt, args);
 	va_end(args);
 
-	/* trim strings */
-	pg_log(PG_REPORT_NONL, "%-*s", MESSAGE_WIDTH, message);
+	pg_log(PG_REPORT_NONL, "%s ... ", message);
 }
 
 /*
@@ -167,9 +163,9 @@ prep_status_progress(const char *fmt,...)
 	 * put the individual progress items onto the next line.
 	 */
 	if (log_opts.isatty || log_opts.verbose)
-		pg_log(PG_REPORT, "%-*s", MESSAGE_WIDTH, message);
+		pg_log(PG_REPORT, "%s ...", message);
 	else
-		pg_log(PG_REPORT_NONL, "%-*s", MESSAGE_WIDTH, message);
+		pg_log(PG_REPORT_NONL, "%s ... ", message);
 }
 
 static void
-- 
2.25.1


--gBBFr7Ir9EOA20Yy--





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

* [PATCH 1/1] work-in-progress: fix pg_upgrade output
@ 2023-08-02 17:20  Nathan Bossart <[email protected]>
  0 siblings, 0 replies; 6+ messages in thread

From: Nathan Bossart @ 2023-08-02 17:20 UTC (permalink / raw)

---
 src/bin/pg_upgrade/util.c | 14 +++++---------
 1 file changed, 5 insertions(+), 9 deletions(-)

diff --git a/src/bin/pg_upgrade/util.c b/src/bin/pg_upgrade/util.c
index 21ba4c8f12..bea6d7289d 100644
--- a/src/bin/pg_upgrade/util.c
+++ b/src/bin/pg_upgrade/util.c
@@ -50,10 +50,10 @@ end_progress_output(void)
 	if (log_opts.isatty)
 	{
 		printf("\r");
-		pg_log(PG_REPORT_NONL, "%-*s", MESSAGE_WIDTH, "");
+		pg_log(PG_REPORT_NONL, "%-*s\r  ", MESSAGE_WIDTH, "");
 	}
 	else if (log_opts.verbose)
-		pg_log(PG_REPORT_NONL, "%-*s", MESSAGE_WIDTH, "");
+		pg_log(PG_REPORT_NONL, "  ");
 }
 
 /*
@@ -114,9 +114,6 @@ cleanup_output_dirs(void)
  * prep_status
  *
  *	Displays a message that describes an operation we are about to begin.
- *	We pad the message out to MESSAGE_WIDTH characters so that all of the
- *	"ok" and "failed" indicators line up nicely.  (Overlength messages
- *	will be truncated, so don't get too verbose.)
  *
  *	A typical sequence would look like this:
  *		prep_status("about to flarb the next %d files", fileCount);
@@ -135,8 +132,7 @@ prep_status(const char *fmt,...)
 	vsnprintf(message, sizeof(message), fmt, args);
 	va_end(args);
 
-	/* trim strings */
-	pg_log(PG_REPORT_NONL, "%-*s", MESSAGE_WIDTH, message);
+	pg_log(PG_REPORT_NONL, "%s ... ", message);
 }
 
 /*
@@ -167,9 +163,9 @@ prep_status_progress(const char *fmt,...)
 	 * put the individual progress items onto the next line.
 	 */
 	if (log_opts.isatty || log_opts.verbose)
-		pg_log(PG_REPORT, "%-*s", MESSAGE_WIDTH, message);
+		pg_log(PG_REPORT, "%s ...", message);
 	else
-		pg_log(PG_REPORT_NONL, "%-*s", MESSAGE_WIDTH, message);
+		pg_log(PG_REPORT_NONL, "%s ... ", message);
 }
 
 static void
-- 
2.25.1


--gBBFr7Ir9EOA20Yy--





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

* [PATCH 1/1] work-in-progress: fix pg_upgrade output
@ 2023-08-02 17:20  Nathan Bossart <[email protected]>
  0 siblings, 0 replies; 6+ messages in thread

From: Nathan Bossart @ 2023-08-02 17:20 UTC (permalink / raw)

---
 src/bin/pg_upgrade/util.c | 14 +++++---------
 1 file changed, 5 insertions(+), 9 deletions(-)

diff --git a/src/bin/pg_upgrade/util.c b/src/bin/pg_upgrade/util.c
index 21ba4c8f12..bea6d7289d 100644
--- a/src/bin/pg_upgrade/util.c
+++ b/src/bin/pg_upgrade/util.c
@@ -50,10 +50,10 @@ end_progress_output(void)
 	if (log_opts.isatty)
 	{
 		printf("\r");
-		pg_log(PG_REPORT_NONL, "%-*s", MESSAGE_WIDTH, "");
+		pg_log(PG_REPORT_NONL, "%-*s\r  ", MESSAGE_WIDTH, "");
 	}
 	else if (log_opts.verbose)
-		pg_log(PG_REPORT_NONL, "%-*s", MESSAGE_WIDTH, "");
+		pg_log(PG_REPORT_NONL, "  ");
 }
 
 /*
@@ -114,9 +114,6 @@ cleanup_output_dirs(void)
  * prep_status
  *
  *	Displays a message that describes an operation we are about to begin.
- *	We pad the message out to MESSAGE_WIDTH characters so that all of the
- *	"ok" and "failed" indicators line up nicely.  (Overlength messages
- *	will be truncated, so don't get too verbose.)
  *
  *	A typical sequence would look like this:
  *		prep_status("about to flarb the next %d files", fileCount);
@@ -135,8 +132,7 @@ prep_status(const char *fmt,...)
 	vsnprintf(message, sizeof(message), fmt, args);
 	va_end(args);
 
-	/* trim strings */
-	pg_log(PG_REPORT_NONL, "%-*s", MESSAGE_WIDTH, message);
+	pg_log(PG_REPORT_NONL, "%s ... ", message);
 }
 
 /*
@@ -167,9 +163,9 @@ prep_status_progress(const char *fmt,...)
 	 * put the individual progress items onto the next line.
 	 */
 	if (log_opts.isatty || log_opts.verbose)
-		pg_log(PG_REPORT, "%-*s", MESSAGE_WIDTH, message);
+		pg_log(PG_REPORT, "%s ...", message);
 	else
-		pg_log(PG_REPORT_NONL, "%-*s", MESSAGE_WIDTH, message);
+		pg_log(PG_REPORT_NONL, "%s ... ", message);
 }
 
 static void
-- 
2.25.1


--gBBFr7Ir9EOA20Yy--





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

* [PATCH 1/1] work-in-progress: fix pg_upgrade output
@ 2023-08-02 17:20  Nathan Bossart <[email protected]>
  0 siblings, 0 replies; 6+ messages in thread

From: Nathan Bossart @ 2023-08-02 17:20 UTC (permalink / raw)

---
 src/bin/pg_upgrade/util.c | 14 +++++---------
 1 file changed, 5 insertions(+), 9 deletions(-)

diff --git a/src/bin/pg_upgrade/util.c b/src/bin/pg_upgrade/util.c
index 21ba4c8f12..bea6d7289d 100644
--- a/src/bin/pg_upgrade/util.c
+++ b/src/bin/pg_upgrade/util.c
@@ -50,10 +50,10 @@ end_progress_output(void)
 	if (log_opts.isatty)
 	{
 		printf("\r");
-		pg_log(PG_REPORT_NONL, "%-*s", MESSAGE_WIDTH, "");
+		pg_log(PG_REPORT_NONL, "%-*s\r  ", MESSAGE_WIDTH, "");
 	}
 	else if (log_opts.verbose)
-		pg_log(PG_REPORT_NONL, "%-*s", MESSAGE_WIDTH, "");
+		pg_log(PG_REPORT_NONL, "  ");
 }
 
 /*
@@ -114,9 +114,6 @@ cleanup_output_dirs(void)
  * prep_status
  *
  *	Displays a message that describes an operation we are about to begin.
- *	We pad the message out to MESSAGE_WIDTH characters so that all of the
- *	"ok" and "failed" indicators line up nicely.  (Overlength messages
- *	will be truncated, so don't get too verbose.)
  *
  *	A typical sequence would look like this:
  *		prep_status("about to flarb the next %d files", fileCount);
@@ -135,8 +132,7 @@ prep_status(const char *fmt,...)
 	vsnprintf(message, sizeof(message), fmt, args);
 	va_end(args);
 
-	/* trim strings */
-	pg_log(PG_REPORT_NONL, "%-*s", MESSAGE_WIDTH, message);
+	pg_log(PG_REPORT_NONL, "%s ... ", message);
 }
 
 /*
@@ -167,9 +163,9 @@ prep_status_progress(const char *fmt,...)
 	 * put the individual progress items onto the next line.
 	 */
 	if (log_opts.isatty || log_opts.verbose)
-		pg_log(PG_REPORT, "%-*s", MESSAGE_WIDTH, message);
+		pg_log(PG_REPORT, "%s ...", message);
 	else
-		pg_log(PG_REPORT_NONL, "%-*s", MESSAGE_WIDTH, message);
+		pg_log(PG_REPORT_NONL, "%s ... ", message);
 }
 
 static void
-- 
2.25.1


--gBBFr7Ir9EOA20Yy--





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

* [PATCH v1 1/1] pg_dump: fix use of pg_get_sequence_data
@ 2026-01-08 17:29  Nathan Bossart <[email protected]>
  0 siblings, 0 replies; 6+ messages in thread

From: Nathan Bossart @ 2026-01-08 17:29 UTC (permalink / raw)

---
 src/backend/access/sequence/sequence.c | 20 ++++++++++++++++++++
 src/backend/commands/sequence.c        | 14 ++++++++------
 src/bin/pg_dump/pg_dump.c              | 10 ++++++++++
 src/include/access/sequence.h          |  1 +
 4 files changed, 39 insertions(+), 6 deletions(-)

diff --git a/src/backend/access/sequence/sequence.c b/src/backend/access/sequence/sequence.c
index 106af1477e9..6f21f49a520 100644
--- a/src/backend/access/sequence/sequence.c
+++ b/src/backend/access/sequence/sequence.c
@@ -45,6 +45,26 @@ sequence_open(Oid relationId, LOCKMODE lockmode)
 	return r;
 }
 
+/* ----------------
+ *		try_sequence_open - open a sequence relation by relation OID
+ *
+ *		Same as sequence_open, except return NULL instead of failing if the
+ *		relation does not exist.
+ * ----------------
+ */
+Relation
+try_sequence_open(Oid relationId, LOCKMODE lockmode)
+{
+	Relation	r;
+
+	r = try_relation_open(relationId, lockmode);
+
+	if (r)
+		validate_relation_kind(r);
+
+	return r;
+}
+
 /* ----------------
  *		sequence_close - close a sequence
  *
diff --git a/src/backend/commands/sequence.c b/src/backend/commands/sequence.c
index 904eeada5ab..e3202dfe951 100644
--- a/src/backend/commands/sequence.c
+++ b/src/backend/commands/sequence.c
@@ -1794,7 +1794,6 @@ pg_get_sequence_data(PG_FUNCTION_ARGS)
 {
 #define PG_GET_SEQUENCE_DATA_COLS	3
 	Oid			relid = PG_GETARG_OID(0);
-	SeqTable	elm;
 	Relation	seqrel;
 	Datum		values[PG_GET_SEQUENCE_DATA_COLS] = {0};
 	bool		isnull[PG_GET_SEQUENCE_DATA_COLS] = {0};
@@ -1811,13 +1810,15 @@ pg_get_sequence_data(PG_FUNCTION_ARGS)
 					   LSNOID, -1, 0);
 	resultTupleDesc = BlessTupleDesc(resultTupleDesc);
 
-	init_sequence(relid, &elm, &seqrel);
+	seqrel = try_sequence_open(relid, AccessShareLock);
 
 	/*
-	 * Return all NULLs for sequences for which we lack privileges, other
-	 * sessions' temporary sequences, and unlogged sequences on standbys.
+	 * Return all NULLs for missing sequences, sequences for which we lack
+	 * privileges, other sessions' temporary sequences, and unlogged sequences
+	 * on standbys.
 	 */
-	if (pg_class_aclcheck(relid, GetUserId(), ACL_SELECT) == ACLCHECK_OK &&
+	if (seqrel &&
+		pg_class_aclcheck(relid, GetUserId(), ACL_SELECT) == ACLCHECK_OK &&
 		!RELATION_IS_OTHER_TEMP(seqrel) &&
 		(RelationIsPermanent(seqrel) || !RecoveryInProgress()))
 	{
@@ -1838,7 +1839,8 @@ pg_get_sequence_data(PG_FUNCTION_ARGS)
 	else
 		memset(isnull, true, sizeof(isnull));
 
-	sequence_close(seqrel, NoLock);
+	if (seqrel)
+		sequence_close(seqrel, AccessShareLock);
 
 	resultHeapTuple = heap_form_tuple(resultTupleDesc, values, isnull);
 	result = HeapTupleGetDatum(resultHeapTuple);
diff --git a/src/bin/pg_dump/pg_dump.c b/src/bin/pg_dump/pg_dump.c
index 7df56d8b1b0..573fb0c06a1 100644
--- a/src/bin/pg_dump/pg_dump.c
+++ b/src/bin/pg_dump/pg_dump.c
@@ -137,6 +137,7 @@ typedef struct
 	int64		cache;			/* cache size */
 	int64		last_value;		/* last value of sequence */
 	bool		is_called;		/* whether nextval advances before returning */
+	bool		null_seqtuple;	/* did pg_get_sequence_data return nulls? */
 } SequenceItem;
 
 typedef enum OidOptions
@@ -18959,6 +18960,7 @@ collectSequences(Archive *fout)
 		sequences[i].cycled = (strcmp(PQgetvalue(res, i, 7), "t") == 0);
 		sequences[i].last_value = strtoi64(PQgetvalue(res, i, 8), NULL, 10);
 		sequences[i].is_called = (strcmp(PQgetvalue(res, i, 9), "t") == 0);
+		sequences[i].null_seqtuple = (PQgetisnull(res, i, 8) || PQgetisnull(res, i, 9));
 	}
 
 	PQclear(res);
@@ -19230,6 +19232,10 @@ dumpSequenceData(Archive *fout, const TableDataInfo *tdinfo)
 	bool		called;
 	PQExpBuffer query = createPQExpBuffer();
 
+	/* needn't bother if not dumping sequence data */
+	if (!fout->dopt->dumpData && !fout->dopt->sequence_data)
+		return;
+
 	/*
 	 * For versions >= 18, the sequence information is gathered in the sorted
 	 * array before any calls to dumpSequenceData().  See collectSequences()
@@ -19271,6 +19277,10 @@ dumpSequenceData(Archive *fout, const TableDataInfo *tdinfo)
 		entry = bsearch(&key, sequences, nsequences,
 						sizeof(SequenceItem), SequenceItemCmp);
 
+		if (entry->null_seqtuple)
+			pg_fatal("failed to get data for sequence \"%s\"; user may lack privileges or sequence may have been dropped",
+					 tbinfo->dobj.name);
+
 		last = entry->last_value;
 		called = entry->is_called;
 	}
diff --git a/src/include/access/sequence.h b/src/include/access/sequence.h
index cbe93775b1b..42f199003b4 100644
--- a/src/include/access/sequence.h
+++ b/src/include/access/sequence.h
@@ -18,6 +18,7 @@
 #include "utils/relcache.h"
 
 extern Relation sequence_open(Oid relationId, LOCKMODE lockmode);
+extern Relation try_sequence_open(Oid relationId, LOCKMODE lockmode);
 extern void sequence_close(Relation relation, LOCKMODE lockmode);
 
 #endif							/* ACCESS_SEQUENCE_H */
-- 
2.39.5 (Apple Git-154)


--iyprHr6gT7UrymdC--






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


end of thread, other threads:[~2026-01-08 17:29 UTC | newest]

Thread overview: 6+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2019-04-18 06:02 [PATCH 06/10] Make XlogReadTwoPhaseData not use callback but call the function directly Kyotaro Horiguchi <[email protected]>
2023-08-02 17:20 [PATCH 1/1] work-in-progress: fix pg_upgrade output Nathan Bossart <[email protected]>
2023-08-02 17:20 [PATCH 1/1] work-in-progress: fix pg_upgrade output Nathan Bossart <[email protected]>
2023-08-02 17:20 [PATCH 1/1] work-in-progress: fix pg_upgrade output Nathan Bossart <[email protected]>
2023-08-02 17:20 [PATCH 1/1] work-in-progress: fix pg_upgrade output Nathan Bossart <[email protected]>
2026-01-08 17:29 [PATCH v1 1/1] pg_dump: fix use of pg_get_sequence_data Nathan Bossart <[email protected]>

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