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

Commit 06d1005

Browse files
committed
Add synchronous promotion support on pg of version < 10
1 parent c6e61b9 commit 06d1005

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
@@ -662,17 +662,19 @@ def reload(self, params=[]):
662662
_params = [
663663
get_bin_path("pg_ctl"),
664664
"-D", self.data_dir,
665-
"-w", # wait
666665
"reload"
667666
] + params # yapf: disable
668667

669668
execute_utility(_params, self.utils_log_file)
670669

671670
return self
672671

673-
def promote(self):
672+
def promote(self, dbname=None, username=None):
674673
"""
675-
Promote standby instance to master using pg_ctl.
674+
Promote standby instance to master using pg_ctl. For PostgreSQL versions
675+
below 10 some additional actions required to ensure that instance
676+
became writable and hence `dbname` and `username` parameters may be
677+
needed.
676678
677679
Returns:
678680
This instance of :class:`.PostgresNode`.
@@ -687,7 +689,19 @@ def promote(self):
687689

688690
execute_utility(_params, self.utils_log_file)
689691

690-
# Node becomes master itself
692+
# for versions below 10 `promote` is asynchronous so we need to wait
693+
# until it actually becomes writable
694+
if not pg_version_ge("10"):
695+
check_query = "SHOW transaction_read_only"
696+
697+
self.poll_query_until(
698+
query=check_query,
699+
expected="on",
700+
dbname=dbname,
701+
username=username,
702+
max_attempts=0) # infinite
703+
704+
# node becomes master itself
691705
self._master = None
692706

693707
return self

0 commit comments

Comments
 (0)