mirror of
https://github.com/MariaDB/server.git
synced 2025-08-08 11:22:35 +03:00
Modified ndbcluster_print_error to stack allocate table and handler, NOT for review, will make patch instead
This commit is contained in:
228
mysql-test/r/ndb_transaction.result
Normal file
228
mysql-test/r/ndb_transaction.result
Normal file
@@ -0,0 +1,228 @@
|
||||
DROP TABLE IF EXISTS t1,t2,t3,t4,t5,t6,t7;
|
||||
CREATE TABLE t1 (
|
||||
pk1 INT NOT NULL PRIMARY KEY,
|
||||
attr1 INT NOT NULL
|
||||
) ENGINE=ndbcluster;
|
||||
begin;
|
||||
insert into t1 values(1,1);
|
||||
insert into t1 values(2,2);
|
||||
select count(*) from t1;
|
||||
count(*)
|
||||
2
|
||||
select * from t1 where pk1 = 1;
|
||||
pk1 attr1
|
||||
1 1
|
||||
select t1.attr1 from t1, t1 as t1x where t1.pk1 = t1x.pk1 + 1;
|
||||
attr1
|
||||
2
|
||||
rollback;
|
||||
select count(*) from t1;
|
||||
count(*)
|
||||
0
|
||||
select * from t1 where pk1 = 1;
|
||||
pk1 attr1
|
||||
select t1.attr1 from t1, t1 as t1x where t1.pk1 = t1x.pk1 + 1;
|
||||
attr1
|
||||
begin;
|
||||
insert into t1 values(1,1);
|
||||
insert into t1 values(2,2);
|
||||
commit;
|
||||
select count(*) from t1;
|
||||
count(*)
|
||||
2
|
||||
select * from t1 where pk1 = 1;
|
||||
pk1 attr1
|
||||
1 1
|
||||
select t1.attr1 from t1, t1 as t1x where t1.pk1 = t1x.pk1 + 1;
|
||||
attr1
|
||||
2
|
||||
begin;
|
||||
update t1 set attr1 = attr1 * 2;
|
||||
select count(*) from t1;
|
||||
count(*)
|
||||
2
|
||||
select * from t1 where pk1 = 1;
|
||||
pk1 attr1
|
||||
1 2
|
||||
select * from t1, t1 as t1x where t1x.attr1 = t1.attr1 - 2;
|
||||
pk1 attr1 pk1 attr1
|
||||
2 4 1 2
|
||||
rollback;
|
||||
select count(*) from t1;
|
||||
count(*)
|
||||
2
|
||||
select * from t1 where pk1 = 1;
|
||||
pk1 attr1
|
||||
1 1
|
||||
select * from t1, t1 as t1x where t1x.attr1 = t1.attr1 - 2;
|
||||
pk1 attr1 pk1 attr1
|
||||
begin;
|
||||
update t1 set attr1 = attr1 * 2;
|
||||
commit;
|
||||
select count(*) from t1;
|
||||
count(*)
|
||||
2
|
||||
select * from t1 where pk1 = 1;
|
||||
pk1 attr1
|
||||
1 2
|
||||
select * from t1, t1 as t1x where t1x.attr1 = t1.attr1 - 2;
|
||||
pk1 attr1 pk1 attr1
|
||||
2 4 1 2
|
||||
begin;
|
||||
delete from t1 where attr1 = 2;
|
||||
select count(*) from t1;
|
||||
count(*)
|
||||
1
|
||||
select * from t1 where pk1 = 1;
|
||||
pk1 attr1
|
||||
select * from t1, t1 as t1x where t1x.attr1 = t1.attr1 - 2;
|
||||
pk1 attr1 pk1 attr1
|
||||
rollback;
|
||||
select count(*) from t1;
|
||||
count(*)
|
||||
2
|
||||
select * from t1 where pk1 = 1;
|
||||
pk1 attr1
|
||||
1 2
|
||||
select * from t1, t1 as t1x where t1x.attr1 = t1.attr1 - 2;
|
||||
pk1 attr1 pk1 attr1
|
||||
2 4 1 2
|
||||
begin;
|
||||
delete from t1 where attr1 = 2;
|
||||
commit;
|
||||
select count(*) from t1;
|
||||
count(*)
|
||||
1
|
||||
select * from t1 where pk1 = 1;
|
||||
pk1 attr1
|
||||
select * from t1, t1 as t1x where t1x.attr1 = t1.attr1 - 2;
|
||||
pk1 attr1 pk1 attr1
|
||||
DROP TABLE t1;
|
||||
CREATE TABLE t1 (id INT, id2 int) engine=ndbcluster;
|
||||
begin;
|
||||
insert into t1 values(1,1);
|
||||
insert into t1 values(2,2);
|
||||
select sum(id) from t1;
|
||||
sum(id)
|
||||
3
|
||||
select * from t1 where id = 1;
|
||||
id id2
|
||||
1 1
|
||||
select t1.id from t1, t1 as t1x where t1.id2 = t1x.id2 + 1;
|
||||
id
|
||||
2
|
||||
rollback;
|
||||
select sum(id) from t1;
|
||||
sum(id)
|
||||
NULL
|
||||
select * from t1 where id = 1;
|
||||
id id2
|
||||
select t1.id from t1, t1 as t1x where t1.id2 = t1x.id2 + 1;
|
||||
id
|
||||
begin;
|
||||
insert into t1 values(1,1);
|
||||
insert into t1 values(2,2);
|
||||
commit;
|
||||
select sum(id) from t1;
|
||||
sum(id)
|
||||
3
|
||||
select * from t1 where id = 1;
|
||||
id id2
|
||||
1 1
|
||||
select t1.id from t1, t1 as t1x where t1.id2 = t1x.id2 + 1;
|
||||
id
|
||||
2
|
||||
begin;
|
||||
update t1 set id = id * 2;
|
||||
select sum(id) from t1;
|
||||
sum(id)
|
||||
6
|
||||
select * from t1 where id = 2;
|
||||
id id2
|
||||
2 1
|
||||
select * from t1, t1 as t1x where t1x.id = t1.id - 2;
|
||||
id id2 id id2
|
||||
4 2 2 1
|
||||
rollback;
|
||||
select sum(id) from t1;
|
||||
sum(id)
|
||||
3
|
||||
select * from t1 where id = 2;
|
||||
id id2
|
||||
2 2
|
||||
select * from t1, t1 as t1x where t1x.id = t1.id - 2;
|
||||
id id2 id id2
|
||||
begin;
|
||||
update t1 set id = id * 2;
|
||||
commit;
|
||||
select sum(id) from t1;
|
||||
sum(id)
|
||||
6
|
||||
select * from t1 where id = 2;
|
||||
id id2
|
||||
2 1
|
||||
select * from t1, t1 as t1x where t1x.id = t1.id - 2;
|
||||
id id2 id id2
|
||||
4 2 2 1
|
||||
DROP TABLE t1;
|
||||
CREATE TABLE t2 (
|
||||
a bigint unsigned NOT NULL PRIMARY KEY,
|
||||
b int unsigned not null,
|
||||
c int unsigned
|
||||
) engine=ndbcluster;
|
||||
CREATE TABLE t3 (
|
||||
a bigint unsigned NOT NULL,
|
||||
b bigint unsigned not null,
|
||||
c bigint unsigned,
|
||||
PRIMARY KEY(a)
|
||||
) engine=ndbcluster;
|
||||
CREATE TABLE t4 (
|
||||
a bigint unsigned NOT NULL,
|
||||
b bigint unsigned not null,
|
||||
c bigint unsigned NOT NULL,
|
||||
d int unsigned,
|
||||
PRIMARY KEY(a, b, c)
|
||||
) engine=ndbcluster;
|
||||
select count(*) from t2;
|
||||
count(*)
|
||||
0
|
||||
select count(*) from t3;
|
||||
count(*)
|
||||
0
|
||||
select count(*) from t4;
|
||||
count(*)
|
||||
0
|
||||
ERROR HY000: Lock wait timeout exceeded; try restarting transaction
|
||||
select count(*) from t2;
|
||||
count(*)
|
||||
0
|
||||
select count(*) from t3;
|
||||
count(*)
|
||||
0
|
||||
select count(*) from t4;
|
||||
count(*)
|
||||
0
|
||||
ERROR HY000: Lock wait timeout exceeded; try restarting transaction
|
||||
select count(*) from t2;
|
||||
count(*)
|
||||
0
|
||||
select count(*) from t3;
|
||||
count(*)
|
||||
0
|
||||
select count(*) from t4;
|
||||
count(*)
|
||||
0
|
||||
select count(*) from t2;
|
||||
count(*)
|
||||
100
|
||||
select count(*) from t3;
|
||||
count(*)
|
||||
100
|
||||
select count(*) from t4;
|
||||
count(*)
|
||||
100
|
||||
begin;
|
||||
begin;
|
||||
drop table t2;
|
||||
drop table t3;
|
||||
drop table t4;
|
300
mysql-test/t/ndb_transaction.test
Normal file
300
mysql-test/t/ndb_transaction.test
Normal file
@@ -0,0 +1,300 @@
|
||||
-- source include/have_ndb.inc
|
||||
|
||||
--disable_warnings
|
||||
DROP TABLE IF EXISTS t1,t2,t3,t4,t5,t6,t7;
|
||||
--enable_warnings
|
||||
|
||||
#
|
||||
# Transactionc test to show that the NDB
|
||||
# table handler is working properly with
|
||||
# transactions
|
||||
#
|
||||
|
||||
#
|
||||
# Create a normal table with primary key
|
||||
#
|
||||
CREATE TABLE t1 (
|
||||
pk1 INT NOT NULL PRIMARY KEY,
|
||||
attr1 INT NOT NULL
|
||||
) ENGINE=ndbcluster;
|
||||
|
||||
# insert
|
||||
begin;
|
||||
insert into t1 values(1,1);
|
||||
insert into t1 values(2,2);
|
||||
select count(*) from t1;
|
||||
select * from t1 where pk1 = 1;
|
||||
select t1.attr1 from t1, t1 as t1x where t1.pk1 = t1x.pk1 + 1;
|
||||
rollback;
|
||||
|
||||
select count(*) from t1;
|
||||
select * from t1 where pk1 = 1;
|
||||
select t1.attr1 from t1, t1 as t1x where t1.pk1 = t1x.pk1 + 1;
|
||||
|
||||
begin;
|
||||
insert into t1 values(1,1);
|
||||
insert into t1 values(2,2);
|
||||
commit;
|
||||
|
||||
select count(*) from t1;
|
||||
select * from t1 where pk1 = 1;
|
||||
select t1.attr1 from t1, t1 as t1x where t1.pk1 = t1x.pk1 + 1;
|
||||
|
||||
# update
|
||||
begin;
|
||||
update t1 set attr1 = attr1 * 2;
|
||||
select count(*) from t1;
|
||||
select * from t1 where pk1 = 1;
|
||||
select * from t1, t1 as t1x where t1x.attr1 = t1.attr1 - 2;
|
||||
rollback;
|
||||
|
||||
select count(*) from t1;
|
||||
select * from t1 where pk1 = 1;
|
||||
select * from t1, t1 as t1x where t1x.attr1 = t1.attr1 - 2;
|
||||
|
||||
begin;
|
||||
update t1 set attr1 = attr1 * 2;
|
||||
commit;
|
||||
|
||||
select count(*) from t1;
|
||||
select * from t1 where pk1 = 1;
|
||||
select * from t1, t1 as t1x where t1x.attr1 = t1.attr1 - 2;
|
||||
|
||||
# delete
|
||||
begin;
|
||||
delete from t1 where attr1 = 2;
|
||||
select count(*) from t1;
|
||||
select * from t1 where pk1 = 1;
|
||||
select * from t1, t1 as t1x where t1x.attr1 = t1.attr1 - 2;
|
||||
rollback;
|
||||
|
||||
select count(*) from t1;
|
||||
select * from t1 where pk1 = 1;
|
||||
select * from t1, t1 as t1x where t1x.attr1 = t1.attr1 - 2;
|
||||
|
||||
begin;
|
||||
delete from t1 where attr1 = 2;
|
||||
commit;
|
||||
|
||||
select count(*) from t1;
|
||||
select * from t1 where pk1 = 1;
|
||||
select * from t1, t1 as t1x where t1x.attr1 = t1.attr1 - 2;
|
||||
|
||||
DROP TABLE t1;
|
||||
|
||||
#
|
||||
# Create table without primary key
|
||||
# a hidden primary key column is created by handler
|
||||
#
|
||||
CREATE TABLE t1 (id INT, id2 int) engine=ndbcluster;
|
||||
|
||||
# insert
|
||||
begin;
|
||||
insert into t1 values(1,1);
|
||||
insert into t1 values(2,2);
|
||||
select sum(id) from t1;
|
||||
select * from t1 where id = 1;
|
||||
select t1.id from t1, t1 as t1x where t1.id2 = t1x.id2 + 1;
|
||||
rollback;
|
||||
|
||||
select sum(id) from t1;
|
||||
select * from t1 where id = 1;
|
||||
select t1.id from t1, t1 as t1x where t1.id2 = t1x.id2 + 1;
|
||||
|
||||
begin;
|
||||
insert into t1 values(1,1);
|
||||
insert into t1 values(2,2);
|
||||
commit;
|
||||
|
||||
select sum(id) from t1;
|
||||
select * from t1 where id = 1;
|
||||
select t1.id from t1, t1 as t1x where t1.id2 = t1x.id2 + 1;
|
||||
|
||||
# update
|
||||
begin;
|
||||
update t1 set id = id * 2;
|
||||
select sum(id) from t1;
|
||||
select * from t1 where id = 2;
|
||||
select * from t1, t1 as t1x where t1x.id = t1.id - 2;
|
||||
rollback;
|
||||
|
||||
select sum(id) from t1;
|
||||
select * from t1 where id = 2;
|
||||
select * from t1, t1 as t1x where t1x.id = t1.id - 2;
|
||||
|
||||
begin;
|
||||
update t1 set id = id * 2;
|
||||
commit;
|
||||
|
||||
select sum(id) from t1;
|
||||
select * from t1 where id = 2;
|
||||
select * from t1, t1 as t1x where t1x.id = t1.id - 2;
|
||||
|
||||
# delete
|
||||
|
||||
DROP TABLE t1;
|
||||
|
||||
#
|
||||
# A more extensive test with a lot more records
|
||||
#
|
||||
|
||||
CREATE TABLE t2 (
|
||||
a bigint unsigned NOT NULL PRIMARY KEY,
|
||||
b int unsigned not null,
|
||||
c int unsigned
|
||||
) engine=ndbcluster;
|
||||
|
||||
CREATE TABLE t3 (
|
||||
a bigint unsigned NOT NULL,
|
||||
b bigint unsigned not null,
|
||||
c bigint unsigned,
|
||||
PRIMARY KEY(a)
|
||||
) engine=ndbcluster;
|
||||
|
||||
CREATE TABLE t4 (
|
||||
a bigint unsigned NOT NULL,
|
||||
b bigint unsigned not null,
|
||||
c bigint unsigned NOT NULL,
|
||||
d int unsigned,
|
||||
PRIMARY KEY(a, b, c)
|
||||
) engine=ndbcluster;
|
||||
|
||||
|
||||
#
|
||||
# insert records into tables and rollback
|
||||
#
|
||||
let $1=100;
|
||||
disable_query_log;
|
||||
begin;
|
||||
while ($1)
|
||||
{
|
||||
eval insert into t2 values($1, $1+9, 5);
|
||||
eval insert into t3 values($1, $1+9, 5);
|
||||
eval insert into t4 values($1, $1+9, 5, $1+26000);
|
||||
dec $1;
|
||||
}
|
||||
rollback;
|
||||
enable_query_log;
|
||||
|
||||
select count(*) from t2;
|
||||
select count(*) from t3;
|
||||
select count(*) from t4;
|
||||
|
||||
#
|
||||
# insert records into tables and commit after timeout;
|
||||
#
|
||||
let $1=100;
|
||||
disable_query_log;
|
||||
begin;
|
||||
while ($1)
|
||||
{
|
||||
eval insert into t2 values($1, $1+9, 5);
|
||||
eval insert into t3 values($1, $1+9, 5);
|
||||
eval insert into t4 values($1, $1+9, 5, $1+26000);
|
||||
dec $1;
|
||||
}
|
||||
sleep 15;
|
||||
-- error 1205
|
||||
commit;
|
||||
enable_query_log;
|
||||
|
||||
select count(*) from t2;
|
||||
select count(*) from t3;
|
||||
select count(*) from t4;
|
||||
|
||||
#
|
||||
# insert records into tables and timeout before last operation
|
||||
#
|
||||
let $1=100;
|
||||
disable_query_log;
|
||||
begin;
|
||||
while ($1)
|
||||
{
|
||||
eval insert into t2 values($1, $1+9, 5);
|
||||
eval insert into t3 values($1, $1+9, 5);
|
||||
eval insert into t4 values($1, $1+9, 5, $1+26000);
|
||||
dec $1;
|
||||
}
|
||||
sleep 15;
|
||||
-- error 1205
|
||||
insert into t2 values(10000, 10000, 36000);
|
||||
commit;
|
||||
enable_query_log;
|
||||
|
||||
select count(*) from t2;
|
||||
select count(*) from t3;
|
||||
select count(*) from t4;
|
||||
|
||||
#
|
||||
# insert records into tables and commit;
|
||||
#
|
||||
let $1=100;
|
||||
disable_query_log;
|
||||
begin;
|
||||
while ($1)
|
||||
{
|
||||
eval insert into t2 values($1, $1+9, 5);
|
||||
eval insert into t3 values($1, $1+9, 5);
|
||||
eval insert into t4 values($1, $1+9, 5, $1+26000);
|
||||
dec $1;
|
||||
}
|
||||
commit;
|
||||
enable_query_log;
|
||||
|
||||
select count(*) from t2;
|
||||
select count(*) from t3;
|
||||
select count(*) from t4;
|
||||
|
||||
#
|
||||
# delete every other record in the tables
|
||||
#
|
||||
let $1=100;
|
||||
disable_query_log;
|
||||
while ($1)
|
||||
{
|
||||
eval delete from t2 where a=$1;
|
||||
eval delete from t3 where a=$1;
|
||||
eval delete from t4 where a=$1 and b=$1+9 and c=5;
|
||||
dec $1;
|
||||
dec $1;
|
||||
}
|
||||
enable_query_log;
|
||||
|
||||
#
|
||||
# update records and rollback
|
||||
#
|
||||
begin;
|
||||
let $1=100;
|
||||
disable_query_log;
|
||||
while ($1)
|
||||
{
|
||||
eval update t2 set c=$1 where a=$1;
|
||||
eval update t3 set c=7 where a=$1 and b=$1+9 and c=5;
|
||||
eval update t4 set d=$1+21987 where a=$1 and b=$1+9 and c=5;
|
||||
dec $1;
|
||||
dec $1;
|
||||
}
|
||||
rollback;
|
||||
enable_query_log;
|
||||
|
||||
#
|
||||
# update records and commit
|
||||
#
|
||||
begin;
|
||||
let $1=100;
|
||||
disable_query_log;
|
||||
while ($1)
|
||||
{
|
||||
eval update t2 set c=$1 where a=$1;
|
||||
eval update t3 set c=7 where a=$1 and b=$1+9 and c=5;
|
||||
eval update t4 set d=$1+21987 where a=$1 and b=$1+9 and c=5;
|
||||
dec $1;
|
||||
dec $1;
|
||||
}
|
||||
rollback;
|
||||
enable_query_log;
|
||||
|
||||
drop table t2;
|
||||
drop table t3;
|
||||
drop table t4;
|
||||
|
@@ -63,11 +63,6 @@ typedef NdbDictionary::Dictionary NDBDICT;
|
||||
|
||||
bool ndbcluster_inited= false;
|
||||
|
||||
// Error handler for printing out ndbcluster error messages
|
||||
TABLE *g_tab_dummy;
|
||||
static ha_ndbcluster* g_ha_error= NULL;
|
||||
static bool g_error_handler = FALSE;
|
||||
|
||||
static Ndb* g_ndb= NULL;
|
||||
|
||||
// Handler synchronization
|
||||
@@ -2659,17 +2654,6 @@ ha_ndbcluster::ha_ndbcluster(TABLE *table_arg):
|
||||
m_unique_index_name[i]= NULL;
|
||||
}
|
||||
|
||||
// Create error handler needed for error msg handling in static
|
||||
// handler functions (ha_commit_trans and ha_rollback_trans)
|
||||
if (!g_error_handler)
|
||||
{
|
||||
DBUG_PRINT("info", ("Setting up error printing handler object"));
|
||||
g_tab_dummy = new TABLE();
|
||||
g_tab_dummy->table_name = NULL;
|
||||
g_error_handler = TRUE;
|
||||
g_ha_error= new ha_ndbcluster(g_tab_dummy);
|
||||
}
|
||||
|
||||
DBUG_VOID_RETURN;
|
||||
}
|
||||
|
||||
@@ -2944,15 +2928,7 @@ bool ndbcluster_init()
|
||||
bool ndbcluster_end()
|
||||
{
|
||||
DBUG_ENTER("ndbcluster_end");
|
||||
if (g_ha_error)
|
||||
{
|
||||
DBUG_PRINT("info", ("deallocating error printing handler object"));
|
||||
delete g_tab_dummy;
|
||||
g_tab_dummy= NULL;
|
||||
delete g_ha_error;
|
||||
g_ha_error= NULL;
|
||||
g_ha_error = FALSE;
|
||||
}
|
||||
|
||||
delete g_ndb;
|
||||
g_ndb= NULL;
|
||||
if (!ndbcluster_inited)
|
||||
@@ -2966,9 +2942,18 @@ bool ndbcluster_end()
|
||||
DBUG_RETURN(0);
|
||||
}
|
||||
|
||||
/*
|
||||
Static error print function called from
|
||||
static handler method ndbcluster_commit
|
||||
and ndbcluster_rollback
|
||||
*/
|
||||
void ndbcluster_print_error(int error)
|
||||
{
|
||||
g_ha_error->print_error(error, MYF(0));
|
||||
DBUG_ENTER("ndbcluster_print_error");
|
||||
TABLE tab;
|
||||
tab.table_name = NULL;
|
||||
ha_ndbcluster error_handler(&tab);
|
||||
error_handler.print_error(error, MYF(0));
|
||||
}
|
||||
|
||||
/*
|
||||
|
Reference in New Issue
Block a user