diff options
author | Alexander Korotkov <akorotkov@postgresql.org> | 2020-04-07 23:51:10 +0300 |
---|---|---|
committer | Alexander Korotkov <akorotkov@postgresql.org> | 2020-04-07 23:51:10 +0300 |
commit | 0f5ca02f53ac2b211d8518f0882c49284c0c9610 (patch) | |
tree | a5dce13eaa64e00a6ec95b913a155efe7f91c99c /src/backend/parser | |
parent | 357889eb17bb9c9336c4f324ceb1651da616fe57 (diff) | |
download | postgresql-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/parser')
-rw-r--r-- | src/backend/parser/gram.y | 37 |
1 files changed, 32 insertions, 5 deletions
diff --git a/src/backend/parser/gram.y b/src/backend/parser/gram.y index 1219ac8c264..ea1084fa3cf 100644 --- a/src/backend/parser/gram.y +++ b/src/backend/parser/gram.y @@ -601,6 +601,8 @@ static Node *makeRecursiveViewSelect(char *relname, List *aliases, Node *query); %type <partboundspec> PartitionBoundSpec %type <list> hash_partbound %type <defelt> hash_partbound_elem +%type <ival> wait_time +%type <node> wait_for /* * Non-keyword token types. These are hard-wired into the "flex" lexer. @@ -670,7 +672,7 @@ static Node *makeRecursiveViewSelect(char *relname, List *aliases, Node *query); LABEL LANGUAGE LARGE_P LAST_P LATERAL_P LEADING LEAKPROOF LEAST LEFT LEVEL LIKE LIMIT LISTEN LOAD LOCAL - LOCALTIME LOCALTIMESTAMP LOCATION LOCK_P LOCKED LOGGED + LOCALTIME LOCALTIMESTAMP LOCATION LOCK_P LOCKED LOGGED LSN MAPPING MATCH MATERIALIZED MAXVALUE METHOD MINUTE_P MINVALUE MODE MONTH_P MOVE @@ -701,7 +703,7 @@ static Node *makeRecursiveViewSelect(char *relname, List *aliases, Node *query); SUBSCRIPTION SUBSTRING SUPPORT SYMMETRIC SYSID SYSTEM_P TABLE TABLES TABLESAMPLE TABLESPACE TEMP TEMPLATE TEMPORARY TEXT_P THEN - TIES TIME TIMESTAMP TO TRAILING TRANSACTION TRANSFORM + TIES TIME TIMEOUT TIMESTAMP TO TRAILING TRANSACTION TRANSFORM TREAT TRIGGER TRIM TRUE_P TRUNCATE TRUSTED TYPE_P TYPES_P @@ -711,7 +713,8 @@ static Node *makeRecursiveViewSelect(char *relname, List *aliases, Node *query); VACUUM VALID VALIDATE VALIDATOR VALUE_P VALUES VARCHAR VARIADIC VARYING VERBOSE VERSION_P VIEW VIEWS VOLATILE - WHEN WHERE WHITESPACE_P WINDOW WITH WITHIN WITHOUT WORK WRAPPER WRITE + WAIT WHEN WHERE WHITESPACE_P WINDOW + WITH WITHIN WITHOUT WORK WRAPPER WRITE XML_P XMLATTRIBUTES XMLCONCAT XMLELEMENT XMLEXISTS XMLFOREST XMLNAMESPACES XMLPARSE XMLPI XMLROOT XMLSERIALIZE XMLTABLE @@ -9955,18 +9958,20 @@ TransactionStmt: n->chain = $3; $$ = (Node *)n; } - | BEGIN_P opt_transaction transaction_mode_list_or_empty + | BEGIN_P opt_transaction transaction_mode_list_or_empty wait_for { TransactionStmt *n = makeNode(TransactionStmt); n->kind = TRANS_STMT_BEGIN; n->options = $3; + n->wait = $4; $$ = (Node *)n; } - | START TRANSACTION transaction_mode_list_or_empty + | START TRANSACTION transaction_mode_list_or_empty wait_for { TransactionStmt *n = makeNode(TransactionStmt); n->kind = TRANS_STMT_START; n->options = $3; + n->wait = $4; $$ = (Node *)n; } | COMMIT opt_transaction opt_transaction_chain @@ -14240,6 +14245,25 @@ xml_passing_mech: | BY VALUE_P ; +/* + * WAIT FOR clause of BEGIN and START TRANSACTION statements + */ +wait_for: + WAIT FOR LSN Sconst wait_time + { + WaitClause *n = makeNode(WaitClause); + n->lsn = $4; + n->timeout = $5; + $$ = (Node *)n; + } + | /* EMPTY */ { $$ = NULL; } + ; + +wait_time: + TIMEOUT Iconst { $$ = $2; } + | /* EMPTY */ { $$ = 0; } + ; + /* * Aggregate decoration clauses @@ -15391,6 +15415,7 @@ unreserved_keyword: | LOCK_P | LOCKED | LOGGED + | LSN | MAPPING | MATCH | MATERIALIZED @@ -15518,6 +15543,7 @@ unreserved_keyword: | TEMPORARY | TEXT_P | TIES + | TIMEOUT | TRANSACTION | TRANSFORM | TRIGGER @@ -15544,6 +15570,7 @@ unreserved_keyword: | VIEW | VIEWS | VOLATILE + | WAIT | WHITESPACE_P | WITHIN | WITHOUT |