Commit 9987500c authored by Julien Muchembled's avatar Julien Muchembled

Fix MySQL db replication

git-svn-id: https://svn.erp5.org/repos/neo/trunk@2814 71dcc9de-d417-0410-9af5-da40c76e7ee4
parent 4a4d2e64
......@@ -21,6 +21,7 @@ from MySQLdb import OperationalError
from MySQLdb.constants.CR import SERVER_GONE_ERROR, SERVER_LOST
import neo.lib
from array import array
from hashlib import md5
import string
from neo.storage.database import DatabaseManager
......@@ -74,6 +75,7 @@ class MySQLDatabaseManager(DatabaseManager):
self.db, self.user)
self.conn = MySQLdb.connect(**kwd)
self.conn.autocommit(False)
self.conn.query("SET SESSION group_concat_max_len = -1")
def _begin(self):
self.query("""BEGIN""")
......@@ -812,14 +814,13 @@ class MySQLDatabaseManager(DatabaseManager):
self.commit()
def checkTIDRange(self, min_tid, max_tid, length, num_partitions, partition):
count, tid_checksum, max_tid = self.query('SELECT COUNT(*), '
'MD5(GROUP_CONCAT(tid SEPARATOR ",")), MAX(tid) FROM ('
'SELECT tid FROM trans '
'WHERE partition = %(partition)s '
'AND tid >= %(min_tid)d '
'AND tid <= %(max_tid)d '
'ORDER BY tid ASC LIMIT %(length)d'
') AS foo' % {
count, tid_checksum, max_tid = self.query(
"""SELECT COUNT(*), MD5(GROUP_CONCAT(tid SEPARATOR ",")), MAX(tid)
FROM (SELECT tid FROM trans
WHERE partition = %(partition)s
AND tid >= %(min_tid)d
AND tid <= %(max_tid)d
ORDER BY tid ASC LIMIT %(length)d) AS t""" % {
'partition': partition,
'min_tid': util.u64(min_tid),
'max_tid': util.u64(max_tid),
......@@ -835,9 +836,12 @@ class MySQLDatabaseManager(DatabaseManager):
def checkSerialRange(self, min_oid, min_serial, max_tid, length,
num_partitions, partition):
u64 = util.u64
count, oid_checksum, max_oid, serial_checksum, max_serial = self.query(
"""SELECT COUNT(*), MD5(GROUP_CONCAT(oid SEPARATOR ",")), MAX(oid),
MD5(GROUP_CONCAT(serial SEPARATOR ",")), MAX(serial)
# We don't ask MySQL to compute everything (like in checkTIDRange)
# because it's difficult to get the last serial _for the last oid_.
# We would need a function (that be named 'LAST') that return the
# last grouped value, instead of the greatest one.
r = self.query(
"""SELECT oid, serial
FROM obj_short
WHERE partition = %(partition)s
AND serial <= %(max_tid)d
......@@ -849,14 +853,12 @@ class MySQLDatabaseManager(DatabaseManager):
'max_tid': u64(max_tid),
'length': length,
'partition': partition,
})[0]
if count:
oid_checksum = a2b_hex(oid_checksum)
serial_checksum = a2b_hex(serial_checksum)
max_oid = util.p64(max_oid)
max_serial = util.p64(max_serial)
else:
max_oid = ZERO_OID
max_serial = ZERO_TID
return count, oid_checksum, max_oid, serial_checksum, max_serial
})
if r:
p64 = util.p64
return (len(r),
md5(','.join(str(x[0]) for x in r)).digest(),
p64(r[-1][0]),
md5(','.join(str(x[1]) for x in r)).digest(),
p64(r[-1][1]))
return 0, None, ZERO_OID, None, ZERO_TID
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