Skip to content

Commit

Permalink
Changed loadBefore to operate more like load behaved, especially
Browse files Browse the repository at this point in the history
  with regard to the load lock.  This allowes ZEO to work with the
  upcoming ZODB 5, which used loadbefore rather than load.

  Reimplemented load using loadBefore, this testing loadBefore
  extensively via existing tests.
  • Loading branch information
Jim Fulton committed Jun 6, 2016
1 parent ec370c8 commit c5e6574
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 63 deletions.
9 changes: 9 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,15 @@ Changelog
4.2.0 (unreleased)
------------------

- Changed loadBefore to operate more like load behaved, especially
with regard to the load lock. This allowes ZEO to work with the
upcoming ZODB 5, which used loadbefore rather than load.

Reimplemented load using loadBefore, this testing loadBefore
extensively via existing tests.

- Fixed: the ZEO cache loadBefore method failed to utilize current data.

- Drop support for Python 2.6 and 3.2.

4.2.0b1 (2015-06-05)
Expand Down
85 changes: 25 additions & 60 deletions src/ZEO/ClientStorage.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,9 @@

logger = logging.getLogger(__name__)

# max signed 64-bit value ~ infinity :) Signed cuz LBTree and TimeStamp
m64 = b'\x7f\xff\xff\xff\xff\xff\xff\xff'

try:
from ZODB.ConflictResolution import ResolvedSerial
except ImportError:
Expand Down Expand Up @@ -819,75 +822,37 @@ def load(self, oid, version=''):
otherwise a KeyError is raised.
"""
self._lock.acquire() # for atomic processing of invalidations
try:
t = self._cache.load(oid)
if t:
return t
finally:
self._lock.release()
result = self.loadBefore(oid, m64)
if result is None:
raise POSException.POSKeyError(oid)
return result[:2]

def loadBefore(self, oid, tid):
"""Load the object data written before a transaction id
"""
with self._lock: # for atomic processing of invalidations
result = self._cache.loadBefore(oid, tid)
if result:
return result

if self._server is None:
raise ClientDisconnected()

self._load_lock.acquire()
try:
self._lock.acquire()
try:
with self._load_lock:
with self._lock:
self._load_oid = oid
self._load_status = 1
finally:
self._lock.release()

data, tid = self._server.loadEx(oid)

self._lock.acquire() # for atomic processing of invalidations
try:
if self._load_status:
self._cache.store(oid, tid, None, data)
self._load_oid = None
finally:
self._lock.release()
finally:
self._load_lock.release()

return data, tid
result = self._server.loadBefore(oid, tid)

def loadBefore(self, oid, tid):
self._lock.acquire()
try:
t = self._cache.loadBefore(oid, tid)
if t is not None:
return t
finally:
self._lock.release()

t = self._server.loadBefore(oid, tid)
if t is None:
return None
data, start, end = t
if end is None:
# This method should not be used to get current data. It
# doesn't use the _load_lock, so it is possble to overlap
# this load with an invalidation for the same object.

# If we call again, we're guaranteed to get the
# post-invalidation data. But if the data is still
# current, we'll still get end == None.

# Maybe the best thing to do is to re-run the test with
# the load lock in the case. That's slow performance, but
# I don't think real application code will ever care about
# it.

return data, start, end
self._lock.acquire()
try:
self._cache.store(oid, start, end, data)
finally:
self._lock.release()
if result:
with self._lock: # for atomic processing of invalidations
if self._load_status:
data, tid, end = result
self._cache.store(oid, tid, end, data)
self._load_oid = None

return data, start, end
return result

def new_oid(self):
"""Storage API: return a new object identifier."""
Expand Down
11 changes: 8 additions & 3 deletions src/ZEO/zrpc/connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -242,19 +242,24 @@ class Connection(smac.SizedMessageAsyncConnection, object):
# Undone oid info returned by vote.
#
# Z3101 -- checkCurrentSerialInTransaction
#
# Z4 -- checkCurrentSerialInTransaction
# No-longer call load.

# Protocol variables:
# Our preferred protocol.
current_protocol = b"Z3101"
current_protocol = b"Z4"

# If we're a client, an exhaustive list of the server protocols we
# can accept.
servers_we_can_talk_to = [b"Z308", b"Z309", b"Z310", current_protocol]
servers_we_can_talk_to = [b"Z308", b"Z309", b"Z310", b"Z3101",
current_protocol]

# If we're a server, an exhaustive list of the client protocols we
# can accept.
clients_we_can_talk_to = [
b"Z200", b"Z201", b"Z303", b"Z308", b"Z309", b"Z310", current_protocol]
b"Z200", b"Z201", b"Z303", b"Z308", b"Z309", b"Z310", b"Z3101",
current_protocol]

# This is pretty excruciating. Details:
#
Expand Down

0 comments on commit c5e6574

Please sign in to comment.