From 245c4c5086e138f3e65b33b542282fa8563fd0ea Mon Sep 17 00:00:00 2001
From: Heikki Linnakangas <heikki.linnakangas@iki.fi>
Date: Thu, 26 Mar 2026 13:26:49 +0200
Subject: [PATCH v1 1/5] Rename MAX_NAMED_TRANCHES to MAX_USER_DEFINED_TRANCHES

The "named tranches" term is a little confusing. In most places it
refers specifically to tranches reqeusted with
RequestNamedLWLockTranche(), event though all built-in tranches and
tranches allocated with LWLockNewTrancheId() also have a name. But
MAX_NAMED_TRANCHES is the maximum for all tranches requested with
either RequestNamedLWLockTranche() or LWLockNewTrancheId(). The "user
defined" term was already used in LWTRANCHE_FIRST_USER_DEFINED, so
let's standardize on that to mean tranches allocated with either
RequestNamedLWLockTranche() or LWLockNewTrancheId().
---
 src/backend/storage/lmgr/lwlock.c | 18 +++++++++---------
 1 file changed, 9 insertions(+), 9 deletions(-)

diff --git a/src/backend/storage/lmgr/lwlock.c b/src/backend/storage/lmgr/lwlock.c
index 49382de88fc..ee482aee647 100644
--- a/src/backend/storage/lmgr/lwlock.c
+++ b/src/backend/storage/lmgr/lwlock.c
@@ -202,7 +202,7 @@ int		   *LWLockCounter = NULL;
 /* backend-local counter of registered tranches */
 static int	LocalLWLockCounter;
 
-#define MAX_NAMED_TRANCHES 256
+#define MAX_USER_DEFINED_TRANCHES 256
 
 static void InitializeLWLocks(void);
 static inline void LWLockReportWaitStart(LWLock *lock);
@@ -415,9 +415,9 @@ LWLockShmemSize(void)
 	/* Space for dynamic allocation counter. */
 	size = MAXALIGN(sizeof(int));
 
-	/* Space for named tranches. */
-	size = add_size(size, mul_size(MAX_NAMED_TRANCHES, sizeof(char *)));
-	size = add_size(size, mul_size(MAX_NAMED_TRANCHES, NAMEDATALEN));
+	/* Space for user-defined tranches. */
+	size = add_size(size, mul_size(MAX_USER_DEFINED_TRANCHES, sizeof(char *)));
+	size = add_size(size, mul_size(MAX_USER_DEFINED_TRANCHES, NAMEDATALEN));
 
 	/*
 	 * Make space for named tranche requests.  This is done for the benefit of
@@ -454,10 +454,10 @@ CreateLWLocks(void)
 		*LWLockCounter = LWTRANCHE_FIRST_USER_DEFINED;
 		ptr += MAXALIGN(sizeof(int));
 
-		/* Initialize tranche names */
+		/* Initialize user-defined tranche names */
 		LWLockTrancheNames = (char **) ptr;
-		ptr += MAX_NAMED_TRANCHES * sizeof(char *);
-		for (int i = 0; i < MAX_NAMED_TRANCHES; i++)
+		ptr += MAX_USER_DEFINED_TRANCHES * sizeof(char *);
+		for (int i = 0; i < MAX_USER_DEFINED_TRANCHES; i++)
 		{
 			LWLockTrancheNames[i] = ptr;
 			ptr += NAMEDATALEN;
@@ -616,13 +616,13 @@ LWLockNewTrancheId(const char *name)
 	 */
 	SpinLockAcquire(ShmemLock);
 
-	if (*LWLockCounter - LWTRANCHE_FIRST_USER_DEFINED >= MAX_NAMED_TRANCHES)
+	if (*LWLockCounter - LWTRANCHE_FIRST_USER_DEFINED >= MAX_USER_DEFINED_TRANCHES)
 	{
 		SpinLockRelease(ShmemLock);
 		ereport(ERROR,
 				(errmsg("maximum number of tranches already registered"),
 				 errdetail("No more than %d tranches may be registered.",
-						   MAX_NAMED_TRANCHES)));
+						   MAX_USER_DEFINED_TRANCHES)));
 	}
 
 	result = (*LWLockCounter)++;
-- 
2.47.3

