首页 > 其他 > 详细

函数lock_rec_create

时间:2015-11-05 20:25:06      阅读:318      评论:0      收藏:0      [点我收藏+]

 

/*********************************************************************//**
Creates a new record lock and inserts it to the lock queue. Does NOT check
for deadlocks or lock compatibility!
@return    created lock */
static
lock_t*
lock_rec_create(
/*============*/
    ulint            type_mode,/*!< in: lock mode and wait
                    flag, type is ignored and
                    replaced by LOCK_REC */
    const buf_block_t*    block,    /*!< in: buffer block containing
                    the record */
    ulint            heap_no,/*!< in: heap number of the record */
    dict_index_t*        index,    /*!< in: index of record */
    trx_t*            trx)    /*!< in: transaction */
{
    lock_t*        lock;
    ulint        page_no;
    ulint        space;
    ulint        n_bits;
    ulint        n_bytes;
    const page_t*    page;

    ut_ad(mutex_own(&kernel_mutex));

    space = buf_block_get_space(block);
    page_no    = buf_block_get_page_no(block);
    page = block->frame;

    btr_assert_not_corrupted(block, index);

    /* If rec is the supremum record, then we reset the gap and
    LOCK_REC_NOT_GAP bits, as all locks on the supremum are
    automatically of the gap type */

    if (UNIV_UNLIKELY(heap_no == PAGE_HEAP_NO_SUPREMUM)) {
        ut_ad(!(type_mode & LOCK_REC_NOT_GAP));

        type_mode = type_mode & ~(LOCK_GAP | LOCK_REC_NOT_GAP);
    }

    /* Make lock bitmap bigger by a safety margin */
    n_bits = page_dir_get_n_heap(page) + LOCK_PAGE_BITMAP_MARGIN;
    n_bytes = 1 + n_bits / 8;

    lock = mem_heap_alloc(trx->lock_heap, sizeof(lock_t) + n_bytes);

    UT_LIST_ADD_LAST(trx_locks, trx->trx_locks, lock);

    lock->trx = trx;

    lock->type_mode = (type_mode & ~LOCK_TYPE_MASK) | LOCK_REC;
    lock->index = index;

    lock->un_member.rec_lock.space = space;
    lock->un_member.rec_lock.page_no = page_no;
    lock->un_member.rec_lock.n_bits = n_bytes * 8;

    /* Reset to zero the bitmap which resides immediately after the
    lock struct */

    lock_rec_bitmap_reset(lock);

    /* Set the bit corresponding to rec */
    lock_rec_set_nth_bit(lock, heap_no);

    HASH_INSERT(lock_t, hash, lock_sys->rec_hash,
            lock_rec_fold(space, page_no), lock);
    if (lock_is_wait_not_by_other(type_mode)) {

        lock_set_lock_and_trx_wait(lock, trx);
    }

    return(lock);
}

 

函数lock_rec_create

原文:http://www.cnblogs.com/taek/p/4940459.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!