Skip to content

Commit

Permalink
Bug#32169848 THD_NDB TRANSACTION FUNCTIONALITY [percona#19]
Browse files Browse the repository at this point in the history
Add test showing that table stats are correct after failure.

Similar tests are already done in ndb_insert.test which is currently
disabled.

Change-Id: I2f6542bfcd1d130b8418e1290edf816a9e0c31bf
  • Loading branch information
blaudden committed May 19, 2021
1 parent 938ace7 commit 0768508
Show file tree
Hide file tree
Showing 2 changed files with 196 additions and 0 deletions.
103 changes: 103 additions & 0 deletions mysql-test/suite/ndbcluster/table_stats.result
@@ -0,0 +1,103 @@
# ###################################################################
# Show that local table stats are correctly reflecting number of
# records in table at failure to insert, both with and without trans
# - in particular this shows how the "uncomitted rows" value in Thd_ndb
# is handled
CREATE TABLE t1 (
a int PRIMARY KEY,
b varchar(255)
) ENGINE = NDB;
INSERT INTO t1 VALUES (1, "this is in the way");
SELECT COUNT(*) as "count should be 1" FROM t1;
count should be 1
1
INSERT INTO t1 VALUES (1, "duplicate key");
ERROR 23000: Duplicate entry '1' for key 't1.PRIMARY'
SELECT COUNT(*) as "count should still be 1" FROM t1;
count should still be 1
1
INSERT INTO t1 VALUES
(2, "val2"), (3, "val3"), (4, "val4"),
(1, "duplicate key, 3 uncommitted");
ERROR 23000: Duplicate entry '1' for key 't1.PRIMARY'
SELECT COUNT(*) as "count should still be 1" FROM t1;
count should still be 1
1
BEGIN;
INSERT INTO t1 VALUES (1, "duplicate key, inside transaction");
ERROR 23000: Duplicate entry '1' for key 't1.PRIMARY'
SELECT COUNT(*) as "count should still be 1" FROM t1;
count should still be 1
1
COMMIT;
SELECT COUNT(*) as "count should still be 1" FROM t1;
count should still be 1
1
BEGIN;
INSERT INTO t1 VALUES
(2, "val2"), (3, "val3"), (4, "val4");
SELECT COUNT(*) as "count should be 4" FROM t1;
count should be 4
4
INSERT INTO t1 VALUES (1, "duplicate key, inside transaction, 3 uncommitted");
ERROR 23000: Duplicate entry '1' for key 't1.PRIMARY'
SELECT COUNT(*) as "count should still be 1, whole trans aborted" FROM t1;
count should still be 1, whole trans aborted
1
COMMIT;
SELECT COUNT(*) as "count should still be 1" FROM t1;
count should still be 1
1
BEGIN;
INSERT INTO t1 VALUES (1, "duplicate key, inside transaction");
ERROR 23000: Duplicate entry '1' for key 't1.PRIMARY'
SELECT COUNT(*) as "count should still be 1" FROM t1;
count should still be 1
1
ROLLBACK;
SELECT COUNT(*) as "count should still be 1" FROM t1;
count should still be 1
1
BEGIN;
INSERT INTO t1 VALUES
(2, "val2"), (3, "val3"), (4, "val4");
SELECT COUNT(*) as "count should be 4" FROM t1;
count should be 4
4
INSERT INTO t1 VALUES (1, "duplicate key, inside transaction, 3 uncommitted");
ERROR 23000: Duplicate entry '1' for key 't1.PRIMARY'
SELECT COUNT(*) as "count should still be 1, whole trans aborted" FROM t1;
count should still be 1, whole trans aborted
1
ROLLBACK;
SELECT COUNT(*) as "count should still be 1" FROM t1;
count should still be 1
1
CREATE TABLE t2 (
a int PRIMARY KEY,
b varchar(255)
) ENGINE = NDB;
INSERT INTO t2 VALUES
(10, "val10"), (12, "val12"), (13, "val13"), (14, "val14"), (15, "val15");
BEGIN;
INSERT INTO t2 VALUES (1, "val1"), (2, "val2"), (3, "val3"), (4, "val4");
SELECT COUNT(*) as "count should be 9" FROM t2;
count should be 9
9
INSERT INTO t1 VALUES (1, "duplicate key, inside transaction");
ERROR 23000: Duplicate entry '1' for key 't1.PRIMARY'
SELECT COUNT(*) as "count should still be 1" FROM t1;
count should still be 1
1
SELECT COUNT(*) as "count should be 5, trans aborted" FROM t2;
count should be 5, trans aborted
5
COMMIT;
SELECT COUNT(*) as "count should still be 1" FROM t1;
count should still be 1
1
SELECT COUNT(*) as "count should be 5" FROM t2;
count should be 5
5
DROP TABLE t2;
DROP TABLE t1;
93 changes: 93 additions & 0 deletions mysql-test/suite/ndbcluster/table_stats.test
@@ -0,0 +1,93 @@
--source include/have_ndb.inc

--echo # ###################################################################
--echo # Show that local table stats are correctly reflecting number of
--echo # records in table at failure to insert, both with and without trans
--echo # - in particular this shows how the "uncomitted rows" value in Thd_ndb
--echo # is handled
CREATE TABLE t1 (
a int PRIMARY KEY,
b varchar(255)
) ENGINE = NDB;
INSERT INTO t1 VALUES (1, "this is in the way");
SELECT COUNT(*) as "count should be 1" FROM t1;

# Autocommit, one uncommitted row when failure occurs
--error ER_DUP_ENTRY
INSERT INTO t1 VALUES (1, "duplicate key");
SELECT COUNT(*) as "count should still be 1" FROM t1;

# Autocommit, three uncommitted rows when failure occurs
--error ER_DUP_ENTRY
INSERT INTO t1 VALUES
(2, "val2"), (3, "val3"), (4, "val4"),
(1, "duplicate key, 3 uncommitted");
SELECT COUNT(*) as "count should still be 1" FROM t1;

# Transaction, one uncommitted row when failure occurs
BEGIN;
--error ER_DUP_ENTRY
INSERT INTO t1 VALUES (1, "duplicate key, inside transaction");
SELECT COUNT(*) as "count should still be 1" FROM t1;
COMMIT;
SELECT COUNT(*) as "count should still be 1" FROM t1;

# Transaction, three uncommitted rows when failure occurs
BEGIN;
# Add three uncommitted to trans
INSERT INTO t1 VALUES
(2, "val2"), (3, "val3"), (4, "val4");
SELECT COUNT(*) as "count should be 4" FROM t1;

--error ER_DUP_ENTRY
INSERT INTO t1 VALUES (1, "duplicate key, inside transaction, 3 uncommitted");
SELECT COUNT(*) as "count should still be 1, whole trans aborted" FROM t1;
COMMIT;
SELECT COUNT(*) as "count should still be 1" FROM t1;

# Transaction, one uncommitted row when failure occurs, rollback
BEGIN;
--error ER_DUP_ENTRY
INSERT INTO t1 VALUES (1, "duplicate key, inside transaction");
SELECT COUNT(*) as "count should still be 1" FROM t1;
ROLLBACK;
SELECT COUNT(*) as "count should still be 1" FROM t1;

# Transaction, three uncommitted rows when failure occurs, rollback
BEGIN;
# Add three uncommitted to trans
INSERT INTO t1 VALUES
(2, "val2"), (3, "val3"), (4, "val4");
SELECT COUNT(*) as "count should be 4" FROM t1;

--error ER_DUP_ENTRY
INSERT INTO t1 VALUES (1, "duplicate key, inside transaction, 3 uncommitted");
SELECT COUNT(*) as "count should still be 1, whole trans aborted" FROM t1;
ROLLBACK;
SELECT COUNT(*) as "count should still be 1" FROM t1;


# Transaction, four uncommitted rows in other table when failure occurs
CREATE TABLE t2 (
a int PRIMARY KEY,
b varchar(255)
) ENGINE = NDB;
INSERT INTO t2 VALUES
(10, "val10"), (12, "val12"), (13, "val13"), (14, "val14"), (15, "val15");
BEGIN;
# Add four uncommitted to other table
INSERT INTO t2 VALUES (1, "val1"), (2, "val2"), (3, "val3"), (4, "val4");
SELECT COUNT(*) as "count should be 9" FROM t2;

--error ER_DUP_ENTRY
INSERT INTO t1 VALUES (1, "duplicate key, inside transaction");
SELECT COUNT(*) as "count should still be 1" FROM t1;

# Check count for other table
SELECT COUNT(*) as "count should be 5, trans aborted" FROM t2;
COMMIT;
SELECT COUNT(*) as "count should still be 1" FROM t1;
SELECT COUNT(*) as "count should be 5" FROM t2;
DROP TABLE t2;

DROP TABLE t1;

0 comments on commit 0768508

Please sign in to comment.