Two noncritical bugs of pg_waldump

Поиск
Список
Период
Сортировка
От Kyotaro Horiguchi
Тема Two noncritical bugs of pg_waldump
Дата
Msg-id 20220127.100738.1985658263632578184.horikyota.ntt@gmail.com
обсуждение исходный текст
Ответы Re: Two noncritical bugs of pg_waldump  (Nathan Bossart <nathandbossart@gmail.com>)
Re: Two noncritical bugs of pg_waldump  (Kyotaro Horiguchi <horikyota.ntt@gmail.com>)
Список pgsql-hackers
Hello.

pg_waldump complains at the end in any case.  I noticed that the LSN
it shows in the finish message is incorrect.  (I faintly thought that
I posted about this but I didn't find it..)

> pg_waldump: fatal: error in WAL record at 0/15073F8: invalid record length at 0/1507470: wanted 24, got 0

xlogreader found the error at the record begins at 1507470, but
pg_waldump tells that error happens at 15073F8, which is actually the
beginning of the last sound record.


If I give an empty file to the tool it complains as the follows.

> pg_waldump: fatal: could not read file "hoge": No such file or directory

No, the file exists.  The cause is it reads uninitialized errno to
detect errors from the system call.  read(2) is defined to set errno
always when it returns -1 and doesn't otherwise. Thus it seems to me
that it is better to check that the return value is less than zero
than to clear errno before the call to read().

regards.

-- 
Kyotaro Horiguchi
NTT Open Source Software Center
From 773f14f01c4a5cfd334d0a80778aa819c55c1cb7 Mon Sep 17 00:00:00 2001
From: Kyotaro Horiguchi <horikyota.ntt@gmail.com>
Date: Thu, 27 Jan 2022 09:47:10 +0900
Subject: [PATCH] Fix errornious messages of pg_waldump

Fix pg_waldump to give the LSN where read error happens instead of the
LSN of the last record successfully read. And fix to give the correct
error message for zero-sized blocks instead of a bogus system-call
error message.
---
 src/bin/pg_waldump/pg_waldump.c | 15 ++++++---------
 1 file changed, 6 insertions(+), 9 deletions(-)

diff --git a/src/bin/pg_waldump/pg_waldump.c b/src/bin/pg_waldump/pg_waldump.c
index a6251e1a96..58dc4044b5 100644
--- a/src/bin/pg_waldump/pg_waldump.c
+++ b/src/bin/pg_waldump/pg_waldump.c
@@ -222,15 +222,12 @@ search_directory(const char *directory, const char *fname)
                                      WalSegSz),
                             fname, WalSegSz);
         }
+        else if (r < 0)
+            fatal_error("could not read file \"%s\": %m",
+                        fname);
         else
-        {
-            if (errno != 0)
-                fatal_error("could not read file \"%s\": %m",
-                            fname);
-            else
-                fatal_error("could not read file \"%s\": read %d of %d",
-                            fname, r, XLOG_BLCKSZ);
-        }
+            fatal_error("could not read file \"%s\": read %d of %d",
+                        fname, r, XLOG_BLCKSZ);
         close(fd);
         return true;
     }
@@ -1177,7 +1174,7 @@ main(int argc, char **argv)
 
     if (errormsg)
         fatal_error("error in WAL record at %X/%X: %s",
-                    LSN_FORMAT_ARGS(xlogreader_state->ReadRecPtr),
+                    LSN_FORMAT_ARGS(xlogreader_state->EndRecPtr),
                     errormsg);
 
     XLogReaderFree(xlogreader_state);
-- 
2.27.0


В списке pgsql-hackers по дате отправления:

Предыдущее
От: Nathan Bossart
Дата:
Сообщение: Re: Avoid erroring out when unable to remove or parse logical rewrite files to save checkpoint work
Следующее
От: Greg Nancarrow
Дата:
Сообщение: Re: row filtering for logical replication