Skip to content

Commit c79de59

Browse files
authored
Fix/synchronous standby name wildcard (#629)
* Clean-up what turns out to be unused code. * Refrain from using synchronous_standby_names = '*'. In case users would connect other nodes (not managed by pg_auto_failover) then those would be the target of synchronous transactions, and that wouldn't be expected.
1 parent 814567e commit c79de59

10 files changed

Lines changed: 56 additions & 121 deletions

File tree

src/bin/pg_autoctl/cli_do_misc.c

Lines changed: 0 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -79,50 +79,6 @@ keeper_cli_drop_replication_slot(int argc, char **argv)
7979
}
8080

8181

82-
/*
83-
* keeper_cli_enable_synchronous_replication implements the CLI to enable
84-
* synchronous replication on the primary.
85-
*/
86-
void
87-
keeper_cli_enable_synchronous_replication(int argc, char **argv)
88-
{
89-
KeeperConfig config = keeperOptions;
90-
LocalPostgresServer postgres = { 0 };
91-
bool missingPgdataOk = false;
92-
bool pgNotRunningOk = false;
93-
94-
keeper_config_init(&config, missingPgdataOk, pgNotRunningOk);
95-
local_postgres_init(&postgres, &(config.pgSetup));
96-
97-
if (!primary_enable_synchronous_replication(&postgres))
98-
{
99-
exit(EXIT_CODE_PGSQL);
100-
}
101-
}
102-
103-
104-
/*
105-
* keeper_cli_disable_synchronous_replication implements the CLI to disable
106-
* synchronous replication on the primary.
107-
*/
108-
void
109-
keeper_cli_disable_synchronous_replication(int argc, char **argv)
110-
{
111-
KeeperConfig config = keeperOptions;
112-
LocalPostgresServer postgres = { 0 };
113-
bool missingPgdataOk = false;
114-
bool pgNotRunningOk = false;
115-
116-
keeper_config_init(&config, missingPgdataOk, pgNotRunningOk);
117-
local_postgres_init(&postgres, &(config.pgSetup));
118-
119-
if (!primary_disable_synchronous_replication(&postgres))
120-
{
121-
exit(EXIT_CODE_PGSQL);
122-
}
123-
}
124-
125-
12682
/*
12783
* keeper_cli_add_defaults implements the CLI to add pg_auto_failover default
12884
* settings to postgresql.conf

src/bin/pg_autoctl/cli_do_root.c

Lines changed: 0 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -57,32 +57,6 @@ CommandLine do_primary_adduser =
5757
"Create users on primary", NULL, NULL,
5858
NULL, do_primary_adduser_subcommands);
5959

60-
CommandLine do_primary_syncrep_enable =
61-
make_command("enable",
62-
"Enable synchronous replication on the primary server",
63-
"",
64-
"",
65-
NULL, keeper_cli_enable_synchronous_replication);
66-
67-
CommandLine do_primary_syncrep_disable =
68-
make_command("disable",
69-
"Disable synchronous replication on the primary server",
70-
"",
71-
"",
72-
NULL, keeper_cli_disable_synchronous_replication);
73-
74-
CommandLine *do_primary_syncrep[] = {
75-
&do_primary_syncrep_enable,
76-
&do_primary_syncrep_disable,
77-
NULL
78-
};
79-
80-
CommandLine do_primary_syncrep_ =
81-
make_command_set("syncrep",
82-
"Manage the synchronous replication setting on the primary server",
83-
NULL, NULL,
84-
NULL, do_primary_syncrep);
85-
8660
CommandLine do_primary_slot_create =
8761
make_command("create",
8862
"Create a replication slot on the primary server",
@@ -128,7 +102,6 @@ CommandLine do_primary_identify_system =
128102

129103
CommandLine *do_primary[] = {
130104
&do_primary_slot_,
131-
&do_primary_syncrep_,
132105
&do_primary_adduser,
133106
&do_primary_defaults,
134107
&do_primary_identify_system,

src/bin/pg_autoctl/pgsql.c

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1616,22 +1616,6 @@ parseReplicationSlotMaintain(void *ctx, PGresult *result)
16161616
}
16171617

16181618

1619-
/*
1620-
* pgsql_enable_synchronous_replication enables synchronous replication
1621-
* in Postgres such that all writes block post-commit until they are
1622-
* replicated.
1623-
*/
1624-
bool
1625-
pgsql_enable_synchronous_replication(PGSQL *pgsql)
1626-
{
1627-
GUC setting = { "synchronous_standby_names", "'*'" };
1628-
1629-
log_info("Enabling synchronous replication");
1630-
1631-
return pgsql_alter_system_set(pgsql, setting);
1632-
}
1633-
1634-
16351619
/*
16361620
* pgsql_disable_synchronous_replication disables synchronous replication
16371621
* in Postgres such that writes do not block if there is no replica.

src/bin/pg_autoctl/pgsql.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,6 @@ bool pgsql_replication_slot_create_and_drop(PGSQL *pgsql,
281281
NodeAddressArray *nodeArray);
282282
bool pgsql_replication_slot_maintain(PGSQL *pgsql, NodeAddressArray *nodeArray);
283283
bool postgres_sprintf_replicationSlotName(int nodeId, char *slotName, int size);
284-
bool pgsql_enable_synchronous_replication(PGSQL *pgsql);
285284
bool pgsql_disable_synchronous_replication(PGSQL *pgsql);
286285
bool pgsql_set_default_transaction_mode_read_only(PGSQL *pgsql);
287286
bool pgsql_set_default_transaction_mode_read_write(PGSQL *pgsql);

src/bin/pg_autoctl/primary_standby.c

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -568,24 +568,6 @@ primary_set_synchronous_standby_names(LocalPostgresServer *postgres)
568568
}
569569

570570

571-
/*
572-
* primary_enable_synchronous_replication enables synchronous replication
573-
* on a primary postgres node.
574-
*/
575-
bool
576-
primary_enable_synchronous_replication(LocalPostgresServer *postgres)
577-
{
578-
PGSQL *pgsql = &(postgres->sqlClient);
579-
580-
log_trace("primary_enable_synchronous_replication");
581-
582-
bool result = pgsql_enable_synchronous_replication(pgsql);
583-
584-
pgsql_finish(pgsql);
585-
return result;
586-
}
587-
588-
589571
/*
590572
* primary_disable_synchronous_replication disables synchronous replication
591573
* on a primary postgres node.

src/bin/pg_autoctl/primary_standby.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,6 @@ bool postgres_replication_slot_create_and_drop(LocalPostgresServer *postgres,
7676
NodeAddressArray *nodeArray);
7777
bool postgres_replication_slot_maintain(LocalPostgresServer *postgres,
7878
NodeAddressArray *nodeArray);
79-
bool primary_enable_synchronous_replication(LocalPostgresServer *postgres);
8079
bool primary_disable_synchronous_replication(LocalPostgresServer *postgres);
8180
bool postgres_add_default_settings(LocalPostgresServer *postgres);
8281
bool primary_create_user_with_hba(LocalPostgresServer *postgres, char *userName,

src/monitor/node_active_protocol.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2192,7 +2192,13 @@ synchronous_standby_names(PG_FUNCTION_ARGS)
21922192
secondaryNode->goalState == REPLICATION_STATE_SECONDARY)
21932193
{
21942194
/* enable synchronous replication */
2195-
PG_RETURN_TEXT_P(cstring_to_text("*"));
2195+
StringInfo sbnames = makeStringInfo();
2196+
2197+
appendStringInfo(sbnames,
2198+
"ANY 1 (pgautofailover_standby_%d)",
2199+
secondaryNode->nodeId);
2200+
2201+
PG_RETURN_TEXT_P(cstring_to_text(sbnames->data));
21962202
}
21972203
else
21982204
{

tests/test_auth.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,14 +61,20 @@ def test_003_init_secondary():
6161
assert node2.wait_until_state(target_state="secondary")
6262
assert node1.wait_until_state(target_state="primary")
6363

64-
eq_(node1.get_synchronous_standby_names_local(), "*")
64+
eq_(
65+
node1.get_synchronous_standby_names_local(),
66+
"ANY 1 (pgautofailover_standby_2)",
67+
)
6568

6669

6770
def test_004_failover():
6871
print()
6972
print("Calling pgautofailover.failover() on the monitor")
7073
cluster.monitor.failover(formation="auth")
7174
assert node2.wait_until_state(target_state="primary")
72-
eq_(node2.get_synchronous_standby_names_local(), "*")
75+
eq_(
76+
node2.get_synchronous_standby_names_local(),
77+
"ANY 1 (pgautofailover_standby_1)",
78+
)
7379

7480
assert node1.wait_until_state(target_state="secondary")

tests/test_basic_operation.py

Lines changed: 38 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,10 @@ def test_004_init_secondary():
7272

7373
assert node2.wait_until_state(target_state="secondary")
7474
assert node1.wait_until_state(target_state="primary")
75-
eq_(node1.get_synchronous_standby_names_local(), "*")
75+
eq_(
76+
node1.get_synchronous_standby_names_local(),
77+
"ANY 1 (pgautofailover_standby_2)",
78+
)
7679

7780
assert node1.has_needed_replication_slots()
7881
assert node2.has_needed_replication_slots()
@@ -125,7 +128,9 @@ def test_007_005_disable_maintenance():
125128
assert node1.wait_until_state(target_state="secondary")
126129
assert node2.wait_until_state(target_state="primary")
127130

128-
node2.check_synchronous_standby_names(ssn="*")
131+
node2.check_synchronous_standby_names(
132+
ssn="ANY 1 (pgautofailover_standby_1)"
133+
)
129134

130135

131136
def test_008_001_enable_maintenance_secondary():
@@ -146,7 +151,9 @@ def test_008_002_disable_maintenance_secondary():
146151
assert node1.wait_until_state(target_state="secondary")
147152
assert node2.wait_until_state(target_state="primary")
148153

149-
node2.check_synchronous_standby_names(ssn="*")
154+
node2.check_synchronous_standby_names(
155+
ssn="ANY 1 (pgautofailover_standby_1)"
156+
)
150157

151158

152159
# the rest of the tests expect node1 to be primary, make it so
@@ -156,7 +163,10 @@ def test_009_failback():
156163
assert node2.wait_until_state(target_state="secondary")
157164
assert node1.wait_until_state(target_state="primary")
158165

159-
eq_(node1.get_synchronous_standby_names_local(), "*")
166+
eq_(
167+
node1.get_synchronous_standby_names_local(),
168+
"ANY 1 (pgautofailover_standby_2)",
169+
)
160170

161171

162172
def test_010_fail_primary():
@@ -176,7 +186,10 @@ def test_012_start_node1_again():
176186
node1.run()
177187

178188
assert node2.wait_until_state(target_state="primary")
179-
eq_(node2.get_synchronous_standby_names_local(), "*")
189+
eq_(
190+
node2.get_synchronous_standby_names_local(),
191+
"ANY 1 (pgautofailover_standby_1)",
192+
)
180193

181194
assert node1.wait_until_state(target_state="secondary")
182195

@@ -226,7 +239,10 @@ def test_019_run_secondary():
226239
assert node2.has_needed_replication_slots()
227240
assert node3.has_needed_replication_slots()
228241

229-
eq_(node2.get_synchronous_standby_names_local(), "*")
242+
eq_(
243+
node2.get_synchronous_standby_names_local(),
244+
"ANY 1 (pgautofailover_standby_3)",
245+
)
230246

231247

232248
# In previous versions of pg_auto_failover we removed the replication slot
@@ -249,12 +265,18 @@ def test_020_multiple_manual_failover_verify_replication_slots():
249265
assert node2.has_needed_replication_slots()
250266
assert node3.has_needed_replication_slots()
251267

252-
eq_(node3.get_synchronous_standby_names_local(), "*")
268+
eq_(
269+
node3.get_synchronous_standby_names_local(),
270+
"ANY 1 (pgautofailover_standby_2)",
271+
)
253272

254273
print("Calling pg_autoctl perform promotion on node 2")
255274
node2.perform_promotion()
256275
assert node2.wait_until_state(target_state="primary")
257-
eq_(node2.get_synchronous_standby_names_local(), "*")
276+
eq_(
277+
node2.get_synchronous_standby_names_local(),
278+
"ANY 1 (pgautofailover_standby_3)",
279+
)
258280

259281
assert node3.wait_until_state(target_state="secondary")
260282

@@ -271,7 +293,10 @@ def test_020_multiple_manual_failover_verify_replication_slots():
271293
def test_021_ifdown_primary():
272294
print()
273295
assert node2.wait_until_state(target_state="primary")
274-
eq_(node2.get_synchronous_standby_names_local(), "*")
296+
eq_(
297+
node2.get_synchronous_standby_names_local(),
298+
"ANY 1 (pgautofailover_standby_3)",
299+
)
275300
node2.ifdown()
276301

277302

@@ -308,7 +333,10 @@ def test_023_ifup_old_primary():
308333
assert node2.wait_until_state("secondary")
309334
assert node3.wait_until_state("primary")
310335

311-
eq_(node3.get_synchronous_standby_names_local(), "*")
336+
eq_(
337+
node3.get_synchronous_standby_names_local(),
338+
"ANY 1 (pgautofailover_standby_2)",
339+
)
312340

313341

314342
def test_024_stop_postgres_monitor():

tests/test_multi_maintenance.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,9 @@ def test_002_add_standby():
5151
# make sure we reached primary on node1 before next tests
5252
assert node1.wait_until_state(target_state="primary")
5353

54-
node1.check_synchronous_standby_names(ssn="*")
54+
node1.check_synchronous_standby_names(
55+
ssn="ANY 1 (pgautofailover_standby_2)"
56+
)
5557

5658

5759
def test_003_add_standby():

0 commit comments

Comments
 (0)