PS_NITPICKS_20241008_v11.txt

text/plain

Filename: PS_NITPICKS_20241008_v11.txt
Type: text/plain
Part: 0
Message: Re: Add contrib/pg_logicalsnapinspect
diff --git a/contrib/pg_logicalinspect/expected/logical_inspect.out b/contrib/pg_logicalinspect/expected/logical_inspect.out
index 219afd6..71dea4a 100644
--- a/contrib/pg_logicalinspect/expected/logical_inspect.out
+++ b/contrib/pg_logicalinspect/expected/logical_inspect.out
@@ -37,7 +37,7 @@ table public.tbl1: INSERT: val1[integer]:1 val2[integer]:null
 COMMIT                                                       
 (3 rows)
 
-step s1_get_logical_snapshot_info: SELECT info.state,info.catchange_count,array_length(info.catchange_xip,1) AS catchange_array_length,info.committed_count,array_length(info.committed_xip,1) AS committed_array_length FROM pg_ls_logicalsnapdir(), pg_get_logical_snapshot_info(name) AS info ORDER BY 2;
+step s1_get_logical_snapshot_info: SELECT info.state, info.catchange_count, array_length(info.catchange_xip, 1) AS catchange_array_length, info.committed_count, array_length(info.committed_xip, 1) AS committed_array_length FROM pg_ls_logicalsnapdir(), pg_get_logical_snapshot_info(name) AS info ORDER BY 2;
 state     |catchange_count|catchange_array_length|committed_count|committed_array_length
 ----------+---------------+----------------------+---------------+----------------------
 consistent|              0|                      |              2|                     2
diff --git a/contrib/pg_logicalinspect/specs/logical_inspect.spec b/contrib/pg_logicalinspect/specs/logical_inspect.spec
index 7dc3cd7..0a4d268 100644
--- a/contrib/pg_logicalinspect/specs/logical_inspect.spec
+++ b/contrib/pg_logicalinspect/specs/logical_inspect.spec
@@ -29,6 +29,6 @@ setup { SET synchronous_commit=on; }
 step "s1_checkpoint" { CHECKPOINT; }
 step "s1_get_changes" { SELECT data FROM pg_logical_slot_get_changes('isolation_slot', NULL, NULL, 'skip-empty-xacts', '1', 'include-xids', '0'); }
 step "s1_get_logical_snapshot_meta" { SELECT COUNT(meta.*) from pg_ls_logicalsnapdir(), pg_get_logical_snapshot_meta(name) as meta;}
-step "s1_get_logical_snapshot_info" { SELECT info.state,info.catchange_count,array_length(info.catchange_xip,1) AS catchange_array_length,info.committed_count,array_length(info.committed_xip,1) AS committed_array_length FROM pg_ls_logicalsnapdir(), pg_get_logical_snapshot_info(name) AS info ORDER BY 2; }
+step "s1_get_logical_snapshot_info" { SELECT info.state, info.catchange_count, array_length(info.catchange_xip, 1) AS catchange_array_length, info.committed_count, array_length(info.committed_xip, 1) AS committed_array_length FROM pg_ls_logicalsnapdir(), pg_get_logical_snapshot_info(name) AS info ORDER BY 2; }
 
 permutation "s0_init" "s0_begin" "s0_savepoint" "s0_truncate" "s1_checkpoint" "s1_get_changes" "s0_commit" "s0_begin" "s0_insert" "s1_checkpoint" "s1_get_changes" "s0_commit" "s1_get_changes" "s1_get_logical_snapshot_info" "s1_get_logical_snapshot_meta"
diff --git a/src/backend/replication/logical/snapbuild.c b/src/backend/replication/logical/snapbuild.c
index 7a3b963..4b24718 100644
--- a/src/backend/replication/logical/snapbuild.c
+++ b/src/backend/replication/logical/snapbuild.c
@@ -1691,7 +1691,6 @@ ValidateAndRestoreSnapshotFile(SnapBuildOnDisk *ondisk, const char *path, int fd
 							   MemoryContext context)
 {
 	pg_crc32c	checksum;
-	Size		sz;
 
 	/* ----
 	 * Make sure the snapshot had been stored safely to disk, that's normally
@@ -1731,7 +1730,7 @@ ValidateAndRestoreSnapshotFile(SnapBuildOnDisk *ondisk, const char *path, int fd
 	/* restore committed xacts information */
 	if (ondisk->builder.committed.xcnt > 0)
 	{
-		sz = sizeof(TransactionId) * ondisk->builder.committed.xcnt;
+		Size sz = sizeof(TransactionId) * ondisk->builder.committed.xcnt;
 		ondisk->builder.committed.xip = MemoryContextAllocZero(context, sz);
 		SnapBuildRestoreContents(fd, (char *) ondisk->builder.committed.xip, sz, path);
 		COMP_CRC32C(checksum, ondisk->builder.committed.xip, sz);
@@ -1740,7 +1739,7 @@ ValidateAndRestoreSnapshotFile(SnapBuildOnDisk *ondisk, const char *path, int fd
 	/* restore catalog modifying xacts information */
 	if (ondisk->builder.catchange.xcnt > 0)
 	{
-		sz = sizeof(TransactionId) * ondisk->builder.catchange.xcnt;
+		Size sz = sizeof(TransactionId) * ondisk->builder.catchange.xcnt;
 		ondisk->builder.catchange.xip = MemoryContextAllocZero(context, sz);
 		SnapBuildRestoreContents(fd, (char *) ondisk->builder.catchange.xip, sz, path);
 		COMP_CRC32C(checksum, ondisk->builder.catchange.xip, sz);
@@ -1782,13 +1781,15 @@ SnapBuildRestore(SnapBuild *builder, XLogRecPtr lsn)
 
 	fd = OpenTransientFile(path, O_RDONLY | PG_BINARY);
 
-	if (fd < 0 && errno == ENOENT)
-		return false;
-	else if (fd < 0)
+	if (fd < 0)
+	{
+		if (errno == ENOENT)
+			return false;
+
 		ereport(ERROR,
 				(errcode_for_file_access(),
 				 errmsg("could not open file \"%s\": %m", path)));
-
+	}
 
 	/* validate and restore the snapshot to 'ondisk' */
 	ValidateAndRestoreSnapshotFile(&ondisk, path, fd, builder->context);