mirror of
https://gitee.com/hyperf/hyperf.git
synced 2024-11-29 18:27:44 +08:00
Reset transaction level to zero, when reconnent to mysql server. (#1565)
This commit is contained in:
parent
825f4ffef5
commit
112e27157c
@ -2,7 +2,8 @@
|
||||
|
||||
## Fixed
|
||||
|
||||
- [#1563](https://github.com/hyperf/hyperf/pull/1563) Fixed crontab's `onOneServer` option not resetting mutex on shutdown
|
||||
- [#1563](https://github.com/hyperf/hyperf/pull/1563) Fixed crontab's `onOneServer` option not resetting mutex on shutdown.
|
||||
- [#1565](https://github.com/hyperf/hyperf/pull/1565) Reset transaction level to zero, when reconnent to mysql server.
|
||||
|
||||
# v1.1.25 - 2020-04-09
|
||||
|
||||
|
@ -58,6 +58,10 @@ abstract class AbstractConnection extends Connection implements ConnectionInterf
|
||||
|
||||
public function retry(\Throwable $throwable, $name, $arguments)
|
||||
{
|
||||
if ($this->transactionLevel() > 0) {
|
||||
throw $throwable;
|
||||
}
|
||||
|
||||
if ($this->causedByLostConnection($throwable)) {
|
||||
try {
|
||||
$this->reconnect();
|
||||
|
@ -78,7 +78,7 @@ class MySQLConnection extends AbstractConnection
|
||||
|
||||
$this->connection = $connection;
|
||||
$this->lastUseTime = microtime(true);
|
||||
|
||||
$this->transactions = 0;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -93,6 +93,7 @@ class PDOConnection extends AbstractConnection
|
||||
|
||||
$this->connection = $pdo;
|
||||
$this->lastUseTime = microtime(true);
|
||||
$this->transactions = 0;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -115,4 +115,17 @@ class PDODriverTest extends AbstractTestCase
|
||||
|
||||
$this->assertSame('Hyperf', $res['name']);
|
||||
}
|
||||
|
||||
public function testTransactionLevelWhenReconnect()
|
||||
{
|
||||
$container = $this->getContainer();
|
||||
$factory = $container->get(PoolFactory::class);
|
||||
$pool = $factory->getPool('default');
|
||||
$connection = $pool->get();
|
||||
$this->assertSame(0, $connection->transactionLevel());
|
||||
$connection->beginTransaction();
|
||||
$this->assertSame(1, $connection->transactionLevel());
|
||||
$connection->reconnect();
|
||||
$this->assertSame(0, $connection->transactionLevel());
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user