@@ -56,7 +56,7 @@ static void
56
56
backup_data_page (pgFile * file , XLogRecPtr prev_backup_start_lsn ,
57
57
BlockNumber blknum , BlockNumber nblocks ,
58
58
FILE * in , FILE * out ,
59
- pg_crc32 * crc )
59
+ pg_crc32 * crc , int * n_skipped )
60
60
{
61
61
BackupPageHeader header ;
62
62
off_t offset ;
@@ -134,7 +134,10 @@ backup_data_page(pgFile *file, XLogRecPtr prev_backup_start_lsn,
134
134
if (!XLogRecPtrIsInvalid (prev_backup_start_lsn )
135
135
&& !XLogRecPtrIsInvalid (page_lsn )
136
136
&& page_lsn < prev_backup_start_lsn )
137
+ {
138
+ * n_skipped += 1 ;
137
139
return ;
140
+ }
138
141
139
142
/* Verify checksum */
140
143
if (current .checksum_version && !is_zero_page )
@@ -195,6 +198,8 @@ backup_data_file(const char *from_root, const char *to_root,
195
198
FILE * out ;
196
199
BlockNumber blknum = 0 ;
197
200
BlockNumber nblocks = 0 ;
201
+ int n_blocks_skipped = 0 ;
202
+ int n_blocks_read = 0 ;
198
203
199
204
/* reset size summary */
200
205
file -> read_size = 0 ;
@@ -253,26 +258,24 @@ backup_data_file(const char *from_root, const char *to_root,
253
258
if (file -> pagemap .bitmapsize == 0 )
254
259
{
255
260
for (blknum = 0 ; blknum < nblocks ; blknum ++ )
261
+ {
256
262
backup_data_page (file , prev_backup_start_lsn , blknum ,
257
- nblocks , in , out , & (file -> crc ));
263
+ nblocks , in , out , & (file -> crc ), & n_blocks_skipped );
264
+ n_blocks_read ++ ;
265
+ }
258
266
}
259
267
else
260
268
{
261
269
datapagemap_iterator_t * iter ;
262
270
iter = datapagemap_iterate (& file -> pagemap );
263
271
while (datapagemap_next (iter , & blknum ))
272
+ {
264
273
backup_data_page (file , prev_backup_start_lsn , blknum ,
265
- nblocks , in , out , & (file -> crc ));
274
+ nblocks , in , out , & (file -> crc ), & n_blocks_skipped );
275
+ n_blocks_read ++ ;
276
+ }
266
277
267
278
pg_free (iter );
268
- /*
269
- * If we have pagemap then file can't be a zero size.
270
- * Otherwise, we will clear the last file.
271
- * Increase read_size to delete after.
272
- * TODO rewrite this code
273
- */
274
- if (file -> read_size == 0 )
275
- file -> read_size ++ ;
276
279
}
277
280
278
281
/* update file permission */
@@ -294,8 +297,11 @@ backup_data_file(const char *from_root, const char *to_root,
294
297
if (file -> read_size == 0 )
295
298
file -> is_datafile = false;
296
299
297
- /* We do not backup if all pages skipped. */
298
- if (file -> write_size == 0 && file -> read_size > 0 )
300
+ /*
301
+ * If we have pagemap then file can't be a zero size.
302
+ * Otherwise, we will clear the last file.
303
+ */
304
+ if (n_blocks_read == n_blocks_skipped )
299
305
{
300
306
if (remove (to_path ) == -1 )
301
307
elog (ERROR , "cannot remove file \"%s\": %s" , to_path ,
0 commit comments