@@ -72,6 +72,8 @@ static void stop_postgres_and_remove_pgdata_and_config(ConfigFilePaths *pathname
7272 * { "verbose", no_argument, NULL, 'v' },
7373 * { "quiet", no_argument, NULL, 'q' },
7474 * { "help", no_argument, NULL, 'h' },
75+ * { "secondary", no_argument, NULL, 'z' }
76+ * { "citus-cluster", required_argument, NULL, 'Z' },
7577 * { "candidate-priority", required_argument, NULL, 'P'},
7678 * { "replication-quorum", required_argument, NULL, 'r'},
7779 * { "help", no_argument, NULL, 0 },
@@ -105,11 +107,12 @@ cli_common_keeper_getopts(int argc, char **argv,
105107 LocalOptionConfig .prepare_promotion_walreceiver = -1 ;
106108 LocalOptionConfig .postgresql_restart_failure_timeout = -1 ;
107109 LocalOptionConfig .postgresql_restart_failure_max_retries = -1 ;
108- LocalOptionConfig .pgSetup .settings .candidatePriority =
109- FAILOVER_NODE_CANDIDATE_PRIORITY ;
110+ LocalOptionConfig .pgSetup .settings .candidatePriority = -1 ;
110111 LocalOptionConfig .pgSetup .settings .replicationQuorum =
111112 FAILOVER_NODE_REPLICATION_QUORUM ;
112113
114+ /* default to a "primary" in citus node_role terms */
115+ LocalOptionConfig .citusRole = CITUS_ROLE_PRIMARY ;
113116
114117 optind = 0 ;
115118
@@ -182,6 +185,26 @@ cli_common_keeper_getopts(int argc, char **argv,
182185 break ;
183186 }
184187
188+ case 'z' :
189+ {
190+ /* { "secondary", no_argument, NULL, 'z' } */
191+ strlcpy (LocalOptionConfig .citusRoleStr , "secondary" , NAMEDATALEN );
192+ LocalOptionConfig .citusRole = CITUS_ROLE_SECONDARY ;
193+ log_trace ("--secondary" );
194+ break ;
195+ }
196+
197+ case 'Z' :
198+ {
199+ /* { "citus-cluster", required_argument, NULL, 'Z' }, */
200+ strlcpy (LocalOptionConfig .pgSetup .citusClusterName ,
201+ optarg ,
202+ NAMEDATALEN );
203+ log_trace ("--citus-cluster %s" ,
204+ LocalOptionConfig .pgSetup .citusClusterName );
205+ break ;
206+ }
207+
185208 case 'U' :
186209 {
187210 /* { "username", required_argument, NULL, 'U' } */
@@ -510,6 +533,41 @@ cli_common_keeper_getopts(int argc, char **argv,
510533 exit (EXIT_CODE_BAD_ARGS );
511534 }
512535
536+ /* check --secondary and --candidate-priority */
537+ if (LocalOptionConfig .pgSetup .settings .candidatePriority == -1 )
538+ {
539+ /* --candidate-priority has not been used */
540+ if (LocalOptionConfig .citusRole == CITUS_ROLE_SECONDARY )
541+ {
542+ /* a Citus secondary can't be a target for failover */
543+ LocalOptionConfig .pgSetup .settings .candidatePriority = 0 ;
544+ }
545+ else
546+ {
547+ /* here we install the default candidate priority */
548+ LocalOptionConfig .pgSetup .settings .candidatePriority =
549+ FAILOVER_NODE_CANDIDATE_PRIORITY ;
550+ }
551+ }
552+ else if (LocalOptionConfig .pgSetup .settings .candidatePriority > 0 &&
553+ LocalOptionConfig .citusRole == CITUS_ROLE_SECONDARY )
554+ {
555+ log_fatal ("Citus does not support secondary roles that are "
556+ "also a candidate for failover: please use --secondary "
557+ "with --candidate-priority 0" );
558+ exit (EXIT_CODE_BAD_ARGS );
559+ }
560+
561+ /* a --secondary citus worker requires a cluster name */
562+ if (LocalOptionConfig .citusRole == CITUS_ROLE_SECONDARY )
563+ {
564+ if (IS_EMPTY_STRING_BUFFER (LocalOptionConfig .pgSetup .citusClusterName ))
565+ {
566+ log_fatal ("When using --secondary, also use --citus-cluster" );
567+ exit (EXIT_CODE_BAD_ARGS );
568+ }
569+ }
570+
513571 if (errors > 0 )
514572 {
515573 commandline_help (stderr );
@@ -573,6 +631,8 @@ cli_common_keeper_getopts(int argc, char **argv,
573631 * { "verbose", no_argument, NULL, 'v' },
574632 * { "quiet", no_argument, NULL, 'q' },
575633 * { "help", no_argument, NULL, 'h' },
634+ * { "secondary", no_argument, NULL, 'z' },
635+ * { "citus-cluster", required_argument, NULL, 'Z' },
576636 * { "candidate-priority", required_argument, NULL, 'P'},
577637 * { "replication-quorum", required_argument, NULL, 'r'},
578638 * { "help", no_argument, NULL, 0 },
@@ -1253,12 +1313,14 @@ cli_print_version_getopts(int argc, char **argv)
12531313void
12541314keeper_cli_print_version (int argc , char * * argv )
12551315{
1316+ const char * version = PG_AUTOCTL_VERSION ;
1317+
12561318 if (outputJSON )
12571319 {
12581320 JSON_Value * js = json_value_init_object ();
12591321 JSON_Object * root = json_value_get_object (js );
12601322
1261- json_object_set_string (root , "pg_autoctl" , PG_AUTOCTL_VERSION );
1323+ json_object_set_string (root , "pg_autoctl" , version );
12621324 json_object_set_string (root ,
12631325 "pgautofailover" , PG_AUTOCTL_EXTENSION_VERSION );
12641326 json_object_set_string (root , "pg_major" , PG_MAJORVERSION );
@@ -1270,7 +1332,7 @@ keeper_cli_print_version(int argc, char **argv)
12701332 }
12711333 else
12721334 {
1273- fformat (stdout , "pg_autoctl version %s\n" , PG_AUTOCTL_VERSION );
1335+ fformat (stdout , "pg_autoctl version %s\n" , version );
12741336 fformat (stdout ,
12751337 "pg_autoctl extension version %s\n" ,
12761338 PG_AUTOCTL_EXTENSION_VERSION );
@@ -1333,10 +1395,8 @@ cli_drop_local_node(KeeperConfig *config, bool dropAndDestroy)
13331395 {
13341396 if (file_exists (config -> pathnames .state ))
13351397 {
1336- bool ignoreMonitorErrors = true;
1337-
13381398 /* keeper_remove uses log_info() to explain what's happening */
1339- if (!keeper_remove (& keeper , config , ignoreMonitorErrors ))
1399+ if (!keeper_remove (& keeper , config ))
13401400 {
13411401 log_fatal ("Failed to remove local node from the pg_auto_failover "
13421402 "monitor, see above for details" );
0 commit comments