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

storage: more refactoring of backends

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