Commit bd03b14b by 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
1 parent d63e45d3
......@@ -149,6 +149,15 @@ class DatabaseManager(object):
logging.debug('backup_tid = %s', 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):
"""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
......
......@@ -244,15 +244,6 @@ class MySQLDatabaseManager(DatabaseManager):
value = e(str(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):
return self.query("SELECT * FROM pt")
......@@ -531,45 +522,19 @@ class MySQLDatabaseManager(DatabaseManager):
oid_list = splitOIDField(tid, oids)
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):
# FIXME: This method doesn't take client's current ransaction id as
# parameter, which means it can return transactions in the future of
# client's transaction.
oid = util.u64(oid)
p64 = util.p64
pack_tid = self._getPackTID()
r = self.query("""SELECT tid, LENGTH(value), value_tid
r = self.query("""SELECT tid, LENGTH(value)
FROM obj LEFT JOIN data ON (obj.data_id = data.id)
WHERE partition = %d AND oid = %d AND tid >= %d
ORDER BY tid DESC LIMIT %d, %d""" \
% (self._getPartition(oid), oid, pack_tid, offset, length))
ORDER BY tid DESC LIMIT %d, %d""" %
(self._getPartition(oid), oid, self._getPackTID(), offset, length))
if r:
result = []
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
return [(p64(tid), length or 0) for tid, length in r]
def getReplicationObjectList(self, min_tid, max_tid, length, partition,
min_oid):
......
......@@ -206,15 +206,6 @@ class SQLiteDatabaseManager(DatabaseManager):
else:
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):
return self.query("SELECT * FROM pt")
......@@ -482,42 +473,19 @@ class SQLiteDatabaseManager(DatabaseManager):
return splitOIDField(tid, oids), str(user), \
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):
# FIXME: This method doesn't take client's current transaction id as
# parameter, which means it can return transactions in the future of
# client's transaction.
p64 = util.p64
oid = util.u64(oid)
pack_tid = self._getPackTID()
result = []
append = result.append
for serial, length, value_serial in self.query("""\
SELECT tid, LENGTH(value), value_tid
return [(p64(tid), length or 0) for tid, length in self.query("""\
SELECT tid, LENGTH(value)
FROM obj LEFT JOIN data ON obj.data_id = data.id
WHERE partition=? AND oid=? AND tid>=?
ORDER BY tid DESC LIMIT ?,?""",
(self._getPartition(oid), oid, pack_tid, offset, length)):
if length is None:
try:
length = self._getObjectLength(oid, value_serial)
except CreationUndone:
length = 0
append((p64(serial), length))
return result or None
(self._getPartition(oid), oid, self._getPackTID(), offset, length))
] or None
def getReplicationObjectList(self, min_tid, max_tid, length, partition,
min_oid):
......
Styling with Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!