Commit 395c6df8 authored by Grégory Wisniewski's avatar Grégory Wisniewski

Drop unassigned partitions in one database query.

git-svn-id: https://svn.erp5.org/repos/neo/trunk@2100 71dcc9de-d417-0410-9af5-da40c76e7ee4
parent 2f1e2a07
......@@ -216,10 +216,8 @@ class DatabaseManager(object):
thrown away."""
raise NotImplementedError
def dropForeignPartitions(self, num_partitions, offset):
""" Drop objects and transactions assigned to a partition table,
this should be called only during storage initialization, to clear
existing data that could be stored by a previous cluster life """
def dropPartitions(self, num_partitions, offset_list):
""" Drop any data of non-assigned partitions for a given UUID """
raise NotImplementedError('this method must be overriden')
def dropUnfinishedData(self):
......
......@@ -394,14 +394,16 @@ class MySQLDatabaseManager(DatabaseManager):
def setPartitionTable(self, ptid, cell_list):
self.doSetPartitionTable(ptid, cell_list, True)
def dropPartition(self, num_partitions, offset):
def dropPartitions(self, num_partitions, offset_list):
q = self.query
e = self.escape
offset_list = ', '.join((str(i) for i in offset_list))
self.begin()
try:
q("""DELETE FROM obj WHERE MOD(oid, %d) = %d""" %
(num_partitions, offset))
q("""DELETE FROM trans WHERE MOD(tid, %d) = %d""" %
(num_partitions, offset))
q("""DELETE FROM obj WHERE MOD(oid, %d) IN (%s)""" %
(num_partitions, offset_list))
q("""DELETE FROM trans WHERE MOD(tid, %d) IN (%s)""" %
(num_partitions, offset_list))
except:
self.rollback()
raise
......
......@@ -44,16 +44,18 @@ class InitializationHandler(BaseMasterHandler):
self.app.pt.log()
# Install the partition table into the database for persistency.
cell_list = []
for offset in xrange(app.pt.getPartitions()):
assigned_to_me = False
num_partitions = app.pt.getPartitions()
assigned_set = set()
for offset in xrange(num_partitions):
for cell in pt.getCellList(offset):
cell_list.append((offset, cell.getUUID(), cell.getState()))
if cell.getUUID() == app.uuid:
assigned_to_me = True
if not assigned_to_me:
logging.debug('drop data for partition %d' % offset)
# not for me, delete objects database
app.dm.dropPartition(app.pt.getPartitions(), offset)
assigned_set.add(offset)
# delete objects database
unassigned_set = list(set(xrange(num_partitions)) - assigned_set)
if unassigned_set:
logging.debug('drop data for partitions %r' % unassigned_set)
app.dm.dropPartitions(num_partitions, unassigned_set)
app.dm.setPartitionTable(ptid, cell_list)
self.app.has_partition_table = True
......
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