Fix the error message when failing to restore the snapshot

Started by Zhijie Hou (Fujitsu)over 2 years ago2 messages
#1Zhijie Hou (Fujitsu)
houzj.fnst@fujitsu.com
1 attachment(s)

Hi,

While testing the logical snapshot restore functionality, I noticed the
data size reported in the error message seems not correct.

I think it's because we used a const value here:

SnapBuildRestoreContents(int fd, char *dest, Size size, const char *path)
...
readBytes = read(fd, dest, size);
pgstat_report_wait_end();
if (readBytes != size)
...
ereport(ERROR,
(errcode(ERRCODE_DATA_CORRUPTED),
errmsg("could not read file \"%s\": read %d of %zu",
** path, readBytes, * sizeof(SnapBuild) *)));

I think we need to pass the size here.

Attach a small patch to fix this. BTW, the error message exists in HEAD ~ PG10.

Best Regards,
Hou zj

Attachments:

0001-Fix-the-error-message-when-failing-to-restore-the-sn.patchapplication/octet-stream; name=0001-Fix-the-error-message-when-failing-to-restore-the-sn.patchDownload
From a28a59d24ffd75c7f5815e799e131ab864c7bd10 Mon Sep 17 00:00:00 2001
From: Hou Zhijie <houzj.fnst@cn.fujitsu.com>
Date: Tue, 22 Aug 2023 20:21:47 +0800
Subject: [PATCH] Fix the error message when failing to restore the snapshot

The snapbuild restore function used a const value in the error message to
indicate the size in bytes it was expecting to read from the serialized
snapshot file. Fix it by reporting the size that was actually passed.
---
 src/backend/replication/logical/snapbuild.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/backend/replication/logical/snapbuild.c b/src/backend/replication/logical/snapbuild.c
index 843ceba840..fec190a8b2 100644
--- a/src/backend/replication/logical/snapbuild.c
+++ b/src/backend/replication/logical/snapbuild.c
@@ -2039,7 +2039,7 @@ SnapBuildRestoreContents(int fd, char *dest, Size size, const char *path)
 			ereport(ERROR,
 					(errcode(ERRCODE_DATA_CORRUPTED),
 					 errmsg("could not read file \"%s\": read %d of %zu",
-							path, readBytes, sizeof(SnapBuild))));
+							path, readBytes, size)));
 	}
 }
 
-- 
2.30.0.windows.2

#2Amit Kapila
amit.kapila16@gmail.com
In reply to: Zhijie Hou (Fujitsu) (#1)
Re: Fix the error message when failing to restore the snapshot

On Tue, Aug 22, 2023 at 6:09 PM Zhijie Hou (Fujitsu)
<houzj.fnst@fujitsu.com> wrote:

While testing the logical snapshot restore functionality, I noticed the
data size reported in the error message seems not correct.

I think it's because we used a const value here:

SnapBuildRestoreContents(int fd, char *dest, Size size, const char *path)
...
readBytes = read(fd, dest, size);
pgstat_report_wait_end();
if (readBytes != size)
...
ereport(ERROR,
(errcode(ERRCODE_DATA_CORRUPTED),
errmsg("could not read file \"%s\": read %d of %zu",
** path, readBytes, * sizeof(SnapBuild) *)));

I think we need to pass the size here.

Good catch. I'll take care of this.

--
With Regards,
Amit Kapila.