mysql start tran_mysql事务-简介

// sql/sql_parse.cc:mysql_execute_command

// 事务开始

// case SQLCOM_BEGIN:

if (trans_begin(thd, lex->start_transaction_opt)) { // 释放事务锁,其他错误处理,忽略}

// sql/transaction.cc

trans_begin:

if (trans_check(thd) DEBUG_RETURN(TRUE);

if (thd->in_multi_stmt_transaction_mode() ||

(thd->variables.option_bits & OPTION_TABLE_LOCK)) {

thd->server_status &= ~SERVER_STATUS_IN_TRANS;

res = test(ha_commit_trans(thd, TRUE));

}

if (res) DEBUG_RETURN(TRUE);

// 待解,啥是consistent_snapshot

if (flags & MYSQL_START_TRANS_OPT_WITH_CONS_SNAPSHOT)

res = ha_start_consistent_snapshot(thd);

// 事务提交

// case SQLCOM_COMMIT:

if (trans_commit(thd)) { //释放事务锁,其他错误处理,忽略}

// sql/transaction.cc

trans_commit:

trans_check(thd);

res = ha_commit_trans(thd, TRUE);

# 如果res==0, 则事务提交成功

if (res)

RUN_HOOK(transaction, after_rollback, (thd, FALSE));

else

RUN_HOOK(transaction, after_commit, (thd, FALSE));

// sql/handler.cc

ha_commit_trans:

// 如果是读写事务

if (thd->mdl_context.acquire_lock(&mld_request, thd->variables.lock_wait_timeout)) {

ha_rollback_trans(thd, all

}

// 如果是非两阶段事务,则直接提交

if (trans->no_2pc || (rw_ha_count <= 1)) {

error = ha_commit_one_phase(thd, all);

goto done;

}

ha_commit_one_phase:

res = commit_one_phase_2(thd, all, trans, is_real_trans);

commit_one_phase_2:

// 所有参与本次事务的存储引擎

Ha_trx_info *ha_info = trans->ha_list, *ha_info_next;

if (ha_info) {

for(; ha_info; ha_info = ha_info_next) {

handlerton *ht = ha_info->ht();

if (( err = ht->commit(ht, thd, all))) {

// 存储引擎commit失败,错误处理

}

ha_info_next = ha_info->next();

// 不解,直接reset后,怎么释放ha_info

ha_info->reset();

}

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值