tidb icon indicating copy to clipboard operation
tidb copied to clipboard

the rolled-back/discarded transaction gets a "Query OK" msg in Snapshot Isolation level

Open tshqin opened this issue 9 years ago • 5 comments

Please answer these questions before submitting your issue. Thanks!

  1. What did you do? If possible, provide a recipe for reproducing the error.

SESSION 1

MySQL [gin]> set autocommit=0;
MySQL [gin]> select * from tab1;
+---+------+
| a | b    |
+---+------+
| 1 | ok   |
| 2 | ok   |
+---+------+
2 rows in set (0.00 sec)

SESSION 2

MySQL [gin]> set autocommit=0;
MySQL [gin]> select * from tab1;
+---+------+
| a | b    |
+---+------+
| 1 | ok   |
| 2 | ok   |
+---+------+
2 rows in set (0.00 sec)

SESSION 1

MySQL [gin]> update tab1 set b = 'not ok'  where a = 1;
Query OK, 1 row affected (0.01 sec)

MySQL [gin]> update tab1 set b = 'not ok'  where a = 2;
Query OK, 1 row affected (0.01 sec)

MySQL [gin]> select * from tab1;
+---+--------+
| a | b      |
+---+--------+
| 1 | not ok |
| 2 | not ok |
+---+--------+
2 rows in set (0.00 sec)

MySQL [gin]> commit;
Query OK, 0 rows affected (0.05 sec)

MySQL [gin]> select * from tab1;
+---+--------+
| a | b      |
+---+--------+
| 1 | not ok |
| 2 | not ok |
+---+--------+
2 rows in set (0.01 sec)

SESSION 2

MySQL [gin]> delete from tab1 where b='ok';   <------correction
Query OK, 2 rows affected (0.01 sec)

MySQL [gin]> select * from tab1;
Empty set (0.00 sec)

MySQL [gin]> commit;
Query OK, 0 rows affected (0.00 sec)      <-------- here SESSION 2's first transaction was discarded, but user got an OK msg.

MySQL [gin]> select * from tab1;
+---+--------+
| a | b      |
+---+--------+
| 1 | not ok |
| 2 | not ok |
+---+--------+
2 rows in set (0.01 sec)

an error msg is needed.

  1. What version of TiDB are you using (tidb-server -V)? Git Commit Hash: 365e4ab Git Commit Branch: master UTC Build Time: 2017-08-16 01:24:27

tshqin avatar Aug 21 '17 17:08 tshqin

create table tab1 (a int, b varchar(30), primary key (a));
insert into tab1 values (1, 'ok'), (2, 'ok');

tshqin avatar Aug 21 '17 17:08 tshqin

@tshqin I do not get your point. What's mean by "here SESSION 2's first transaction was discarded". @disksing PTAL

shenli avatar Aug 22 '17 15:08 shenli

I opened 2 sessions, and disabled auto commit of both sessions, above operations are in time order, as the autocommit is disabled, so session2's first transaction contains: select * from tab1; delete from tab1; select * from tab1; session1 has committed its update operation the earliest, session2 has committed later so its transaction was rolled-back/discarded by TiDB‘s optimistic locking.

tshqin avatar Aug 22 '17 16:08 tshqin

Hi @tshqin , I'm not able to reproduce the issue. Do you run tidb with tikv-server and pd-server? If so, please also provide the versions of them.

disksing avatar Aug 23 '17 02:08 disksing

my fault, in the last step, there's a correction, pls use "delete from tab1 where b='ok';" instead, you'll see.

tshqin avatar Aug 23 '17 04:08 tshqin