mirror of
https://github.com/postgres/postgres.git
synced 2025-07-26 01:22:12 +03:00
Avoid unnecessary streaming of transactions during logical replication.
After restart, we don't perform streaming of an in-progress transaction if it was previously decoded and confirmed by the client. To achieve that we were comparing the END location of the WAL record being decoded with the WAL location we have already decoded and confirmed by the client. While decoding the commit record, to decide whether to process and send the complete transaction, we compare its START location with the WAL location we have already decoded and confirmed by the client. Now, if we need to queue some change in the transaction while decoding the commit record (e.g. snapshot), it is possible that we decide to stream the transaction but later commit processing decides to skip it. In such a case, we would needlessly send the changes and later when we decide to skip it, we will send stream abort. We also sometimes decide to stream the changes when we actually just need to process them locally like a change for invalidations. This will lead us to send empty streams. To avoid this, while queuing each change for decoding, we remember whether the transaction has any change that actually needs to be sent downstream and use that information later to decide whether to stream the transaction or not. Note, we can't avoid all cases where we have to send empty streams like the case where the plugin later decides that the change is not publishable. However, we will no longer need to send stream_abort when we skip sending a particular transaction. Author: Dilip Kumar Reviewed-by: Hou Zhijie, Ashutosh Bapat, Shi yu, Amit Kapila Discussion: https://postgr.es/m/CAFiTN-tHK=7LzfrPs8fbT2ksrOJGQbzywcgXst2bM9-rJJAAUg@mail.gmail.com
This commit is contained in:
@ -168,14 +168,15 @@ typedef struct ReorderBufferChange
|
||||
} ReorderBufferChange;
|
||||
|
||||
/* ReorderBufferTXN txn_flags */
|
||||
#define RBTXN_HAS_CATALOG_CHANGES 0x0001
|
||||
#define RBTXN_IS_SUBXACT 0x0002
|
||||
#define RBTXN_IS_SERIALIZED 0x0004
|
||||
#define RBTXN_IS_SERIALIZED_CLEAR 0x0008
|
||||
#define RBTXN_IS_STREAMED 0x0010
|
||||
#define RBTXN_HAS_PARTIAL_CHANGE 0x0020
|
||||
#define RBTXN_PREPARE 0x0040
|
||||
#define RBTXN_SKIPPED_PREPARE 0x0080
|
||||
#define RBTXN_HAS_CATALOG_CHANGES 0x0001
|
||||
#define RBTXN_IS_SUBXACT 0x0002
|
||||
#define RBTXN_IS_SERIALIZED 0x0004
|
||||
#define RBTXN_IS_SERIALIZED_CLEAR 0x0008
|
||||
#define RBTXN_IS_STREAMED 0x0010
|
||||
#define RBTXN_HAS_PARTIAL_CHANGE 0x0020
|
||||
#define RBTXN_PREPARE 0x0040
|
||||
#define RBTXN_SKIPPED_PREPARE 0x0080
|
||||
#define RBTXN_HAS_STREAMABLE_CHANGE 0x0100
|
||||
|
||||
/* Does the transaction have catalog changes? */
|
||||
#define rbtxn_has_catalog_changes(txn) \
|
||||
@ -207,6 +208,12 @@ typedef struct ReorderBufferChange
|
||||
((txn)->txn_flags & RBTXN_HAS_PARTIAL_CHANGE) != 0 \
|
||||
)
|
||||
|
||||
/* Does this transaction contain streamable changes? */
|
||||
#define rbtxn_has_streamable_change(txn) \
|
||||
( \
|
||||
((txn)->txn_flags & RBTXN_HAS_STREAMABLE_CHANGE) != 0 \
|
||||
)
|
||||
|
||||
/*
|
||||
* Has this transaction been streamed to downstream?
|
||||
*
|
||||
|
Reference in New Issue
Block a user