From 8b8db01517bd688e35a70eb3a34fb0ce3c977085 Mon Sep 17 00:00:00 2001
From: Tom Lane <tgl@sss.pgh.pa.us>
Date: Thu, 9 Sep 1999 14:56:06 +0000
Subject: [PATCH] Minor improvement in SI overflow logic: try to delete expired
 messages before concluding that we really have buffer overflow.

---
 src/backend/storage/ipc/sinvaladt.c | 18 ++++++++++++++----
 1 file changed, 14 insertions(+), 4 deletions(-)

diff --git a/src/backend/storage/ipc/sinvaladt.c b/src/backend/storage/ipc/sinvaladt.c
index 99426693cd1..1a91dde9b1c 100644
--- a/src/backend/storage/ipc/sinvaladt.c
+++ b/src/backend/storage/ipc/sinvaladt.c
@@ -7,7 +7,7 @@
  *
  *
  * IDENTIFICATION
- *	  $Header: /cvsroot/pgsql/src/backend/storage/ipc/sinvaladt.c,v 1.25 1999/09/06 19:37:38 tgl Exp $
+ *	  $Header: /cvsroot/pgsql/src/backend/storage/ipc/sinvaladt.c,v 1.26 1999/09/09 14:56:06 tgl Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -228,9 +228,19 @@ SIInsertDataEntry(SISeg *segP, SharedInvalidData *data)
 	/* Is the buffer full? */
 	if (numMsgs >= MAXNUMMESSAGES)
 	{
-		/* Yes, so force reset */
-		SISetProcStateInvalid(segP);
-		return false;
+		/*
+		 * Don't panic just yet: slowest backend might have consumed some
+		 * messages but not yet have done SIDelExpiredDataEntries() to
+		 * advance minMsgNum.  So, make sure minMsgNum is up-to-date.
+		 */
+		SIDelExpiredDataEntries(segP);
+		numMsgs = segP->maxMsgNum - segP->minMsgNum;
+		if (numMsgs >= MAXNUMMESSAGES)
+		{
+			/* Yup, it's definitely full, no choice but to reset */
+			SISetProcStateInvalid(segP);
+			return false;
+		}
 	}
 
 	/*
-- 
GitLab