Skip to content
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
6 changes: 6 additions & 0 deletions pgsync/sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -2020,6 +2020,12 @@ def pull(self, polling: bool = False) -> None:
self.index, self.sync(txmin=txmin, txmax=txmax)
)

# PostgreSQL polling uses only the forward pass and has no logical
# replication slot, so advance its safe snapshot checkpoint directly.
if polling and not self.is_mysql_compat:
self.checkpoint = snapshot_xmin
return

if self.is_mysql_compat:
self.binlog_changes(
start_log=start_log,
Expand Down
23 changes: 23 additions & 0 deletions tests/test_sync_polling.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,29 @@ def make_sync():
)


def test_pull_polling_updates_checkpoint_without_logical_slot():
"""PostgreSQL polling must not depend on logical replication."""
docs = [{"_id": "1"}]
sync = SimpleNamespace(
is_mysql_compat=False,
checkpoint=1,
txid_snapshot_xmin=100,
txid_current=200,
current_wal_lsn="0/16B6C50",
index="testdb",
search_client=Mock(),
sync=Mock(return_value=docs),
logical_slot_changes=Mock(),
_truncate=False,
)

Sync.pull(sync, polling=True)

assert sync.checkpoint == 100
sync.logical_slot_changes.assert_not_called()
sync.search_client.bulk.assert_called_once_with("testdb", docs)


def test_poll_db_once_flushes_buffer_when_notification_wait_times_out():
sync = make_sync()
conn = Mock()
Expand Down