@@ -123,27 +123,38 @@ extractPageMap(const char *archivedir, XLogRecPtr startpoint, TimeLineID tli,
123123do
124124{
125125record = XLogReadRecord (xlogreader ,startpoint ,& errormsg );
126+
126127if (record == NULL )
127128{
128129XLogRecPtr errptr ;
129130
130131errptr = startpoint ?startpoint :xlogreader -> EndRecPtr ;
131132
132133if (errormsg )
133- elog (ERROR ,"could not read WAL record at %X/%X: %s" ,
134+ elog (WARNING ,"could not read WAL record at %X/%X: %s" ,
134135 (uint32 ) (errptr >>32 ), (uint32 ) (errptr ),
135136errormsg );
136137else
137- elog (ERROR ,"could not read WAL record at %X/%X" ,
138+ elog (WARNING ,"could not read WAL record at %X/%X" ,
138139 (uint32 ) (errptr >>32 ), (uint32 ) (errptr ));
140+
141+ /*
142+ * If we don't have all WAL files from prev backup start_lsn to current
143+ * start_lsn, we won't be able to build page map and PAGE backup will
144+ * be incorrect. Stop it and throw an error.
145+ */
146+ if (!xlogexists )
147+ elog (ERROR ,"WAL segment \"%s\" is absent" ,xlogfpath );
148+ else if (xlogreadfd != -1 )
149+ elog (ERROR ,"Possible WAL CORRUPTION."
150+ "Error has occured during reading WAL segment \"%s\"" ,xlogfpath );
139151}
140152
141153extractPageInfo (xlogreader );
142154
143155startpoint = InvalidXLogRecPtr ;/* continue reading at next record */
144156
145157XLByteToSeg (xlogreader -> EndRecPtr ,nextSegNo );
146-
147158}while (nextSegNo <=endSegNo && xlogreader -> EndRecPtr != endpoint );
148159
149160XLogReaderFree (xlogreader );
@@ -228,6 +239,8 @@ validate_wal(pgBackup *backup,
228239startpoint = InvalidXLogRecPtr ;/* continue reading at next record */
229240}
230241
242+
243+ /* TODO Add comment */
231244if (last_time > 0 )
232245time2iso (last_timestamp ,lengthof (last_timestamp ),
233246timestamptz_to_time_t (last_time ));
@@ -237,33 +250,37 @@ validate_wal(pgBackup *backup,
237250if (last_xid == InvalidTransactionId )
238251last_xid = backup -> recovery_xid ;
239252
240- /* There are allneed WAL records */
253+ /* There are allneeded WAL records */
241254if (all_wal )
242255elog (INFO ,"backup validation completed successfully on time %s and xid " XID_FMT ,
243256last_timestamp ,last_xid );
244- /*There are not need WAL records */
257+ /*Some needed WAL records are absent */
245258else
246259{
247260if (xlogfpath [0 ]!= 0 )
248261{
249- /* Update backup status */
250- backup -> status = BACKUP_STATUS_CORRUPT ;
251- pgBackupWriteBackupControlFile (backup );
252-
253- /* XLOG reader couldnt read WAL segment */
262+ /* XLOG reader couldn't read WAL segment.
263+ * We throw a WARNING here to be able to update backup status below.
264+ */
254265if (!xlogexists )
266+ {
255267elog (WARNING ,"WAL segment \"%s\" is absent" ,xlogfpath );
268+ }
256269else if (xlogreadfd != -1 )
257- elog (ERROR ,"Possible WAL CORRUPTION."
258- "Error has occured during reading WAL segment \"%s\"" ,xlogfpath );
270+ {
271+ elog (WARNING ,"Possible WAL CORRUPTION."
272+ "Error has occured during reading WAL segment \"%s\"" ,xlogfpath );
273+ }
259274}
260275
261276if (!got_endpoint )
262277{
263- /* Update backup status */
278+ /*
279+ * If we don't have WAL between start_lsn and stop_lsn,
280+ * the backup is definitely corrupted. Update its status.
281+ */
264282backup -> status = BACKUP_STATUS_CORRUPT ;
265283pgBackupWriteBackupControlFile (backup );
266-
267284elog (ERROR ,"there are not enough WAL records to restore from %X/%X to %X/%X" ,
268285 (uint32 ) (backup -> start_lsn >>32 ),
269286 (uint32 ) (backup -> start_lsn ),