Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
N
neoppod
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
Levin Zimmermann
neoppod
Commits
b70b4689
Commit
b70b4689
authored
Oct 19, 2015
by
Julien Muchembled
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
mysql: refuse to start if max_allowed_packet is too small
parent
f4a66782
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
33 additions
and
3 deletions
+33
-3
neo/storage/database/mysqldb.py
neo/storage/database/mysqldb.py
+14
-3
neo/tests/storage/testStorageMySQL.py
neo/tests/storage/testStorageMySQL.py
+19
-0
No files found.
neo/storage/database/mysqldb.py
View file @
b70b4689
...
...
@@ -50,6 +50,8 @@ class MySQLDatabaseManager(DatabaseManager):
# (tested with testOudatedCellsOnDownStorage).
_use_partition
=
False
_max_allowed_packet
=
32769
*
1024
def
__init__
(
self
,
*
args
,
**
kw
):
super
(
MySQLDatabaseManager
,
self
).
__init__
(
*
args
,
**
kw
)
self
.
conn
=
None
...
...
@@ -87,9 +89,18 @@ class MySQLDatabaseManager(DatabaseManager):
logging
.
exception
(
'Connection to MySQL failed, retrying.'
)
time
.
sleep
(
1
)
self
.
_active
=
0
self
.
conn
.
autocommit
(
False
)
self
.
conn
.
query
(
"SET SESSION group_concat_max_len = %u"
%
(
2
**
32
-
1
))
self
.
conn
.
set_sql_mode
(
"TRADITIONAL,NO_ENGINE_SUBSTITUTION"
)
conn
=
self
.
conn
conn
.
autocommit
(
False
)
conn
.
query
(
"SET SESSION group_concat_max_len = %u"
%
(
2
**
32
-
1
))
conn
.
set_sql_mode
(
"TRADITIONAL,NO_ENGINE_SUBSTITUTION"
)
conn
.
query
(
"SHOW VARIABLES WHERE variable_name='max_allowed_packet'"
)
r
=
conn
.
store_result
()
(
name
,
value
),
=
r
.
fetch_row
(
r
.
num_rows
())
if
int
(
value
)
<
self
.
_max_allowed_packet
:
raise
DatabaseFailure
(
"Global variable %r is too small."
" Minimal value must be %uk."
%
(
name
,
self
.
_max_allowed_packet
//
1024
))
self
.
_max_allowed_packet
=
int
(
value
)
def
commit
(
self
):
logging
.
debug
(
'committing...'
)
...
...
neo/tests/storage/testStorageMySQL.py
View file @
b70b4689
...
...
@@ -91,6 +91,25 @@ class StorageMySQLdbTests(StorageDBTests):
self
.
assertEqual
(
self
.
db
.
escape
(
'a"b'
),
'a
\
\
"b'
)
self
.
assertEqual
(
self
.
db
.
escape
(
"a'b"
),
"a
\
\
'b"
)
def
test_max_allowed_packet
(
self
):
EXTRA
=
2
# Check EXTRA
x
=
"SELECT '%s'"
%
(
'x'
*
(
self
.
db
.
_max_allowed_packet
-
11
))
assert
len
(
x
)
+
EXTRA
==
self
.
db
.
_max_allowed_packet
self
.
assertRaises
(
DatabaseFailure
,
self
.
db
.
query
,
x
+
' '
)
self
.
db
.
query
(
x
)
# Check MySQLDatabaseManager._max_allowed_packet
query_list
=
[]
query
=
self
.
db
.
query
self
.
db
.
query
=
lambda
query
:
query_list
.
append
(
EXTRA
+
len
(
query
))
self
.
assertEqual
(
2
,
max
(
len
(
self
.
db
.
escape
(
chr
(
x
)))
for
x
in
xrange
(
256
)))
self
.
assertEqual
(
2
,
len
(
self
.
db
.
escape
(
'
\
0
'
)))
self
.
db
.
storeData
(
'
\
0
'
*
20
,
'
\
0
'
*
(
2
**
24
-
1
),
0
)
size
,
=
query_list
max_allowed
=
self
.
db
.
__class__
.
_max_allowed_packet
self
.
assertTrue
(
max_allowed
-
1024
<
size
<=
max_allowed
,
size
)
class
StorageMySQLdbTokuDBTests
(
StorageMySQLdbTests
):
engine
=
"TokuDB"
...
...
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