Skip to content

Commit c052651

Browse files
committed
PGPRO-2432: Expand 04a7d45 to usual files
1 parent 04a7d45 commit c052651

File tree

1 file changed

+31
-26
lines changed

1 file changed

+31
-26
lines changed

src/parsexlog.c

Lines changed: 31 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,9 @@ typedef struct XLogPageReadPrivate
9393
TimeLineID tli;
9494
uint32 xlog_seg_size;
9595

96+
char page_buf[XLOG_BLCKSZ];
97+
uint32 prev_page_off;
98+
9699
bool manual_switch;
97100
bool need_switch;
98101

@@ -104,9 +107,6 @@ typedef struct XLogPageReadPrivate
104107
#ifdef HAVE_LIBZ
105108
gzFile gz_xlogfile;
106109
char gz_xlogpath[MAXPGPATH];
107-
108-
char gz_buf[XLOG_BLCKSZ];
109-
uint32 gz_prev_off;
110110
#endif
111111
} XLogPageReadPrivate;
112112

@@ -1040,6 +1040,17 @@ SimpleXLogPageRead(XLogReaderState *xlogreader, XLogRecPtr targetPagePtr,
10401040
*/
10411041
Assert(private_data->xlogexists);
10421042

1043+
/*
1044+
* Do not read same page read earlier from the file, read it from the buffer
1045+
*/
1046+
if (private_data->prev_page_off != 0 &&
1047+
private_data->prev_page_off == targetPageOff)
1048+
{
1049+
memcpy(readBuf, private_data->page_buf, XLOG_BLCKSZ);
1050+
*pageTLI = private_data->tli;
1051+
return XLOG_BLCKSZ;
1052+
}
1053+
10431054
/* Read the requested page */
10441055
if (private_data->xlogfile != -1)
10451056
{
@@ -1060,34 +1071,28 @@ SimpleXLogPageRead(XLogReaderState *xlogreader, XLogRecPtr targetPagePtr,
10601071
#ifdef HAVE_LIBZ
10611072
else
10621073
{
1063-
if (private_data->gz_prev_off != 0 &&
1064-
private_data->gz_prev_off == targetPageOff)
1065-
memcpy(readBuf, private_data->gz_buf, XLOG_BLCKSZ);
1066-
else
1074+
if (gzseek(private_data->gz_xlogfile, (z_off_t) targetPageOff, SEEK_SET) == -1)
10671075
{
1068-
if (gzseek(private_data->gz_xlogfile, (z_off_t) targetPageOff, SEEK_SET) == -1)
1069-
{
1070-
elog(WARNING, "Thread [%d]: Could not seek in compressed WAL segment \"%s\": %s",
1071-
private_data->thread_num,
1072-
private_data->gz_xlogpath,
1073-
get_gz_error(private_data->gz_xlogfile));
1074-
return -1;
1075-
}
1076+
elog(WARNING, "Thread [%d]: Could not seek in compressed WAL segment \"%s\": %s",
1077+
private_data->thread_num,
1078+
private_data->gz_xlogpath,
1079+
get_gz_error(private_data->gz_xlogfile));
1080+
return -1;
1081+
}
10761082

1077-
if (gzread(private_data->gz_xlogfile, readBuf, XLOG_BLCKSZ) != XLOG_BLCKSZ)
1078-
{
1079-
elog(WARNING, "Thread [%d]: Could not read from compressed WAL segment \"%s\": %s",
1080-
private_data->thread_num,
1081-
private_data->gz_xlogpath,
1082-
get_gz_error(private_data->gz_xlogfile));
1083-
return -1;
1084-
}
1085-
private_data->gz_prev_off = targetPageOff;
1086-
memcpy(private_data->gz_buf, readBuf, XLOG_BLCKSZ);
1083+
if (gzread(private_data->gz_xlogfile, readBuf, XLOG_BLCKSZ) != XLOG_BLCKSZ)
1084+
{
1085+
elog(WARNING, "Thread [%d]: Could not read from compressed WAL segment \"%s\": %s",
1086+
private_data->thread_num,
1087+
private_data->gz_xlogpath,
1088+
get_gz_error(private_data->gz_xlogfile));
1089+
return -1;
10871090
}
10881091
}
10891092
#endif
10901093

1094+
memcpy(private_data->page_buf, readBuf, XLOG_BLCKSZ);
1095+
private_data->prev_page_off = targetPageOff;
10911096
*pageTLI = private_data->tli;
10921097
return XLOG_BLCKSZ;
10931098
}
@@ -1142,9 +1147,9 @@ CleanupXLogPageRead(XLogReaderState *xlogreader)
11421147
{
11431148
gzclose(private_data->gz_xlogfile);
11441149
private_data->gz_xlogfile = NULL;
1145-
private_data->gz_prev_off = 0;
11461150
}
11471151
#endif
1152+
private_data->prev_page_off = 0;
11481153
private_data->xlogexists = false;
11491154
}
11501155

0 commit comments

Comments
 (0)