举个例子吧。自己实验了一下。
对MYSQL的innodb 和 ndb 引擎对事务的处理
对于NDB
mysql> begin;
Query OK, 0 rows affected (0.00 sec)
mysql> insert into foo values(1);
Query OK, 1 row affected (0.01 sec)
mysql> insert into foo values(1);
ERROR 1062 (23000): Duplicate entry '1' for key 'PRIMARY'
mysql> commit;
ERROR 1296 (HY000): Got error 4350 'Transaction already aborted' from NDBCLUSTER
mysql> show errors;
+-------+------+--------------------------------------------------------------+
| Level | Code | Message |
+-------+------+--------------------------------------------------------------+
| Error | 1296 | Got error 4350 'Transaction already aborted' from NDB |
| Error | 1296 | Got error 4350 'Transaction already aborted' from NDBCLUSTER |
| Error | 1180 | Got error 4350 during COMMIT |
+-------+------+--------------------------------------------------------------+
3 rows in set (0.00 sec)
mysql> select * from foo;
Empty set (0.00 sec)
对于INNODB
mysql> create table foo2 (i int not null primary key) engine innodb;
Query OK, 0 rows affected (0.00 sec)
mysql> begin;
Query OK, 0 rows affected (0.00 sec)
mysql> insert into foo2 values(1);
Query OK, 1 row affected (0.00 sec)
mysql> insert into foo2 values(1);
ERROR 1062 (23000): Duplicate entry '1' for key 'PRIMARY'
mysql> commit;
Query OK, 0 rows affected (0.00 sec)
mysql> select * from foo2;
+---+
| i |
+---+
| 1 |
+---+
1 row in set (0.00 sec)
NDB遇到错误就终止了,回滚到最初的状态。
而INNODB遇到错误还是继续执行已经成功事务。
其他的等待测试。。。
阅读(7774) | 评论(3) | 转发(0) |