Skip to content

Commit e7d088c

Browse files
committed
PGPRO-1700: Show default options in show-config
and clean up the code of the config options.
1 parent 9a7daf0 commit e7d088c

File tree

10 files changed

+158
-128
lines changed

10 files changed

+158
-128
lines changed

src/configure.c

Lines changed: 98 additions & 92 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
*/
99

1010
#include "pg_probackup.h"
11+
#include "utils/logger.h"
1112

1213
#include "pqexpbuffer.h"
1314

@@ -57,13 +58,17 @@ do_configure(bool show_only)
5758
config->master_db = master_db;
5859
if (master_user)
5960
config->master_user = master_user;
60-
if (replica_timeout != 300) /* 300 is default value */
61+
62+
if (replica_timeout)
6163
config->replica_timeout = replica_timeout;
6264

63-
if (log_level_console != LOG_NONE)
64-
config->log_level_console = LOG_LEVEL_CONSOLE;
65-
if (log_level_file != LOG_NONE)
66-
config->log_level_file = LOG_LEVEL_FILE;
65+
if (archive_timeout)
66+
config->archive_timeout = archive_timeout;
67+
68+
if (log_level_console)
69+
config->log_level_console = log_level_console;
70+
if (log_level_file)
71+
config->log_level_file = log_level_file;
6772
if (log_filename)
6873
config->log_filename = log_filename;
6974
if (error_log_filename)
@@ -80,9 +85,9 @@ do_configure(bool show_only)
8085
if (retention_window)
8186
config->retention_window = retention_window;
8287

83-
if (compress_alg != NOT_DEFINED_COMPRESS)
88+
if (compress_alg)
8489
config->compress_alg = compress_alg;
85-
if (compress_level != DEFAULT_COMPRESS_LEVEL)
90+
if (compress_level)
8691
config->compress_level = compress_level;
8792

8893
if (show_only)
@@ -107,21 +112,23 @@ pgBackupConfigInit(pgBackupConfig *config)
107112
config->master_port = NULL;
108113
config->master_db = NULL;
109114
config->master_user = NULL;
110-
config->replica_timeout = INT_MIN; /* INT_MIN means "undefined" */
115+
config->replica_timeout = REPLICA_TIMEOUT_DEFAULT;
116+
117+
config->archive_timeout = ARCHIVE_TIMEOUT_DEFAULT;
111118

112-
config->log_level_console = INT_MIN; /* INT_MIN means "undefined" */
113-
config->log_level_file = INT_MIN; /* INT_MIN means "undefined" */
114-
config->log_filename = NULL;
119+
config->log_level_console = LOG_LEVEL_CONSOLE_DEFAULT;
120+
config->log_level_file = LOG_LEVEL_FILE_DEFAULT;
121+
config->log_filename = LOG_FILENAME_DEFAULT;
115122
config->error_log_filename = NULL;
116-
config->log_directory = NULL;
117-
config->log_rotation_size = 0;
118-
config->log_rotation_age = 0;
123+
config->log_directory = LOG_DIRECTORY_DEFAULT;
124+
config->log_rotation_size = LOG_ROTATION_SIZE_DEFAULT;
125+
config->log_rotation_age = LOG_ROTATION_AGE_DEFAULT;
119126

120-
config->retention_redundancy = 0;
121-
config->retention_window = 0;
127+
config->retention_redundancy = RETENTION_REDUNDANCY_DEFAULT;
128+
config->retention_window = RETENTION_WINDOW_DEFAULT;
122129

123-
config->compress_alg = NOT_DEFINED_COMPRESS;
124-
config->compress_level = DEFAULT_COMPRESS_LEVEL;
130+
config->compress_alg = COMPRESS_ALG_DEFAULT;
131+
config->compress_level = COMPRESS_LEVEL_DEFAULT;
125132
}
126133

127134
void
@@ -154,55 +161,43 @@ writeBackupCatalogConfig(FILE *out, pgBackupConfig *config)
154161
if (config->master_user)
155162
fprintf(out, "master-user = %s\n", config->master_user);
156163

157-
if (config->replica_timeout != INT_MIN)
158-
{
159-
convert_from_base_unit_u(config->replica_timeout, OPTION_UNIT_S,
160-
&res, &unit);
161-
fprintf(out, "replica-timeout = " UINT64_FORMAT "%s\n", res, unit);
162-
}
164+
convert_from_base_unit_u(config->replica_timeout, OPTION_UNIT_S,
165+
&res, &unit);
166+
fprintf(out, "replica-timeout = " UINT64_FORMAT "%s\n", res, unit);
167+
168+
fprintf(out, "#Archive parameters:\n");
169+
convert_from_base_unit_u(config->archive_timeout, OPTION_UNIT_S,
170+
&res, &unit);
171+
fprintf(out, "archive-timeout = " UINT64_FORMAT "%s\n", res, unit);
163172

164173
fprintf(out, "#Logging parameters:\n");
165-
if (config->log_level_console != INT_MIN)
166-
fprintf(out, "log-level-console = %s\n", deparse_log_level(config->log_level_console));
167-
if (config->log_level_file != INT_MIN)
168-
fprintf(out, "log-level-file = %s\n", deparse_log_level(config->log_level_file));
169-
if (config->log_filename)
170-
fprintf(out, "log-filename = %s\n", config->log_filename);
174+
fprintf(out, "log-level-console = %s\n", deparse_log_level(config->log_level_console));
175+
fprintf(out, "log-level-file = %s\n", deparse_log_level(config->log_level_file));
176+
fprintf(out, "log-filename = %s\n", config->log_filename);
171177
if (config->error_log_filename)
172178
fprintf(out, "error-log-filename = %s\n", config->error_log_filename);
173-
if (config->log_directory)
179+
180+
if (strcmp(config->log_directory, LOG_DIRECTORY_DEFAULT) == 0)
181+
fprintf(out, "log-directory = %s/%s\n", backup_path, config->log_directory);
182+
else
174183
fprintf(out, "log-directory = %s\n", config->log_directory);
184+
/* Convert values from base unit */
185+
convert_from_base_unit_u(config->log_rotation_size, OPTION_UNIT_KB,
186+
&res, &unit);
187+
fprintf(out, "log-rotation-size = " UINT64_FORMAT "%s\n", res, (res)?unit:"KB");
175188

176-
/*
177-
* Convert values from base unit
178-
*/
179-
if (config->log_rotation_size)
180-
{
181-
convert_from_base_unit_u(config->log_rotation_size, OPTION_UNIT_KB,
182-
&res, &unit);
183-
fprintf(out, "log-rotation-size = " UINT64_FORMAT "%s\n", res, unit);
184-
}
185-
if (config->log_rotation_age)
186-
{
187-
convert_from_base_unit_u(config->log_rotation_age, OPTION_UNIT_S,
188-
&res, &unit);
189-
fprintf(out, "log-rotation-age = " UINT64_FORMAT "%s\n", res, unit);
190-
}
189+
convert_from_base_unit_u(config->log_rotation_age, OPTION_UNIT_S,
190+
&res, &unit);
191+
fprintf(out, "log-rotation-age = " UINT64_FORMAT "%s\n", res, (res)?unit:"min");
191192

192193
fprintf(out, "#Retention parameters:\n");
193-
if (config->retention_redundancy)
194-
fprintf(out, "retention-redundancy = %u\n", config->retention_redundancy);
195-
if (config->retention_window)
196-
fprintf(out, "retention-window = %u\n", config->retention_window);
194+
fprintf(out, "retention-redundancy = %u\n", config->retention_redundancy);
195+
fprintf(out, "retention-window = %u\n", config->retention_window);
197196

198197
fprintf(out, "#Compression parameters:\n");
199198

200199
fprintf(out, "compress-algorithm = %s\n", deparse_compress_alg(config->compress_alg));
201-
202-
if (compress_level != config->compress_level)
203-
fprintf(out, "compress-level = %d\n", compress_level);
204-
else
205-
fprintf(out, "compress-level = %d\n", config->compress_level);
200+
fprintf(out, "compress-level = %d\n", config->compress_level);
206201
}
207202

208203
void
@@ -258,6 +253,8 @@ readBackupCatalogConfigFile(void)
258253
{ 'u', 0, "replica-timeout", &(config->replica_timeout), SOURCE_CMDLINE, SOURCE_DEFAULT, OPTION_UNIT_S },
259254
/* other options */
260255
{ 'U', 0, "system-identifier", &(config->system_identifier), SOURCE_FILE_STRICT },
256+
/* archive options */
257+
{ 'u', 0, "archive-timeout", &(config->archive_timeout), SOURCE_CMDLINE, SOURCE_DEFAULT, OPTION_UNIT_S },
261258
{0}
262259
};
263260

@@ -342,6 +339,8 @@ static void
342339
show_configure_json(pgBackupConfig *config)
343340
{
344341
PQExpBuffer buf = &show_buf;
342+
uint64 res;
343+
const char *unit;
345344

346345
json_add(buf, JT_BEGIN_OBJECT, &json_level);
347346

@@ -373,53 +372,60 @@ show_configure_json(pgBackupConfig *config)
373372
json_add_value(buf, "master-user", config->master_user, json_level,
374373
true);
375374

376-
if (config->replica_timeout != INT_MIN)
377-
{
378-
json_add_key(buf, "replica-timeout", json_level, true);
379-
appendPQExpBuffer(buf, "%d", config->replica_timeout);
380-
}
375+
json_add_key(buf, "replica-timeout", json_level, true);
376+
convert_from_base_unit_u(config->replica_timeout, OPTION_UNIT_S,
377+
&res, &unit);
378+
appendPQExpBuffer(buf, UINT64_FORMAT "%s", res, unit);
379+
380+
/* Archive parameters */
381+
json_add_key(buf, "archive-timeout", json_level, true);
382+
convert_from_base_unit_u(config->archive_timeout, OPTION_UNIT_S,
383+
&res, &unit);
384+
appendPQExpBuffer(buf, UINT64_FORMAT "%s", res, unit);
381385

382386
/* Logging parameters */
383-
if (config->log_level_console != INT_MIN)
384-
json_add_value(buf, "log-level-console",
385-
deparse_log_level(config->log_level_console), json_level,
386-
true);
387-
if (config->log_level_file != INT_MIN)
388-
json_add_value(buf, "log-level-file",
389-
deparse_log_level(config->log_level_file), json_level,
390-
true);
391-
if (config->log_filename)
392-
json_add_value(buf, "log-filename", config->log_filename, json_level,
393-
true);
387+
json_add_value(buf, "log-level-console",
388+
deparse_log_level(config->log_level_console), json_level,
389+
true);
390+
json_add_value(buf, "log-level-file",
391+
deparse_log_level(config->log_level_file), json_level,
392+
true);
393+
json_add_value(buf, "log-filename", config->log_filename, json_level,
394+
true);
394395
if (config->error_log_filename)
395396
json_add_value(buf, "error-log-filename", config->error_log_filename,
396397
json_level, true);
397-
if (config->log_directory)
398-
json_add_value(buf, "log-directory", config->log_directory, json_level,
399-
true);
400398

401-
if (config->log_rotation_size)
402-
{
403-
json_add_key(buf, "log-rotation-size", json_level, true);
404-
appendPQExpBuffer(buf, "%d", config->log_rotation_size);
405-
}
406-
if (config->log_rotation_age)
399+
if (strcmp(config->log_directory, LOG_DIRECTORY_DEFAULT) == 0)
407400
{
408-
json_add_key(buf, "log-rotation-age", json_level, true);
409-
appendPQExpBuffer(buf, "%d", config->log_rotation_age);
401+
char log_directory_fullpath[MAXPGPATH];
402+
403+
sprintf(log_directory_fullpath, "%s/%s",
404+
backup_path, config->log_directory);
405+
406+
json_add_value(buf, "log-directory", log_directory_fullpath,
407+
json_level, true);
410408
}
409+
else
410+
json_add_value(buf, "log-directory", config->log_directory,
411+
json_level, true);
412+
413+
json_add_key(buf, "log-rotation-size", json_level, true);
414+
convert_from_base_unit_u(config->log_rotation_size, OPTION_UNIT_KB,
415+
&res, &unit);
416+
appendPQExpBuffer(buf, UINT64_FORMAT "%s", res, (res)?unit:"KB");
417+
418+
json_add_key(buf, "log-rotation-age", json_level, true);
419+
convert_from_base_unit_u(config->log_rotation_age, OPTION_UNIT_S,
420+
&res, &unit);
421+
appendPQExpBuffer(buf, UINT64_FORMAT "%s", res, (res)?unit:"min");
411422

412423
/* Retention parameters */
413-
if (config->retention_redundancy)
414-
{
415-
json_add_key(buf, "retention-redundancy", json_level, true);
416-
appendPQExpBuffer(buf, "%u", config->retention_redundancy);
417-
}
418-
if (config->retention_window)
419-
{
420-
json_add_key(buf, "retention-window", json_level, true);
421-
appendPQExpBuffer(buf, "%u", config->retention_window);
422-
}
424+
json_add_key(buf, "retention-redundancy", json_level, true);
425+
appendPQExpBuffer(buf, "%u", config->retention_redundancy);
426+
427+
json_add_key(buf, "retention-window", json_level, true);
428+
appendPQExpBuffer(buf, "%u", config->retention_window);
423429

424430
/* Compression parameters */
425431
json_add_value(buf, "compress-algorithm",

src/delete.c

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,8 @@ do_retention_purge(void)
141141
if (retention_window > 0)
142142
elog(LOG, "WINDOW=%u", retention_window);
143143

144-
if (retention_redundancy == 0 && retention_window == 0)
144+
if (retention_redundancy == 0
145+
&& retention_window == 0)
145146
{
146147
elog(WARNING, "Retention policy is not set");
147148
if (!delete_wal)
@@ -161,7 +162,8 @@ do_retention_purge(void)
161162
}
162163

163164
/* Find target backups to be deleted */
164-
if (delete_expired && (retention_redundancy > 0 || retention_window > 0))
165+
if (delete_expired &&
166+
(retention_redundancy > 0 || retention_window > 0))
165167
{
166168
backup_num = 0;
167169
for (i = 0; i < parray_num(backup_list); i++)
@@ -173,13 +175,13 @@ do_retention_purge(void)
173175
if (backup->status != BACKUP_STATUS_OK)
174176
continue;
175177
/*
176-
* When a validate full backup was found, we can delete the
178+
* When a valid full backup was found, we can delete the
177179
* backup that is older than it using the number of generations.
178180
*/
179181
if (backup->backup_mode == BACKUP_MODE_FULL)
180182
backup_num++;
181183

182-
/* Evaluateretention_redundancy if this backup is eligible for removal */
184+
/* Evaluate retention_redundancy if this backup is eligible for removal */
183185
if (keep_next_backup ||
184186
retention_redundancy >= backup_num_evaluate + 1 ||
185187
(retention_window > 0 && backup->recovery_time >= days_threshold))
@@ -200,6 +202,7 @@ do_retention_purge(void)
200202

201203
continue;
202204
}
205+
203206
/* Delete backup and update status to DELETED */
204207
pgBackupDeleteFiles(backup);
205208
backup_deleted = true;
@@ -259,7 +262,8 @@ pgBackupDeleteFiles(pgBackup *backup)
259262

260263
time2iso(timestamp, lengthof(timestamp), backup->recovery_time);
261264

262-
elog(INFO, "delete: %s %s", base36enc(backup->start_time), timestamp);
265+
elog(INFO, "delete: %s %s",
266+
base36enc(backup->start_time), timestamp);
263267

264268
/*
265269
* Update STATUS to BACKUP_STATUS_DELETING in preparation for the case which

src/help.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ help_pg_probackup(void)
8787
printf(_(" [--master-db=db_name] [--master-host=host_name]\n"));
8888
printf(_(" [--master-port=port] [--master-user=user_name]\n"));
8989
printf(_(" [--replica-timeout=timeout]\n"));
90+
printf(_(" [--archive-timeout=timeout]\n"));
9091

9192
printf(_("\n %s show-config -B backup-dir --instance=instance_name\n"), PROGRAM_NAME);
9293
printf(_(" [--format=format]\n"));
@@ -257,7 +258,7 @@ help_backup(void)
257258
printf(_(" --master-db=db_name database to connect to master\n"));
258259
printf(_(" --master-host=host_name database server host of master\n"));
259260
printf(_(" --master-port=port database server port of master\n"));
260-
printf(_(" --replica-timeout=timeout wait timeout for WAL segment streaming through replication in seconds\n"));
261+
printf(_(" --replica-timeout=timeout wait timeout for WAL segment streaming through replication (default: 5min)\n"));
261262
}
262263

263264
static void
@@ -429,6 +430,7 @@ help_set_config(void)
429430
printf(_(" [--master-db=db_name] [--master-host=host_name]\n"));
430431
printf(_(" [--master-port=port] [--master-user=user_name]\n"));
431432
printf(_(" [--replica-timeout=timeout]\n\n"));
433+
printf(_(" [--archive-timeout=timeout]\n\n"));
432434

433435
printf(_(" -B, --backup-path=backup-path location of the backup storage area\n"));
434436
printf(_(" --instance=instance_name name of the instance\n"));
@@ -477,7 +479,9 @@ help_set_config(void)
477479
printf(_(" --master-db=db_name database to connect to master\n"));
478480
printf(_(" --master-host=host_name database server host of master\n"));
479481
printf(_(" --master-port=port database server port of master\n"));
480-
printf(_(" --replica-timeout=timeout wait timeout for WAL segment streaming through replication\n"));
482+
printf(_(" --replica-timeout=timeout wait timeout for WAL segment streaming through replication (default: 5min)\n"));
483+
printf(_("\n Archive options:\n"));
484+
printf(_(" --archive-timeout=timeout wait timeout for WAL segment archiving (default: 5min)\n"));
481485
}
482486

483487
static void

0 commit comments

Comments
 (0)