Skip to content

Commit

Permalink
Rename default-units to no-scale-units
Browse files Browse the repository at this point in the history
  • Loading branch information
oleg gurev authored and postgres-dev committed May 6, 2024
1 parent 79d2b9d commit d29b005
Show file tree
Hide file tree
Showing 10 changed files with 34 additions and 21 deletions.
13 changes: 13 additions & 0 deletions doc/pgprobackup.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4267,6 +4267,7 @@ pg_probackup set-backup -B <replaceable>backup_dir</replaceable> --instance <rep
<title>show-config</title>
<programlisting>
pg_probackup show-config -B <replaceable>backup_dir</replaceable> --instance <replaceable>instance_name</replaceable> [--format=plain|json]
[--no-scale-units] [<replaceable>logging_options</replaceable>]
</programlisting>
<para>
Displays the contents of the <filename>pg_probackup.conf</filename> configuration
Expand All @@ -4277,6 +4278,18 @@ pg_probackup show-config -B <replaceable>backup_dir</replaceable> --instance <re
in the <acronym>JSON</acronym> format. By default, configuration settings are
shown as plain text.
</para>
<para>
You can also specify the <option>--no-scale-units</option>
option to display time and memory configuration settings in their base (unscaled) units.
Otherwise, the values are scaled to larger units for optimal display.
For example, if <literal>archive-timeout</literal> is 300, then
<literal>5min</literal> is displayed, but if <literal>archive-timeout</literal>
is 301, then <literal>301s</literal> is displayed.
Also, if the <option>--no-scale-units</option> option is specified, configuration
settings are displayed without units and for the JSON format,
numeric and boolean values are not enclosed in quotes. This facilitates parsing
the output.
</para>
<para>
To edit <filename>pg_probackup.conf</filename>, use the
<xref linkend="pbk-set-config"/> command.
Expand Down
10 changes: 5 additions & 5 deletions src/configure.c
Original file line number Diff line number Diff line change
Expand Up @@ -269,21 +269,21 @@ static const char *current_group = NULL;
* Show configure options including default values.
*/
void
do_show_config(bool show_default_units)
do_show_config(bool show_base_units)
{
int i;

show_configure_start();

for (i = 0; instance_options[i].type; i++)
{
if (show_default_units && strchr("bBiIuU", instance_options[i].type) && instance_options[i].get_value == *option_get_value)
instance_options[i].flags |= GET_VAL_IN_DEFAULT_UNITS; /* Set flag */
if (show_base_units && strchr("bBiIuU", instance_options[i].type) && instance_options[i].get_value == *option_get_value)
instance_options[i].flags |= GET_VAL_IN_BASE_UNITS; /* Set flag */
if (show_format == SHOW_PLAIN)
show_configure_plain(&instance_options[i]);
else
show_configure_json(&instance_options[i]);
instance_options[i].flags &= ~(GET_VAL_IN_DEFAULT_UNITS); /* Reset flag. It was resetted in option_get_value(). Probably this reset isn't needed */
instance_options[i].flags &= ~(GET_VAL_IN_BASE_UNITS); /* Reset flag. It was resetted in option_get_value(). Probably this reset isn't needed */
}

show_configure_end();
Expand Down Expand Up @@ -804,6 +804,6 @@ show_configure_json(ConfigOption *opt)
return;

json_add_value(&show_buf, opt->lname, value, json_level,
!(opt->flags & GET_VAL_IN_DEFAULT_UNITS));
!(opt->flags & GET_VAL_IN_BASE_UNITS));
pfree(value);
}
4 changes: 2 additions & 2 deletions src/help.c
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ help_pg_probackup(void)

printf(_("\n %s show-config -B backup-dir --instance=instance-name\n"), PROGRAM_NAME);
printf(_(" [--format=format]\n"));
printf(_(" [--default-units]\n"));
printf(_(" [--no-scale-units]\n"));
printf(_(" [--help]\n"));

printf(_("\n %s backup -B backup-dir -b backup-mode --instance=instance-name\n"), PROGRAM_NAME);
Expand Down Expand Up @@ -955,7 +955,7 @@ help_show_config(void)
printf(_(" -B, --backup-path=backup-dir location of the backup storage area\n"));
printf(_(" --instance=instance-name name of the instance\n"));
printf(_(" --format=format show format=PLAIN|JSON\n"));
printf(_(" --default-units show memory and time values in default units\n\n"));
printf(_(" --no-scale-units show memory and time values in default units\n\n"));
}

static void
Expand Down
6 changes: 3 additions & 3 deletions src/pg_probackup.c
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ bool no_validate_wal = false;
/* show options */
ShowFormat show_format = SHOW_PLAIN;
bool show_archive = false;
static bool show_default_units = false;
static bool show_base_units = false;

/* set-backup options */
int64 ttl = -1;
Expand Down Expand Up @@ -277,7 +277,7 @@ static ConfigOption cmd_options[] =
{ 'f', 165, "format", opt_show_format, SOURCE_CMD_STRICT },
{ 'b', 166, "archive", &show_archive, SOURCE_CMD_STRICT },
/* show-config options */
{ 'b', 167, "default-units", &show_default_units,SOURCE_CMD_STRICT },
{ 'b', 167, "no-scale-units", &show_base_units,SOURCE_CMD_STRICT },
/* set-backup options */
{ 'I', 170, "ttl", &ttl, SOURCE_CMD_STRICT, SOURCE_DEFAULT, 0, OPTION_UNIT_S, option_get_value},
{ 's', 171, "expire-time", &expire_time_string, SOURCE_CMD_STRICT },
Expand Down Expand Up @@ -1052,7 +1052,7 @@ main(int argc, char *argv[])
do_merge(instanceState, current.backup_id, no_validate, no_sync);
break;
case SHOW_CONFIG_CMD:
do_show_config(show_default_units);
do_show_config(show_base_units);
break;
case SET_CONFIG_CMD:
do_set_config(instanceState, false);
Expand Down
2 changes: 1 addition & 1 deletion src/pg_probackup.h
Original file line number Diff line number Diff line change
Expand Up @@ -939,7 +939,7 @@ extern void do_archive_get(InstanceState *instanceState, InstanceConfig *instanc
char *wal_file_name, int batch_size, bool validate_wal);

/* in configure.c */
extern void do_show_config(bool show_default_units);
extern void do_show_config(bool show_base_units);
extern void do_set_config(InstanceState *instanceState, bool missing_ok);
extern void init_config(InstanceConfig *config, const char *instance_name);
extern InstanceConfig *readInstanceConfigFile(InstanceState *instanceState);
Expand Down
4 changes: 2 additions & 2 deletions src/utils/configuration.c
Original file line number Diff line number Diff line change
Expand Up @@ -678,7 +678,7 @@ config_set_opt(ConfigOption options[], void *var, OptionSource source)
/*
* Return value of the function in the string representation. Result is
* allocated string.
* We can set GET_VAL_IN_DEFAULT_UNITS flag in opt->flags
* We can set GET_VAL_IN_BASE_UNITS flag in opt->flags
* before call option_get_value() to get option value in default units
*/
char *
Expand All @@ -694,7 +694,7 @@ option_get_value(ConfigOption *opt)
*/
if (opt->flags & OPTION_UNIT)
{
if (opt->flags & GET_VAL_IN_DEFAULT_UNITS){
if (opt->flags & GET_VAL_IN_BASE_UNITS){
if (opt->type == 'i')
value = *((int32 *) opt->var);
else if (opt->type == 'I')
Expand Down
2 changes: 1 addition & 1 deletion src/utils/configuration.h
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ struct ConfigOption
#define OPTION_UNIT_TIME 0xF0000 /* mask for time-related units */

#define OPTION_UNIT (OPTION_UNIT_MEMORY | OPTION_UNIT_TIME)
#define GET_VAL_IN_DEFAULT_UNITS 0x80000000 /* bitflag to get memory and time values in default units*/
#define GET_VAL_IN_BASE_UNITS 0x80000000 /* bitflag to get memory and time values in default units*/

extern ProbackupSubcmd parse_subcmd(char const * const subcmd_str);
extern char const *get_subcmd_name(ProbackupSubcmd const subcmd);
Expand Down
2 changes: 1 addition & 1 deletion tests/expected/option_help.out
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ pg_probackup - utility to manage backup/recovery of PostgreSQL database.

pg_probackup show-config -B backup-dir --instance=instance-name
[--format=format]
[--default-units]
[--no-scale-units]
[--help]

pg_probackup backup -B backup-dir -b backup-mode --instance=instance-name
Expand Down
2 changes: 1 addition & 1 deletion tests/expected/option_help_ru.out
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ pg_probackup - утилита для управления резервным к

pg_probackup show-config -B backup-dir --instance=instance-name
[--format=format]
[--default-units]
[--no-scale-units]
[--help]

pg_probackup backup -B backup-dir -b backup-mode --instance=instance-name
Expand Down
10 changes: 5 additions & 5 deletions tests/option_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -222,21 +222,21 @@ def test_help_6(self):
'You need configure PostgreSQL with --enabled-nls option for this test')

# @unittest.skip("skip")
def test_options_default_units(self):
"""check --default-units option"""
def test_options_no_scale_units(self):
"""check --no-scale-units option"""
backup_dir = os.path.join(self.tmp_path, self.module_name, self.fname, 'backup')
node = self.make_simple_node(
base_dir=os.path.join(self.module_name, self.fname, 'node'))
self.init_pb(backup_dir)
self.add_instance(backup_dir, 'node', node)
# check that --default-units option works correctly
# check that --no-scale-units option works correctly
output = self.run_pb(["show-config", "--backup-path", backup_dir, "--instance=node"])
self.assertIn(container=output, member="archive-timeout = 5min")
output = self.run_pb(["show-config", "--backup-path", backup_dir, "--instance=node", "--default-units"])
output = self.run_pb(["show-config", "--backup-path", backup_dir, "--instance=node", "--no-scale-units"])
self.assertIn(container=output, member="archive-timeout = 300")
self.assertNotIn(container=output, member="archive-timeout = 300s")
# check that we have now quotes ("") in json output
output = self.run_pb(["show-config", "--backup-path", backup_dir, "--instance=node", "--default-units", "--format=json"])
output = self.run_pb(["show-config", "--backup-path", backup_dir, "--instance=node", "--no-scale-units", "--format=json"])
self.assertIn(container=output, member='"archive-timeout": 300,')
self.assertIn(container=output, member='"retention-redundancy": 0,')
self.assertNotIn(container=output, member='"archive-timeout": "300",')
Expand Down

0 comments on commit d29b005

Please sign in to comment.