From 90b09d3dd0562599c6fcdb90a49e1eb8fd11caca Mon Sep 17 00:00:00 2001 From: Dmitriy Kuzmin Date: Wed, 18 Nov 2020 18:00:03 +1000 Subject: [PATCH 1/5] add wal-window option --- src/configure.c | 11 +++++++++++ src/pg_probackup.h | 1 + 2 files changed, 12 insertions(+) diff --git a/src/configure.c b/src/configure.c index 1aae3df13..41179f9b8 100644 --- a/src/configure.c +++ b/src/configure.c @@ -194,6 +194,11 @@ ConfigOption instance_options[] = &instance_config.wal_depth, SOURCE_CMD, 0, OPTION_RETENTION_GROUP, 0, option_get_value }, + { + 'u', 231, "wal-window", + &instance_config.wal_window, SOURCE_CMD, 0, + OPTION_RETENTION_GROUP, 0, option_get_value + }, /* Compression options */ { 'f', 222, "compress-algorithm", @@ -363,6 +368,7 @@ init_config(InstanceConfig *config, const char *instance_name) config->retention_redundancy = RETENTION_REDUNDANCY_DEFAULT; config->retention_window = RETENTION_WINDOW_DEFAULT; config->wal_depth = 0; + config->wal_window = 0; config->compress_alg = COMPRESS_ALG_DEFAULT; config->compress_level = COMPRESS_LEVEL_DEFAULT; @@ -541,6 +547,11 @@ readInstanceConfigFile(const char *instance_name) &instance->wal_depth, SOURCE_CMD, 0, OPTION_RETENTION_GROUP, 0, option_get_value }, + { + 'u', 231, "wal-window", + &instance->wal_window, SOURCE_CMD, 0, + OPTION_RETENTION_GROUP, 0, option_get_value + }, /* Compression options */ { 's', 222, "compress-algorithm", diff --git a/src/pg_probackup.h b/src/pg_probackup.h index b9f5cff67..09bb5cfbc 100644 --- a/src/pg_probackup.h +++ b/src/pg_probackup.h @@ -384,6 +384,7 @@ typedef struct InstanceConfig uint32 retention_redundancy; uint32 retention_window; uint32 wal_depth; + uint32 wal_window; CompressAlg compress_alg; int compress_level; From f0e88d785443d578b04433a7cd88340f7818d061 Mon Sep 17 00:00:00 2001 From: Dmitriy Kuzmin Date: Wed, 18 Nov 2020 18:00:45 +1000 Subject: [PATCH 2/5] take wal-window into account when calculating wal retention --- src/catalog.c | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/src/catalog.c b/src/catalog.c index 57da50c8d..4f25d5254 100644 --- a/src/catalog.c +++ b/src/catalog.c @@ -15,6 +15,7 @@ #include #include #include +#include #include "utils/file.h" #include "utils/configuration.h" @@ -1493,7 +1494,7 @@ catalog_get_timelines(InstanceConfig *instance) } /* determine which WAL segments must be kept because of wal retention */ - if (instance->wal_depth <= 0) + if (instance->wal_depth <= 0 && instance->wal_window <= 0) return timelineinfos; /* @@ -1559,8 +1560,19 @@ catalog_get_timelines(InstanceConfig *instance) for (i = 0; i < parray_num(timelineinfos); i++) { int count = 0; + time_t days_threshold = current_time; timelineInfo *tlinfo = parray_get(timelineinfos, i); + if (instance_config.wal_window > 0) + { + days_threshold = current_time - + (instance_config.wal_window * 60 * 60 * 24); + } + + char logts[100]; + time2iso(logts, lengthof(logts), days_threshold); + elog(LOG, "day_threshold: %s",logts); + /* * Iterate backward on backups belonging to this timeline to find * anchor_backup. NOTE Here we rely on the fact that backups list @@ -1597,7 +1609,9 @@ catalog_get_timelines(InstanceConfig *instance) count++; - if (count == instance->wal_depth) + if (count >= instance->wal_depth && + days_threshold >= backup->recovery_time) + { elog(LOG, "On timeline %i WAL is protected from purge at %X/%X", tlinfo->tli, From 93b8beea6eac51f0033467cae497c16cfbb36acf Mon Sep 17 00:00:00 2001 From: Dmitriy Kuzmin Date: Wed, 27 Jan 2021 23:12:49 +1000 Subject: [PATCH 3/5] remove unnecessary logging --- src/catalog.c | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/catalog.c b/src/catalog.c index 4f25d5254..fd8c78637 100644 --- a/src/catalog.c +++ b/src/catalog.c @@ -1569,10 +1569,6 @@ catalog_get_timelines(InstanceConfig *instance) (instance_config.wal_window * 60 * 60 * 24); } - char logts[100]; - time2iso(logts, lengthof(logts), days_threshold); - elog(LOG, "day_threshold: %s",logts); - /* * Iterate backward on backups belonging to this timeline to find * anchor_backup. NOTE Here we rely on the fact that backups list From 95b4f0563375d4c7ce78f865a6863177eed1f863 Mon Sep 17 00:00:00 2001 From: Dmitriy Kuzmin Date: Wed, 27 Jan 2021 23:19:26 +1000 Subject: [PATCH 4/5] fix style --- src/catalog.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/catalog.c b/src/catalog.c index fd8c78637..f35a51a5c 100644 --- a/src/catalog.c +++ b/src/catalog.c @@ -1560,14 +1560,14 @@ catalog_get_timelines(InstanceConfig *instance) for (i = 0; i < parray_num(timelineinfos); i++) { int count = 0; - time_t days_threshold = current_time; + time_t days_threshold = current_time; timelineInfo *tlinfo = parray_get(timelineinfos, i); - if (instance_config.wal_window > 0) - { - days_threshold = current_time - - (instance_config.wal_window * 60 * 60 * 24); - } + if (instance_config.wal_window > 0) + { + days_threshold = current_time - + (instance_config.wal_window * 60 * 60 * 24); + } /* * Iterate backward on backups belonging to this timeline to find @@ -1605,8 +1605,8 @@ catalog_get_timelines(InstanceConfig *instance) count++; - if (count >= instance->wal_depth && - days_threshold >= backup->recovery_time) + if (count >= instance->wal_depth && + days_threshold >= backup->recovery_time) { elog(LOG, "On timeline %i WAL is protected from purge at %X/%X", From 7c1a55d6271be312e11f6fcafebb62d37b427b9e Mon Sep 17 00:00:00 2001 From: Dmitriy Kuzmin Date: Wed, 27 Jan 2021 23:20:56 +1000 Subject: [PATCH 5/5] fix style2 --- src/catalog.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/catalog.c b/src/catalog.c index f35a51a5c..780a1f28b 100644 --- a/src/catalog.c +++ b/src/catalog.c @@ -1494,7 +1494,7 @@ catalog_get_timelines(InstanceConfig *instance) } /* determine which WAL segments must be kept because of wal retention */ - if (instance->wal_depth <= 0 && instance->wal_window <= 0) + if (instance->wal_depth <= 0 && instance->wal_window <= 0) return timelineinfos; /*