@@ -93,6 +93,9 @@ typedef struct XLogPageReadPrivate
93
93
TimeLineID tli ;
94
94
uint32 xlog_seg_size ;
95
95
96
+ char page_buf [XLOG_BLCKSZ ];
97
+ uint32 prev_page_off ;
98
+
96
99
bool manual_switch ;
97
100
bool need_switch ;
98
101
@@ -104,9 +107,6 @@ typedef struct XLogPageReadPrivate
104
107
#ifdef HAVE_LIBZ
105
108
gzFile gz_xlogfile ;
106
109
char gz_xlogpath [MAXPGPATH ];
107
-
108
- char gz_buf [XLOG_BLCKSZ ];
109
- uint32 gz_prev_off ;
110
110
#endif
111
111
} XLogPageReadPrivate ;
112
112
@@ -1040,6 +1040,17 @@ SimpleXLogPageRead(XLogReaderState *xlogreader, XLogRecPtr targetPagePtr,
1040
1040
*/
1041
1041
Assert (private_data -> xlogexists );
1042
1042
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
+
1043
1054
/* Read the requested page */
1044
1055
if (private_data -> xlogfile != -1 )
1045
1056
{
@@ -1060,34 +1071,28 @@ SimpleXLogPageRead(XLogReaderState *xlogreader, XLogRecPtr targetPagePtr,
1060
1071
#ifdef HAVE_LIBZ
1061
1072
else
1062
1073
{
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 )
1067
1075
{
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
+ }
1076
1082
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 ;
1087
1090
}
1088
1091
}
1089
1092
#endif
1090
1093
1094
+ memcpy (private_data -> page_buf , readBuf , XLOG_BLCKSZ );
1095
+ private_data -> prev_page_off = targetPageOff ;
1091
1096
* pageTLI = private_data -> tli ;
1092
1097
return XLOG_BLCKSZ ;
1093
1098
}
@@ -1142,9 +1147,9 @@ CleanupXLogPageRead(XLogReaderState *xlogreader)
1142
1147
{
1143
1148
gzclose (private_data -> gz_xlogfile );
1144
1149
private_data -> gz_xlogfile = NULL ;
1145
- private_data -> gz_prev_off = 0 ;
1146
1150
}
1147
1151
#endif
1152
+ private_data -> prev_page_off = 0 ;
1148
1153
private_data -> xlogexists = false;
1149
1154
}
1150
1155
0 commit comments