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 ...@@ -21,6 +21,7 @@ from MySQLdb import OperationalError
from MySQLdb.constants.CR import SERVER_GONE_ERROR, SERVER_LOST from MySQLdb.constants.CR import SERVER_GONE_ERROR, SERVER_LOST
import neo.lib import neo.lib
from array import array from array import array
from hashlib import md5
import string import string
from neo.storage.database import DatabaseManager from neo.storage.database import DatabaseManager
...@@ -74,6 +75,7 @@ class MySQLDatabaseManager(DatabaseManager): ...@@ -74,6 +75,7 @@ class MySQLDatabaseManager(DatabaseManager):
self.db, self.user) self.db, self.user)
self.conn = MySQLdb.connect(**kwd) self.conn = MySQLdb.connect(**kwd)
self.conn.autocommit(False) self.conn.autocommit(False)
self.conn.query("SET SESSION group_concat_max_len = -1")
def _begin(self): def _begin(self):
self.query("""BEGIN""") self.query("""BEGIN""")
...@@ -812,18 +814,17 @@ class MySQLDatabaseManager(DatabaseManager): ...@@ -812,18 +814,17 @@ class MySQLDatabaseManager(DatabaseManager):
self.commit() self.commit()
def checkTIDRange(self, min_tid, max_tid, length, num_partitions, partition): def checkTIDRange(self, min_tid, max_tid, length, num_partitions, partition):
count, tid_checksum, max_tid = self.query('SELECT COUNT(*), ' count, tid_checksum, max_tid = self.query(
'MD5(GROUP_CONCAT(tid SEPARATOR ",")), MAX(tid) FROM (' """SELECT COUNT(*), MD5(GROUP_CONCAT(tid SEPARATOR ",")), MAX(tid)
'SELECT tid FROM trans ' FROM (SELECT tid FROM trans
'WHERE partition = %(partition)s ' WHERE partition = %(partition)s
'AND tid >= %(min_tid)d ' AND tid >= %(min_tid)d
'AND tid <= %(max_tid)d ' AND tid <= %(max_tid)d
'ORDER BY tid ASC LIMIT %(length)d' ORDER BY tid ASC LIMIT %(length)d) AS t""" % {
') AS foo' % { 'partition': partition,
'partition': partition, 'min_tid': util.u64(min_tid),
'min_tid': util.u64(min_tid), 'max_tid': util.u64(max_tid),
'max_tid': util.u64(max_tid), 'length': length,
'length': length,
})[0] })[0]
if count == 0: if count == 0:
max_tid = ZERO_TID max_tid = ZERO_TID
...@@ -835,28 +836,29 @@ class MySQLDatabaseManager(DatabaseManager): ...@@ -835,28 +836,29 @@ class MySQLDatabaseManager(DatabaseManager):
def checkSerialRange(self, min_oid, min_serial, max_tid, length, def checkSerialRange(self, min_oid, min_serial, max_tid, length,
num_partitions, partition): num_partitions, partition):
u64 = util.u64 u64 = util.u64
count, oid_checksum, max_oid, serial_checksum, max_serial = self.query( # We don't ask MySQL to compute everything (like in checkTIDRange)
"""SELECT COUNT(*), MD5(GROUP_CONCAT(oid SEPARATOR ",")), MAX(oid), # because it's difficult to get the last serial _for the last oid_.
MD5(GROUP_CONCAT(serial SEPARATOR ",")), MAX(serial) # 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 FROM obj_short
WHERE partition = %(partition)s WHERE partition = %(partition)s
AND serial <= %(max_tid)d AND serial <= %(max_tid)d
AND (oid > %(min_oid)d OR AND (oid > %(min_oid)d OR
oid = %(min_oid)d AND serial >= %(min_serial)d) oid = %(min_oid)d AND serial >= %(min_serial)d)
ORDER BY oid ASC, serial ASC LIMIT %(length)d""" % { ORDER BY oid ASC, serial ASC LIMIT %(length)d""" % {
'min_oid': u64(min_oid), 'min_oid': u64(min_oid),
'min_serial': u64(min_serial), 'min_serial': u64(min_serial),
'max_tid': u64(max_tid), 'max_tid': u64(max_tid),
'length': length, 'length': length,
'partition': partition, 'partition': partition,
})[0] })
if count: if r:
oid_checksum = a2b_hex(oid_checksum) p64 = util.p64
serial_checksum = a2b_hex(serial_checksum) return (len(r),
max_oid = util.p64(max_oid) md5(','.join(str(x[0]) for x in r)).digest(),
max_serial = util.p64(max_serial) p64(r[-1][0]),
else: md5(','.join(str(x[1]) for x in r)).digest(),
max_oid = ZERO_OID p64(r[-1][1]))
max_serial = ZERO_TID return 0, None, ZERO_OID, None, ZERO_TID
return count, oid_checksum, max_oid, serial_checksum, max_serial
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