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

Commit43318d6

Browse files
author
Oleg Gurev
committed
[PBCKP-874] Addeded default unit output for config-show
- config-show command now has --default-units parameter- If it is provided, all time and memory- configuration options will be printed in their default units- test added, test_help_1 corrected
1 parent09236c6 commit43318d6

9 files changed

+63
-18
lines changed

‎src/configure.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -269,18 +269,21 @@ static const char *current_group = NULL;
269269
* Show configure options including default values.
270270
*/
271271
void
272-
do_show_config(void)
272+
do_show_config(boolshow_default_units)
273273
{
274274
inti;
275275

276276
show_configure_start();
277277

278278
for (i=0;instance_options[i].type;i++)
279279
{
280+
if (show_default_units&&strchr("bBiIuU",instance_options[i].type)&&instance_options[i].get_value==*option_get_value)
281+
instance_options[i].flags |=GET_VAL_IN_DEFAULT_UNITS;/* Set flag */
280282
if (show_format==SHOW_PLAIN)
281283
show_configure_plain(&instance_options[i]);
282284
else
283285
show_configure_json(&instance_options[i]);
286+
instance_options[i].flags &= ~(GET_VAL_IN_DEFAULT_UNITS);/* Reset flag. It was resetted in option_get_value(). Probably this reset isn't needed */
284287
}
285288

286289
show_configure_end();
@@ -801,6 +804,6 @@ show_configure_json(ConfigOption *opt)
801804
return;
802805

803806
json_add_value(&show_buf,opt->lname,value,json_level,
804-
true);
807+
!(opt->flags&GET_VAL_IN_DEFAULT_UNITS));
805808
pfree(value);
806809
}

‎src/help.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,7 @@ help_pg_probackup(void)
121121

122122
printf(_("\n %s show-config -B backup-path --instance=instance_name\n"),PROGRAM_NAME);
123123
printf(_(" [--format=format]\n"));
124+
printf(_(" [--default-units]\n"));
124125
printf(_(" [--help]\n"));
125126

126127
printf(_("\n %s backup -B backup-path -b backup-mode --instance=instance_name\n"),PROGRAM_NAME);
@@ -953,7 +954,8 @@ help_show_config(void)
953954

954955
printf(_(" -B, --backup-path=backup-path location of the backup storage area\n"));
955956
printf(_(" --instance=instance_name name of the instance\n"));
956-
printf(_(" --format=format show format=PLAIN|JSON\n\n"));
957+
printf(_(" --format=format show format=PLAIN|JSON\n"));
958+
printf(_(" --default-units show memory and time values in default units\n\n"));
957959
}
958960

959961
staticvoid

‎src/pg_probackup.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,7 @@ bool no_validate_wal = false;
164164
/* show options */
165165
ShowFormatshow_format=SHOW_PLAIN;
166166
boolshow_archive= false;
167+
staticboolshow_default_units= false;
167168

168169
/* set-backup options */
169170
int64ttl=-1;
@@ -275,6 +276,8 @@ static ConfigOption cmd_options[] =
275276
/* show options */
276277
{'f',165,"format",opt_show_format,SOURCE_CMD_STRICT },
277278
{'b',166,"archive",&show_archive,SOURCE_CMD_STRICT },
279+
/* show-config options */
280+
{'b',167,"default-units",&show_default_units,SOURCE_CMD_STRICT },
278281
/* set-backup options */
279282
{'I',170,"ttl",&ttl,SOURCE_CMD_STRICT,SOURCE_DEFAULT,0,OPTION_UNIT_S,option_get_value},
280283
{'s',171,"expire-time",&expire_time_string,SOURCE_CMD_STRICT },
@@ -1049,7 +1052,7 @@ main(int argc, char *argv[])
10491052
do_merge(instanceState,current.backup_id,no_validate,no_sync);
10501053
break;
10511054
caseSHOW_CONFIG_CMD:
1052-
do_show_config();
1055+
do_show_config(show_default_units);
10531056
break;
10541057
caseSET_CONFIG_CMD:
10551058
do_set_config(instanceState, false);

‎src/pg_probackup.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -939,7 +939,7 @@ extern void do_archive_get(InstanceState *instanceState, InstanceConfig *instanc
939939
char*wal_file_name,intbatch_size,boolvalidate_wal);
940940

941941
/* in configure.c */
942-
externvoiddo_show_config(void);
942+
externvoiddo_show_config(boolshow_default_units);
943943
externvoiddo_set_config(InstanceState*instanceState,boolmissing_ok);
944944
externvoidinit_config(InstanceConfig*config,constchar*instance_name);
945945
externInstanceConfig*readInstanceConfigFile(InstanceState*instanceState);

‎src/utils/configuration.c

Lines changed: 28 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -678,6 +678,8 @@ config_set_opt(ConfigOption options[], void *var, OptionSource source)
678678
/*
679679
* Return value of the function in the string representation. Result is
680680
* allocated string.
681+
* We can set GET_VAL_IN_DEFAULT_UNITS flag in opt->flags
682+
* before call option_get_value() to get option value in default units
681683
*/
682684
char*
683685
option_get_value(ConfigOption*opt)
@@ -692,20 +694,33 @@ option_get_value(ConfigOption *opt)
692694
*/
693695
if (opt->flags&OPTION_UNIT)
694696
{
695-
if (opt->type=='i')
696-
convert_from_base_unit(*((int32*)opt->var),
697-
opt->flags&OPTION_UNIT,&value,&unit);
698-
elseif (opt->type=='I')
699-
convert_from_base_unit(*((int64*)opt->var),
700-
opt->flags&OPTION_UNIT,&value,&unit);
701-
elseif (opt->type=='u')
702-
convert_from_base_unit_u(*((uint32*)opt->var),
703-
opt->flags&OPTION_UNIT,&value_u,&unit);
704-
elseif (opt->type=='U')
705-
convert_from_base_unit_u(*((uint64*)opt->var),
706-
opt->flags&OPTION_UNIT,&value_u,&unit);
697+
if (opt->flags&GET_VAL_IN_DEFAULT_UNITS){
698+
if (opt->type=='i')
699+
value=*((int32*)opt->var);
700+
elseif (opt->type=='I')
701+
value=*((int64*)opt->var);
702+
elseif (opt->type=='u')
703+
value_u=*((uint32*)opt->var);
704+
elseif (opt->type=='U')
705+
value_u=*((uint64*)opt->var);
706+
unit="";
707+
}
708+
else
709+
{
710+
if (opt->type=='i')
711+
convert_from_base_unit(*((int32*)opt->var),
712+
opt->flags&OPTION_UNIT,&value,&unit);
713+
elseif (opt->type=='I')
714+
convert_from_base_unit(*((int64*)opt->var),
715+
opt->flags&OPTION_UNIT,&value,&unit);
716+
elseif (opt->type=='u')
717+
convert_from_base_unit_u(*((uint32*)opt->var),
718+
opt->flags&OPTION_UNIT,&value_u,&unit);
719+
elseif (opt->type=='U')
720+
convert_from_base_unit_u(*((uint64*)opt->var),
721+
opt->flags&OPTION_UNIT,&value_u,&unit);
722+
}
707723
}
708-
709724
/* Get string representation itself */
710725
switch (opt->type)
711726
{

‎src/utils/configuration.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ struct ConfigOption
100100
#defineOPTION_UNIT_TIME0xF0000/* mask for time-related units */
101101

102102
#defineOPTION_UNIT(OPTION_UNIT_MEMORY | OPTION_UNIT_TIME)
103+
#defineGET_VAL_IN_DEFAULT_UNITS 0x80000000/* bitflag to get memory and time values in default units*/
103104

104105
externProbackupSubcmdparse_subcmd(charconst*constsubcmd_str);
105106
externcharconst*get_subcmd_name(ProbackupSubcmdconstsubcmd);

‎tests/expected/option_help.out

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ pg_probackup - utility to manage backup/recovery of PostgreSQL database.
3939

4040
pg_probackup show-config -B backup-path --instance=instance_name
4141
[--format=format]
42+
[--default-units]
4243
[--help]
4344

4445
pg_probackup backup -B backup-path -b backup-mode --instance=instance_name

‎tests/expected/option_help_ru.out

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ pg_probackup - утилита для управления резервным к
3939

4040
pg_probackup show-config -B backup-path --instance=instance_name
4141
[--format=format]
42+
[--default-units]
4243
[--help]
4344

4445
pg_probackup backup -B backup-path -b backup-mode --instance=instance_name

‎tests/option_test.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,25 @@ def test_help_6(self):
230230
self.skipTest(
231231
'You need configure PostgreSQL with --enabled-nls option for this test')
232232

233+
# @unittest.skip("skip")
234+
deftest_options_default_units(self):
235+
"""check --default-units option"""
236+
backup_dir=os.path.join(self.tmp_path,self.module_name,self.fname,'backup')
237+
node=self.make_simple_node(
238+
base_dir=os.path.join(self.module_name,self.fname,'node'))
239+
self.init_pb(backup_dir)
240+
self.add_instance(backup_dir,'node',node)
241+
# check that --default-units option works correctly
242+
output=self.run_pb(["show-config","--backup-path",backup_dir,"--instance=node"])
243+
self.assertIn(container=output,member="archive-timeout = 5min")
244+
output=self.run_pb(["show-config","--backup-path",backup_dir,"--instance=node","--default-units"])
245+
self.assertIn(container=output,member="archive-timeout = 300")
246+
self.assertNotIn(container=output,member="archive-timeout = 300s")
247+
# check that we have now quotes ("") in json output
248+
output=self.run_pb(["show-config","--backup-path",backup_dir,"--instance=node","--default-units","--format=json"])
249+
self.assertIn(container=output,member='"archive-timeout": 300,')
250+
self.assertIn(container=output,member='"retention-redundancy": 0,')
251+
self.assertNotIn(container=output,member='"archive-timeout": "300",')
233252

234253
defcheck_locale(locale_name):
235254
ret=True

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp