[PATCH]A minor improvement to the error-report in SimpleLruWriteAll()

From: "Long Song" <songlong88(at)126(dot)com>
To: pgsql-hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: [PATCH]A minor improvement to the error-report in SimpleLruWriteAll()
Date: 2024-05-25 10:29:00
Message-ID: 4b07eb8f.27a6.18faf1164a5.Coremail.songlong88@126.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Hi hackers,
When I read the code, I noticed that in SimpleLruWriteAll(), only the last error is
recorded when the file fails to close. Like the following,
```void
SimpleLruWriteAll(SlruCtl ctl, bool allow_redirtied)
{
SlruShared shared = ctl->shared;
SlruWriteAllData fdata;
int64 pageno = 0;
int prevbank = SlotGetBankNumber(0);
bool ok;
...
/*
* Now close any files that were open
*/
ok = true;
for (int i = 0; i < fdata.num_files; i++)
{
if (CloseTransientFile(fdata.fd[i]) != 0)
{
slru_errcause = SLRU_CLOSE_FAILED;
slru_errno = errno;
pageno = fdata.segno[i] * SLRU_PAGES_PER_SEGMENT;
ok = false;
}
}
if (!ok)
SlruReportIOError(ctl, pageno, InvalidTransactionId);
```
// Here, SlruReportIOError() is called only once, meaning that the last error message is
recorded. In my opinion, since failure to close a file is not common, logging an error
message every time a failure occurs will not result in much log growth, but detailed error
logging will help in most cases.

So, I changed the code to move the call to SlruReportIOError() inside the while loop.

Attached is the patch, I hope it can help.

Attachment Content-Type Size
v1-0001-Fix-error-report-missing-of-SimpleLruWriteAll.patch application/octet-stream 1.5 KB

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Jelte Fennema-Nio 2024-05-25 10:39:58 Re: Add new protocol message to change GUCs for usage with future protocol-only GUCs
Previous Message Jelte Fennema-Nio 2024-05-25 10:23:11 Re: Add new protocol message to change GUCs for usage with future protocol-only GUCs