type_mode基础上 加上 LOCK_WAIT 表示等待状态

  1. /*********************************************************************//**
  2. Enqueues a waiting request for a lock which cannot be granted immediately.
  3. Checks for deadlocks.
  4. @return DB_LOCK_WAIT, DB_DEADLOCK, or DB_QUE_THR_SUSPENDED, or
  5. DB_SUCCESS_LOCKED_REC; DB_SUCCESS_LOCKED_REC means that
  6. there was a deadlock, but another transaction was chosen as a victim,
  7. and we got the lock immediately: no need to wait then */
  8. static
  9. enum db_err
  10. lock_rec_enqueue_waiting(
  11. /*=====================*/
  12. ulint type_mode,/*!< in: lock mode this
  13. transaction is requesting:
  14. LOCK_S or LOCK_X, possibly
  15. ORed with LOCK_GAP or
  16. LOCK_REC_NOT_GAP, ORed with
  17. LOCK_INSERT_INTENTION if this
  18. waiting lock request is set
  19. when performing an insert of
  20. an index record */
  21. const buf_block_t* block, /*!< in: buffer block containing
  22. the record */
  23. ulint heap_no,/*!< in: heap number of the record */
  24. lock_t* lock, /*!< in: lock object; NULL if a new
  25. one should be created. */
  26. dict_index_t* index, /*!< in: index of record */
  27. que_thr_t* thr) /*!< in: query thread */
  28. {
  29. trx_t* trx;
  30.  
  31. ut_ad(mutex_own(&kernel_mutex));
  32.  
  33. /* Test if there already is some other reason to suspend thread:
  34. we do not enqueue a lock request if the query thread should be
  35. stopped anyway */
  36.  
  37. if (UNIV_UNLIKELY(que_thr_stop(thr))) {
  38.  
  39. ut_error;
  40.  
  41. return(DB_QUE_THR_SUSPENDED);
  42. }
  43.  
  44. trx = thr_get_trx(thr);
  45.  
  46. switch (trx_get_dict_operation(trx)) {
  47. case TRX_DICT_OP_NONE:
  48. break;
  49. case TRX_DICT_OP_TABLE:
  50. case TRX_DICT_OP_INDEX:
  51. ut_print_timestamp(stderr);
  52. fputs(" InnoDB: Error: a record lock wait happens"
  53. " in a dictionary operation!\n"
  54. "InnoDB: ", stderr);
  55. dict_index_name_print(stderr, trx, index);
  56. fputs(".\n"
  57. "InnoDB: Submit a detailed bug report"
  58. " to http://bugs.mysql.com\n",
  59. stderr);
  60. ut_ad();
  61. }
  62.  
  63. if (lock == NULL) {
  64. /* Enqueue the lock request that will wait to be granted */
  65. lock = lock_rec_create(type_mode | LOCK_WAIT, block, heap_no, index, trx);
  66. } else {
  67. ut_ad(lock->type_mode & LOCK_WAIT);
  68. ut_ad(lock->type_mode & LOCK_CONV_BY_OTHER);
  69.  
  70. lock->type_mode &= ~LOCK_CONV_BY_OTHER;
  71. lock_set_lock_and_trx_wait(lock, trx);
  72. }
  73.  
  74. /* Check if a deadlock occurs: if yes, remove the lock request and
  75. return an error code */
  76.  
  77. if (UNIV_UNLIKELY(lock_deadlock_occurs(lock, trx))) {
  78.  
  79. lock_reset_lock_and_trx_wait(lock);
  80. lock_rec_reset_nth_bit(lock, heap_no);
  81.  
  82. return(DB_DEADLOCK);
  83. }
  84.  
  85. /* If there was a deadlock but we chose another transaction as a
  86. victim, it is possible that we already have the lock now granted! */
  87.  
  88. if (trx->wait_lock == NULL) {
  89.  
  90. return(DB_SUCCESS_LOCKED_REC);
  91. }
  92.  
  93. trx->que_state = TRX_QUE_LOCK_WAIT;
  94. trx->was_chosen_as_deadlock_victim = FALSE;
  95. trx->wait_started = time(NULL);
  96.  
  97. ut_a(que_thr_stop(thr));
  98.  
  99. #ifdef UNIV_DEBUG
  100. if (lock_print_waits) {
  101. fprintf(stderr, "Lock wait for trx " TRX_ID_FMT " in index ",
  102. (ullint) trx->id);
  103. ut_print_name(stderr, trx, FALSE, index->name);
  104. }
  105. #endif /* UNIV_DEBUG */
  106.  
  107. return(DB_LOCK_WAIT);
  108. }

函数lock_rec_enqueue_waiting的更多相关文章

  1. 【MySQL】MySQL锁和隔离级别浅析二 之 INSERT

    最近在整理线上性能时,发现一台线上DB出现两个insert产生的死锁问题 ------------------------ LATEST DETECTED DEADLOCK ------------- ...

  2. 谈谈MySQL死锁之二 死锁检测和处理源码分析

    这一篇主要是通过一个实验来进行描述,过程是比较枯燥的. 实验准备 create table test_lock(id int auto_increment primary key ,stock int ...

  3. Python 小而美的函数

    python提供了一些有趣且实用的函数,如any all zip,这些函数能够大幅简化我们得代码,可以更优雅的处理可迭代的对象,同时使用的时候也得注意一些情况   any any(iterable) ...

  4. 探究javascript对象和数组的异同,及函数变量缓存技巧

    javascript中最经典也最受非议的一句话就是:javascript中一切皆是对象.这篇重点要提到的,就是任何jser都不陌生的Object和Array. 有段时间曾经很诧异,到底两种数据类型用来 ...

  5. JavaScript权威指南 - 函数

    函数本身就是一段JavaScript代码,定义一次但可能被调用任意次.如果函数挂载在一个对象上,作为对象的一个属性,通常这种函数被称作对象的方法.用于初始化一个新创建的对象的函数被称作构造函数. 相对 ...

  6. C++对C的函数拓展

    一,内联函数 1.内联函数的概念 C++中的const常量可以用来代替宏常数的定义,例如:用const int a = 10来替换# define a 10.那么C++中是否有什么解决方案来替代宏代码 ...

  7. 菜鸟Python学习笔记第一天:关于一些函数库的使用

    2017年1月3日 星期二 大一学习一门新的计算机语言真的很难,有时候连函数拼写出错查错都能查半天,没办法,谁让我英语太渣. 关于计算机语言的学习我想还是从C语言学习开始为好,Python有很多语言的 ...

  8. javascript中的this与函数讲解

    前言 javascript中没有块级作用域(es6以前),javascript中作用域分为函数作用域和全局作用域.并且,大家可以认为全局作用域其实就是Window函数的函数作用域,我们编写的js代码, ...

  9. 复杂的 Hash 函数组合有意义吗?

    很久以前看到一篇文章,讲某个大网站储存用户口令时,会经过十分复杂的处理.怎么个复杂记不得了,大概就是先 Hash,结果加上一些特殊字符再 Hash,结果再加上些字符.再倒序.再怎么怎么的.再 Hash ...

随机推荐

  1. asp.net 分布式缓存

    之前Velocity已被 集成到App Fabric(包含有WCF监控==)中.   网络Velocity使用大多是针对老版本:  老版本的下载地址:  http://www.microsoft.co ...

  2. AVRStudio 的编译优化级别

    -00 无优化. -01 减少代码尺寸和执行时间,不进行需要大量编译时间的优化. -02 几乎执行所有优化,而不考虑代码尺寸和执行时间. -03 执行 -02 所有的优化,以及内联函数,重命名寄存器的 ...

  3. ios 图片转视频

    转自:http://blog.iosxcode4.com/archives/160 用到的FrameWork有: MediaPlayer.framework,QuartzCore.framework, ...

  4. 一个奇怪的网络故障 默认网关为0.0.0.0(Windows)

    用IPCONFIG命令看到的情况是这样: Windows IP 配置 以太网适配器 本地连接 : 连接特定的 DNS 后缀 . . . . . . . : 本地链接 IPv6 地址. . . . . ...

  5. URL编码方法比较

    javascript中存在几种对URL字符串进行编码的方法:escape(),encodeURI(),以及encodeURIComponent().这几种编码所起的作用各不相同. escape() 方 ...

  6. FIN_WAIT1 能持续多久?你知道吗

    FIN_WAIT1 能持续多久?你知道吗 2016-01-12 运维帮 原文:http://blogread.cn/it/article/7215?f=wb&luicode=10000359 ...

  7. codeforces 425A Sereja and Swaps(模拟,vector,枚举区间)

    题目 这要学习的是如何枚举区间,vector的基本使用(存入,取出,排序等),这题的思路来自: http://www.tuicool.com/articles/fAveE3 //vector 可以用s ...

  8. Wamp Mysql错误消息 语言设置

    Wamp Mysql错误消息 语言设置 http://my.oschina.net/wandershi/blog/264347 打开my.ini   找到 [wampmysqld] port = 33 ...

  9. POJ 2014

    #include <iostream> using namespace std; int main() { //freopen("acm.acm","r&qu ...

  10. iOS多线程的初步研究(六)-- NSOperation

    iOS平台提供更高级的并发(异步)调用接口,让你可以集中精力去设计需完成的任务代码,避免去写与程序逻辑无关的线程生成.运行等管理代码.当然实质上是这些接口隐含生成线程和管理线程的运行,从而更加简洁地实 ...