Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 7c48fae

Browse files
committed
Add synchronous promotion support on pg of version < 10
1 parent 5ea4bd8 commit 7c48fae

File tree

1 file changed

+18
-4
lines changed

1 file changed

+18
-4
lines changed

testgres/node.py

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -683,17 +683,19 @@ def reload(self, params=[]):
683683
_params = [
684684
get_bin_path("pg_ctl"),
685685
"-D", self.data_dir,
686-
"-w", # wait
687686
"reload"
688687
] + params # yapf: disable
689688

690689
execute_utility(_params, self.utils_log_file)
691690

692691
return self
693692

694-
def promote(self):
693+
def promote(self, dbname=None, username=None):
695694
"""
696-
Promote standby instance to master using pg_ctl.
695+
Promote standby instance to master using pg_ctl. For PostgreSQL versions
696+
below 10 some additional actions required to ensure that instance
697+
became writable and hence `dbname` and `username` parameters may be
698+
needed.
697699
698700
Returns:
699701
This instance of :class:`.PostgresNode`.
@@ -708,7 +710,19 @@ def promote(self):
708710

709711
execute_utility(_params, self.utils_log_file)
710712

711-
# Node becomes master itself
713+
# for versions below 10 `promote` is asynchronous so we need to wait
714+
# until it actually becomes writable
715+
if not pg_version_ge("10"):
716+
check_query = "SHOW transaction_read_only"
717+
718+
self.poll_query_until(
719+
query=check_query,
720+
expected="on",
721+
dbname=dbname,
722+
username=username,
723+
max_attempts=0) # infinite
724+
725+
# node becomes master itself
712726
self._master = None
713727

714728
return self

0 commit comments

Comments
 (0)