Commit 745ee2b2 authored by Julien Muchembled's avatar Julien Muchembled

storage: skip useless work when unlocking transactions

parent 67df59ad
...@@ -828,7 +828,7 @@ class DatabaseManager(object): ...@@ -828,7 +828,7 @@ class DatabaseManager(object):
""" """
@abstract @abstract
def unlockTransaction(self, tid, ttid): def unlockTransaction(self, tid, ttid, trans, obj):
"""Finalize a transaction by moving data to a finished area.""" """Finalize a transaction by moving data to a finished area."""
@abstract @abstract
......
...@@ -705,18 +705,21 @@ class MySQLDatabaseManager(DatabaseManager): ...@@ -705,18 +705,21 @@ class MySQLDatabaseManager(DatabaseManager):
% (u64(tid), u64(ttid))) % (u64(tid), u64(ttid)))
self.commit() self.commit()
def unlockTransaction(self, tid, ttid): def unlockTransaction(self, tid, ttid, trans, obj):
q = self.query q = self.query
u64 = util.u64 u64 = util.u64
tid = u64(tid) tid = u64(tid)
if trans:
q("INSERT INTO trans SELECT * FROM ttrans WHERE tid=%d" % tid)
q("DELETE FROM ttrans WHERE tid=%d" % tid)
if not obj:
return
sql = " FROM tobj WHERE tid=%d" % u64(ttid) sql = " FROM tobj WHERE tid=%d" % u64(ttid)
data_id_list = [x for x, in q("SELECT data_id%s AND data_id IS NOT NULL" data_id_list = [x for x, in q("SELECT data_id%s AND data_id IS NOT NULL"
% sql)] % sql)]
q("INSERT INTO obj SELECT `partition`, oid, %d, data_id, value_tid %s" q("INSERT INTO obj SELECT `partition`, oid, %d, data_id, value_tid %s"
% (tid, sql)) % (tid, sql))
q("DELETE" + sql) q("DELETE" + sql)
q("INSERT INTO trans SELECT * FROM ttrans WHERE tid=%d" % tid)
q("DELETE FROM ttrans WHERE tid=%d" % tid)
self.releaseData(data_id_list) self.releaseData(data_id_list)
def abortTransaction(self, ttid): def abortTransaction(self, ttid):
......
...@@ -470,10 +470,15 @@ class SQLiteDatabaseManager(DatabaseManager): ...@@ -470,10 +470,15 @@ class SQLiteDatabaseManager(DatabaseManager):
(u64(tid), u64(ttid))) (u64(tid), u64(ttid)))
self.commit() self.commit()
def unlockTransaction(self, tid, ttid): def unlockTransaction(self, tid, ttid, trans, obj):
q = self.query q = self.query
u64 = util.u64 u64 = util.u64
tid = u64(tid) tid = u64(tid)
if trans:
q("INSERT INTO trans SELECT * FROM ttrans WHERE tid=?", (tid,))
q("DELETE FROM ttrans WHERE tid=?", (tid,))
if not obj:
return
ttid = u64(ttid) ttid = u64(ttid)
sql = " FROM tobj WHERE tid=?" sql = " FROM tobj WHERE tid=?"
data_id_list = [x for x, in q("SELECT data_id%s AND data_id IS NOT NULL" data_id_list = [x for x, in q("SELECT data_id%s AND data_id IS NOT NULL"
...@@ -481,8 +486,6 @@ class SQLiteDatabaseManager(DatabaseManager): ...@@ -481,8 +486,6 @@ class SQLiteDatabaseManager(DatabaseManager):
q("INSERT INTO obj SELECT partition, oid, ?, data_id, value_tid" + sql, q("INSERT INTO obj SELECT partition, oid, ?, data_id, value_tid" + sql,
(tid, ttid)) (tid, ttid))
q("DELETE" + sql, (ttid,)) q("DELETE" + sql, (ttid,))
q("INSERT INTO trans SELECT * FROM ttrans WHERE tid=?", (tid,))
q("DELETE FROM ttrans WHERE tid=?", (tid,))
self.releaseData(data_id_list) self.releaseData(data_id_list)
def abortTransaction(self, ttid): def abortTransaction(self, ttid):
......
...@@ -77,7 +77,7 @@ class InitializationHandler(BaseMasterHandler): ...@@ -77,7 +77,7 @@ class InitializationHandler(BaseMasterHandler):
def validateTransaction(self, conn, ttid, tid): def validateTransaction(self, conn, ttid, tid):
dm = self.app.dm dm = self.app.dm
dm.lockTransaction(tid, ttid) dm.lockTransaction(tid, ttid)
dm.unlockTransaction(tid, ttid) dm.unlockTransaction(tid, ttid, True, True)
dm.commit() dm.commit()
def startOperation(self, conn, backup): def startOperation(self, conn, backup):
......
...@@ -314,12 +314,15 @@ class TransactionManager(EventQueue): ...@@ -314,12 +314,15 @@ class TransactionManager(EventQueue):
Unlock transaction Unlock transaction
""" """
try: try:
tid = self._transaction_dict[ttid].tid transaction = self._transaction_dict[ttid]
except KeyError: except KeyError:
raise ProtocolError("unknown ttid %s" % dump(ttid)) raise ProtocolError("unknown ttid %s" % dump(ttid))
tid = transaction.tid
logging.debug('Unlock TXN %s (ttid=%s)', dump(tid), dump(ttid)) logging.debug('Unlock TXN %s (ttid=%s)', dump(tid), dump(ttid))
dm = self._app.dm dm = self._app.dm
dm.unlockTransaction(tid, ttid) dm.unlockTransaction(tid, ttid,
transaction.voted == 2,
transaction.store_dict)
self._app.em.setTimeout(time() + 1, dm.deferCommit()) self._app.em.setTimeout(time() + 1, dm.deferCommit())
self.abort(ttid, even_if_locked=True) self.abort(ttid, even_if_locked=True)
......
...@@ -89,7 +89,7 @@ class StorageDBTests(NeoUnitTestBase): ...@@ -89,7 +89,7 @@ class StorageDBTests(NeoUnitTestBase):
self.db.lockTransaction(tid, ttid) self.db.lockTransaction(tid, ttid)
yield yield
if commit: if commit:
self.db.unlockTransaction(tid, ttid) self.db.unlockTransaction(tid, ttid, True, objs)
self.db.commit() self.db.commit()
elif commit is not None: elif commit is not None:
self.db.abortTransaction(ttid) self.db.abortTransaction(ttid)
......
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