-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
MDEV-27862 Galera should replicate nextval()-related changes in seque…
…nces with INCREMENT <> 0, at least NOCACHE ones with engine=InnoDB Sequence storage engine is not transactionl so cache will be written in stmt_cache that is not replicated in cluster. To fix this replicate what is available in both trans_cache and stmt_cache. Sequences will only work when NOCACHE keyword is used when sequnce is created. If WSREP is enabled and we don't have this keyword report error indicting that sequence will not work correctly in cluster. When binlog is enabled statement cache will be cleared in transaction before COMMIT so cache generated from sequence will not be replicated. We need to keep cache until replication. Tests are re-recorded because of replication changes that were introducted with this PR. Reviewed-by: Jan Lindström <jan.lindstrom@mariadb.com>
- Loading branch information
mkaruza
authored and
Jan Lindström
committed
May 30, 2022
1 parent
c8fabbe
commit ebbd5ef
Showing
13 changed files
with
197 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
connection node_2; | ||
connection node_1; | ||
CREATE SEQUENCE seq_nocache ENGINE=InnoDB; | ||
DROP SEQUENCE seq_nocache; | ||
CALL mtr.add_suppression("SEQUENCES declared without `NOCACHE` will not behave correctly in galera cluster."); | ||
connection node_2; | ||
CALL mtr.add_suppression("SEQUENCES declared without `NOCACHE` will not behave correctly in galera cluster."); | ||
connection node_1; | ||
CREATE SEQUENCE seq NOCACHE ENGINE=InnoDB; | ||
SELECT NEXTVAL(seq) = 1; | ||
NEXTVAL(seq) = 1 | ||
1 | ||
connection node_2; | ||
SELECT NEXTVAL(seq) = 2; | ||
NEXTVAL(seq) = 2 | ||
1 | ||
connection node_1; | ||
SELECT NEXTVAL(seq) = 3; | ||
NEXTVAL(seq) = 3 | ||
1 | ||
SELECT SETVAL(seq, 100); | ||
SETVAL(seq, 100) | ||
100 | ||
connection node_2; | ||
SELECT NEXTVAL(seq) = 101; | ||
NEXTVAL(seq) = 101 | ||
1 | ||
connection node_1; | ||
SELECT NEXTVAL(seq) = 102; | ||
NEXTVAL(seq) = 102 | ||
1 | ||
DROP SEQUENCE seq; | ||
CREATE TABLE t1(f1 INT); | ||
CREATE SEQUENCE seq_transaction NOCACHE ENGINE=InnoDB; | ||
START TRANSACTION; | ||
INSERT INTO t1 VALUES (0); | ||
SELECT NEXTVAL(seq_transaction); | ||
NEXTVAL(seq_transaction) | ||
1 | ||
INSERT INTO t1 VALUES (NEXTVAL(seq_transaction)); | ||
COMMIT; | ||
connection node_2; | ||
SELECT COUNT(*) = 2 FROM t1; | ||
COUNT(*) = 2 | ||
1 | ||
SELECT NEXTVAL(seq_transaction) = 3; | ||
NEXTVAL(seq_transaction) = 3 | ||
1 | ||
connection node_1; | ||
SELECT NEXTVAL(seq_transaction) = 4; | ||
NEXTVAL(seq_transaction) = 4 | ||
1 | ||
DROP SEQUENCE seq_transaction; | ||
DROP TABLE t1; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
[binlogoff] | ||
|
||
[binlogon] | ||
log-bin |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
--source include/galera_cluster.inc | ||
--source include/have_innodb.inc | ||
|
||
# Report WARNING when SEQUENCE is created without `NOCACHE` | ||
|
||
CREATE SEQUENCE seq_nocache ENGINE=InnoDB; | ||
DROP SEQUENCE seq_nocache; | ||
|
||
CALL mtr.add_suppression("SEQUENCES declared without `NOCACHE` will not behave correctly in galera cluster."); | ||
|
||
--connection node_2 | ||
|
||
CALL mtr.add_suppression("SEQUENCES declared without `NOCACHE` will not behave correctly in galera cluster."); | ||
|
||
# NEXTVAL | ||
|
||
--connection node_1 | ||
|
||
CREATE SEQUENCE seq NOCACHE ENGINE=InnoDB; | ||
|
||
SELECT NEXTVAL(seq) = 1; | ||
|
||
--connection node_2 | ||
|
||
SELECT NEXTVAL(seq) = 2; | ||
|
||
--connection node_1 | ||
|
||
SELECT NEXTVAL(seq) = 3; | ||
|
||
|
||
# SETVAL | ||
|
||
SELECT SETVAL(seq, 100); | ||
|
||
--connection node_2 | ||
|
||
SELECT NEXTVAL(seq) = 101; | ||
|
||
--connection node_1 | ||
|
||
SELECT NEXTVAL(seq) = 102; | ||
|
||
DROP SEQUENCE seq; | ||
|
||
# TRANSACTIONS | ||
|
||
CREATE TABLE t1(f1 INT); | ||
CREATE SEQUENCE seq_transaction NOCACHE ENGINE=InnoDB; | ||
|
||
START TRANSACTION; | ||
INSERT INTO t1 VALUES (0); | ||
SELECT NEXTVAL(seq_transaction); | ||
INSERT INTO t1 VALUES (NEXTVAL(seq_transaction)); | ||
COMMIT; | ||
|
||
--connection node_2 | ||
|
||
SELECT COUNT(*) = 2 FROM t1; | ||
SELECT NEXTVAL(seq_transaction) = 3; | ||
|
||
--connection node_1 | ||
SELECT NEXTVAL(seq_transaction) = 4; | ||
|
||
DROP SEQUENCE seq_transaction; | ||
DROP TABLE t1; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters