From 1796070f97c661c750b958209055f91b971e4123 Mon Sep 17 00:00:00 2001
From: Andrew Dunstan <andrew@dunslane.net>
Date: Fri, 26 Jan 2024 12:09:48 -0500
Subject: [PATCH v7 4/4] add logging traces to see if we can find out what is
 upsetting the cfbot

---
 src/backend/backup/basebackup_incremental.c | 15 ++++++++++++++-
 src/bin/pg_combinebackup/t/003_timeline.pl  |  2 ++
 src/common/parse_manifest.c                 |  7 +++++--
 3 files changed, 21 insertions(+), 3 deletions(-)

diff --git a/src/backend/backup/basebackup_incremental.c b/src/backend/backup/basebackup_incremental.c
index 9e1973b2d3..c23bb40bc9 100644
--- a/src/backend/backup/basebackup_incremental.c
+++ b/src/backend/backup/basebackup_incremental.c
@@ -193,12 +193,18 @@ AppendIncrementalManifestData(IncrementalBackupInfo *ib, const char *data,
 	/* Switch to our memory context. */
 	oldcontext = MemoryContextSwitchTo(ib->mcxt);
 
-	if (ib->buf.len >= MIN_CHUNK && ib->buf.len + len > MAX_CHUNK)
+	if (ib->buf.len > MIN_CHUNK && ib->buf.len + len > MAX_CHUNK)
 	{
 		/*
 		 * time for an incremental parse. We'll do all but the last but so
 		 * that we have enough left for the final piece.
 		 */
+		char chunk_start[100], chunk_end[100];
+
+		snprintf(chunk_start, 100, "%s", ib->buf.data);
+		snprintf(chunk_end, 100, "%s", ib->buf.data + (ib->buf.len - (MIN_CHUNK + 99)));
+		elog(NOTICE,"incremental manifest:\nchunk_start='%s',\nchunk_end='%s'", chunk_start, chunk_end);
+
 		json_parse_manifest_incremental_chunk(
 											  ib->inc_state, ib->buf.data, ib->buf.len - MIN_CHUNK, false);
 		/* now remove what we just parsed  */
@@ -224,6 +230,13 @@ FinalizeIncrementalManifest(IncrementalBackupInfo *ib)
 	/* Switch to our memory context. */
 	oldcontext = MemoryContextSwitchTo(ib->mcxt);
 
+	{
+		char chunk_start[100];
+
+		snprintf(chunk_start, 100, "%s", ib->buf.data);
+		elog(NOTICE,"incremental manifest:\nfinal chunk_start='%s'", chunk_start);
+	}
+
 	/* parse the last chunk of the manifest */
 	json_parse_manifest_incremental_chunk(
 										  ib->inc_state, ib->buf.data, ib->buf.len, true);
diff --git a/src/bin/pg_combinebackup/t/003_timeline.pl b/src/bin/pg_combinebackup/t/003_timeline.pl
index 82bd886c87..243081e134 100644
--- a/src/bin/pg_combinebackup/t/003_timeline.pl
+++ b/src/bin/pg_combinebackup/t/003_timeline.pl
@@ -35,6 +35,8 @@ EOM
 
 # Now take an incremental backup.
 my $backup2path = $node1->backup_dir . '/backup2';
+my $manifest = slurp_file("$backup1path/backup_manifest");
+note "$backup1path/backup_manifest:\n$manifest";
 $node1->command_ok(
 	[ 'pg_basebackup', '-D', $backup2path, '--no-sync', '-cfast',
 	  '--incremental', $backup1path . '/backup_manifest' ],
diff --git a/src/common/parse_manifest.c b/src/common/parse_manifest.c
index ef68b41726..774039bb66 100644
--- a/src/common/parse_manifest.c
+++ b/src/common/parse_manifest.c
@@ -607,8 +607,11 @@ json_manifest_finalize_file(JsonManifestParseState *parse)
 	/* Parse size. */
 	size = strtoul(parse->size, &ep, 10);
 	if (*ep)
-		json_manifest_parse_failure(parse->context,
-									"file size is not an integer");
+	{
+		char msg[200];
+		snprintf(msg, 200, "file size is not an integer: '%s'", parse->size);
+		json_manifest_parse_failure(parse->context, msg);
+	}
 
 	/* Parse the checksum algorithm, if it's present. */
 	if (parse->algorithm == NULL)
-- 
2.34.1

