mysql lock wait t_mysql-排序事务:ER_LOCK_WAIT_TIMEOUT

我在使用mysql(5.6.17)进行事务续集时遇到问题,我有一个插入语句和两个更新应该全部完成或不执行,但是最终交易.create似乎回滚了,但是driver.update执行了,但没有执行回滚和第三次更新,即trip.update语句,没有任何更改或回滚,控制台挂起,几秒钟后抛出此错误:

Executing (42a68c8e-8347-45af-b9a2-7b0e7a89606b): START TRANSACTION;

Executing (42a68c8e-8347-45af-b9a2-7b0e7a89606b): SET SESSION TRANSACTION ISOLATION LEVEL READ COMMITTED;

Executing (42a68c8e-8347-45af-b9a2-7b0e7a89606b): SET autocommit = 1;

Executing (42a68c8e-8347-45af-b9a2-7b0e7a89606b): INSERT INTO `transactions` (`id`,`tId`,`total_price`,`company_share`,`driver_share`,`at`) VALUES (DEFAULT,'13',1000,100,900,'2016-07-04 10:44:43');

Executing (default): UPDATE `driver` SET `balance`=`balance` - 100 WHERE `id` = '1'

Executing (default): UPDATE `trip` SET `paid`=1 WHERE `id` = '13'

Executing (42a68c8e-8347-45af-b9a2-7b0e7a89606b): ROLLBACK;

5---SequelizeDatabaseError: ER_LOCK_WAIT_TIMEOUT: Lock wait timeout exceeded; try restarting transaction

交易部分是:

var Sequelize = require('sequelize');

var config = {};

config.sequelize = new Sequelize('mydb', 'root', null, {

host: 'localhost',

port: 3306,

dialect: 'mysql',

logging: true,

pool: {

max: 100,

min: 0,

idle: 10000

},

define: {

timestamps: false

}

});

require('sequelize-isunique-validator')(Sequelize);

var driver = require('./../models/driver.js')(config.sequelize, Sequelize);

var transactions = require('./../models/transactions.js')(config.sequelize, Sequelize);

var trip = require('./../models/trip.js')(config.sequelize, Sequelize);

return config.sequelize.transaction({isolationLevel:Sequelize.Transaction.ISOLATION_LEVELS.READ_COMMITTED},function (t) {

return transactions.create({tId: tripId, total_price: totalPrice, company_share: companyShare, driver_share: driverShare}, {transaction: t})

.then(function (result) {

return driver.update({balance: config.sequelize.literal('`balance` - '+companyShare)}, {where: {id: dId}}, {transaction: t})

.then(function (result) {

return trip.update({paid: 1}, {where: {id: tripId}}, {transaction: t});

});

});

}).then(function (result) {

RequestQueue.hmset(ticket,"ticketState",value.Paid);

res.json({'status': 'success','change':(-company_share)});

}).catch(function (err) {

global.console.log('5---'+err);

res.json({'status': 'failed'});

});

我确信我的模型是正确的,因为我在其他地方使用了它们,没有任何问题,也没有将它们放在此处以保持问题的清洁度和主题性,但是如果它有助于提出意见,请tnx!

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值