Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
N
neo
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Labels
Merge Requests
2
Merge Requests
2
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Jobs
Commits
Open sidebar
Kirill Smelkov
neo
Commits
93aef5ed
Commit
93aef5ed
authored
Jun 23, 2015
by
Julien Muchembled
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
mysql: log failed query in case of database failure
parent
f8ce322b
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
28 additions
and
27 deletions
+28
-27
neo/storage/database/mysqldb.py
neo/storage/database/mysqldb.py
+28
-27
No files found.
neo/storage/database/mysqldb.py
View file @
93aef5ed
...
@@ -33,6 +33,11 @@ from neo.lib.exception import DatabaseFailure
...
@@ -33,6 +33,11 @@ from neo.lib.exception import DatabaseFailure
from
neo.lib.protocol
import
CellStates
,
ZERO_OID
,
ZERO_TID
,
ZERO_HASH
from
neo.lib.protocol
import
CellStates
,
ZERO_OID
,
ZERO_TID
,
ZERO_HASH
def
getPrintableQuery
(
query
,
max
=
70
):
return
''
.
join
(
c
if
c
in
string
.
printable
and
c
not
in
'
\
t
\
x0b
\
x0c
\
r
'
else
'
\
\
x%02x'
%
ord
(
c
)
for
c
in
query
)
class
MySQLDatabaseManager
(
DatabaseManager
):
class
MySQLDatabaseManager
(
DatabaseManager
):
"""This class manages a database on MySQL."""
"""This class manages a database on MySQL."""
...
@@ -92,17 +97,12 @@ class MySQLDatabaseManager(DatabaseManager):
...
@@ -92,17 +97,12 @@ class MySQLDatabaseManager(DatabaseManager):
def
query
(
self
,
query
):
def
query
(
self
,
query
):
"""Query data from a database."""
"""Query data from a database."""
if
LOG_QUERIES
:
logging
.
debug
(
'querying %s...'
,
getPrintableQuery
(
query
.
split
(
'
\
n
'
,
1
)[
0
][:
70
]))
while
1
:
conn
=
self
.
conn
conn
=
self
.
conn
try
:
try
:
if
LOG_QUERIES
:
printable_char_list
=
[]
for
c
in
query
.
split
(
'
\
n
'
,
1
)[
0
][:
70
]:
if
c
not
in
string
.
printable
or
c
in
'
\
t
\
x0b
\
x0c
\
r
'
:
c
=
'
\
\
x%02x'
%
ord
(
c
)
printable_char_list
.
append
(
c
)
query_part
=
''
.
join
(
printable_char_list
)
logging
.
debug
(
'querying %s...'
,
query_part
)
conn
.
query
(
query
)
conn
.
query
(
query
)
if
query
.
startswith
(
"SELECT "
):
if
query
.
startswith
(
"SELECT "
):
r
=
conn
.
store_result
()
r
=
conn
.
store_result
()
...
@@ -110,17 +110,18 @@ class MySQLDatabaseManager(DatabaseManager):
...
@@ -110,17 +110,18 @@ class MySQLDatabaseManager(DatabaseManager):
tuple
([
d
.
tostring
()
if
isinstance
(
d
,
array
)
else
d
tuple
([
d
.
tostring
()
if
isinstance
(
d
,
array
)
else
d
for
d
in
row
])
for
d
in
row
])
for
row
in
r
.
fetch_row
(
r
.
num_rows
())])
for
row
in
r
.
fetch_row
(
r
.
num_rows
())])
break
except
OperationalError
,
m
:
if
self
.
_active
or
m
[
0
]
not
in
(
SERVER_GONE_ERROR
,
SERVER_LOST
):
raise
DatabaseFailure
(
'MySQL error %d: %s
\
n
Query: %s'
%
(
m
[
0
],
m
[
1
],
getPrintableQuery
(
query
[:
1000
])))
logging
.
info
(
'the MySQL server is gone; reconnecting'
)
self
.
_connect
()
r
=
query
.
split
(
None
,
1
)[
0
]
r
=
query
.
split
(
None
,
1
)[
0
]
if
r
in
(
"INSERT"
,
"REPLACE"
,
"DELETE"
,
"UPDATE"
):
if
r
in
(
"INSERT"
,
"REPLACE"
,
"DELETE"
,
"UPDATE"
):
self
.
_active
=
1
self
.
_active
=
1
else
:
else
:
assert
r
in
(
"ALTER"
,
"CREATE"
,
"DROP"
,
"TRUNCATE"
),
query
assert
r
in
(
"ALTER"
,
"CREATE"
,
"DROP"
,
"TRUNCATE"
),
query
except
OperationalError
,
m
:
if
m
[
0
]
in
(
SERVER_GONE_ERROR
,
SERVER_LOST
)
and
not
self
.
_active
:
logging
.
info
(
'the MySQL server is gone; reconnecting'
)
self
.
_connect
()
return
self
.
query
(
query
)
raise
DatabaseFailure
(
'MySQL error %d: %s'
%
(
m
[
0
],
m
[
1
]))
@
property
@
property
def
escape
(
self
):
def
escape
(
self
):
...
...
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