Commit 1d11287f authored by Julien Muchembled's avatar Julien Muchembled

storage: more refactoring of backends

parent e76af297
......@@ -244,17 +244,12 @@ class DatabaseManager(object):
# See if object exists at all
return self._getObject(oid) and False
def changePartitionTable(self, ptid, cell_list):
def changePartitionTable(self, ptid, cell_list, reset=False):
"""Change a part of a partition table. The list of cells is
a tuple of tuples, each of which consists of an offset (row ID),
the NID of a storage node, and a cell state. The Partition
Table ID must be stored as well."""
raise NotImplementedError
def setPartitionTable(self, ptid, cell_list):
"""Set a whole partition table. The semantics is the same as
changePartitionTable, except that existing data must be
thrown away."""
Table ID must be stored as well. If reset is True, existing data
is first thrown away."""
raise NotImplementedError
def dropPartitions(self, offset_list):
......
......@@ -306,7 +306,7 @@ class MySQLDatabaseManager(DatabaseManager):
return (serial, r[0][0] if r else None, compression, checksum, data,
value_serial)
def doSetPartitionTable(self, ptid, cell_list, reset):
def changePartitionTable(self, ptid, cell_list, reset=False):
offset_list = []
q = self.query
if reset:
......@@ -334,12 +334,6 @@ class MySQLDatabaseManager(DatabaseManager):
if code != 1517: # duplicate partition name
raise
def changePartitionTable(self, ptid, cell_list):
self.doSetPartitionTable(ptid, cell_list, False)
def setPartitionTable(self, ptid, cell_list):
self.doSetPartitionTable(ptid, cell_list, True)
def dropPartitions(self, offset_list):
q = self.query
# XXX: these queries are inefficient (execution time increase with
......
......@@ -271,7 +271,7 @@ class SQLiteDatabaseManager(DatabaseManager):
data = str(data)
return serial, r and r[0], compression, checksum, data, value_serial
def doSetPartitionTable(self, ptid, cell_list, reset):
def changePartitionTable(self, ptid, cell_list, reset=False):
q = self.query
if reset:
q("DELETE FROM pt")
......@@ -288,12 +288,6 @@ class SQLiteDatabaseManager(DatabaseManager):
(offset, nid, int(state)))
self.setPTID(ptid)
def changePartitionTable(self, ptid, cell_list):
self.doSetPartitionTable(ptid, cell_list, False)
def setPartitionTable(self, ptid, cell_list):
self.doSetPartitionTable(ptid, cell_list, True)
def dropPartitions(self, offset_list):
where = " WHERE partition=?"
q = self.query
......
......@@ -44,7 +44,7 @@ class InitializationHandler(BaseMasterHandler):
logging.debug('drop data for partitions %r', unassigned_set)
app.dm.dropPartitions(unassigned_set)
app.dm.setPartitionTable(ptid, cell_list)
app.dm.changePartitionTable(ptid, cell_list, reset=True)
def notifyPartitionChanges(self, conn, ptid, cell_list):
# XXX: This is safe to ignore those notifications because all of the
......
......@@ -68,8 +68,9 @@ class StorageDBTests(NeoUnitTestBase):
uuid = self.getStorageUUID()
db.setUUID(uuid)
self.assertEqual(uuid, db.getUUID())
db.setPartitionTable(1,
[(i, uuid, CellStates.UP_TO_DATE) for i in xrange(num_partitions)])
db.changePartitionTable(1,
[(i, uuid, CellStates.UP_TO_DATE) for i in xrange(num_partitions)],
reset=True)
def checkConfigEntry(self, get_call, set_call, value):
# generic test for all configuration entries accessors
......@@ -97,7 +98,7 @@ class StorageDBTests(NeoUnitTestBase):
uuid1, uuid2 = self.getStorageUUID(), self.getStorageUUID()
cell1 = (0, uuid1, CellStates.OUT_OF_DATE)
cell2 = (1, uuid1, CellStates.UP_TO_DATE)
db.setPartitionTable(ptid, [cell1, cell2])
db.changePartitionTable(ptid, [cell1, cell2], 1)
result = db.getPartitionTable()
self.assertEqual(set(result), {cell1, cell2})
......@@ -225,15 +226,15 @@ class StorageDBTests(NeoUnitTestBase):
# no partition table
self.assertEqual(list(db.getPartitionTable()), [])
# set one
db.setPartitionTable(ptid, [cell1])
db.changePartitionTable(ptid, [cell1], 1)
result = db.getPartitionTable()
self.assertEqual(list(result), [cell1])
# then another
db.setPartitionTable(ptid, [cell2])
db.changePartitionTable(ptid, [cell2], 1)
result = db.getPartitionTable()
self.assertEqual(list(result), [cell2])
# drop discarded cells
db.setPartitionTable(ptid, [cell2, cell3])
db.changePartitionTable(ptid, [cell2, cell3], 1)
result = db.getPartitionTable()
self.assertEqual(list(result), [])
......
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