Skip to content

Commit 6a95d7c

Browse files
committed
PGPRO-427: A little optimization in process_block_change()
1 parent dac3958 commit 6a95d7c

File tree

2 files changed

+31
-10
lines changed

2 files changed

+31
-10
lines changed

src/backup.c

Lines changed: 30 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,11 @@ static void check_system_identifiers(void);
130130
static void confirm_block_size(const char *name, int blcksz);
131131
static void set_cfs_datafiles(parray *files, const char *root, char *relative, size_t i);
132132

133+
/*
134+
* A little optimization used in process_block_change().
135+
*/
136+
static pgFile *last_used_file = NULL;
137+
133138

134139
#define disconnect_and_exit(code) \
135140
{ \
@@ -500,6 +505,7 @@ do_backup_instance(void)
500505
}
501506
else
502507
current.tli = get_current_timeline(false);
508+
503509
/*
504510
* In incremental backup mode ensure that already-validated
505511
* backup on current timeline exists and get its filelist.
@@ -509,6 +515,7 @@ do_backup_instance(void)
509515
current.backup_mode == BACKUP_MODE_DIFF_DELTA)
510516
{
511517
parray *backup_list;
518+
512519
/* get list of backups already taken */
513520
backup_list = catalog_get_backup_list(INVALID_BACKUP_ID);
514521
if (backup_list == NULL)
@@ -628,6 +635,9 @@ do_backup_instance(void)
628635
*/
629636
if (current.backup_mode == BACKUP_MODE_DIFF_PAGE)
630637
{
638+
/* Just in case initialize it to NULL */
639+
last_used_file = NULL;
640+
631641
/*
632642
* Build the page map. Obtain information about changed pages
633643
* reading WAL segments present in archives up to the point
@@ -2318,11 +2328,11 @@ datasegpath(RelFileNode rnode, ForkNumber forknum, BlockNumber segno)
23182328
void
23192329
process_block_change(ForkNumber forknum, RelFileNode rnode, BlockNumber blkno)
23202330
{
2321-
char *path;
2322-
char *rel_path;
2331+
char *path;
2332+
char *rel_path;
23232333
BlockNumber blkno_inseg;
23242334
int segno;
2325-
pgFile *file_item = NULL;
2335+
pgFile *file_item = NULL;
23262336
int j;
23272337

23282338
segno = blkno / RELSEG_SIZE;
@@ -2332,14 +2342,24 @@ process_block_change(ForkNumber forknum, RelFileNode rnode, BlockNumber blkno)
23322342
path = pg_malloc(strlen(rel_path) + strlen(pgdata) + 2);
23332343
sprintf(path, "%s/%s", pgdata, rel_path);
23342344

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
23362352
{
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++)
23402354
{
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+
}
23432363
}
23442364
}
23452365

@@ -2443,7 +2463,7 @@ make_pagemap_from_ptrack(parray *files)
24432463
}
24442464
else
24452465
{
2446-
file->pagemap.bitmapsize = RELSEG_SIZE/HEAPBLOCKS_PER_BYTE;
2466+
file->pagemap.bitmapsize = RELSEG_SIZE/HEAPBLOCKS_PER_BYTE;
24472467
elog(VERBOSE, "pagemap size: %i", file->pagemap.bitmapsize);
24482468
}
24492469

src/parsexlog.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,7 @@ extractPageMap(const char *archivedir, XLogRecPtr startpoint, TimeLineID tli,
193193
for (i = 0; i < parray_num(files); i++)
194194
{
195195
pgFile *file = (pgFile *) parray_get(files, i);
196+
196197
if (file->is_datafile && file->pagemap.bitmap == NULL)
197198
file->pagemap.bitmapsize = PageBitmapIsEmpty;
198199
}

0 commit comments

Comments
 (0)