mirror of
https://github.com/postgres/postgres.git
synced 2025-07-08 11:42:09 +03:00
Improve performance of replay of AccessExclusiveLocks
A hot standby replica keeps a list of Access Exclusive locks for a top level transaction. These locks are released when the top level transaction ends. Searching of this list is O(N^2), and each transaction had to pay the price of searching this list for locks, even if it didn't take any AE locks itself. This patch optimizes this case by having the master server track which transactions took AE locks, and passes that along to the standby server in the commit/abort record. This allows the standby to only try to release locks for transactions which actually took any, avoiding the majority of the performance issue. Refactor MyXactAccessedTempRel into MyXactFlags to allow minimal additional cruft with this. Analysis and initial patch by David Rowley Author: David Rowley and Simon Riggs
This commit is contained in:
@ -71,8 +71,27 @@ typedef enum
|
||||
/* Synchronous commit level */
|
||||
extern int synchronous_commit;
|
||||
|
||||
/* Kluge for 2PC support */
|
||||
extern bool MyXactAccessedTempRel;
|
||||
/*
|
||||
* Miscellaneous flag bits to record events which occur on the top level
|
||||
* transaction. These flags are only persisted in MyXactFlags and are intended
|
||||
* so we remember to do certain things later in the transaction. This is
|
||||
* globally accessible, so can be set from anywhere in the code which requires
|
||||
* recording flags.
|
||||
*/
|
||||
extern int MyXactFlags;
|
||||
|
||||
/*
|
||||
* XACT_FLAGS_ACCESSEDTEMPREL - set when a temporary relation is accessed. We
|
||||
* don't allow PREPARE TRANSACTION in that case.
|
||||
*/
|
||||
#define XACT_FLAGS_ACCESSEDTEMPREL (1U << 0)
|
||||
|
||||
/*
|
||||
* XACT_FLAGS_ACQUIREDACCESSEXCLUSIVELOCK - records whether the top level xact
|
||||
* logged any Access Exclusive Locks.
|
||||
*/
|
||||
#define XACT_FLAGS_ACQUIREDACCESSEXCLUSIVELOCK (1U << 1)
|
||||
|
||||
|
||||
/*
|
||||
* start- and end-of-transaction callbacks for dynamically loaded modules
|
||||
@ -137,6 +156,7 @@ typedef void (*SubXactCallback) (SubXactEvent event, SubTransactionId mySubid,
|
||||
#define XACT_XINFO_HAS_INVALS (1U << 3)
|
||||
#define XACT_XINFO_HAS_TWOPHASE (1U << 4)
|
||||
#define XACT_XINFO_HAS_ORIGIN (1U << 5)
|
||||
#define XACT_XINFO_HAS_AE_LOCKS (1U << 6)
|
||||
|
||||
/*
|
||||
* Also stored in xinfo, these indicating a variety of additional actions that
|
||||
@ -364,12 +384,13 @@ extern XLogRecPtr XactLogCommitRecord(TimestampTz commit_time,
|
||||
int nrels, RelFileNode *rels,
|
||||
int nmsgs, SharedInvalidationMessage *msgs,
|
||||
bool relcacheInval, bool forceSync,
|
||||
int xactflags,
|
||||
TransactionId twophase_xid);
|
||||
|
||||
extern XLogRecPtr XactLogAbortRecord(TimestampTz abort_time,
|
||||
int nsubxacts, TransactionId *subxacts,
|
||||
int nrels, RelFileNode *rels,
|
||||
TransactionId twophase_xid);
|
||||
int xactflags, TransactionId twophase_xid);
|
||||
extern void xact_redo(XLogReaderState *record);
|
||||
|
||||
/* xactdesc.c */
|
||||
|
Reference in New Issue
Block a user