Skip to content

Commit

Permalink
Merge pull request #31 from jimfulton/fix-lastTransaction
Browse files Browse the repository at this point in the history
Update to work with ZODB5.
  • Loading branch information
jimfulton committed Jun 9, 2016
2 parents 9dacfa5 + 24f79da commit 9b62af6
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 24 deletions.
20 changes: 1 addition & 19 deletions relstorage/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,30 +34,12 @@ def patch_zodb_sync():
"""Patch Connection.sync() and afterCompletion() to pass the 'force' flag.
"""

def _storage_sync(self, *ignored, **kw):
if hasattr(self, '_readCurrent'):
self._readCurrent.clear()
sync = getattr(self._storage, 'sync', 0)
if sync:
# By default, do not force the sync, allowing RelStorage
# to ignore sync requests for a while.
force = kw.get('force', False)
try:
sync(force=force)
except TypeError:
# The 'force' parameter is not accepted.
sync()
self._flush_invalidations()

def sync(self):
"""Manually update the view on the database."""
self._storage.sync(force=True)
self.transaction_manager.abort()
self._storage_sync(force=True)

from ZODB.Connection import Connection
Connection._storage_sync = _storage_sync
Connection.afterCompletion = _storage_sync
Connection.newTransaction = _storage_sync
Connection.sync = sync

patch_zodb_sync()
4 changes: 2 additions & 2 deletions relstorage/storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -957,7 +957,7 @@ def _abort(self):
def lastTransaction(self):
self._lock_acquire()
try:
return self._ltid
return max(self._ltid, p64(self._prev_polled_tid or 0))
finally:
self._lock_release()

Expand Down Expand Up @@ -1203,7 +1203,7 @@ def _pack_finished(self):
def iterator(self, start=None, stop=None):
return TransactionIterator(self._adapter, start, stop)

def sync(self, force=True):
def sync(self, force=False):
"""Updates to a current view of the database.
This is implemented by rolling back the relational database
Expand Down
8 changes: 6 additions & 2 deletions relstorage/tests/blob/testblob.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

from ZODB.blob import Blob
from ZODB.DB import DB
from zope.testing import doctest
import doctest

import atexit
import collections
Expand Down Expand Up @@ -437,7 +437,11 @@ def loadblob_tmpstore():
... tmpstore = TmpStore(blob_storage)
... except TypeError:
... # ZODB 3.8
... tmpstore = TmpStore('', blob_storage)
... try:
... tmpstore = TmpStore('', blob_storage)
... except AttributeError:
... # ZODB >=5
... tmpstore = TmpStore(blob_storage, connection._txn_time)
We can access the blob correctly:
Expand Down
7 changes: 6 additions & 1 deletion relstorage/tests/reltestbase.py
Original file line number Diff line number Diff line change
Expand Up @@ -410,7 +410,12 @@ def checkPollInterval(self, shared_cache=True):
self.assertFalse(c2._storage.need_poll())
tm2.commit()
r2 = c2.root()
self.assertEqual(r2['alpha'], 1)
try:
self.assertEqual(r2['alpha'], 1)
except AssertionError:
if hasattr(c1, '_flush_invalidations'):
# Only fail with ZODB <5
raise

# expire the poll timer and verify c2 sees the change
c2._storage._poll_at -= 3601
Expand Down

0 comments on commit 9b62af6

Please sign in to comment.