From dd7a98a990aa28a06a82607052180f69ee44e05f Mon Sep 17 00:00:00 2001
From: Michael Paquier <michael@paquier.xyz>
Date: Thu, 13 Jun 2024 13:25:48 +0900
Subject: [PATCH 2/6] Replace hardcoded identifiers in pgstats file by
 variables

This changes three variable types:
- N for named entries.
- S for entries identified by a hash.
- E for end-of-file
---
 src/backend/utils/activity/pgstat.c | 23 +++++++++++++++--------
 1 file changed, 15 insertions(+), 8 deletions(-)

diff --git a/src/backend/utils/activity/pgstat.c b/src/backend/utils/activity/pgstat.c
index d558cc1414..f03fee7cd5 100644
--- a/src/backend/utils/activity/pgstat.c
+++ b/src/backend/utils/activity/pgstat.c
@@ -127,6 +127,13 @@
 
 #define PGSTAT_SNAPSHOT_HASH_SIZE	512
 
+/* ---------
+ * Identifiers in stats file.
+ * ---------
+ */
+#define PGSTAT_FILE_END		'E' /* end of file */
+#define PGSTAT_FILE_NAME	'N' /* stats entry identified by name */
+#define PGSTAT_FILE_SYSTEM	'S' /* stats entry identified by PgStat_HashKey */
 
 /* hash table for statistics snapshots entry */
 typedef struct PgStat_SnapshotEntry
@@ -1408,7 +1415,7 @@ pgstat_write_statsfile(void)
 		if (!kind_info->to_serialized_name)
 		{
 			/* normal stats entry, identified by PgStat_HashKey */
-			fputc('S', fpout);
+			fputc(PGSTAT_FILE_SYSTEM, fpout);
 			write_chunk_s(fpout, &ps->key);
 		}
 		else
@@ -1418,7 +1425,7 @@ pgstat_write_statsfile(void)
 
 			kind_info->to_serialized_name(&ps->key, shstats, &name);
 
-			fputc('N', fpout);
+			fputc(PGSTAT_FILE_NAME, fpout);
 			write_chunk_s(fpout, &ps->key.kind);
 			write_chunk_s(fpout, &name);
 		}
@@ -1435,7 +1442,7 @@ pgstat_write_statsfile(void)
 	 * pgstat.stat with it.  The ferror() check replaces testing for error
 	 * after each individual fputc or fwrite (in write_chunk()) above.
 	 */
-	fputc('E', fpout);
+	fputc(PGSTAT_FILE_END, fpout);
 
 	if (ferror(fpout))
 	{
@@ -1572,8 +1579,8 @@ pgstat_read_statsfile(void)
 
 		switch (t)
 		{
-			case 'S':
-			case 'N':
+			case PGSTAT_FILE_SYSTEM:
+			case PGSTAT_FILE_NAME:
 				{
 					PgStat_HashKey key;
 					PgStatShared_HashEntry *p;
@@ -1581,7 +1588,7 @@ pgstat_read_statsfile(void)
 
 					CHECK_FOR_INTERRUPTS();
 
-					if (t == 'S')
+					if (t == PGSTAT_FILE_SYSTEM)
 					{
 						/* normal stats entry, identified by PgStat_HashKey */
 						if (!read_chunk_s(fpin, &key))
@@ -1647,8 +1654,8 @@ pgstat_read_statsfile(void)
 
 					break;
 				}
-			case 'E':
-				/* check that 'E' actually signals end of file */
+			case PGSTAT_FILE_END:
+				/* check that PGSTAT_FILE_END actually signals end of file */
 				if (fgetc(fpin) != EOF)
 					goto error;
 
-- 
2.43.0

