Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
D
doctrine-dbal
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Tomáš Trávníček
doctrine-dbal
Commits
a3a86aa5
Commit
a3a86aa5
authored
Jan 10, 2016
by
Steve Müller
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #718 from Tobion/retry-logic
Identify retryable transaction errors
parents
3dcf0cc8
43f92753
Changes
12
Hide whitespace changes
Inline
Side-by-side
Showing
12 changed files
with
137 additions
and
0 deletions
+137
-0
AbstractMySQLDriver.php
lib/Doctrine/DBAL/Driver/AbstractMySQLDriver.php
+4
-0
AbstractPostgreSQLDriver.php
lib/Doctrine/DBAL/Driver/AbstractPostgreSQLDriver.php
+3
-0
AbstractSQLAnywhereDriver.php
lib/Doctrine/DBAL/Driver/AbstractSQLAnywhereDriver.php
+8
-0
AbstractSQLiteDriver.php
lib/Doctrine/DBAL/Driver/AbstractSQLiteDriver.php
+4
-0
DeadlockException.php
lib/Doctrine/DBAL/Exception/DeadlockException.php
+31
-0
LockWaitTimeoutException.php
lib/Doctrine/DBAL/Exception/LockWaitTimeoutException.php
+31
-0
RetryableException.php
lib/Doctrine/DBAL/Exception/RetryableException.php
+31
-0
AbstractDriverTest.php
tests/Doctrine/Tests/DBAL/Driver/AbstractDriverTest.php
+2
-0
AbstractMySQLDriverTest.php
tests/Doctrine/Tests/DBAL/Driver/AbstractMySQLDriverTest.php
+6
-0
AbstractPostgreSQLDriverTest.php
...ctrine/Tests/DBAL/Driver/AbstractPostgreSQLDriverTest.php
+4
-0
AbstractSQLAnywhereDriverTest.php
...trine/Tests/DBAL/Driver/AbstractSQLAnywhereDriverTest.php
+10
-0
AbstractSQLiteDriverTest.php
...s/Doctrine/Tests/DBAL/Driver/AbstractSQLiteDriverTest.php
+3
-0
No files found.
lib/Doctrine/DBAL/Driver/AbstractMySQLDriver.php
View file @
a3a86aa5
...
...
@@ -45,6 +45,10 @@ abstract class AbstractMySQLDriver implements Driver, ExceptionConverterDriver,
public
function
convertException
(
$message
,
DriverException
$exception
)
{
switch
(
$exception
->
getErrorCode
())
{
case
'1213'
:
return
new
Exception\DeadlockException
(
$message
,
$exception
);
case
'1205'
:
return
new
Exception\LockWaitTimeoutException
(
$message
,
$exception
);
case
'1050'
:
return
new
Exception\TableExistsException
(
$message
,
$exception
);
...
...
lib/Doctrine/DBAL/Driver/AbstractPostgreSQLDriver.php
View file @
a3a86aa5
...
...
@@ -46,6 +46,9 @@ abstract class AbstractPostgreSQLDriver implements Driver, ExceptionConverterDri
public
function
convertException
(
$message
,
DriverException
$exception
)
{
switch
(
$exception
->
getSQLState
())
{
case
'40001'
:
case
'40P01'
:
return
new
Exception\DeadlockException
(
$message
,
$exception
);
case
'0A000'
:
// Foreign key constraint violations during a TRUNCATE operation
// are considered "feature not supported" in PostgreSQL.
...
...
lib/Doctrine/DBAL/Driver/AbstractSQLAnywhereDriver.php
View file @
a3a86aa5
...
...
@@ -46,6 +46,14 @@ abstract class AbstractSQLAnywhereDriver implements Driver, ExceptionConverterDr
public
function
convertException
(
$message
,
DriverException
$exception
)
{
switch
(
$exception
->
getErrorCode
())
{
case
'-306'
:
case
'-307'
:
case
'-684'
:
return
new
Exception\DeadlockException
(
$message
,
$exception
);
case
'-210'
:
case
'-1175'
:
case
'-1281'
:
return
new
Exception\LockWaitTimeoutException
(
$message
,
$exception
);
case
'-100'
:
case
'-103'
:
case
'-832'
:
...
...
lib/Doctrine/DBAL/Driver/AbstractSQLiteDriver.php
View file @
a3a86aa5
...
...
@@ -40,6 +40,10 @@ abstract class AbstractSQLiteDriver implements Driver, ExceptionConverterDriver
*/
public
function
convertException
(
$message
,
DriverException
$exception
)
{
if
(
strpos
(
$exception
->
getMessage
(),
'database is locked'
)
!==
false
)
{
return
new
Exception\LockWaitTimeoutException
(
$message
,
$exception
);
}
if
(
strpos
(
$exception
->
getMessage
(),
'must be unique'
)
!==
false
||
strpos
(
$exception
->
getMessage
(),
'is not unique'
)
!==
false
||
strpos
(
$exception
->
getMessage
(),
'are not unique'
)
!==
false
||
...
...
lib/Doctrine/DBAL/Exception/DeadlockException.php
0 → 100644
View file @
a3a86aa5
<?php
/*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* This software consists of voluntary contributions made by many individuals
* and is licensed under the MIT license. For more information, see
* <http://www.doctrine-project.org>.
*/
namespace
Doctrine\DBAL\Exception
;
/**
* Exception for a deadlock error of a transaction detected in the driver.
*
* @author Tobias Schultze <http://tobion.de>
* @link www.doctrine-project.org
* @since 2.6
*/
class
DeadlockException
extends
ServerException
implements
RetryableException
{
}
lib/Doctrine/DBAL/Exception/LockWaitTimeoutException.php
0 → 100644
View file @
a3a86aa5
<?php
/*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* This software consists of voluntary contributions made by many individuals
* and is licensed under the MIT license. For more information, see
* <http://www.doctrine-project.org>.
*/
namespace
Doctrine\DBAL\Exception
;
/**
* Exception for a lock wait timeout error of a transaction detected in the driver.
*
* @author Tobias Schultze <http://tobion.de>
* @link www.doctrine-project.org
* @since 2.6
*/
class
LockWaitTimeoutException
extends
ServerException
implements
RetryableException
{
}
lib/Doctrine/DBAL/Exception/RetryableException.php
0 → 100644
View file @
a3a86aa5
<?php
/*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* This software consists of voluntary contributions made by many individuals
* and is licensed under the MIT license. For more information, see
* <http://www.doctrine-project.org>.
*/
namespace
Doctrine\DBAL\Exception
;
/**
* Marker interface for all exceptions where retrying the transaction makes sense.
*
* @author Tobias Schultze <http://tobion.de>
* @link www.doctrine-project.org
* @since 2.6
*/
interface
RetryableException
{
}
tests/Doctrine/Tests/DBAL/Driver/AbstractDriverTest.php
View file @
a3a86aa5
...
...
@@ -24,6 +24,8 @@ abstract class AbstractDriverTest extends DbalTestCase
const
EXCEPTION_TABLE_EXISTS
=
'Doctrine\DBAL\Exception\TableExistsException'
;
const
EXCEPTION_TABLE_NOT_FOUND
=
'Doctrine\DBAL\Exception\TableNotFoundException'
;
const
EXCEPTION_UNIQUE_CONSTRAINT_VIOLATION
=
'Doctrine\DBAL\Exception\UniqueConstraintViolationException'
;
const
EXCEPTION_DEADLOCK
=
'Doctrine\DBAL\Exception\DeadlockException'
;
const
EXCEPTION_LOCK_WAIT_TIMEOUT
=
'Doctrine\DBAL\Exception\LockWaitTimeoutException'
;
/**
* The driver mock under test.
...
...
tests/Doctrine/Tests/DBAL/Driver/AbstractMySQLDriverTest.php
View file @
a3a86aa5
...
...
@@ -134,6 +134,12 @@ class AbstractMySQLDriverTest extends AbstractDriverTest
array
(
'1569'
,
null
,
null
),
array
(
'1586'
,
null
,
null
),
),
self
::
EXCEPTION_DEADLOCK
=>
array
(
array
(
'1213'
,
null
,
null
),
),
self
::
EXCEPTION_LOCK_WAIT_TIMEOUT
=>
array
(
array
(
'1205'
,
null
,
null
),
),
);
}
}
tests/Doctrine/Tests/DBAL/Driver/AbstractPostgreSQLDriverTest.php
View file @
a3a86aa5
...
...
@@ -101,6 +101,10 @@ class AbstractPostgreSQLDriverTest extends AbstractDriverTest
self
::
EXCEPTION_UNIQUE_CONSTRAINT_VIOLATION
=>
array
(
array
(
null
,
'23505'
,
null
),
),
self
::
EXCEPTION_DEADLOCK
=>
array
(
array
(
null
,
'40001'
,
null
),
array
(
null
,
'40P01'
,
null
),
),
);
}
}
tests/Doctrine/Tests/DBAL/Driver/AbstractSQLAnywhereDriverTest.php
View file @
a3a86aa5
...
...
@@ -93,6 +93,16 @@ class AbstractSQLAnywhereDriverTest extends AbstractDriverTest
array
(
'-193'
,
null
,
null
),
array
(
'-196'
,
null
,
null
),
),
self
::
EXCEPTION_DEADLOCK
=>
array
(
array
(
'-306'
,
null
,
null
),
array
(
'-307'
,
null
,
null
),
array
(
'-684'
,
null
,
null
),
),
self
::
EXCEPTION_LOCK_WAIT_TIMEOUT
=>
array
(
array
(
'-210'
,
null
,
null
),
array
(
'-1175'
,
null
,
null
),
array
(
'-1281'
,
null
,
null
),
),
);
}
}
tests/Doctrine/Tests/DBAL/Driver/AbstractSQLiteDriverTest.php
View file @
a3a86aa5
...
...
@@ -73,6 +73,9 @@ class AbstractSQLiteDriverTest extends AbstractDriverTest
array
(
null
,
null
,
'is not unique'
),
array
(
null
,
null
,
'are not unique'
),
),
self
::
EXCEPTION_LOCK_WAIT_TIMEOUT
=>
array
(
array
(
null
,
null
,
'database is locked'
),
),
);
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment