On Thu, Sep 5, 2019 at 11:40 PM Robert Haas <robertmh...@gmail.com> wrote:
> On Fri, Aug 30, 2019 at 7:05 AM Jeevan Ladhe > <jeevan.la...@enterprisedb.com> wrote: > >> Fixed both comments in the attached patch. > > > > Thanks, the patch looks good to me. > > Here's a version of the patch with a further change to the wording of > the comment. I hope this is clearer. > Yep. > > I think this needs to be back-patched all the way back to 9.4, and it > doesn't seem to apply cleanly before v11. Any chance you could > prepare a version for the older branches? > Attached patch for v10 and pre. The same v10 patch applies cleanly. Changes related to the page checksum verification is not present on v10 and pre, and thus those changes are not applicable, so removed those. Also, wal_segment_size is XLogSegSize over there, adjusted that. > > Thanks, > > -- > Robert Haas > EnterpriseDB: http://www.enterprisedb.com > The Enterprise PostgreSQL Company > Thanks -- Jeevan Chalke Technical Architect, Product Development EnterpriseDB Corporation The Enterprise PostgreSQL Company
diff --git a/src/backend/replication/basebackup.c b/src/backend/replication/basebackup.c index ba4937b..dfb0f47 100644 --- a/src/backend/replication/basebackup.c +++ b/src/backend/replication/basebackup.c @@ -85,6 +85,18 @@ static char *statrelpath = NULL; */ #define THROTTLING_FREQUENCY 8 +/* + * Checks whether we encountered any error in fread(). fread() doesn't give + * any clue what has happened, so we check with ferror(). Also, neither + * fread() nor ferror() set errno, so we just throw a generic error. + */ +#define CHECK_FREAD_ERROR(fp, filename) \ +do { \ + if (ferror(fp)) \ + ereport(ERROR, \ + (errmsg("could not read from file \"%s\"", filename))); \ +} while (0) + /* The actual number of bytes, transfer of which may cause sleep. */ static uint64 throttling_sample; @@ -509,6 +521,8 @@ perform_base_backup(basebackup_options *opt, DIR *tblspcdir) break; } + CHECK_FREAD_ERROR(fp, pathbuf); + if (len != XLogSegSize) { CheckXLogRemoved(segno, tli); @@ -1245,6 +1259,8 @@ sendFile(char *readfilename, char *tarfilename, struct stat *statbuf, } } + CHECK_FREAD_ERROR(fp, readfilename); + /* If the file was truncated while we were sending it, pad it with zeros */ if (len < statbuf->st_size) {