aboutsummaryrefslogtreecommitdiff
path: root/src/backend/access/transam/xlog.c
diff options
context:
space:
mode:
authorAlexander Korotkov <akorotkov@postgresql.org>2020-04-07 23:51:10 +0300
committerAlexander Korotkov <akorotkov@postgresql.org>2020-04-07 23:51:10 +0300
commit0f5ca02f53ac2b211d8518f0882c49284c0c9610 (patch)
treea5dce13eaa64e00a6ec95b913a155efe7f91c99c /src/backend/access/transam/xlog.c
parent357889eb17bb9c9336c4f324ceb1651da616fe57 (diff)
downloadpostgresql-0f5ca02f53ac2b211d8518f0882c49284c0c9610.tar.gz
postgresql-0f5ca02f53ac2b211d8518f0882c49284c0c9610.zip
Implement waiting for given lsn at transaction start
This commit adds following optional clause to BEGIN and START TRANSACTION commands. WAIT FOR LSN lsn [ TIMEOUT timeout ] New clause pospones transaction start till given lsn is applied on standby. This clause allows user be sure, that changes previously made on primary would be visible on standby. New shared memory struct is used to track awaited lsn per backend. Recovery process wakes up backend once required lsn is applied. Author: Ivan Kartyshov, Anna Akenteva Reviewed-by: Craig Ringer, Thomas Munro, Robert Haas, Kyotaro Horiguchi Reviewed-by: Masahiko Sawada, Ants Aasma, Dmitry Ivanov, Simon Riggs Reviewed-by: Amit Kapila, Alexander Korotkov Discussion: https://postgr.es/m/0240c26c-9f84-30ea-fca9-93ab2df5f305%40postgrespro.ru
Diffstat (limited to 'src/backend/access/transam/xlog.c')
-rw-r--r--src/backend/access/transam/xlog.c13
1 files changed, 13 insertions, 0 deletions
diff --git a/src/backend/access/transam/xlog.c b/src/backend/access/transam/xlog.c
index ec55d68d272..1651e15e898 100644
--- a/src/backend/access/transam/xlog.c
+++ b/src/backend/access/transam/xlog.c
@@ -42,6 +42,7 @@
#include "catalog/pg_database.h"
#include "commands/progress.h"
#include "commands/tablespace.h"
+#include "commands/wait.h"
#include "common/controldata_utils.h"
#include "executor/instrument.h"
#include "miscadmin.h"
@@ -7154,6 +7155,7 @@ StartupXLOG(void)
do
{
bool switchedTLI = false;
+ XLogRecPtr minWaitedLSN;
#ifdef WAL_DEBUG
if (XLOG_DEBUG ||
@@ -7357,6 +7359,17 @@ StartupXLOG(void)
break;
}
+ /*
+ * If we replayed an LSN that someone was waiting for, set
+ * latches in shared memory array to notify the waiter.
+ */
+ minWaitedLSN = WaitLSNGetMin();
+ if (!XLogRecPtrIsInvalid(minWaitedLSN) &&
+ minWaitedLSN <= XLogCtl->lastReplayedEndRecPtr)
+ {
+ WaitLSNSetLatch(XLogCtl->lastReplayedEndRecPtr);
+ }
+
/* Else, try to fetch the next WAL record */
record = ReadRecord(xlogreader, LOG, false);
} while (record != NULL);