diff options
author | Robert Haas <rhaas@postgresql.org> | 2016-03-29 21:16:12 -0400 |
---|---|---|
committer | Robert Haas <rhaas@postgresql.org> | 2016-03-29 21:29:49 -0400 |
commit | 314cbfc5da988eff8998655158f84c9815ecfbcd (patch) | |
tree | 94415b7fed00b4a70f337e403c1d5fe7e811ec70 /src/backend/access/transam/xlog.c | |
parent | a898b409f66f956e99694710f537829db02652c0 (diff) | |
download | postgresql-314cbfc5da988eff8998655158f84c9815ecfbcd.tar.gz postgresql-314cbfc5da988eff8998655158f84c9815ecfbcd.zip |
Add new replication mode synchronous_commit = 'remote_apply'.
In this mode, the master waits for the transaction to be applied on
the remote side, not just written to disk. That means that you can
count on a transaction started on the standby to see all commits
previously acknowledged by the master.
To make this work, the standby sends a reply after replaying each
commit record generated with synchronous_commit >= 'remote_apply'.
This introduces a small inefficiency: the extra replies will be sent
even by standbys that aren't the current synchronous standby. But
previously-existing synchronous_commit levels make no attempt at all
to optimize which replies are sent based on what the primary cares
about, so this is no worse, and at least avoids any extra replies for
people not using the feature at all.
Thomas Munro, reviewed by Michael Paquier and by me. Some additional
tweaks by me.
Diffstat (limited to 'src/backend/access/transam/xlog.c')
-rw-r--r-- | src/backend/access/transam/xlog.c | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/src/backend/access/transam/xlog.c b/src/backend/access/transam/xlog.c index b119a47e4e0..06cefe2efeb 100644 --- a/src/backend/access/transam/xlog.c +++ b/src/backend/access/transam/xlog.c @@ -345,6 +345,9 @@ static XLogRecPtr RedoRecPtr; */ static bool doPageWrites; +/* Has the recovery code requested a walreceiver wakeup? */ +static bool doRequestWalReceiverReply; + /* * RedoStartLSN points to the checkpoint's REDO location which is specified * in a backup label file, backup history file or control file. In standby @@ -6879,6 +6882,17 @@ StartupXLOG(void) XLogCtl->lastReplayedTLI = ThisTimeLineID; SpinLockRelease(&XLogCtl->info_lck); + /* + * If rm_redo called XLogRequestWalReceiverReply, then we + * wake up the receiver so that it notices the updated + * lastReplayedEndRecPtr and sends a reply to the master. + */ + if (doRequestWalReceiverReply) + { + doRequestWalReceiverReply = false; + WalRcvForceReply(); + } + /* Remember this record as the last-applied one */ LastRec = ReadRecPtr; @@ -11594,3 +11608,12 @@ SetWalWriterSleeping(bool sleeping) XLogCtl->WalWriterSleeping = sleeping; SpinLockRelease(&XLogCtl->info_lck); } + +/* + * Schedule a walreceiver wakeup in the main recovery loop. + */ +void +XLogRequestWalReceiverReply(void) +{ + doRequestWalReceiverReply = true; +} |