Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitaba8943

Browse files
committed
pg_upgrade: Improve error checking in rewriteVisibilityMap.
In the old logic, if read() were to return an error, we'd silently stoprewriting the visibility map at that point in the file. That's safe,but reporting the error is better, so do that instead.Report by Andres Freund. Patch by Masahiko Sawada, with one correctionby me.
1 parent6201a8e commitaba8943

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

‎src/bin/pg_upgrade/file.c

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,7 @@ rewriteVisibilityMap(const char *fromfile, const char *tofile, bool force)
165165
intdst_fd=0;
166166
charbuffer[BLCKSZ];
167167
ssize_tbytesRead;
168+
ssize_ttotalBytesRead=0;
168169
ssize_tsrc_filesize;
169170
intrewriteVmBytesPerPage;
170171
BlockNumbernew_blkno=0;
@@ -200,13 +201,23 @@ rewriteVisibilityMap(const char *fromfile, const char *tofile, bool force)
200201
* page is empty, we skip it, mostly to avoid turning one-page visibility
201202
* maps for small relations into two pages needlessly.
202203
*/
203-
while ((bytesRead=read(src_fd,buffer,BLCKSZ))==BLCKSZ)
204+
while (totalBytesRead<src_filesize)
204205
{
205206
char*old_cur;
206207
char*old_break;
207208
char*old_blkend;
208209
PageHeaderDatapageheader;
209-
boolold_lastblk= ((BLCKSZ* (new_blkno+1))==src_filesize);
210+
boolold_lastblk;
211+
212+
if ((bytesRead=read(src_fd,buffer,BLCKSZ))!=BLCKSZ)
213+
{
214+
close(dst_fd);
215+
close(src_fd);
216+
returngetErrorText();
217+
}
218+
219+
totalBytesRead+=BLCKSZ;
220+
old_lastblk= (totalBytesRead==src_filesize);
210221

211222
/* Save the page header data */
212223
memcpy(&pageheader,buffer,SizeOfPageHeaderData);

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp