Commit a94d14a5 authored by Yoshinori Okuji's avatar Yoshinori Okuji

Remove MySQL dependency from CMFActivity. Translate a lock error into...

Remove MySQL dependency from CMFActivity. Translate a lock error into ConflictError in database adapters instead.

git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@20317 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 74711589
...@@ -26,9 +26,8 @@ ...@@ -26,9 +26,8 @@
# #
############################################################################## ##############################################################################
from _mysql_exceptions import OperationalError
from MySQLdb.constants import ER
from zLOG import LOG, INFO from zLOG import LOG, INFO
from ZODB.POSException import ConflictError
class SQLBase: class SQLBase:
""" """
...@@ -60,12 +59,10 @@ class SQLBase: ...@@ -60,12 +59,10 @@ class SQLBase:
while True: while True:
try: try:
result = method(*args, **kw) result = method(*args, **kw)
except OperationalError, value: except ConflictError:
if isinstance(value, OperationalError) and \ # Note that this code assumes that a database adapter translates
value[0] in (ER.LOCK_WAIT_TIMEOUT, ER.LOCK_DEADLOCK): # a lock error into a conflict error.
LOG('SQLBase', INFO, 'Got a lock error, retrying...') LOG('SQLBase', INFO, 'Got a lock error, retrying...')
else:
raise
else: else:
break break
return result return result
......
...@@ -102,6 +102,7 @@ from MySQLdb.constants import FIELD_TYPE, CR, ER, CLIENT ...@@ -102,6 +102,7 @@ from MySQLdb.constants import FIELD_TYPE, CR, ER, CLIENT
from Shared.DC.ZRDB.TM import TM from Shared.DC.ZRDB.TM import TM
from DateTime import DateTime from DateTime import DateTime
from zLOG import LOG, ERROR, INFO from zLOG import LOG, ERROR, INFO
from ZODB.POSException import ConflictError
import string, sys import string, sys
from string import strip, split, find, upper, rfind from string import strip, split, find, upper, rfind
...@@ -117,6 +118,11 @@ query_syntax_error = ( ...@@ -117,6 +118,11 @@ query_syntax_error = (
ER.BAD_FIELD_ERROR, ER.BAD_FIELD_ERROR,
) )
lock_error = (
ER.LOCK_WAIT_TIMEOUT,
ER.LOCK_DEADLOCK,
)
key_types = { key_types = {
"PRI": "PRIMARY KEY", "PRI": "PRIMARY KEY",
"MUL": "INDEX", "MUL": "INDEX",
...@@ -388,6 +394,8 @@ class DB(TM): ...@@ -388,6 +394,8 @@ class DB(TM):
except OperationalError, m: except OperationalError, m:
if m[0] in query_syntax_error: if m[0] in query_syntax_error:
raise OperationalError(m[0], '%s: %s' % (m[1], query)) raise OperationalError(m[0], '%s: %s' % (m[1], query))
if m[0] in lock_error:
raise ConflictError('%s: %s: %s' % (m[0], m[1], query))
if ((not force_reconnect) and \ if ((not force_reconnect) and \
(self._mysql_lock or self._transactions)) or \ (self._mysql_lock or self._transactions)) or \
m[0] not in hosed_connection: m[0] not in hosed_connection:
......
...@@ -100,6 +100,7 @@ from MySQLdb.constants import FIELD_TYPE, CR, ER, CLIENT ...@@ -100,6 +100,7 @@ from MySQLdb.constants import FIELD_TYPE, CR, ER, CLIENT
from Shared.DC.ZRDB.TM import TM from Shared.DC.ZRDB.TM import TM
from DateTime import DateTime from DateTime import DateTime
from zLOG import LOG, ERROR, INFO from zLOG import LOG, ERROR, INFO
from ZODB.POSException import ConflictError
import string, sys import string, sys
from string import strip, split, find, upper, rfind from string import strip, split, find, upper, rfind
...@@ -115,6 +116,11 @@ query_syntax_error = ( ...@@ -115,6 +116,11 @@ query_syntax_error = (
ER.BAD_FIELD_ERROR, ER.BAD_FIELD_ERROR,
) )
lock_error = (
ER.LOCK_WAIT_TIMEOUT,
ER.LOCK_DEADLOCK,
)
key_types = { key_types = {
"PRI": "PRIMARY KEY", "PRI": "PRIMARY KEY",
"MUL": "INDEX", "MUL": "INDEX",
...@@ -393,6 +399,8 @@ class DeferredDB(TM): ...@@ -393,6 +399,8 @@ class DeferredDB(TM):
except OperationalError, m: except OperationalError, m:
if m[0] in query_syntax_error: if m[0] in query_syntax_error:
raise OperationalError(m[0], '%s: %s' % (m[1], query)) raise OperationalError(m[0], '%s: %s' % (m[1], query))
if m[0] in lock_error:
raise ConflictError('%s: %s: %s' % (m[0], m[1], query))
if ((not force_reconnect) and \ if ((not force_reconnect) and \
(self._mysql_lock or self._transactions)) or \ (self._mysql_lock or self._transactions)) or \
m[0] not in hosed_connection: m[0] not in hosed_connection:
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment