@@ -130,6 +130,11 @@ static void check_system_identifiers(void);
130
130
static void confirm_block_size (const char * name , int blcksz );
131
131
static void set_cfs_datafiles (parray * files , const char * root , char * relative , size_t i );
132
132
133
+ /*
134
+ * A little optimization used in process_block_change().
135
+ */
136
+ static pgFile * last_used_file = NULL ;
137
+
133
138
134
139
#define disconnect_and_exit (code ) \
135
140
{ \
@@ -500,6 +505,7 @@ do_backup_instance(void)
500
505
}
501
506
else
502
507
current .tli = get_current_timeline (false);
508
+
503
509
/*
504
510
* In incremental backup mode ensure that already-validated
505
511
* backup on current timeline exists and get its filelist.
@@ -509,6 +515,7 @@ do_backup_instance(void)
509
515
current .backup_mode == BACKUP_MODE_DIFF_DELTA )
510
516
{
511
517
parray * backup_list ;
518
+
512
519
/* get list of backups already taken */
513
520
backup_list = catalog_get_backup_list (INVALID_BACKUP_ID );
514
521
if (backup_list == NULL )
@@ -628,6 +635,9 @@ do_backup_instance(void)
628
635
*/
629
636
if (current .backup_mode == BACKUP_MODE_DIFF_PAGE )
630
637
{
638
+ /* Just in case initialize it to NULL */
639
+ last_used_file = NULL ;
640
+
631
641
/*
632
642
* Build the page map. Obtain information about changed pages
633
643
* reading WAL segments present in archives up to the point
@@ -2318,11 +2328,11 @@ datasegpath(RelFileNode rnode, ForkNumber forknum, BlockNumber segno)
2318
2328
void
2319
2329
process_block_change (ForkNumber forknum , RelFileNode rnode , BlockNumber blkno )
2320
2330
{
2321
- char * path ;
2322
- char * rel_path ;
2331
+ char * path ;
2332
+ char * rel_path ;
2323
2333
BlockNumber blkno_inseg ;
2324
2334
int segno ;
2325
- pgFile * file_item = NULL ;
2335
+ pgFile * file_item = NULL ;
2326
2336
int j ;
2327
2337
2328
2338
segno = blkno / RELSEG_SIZE ;
@@ -2332,14 +2342,24 @@ process_block_change(ForkNumber forknum, RelFileNode rnode, BlockNumber blkno)
2332
2342
path = pg_malloc (strlen (rel_path ) + strlen (pgdata ) + 2 );
2333
2343
sprintf (path , "%s/%s" , pgdata , rel_path );
2334
2344
2335
- for (j = 0 ; j < parray_num (backup_files_list ); j ++ )
2345
+ /*
2346
+ * Little optimization in case if we need the same file as in the previoius
2347
+ * call.
2348
+ */
2349
+ if (last_used_file && strcmp (last_used_file -> path , path ) == 0 )
2350
+ file_item = last_used_file ;
2351
+ else
2336
2352
{
2337
- pgFile * p = (pgFile * ) parray_get (backup_files_list , j );
2338
-
2339
- if (strcmp (p -> path , path ) == 0 )
2353
+ for (j = 0 ; j < parray_num (backup_files_list ); j ++ )
2340
2354
{
2341
- file_item = p ;
2342
- break ;
2355
+ pgFile * p = (pgFile * ) parray_get (backup_files_list , j );
2356
+
2357
+ if (strcmp (p -> path , path ) == 0 )
2358
+ {
2359
+ file_item = p ;
2360
+ last_used_file = p ;
2361
+ break ;
2362
+ }
2343
2363
}
2344
2364
}
2345
2365
@@ -2443,7 +2463,7 @@ make_pagemap_from_ptrack(parray *files)
2443
2463
}
2444
2464
else
2445
2465
{
2446
- file -> pagemap .bitmapsize = RELSEG_SIZE /HEAPBLOCKS_PER_BYTE ;
2466
+ file -> pagemap .bitmapsize = RELSEG_SIZE /HEAPBLOCKS_PER_BYTE ;
2447
2467
elog (VERBOSE , "pagemap size: %i" , file -> pagemap .bitmapsize );
2448
2468
}
2449
2469
0 commit comments