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

Drop unassigned partitions in one database query.

git-svn-id: 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))
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))
......@@ -44,16 +44,18 @@ class InitializationHandler(BaseMasterHandler):
# Install the partition table into the database for persistency.
cell_list = []
for offset in xrange(
assigned_to_me = False
num_partitions =
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, 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), unassigned_set), cell_list) = 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