From cf962262c2466f146064deda926fff4a04109daa Mon Sep 17 00:00:00 2001 From: Jim Fulton Date: Tue, 17 May 2016 13:32:18 -0400 Subject: [PATCH 1/4] Make lastTransaction accurate By reflecting information gaind when polling. This is important because https://github.com/zopefoundation/ZODB/pull/56/files depends on a working lastTransaction method to set transaction start times. --- relstorage/storage.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/relstorage/storage.py b/relstorage/storage.py index 1072b3e1..9561bda0 100644 --- a/relstorage/storage.py +++ b/relstorage/storage.py @@ -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() From 5e8607a94457cdc1a29f0d0ee135d214e33592b8 Mon Sep 17 00:00:00 2001 From: Jim Fulton Date: Tue, 17 May 2016 13:34:14 -0400 Subject: [PATCH 2/4] Use standard doctest, as it's not in zope.testing any more. --- relstorage/tests/blob/testblob.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/relstorage/tests/blob/testblob.py b/relstorage/tests/blob/testblob.py index 063f1c28..39bf2fd0 100644 --- a/relstorage/tests/blob/testblob.py +++ b/relstorage/tests/blob/testblob.py @@ -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 From 689a07529696211a47e8cdd17f2bbd903b699189 Mon Sep 17 00:00:00 2001 From: Jim Fulton Date: Tue, 17 May 2016 15:09:44 -0400 Subject: [PATCH 3/4] More changes to work with ZODB 5 - Change default for storage sync force to False. - Reduced ths monkey patch in relstorage.__init__.py to work with current ZODB and with ZODB 5. - Changed a test that tested for delayed polling to ignore non-delay under ZODB 5. --- relstorage/__init__.py | 20 +------------------- relstorage/storage.py | 2 +- relstorage/tests/reltestbase.py | 7 ++++++- 3 files changed, 8 insertions(+), 21 deletions(-) diff --git a/relstorage/__init__.py b/relstorage/__init__.py index 1805b0af..0af8608c 100644 --- a/relstorage/__init__.py +++ b/relstorage/__init__.py @@ -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() diff --git a/relstorage/storage.py b/relstorage/storage.py index 9561bda0..3f78a1df 100644 --- a/relstorage/storage.py +++ b/relstorage/storage.py @@ -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 diff --git a/relstorage/tests/reltestbase.py b/relstorage/tests/reltestbase.py index 55166c8b..e0d08848 100644 --- a/relstorage/tests/reltestbase.py +++ b/relstorage/tests/reltestbase.py @@ -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 From 24f79da5c0783b271bec515f14e608a383e940f5 Mon Sep 17 00:00:00 2001 From: Jim Fulton Date: Tue, 17 May 2016 15:10:44 -0400 Subject: [PATCH 4/4] Work with ZODB5. The constructor signature for TmpStore changed again. (It's private, dang it.) --- relstorage/tests/blob/testblob.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/relstorage/tests/blob/testblob.py b/relstorage/tests/blob/testblob.py index 39bf2fd0..56e612c1 100644 --- a/relstorage/tests/blob/testblob.py +++ b/relstorage/tests/blob/testblob.py @@ -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: