1
0
mirror of https://github.com/postgrespro/pg_probackup.git synced 2024-12-13 11:53:59 +02:00

Improve error reporting in remote backup

This commit is contained in:
Konstantin Knizhnik 2019-03-14 16:41:19 +03:00
parent cec20ccb83
commit ed81839ab8
4 changed files with 22 additions and 4 deletions

View File

@ -1052,7 +1052,7 @@ get_gz_error(gzFile gzf, int errnum)
int gz_errnum;
const char *errmsg;
errmsg = gzerror(gzf, &gz_errnum);
errmsg = fio_gzerror(gzf, &gz_errnum);
if (gz_errnum == Z_ERRNO)
return strerror(errnum);
else

View File

@ -906,7 +906,7 @@ get_gz_error(gzFile gzf)
int errnum;
const char *errmsg;
errmsg = gzerror(gzf, &errnum);
errmsg = fio_gzerror(gzf, &errnum);
if (errnum == Z_ERRNO)
return strerror(errno);
else

View File

@ -740,6 +740,7 @@ typedef struct fioGZFile
{
z_stream strm;
int fd;
int errnum;
bool compress;
bool eof;
Bytef buf[ZLIB_BUFFER_SIZE];
@ -754,7 +755,7 @@ fio_gzopen(char const* path, char const* mode, int level, fio_location location)
fioGZFile* gz = (fioGZFile*)malloc(sizeof(fioGZFile));
memset(&gz->strm, 0, sizeof(gz->strm));
gz->eof = 0;
gz->errnum = Z_OK;
if (strcmp(mode, PG_BINARY_W) == 0) /* compress */
{
gz->strm.next_out = gz->buf;
@ -838,6 +839,7 @@ fio_gzread(gzFile f, void *buf, unsigned size)
}
else if (rc != Z_OK)
{
gz->errnum = rc;
return -1;
}
if (gz->strm.avail_out != size)
@ -968,6 +970,21 @@ int fio_gzeof(gzFile f)
}
}
const char* fio_gzerror(gzFile f, int *errnum)
{
if ((size_t)f & FIO_GZ_REMOTE_MARKER)
{
fioGZFile* gz = (fioGZFile*)((size_t)f - FIO_GZ_REMOTE_MARKER);
if (errnum)
*errnum = gz->errnum;
return gz->strm.msg;
}
else
{
return gzerror(f, errnum);
}
}
z_off_t fio_gzseek(gzFile f, z_off_t offset, int whence)
{
Assert(!((size_t)f & FIO_GZ_REMOTE_MARKER));

View File

@ -49,7 +49,7 @@ typedef enum
#define PAGE_CHECKSUM_MISMATCH (-256)
#define SYS_CHECK(cmd) do if ((cmd) < 0) { fprintf(stderr, "%s:%d: (%s) %s\n", __FILE__, __LINE__, #cmd, strerror(errno)); exit(EXIT_FAILURE); } while (0)
#define IO_CHECK(cmd, size) do { int _rc = (cmd); if (_rc != (size)) { fprintf(stderr, "%s:%d: proceeds %d bytes instead of %d: %s\n", __FILE__, __LINE__, _rc, (int)(size), _rc < 0 ? "end of data" : strerror(errno)); exit(EXIT_FAILURE); } } while (0)
#define IO_CHECK(cmd, size) do { int _rc = (cmd); if (_rc != (size)) if (remote_agent) { fprintf(stderr, "%s:%d: proceeds %d bytes instead of %d: %s\n", __FILE__, __LINE__, _rc, (int)(size), _rc >= 0 ? "end of data" : strerror(errno)); exit(EXIT_FAILURE); } else elog(ERROR, "Communication error: %s", _rc >= 0 ? "end of data" : strerror(errno)); } while (0)
typedef struct
{
@ -111,6 +111,7 @@ extern int fio_gzread(gzFile f, void *buf, unsigned size);
extern int fio_gzwrite(gzFile f, void const* buf, unsigned size);
extern int fio_gzeof(gzFile f);
extern z_off_t fio_gzseek(gzFile f, z_off_t offset, int whence);
extern const char* fio_gzerror(gzFile file, int *errnum);
#endif
#endif