1
0
mirror of https://github.com/postgrespro/pg_probackup.git synced 2025-02-14 14:59:52 +02:00

PGPRO-2432: Improve reading of compressed WAL's if Postgrestries to read same record many times

This commit is contained in:
Arthur Zakirov 2019-02-11 15:16:59 +03:00
parent bed0a45121
commit 04a7d45647

View File

@ -104,6 +104,9 @@ typedef struct XLogPageReadPrivate
#ifdef HAVE_LIBZ #ifdef HAVE_LIBZ
gzFile gz_xlogfile; gzFile gz_xlogfile;
char gz_xlogpath[MAXPGPATH]; char gz_xlogpath[MAXPGPATH];
char gz_buf[XLOG_BLCKSZ];
uint32 gz_prev_off;
#endif #endif
} XLogPageReadPrivate; } XLogPageReadPrivate;
@ -1057,22 +1060,30 @@ SimpleXLogPageRead(XLogReaderState *xlogreader, XLogRecPtr targetPagePtr,
#ifdef HAVE_LIBZ #ifdef HAVE_LIBZ
else else
{ {
if (gzseek(private_data->gz_xlogfile, (z_off_t) targetPageOff, SEEK_SET) == -1) if (private_data->gz_prev_off != 0 &&
private_data->gz_prev_off == targetPageOff)
memcpy(readBuf, private_data->gz_buf, XLOG_BLCKSZ);
else
{ {
elog(WARNING, "Thread [%d]: Could not seek in compressed WAL segment \"%s\": %s", if (gzseek(private_data->gz_xlogfile, (z_off_t) targetPageOff, SEEK_SET) == -1)
private_data->thread_num, {
private_data->gz_xlogpath, elog(WARNING, "Thread [%d]: Could not seek in compressed WAL segment \"%s\": %s",
get_gz_error(private_data->gz_xlogfile)); private_data->thread_num,
return -1; private_data->gz_xlogpath,
} get_gz_error(private_data->gz_xlogfile));
return -1;
}
if (gzread(private_data->gz_xlogfile, readBuf, XLOG_BLCKSZ) != XLOG_BLCKSZ) if (gzread(private_data->gz_xlogfile, readBuf, XLOG_BLCKSZ) != XLOG_BLCKSZ)
{ {
elog(WARNING, "Thread [%d]: Could not read from compressed WAL segment \"%s\": %s", elog(WARNING, "Thread [%d]: Could not read from compressed WAL segment \"%s\": %s",
private_data->thread_num, private_data->thread_num,
private_data->gz_xlogpath, private_data->gz_xlogpath,
get_gz_error(private_data->gz_xlogfile)); get_gz_error(private_data->gz_xlogfile));
return -1; return -1;
}
private_data->gz_prev_off = targetPageOff;
memcpy(private_data->gz_buf, readBuf, XLOG_BLCKSZ);
} }
} }
#endif #endif
@ -1131,6 +1142,7 @@ CleanupXLogPageRead(XLogReaderState *xlogreader)
{ {
gzclose(private_data->gz_xlogfile); gzclose(private_data->gz_xlogfile);
private_data->gz_xlogfile = NULL; private_data->gz_xlogfile = NULL;
private_data->gz_prev_off = 0;
} }
#endif #endif
private_data->xlogexists = false; private_data->xlogexists = false;