1. Query OK, 0 rows affected (0.00 sec)
  2. mysql> insert into t values (1),(10),(100);
  3. Query OK, 3 rows affected (0.00 sec)
  4. Records: 3 Duplicates: 0 Warnings: 0
  5. mysql> select * from information_schema.tokudb_locks\G
  6. *************************** 1. row ***************************
  7. locks_trx_id: 238
  8. locks_mysql_thread_id: 3
  9. locks_dname: ./test/t-main
  10. locks_key_left: 0001000000
  11. locks_key_right: 0001000000
  12. locks_table_schema: test
  13. locks_table_name: t
  14. locks_table_dictionary_name: main
  15. *************************** 2. row ***************************
  16. locks_trx_id: 238
  17. locks_mysql_thread_id: 3
  18. locks_dname: ./test/t-main
  19. locks_key_left: 000a000000
  20. locks_table_schema: test
  21. locks_table_name: t
  22. *************************** 3. row ***************************
  23. locks_trx_id: 238
  24. locks_mysql_thread_id: 3
  25. locks_dname: ./test/t-main
  26. locks_key_left: 0064000000
  27. locks_key_right: 0064000000
  28. locks_table_schema: test
  29. locks_table_name: t
  30. locks_table_dictionary_name: main
  31. 3 rows in set (0.00 sec)

从tokudb_locks表可以查询到,生成了3条row-lock(locks_key_left和locks_key_right相等)。
为了存储和显示方便,locks_key_left/locks_key_right取key的hash值。

client1执行如下操作:

  1. mysql1> set autocommit=off;
  2. Query OK, 0 rows affected (0.00 sec)
  3. mysql1> insert into t values (1),(10),(100);
  4. Query OK, 3 rows affected (0.00 sec)
  5. Records: 3 Duplicates: 0 Warnings: 0
  6. mysql1> select * from information_schema.tokudb_locks\G
  7. *************************** 1. row ***************************
  8. locks_trx_id: 283
  9. locks_mysql_thread_id: 14
  10. locks_dname: ./test/t-main
  11. locks_key_left: 0001000000
  12. locks_table_name: t
  13. locks_table_dictionary_name: main
  14. *************************** 2. row ***************************
  15. locks_trx_id: 283
  16. locks_mysql_thread_id: 14
  17. locks_dname: ./test/t-main
  18. locks_key_left: 000a000000
  19. locks_key_right: 000a000000
  20. locks_table_schema: test
  21. locks_table_name: t
  22. locks_table_dictionary_name: main
  23. *************************** 3. row ***************************
  24. locks_trx_id: 283
  25. locks_mysql_thread_id: 14
  26. locks_dname: ./test/t-main
  27. locks_key_left: 0064000000
  28. locks_key_right: 0064000000
  29. locks_table_schema: test
  30. locks_table_name: t
  31. locks_table_dictionary_name: main
  32. 3 rows in set (0.00 sec)

锁等待超时了,通过参数tokudb_last_lock_timeout得知,hash为0064000000的row-lock已经被txnid为283(client1)抢占。

  1. tokudb_lock_timeout_debug = 0: No lock timeouts or lock deadlocks are reported.
  2. tokudb_lock_timeout_debug = 1: A JSON document that describes the lock conflict is stored in the tokudb_last_lock_timeout session variable
  3. tokudb_lock_timeout_debug = 3: A JSON document that describes the lock conflict is stored in the tokudb_last_lock_timeout session variable and is printed to the MySQL error log.