Commit 1f307db2 authored by Grégory Wisniewski's avatar Grégory Wisniewski

Move u64()/p64() method definitions out of mysqldb adapter implementation.

git-svn-id: https://svn.erp5.org/repos/neo/trunk@1387 71dcc9de-d417-0410-9af5-da40c76e7ee4
parent 44ad4b80
...@@ -30,12 +30,6 @@ from neo import util ...@@ -30,12 +30,6 @@ from neo import util
LOG_QUERIES = False LOG_QUERIES = False
def p64(n):
return pack('!Q', n)
def u64(s):
return unpack('!Q', s)[0]
class MySQLDatabaseManager(DatabaseManager): class MySQLDatabaseManager(DatabaseManager):
"""This class manages a database on MySQL.""" """This class manages a database on MySQL."""
...@@ -222,7 +216,7 @@ class MySQLDatabaseManager(DatabaseManager): ...@@ -222,7 +216,7 @@ class MySQLDatabaseManager(DatabaseManager):
ltid = tmp_serial ltid = tmp_serial
self.commit() self.commit()
if ltid is not None: if ltid is not None:
ltid = p64(ltid) ltid = util.p64(ltid)
return ltid return ltid
def getUnfinishedTIDList(self): def getUnfinishedTIDList(self):
...@@ -230,16 +224,16 @@ class MySQLDatabaseManager(DatabaseManager): ...@@ -230,16 +224,16 @@ class MySQLDatabaseManager(DatabaseManager):
tid_set = set() tid_set = set()
self.begin() self.begin()
r = q("""SELECT tid FROM ttrans""") r = q("""SELECT tid FROM ttrans""")
tid_set.update((p64(t[0]) for t in r)) tid_set.update((util.p64(t[0]) for t in r))
r = q("""SELECT serial FROM tobj""") r = q("""SELECT serial FROM tobj""")
self.commit() self.commit()
tid_set.update((p64(t[0]) for t in r)) tid_set.update((util.p64(t[0]) for t in r))
return list(tid_set) return list(tid_set)
def objectPresent(self, oid, tid, all = True): def objectPresent(self, oid, tid, all = True):
q = self.query q = self.query
oid = u64(oid) oid = util.u64(oid)
tid = u64(tid) tid = util.u64(tid)
self.begin() self.begin()
r = q("""SELECT oid FROM obj WHERE oid = %d AND serial = %d""" \ r = q("""SELECT oid FROM obj WHERE oid = %d AND serial = %d""" \
% (oid, tid)) % (oid, tid))
...@@ -253,9 +247,9 @@ class MySQLDatabaseManager(DatabaseManager): ...@@ -253,9 +247,9 @@ class MySQLDatabaseManager(DatabaseManager):
def getObject(self, oid, tid = None, before_tid = None): def getObject(self, oid, tid = None, before_tid = None):
q = self.query q = self.query
oid = u64(oid) oid = util.u64(oid)
if tid is not None: if tid is not None:
tid = u64(tid) tid = util.u64(tid)
r = q("""SELECT serial, compression, checksum, value FROM obj r = q("""SELECT serial, compression, checksum, value FROM obj
WHERE oid = %d AND serial = %d""" \ WHERE oid = %d AND serial = %d""" \
% (oid, tid)) % (oid, tid))
...@@ -265,7 +259,7 @@ class MySQLDatabaseManager(DatabaseManager): ...@@ -265,7 +259,7 @@ class MySQLDatabaseManager(DatabaseManager):
except IndexError: except IndexError:
return None return None
elif before_tid is not None: elif before_tid is not None:
before_tid = u64(before_tid) before_tid = util.u64(before_tid)
r = q("""SELECT serial, compression, checksum, value FROM obj r = q("""SELECT serial, compression, checksum, value FROM obj
WHERE oid = %d AND serial < %d WHERE oid = %d AND serial < %d
ORDER BY serial DESC LIMIT 1""" \ ORDER BY serial DESC LIMIT 1""" \
...@@ -295,9 +289,9 @@ class MySQLDatabaseManager(DatabaseManager): ...@@ -295,9 +289,9 @@ class MySQLDatabaseManager(DatabaseManager):
return None return None
if serial is not None: if serial is not None:
serial = p64(serial) serial = util.p64(serial)
if next_serial is not None: if next_serial is not None:
next_serial = p64(next_serial) next_serial = util.p64(next_serial)
return serial, next_serial, compression, checksum, data return serial, next_serial, compression, checksum, data
def doSetPartitionTable(self, ptid, cell_list, reset): def doSetPartitionTable(self, ptid, cell_list, reset):
...@@ -355,7 +349,7 @@ class MySQLDatabaseManager(DatabaseManager): ...@@ -355,7 +349,7 @@ class MySQLDatabaseManager(DatabaseManager):
def storeTransaction(self, tid, object_list, transaction, temporary = True): def storeTransaction(self, tid, object_list, transaction, temporary = True):
q = self.query q = self.query
e = self.escape e = self.escape
tid = u64(tid) tid = util.u64(tid)
if temporary: if temporary:
obj_table = 'tobj' obj_table = 'tobj'
...@@ -367,7 +361,7 @@ class MySQLDatabaseManager(DatabaseManager): ...@@ -367,7 +361,7 @@ class MySQLDatabaseManager(DatabaseManager):
self.begin() self.begin()
try: try:
for oid, compression, checksum, data in object_list: for oid, compression, checksum, data in object_list:
oid = u64(oid) oid = util.u64(oid)
data = e(data) data = e(data)
q("""REPLACE INTO %s VALUES (%d, %d, %d, %d, '%s')""" \ q("""REPLACE INTO %s VALUES (%d, %d, %d, %d, '%s')""" \
% (obj_table, oid, tid, compression, checksum, data)) % (obj_table, oid, tid, compression, checksum, data))
...@@ -386,7 +380,7 @@ class MySQLDatabaseManager(DatabaseManager): ...@@ -386,7 +380,7 @@ class MySQLDatabaseManager(DatabaseManager):
def finishTransaction(self, tid): def finishTransaction(self, tid):
q = self.query q = self.query
tid = u64(tid) tid = util.u64(tid)
self.begin() self.begin()
try: try:
q("""INSERT INTO obj SELECT * FROM tobj WHERE tobj.serial = %d""" \ q("""INSERT INTO obj SELECT * FROM tobj WHERE tobj.serial = %d""" \
...@@ -402,7 +396,7 @@ class MySQLDatabaseManager(DatabaseManager): ...@@ -402,7 +396,7 @@ class MySQLDatabaseManager(DatabaseManager):
def deleteTransaction(self, tid, all = False): def deleteTransaction(self, tid, all = False):
q = self.query q = self.query
tid = u64(tid) tid = util.u64(tid)
self.begin() self.begin()
try: try:
q("""DELETE FROM tobj WHERE serial = %d""" % tid) q("""DELETE FROM tobj WHERE serial = %d""" % tid)
...@@ -418,7 +412,7 @@ class MySQLDatabaseManager(DatabaseManager): ...@@ -418,7 +412,7 @@ class MySQLDatabaseManager(DatabaseManager):
def getTransaction(self, tid, all = False): def getTransaction(self, tid, all = False):
q = self.query q = self.query
tid = u64(tid) tid = util.u64(tid)
self.begin() self.begin()
r = q("""SELECT oids, user, description, ext FROM trans r = q("""SELECT oids, user, description, ext FROM trans
WHERE tid = %d""" \ WHERE tid = %d""" \
...@@ -444,16 +438,16 @@ class MySQLDatabaseManager(DatabaseManager): ...@@ -444,16 +438,16 @@ class MySQLDatabaseManager(DatabaseManager):
ORDER BY oid DESC LIMIT %d,%d""" \ ORDER BY oid DESC LIMIT %d,%d""" \
% (num_partitions, ','.join([str(p) for p in partition_list]), % (num_partitions, ','.join([str(p) for p in partition_list]),
offset, length)) offset, length))
return [p64(t[0]) for t in r] return [util.p64(t[0]) for t in r]
def getObjectHistory(self, oid, offset = 0, length = 1): def getObjectHistory(self, oid, offset = 0, length = 1):
q = self.query q = self.query
oid = u64(oid) oid = util.u64(oid)
r = q("""SELECT serial, LENGTH(value) FROM obj WHERE oid = %d r = q("""SELECT serial, LENGTH(value) FROM obj WHERE oid = %d
ORDER BY serial DESC LIMIT %d, %d""" \ ORDER BY serial DESC LIMIT %d, %d""" \
% (oid, offset, length)) % (oid, offset, length))
if r: if r:
return [(p64(serial), length) for serial, length in r] return [(util.p64(serial), length) for serial, length in r]
return None return None
def getTIDList(self, offset, length, num_partitions, partition_list): def getTIDList(self, offset, length, num_partitions, partition_list):
...@@ -463,18 +457,18 @@ class MySQLDatabaseManager(DatabaseManager): ...@@ -463,18 +457,18 @@ class MySQLDatabaseManager(DatabaseManager):
% (num_partitions, % (num_partitions,
','.join([str(p) for p in partition_list]), ','.join([str(p) for p in partition_list]),
offset, length)) offset, length))
return [p64(t[0]) for t in r] return [util.p64(t[0]) for t in r]
def getTIDListPresent(self, tid_list): def getTIDListPresent(self, tid_list):
q = self.query q = self.query
r = q("""SELECT tid FROM trans WHERE tid in (%s)""" \ r = q("""SELECT tid FROM trans WHERE tid in (%s)""" \
% ','.join([str(u64(tid)) for tid in tid_list])) % ','.join([str(util.u64(tid)) for tid in tid_list]))
return [p64(t[0]) for t in r] return [util.p64(t[0]) for t in r]
def getSerialListPresent(self, oid, serial_list): def getSerialListPresent(self, oid, serial_list):
q = self.query q = self.query
oid = u64(oid) oid = util.u64(oid)
r = q("""SELECT serial FROM obj WHERE oid = %d AND serial in (%s)""" \ r = q("""SELECT serial FROM obj WHERE oid = %d AND serial in (%s)""" \
% (oid, ','.join([str(u64(serial)) for serial in serial_list]))) % (oid, ','.join([str(util.u64(serial)) for serial in serial_list])))
return [p64(t[0]) for t in r] return [util.p64(t[0]) for t in r]
...@@ -19,7 +19,7 @@ import unittest ...@@ -19,7 +19,7 @@ import unittest
from mock import Mock from mock import Mock
from neo.tests import NeoTestBase from neo.tests import NeoTestBase
from neo.master.app import Application from neo.master.app import Application
from neo.storage.mysqldb import p64, u64 from neo.util import p64, u64
class MasterAppTests(NeoTestBase): class MasterAppTests(NeoTestBase):
......
...@@ -20,11 +20,11 @@ import unittest ...@@ -20,11 +20,11 @@ import unittest
from neo import logging from neo import logging
import MySQLdb import MySQLdb
from mock import Mock from mock import Mock
from neo.util import dump from neo.util import dump, p64, u64
from neo.protocol import CellStates, INVALID_PTID from neo.protocol import CellStates, INVALID_PTID
from neo.tests import NeoTestBase from neo.tests import NeoTestBase
from neo.exception import DatabaseFailure from neo.exception import DatabaseFailure
from neo.storage.mysqldb import MySQLDatabaseManager, p64, u64 from neo.storage.database.mysqldb import MySQLDatabaseManager
NEO_SQL_DATABASE = 'test_mysqldb0' NEO_SQL_DATABASE = 'test_mysqldb0'
NEO_SQL_USER = 'test' NEO_SQL_USER = 'test'
......
...@@ -24,7 +24,7 @@ from neo.storage.handlers.verification import VerificationHandler ...@@ -24,7 +24,7 @@ from neo.storage.handlers.verification import VerificationHandler
from neo.protocol import Packet, Packets, CellStates, ErrorCodes from neo.protocol import Packet, Packets, CellStates, ErrorCodes
from neo.protocol import INVALID_OID, INVALID_TID from neo.protocol import INVALID_OID, INVALID_TID
from neo.exception import PrimaryFailure, OperationFailure from neo.exception import PrimaryFailure, OperationFailure
from neo.storage.mysqldb import p64, u64 from neo.util import p64, u64
class StorageVerificationHandlerTests(NeoTestBase): class StorageVerificationHandlerTests(NeoTestBase):
......
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