Commit 05136a48 authored by Grégory Wisniewski's avatar Grégory Wisniewski

Move getPartition to manager and make it private.

git-svn-id: https://svn.erp5.org/repos/neo/trunk@2324 71dcc9de-d417-0410-9af5-da40c76e7ee4
parent ebc270d9
...@@ -72,6 +72,9 @@ class DatabaseManager(object): ...@@ -72,6 +72,9 @@ class DatabaseManager(object):
def _rollback(self): def _rollback(self):
raise NotImplementedError raise NotImplementedError
def _getPartition(self, oid_or_tid):
return oid_or_tid % self.getNumPartitions()
def getConfiguration(self, key): def getConfiguration(self, key):
""" """
Return a configuration value, returns None if not found or not set Return a configuration value, returns None if not found or not set
......
...@@ -50,9 +50,6 @@ class MySQLDatabaseManager(DatabaseManager): ...@@ -50,9 +50,6 @@ class MySQLDatabaseManager(DatabaseManager):
self._config = {} self._config = {}
self._connect() self._connect()
def getPartition(self, oid_or_tid):
return oid_or_tid % self.getNumPartitions()
def _parse(self, database): def _parse(self, database):
""" Get the database credentials (username, password, database) """ """ Get the database credentials (username, password, database) """
# expected pattern : [user[:password]@]database # expected pattern : [user[:password]@]database
...@@ -279,7 +276,7 @@ class MySQLDatabaseManager(DatabaseManager): ...@@ -279,7 +276,7 @@ class MySQLDatabaseManager(DatabaseManager):
q = self.query q = self.query
oid = util.u64(oid) oid = util.u64(oid)
tid = util.u64(tid) tid = util.u64(tid)
partition = self.getPartition(oid) partition = self._getPartition(oid)
self.begin() self.begin()
r = q("SELECT oid FROM obj WHERE partition=%d AND oid=%d AND serial=%d" r = q("SELECT oid FROM obj WHERE partition=%d AND oid=%d AND serial=%d"
% (partition, oid, tid)) % (partition, oid, tid))
...@@ -311,7 +308,7 @@ class MySQLDatabaseManager(DatabaseManager): ...@@ -311,7 +308,7 @@ 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
partition = self.getPartition(oid) partition = self._getPartition(oid)
if tid is not None: if tid is not None:
r = q("""SELECT serial, compression, checksum, value, value_serial r = q("""SELECT serial, compression, checksum, value, value_serial
FROM obj FROM obj
...@@ -445,7 +442,7 @@ class MySQLDatabaseManager(DatabaseManager): ...@@ -445,7 +442,7 @@ class MySQLDatabaseManager(DatabaseManager):
value_serial = 'NULL' value_serial = 'NULL'
else: else:
value_serial = '%d' % (u64(value_serial), ) value_serial = '%d' % (u64(value_serial), )
partition = self.getPartition(oid) partition = self._getPartition(oid)
q("""REPLACE INTO %s VALUES (%d, %d, %d, %s, %s, %s, %s)""" \ q("""REPLACE INTO %s VALUES (%d, %d, %d, %s, %s, %s, %s)""" \
% (obj_table, partition, oid, tid, compression, checksum, % (obj_table, partition, oid, tid, compression, checksum,
data, value_serial)) data, value_serial))
...@@ -457,7 +454,7 @@ class MySQLDatabaseManager(DatabaseManager): ...@@ -457,7 +454,7 @@ class MySQLDatabaseManager(DatabaseManager):
user = e(user) user = e(user)
desc = e(desc) desc = e(desc)
ext = e(ext) ext = e(ext)
partition = self.getPartition(tid) partition = self._getPartition(tid)
q("REPLACE INTO %s VALUES (%d, %d, %i, '%s', '%s', '%s', '%s')" q("REPLACE INTO %s VALUES (%d, %d, %i, '%s', '%s', '%s', '%s')"
% (trans_table, partition, tid, packed, oids, user, desc, % (trans_table, partition, tid, packed, oids, user, desc,
ext)) ext))
...@@ -505,13 +502,13 @@ class MySQLDatabaseManager(DatabaseManager): ...@@ -505,13 +502,13 @@ class MySQLDatabaseManager(DatabaseManager):
q = self.query q = self.query
u64 = util.u64 u64 = util.u64
tid = u64(tid) tid = u64(tid)
getPartition = self.getPartition getPartition = self._getPartition
self.begin() self.begin()
try: try:
q("""DELETE FROM tobj WHERE serial = %d""" % tid) q("""DELETE FROM tobj WHERE serial = %d""" % tid)
q("""DELETE FROM ttrans WHERE tid = %d""" % tid) q("""DELETE FROM ttrans WHERE tid = %d""" % tid)
q("""DELETE FROM trans WHERE partition = %d AND tid = %d""" % q("""DELETE FROM trans WHERE partition = %d AND tid = %d""" %
(self.getPartition(tid), tid)) (getPartition(tid), tid))
# delete from obj using indexes # delete from obj using indexes
for oid in oid_list: for oid in oid_list:
oid = u64(oid) oid = u64(oid)
...@@ -531,7 +528,7 @@ class MySQLDatabaseManager(DatabaseManager): ...@@ -531,7 +528,7 @@ class MySQLDatabaseManager(DatabaseManager):
u64 = util.u64 u64 = util.u64
oid = u64(oid) oid = u64(oid)
query_param_dict = { query_param_dict = {
'partition': self.getPartition(oid), 'partition': self._getPartition(oid),
'oid': oid, 'oid': oid,
} }
query_fmt = """DELETE FROM obj WHERE partition = %(partition)d query_fmt = """DELETE FROM obj WHERE partition = %(partition)d
...@@ -553,7 +550,7 @@ class MySQLDatabaseManager(DatabaseManager): ...@@ -553,7 +550,7 @@ class MySQLDatabaseManager(DatabaseManager):
self.begin() self.begin()
r = q("""SELECT oids, user, description, ext, packed FROM trans r = q("""SELECT oids, user, description, ext, packed FROM trans
WHERE partition = %d AND tid = %d""" \ WHERE partition = %d AND tid = %d""" \
% (self.getPartition(tid), tid)) % (self._getPartition(tid), tid))
if not r and all: if not r and all:
r = q("""SELECT oids, user, description, ext, packed FROM ttrans r = q("""SELECT oids, user, description, ext, packed FROM ttrans
WHERE tid = %d""" \ WHERE tid = %d""" \
...@@ -570,7 +567,7 @@ class MySQLDatabaseManager(DatabaseManager): ...@@ -570,7 +567,7 @@ class MySQLDatabaseManager(DatabaseManager):
raise CreationUndone raise CreationUndone
r = self.query("""SELECT LENGTH(value), value_serial FROM obj """ \ r = self.query("""SELECT LENGTH(value), value_serial FROM obj """ \
"""WHERE partition = %d AND oid = %d AND serial = %d""" % """WHERE partition = %d AND oid = %d AND serial = %d""" %
(self.getPartition(oid), oid, value_serial)) (self._getPartition(oid), oid, value_serial))
length, value_serial = r[0] length, value_serial = r[0]
if length is None: if length is None:
logging.info("Multiple levels of indirection when " \ logging.info("Multiple levels of indirection when " \
...@@ -590,7 +587,7 @@ class MySQLDatabaseManager(DatabaseManager): ...@@ -590,7 +587,7 @@ class MySQLDatabaseManager(DatabaseManager):
r = q("""SELECT serial, LENGTH(value), value_serial FROM obj r = q("""SELECT serial, LENGTH(value), value_serial FROM obj
WHERE partition = %d AND oid = %d AND serial >= %d WHERE partition = %d AND oid = %d AND serial >= %d
ORDER BY serial DESC LIMIT %d, %d""" \ ORDER BY serial DESC LIMIT %d, %d""" \
% (self.getPartition(oid), oid, pack_tid, offset, length)) % (self._getPartition(oid), oid, pack_tid, offset, length))
if r: if r:
result = [] result = []
append = result.append append = result.append
...@@ -662,7 +659,7 @@ class MySQLDatabaseManager(DatabaseManager): ...@@ -662,7 +659,7 @@ class MySQLDatabaseManager(DatabaseManager):
updateObjectDataForPack): updateObjectDataForPack):
q = self.query q = self.query
p64 = util.p64 p64 = util.p64
getPartition = self.getPartition getPartition = self._getPartition
# Before deleting this objects revision, see if there is any # Before deleting this objects revision, see if there is any
# transaction referencing its value at max_serial or above. # transaction referencing its value at max_serial or above.
# If there is, copy value to the first future transaction. Any further # If there is, copy value to the first future transaction. Any further
...@@ -724,7 +721,7 @@ class MySQLDatabaseManager(DatabaseManager): ...@@ -724,7 +721,7 @@ class MySQLDatabaseManager(DatabaseManager):
q = self.query q = self.query
tid = util.u64(tid) tid = util.u64(tid)
updatePackFuture = self._updatePackFuture updatePackFuture = self._updatePackFuture
getPartition = self.getPartition getPartition = self._getPartition
self.begin() self.begin()
try: try:
self._setPackTID(tid) self._setPackTID(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