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