From 2370a3f89f80d575cfb3e00b2ec90594e44cc70d Mon Sep 17 00:00:00 2001 From: antao Date: Mon, 18 Feb 2019 14:26:21 +0800 Subject: [PATCH] Fix a bug in the MysqlConnection class --- orm_lib/src/TransactionImpl.cc | 75 ++++++++++------------- orm_lib/src/mysql_impl/MysqlConnection.cc | 3 + 2 files changed, 37 insertions(+), 41 deletions(-) diff --git a/orm_lib/src/TransactionImpl.cc b/orm_lib/src/TransactionImpl.cc index d3e6a5d9..fd98ca89 100644 --- a/orm_lib/src/TransactionImpl.cc +++ b/orm_lib/src/TransactionImpl.cc @@ -164,25 +164,23 @@ void TransactionImpl::rollback() return; } thisPtr->_isWorking = true; - thisPtr - ->_connectionPtr - ->execSql("rollback", - 0, - std::vector(), - std::vector(), - std::vector(), - [](const Result &r) { - LOG_TRACE << "Transaction roll back!"; - //clearupCb(); - }, - [](const std::exception_ptr &ePtr) { - //clearupCb(); - LOG_ERROR << "Transaction rool back error"; - }, - [thisPtr, clearupCb]() { - clearupCb(); - thisPtr->execNewTask(); - }); + thisPtr->_connectionPtr->execSql("rollback", + 0, + std::vector(), + std::vector(), + std::vector(), + [](const Result &r) { + LOG_TRACE << "Transaction roll back!"; + //clearupCb(); + }, + [](const std::exception_ptr &ePtr) { + //clearupCb(); + LOG_ERROR << "Transaction rool back error"; + }, + [thisPtr, clearupCb]() { + clearupCb(); + thisPtr->execNewTask(); + }); }); } @@ -197,29 +195,24 @@ void TransactionImpl::execNewTask() { auto cmd = _sqlCmdBuffer.front(); _sqlCmdBuffer.pop_front(); - auto conn = _connectionPtr; - - _loop->queueInLoop([=]() mutable { - conn->execSql(std::move(cmd._sql), - cmd._paraNum, - std::move(cmd._parameters), - std::move(cmd._length), - std::move(cmd._format), - std::move(cmd._cb), - [cmd, thisPtr](const std::exception_ptr &ePtr) { - if (!cmd._idleCb) - thisPtr->rollback(); - if (cmd._exceptCb) - cmd._exceptCb(ePtr); - }, - [cmd,thisPtr]() { - if(cmd._idleCb) - cmd._idleCb(); - thisPtr->execNewTask(); - }); - }); - + conn->execSql(std::move(cmd._sql), + cmd._paraNum, + std::move(cmd._parameters), + std::move(cmd._length), + std::move(cmd._format), + std::move(cmd._cb), + [cmd, thisPtr](const std::exception_ptr &ePtr) { + if (!cmd._idleCb) + thisPtr->rollback(); + if (cmd._exceptCb) + cmd._exceptCb(ePtr); + }, + [cmd, thisPtr]() { + if (cmd._idleCb) + cmd._idleCb(); + thisPtr->execNewTask(); + }); return; } _isWorking = false; diff --git a/orm_lib/src/mysql_impl/MysqlConnection.cc b/orm_lib/src/mysql_impl/MysqlConnection.cc index ba8013af..2f624aef 100644 --- a/orm_lib/src/mysql_impl/MysqlConnection.cc +++ b/orm_lib/src/mysql_impl/MysqlConnection.cc @@ -72,6 +72,7 @@ MysqlConnection::MysqlConnection(trantor::EventLoop *loop, const std::string &co } else if (key == "dbname") { + LOG_DEBUG << "database:" << value; dbname = value; } else if (key == "port") @@ -204,6 +205,8 @@ void MysqlConnection::handleEvent() if (revents & POLLPRI) status |= MYSQL_WAIT_EXCEPT; status = (status & _waitStatus); + if (status == 0) + return; MYSQL *ret; if (_status == ConnectStatus_Connecting) {