Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 4d51c7f

Browse files
committed
[Issue #143] review feedback implementation
1 parent 4a94fda commit 4d51c7f

File tree

7 files changed

+32
-26
lines changed

7 files changed

+32
-26
lines changed

src/catalog.c

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -615,7 +615,7 @@ catalog_get_last_data_backup(parray *backup_list, TimeLineID tli, time_t current
615615
switch (scan_parent_chain(backup, &tmp_backup))
616616
{
617617
/* broken chain */
618-
case 0:
618+
case ChainIsBroken:
619619
invalid_backup_id = base36enc_dup(tmp_backup->parent_backup);
620620

621621
elog(WARNING, "Backup %s has missing parent: %s. Cannot be a parent",
@@ -624,7 +624,7 @@ catalog_get_last_data_backup(parray *backup_list, TimeLineID tli, time_t current
624624
continue;
625625

626626
/* chain is intact, but at least one parent is invalid */
627-
case 1:
627+
case ChainIsInvalid:
628628
invalid_backup_id = base36enc_dup(tmp_backup->start_time);
629629

630630
elog(WARNING, "Backup %s has invalid parent: %s. Cannot be a parent",
@@ -633,7 +633,7 @@ catalog_get_last_data_backup(parray *backup_list, TimeLineID tli, time_t current
633633
continue;
634634

635635
/* chain is ok */
636-
case 2:
636+
case ChainIsOk:
637637
/* Yes, we could call is_parent() earlier - after choosing the ancestor,
638638
* but this way we have an opportunity to detect and report all possible
639639
* anomalies.
@@ -755,13 +755,14 @@ get_multi_timeline_parent(parray *backup_list, parray *tli_list,
755755
/* Optimistically, look on current timeline for valid incremental backup, child of ancestor */
756756
if (my_tlinfo->backups)
757757
{
758+
/* backups are sorted in descending order and we need latest valid */
758759
for (i = 0; i < parray_num(my_tlinfo->backups); i++)
759760
{
760761
pgBackup *tmp_backup = NULL;
761762
pgBackup *backup = (pgBackup *) parray_get(my_tlinfo->backups, i);
762763

763764
/* found suitable parent */
764-
if (scan_parent_chain(backup, &tmp_backup) == 2 &&
765+
if (scan_parent_chain(backup, &tmp_backup) == ChainIsOk &&
765766
is_parent(ancestor_backup->start_time, backup, false))
766767
return backup;
767768
}
@@ -786,7 +787,7 @@ get_multi_timeline_parent(parray *backup_list, parray *tli_list,
786787
if (backup->stop_lsn > tmp_tlinfo->switchpoint)
787788
continue;
788789

789-
if (scan_parent_chain(backup, &tmp_backup) == 2 &&
790+
if (scan_parent_chain(backup, &tmp_backup) == ChainIsOk &&
790791
is_parent(ancestor_backup->start_time, backup, true))
791792
return backup;
792793
}
@@ -2382,18 +2383,18 @@ scan_parent_chain(pgBackup *current_backup, pgBackup **result_backup)
23822383
{
23832384
/* Set oldest child backup in chain */
23842385
*result_backup = target_backup;
2385-
return 0;
2386+
return ChainIsBroken;
23862387
}
23872388

23882389
/* chain is ok, but some backups are invalid */
23892390
if (invalid_backup)
23902391
{
23912392
*result_backup = invalid_backup;
2392-
return 1;
2393+
return ChainIsInvalid;
23932394
}
23942395

23952396
*result_backup = target_backup;
2396-
return 2;
2397+
return ChainIsOk;
23972398
}
23982399

23992400
/*

src/parsexlog.c

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -859,23 +859,23 @@ SimpleXLogPageRead(XLogReaderState *xlogreader, XLogRecPtr targetPagePtr,
859859
char xlogfname[MAXFNAMELEN];
860860
char partial_file[MAXPGPATH];
861861

862-
GetXLogFileName(xlogfname, reader_data->tli, reader_data->xlogsegno,
863-
wal_seg_size);
864-
snprintf(reader_data->xlogpath, MAXPGPATH, "%s/%s", wal_archivedir,
865-
xlogfname);
866-
snprintf(partial_file, MAXPGPATH, "%s/%s.partial", wal_archivedir,
867-
xlogfname);
868-
snprintf(reader_data->gz_xlogpath, sizeof(reader_data->gz_xlogpath),
869-
"%s.gz", reader_data->xlogpath);
862+
GetXLogFileName(xlogfname, reader_data->tli, reader_data->xlogsegno, wal_seg_size);
863+
864+
snprintf(reader_data->xlogpath, MAXPGPATH, "%s/%s", wal_archivedir, xlogfname);
865+
snprintf(reader_data->gz_xlogpath, MAXPGPATH, "%s.gz", reader_data->xlogpath);
866+
867+
/* We fall back to using .partial segment in case if we are running
868+
* multi-timeline incremental backup right after standby promotion.
869+
* TODO: it should be explicitly enabled.
870+
*/
871+
snprintf(partial_file, MAXPGPATH, "%s.partial", reader_data->xlogpath);
870872

871873
/* If segment do not exists, but the same
872874
* segment with '.partial' suffix does, use it instead */
873875
if (!fileExists(reader_data->xlogpath, FIO_BACKUP_HOST) &&
874876
fileExists(partial_file, FIO_BACKUP_HOST))
875877
{
876-
snprintf(reader_data->xlogpath, MAXPGPATH, "%s/%s.partial", wal_archivedir,
877-
xlogfname);
878-
strncpy(reader_data->xlogpath, partial_file, MAXPGPATH);
878+
snprintf(reader_data->xlogpath, MAXPGPATH, "%s", partial_file);
879879
}
880880

881881
if (fileExists(reader_data->xlogpath, FIO_BACKUP_HOST))

src/pg_probackup.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -800,6 +800,11 @@ extern int pgBackupCompareIdEqual(const void *l, const void *r);
800800

801801
extern pgBackup* find_parent_full_backup(pgBackup *current_backup);
802802
extern int scan_parent_chain(pgBackup *current_backup, pgBackup **result_backup);
803+
/* return codes for scan_parent_chain */
804+
#define ChainIsBroken 0
805+
#define ChainIsInvalid 1
806+
#define ChainIsOk 2
807+
803808
extern bool is_parent(time_t parent_backup_time, pgBackup *child_backup, bool inclusive);
804809
extern bool is_prolific(parray *backup_list, pgBackup *target_backup);
805810
extern bool in_backup_list(parray *backup_list, pgBackup *target_backup);

src/restore.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,7 @@ do_restore_or_validate(time_t target_backup_id, pgRecoveryTarget *rt,
251251

252252
result = scan_parent_chain(dest_backup, &tmp_backup);
253253

254-
if (result == 0)
254+
if (result == ChainIsBroken)
255255
{
256256
/* chain is broken, determine missing backup ID
257257
* and orphinize all his descendants
@@ -290,7 +290,7 @@ do_restore_or_validate(time_t target_backup_id, pgRecoveryTarget *rt,
290290
/* No point in doing futher */
291291
elog(ERROR, "%s of backup %s failed.", action, base36enc(dest_backup->start_time));
292292
}
293-
else if (result == 1)
293+
else if (result == ChainIsInvalid)
294294
{
295295
/* chain is intact, but at least one parent is invalid */
296296
set_orphan_status(backups, tmp_backup);

src/validate.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -479,7 +479,7 @@ do_validate_instance(void)
479479
result = scan_parent_chain(current_backup, &tmp_backup);
480480

481481
/* chain is broken */
482-
if (result == 0)
482+
if (result == ChainIsBroken)
483483
{
484484
char *parent_backup_id;
485485
/* determine missing backup ID */
@@ -505,7 +505,7 @@ do_validate_instance(void)
505505
continue;
506506
}
507507
/* chain is whole, but at least one parent is invalid */
508-
else if (result == 1)
508+
else if (result == ChainIsInvalid)
509509
{
510510
/* Oldest corrupt backup has a chance for revalidation */
511511
if (current_backup->start_time != tmp_backup->start_time)
@@ -630,7 +630,7 @@ do_validate_instance(void)
630630
*/
631631
result = scan_parent_chain(backup, &tmp_backup);
632632

633-
if (result == 1)
633+
if (result == ChainIsInvalid)
634634
{
635635
/* revalidation make sense only if oldest invalid backup is current_backup
636636
*/

tests/page.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -819,7 +819,7 @@ def test_page_backup_with_corrupted_wal_segment(self):
819819
self.backup_node(backup_dir, 'node', node)
820820

821821
# make some wals
822-
node.pgbench_init(scale=4)
822+
node.pgbench_init(scale=10)
823823

824824
# delete last wal segment
825825
wals_dir = os.path.join(backup_dir, 'wal', 'node')

tests/validate.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1786,7 +1786,7 @@ def test_pgpro561(self):
17861786
self.assertTrue(
17871787
'LOG: archive command failed with exit code 1' in log_content and
17881788
'DETAIL: The failed archive command was:' in log_content and
1789-
'INFO: pg_probackup archive-push from' in log_content,
1789+
'WAL file already exists in archive with different checksum' in log_content,
17901790
'Expecting error messages about failed archive_command'
17911791
)
17921792
self.assertFalse(

0 commit comments

Comments
 (0)