Re: logical replication empty transactions - Mailing list pgsql-hackers
From | Peter Smith |
---|---|
Subject | Re: logical replication empty transactions |
Date | |
Msg-id | CAHut+Puhjzek8zEJ79SX5Vzmi+tfi_j1QKh27mqAXmvQLwxkhw@mail.gmail.com Whole thread Raw |
In response to | Re: logical replication empty transactions (Ajin Cherian <itsajin@gmail.com>) |
List | pgsql-hackers |
On Sat, Aug 7, 2021 at 12:01 AM Ajin Cherian <itsajin@gmail.com> wrote: > > On Mon, Aug 2, 2021 at 7:20 PM Amit Kapila <amit.kapila16@gmail.com> wrote: > > > > On Fri, Jul 23, 2021 at 3:39 PM Ajin Cherian <itsajin@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. > > As a first shot, I have split the patch into prepared and non-prepared cases, I have reviewed the v12* split patch set. Apply / build / test was all OK Below are my code review comments (mostly cosmetic). ////////// Comments for v12-0001 ===================== 1. Patch comment => This comment as-is might have been OK before the 2PC code was committed, but now that the 2PC is part of the HEAD perhaps this comment needs to be expanded just to say this patch is ONLY for fixing empty transactions for the cases of non-"streaming" and non-"two_phase", and the other kinds will be tackled separately. ------ 2. src/backend/replication/pgoutput/pgoutput.c - PGOutputTxnData comment +/* + * Maintain a per-transaction level variable to track whether the + * transaction has sent BEGIN or BEGIN PREPARE. BEGIN or BEGIN PREPARE + * is only sent when the first change in a transaction is processed. + * This makes it possible to skip transactions that are empty. + */ => Maybe this is true for the combined v12-0001/v12-0002 case but just for the v12-0001 patch I think it is nor right to imply that some skipping of the BEGIN_PREPARE is possible, because IIUC it isn;t implemented in the *this* patch/ ------ 3. src/backend/replication/pgoutput/pgoutput.c - pgoutput_begin_txn whitespace + PGOutputTxnData *txndata = MemoryContextAllocZero(ctx->context, + sizeof(PGOutputTxnData)); => Misaligned indentation? ------ 4. src/backend/replication/pgoutput/pgoutput.c - pgoutput_change brackets + /* + * Output BEGIN if we haven't yet, unless streaming. + */ + if (!in_streaming && !txndata->sent_begin_txn) + { + pgoutput_begin(ctx, txn); + } => The brackets are not needed for the if with a single statement. ------ 5. src/backend/replication/pgoutput/pgoutput.c - pgoutput_truncate brackets/comment + /* + * output BEGIN if we haven't yet, + * while streaming no need to send BEGIN / BEGIN PREPARE. + */ + if (!in_streaming && !txndata->sent_begin_txn) + { + pgoutput_begin(ctx, txn); + } 5a. => Same as review comment 4. The brackets are not needed for the if with a single statement. 5b. => Notice this code is the same as cited in review comment 4. So probably the code comment should be consistent/same also? ------ 6. src/backend/replication/pgoutput/pgoutput.c - pgoutput_message brackets + Assert(txndata); + if (!txndata->sent_begin_txn) + { + pgoutput_begin(ctx, txn); + } => The brackets are not needed for the if with a single statement. ------ 7. typdefs.list => The structure PGOutputTxnData was added in v12-0001, so the typedefs.list probably should also be updated. ////////// Comments for v12-0002 ===================== 8. Patch comment This patch addresses the above problem by postponing the BEGIN / BEGIN PREPARE messages until the first change is encountered. If (when processing a COMMIT / PREPARE message) we find there had been no other change for that transaction, then do not send the COMMIT / PREPARE message. This means that pgoutput will skip BEGIN / COMMIT or BEGIN PREPARE / PREPARE messages for transactions that are empty. pgoutput will also skip COMMIT PREPARED and ROLLBACK PREPARED messages for transactions that are empty. 8a. => I’m not sure this comment is 100% correct for this specific patch. The whole BEGIN/COMMIT was already handled by the v12-0001 patch, right? So really this comment should only be mentioning about BEGIN PREPARE and COMMIT PREPARED I thought. 8b. => I think there should also be some mention that this patch is not handling the "streaming" case of empty tx at all. ------ 9. src/backend/replication/logical/proto.c - protocol version @@ -248,8 +250,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); pq_sendint64(out, txn->xact_time.commit_time); pq_sendint32(out, txn->xid); => I agree with a previous feedback comment from Amit - Probably there is some protocol version requirement/implications here because the message format has been changed in logicalrep_write_commit_prepared and logicalrep_read_commit_prepared. e.g. Does this code need to be cognisant of the version and behave differently accordingly? ------ 10. src/backend/replication/pgoutput/pgoutput.c - pgoutput_begin_prepare flag moved? + Assert(txndata); OutputPluginPrepareWrite(ctx, !send_replication_origin); logicalrep_write_begin_prepare(ctx->out, txn); + txndata->sent_begin_txn = true; send_repl_origin(ctx, txn->origin_id, txn->origin_lsn, send_replication_origin); OutputPluginWrite(ctx, true); - txndata->sent_begin_txn = true; - txn->output_plugin_private = txndata; } => In the v12-0001 patch, you set the begin_txn flags AFTER the OuputPluginWrite, but in the v12-0002 you set them BEFORE the OuputPluginWrite. Why the difference? Maybe it should be consistent? ------ 11. src/test/subscription/t/021_twophase.pl - proto_version tests needed? Does this need some other tests to make sure the older proto_version is still usable? Refer also to the review comment 9. ------ 12. src/tools/pgindent/typedefs.list - PGOutputTxnData PGOutputData +PGOutputTxnData PGPROC => This change looks good, but I think it should have been done in v12-0001 and not here in v12-0002. ------ Kind Regards, Peter Smith. Fujitsu Australia
pgsql-hackers by date: