Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix when we switch synchronous_standby_names to '*'. #488

Merged
merged 2 commits into from
Nov 2, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/monitor/node_active_protocol.c
Original file line number Diff line number Diff line change
Expand Up @@ -2178,7 +2178,7 @@ synchronous_standby_names(PG_FUNCTION_ARGS)

if (secondaryNode != NULL &&
secondaryNode->replicationQuorum &&
IsCurrentState(secondaryNode, REPLICATION_STATE_SECONDARY))
secondaryNode->goalState == REPLICATION_STATE_SECONDARY)
DimCitus marked this conversation as resolved.
Show resolved Hide resolved
{
/* enable synchronous replication */
PG_RETURN_TEXT_P(cstring_to_text("*"));
Expand Down
5 changes: 5 additions & 0 deletions tests/test_auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,14 @@ def test_003_init_secondary():
assert node2.wait_until_state(target_state="secondary")
assert node1.wait_until_state(target_state="primary")

eq_(node1.get_synchronous_standby_names_local(), '*')
DimCitus marked this conversation as resolved.
Show resolved Hide resolved

def test_004_failover():
print()
print("Calling pgautofailover.failover() on the monitor")
cluster.monitor.failover()

assert node2.wait_until_state(target_state="primary")
eq_(node2.get_synchronous_standby_names_local(), '*')

assert node1.wait_until_state(target_state="secondary")
22 changes: 22 additions & 0 deletions tests/test_basic_operation.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ def test_004_init_secondary():

assert node2.wait_until_state(target_state="secondary")
assert node1.wait_until_state(target_state="primary")
eq_(node1.get_synchronous_standby_names_local(), '*')

assert node1.has_needed_replication_slots()
assert node2.has_needed_replication_slots()
Expand Down Expand Up @@ -96,6 +97,8 @@ def test_007b_maintenance_primary_allow_failover():
assert node1.wait_until_state(target_state="secondary")
assert node2.wait_until_state(target_state="primary")

eq_(node2.get_synchronous_standby_names_local(), '*')

def test_008_maintenance_secondary():
print()
print("Enabling maintenance on node2")
Expand All @@ -111,13 +114,17 @@ def test_008_maintenance_secondary():
assert node1.wait_until_state(target_state="secondary")
assert node2.wait_until_state(target_state="primary")

eq_(node2.get_synchronous_standby_names_local(), '*')

# the rest of the tests expect node1 to be primary, make it so
def test_009_failback():
print()
monitor.failover()
assert node2.wait_until_state(target_state="secondary")
assert node1.wait_until_state(target_state="primary")

eq_(node1.get_synchronous_standby_names_local(), '*')

def test_010_fail_primary():
print()
print("Injecting failure of node1")
Expand All @@ -131,9 +138,13 @@ def test_011_writes_to_node2_succeed():

def test_012_start_node1_again():
node1.run()

assert node2.wait_until_state(target_state="primary")
eq_(node2.get_synchronous_standby_names_local(), '*')

assert node1.wait_until_state(target_state="secondary")


def test_013_read_from_new_secondary():
results = node1.run_sql_query("SELECT * FROM t1 ORDER BY a")
assert results == [(1,), (2,), (3,), (4,)]
Expand Down Expand Up @@ -173,6 +184,8 @@ def test_019_run_secondary():
assert node2.has_needed_replication_slots()
assert node3.has_needed_replication_slots()

eq_(node2.get_synchronous_standby_names_local(), '*')

# In previous versions of pg_auto_failover we removed the replication slot
# on the secondary after failover. Now, we instead maintain the replication
# slot's replay_lsn thanks for the monitor tracking of the nodes' LSN
Expand All @@ -193,14 +206,19 @@ def test_020_multiple_manual_failover_verify_replication_slots():
assert node2.has_needed_replication_slots()
assert node3.has_needed_replication_slots()

eq_(node3.get_synchronous_standby_names_local(), '*')

print("Calling pg_autoctl perform promotion on node 2")
node2.perform_promotion()
assert node2.wait_until_state(target_state="primary")
eq_(node2.get_synchronous_standby_names_local(), '*')

assert node3.wait_until_state(target_state="secondary")

assert node2.has_needed_replication_slots()
assert node3.has_needed_replication_slots()


#
# Now test network partition detection. Cut the primary out of the network
# by means of `ifconfig down` on its virtual network interface, and then
Expand All @@ -210,6 +228,7 @@ def test_020_multiple_manual_failover_verify_replication_slots():
def test_021_ifdown_primary():
print()
assert node2.wait_until_state(target_state="primary")
eq_(node2.get_synchronous_standby_names_local(), '*')
node2.ifdown()

def test_022_detect_network_partition():
Expand All @@ -233,6 +252,7 @@ def test_022_detect_network_partition():
print()
assert not node2.pg_is_running()
assert node3.wait_until_state(target_state="wait_primary")
eq_(node3.get_synchronous_standby_names_local(), '')

def test_023_ifup_old_primary():
print()
Expand All @@ -242,6 +262,8 @@ def test_023_ifup_old_primary():
assert node2.wait_until_state("secondary")
assert node3.wait_until_state("primary")

eq_(node3.get_synchronous_standby_names_local(), '*')

def test_024_stop_postgres_monitor():
original_state = node3.get_state()
monitor.stop_postgres()
Expand Down