From 9097a5b98903d03d3a06c570d412cf3a437c67c1 Mon Sep 17 00:00:00 2001 From: Alexander Kukushkin Date: Fri, 5 Jul 2019 08:37:24 +0200 Subject: [PATCH 1/2] Don't advance replication cursor when the message wasn't confirmed Fixes https://github.com/psycopg/psycopg2/issues/940 --- psycopg/pqpath.c | 4 +++- psycopg/replication_cursor.h | 1 + psycopg/replication_cursor_type.c | 3 +++ 3 files changed, 7 insertions(+), 1 deletion(-) diff --git a/psycopg/pqpath.c b/psycopg/pqpath.c index b21f3977..06730562 100644 --- a/psycopg/pqpath.c +++ b/psycopg/pqpath.c @@ -1576,7 +1576,9 @@ retry: /* We can safely forward flush_lsn to the wal_end from the server keepalive message * if we know that the client already processed (confirmed) the last XLogData message */ - if (repl->flush_lsn >= repl->last_msg_data_start && wal_end > repl->flush_lsn) { + if (repl->explicitly_flushed_lsn >= repl->last_msg_data_start + && wal_end > repl->explicitly_flushed_lsn + && wal_end > repl->flush_lsn) { repl->flush_lsn = wal_end; } diff --git a/psycopg/replication_cursor.h b/psycopg/replication_cursor.h index 1b92b09d..ba066b52 100644 --- a/psycopg/replication_cursor.h +++ b/psycopg/replication_cursor.h @@ -52,6 +52,7 @@ typedef struct replicationCursorObject { XLogRecPtr last_msg_data_start; /* WAL pointer to the last non-keepalive message from the server */ struct timeval last_feedback; /* timestamp of the last feedback message to the server */ + XLogRecPtr explicitly_flushed_lsn; /* the flush LSN explicitly set by the send_feedback call */ } replicationCursorObject; diff --git a/psycopg/replication_cursor_type.c b/psycopg/replication_cursor_type.c index 5fdeaf03..c1dbd431 100644 --- a/psycopg/replication_cursor_type.c +++ b/psycopg/replication_cursor_type.c @@ -211,6 +211,9 @@ send_feedback(replicationCursorObject *self, if (write_lsn > self->write_lsn) self->write_lsn = write_lsn; + if (flush_lsn > self->explicitly_flushed_lsn) + self->explicitly_flushed_lsn = flush_lsn; + if (flush_lsn > self->flush_lsn) self->flush_lsn = flush_lsn; From 63352d7da0cfc0a8e30577a3bb4e1b3504b1e0ab Mon Sep 17 00:00:00 2001 From: Daniele Varrazzo Date: Sat, 19 Oct 2019 18:02:32 +0100 Subject: [PATCH 2/2] Mention bug 940 fixed in NEWS file --- NEWS | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/NEWS b/NEWS index da996b83..ed7c24da 100644 --- a/NEWS +++ b/NEWS @@ -4,8 +4,10 @@ Current release What's new in psycopg 2.8.4 ^^^^^^^^^^^^^^^^^^^^^^^^^^^ -Don't swallow keyboard interrupts on connect when a password is specified -in the connection string (:ticket:`#898`). +- Don't swallow keyboard interrupts on connect when a password is specified + in the connection string (:ticket:`#898`). +- Don't advance replication cursor when the message wasn't confirmed + (:ticket:`#940`). What's new in psycopg 2.8.3