Skip to content

Commit 2ec2476

Browse files
committed
Wire --region through CLI, fix extension versioning, add 3-DC stall test
- Thread --region option (-G) through all three pg_autoctl create postgres long_options arrays in cli_create_node.c, central option parsing in cli_common.c (case 'G'), keeper_config KeeperConfig.region field, nodespec.c ini/argv builder, and monitor_register_node() SQL call (). - Bump extension version to 2.3 consistently: Makefile EXTVERSION, metadata.h AUTO_FAILOVER_EXTENSION_VERSION, and pgautofailover.control already at 2.3. Add pgautofailover--2.3--dummy.sql upgrade path for dummy_update regress test. Update dummy_update.out expected DETAIL line to say '2.3'. - Fix monitor regress test ordering: add ORDER BY nodeid to the unordered SELECT from pgautofailover.node so the result is deterministic regardless of heap page layout (wider rows from new region/replication_stall_since columns changed physical scan order). - Update watch_colspecs.h MAX_COL_SPECS 12→14 to accommodate the new COLUMN_TYPE_REGION entry plus COLUMN_TYPE_LAST sentinel in the fully-verbose column policy (13 entries total). - Add pgaftest DSL support for 'region <name>' node option: T_REGION token in lexer, grammar rule in parser, TestNode.region field, compose_gen writes --region flag, cli_indent pretty-prints it. - Add tests/tap/specs/replication_stall_3dc.pgaf: 2-node cluster across dc1/dc2 regions; cuts network to node2, waits for node1 to reach wait_primary (FSM rule fires after replication_stall_timeout), then restores connectivity and waits for secondary recovery.
1 parent 1dcd8bd commit 2ec2476

26 files changed

Lines changed: 1770 additions & 1682 deletions

src/bin/pg_autoctl/cli_common.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -407,6 +407,14 @@ cli_common_keeper_getopts(int argc, char **argv,
407407
break;
408408
}
409409

410+
case 'G':
411+
{
412+
/* { "region", required_argument, NULL, 'G' } */
413+
strlcpy(LocalOptionConfig.region, optarg, NAMEDATALEN);
414+
log_trace("--region %s", LocalOptionConfig.region);
415+
break;
416+
}
417+
410418
case 'V':
411419
{
412420
/* keeper_cli_print_version prints version and exits. */

src/bin/pg_autoctl/cli_create_node.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -343,6 +343,7 @@ cli_create_postgres_getopts(int argc, char **argv)
343343
{ "candidate-priority", required_argument, NULL, 'P' },
344344
{ "replication-quorum", required_argument, NULL, 'r' },
345345
{ "maximum-backup-rate", required_argument, NULL, 'R' },
346+
{ "region", required_argument, NULL, 'G' },
346347
{ "run", no_argument, NULL, 'x' },
347348
{ "no-ssl", no_argument, NULL, 'N' },
348349
{ "ssl-self-signed", no_argument, NULL, 's' },
@@ -356,7 +357,7 @@ cli_create_postgres_getopts(int argc, char **argv)
356357

357358
int optind =
358359
cli_create_node_getopts(argc, argv, long_options,
359-
"C:D:H:p:l:U:A:SLd:a:n:f:m:MI:W:w:RVvqhP:r:xsN",
360+
"C:D:H:p:l:U:A:SLd:a:n:f:m:MI:W:w:RGVvqhP:r:xsN",
360361
&options);
361362

362363
/* publish our option parsing in the global variable */
@@ -441,6 +442,7 @@ cli_create_coordinator_getopts(int argc, char **argv)
441442
{ "citus-cluster", required_argument, NULL, 'Z' },
442443
{ "candidate-priority", required_argument, NULL, 'P' },
443444
{ "replication-quorum", required_argument, NULL, 'r' },
445+
{ "region", required_argument, NULL, 'G' },
444446
{ "run", no_argument, NULL, 'x' },
445447
{ "no-ssl", no_argument, NULL, 'N' },
446448
{ "ssl-self-signed", no_argument, NULL, 's' },
@@ -454,7 +456,7 @@ cli_create_coordinator_getopts(int argc, char **argv)
454456

455457
int optind =
456458
cli_create_node_getopts(argc, argv, long_options,
457-
"C:D:H:p:l:U:A:SLd:a:n:f:m:MRVvqhzZ:P:r:xsN",
459+
"C:D:H:p:l:U:A:SLd:a:n:f:m:MRGVvqhzZ:P:r:xsN",
458460
&options);
459461

460462
options.groupId = 0;
@@ -551,6 +553,7 @@ cli_create_worker_getopts(int argc, char **argv)
551553
{ "citus-cluster", required_argument, NULL, 'Z' },
552554
{ "candidate-priority", required_argument, NULL, 'P' },
553555
{ "replication-quorum", required_argument, NULL, 'r' },
556+
{ "region", required_argument, NULL, 'G' },
554557
{ "run", no_argument, NULL, 'x' },
555558
{ "no-ssl", no_argument, NULL, 'N' },
556559
{ "ssl-self-signed", no_argument, NULL, 's' },
@@ -564,7 +567,7 @@ cli_create_worker_getopts(int argc, char **argv)
564567

565568
int optind =
566569
cli_create_node_getopts(argc, argv, long_options,
567-
"C:D:H:p:l:y:zZ:U:A:SLd:a:n:f:m:MRVvqhzP:r:xsN",
570+
"C:D:H:p:l:y:zZ:U:A:SLd:a:n:f:m:MRGVvqhzP:r:xsN",
568571
&options);
569572

570573
if (options.groupId == 0)

src/bin/pg_autoctl/defaults.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
#define PG_AUTOCTL_VERSION GIT_VERSION
2020

2121
/* version of the extension that we requite to talk to on the monitor */
22-
#define PG_AUTOCTL_EXTENSION_VERSION "2.2"
22+
#define PG_AUTOCTL_EXTENSION_VERSION "2.3"
2323

2424
/* environment variable to use to make DEBUG facilities available */
2525
#define PG_AUTOCTL_DEBUG "PG_AUTOCTL_DEBUG"

src/bin/pg_autoctl/keeper.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1670,6 +1670,7 @@ keeper_register_and_init(Keeper *keeper, NodeState initialState)
16701670
config->pgSetup.settings.candidatePriority,
16711671
config->pgSetup.settings.replicationQuorum,
16721672
config->pgSetup.citusClusterName,
1673+
config->region,
16731674
&mayRetry,
16741675
&assignedState))
16751676
{
@@ -1875,6 +1876,7 @@ keeper_register_again(Keeper *keeper)
18751876
config->pgSetup.settings.candidatePriority,
18761877
config->pgSetup.settings.replicationQuorum,
18771878
DEFAULT_CITUS_CLUSTER_NAME,
1879+
config->region,
18781880
&mayRetry,
18791881
&assignedState))
18801882
{

src/bin/pg_autoctl/keeper_config.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,10 @@
6161
make_strbuf_option("pg_autoctl", "nodekind", NULL, false, NAMEDATALEN, \
6262
config->nodeKind)
6363

64+
#define OPTION_AUTOCTL_REGION(config) \
65+
make_strbuf_option_default("pg_autoctl", "region", "region", \
66+
false, NAMEDATALEN, config->region, "")
67+
6468
#define OPTION_POSTGRESQL_PGDATA(config) \
6569
make_strbuf_option("postgresql", "pgdata", "pgdata", true, MAXPGPATH, \
6670
config->pgSetup.pgdata)
@@ -227,6 +231,7 @@
227231
OPTION_AUTOCTL_HOSTNAME(config), \
228232
OPTION_AUTOCTL_NODENAME(config), \
229233
OPTION_AUTOCTL_NODEKIND(config), \
234+
OPTION_AUTOCTL_REGION(config), \
230235
OPTION_POSTGRESQL_PGDATA(config), \
231236
OPTION_POSTGRESQL_PG_CTL(config), \
232237
OPTION_POSTGRESQL_USERNAME(config), \

src/bin/pg_autoctl/keeper_config.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ typedef struct KeeperConfig
4646
char name[_POSIX_HOST_NAME_MAX];
4747
char hostname[_POSIX_HOST_NAME_MAX];
4848
char nodeKind[NAMEDATALEN];
49+
char region[NAMEDATALEN];
4950

5051
/* PostgreSQL setup */
5152
PostgresSetup pgSetup;

src/bin/pg_autoctl/monitor.c

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -861,19 +861,20 @@ monitor_register_node(Monitor *monitor, char *formation,
861861
NodeState initialState,
862862
PgInstanceKind kind, int candidatePriority, bool quorum,
863863
char *citusClusterName,
864+
char *region,
864865
bool *mayRetry,
865866
MonitorAssignedState *assignedState)
866867
{
867868
PGSQL *pgsql = &monitor->pgsql;
868869
const char *sql =
869870
"SELECT * FROM pgautofailover.register_node($1, $2, $3, $4, $5, $6, $7, "
870-
"$8, $9::pgautofailover.replication_state, $10, $11, $12, $13)";
871-
int paramCount = 13;
872-
Oid paramTypes[13] = {
871+
"$8, $9::pgautofailover.replication_state, $10, $11, $12, $13, $14)";
872+
int paramCount = 14;
873+
Oid paramTypes[14] = {
873874
TEXTOID, TEXTOID, INT4OID, NAMEOID, TEXTOID, INT8OID,
874-
INT8OID, INT4OID, TEXTOID, TEXTOID, INT4OID, BOOLOID, TEXTOID
875+
INT8OID, INT4OID, TEXTOID, TEXTOID, INT4OID, BOOLOID, TEXTOID, TEXTOID
875876
};
876-
const char *paramValues[13];
877+
const char *paramValues[14];
877878
MonitorAssignedStateParseContext parseContext =
878879
{ { 0 }, assignedState, false };
879880
const char *nodeStateString = NodeStateToString(initialState);
@@ -899,6 +900,10 @@ monitor_register_node(Monitor *monitor, char *formation,
899900
IS_EMPTY_STRING_BUFFER(citusClusterName)
900901
? DEFAULT_CITUS_CLUSTER_NAME
901902
: citusClusterName;
903+
paramValues[13] =
904+
IS_EMPTY_STRING_BUFFER(region)
905+
? "default"
906+
: region;
902907

903908
if (!pgsql_execute_with_params(pgsql, sql,
904909
paramCount, paramTypes, paramValues,

src/bin/pg_autoctl/monitor.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,7 @@ bool monitor_register_node(Monitor *monitor,
140140
int candidatePriority,
141141
bool quorum,
142142
char *citusClusterName,
143+
char *region,
143144
bool *mayRetry,
144145
MonitorAssignedState *assignedState);
145146
bool monitor_node_active(Monitor *monitor,

src/bin/pg_autoctl/nodespec.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,9 @@ nodespec_read(const char *path, NodeSpec *spec)
114114
make_strbuf_option_default("settings", "replication_quorum", NULL, false,
115115
sizeof(replicationQuorumStr),
116116
replicationQuorumStr, "true"),
117+
make_strbuf_option_default("settings", "region", NULL, false,
118+
sizeof(spec->region), spec->region,
119+
""),
117120

118121
/* [options] — immutable, used only at create time */
119122
make_strbuf_option_default("options", "ssl", NULL, false,
@@ -694,6 +697,13 @@ nodespec_create_argv(const NodeSpec *spec,
694697
PUSH("false");
695698
}
696699

700+
/* region label (omit when empty — monitor defaults to "default") */
701+
if (!IS_EMPTY_STRING_BUFFER(spec->region))
702+
{
703+
PUSH("--region");
704+
PUSH(spec->region);
705+
}
706+
697707
/* Citus secondary/read-replica cluster settings */
698708
if (spec->citusSecondary)
699709
{

src/bin/pg_autoctl/nodespec.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ typedef struct NodeSpec
7171
/* [settings] — mutable; applied on SIGHUP / file change */
7272
int candidate_priority; /* 0-100, default 50 */
7373
bool replication_quorum; /* sync quorum participant, default true */
74+
char region[NAMEDATALEN]; /* data-centre / availability zone label */
7475

7576
/* [options] — immutable; used only at pg_autoctl create time */
7677
char ssl[32]; /* self-signed | verify-ca | verify-full | off */

0 commit comments

Comments
 (0)