On Fri, Jul 23, 2021 at 3:39 PM Ajin Cherian <itsa...@gmail.com> wrote: >
Let's first split the patch for prepared and non-prepared cases as that will help to focus on each of them separately. BTW, why haven't you considered implementing point 1b as explained by Andres in his email [1]? I think we can send a keepalive message in case of synchronous replication when we skip an empty transaction, otherwise, it might delay in responding to transactions synchronous_commit mode. I think in the tests done in the thread, it might not have been shown because we are already sending keepalives too frequently. But what if someone disables wal_sender_timeout or kept it to a very large value? See WalSndKeepaliveIfNecessary. The other thing you might want to look at is if the reason for frequent keepalives is the same as described in the email [2]. Few other miscellaneous comments: 1. static void pgoutput_commit_prepared_txn(LogicalDecodingContext *ctx, ReorderBufferTXN *txn, - XLogRecPtr commit_lsn) + XLogRecPtr commit_lsn, XLogRecPtr prepare_end_lsn, + TimestampTz prepare_time) { + PGOutputTxnData *txndata = (PGOutputTxnData *) txn->output_plugin_private; + OutputPluginUpdateProgress(ctx); + /* + * If the BEGIN PREPARE was not yet sent, then it means there were no + * relevant changes encountered, so we can skip the COMMIT PREPARED + * message too. + */ + if (txndata) + { + bool skip = !txndata->sent_begin_txn; + pfree(txndata); + txn->output_plugin_private = NULL; How is this supposed to work after the restart when prepared is sent before the restart and we are just sending commit_prepared after restart? Won't this lead to sending commit_prepared even when the corresponding prepare is not sent? Can we think of a better way to deal with this? 2. @@ -222,8 +224,10 @@ logicalrep_write_commit_prepared(StringInfo out, ReorderBufferTXN *txn, pq_sendbyte(out, flags); /* send fields */ + pq_sendint64(out, prepare_end_lsn); pq_sendint64(out, commit_lsn); pq_sendint64(out, txn->end_lsn); + pq_sendint64(out, prepare_time); Doesn't this means a change of protocol and how is it suppose to work when say publisher is 15 and subscriber from 14 which I think works without such a change? [1] - https://www.postgresql.org/message-id/20200309183018.tzkzwu635sd366ej%40alap3.anarazel.de [2] - https://www.postgresql.org/message-id/CALtH27cip5uQNJb4uHjLXtx1R52ELqXVfcP9fhHr%3DAvFo1dtqw%40mail.gmail.com -- With Regards, Amit Kapila.