Commit 37948381 authored by Vincent Pelletier's avatar Vincent Pelletier

Always hold load lock when loading (even non-current).

Also, move cache look-up to its own method, with an API consistent with
_loadFromStorage.

git-svn-id: https://svn.erp5.org/repos/neo/trunk@2489 71dcc9de-d417-0410-9af5-da40c76e7ee4
parent 61f8777d
......@@ -493,12 +493,21 @@ class Application(object):
# TODO:
# - rename parameters (here and in handlers & packet definitions)
self._load_lock_acquire()
try:
# Once per transaction, upon first load, trigger a barrier so we
# handle all pending invalidations, so the snapshot of the database is
# as up-to-date as possible.
# handle all pending invalidations, so the snapshot of the database
# is as up-to-date as possible.
if not self.local_var.barrier_done:
self.invalidationBarrier()
self.local_var.barrier_done = True
if cache:
try:
result = self._loadFromCache(oid, serial, tid)
except KeyError:
pass
else:
return result
data, start_serial, end_serial = self._loadFromStorage(oid, serial,
tid)
if cache:
......@@ -510,6 +519,8 @@ class Application(object):
if data == '':
raise NEOStorageCreationUndoneError(dump(oid))
return data, start_serial, end_serial
finally:
self._load_lock_release()
@profiler_decorator
def _loadFromStorage(self, oid, at_tid, before_tid):
......@@ -567,25 +578,22 @@ class Application(object):
data = decompress(data)
return data, tid, next_tid
@profiler_decorator
def load(self, oid, version=None):
"""Load an object for a given oid."""
# First try from cache
self._load_lock_acquire()
try:
def _loadFromCache(self, oid, at_tid, before_tid):
"""
Load from local cache, raising KeyError if not found.
"""
self._cache_lock_acquire()
try:
try:
serial, data = self.mq_cache[oid]
except KeyError:
pass
else:
tid, data = self.mq_cache[oid]
neo.logging.debug('load oid %s is cached', dump(oid))
return data, serial
return (data, tid, None)
finally:
self._cache_lock_release()
# Otherwise get it from storage node
@profiler_decorator
def load(self, oid, version=None):
"""Load an object for a given oid."""
result = self._load(oid, cache=1)[:2]
# Start a network barrier, so we get all invalidations *after* we
# received data. This ensures we get any invalidation message that
......@@ -596,9 +604,6 @@ class Application(object):
# XXX: A better implementation is required to improve performances
self.invalidationBarrier()
return result
finally:
self._load_lock_release()
@profiler_decorator
def loadSerial(self, oid, serial):
......
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