1
0
mirror of https://github.com/postgres/postgres.git synced 2025-07-05 07:21:24 +03:00

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
This commit is contained in:
Alexander Korotkov
2020-04-07 23:51:10 +03:00
parent 357889eb17
commit 0f5ca02f53
20 changed files with 585 additions and 10 deletions

View File

@ -2784,6 +2784,28 @@ _outDefElem(StringInfo str, const DefElem *node)
WRITE_LOCATION_FIELD(location);
}
static void
_outTransactionStmt(StringInfo str, const TransactionStmt *node)
{
WRITE_NODE_TYPE("TRANSACTIONSTMT");
WRITE_STRING_FIELD(savepoint_name);
WRITE_STRING_FIELD(gid);
WRITE_NODE_FIELD(options);
WRITE_BOOL_FIELD(chain);
WRITE_ENUM_FIELD(kind, TransactionStmtKind);
WRITE_NODE_FIELD(wait);
}
static void
_outWaitClause(StringInfo str, const WaitClause *node)
{
WRITE_NODE_TYPE("WAITCLAUSE");
WRITE_STRING_FIELD(lsn);
WRITE_UINT_FIELD(timeout);
}
static void
_outTableLikeClause(StringInfo str, const TableLikeClause *node)
{
@ -4334,6 +4356,12 @@ outNode(StringInfo str, const void *obj)
case T_PartitionRangeDatum:
_outPartitionRangeDatum(str, obj);
break;
case T_TransactionStmt:
_outTransactionStmt(str, obj);
break;
case T_WaitClause:
_outWaitClause(str, obj);
break;
default: