@@ -123,27 +123,38 @@ extractPageMap(const char *archivedir, XLogRecPtr startpoint, TimeLineID tli,
123
123
do
124
124
{
125
125
record = XLogReadRecord (xlogreader , startpoint , & errormsg );
126
+
126
127
if (record == NULL )
127
128
{
128
129
XLogRecPtr errptr ;
129
130
130
131
errptr = startpoint ? startpoint : xlogreader -> EndRecPtr ;
131
132
132
133
if (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" ,
134
135
(uint32 ) (errptr >> 32 ), (uint32 ) (errptr ),
135
136
errormsg );
136
137
else
137
- elog (ERROR , "could not read WAL record at %X/%X" ,
138
+ elog (WARNING , "could not read WAL record at %X/%X" ,
138
139
(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 );
139
151
}
140
152
141
153
extractPageInfo (xlogreader );
142
154
143
155
startpoint = InvalidXLogRecPtr ; /* continue reading at next record */
144
156
145
157
XLByteToSeg (xlogreader -> EndRecPtr , nextSegNo );
146
-
147
158
} while (nextSegNo <= endSegNo && xlogreader -> EndRecPtr != endpoint );
148
159
149
160
XLogReaderFree (xlogreader );
@@ -228,6 +239,8 @@ validate_wal(pgBackup *backup,
228
239
startpoint = InvalidXLogRecPtr ; /* continue reading at next record */
229
240
}
230
241
242
+
243
+ /* TODO Add comment */
231
244
if (last_time > 0 )
232
245
time2iso (last_timestamp , lengthof (last_timestamp ),
233
246
timestamptz_to_time_t (last_time ));
@@ -237,33 +250,37 @@ validate_wal(pgBackup *backup,
237
250
if (last_xid == InvalidTransactionId )
238
251
last_xid = backup -> recovery_xid ;
239
252
240
- /* There are all need WAL records */
253
+ /* There are all needed WAL records */
241
254
if (all_wal )
242
255
elog (INFO , "backup validation completed successfully on time %s and xid " XID_FMT ,
243
256
last_timestamp , last_xid );
244
- /* There are not need WAL records */
257
+ /* Some needed WAL records are absent */
245
258
else
246
259
{
247
260
if (xlogfpath [0 ] != 0 )
248
261
{
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
+ */
254
265
if (!xlogexists )
266
+ {
255
267
elog (WARNING , "WAL segment \"%s\" is absent" , xlogfpath );
268
+ }
256
269
else 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
+ }
259
274
}
260
275
261
276
if (!got_endpoint )
262
277
{
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
+ */
264
282
backup -> status = BACKUP_STATUS_CORRUPT ;
265
283
pgBackupWriteBackupControlFile (backup );
266
-
267
284
elog (ERROR , "there are not enough WAL records to restore from %X/%X to %X/%X" ,
268
285
(uint32 ) (backup -> start_lsn >> 32 ),
269
286
(uint32 ) (backup -> start_lsn ),
0 commit comments