Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit4217bc2

Browse files
committed
[Issue#92] Overlapping chains and retention redundancy
1 parent54737fb commit4217bc2

File tree

4 files changed

+258
-93
lines changed

4 files changed

+258
-93
lines changed

‎src/catalog.c‎

Lines changed: 31 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -441,22 +441,47 @@ catalog_lock_backup_list(parray *backup_list, int from_idx, int to_idx)
441441
}
442442

443443
/*
444-
* Find thelast completed backup on given timeline
444+
* Find thelatest valid child of latest valid FULL backup on given timeline
445445
*/
446446
pgBackup*
447447
catalog_get_last_data_backup(parray*backup_list,TimeLineIDtli)
448448
{
449449
inti;
450-
pgBackup*backup=NULL;
450+
pgBackup*full_backup=NULL;
451451

452452
/* backup_list is sorted in order of descending ID */
453453
for (i=0;i<parray_num(backup_list);i++)
454454
{
455-
backup= (pgBackup*)parray_get(backup_list, (size_t)i);
455+
pgBackup*backup= (pgBackup*)parray_get(backup_list,i);
456456

457-
if ((backup->status==BACKUP_STATUS_OK||
458-
backup->status==BACKUP_STATUS_DONE)&&backup->tli==tli)
459-
returnbackup;
457+
if ((backup->backup_mode==BACKUP_MODE_FULL&&
458+
(backup->status==BACKUP_STATUS_OK||
459+
backup->status==BACKUP_STATUS_DONE))&&backup->tli==tli)
460+
{
461+
full_backup=backup;
462+
break;
463+
}
464+
}
465+
466+
/* Failed to find valid FULL backup to fulfill ancestor role */
467+
if (!full_backup)
468+
returnNULL;
469+
470+
/* FULL backup is found, lets find his latest child */
471+
for (i=0;i<parray_num(backup_list);i++)
472+
{
473+
pgBackup*backup= (pgBackup*)parray_get(backup_list,i);
474+
475+
if (is_parent(full_backup->start_time,backup, true))
476+
{
477+
478+
/* only valid descendants are acceptable */
479+
if (backup->status==BACKUP_STATUS_OK||
480+
backup->status==BACKUP_STATUS_DONE)
481+
{
482+
returnbackup;
483+
}
484+
}
460485
}
461486

462487
returnNULL;

‎src/delete.c‎

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,8 @@ int do_retention(void)
175175
if (delete_wal&& !dry_run)
176176
do_retention_wal();
177177

178+
/* TODO: consider dry-run flag */
179+
178180
if (!backup_merged)
179181
elog(INFO,"There are no backups to merge by retention policy");
180182

@@ -203,6 +205,8 @@ do_retention_internal(parray *backup_list, parray *to_keep_list, parray *to_purg
203205
inti;
204206
time_tcurrent_time;
205207

208+
parray*redundancy_full_backup_list=NULL;
209+
206210
/* For retention calculation */
207211
uint32n_full_backups=0;
208212
intcur_full_backup_num=0;
@@ -228,8 +232,19 @@ do_retention_internal(parray *backup_list, parray *to_keep_list, parray *to_purg
228232
backup->status==BACKUP_STATUS_DONE))
229233
{
230234
n_full_backups++;
235+
236+
if (n_full_backups <=instance_config.retention_redundancy)
237+
{
238+
if (!redundancy_full_backup_list)
239+
redundancy_full_backup_list=parray_new();
240+
241+
parray_append(redundancy_full_backup_list,backup);
242+
}
231243
}
232244
}
245+
/* Sort list of full backups to keep */
246+
if (redundancy_full_backup_list)
247+
parray_qsort(redundancy_full_backup_list,pgBackupCompareIdDesc);
233248
}
234249

235250
if (instance_config.retention_window>0)
@@ -242,8 +257,20 @@ do_retention_internal(parray *backup_list, parray *to_keep_list, parray *to_purg
242257
for (i= (int)parray_num(backup_list)-1;i >=0;i--)
243258
{
244259

260+
boolredundancy_keep= false;
245261
pgBackup*backup= (pgBackup*)parray_get(backup_list, (size_t)i);
246262

263+
/* check if backups FULL parent is in redundancy list */
264+
if (redundancy_full_backup_list)
265+
{
266+
pgBackup*full_backup=find_parent_full_backup(backup);
267+
268+
if (full_backup&&parray_bsearch(redundancy_full_backup_list,
269+
full_backup,
270+
pgBackupCompareIdDesc))
271+
redundancy_keep= true;
272+
}
273+
247274
/* Remember the serial number of latest valid FULL backup */
248275
if (backup->backup_mode==BACKUP_MODE_FULL&&
249276
(backup->status==BACKUP_STATUS_OK||
@@ -256,7 +283,8 @@ do_retention_internal(parray *backup_list, parray *to_keep_list, parray *to_purg
256283
* TODO: consider that ERROR backup most likely to have recovery_time == 0
257284
*/
258285
if ((days_threshold==0|| (days_threshold>backup->recovery_time))&&
259-
(instance_config.retention_redundancy <= (n_full_backups-cur_full_backup_num)))
286+
//(instance_config.retention_redundancy <= (n_full_backups - cur_full_backup_num)))
287+
(instance_config.retention_redundancy==0|| !redundancy_keep))
260288
{
261289
/* This backup is not guarded by retention
262290
*
@@ -344,6 +372,7 @@ do_retention_internal(parray *backup_list, parray *to_keep_list, parray *to_purg
344372
else
345373
actual_window= (current_time-backup->recovery_time)/(60*60*24);
346374

375+
/* TODO: add ancestor(chain full backup) ID */
347376
elog(INFO,"Backup %s, mode: %s, status: %s. Redundancy: %i/%i, Time Window: %ud/%ud. %s",
348377
base36enc(backup->start_time),
349378
pgBackupGetBackupMode(backup),

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp