Commit 52c5d862 authored by Julien Muchembled's avatar Julien Muchembled

storage: fix severe performance issue by committing backend only at key moments

parent 4741e38e
...@@ -15,7 +15,6 @@ ...@@ -15,7 +15,6 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>. # along with this program. If not, see <http://www.gnu.org/licenses/>.
from neo.lib import logging, util from neo.lib import logging, util
from neo.lib.exception import DatabaseFailure
from neo.lib.protocol import ZERO_TID from neo.lib.protocol import ZERO_TID
class CreationUndone(Exception): class CreationUndone(Exception):
...@@ -28,7 +27,6 @@ class DatabaseManager(object): ...@@ -28,7 +27,6 @@ class DatabaseManager(object):
""" """
Initialize the object. Initialize the object.
""" """
self._under_transaction = False
self._wait = wait self._wait = wait
self._parse(database) self._parse(database)
...@@ -50,34 +48,9 @@ class DatabaseManager(object): ...@@ -50,34 +48,9 @@ class DatabaseManager(object):
""" """
raise NotImplementedError raise NotImplementedError
def __enter__(self):
"""
Begin a transaction
"""
if self._under_transaction:
raise DatabaseFailure('A transaction has already begun')
r = self.begin()
self._under_transaction = True
return r
def __exit__(self, exc_type, exc_value, tb):
if not self._under_transaction:
raise DatabaseFailure('The transaction has not begun')
self._under_transaction = False
if exc_type is None:
self.commit()
else:
self.rollback()
def begin(self):
pass
def commit(self): def commit(self):
pass pass
def rollback(self):
pass
def _getPartition(self, oid_or_tid): def _getPartition(self, oid_or_tid):
return oid_or_tid % self.getNumPartitions() return oid_or_tid % self.getNumPartitions()
...@@ -91,11 +64,8 @@ class DatabaseManager(object): ...@@ -91,11 +64,8 @@ class DatabaseManager(object):
""" """
Set a configuration value Set a configuration value
""" """
if self._under_transaction: self._setConfiguration(key, value)
self._setConfiguration(key, value) self.commit()
else:
with self:
self._setConfiguration(key, value)
def _setConfiguration(self, key, value): def _setConfiguration(self, key, value):
raise NotImplementedError raise NotImplementedError
...@@ -344,8 +314,8 @@ class DatabaseManager(object): ...@@ -344,8 +314,8 @@ class DatabaseManager(object):
else: else:
del refcount[data_id] del refcount[data_id]
if prune: if prune:
with self: self._pruneData(data_id_list)
self._pruneData(data_id_list) self.commit()
__getDataTID = set() __getDataTID = set()
def _getDataTID(self, oid, tid=None, before_tid=None): def _getDataTID(self, oid, tid=None, before_tid=None):
...@@ -465,11 +435,11 @@ class DatabaseManager(object): ...@@ -465,11 +435,11 @@ class DatabaseManager(object):
def truncate(self, tid): def truncate(self, tid):
assert tid not in (None, ZERO_TID), tid assert tid not in (None, ZERO_TID), tid
with self: assert self.getBackupTID()
assert self.getBackupTID() self.setBackupTID(tid)
self.setBackupTID(tid) for partition in xrange(self.getNumPartitions()):
for partition in xrange(self.getNumPartitions()): self._deleteRange(partition, tid)
self._deleteRange(partition, tid) self.commit()
def getTransaction(self, tid, all = False): def getTransaction(self, tid, all = False):
"""Return a tuple of the list of OIDs, user information, """Return a tuple of the list of OIDs, user information,
......
This diff is collapsed.
This diff is collapsed.
...@@ -98,6 +98,7 @@ class StorageOperationHandler(EventHandler): ...@@ -98,6 +98,7 @@ class StorageOperationHandler(EventHandler):
for serial, oid_list in object_dict.iteritems(): for serial, oid_list in object_dict.iteritems():
for oid in oid_list: for oid in oid_list:
deleteObject(oid, serial) deleteObject(oid, serial)
self.app.dm.commit()
assert not pack_tid, "TODO" assert not pack_tid, "TODO"
if next_tid: if next_tid:
self.app.replicator.fetchObjects(next_tid, next_oid) self.app.replicator.fetchObjects(next_tid, next_oid)
......
...@@ -20,7 +20,6 @@ from mock import Mock ...@@ -20,7 +20,6 @@ from mock import Mock
from neo.lib.util import add64, dump, p64, u64 from neo.lib.util import add64, dump, p64, u64
from neo.lib.protocol import CellStates, ZERO_HASH, ZERO_OID, ZERO_TID, MAX_TID from neo.lib.protocol import CellStates, ZERO_HASH, ZERO_OID, ZERO_TID, MAX_TID
from .. import NeoUnitTestBase from .. import NeoUnitTestBase
from neo.lib.exception import DatabaseFailure
class StorageDBTests(NeoUnitTestBase): class StorageDBTests(NeoUnitTestBase):
...@@ -93,29 +92,6 @@ class StorageDBTests(NeoUnitTestBase): ...@@ -93,29 +92,6 @@ class StorageDBTests(NeoUnitTestBase):
db = self.getDB() db = self.getDB()
self.checkConfigEntry(db.getPTID, db.setPTID, self.getPTID(1)) self.checkConfigEntry(db.getPTID, db.setPTID, self.getPTID(1))
def test_transaction(self):
db = self.getDB()
x = []
class DB(db.__class__):
begin = lambda self: x.append('begin')
commit = lambda self: x.append('commit')
rollback = lambda self: x.append('rollback')
db.__class__ = DB
with db:
self.assertEqual(x.pop(), 'begin')
self.assertEqual(x.pop(), 'commit')
try:
with db:
self.assertEqual(x.pop(), 'begin')
with db:
self.fail()
self.fail()
except DatabaseFailure:
pass
self.assertEqual(x.pop(), 'rollback')
self.assertRaises(DatabaseFailure, db.__exit__, None, None, None)
self.assertFalse(x)
def test_getPartitionTable(self): def test_getPartitionTable(self):
db = self.getDB() db = self.getDB()
ptid = self.getPTID(1) ptid = self.getPTID(1)
......
...@@ -300,11 +300,11 @@ class StorageApplication(ServerNode, neo.storage.app.Application): ...@@ -300,11 +300,11 @@ class StorageApplication(ServerNode, neo.storage.app.Application):
pass pass
def switchTables(self): def switchTables(self):
with self.dm as q: q = self.dm.query
for table in ('trans', 'obj'): for table in 'trans', 'obj':
q('ALTER TABLE %s RENAME TO tmp' % table) q('ALTER TABLE %s RENAME TO tmp' % table)
q('ALTER TABLE t%s RENAME TO %s' % (table, table)) q('ALTER TABLE t%s RENAME TO %s' % (table, table))
q('ALTER TABLE tmp RENAME TO t%s' % table) q('ALTER TABLE tmp RENAME TO t%s' % table)
def getDataLockInfo(self): def getDataLockInfo(self):
dm = self.dm dm = self.dm
......
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