8000 Logical replication support by zilder · Pull Request #42 · postgrespro/testgres · GitHub
[go: up one dir, main page]

Skip to content

Logical replication support #42

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

Merged
merged 16 commits into from
Jun 1, 2018
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
8000 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
Prev Previous commit
Next Next commit
Some minor refactoring of logical replication
  • Loading branch information
zilder committed Mar 22, 2018
commit b1cba73cf385896e7307998f230ec9b4a43f8aa4
23 changes: 9 additions & 14 deletions testgres/node.py
Original file line number Diff line number Diff line change
Expand Up @@ -847,8 +847,7 @@ def poll_query_until(self,
expected=True,
commit=True,
raise_programming_error=True,
raise_internal_error=True,
zero_rows_is_ok=False):
raise_internal_error=True):
"""
Run a query once per second until it returns 'expected'.
Query should return a single value (1 row, 1 column).
Expand Down Expand Up @@ -884,18 +883,14 @@ def poll_query_until(self,
if res is None:
raise QueryException('Query returned None', query)

if len(res) == 0:
if zero_rows_is_ok:
time.sleep(sleep_time)
attempts += 1
continue
else:
raise QueryException('Query returned 0 rows', query)

if len(res[0]) == 0:
raise QueryException('Query returned 0 columns', query)

if res[0][0] == expected:
# result set is not empty
if len(res):
if len(res[0]) == 0:
raise QueryException('Query returned 0 columns', query)
if res[0][0] == expected:
return # done
# empty result set is considered as None
elif expected is None:
return # done

except ProgrammingError as e:
Expand Down
17 changes: 5 additions & 12 deletions testgres/pubsub.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,24 +138,17 @@ def catchup(self, username=None):
Args:
username: remote node's user name
"""
if pg_version_ge('10'):
query = (
"select pg_current_wal_lsn() - replay_lsn = 0 "
"from pg_stat_replication where application_name = '{}'"
).format(self.name)
else:
query = (
"select pg_current_xlog_location() - replay_location = 0 "
"from pg_stat_replication where application_name = '{}'"
).format(self.name)
query = (
"select pg_current_wal_lsn() - replay_lsn = 0 "
"from pg_stat_replication where application_name = '{}'"
).format(self.name)

try:
# wait until this LSN reaches subscriber
self.pub.node.poll_query_until(
query=query,
dbname=self.pub.dbname,
username=username or self.pub.username,
max_attempts=60,
zero_rows_is_ok=True) # statistics may have not updated yet
max_attempts=60)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Personally, I don't like the hard-coded number.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it should be a parameter here.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, added LOGICAL_REPL_MAX_CATCHUP_ATTEMPTS parameter

except Exception as e:
raise_from(CatchUpException("Failed to catch up", query), e)
9 changes: 4 additions & 5 deletions tests/test_simple.py
Original file line number Diff line number Diff line change
Expand Up @@ -495,11 +495,6 @@ def test_poll_query_until(self):

self.assertTrue(end_time - start_time >= 5)

# check 0 rows
with self.assertRaises(QueryException):
node.poll_query_until(
query='select * from pg_class where true = false')

# check 0 columns
with self.assertRaises(QueryException):
node.poll_query_until(query='select from pg_class limit 1')
Expand All @@ -512,6 +507,10 @@ def test_poll_query_until(self):
node.poll_query_until(
query='create table def()', expected=None) # returns nothing

# check 0 rows equivalent to expected=None
node.poll_query_until(
query='select * from pg_class where true = false', expected=None)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pg_class should be schema-qualified.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done


# check arbitrary expected value, fail
with self.assertRaises(TimeoutException):
node.poll_query_until(
Expand Down
0