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
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Stefane Fermigier
neo
Commits
041a3eda
Commit
041a3eda
authored
Feb 24, 2017
by
Julien Muchembled
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
mysql: code clean up
parent
9b33b1db
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
17 additions
and
13 deletions
+17
-13
neo/storage/database/mysqldb.py
neo/storage/database/mysqldb.py
+17
-13
No files found.
neo/storage/database/mysqldb.py
View file @
041a3eda
...
...
@@ -20,6 +20,9 @@ from MySQLdb import DataError, IntegrityError, \
OperationalError
,
ProgrammingError
from
MySQLdb.constants.CR
import
SERVER_GONE_ERROR
,
SERVER_LOST
from
MySQLdb.constants.ER
import
DATA_TOO_LONG
,
DUP_ENTRY
,
NO_SUCH_TABLE
# BBB: the following 2 constants were added to mysqlclient 1.3.8
DROP_LAST_PARTITION
=
1508
SAME_NAME_PARTITION
=
1517
from
array
import
array
from
hashlib
import
sha1
import
os
...
...
@@ -121,10 +124,11 @@ class MySQLDatabaseManager(DatabaseManager):
for
d
in
row
])
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
):
except
OperationalError
as
m
:
code
,
m
=
m
.
args
if
self
.
_active
or
SERVER_GONE_ERROR
!=
code
!=
SERVER_LOST
:
raise
DatabaseFailure
(
'MySQL error %d: %s
\
n
Query: %s'
%
(
m
[
0
],
m
[
1
]
,
getPrintableQuery
(
query
[:
1000
])))
%
(
code
,
m
,
getPrintableQuery
(
query
[:
1000
])))
logging
.
info
(
'the MySQL server is gone; reconnecting'
)
self
.
_connect
()
r
=
query
.
split
(
None
,
1
)[
0
]
...
...
@@ -145,8 +149,8 @@ class MySQLDatabaseManager(DatabaseManager):
def
nonempty
(
self
,
table
):
try
:
return
bool
(
self
.
query
(
"SELECT 1 FROM %s LIMIT 1"
%
table
))
except
ProgrammingError
,
(
code
,
_
)
:
if
code
!=
NO_SUCH_TABLE
:
except
ProgrammingError
as
e
:
if
e
.
args
[
0
]
!=
NO_SUCH_TABLE
:
raise
def
_setup
(
self
):
...
...
@@ -276,8 +280,8 @@ class MySQLDatabaseManager(DatabaseManager):
sql
=
"REPLACE INTO config VALUES ('%s', '%s')"
%
(
k
,
e
(
value
))
try
:
q
(
sql
)
except
DataError
,
(
code
,
_
)
:
if
code
!=
DATA_TOO_LONG
or
len
(
value
)
<
256
or
key
!=
"zodb"
:
except
DataError
as
e
:
if
e
.
args
[
0
]
!=
DATA_TOO_LONG
or
len
(
value
)
<
256
or
key
!=
"zodb"
:
raise
q
(
"ALTER TABLE config MODIFY value VARBINARY(%s) NULL"
%
len
(
value
))
q
(
sql
)
...
...
@@ -380,8 +384,8 @@ class MySQLDatabaseManager(DatabaseManager):
for
table
in
'trans'
,
'obj'
:
try
:
self
.
conn
.
query
(
add
%
table
)
except
OperationalError
,
(
code
,
_
)
:
if
code
!=
1517
:
# duplicate partition name
except
OperationalError
as
e
:
if
e
.
args
[
0
]
!=
SAME_NAME_PARTITION
:
raise
def
dropPartitions
(
self
,
offset_list
):
...
...
@@ -404,8 +408,8 @@ class MySQLDatabaseManager(DatabaseManager):
for
table
in
'trans'
,
'obj'
:
try
:
self
.
conn
.
query
(
drop
%
table
)
except
OperationalError
,
(
code
,
_
)
:
if
code
!=
1508
:
# already dropped
except
OperationalError
as
e
:
if
e
.
args
[
0
]
!=
DROP_LAST_PARTITION
:
raise
def
dropUnfinishedData
(
self
):
...
...
@@ -531,8 +535,8 @@ class MySQLDatabaseManager(DatabaseManager):
try
:
self
.
query
(
"INSERT INTO data VALUES (NULL, '%s', %d, '%s')"
%
(
checksum
,
compression
,
e
(
data
)))
except
IntegrityError
,
(
code
,
_
)
:
if
code
==
DUP_ENTRY
:
except
IntegrityError
as
e
:
if
e
.
args
[
0
]
==
DUP_ENTRY
:
(
r
,
d
),
=
self
.
query
(
"SELECT id, value FROM data"
" WHERE hash='%s' AND compression=%s"
%
(
checksum
,
compression
))
...
...
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