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

/*********************************************************************//**
Enqueues a waiting request for a lock which cannot be granted immediately.
Checks for deadlocks.
@return DB_LOCK_WAIT, DB_DEADLOCK, or DB_QUE_THR_SUSPENDED, or
DB_SUCCESS_LOCKED_REC; DB_SUCCESS_LOCKED_REC means that
there was a deadlock, but another transaction was chosen as a victim,
and we got the lock immediately: no need to wait then */
static
enum db_err
lock_rec_enqueue_waiting(
/*=====================*/
    ulint            type_mode,/*!< in: lock mode this
                    transaction is requesting:
                    LOCK_S or LOCK_X, possibly
                    ORed with LOCK_GAP or
                    LOCK_REC_NOT_GAP, ORed with
                    LOCK_INSERT_INTENTION if this
                    waiting lock request is set
                    when performing an insert of
                    an index record */
    const buf_block_t*    block,    /*!< in: buffer block containing
                    the record */
    ulint            heap_no,/*!< in: heap number of the record */
    lock_t*            lock,    /*!< in: lock object; NULL if a new
                    one should be created. */
    dict_index_t*        index,    /*!< in: index of record */
    que_thr_t*        thr)    /*!< in: query thread */
{
    trx_t*    trx;

    ut_ad(mutex_own(&kernel_mutex));

    /* Test if there already is some other reason to suspend thread:
    we do not enqueue a lock request if the query thread should be
    stopped anyway */

    if (UNIV_UNLIKELY(que_thr_stop(thr))) {

        ut_error;

        return(DB_QUE_THR_SUSPENDED);
    }

    trx = thr_get_trx(thr);

    switch (trx_get_dict_operation(trx)) {
    case TRX_DICT_OP_NONE:
        break;
    case TRX_DICT_OP_TABLE:
    case TRX_DICT_OP_INDEX:
        ut_print_timestamp(stderr);
        fputs("  InnoDB: Error: a record lock wait happens"
              " in a dictionary operation!\n"
              "InnoDB: ", stderr);
        dict_index_name_print(stderr, trx, index);
        fputs(".\n"
              "InnoDB: Submit a detailed bug report"
              " to http://bugs.mysql.com\n",
              stderr);
        ut_ad();
    }

    if (lock == NULL) {
        /* Enqueue the lock request that will wait to be granted */
        lock = lock_rec_create(type_mode | LOCK_WAIT, block, heap_no, index, trx);
    } else {
        ut_ad(lock->type_mode & LOCK_WAIT);
        ut_ad(lock->type_mode & LOCK_CONV_BY_OTHER);

        lock->type_mode &= ~LOCK_CONV_BY_OTHER;
        lock_set_lock_and_trx_wait(lock, trx);
    }

    /* Check if a deadlock occurs: if yes, remove the lock request and
    return an error code */

    if (UNIV_UNLIKELY(lock_deadlock_occurs(lock, trx))) {

        lock_reset_lock_and_trx_wait(lock);
        lock_rec_reset_nth_bit(lock, heap_no);

        return(DB_DEADLOCK);
    }

    /* If there was a deadlock but we chose another transaction as a
    victim, it is possible that we already have the lock now granted! */

    if (trx->wait_lock == NULL) {

        return(DB_SUCCESS_LOCKED_REC);
    }

    trx->que_state = TRX_QUE_LOCK_WAIT;
    trx->was_chosen_as_deadlock_victim = FALSE;
    trx->wait_started = time(NULL);

    ut_a(que_thr_stop(thr));

#ifdef UNIV_DEBUG
    if (lock_print_waits) {
        fprintf(stderr, "Lock wait for trx " TRX_ID_FMT " in index ",
            (ullint) trx->id);
        ut_print_name(stderr, trx, FALSE, index->name);
    }
#endif /* UNIV_DEBUG */

    return(DB_LOCK_WAIT);
}

函数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. 如何让360、遨游、猎豹等双核浏览器默认以webkit内核渲染网页?

    众知目前国内不少浏览器都自称双核,一般是 IE(Trident)+Webkit.因为 webkit 急速的体验和对 HTML5 的支持,有些情况下开发者可能希望用户优先甚至只使用 webkit 内核渲 ...

  2. Gitlab仓库规范实践建议

    记录一下Gitlab仓库实践信息: 仓库是指一个可以git clone的地址,用于存储某个服务,模块,子系统或某类辅助代码的地方 仓库的visibility level一般设置为Private(访问需 ...

  3. 利用dsniff的tcpkill杀TCP连接

    利用dsniff的tcpkill杀TCP连接 Linux连接久久不能释放的现象不常见,但偶然也会发生.进程虽不复存在,但是客户端的连接咬定青山不放松,死活也不肯吐出连接,导致重启进程时因操作系统判断监 ...

  4. 【C++】指针数组和数组指针

    首先的首先,稍微抱怨一下阿里今天的严重失误.说好的晚六点笔试,说好的务必提前半小时到场.六点十五的时候告诉闷在一个大教室里躁动的我们“今天七点半开考,大家先回去吧,七点半再过来”,满脸黑线…等到七点半 ...

  5. 自绘按钮,添加Color属性(转载)

    在标准的Windows程序中所有按钮均没有颜色.因此Delphi提供的所有按钮组件也均无颜色属性,有时你可能做了一个五颜六色的程序界面,而按钮颜色可能很不相称. 在此本人提供一种用自定义组件制作有颜色 ...

  6. POJ 1325

    #include<iostream> #include<stdio.h> #define MAXN 105 using namespace std; int _m[MAXN][ ...

  7. Codeforces Round #263 (Div. 2) D. Appleman and Tree(树形DP)

    题目链接 D. Appleman and Tree time limit per test :2 seconds memory limit per test: 256 megabytes input ...

  8. lintcode:买卖股票的最佳时机 II

    买卖股票的最佳时机 II 假设有一个数组,它的第i个元素是一个给定的股票在第i天的价格.设计一个算法来找到最大的利润.你可以完成尽可能多的交易(多次买卖股票).然而,你不能同时参与多个交易(你必须在再 ...

  9. Qt源代码分析

    记下好文章,慢慢看,然后加上自己心得: http://www.cnblogs.com/hicjiajia/archive/2011/08/27/2155512.html Qt源码分析之信号和槽机制ht ...

  10. 如何在Eclipse中添加Tomcat的jar包

    原文:如何在Eclipse中添加Tomcat的jar包 右键项目工程,点击Java Build Path 点击Add Library,选择Server Runtime 选择Tomcat版本 此时就看到 ...