Commit bd03b14b authored by Julien Muchembled's avatar Julien Muchembled

storage: refactoring & cleanup

- _[gs]etPackTID accessors implementation is not backend-specific
  so move them to superclass
- _getObjectLength method is useless since data_tid always contains the wanted
  information, regardless the contents of value_tid column
parent d63e45d3
...@@ -149,6 +149,15 @@ class DatabaseManager(object): ...@@ -149,6 +149,15 @@ class DatabaseManager(object):
logging.debug('backup_tid = %s', tid) logging.debug('backup_tid = %s', tid)
return self.setConfiguration('backup_tid', tid) return self.setConfiguration('backup_tid', tid)
def _setPackTID(self, tid):
self._setConfiguration('_pack_tid', tid)
def _getPackTID(self):
try:
return int(self.getConfiguration('_pack_tid'))
except TypeError:
return -1
def getPartitionTable(self): def getPartitionTable(self):
"""Return a whole partition table as a sequence of rows. Each row """Return a whole partition table as a sequence of rows. Each row
is again a tuple of an offset (row ID), the NID of a storage is again a tuple of an offset (row ID), the NID of a storage
......
...@@ -244,15 +244,6 @@ class MySQLDatabaseManager(DatabaseManager): ...@@ -244,15 +244,6 @@ class MySQLDatabaseManager(DatabaseManager):
value = e(str(value)) value = e(str(value))
q("REPLACE INTO config VALUES ('%s', '%s')" % (key, value)) q("REPLACE INTO config VALUES ('%s', '%s')" % (key, value))
def _setPackTID(self, tid):
self._setConfiguration('_pack_tid', tid)
def _getPackTID(self):
try:
return int(self.getConfiguration('_pack_tid'))
except TypeError:
return -1
def getPartitionTable(self): def getPartitionTable(self):
return self.query("SELECT * FROM pt") return self.query("SELECT * FROM pt")
...@@ -531,45 +522,19 @@ class MySQLDatabaseManager(DatabaseManager): ...@@ -531,45 +522,19 @@ class MySQLDatabaseManager(DatabaseManager):
oid_list = splitOIDField(tid, oids) oid_list = splitOIDField(tid, oids)
return oid_list, user, desc, ext, bool(packed), util.p64(ttid) return oid_list, user, desc, ext, bool(packed), util.p64(ttid)
def _getObjectLength(self, oid, value_serial):
if value_serial is None:
raise CreationUndone
r = self.query("""SELECT LENGTH(value), value_tid
FROM obj LEFT JOIN data ON (obj.data_id = data.id)
WHERE partition = %d AND oid = %d AND tid = %d""" %
(self._getPartition(oid), oid, value_serial))
length, value_serial = r[0]
if length is None:
logging.info("Multiple levels of indirection when "
"searching for object data for oid %d at tid %d."
" This causes suboptimal performance.", oid, value_serial)
length = self._getObjectLength(oid, value_serial)
return length
def getObjectHistory(self, oid, offset = 0, length = 1): def getObjectHistory(self, oid, offset = 0, length = 1):
# FIXME: This method doesn't take client's current ransaction id as # FIXME: This method doesn't take client's current ransaction id as
# parameter, which means it can return transactions in the future of # parameter, which means it can return transactions in the future of
# client's transaction. # client's transaction.
oid = util.u64(oid) oid = util.u64(oid)
p64 = util.p64 p64 = util.p64
pack_tid = self._getPackTID() r = self.query("""SELECT tid, LENGTH(value)
r = self.query("""SELECT tid, LENGTH(value), value_tid
FROM obj LEFT JOIN data ON (obj.data_id = data.id) FROM obj LEFT JOIN data ON (obj.data_id = data.id)
WHERE partition = %d AND oid = %d AND tid >= %d WHERE partition = %d AND oid = %d AND tid >= %d
ORDER BY tid DESC LIMIT %d, %d""" \ ORDER BY tid DESC LIMIT %d, %d""" %
% (self._getPartition(oid), oid, pack_tid, offset, length)) (self._getPartition(oid), oid, self._getPackTID(), offset, length))
if r: if r:
result = [] return [(p64(tid), length or 0) for tid, length in r]
append = result.append
for serial, length, value_serial in r:
if length is None:
try:
length = self._getObjectLength(oid, value_serial)
except CreationUndone:
length = 0
append((p64(serial), length))
return result
return None
def getReplicationObjectList(self, min_tid, max_tid, length, partition, def getReplicationObjectList(self, min_tid, max_tid, length, partition,
min_oid): min_oid):
......
...@@ -206,15 +206,6 @@ class SQLiteDatabaseManager(DatabaseManager): ...@@ -206,15 +206,6 @@ class SQLiteDatabaseManager(DatabaseManager):
else: else:
q("REPLACE INTO config VALUES (?,?)", (key, str(value))) q("REPLACE INTO config VALUES (?,?)", (key, str(value)))
def _setPackTID(self, tid):
self._setConfiguration('_pack_tid', tid)
def _getPackTID(self):
try:
return int(self.getConfiguration('_pack_tid'))
except TypeError:
return -1
def getPartitionTable(self): def getPartitionTable(self):
return self.query("SELECT * FROM pt") return self.query("SELECT * FROM pt")
...@@ -482,42 +473,19 @@ class SQLiteDatabaseManager(DatabaseManager): ...@@ -482,42 +473,19 @@ class SQLiteDatabaseManager(DatabaseManager):
return splitOIDField(tid, oids), str(user), \ return splitOIDField(tid, oids), str(user), \
str(description), str(ext), packed, util.p64(ttid) str(description), str(ext), packed, util.p64(ttid)
def _getObjectLength(self, oid, value_serial):
if value_serial is None:
raise CreationUndone
length, value_serial = self.query("""SELECT LENGTH(value), value_tid
FROM obj LEFT JOIN data ON obj.data_id=data.id
WHERE partition=? AND oid=? AND tid=?""",
(self._getPartition(oid), oid, value_serial)).fetchone()
if length is None:
logging.info("Multiple levels of indirection"
" when searching for object data for oid %d at tid %d."
" This causes suboptimal performance.", oid, value_serial)
length = self._getObjectLength(oid, value_serial)
return length
def getObjectHistory(self, oid, offset=0, length=1): def getObjectHistory(self, oid, offset=0, length=1):
# FIXME: This method doesn't take client's current transaction id as # FIXME: This method doesn't take client's current transaction id as
# parameter, which means it can return transactions in the future of # parameter, which means it can return transactions in the future of
# client's transaction. # client's transaction.
p64 = util.p64 p64 = util.p64
oid = util.u64(oid) oid = util.u64(oid)
pack_tid = self._getPackTID() return [(p64(tid), length or 0) for tid, length in self.query("""\
result = [] SELECT tid, LENGTH(value)
append = result.append
for serial, length, value_serial in self.query("""\
SELECT tid, LENGTH(value), value_tid
FROM obj LEFT JOIN data ON obj.data_id = data.id FROM obj LEFT JOIN data ON obj.data_id = data.id
WHERE partition=? AND oid=? AND tid>=? WHERE partition=? AND oid=? AND tid>=?
ORDER BY tid DESC LIMIT ?,?""", ORDER BY tid DESC LIMIT ?,?""",
(self._getPartition(oid), oid, pack_tid, offset, length)): (self._getPartition(oid), oid, self._getPackTID(), offset, length))
if length is None: ] or None
try:
length = self._getObjectLength(oid, value_serial)
except CreationUndone:
length = 0
append((p64(serial), length))
return result or None
def getReplicationObjectList(self, min_tid, max_tid, length, partition, def getReplicationObjectList(self, min_tid, max_tid, length, partition,
min_oid): min_oid):
......
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