1
0
mirror of https://github.com/postgrespro/pg_probackup.git synced 2024-11-28 09:33:54 +02:00

Remove unnecessary do_deletewal() function

This commit is contained in:
Arthur Zakirov 2017-04-25 13:49:16 +03:00
parent c8d5e0338d
commit 61475a8292
3 changed files with 23 additions and 54 deletions

View File

@ -341,9 +341,9 @@ catalog_get_last_data_backup(parray *backup_list, TimeLineID tli)
pgBackup *backup = NULL;
/* backup_list is sorted in order of descending ID */
for (i = 0; i < parray_num(backup_list); i++)
for (i = (int) parray_num(backup_list) - 1; i >= 0; i--)
{
backup = (pgBackup *) parray_get(backup_list, i);
backup = (pgBackup *) parray_get(backup_list, (size_t) i);
if (backup->status == BACKUP_STATUS_OK && backup->tli == tli)
return backup;

View File

@ -26,6 +26,8 @@ do_delete(time_t backup_id)
*delete_list;
time_t parent_id = 0;
bool backup_found = false;
XLogRecPtr oldest_lsn = InvalidXLogRecPtr;
TimeLineID oldest_tli = 0;
/* DATE are always required */
if (backup_id == 0)
@ -90,62 +92,30 @@ do_delete(time_t backup_id)
pgBackupDeleteFiles(backup);
}
/* Clean WAL segments */
if (delete_wal)
{
/* Find oldest LSN, used by backups */
for (i = (int) parray_num(backup_list) - 1; i >= 0; i--)
{
pgBackup *backup = (pgBackup *) parray_get(backup_list, (size_t) i);
if (backup->status == BACKUP_STATUS_OK)
{
oldest_lsn = backup->start_lsn;
oldest_tli = backup->tli;
break;
}
}
delete_walfiles(oldest_lsn, oldest_tli, true);
}
/* cleanup */
parray_free(delete_list);
parray_walk(backup_list, pgBackupFree);
parray_free(backup_list);
if (delete_wal)
do_deletewal(backup_id, false, false);
return 0;
}
/*
* Delete in archive WAL segments that are not needed anymore. The oldest
* segment to be kept is the first segment that the oldest full backup
* found around needs to keep.
*/
int
do_deletewal(time_t backup_id, bool strict, bool need_catalog_lock)
{
size_t i;
parray *backup_list;
XLogRecPtr oldest_lsn = InvalidXLogRecPtr;
TimeLineID oldest_tli;
bool backup_found = false;
/* Get exclusive lock of backup catalog */
if (need_catalog_lock)
catalog_lock();
/* Find oldest LSN, used by backups */
backup_list = catalog_get_backup_list(INVALID_BACKUP_ID);
for (i = 0; i < parray_num(backup_list); i++)
{
pgBackup *last_backup = (pgBackup *) parray_get(backup_list, i);
if (last_backup->status == BACKUP_STATUS_OK)
{
oldest_lsn = last_backup->start_lsn;
oldest_tli = last_backup->tli;
if (strict && backup_id != 0 && backup_id >= last_backup->start_time)
{
backup_found = true;
break;
}
}
}
if (strict && backup_id != 0 && backup_found == false)
elog(ERROR, "not found backup for deletwal command");
parray_walk(backup_list, pgBackupFree);
parray_free(backup_list);
delete_walfiles(oldest_lsn, oldest_tli, true);
return 0;
}

View File

@ -287,7 +287,6 @@ extern int do_show(time_t requested_backup_id);
/* in delete.c */
extern int do_delete(time_t backup_id);
extern int do_deletewal(time_t backup_id, bool strict, bool need_catalog_lock);
extern int do_retention_purge(void);
/* in fetch.c */