diff options
author | Andres Freund <andres@anarazel.de> | 2016-04-23 19:18:00 -0700 |
---|---|---|
committer | Andres Freund <andres@anarazel.de> | 2016-04-26 20:21:54 -0700 |
commit | c6ff84b06a68b71719aa1aaa5f6704d8db1b51f8 (patch) | |
tree | bca1d7f785aa03f73b137f3182d028e16abdf519 /src/include | |
parent | 2ac3be2e763d9b971352819f285dd51519e0aeb9 (diff) | |
download | postgresql-c6ff84b06a68b71719aa1aaa5f6704d8db1b51f8.tar.gz postgresql-c6ff84b06a68b71719aa1aaa5f6704d8db1b51f8.zip |
Emit invalidations to standby for transactions without xid.
So far, when a transaction with pending invalidations, but without an
assigned xid, committed, we simply ignored those invalidation
messages. That's problematic, because those are actually sent for a
reason.
Known symptoms of this include that existing sessions on a hot-standby
replica sometimes fail to notice new concurrently built indexes and
visibility map updates.
The solution is to WAL log such invalidations in transactions without an
xid. We considered to alternatively force-assign an xid, but that'd be
problematic for vacuum, which might be run in systems with few xids.
Important: This adds a new WAL record, but as the patch has to be
back-patched, we can't bump the WAL page magic. This means that standbys
have to be updated before primaries; otherwise
"PANIC: standby_redo: unknown op code 32" errors can be encountered.
XXX:
Reported-By: Васильев Дмитрий, Masahiko Sawada
Discussion:
CAB-SwXY6oH=9twBkXJtgR4UC1NqT-vpYAtxCseME62ADwyK5OA@mail.gmail.com
CAD21AoDpZ6Xjg=gFrGPnSn4oTRRcwK1EBrWCq9OqOHuAcMMC=w@mail.gmail.com
Diffstat (limited to 'src/include')
-rw-r--r-- | src/include/replication/reorderbuffer.h | 2 | ||||
-rw-r--r-- | src/include/storage/standby.h | 2 | ||||
-rw-r--r-- | src/include/storage/standbydefs.h | 21 |
3 files changed, 25 insertions, 0 deletions
diff --git a/src/include/replication/reorderbuffer.h b/src/include/replication/reorderbuffer.h index 4c54953a512..e0708940a04 100644 --- a/src/include/replication/reorderbuffer.h +++ b/src/include/replication/reorderbuffer.h @@ -391,6 +391,8 @@ void ReorderBufferAddNewTupleCids(ReorderBuffer *, TransactionId, XLogRecPtr lsn CommandId cmin, CommandId cmax, CommandId combocid); void ReorderBufferAddInvalidations(ReorderBuffer *, TransactionId, XLogRecPtr lsn, Size nmsgs, SharedInvalidationMessage *msgs); +void ReorderBufferImmediateInvalidation(ReorderBuffer *, uint32 ninvalidations, + SharedInvalidationMessage *invalidations); void ReorderBufferProcessXid(ReorderBuffer *, TransactionId xid, XLogRecPtr lsn); void ReorderBufferXidSetCatalogChanges(ReorderBuffer *, TransactionId xid, XLogRecPtr lsn); bool ReorderBufferXidHasCatalogChanges(ReorderBuffer *, TransactionId xid); diff --git a/src/include/storage/standby.h b/src/include/storage/standby.h index aafc9b8a482..52058840a59 100644 --- a/src/include/storage/standby.h +++ b/src/include/storage/standby.h @@ -85,5 +85,7 @@ extern void LogAccessExclusiveLock(Oid dbOid, Oid relOid); extern void LogAccessExclusiveLockPrepare(void); extern XLogRecPtr LogStandbySnapshot(void); +extern void LogStandbyInvalidations(int nmsgs, SharedInvalidationMessage *msgs, + bool relcacheInitFileInval); #endif /* STANDBY_H */ diff --git a/src/include/storage/standbydefs.h b/src/include/storage/standbydefs.h index 609d06edeeb..bd3c97fe434 100644 --- a/src/include/storage/standbydefs.h +++ b/src/include/storage/standbydefs.h @@ -17,17 +17,23 @@ #include "access/xlogreader.h" #include "lib/stringinfo.h" #include "storage/lockdefs.h" +#include "storage/sinval.h" /* Recovery handlers for the Standby Rmgr (RM_STANDBY_ID) */ extern void standby_redo(XLogReaderState *record); extern void standby_desc(StringInfo buf, XLogReaderState *record); extern const char *standby_identify(uint8 info); +extern void standby_desc_invalidations(StringInfo buf, + int nmsgs, SharedInvalidationMessage *msgs, + Oid dbId, Oid tsId, + bool relcacheInitFileInval); /* * XLOG message types */ #define XLOG_STANDBY_LOCK 0x00 #define XLOG_RUNNING_XACTS 0x10 +#define XLOG_INVALIDATIONS 0x20 typedef struct xl_standby_locks { @@ -50,4 +56,19 @@ typedef struct xl_running_xacts TransactionId xids[FLEXIBLE_ARRAY_MEMBER]; } xl_running_xacts; +/* + * Invalidations for standby, currently only when transactions without an + * assigned xid commit. + */ +typedef struct xl_invalidations +{ + Oid dbId; /* MyDatabaseId */ + Oid tsId; /* MyDatabaseTableSpace */ + bool relcacheInitFileInval; /* invalidate relcache init file */ + int nmsgs; /* number of shared inval msgs */ + SharedInvalidationMessage msgs[FLEXIBLE_ARRAY_MEMBER]; +} xl_invalidations; + +#define MinSizeOfInvalidations offsetof(xl_invalidations, msgs) + #endif /* STANDBYDEFS_H */ |