mirror of
				https://github.com/postgres/postgres.git
				synced 2025-11-03 09:13:20 +03:00 
			
		
		
		
	pg_upgrade: Improve error checking in rewriteVisibilityMap.
In the old logic, if read() were to return an error, we'd silently stop rewriting 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 correction by me.
This commit is contained in:
		@@ -165,6 +165,7 @@ rewriteVisibilityMap(const char *fromfile, const char *tofile, bool force)
 | 
			
		||||
	int			dst_fd = 0;
 | 
			
		||||
	char		buffer[BLCKSZ];
 | 
			
		||||
	ssize_t		bytesRead;
 | 
			
		||||
	ssize_t		totalBytesRead = 0;
 | 
			
		||||
	ssize_t		src_filesize;
 | 
			
		||||
	int			rewriteVmBytesPerPage;
 | 
			
		||||
	BlockNumber new_blkno = 0;
 | 
			
		||||
@@ -200,13 +201,23 @@ rewriteVisibilityMap(const char *fromfile, const char *tofile, bool force)
 | 
			
		||||
	 * page is empty, we skip it, mostly to avoid turning one-page visibility
 | 
			
		||||
	 * maps for small relations into two pages needlessly.
 | 
			
		||||
	 */
 | 
			
		||||
	while ((bytesRead = read(src_fd, buffer, BLCKSZ)) == BLCKSZ)
 | 
			
		||||
	while (totalBytesRead < src_filesize)
 | 
			
		||||
	{
 | 
			
		||||
		char	   *old_cur;
 | 
			
		||||
		char	   *old_break;
 | 
			
		||||
		char	   *old_blkend;
 | 
			
		||||
		PageHeaderData pageheader;
 | 
			
		||||
		bool		old_lastblk = ((BLCKSZ * (new_blkno + 1)) == src_filesize);
 | 
			
		||||
		bool		old_lastblk;
 | 
			
		||||
 | 
			
		||||
		if ((bytesRead = read(src_fd, buffer, BLCKSZ)) != BLCKSZ)
 | 
			
		||||
		{
 | 
			
		||||
			close(dst_fd);
 | 
			
		||||
			close(src_fd);
 | 
			
		||||
			return getErrorText();
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		totalBytesRead += BLCKSZ;
 | 
			
		||||
		old_lastblk = (totalBytesRead == src_filesize);
 | 
			
		||||
 | 
			
		||||
		/* Save the page header data */
 | 
			
		||||
		memcpy(&pageheader, buffer, SizeOfPageHeaderData);
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user