@@ -104,18 +104,20 @@ extractPageMap(const char *archivedir, XLogRecPtr startpoint, TimeLineID tli,
104
104
void
105
105
validate_wal (pgBackup * backup ,
106
106
const char * archivedir ,
107
- XLogRecPtr startpoint ,
108
107
time_t target_time ,
109
- TransactionId recovery_target_xid ,
108
+ TransactionId target_xid ,
110
109
TimeLineID tli )
111
110
{
111
+ XLogRecPtr startpoint = backup -> start_lsn ;
112
112
XLogRecord * record ;
113
113
XLogReaderState * xlogreader ;
114
114
char * errormsg ;
115
115
XLogPageReadPrivate private ;
116
116
TransactionId last_xid = InvalidTransactionId ;
117
117
TimestampTz last_time = 0 ;
118
- char timestamp [100 ];
118
+ char timestamp [100 ];
119
+ bool all_wal = false,
120
+ got_endpoint = false;
119
121
120
122
private .archivedir = archivedir ;
121
123
private .tli = tli ;
@@ -130,32 +132,39 @@ validate_wal(pgBackup *backup,
130
132
record = XLogReadRecord (xlogreader , startpoint , & errormsg );
131
133
if (record == NULL )
132
134
{
133
- XLogRecPtr errptr ;
134
-
135
- errptr = startpoint ? startpoint : xlogreader -> EndRecPtr ;
136
- if (recovery_target_xid == InvalidTransactionId && target_time == 0 )
137
- {
138
- break ;
139
- }
140
-
141
135
if (errormsg )
142
- elog (ERROR , "could not read WAL record at %X/%X: %s" ,
143
- (uint32 ) (errptr >> 32 ), (uint32 ) (errptr ),
144
- errormsg );
145
- else
146
- elog (ERROR , "could not read WAL record at %X/%X" ,
147
- (uint32 ) (errptr >> 32 ),
148
- (uint32 ) (errptr ));
136
+ elog (WARNING , "%s" , errormsg );
137
+
138
+ break ;
149
139
}
150
140
141
+ /* Got WAL record at stop_lsn */
142
+ if (xlogreader -> ReadRecPtr == backup -> stop_lsn )
143
+ got_endpoint = true;
144
+
151
145
timestamp_record = getRecordTimestamp (xlogreader , & last_time );
152
146
if (XLogRecGetXid (xlogreader ) != InvalidTransactionId )
153
147
last_xid = XLogRecGetXid (xlogreader );
154
- if (recovery_target_xid != InvalidTransactionId && recovery_target_xid == last_xid )
155
- break ;
156
148
157
- if (target_time != 0 && timestamp_record && timestamptz_to_time_t (last_time ) >= target_time )
149
+ /* Check target xid */
150
+ if (TransactionIdIsValid (target_xid ) && target_xid == last_xid )
151
+ {
152
+ all_wal = true;
153
+ break ;
154
+ }
155
+ /* Check target time */
156
+ else if (target_time != 0 && timestamp_record && timestamptz_to_time_t (last_time ) >= target_time )
157
+ {
158
+ all_wal = true;
159
+ break ;
160
+ }
161
+ /* Stop if there are no target xid and target time */
162
+ else if (!TransactionIdIsValid (target_xid ) && target_time == 0 &&
163
+ xlogreader -> ReadRecPtr == backup -> stop_lsn )
164
+ {
165
+ all_wal = true;
158
166
break ;
167
+ }
159
168
160
169
startpoint = InvalidXLogRecPtr ; /* continue reading at next record */
161
170
}
@@ -167,7 +176,39 @@ validate_wal(pgBackup *backup,
167
176
if (last_xid == InvalidTransactionId )
168
177
last_xid = backup -> recovery_xid ;
169
178
170
- elog (INFO , "Backup validation stopped on %s time and xid:" XID_FMT , timestamp , last_xid );
179
+ /* There are all need WAL records */
180
+ if (all_wal )
181
+ elog (INFO , "Backup validation stopped on %s time and xid:" XID_FMT ,
182
+ timestamp , last_xid );
183
+ /* There are not need WAL records */
184
+ else
185
+ {
186
+ if (!got_endpoint )
187
+ elog (ERROR , "there are not enough WAL records to restore from %X/%X to %X/%X" ,
188
+ (uint32 ) (backup -> start_lsn >> 32 ),
189
+ (uint32 ) (backup -> start_lsn ),
190
+ (uint32 ) (backup -> stop_lsn >> 32 ),
191
+ (uint32 ) (backup -> stop_lsn ));
192
+ else
193
+ {
194
+ if (target_time > 0 )
195
+ time2iso (timestamp , lengthof (timestamp ),
196
+ timestamptz_to_time_t (target_time ));
197
+
198
+ if (TransactionIdIsValid (target_xid ) && target_time != 0 )
199
+ elog (WARNING , "there are not WAL records to time %s and xid " XID_FMT ,
200
+ timestamp , target_xid );
201
+ else if (TransactionIdIsValid (target_xid ))
202
+ elog (WARNING , "there are not WAL records to xid " XID_FMT ,
203
+ target_xid );
204
+ else if (target_time != 0 )
205
+ elog (WARNING , "there are not WAL records to time %s " ,
206
+ timestamp );
207
+
208
+ elog (WARNING , "recovery can be done to time %s and xid " XID_FMT ,
209
+ timestamp , last_xid );
210
+ }
211
+ }
171
212
172
213
/* clean */
173
214
XLogReaderFree (xlogreader );
0 commit comments