Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Per @jimfulton, handle_all_serials shouldn't be sniffing in ZODB5 #87

Merged
merged 3 commits into from
Jul 12, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 4 additions & 8 deletions src/ZODB/tests/BasicStorage.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
from ZODB import POSException
from ZODB.tests.MinPO import MinPO
from ZODB.tests.StorageTestBase import zodb_unpickle, zodb_pickle
from ZODB.tests.StorageTestBase import handle_serials

import threading
import time
Expand Down Expand Up @@ -68,13 +67,10 @@ def checkSerialIsNoneForInitialRevision(self):
self._storage.tpc_begin(txn)
# Use None for serial. Don't use _dostore() here because that coerces
# serial=None to serial=ZERO.
r1 = self._storage.store(oid, None, zodb_pickle(MinPO(11)),
'', txn)
r2 = self._storage.tpc_vote(txn)
serial = self._storage.tpc_finish(txn)
newrevid = handle_serials(oid, r1, r2)
if newrevid is None and serial is not None:
newrevid = serial
self._storage.store(oid, None, zodb_pickle(MinPO(11)),
'', txn)
self._storage.tpc_vote(txn)
newrevid = self._storage.tpc_finish(txn)
data, revid = utils.load_current(self._storage, oid)
value = zodb_unpickle(data)
eq(value, MinPO(11))
Expand Down
11 changes: 3 additions & 8 deletions src/ZODB/tests/MTStorage.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@

import ZODB
from ZODB.tests.StorageTestBase import zodb_pickle, zodb_unpickle
from ZODB.tests.StorageTestBase import handle_serials
from ZODB.tests.MinPO import MinPO
from ZODB.POSException import ConflictError

Expand Down Expand Up @@ -149,18 +148,14 @@ def dostore(self, i):
self.pause()

# Always create a new object, signified by None for revid
r1 = self.storage.store(oid, None, data, '', t)
self.storage.store(oid, None, data, '', t)
self.pause()

r2 = self.storage.tpc_vote(t)
self.storage.tpc_vote(t)
self.pause()

serial = self.storage.tpc_finish(t)
revid = self.storage.tpc_finish(t)
self.pause()

revid = handle_serials(oid, r1, r2)
if serial is not None and revid is None:
revid = serial
self.oids[oid] = revid

class ExtStorageClientThread(StorageClientThread):
Expand Down
10 changes: 3 additions & 7 deletions src/ZODB/tests/RevisionStorage.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@

from ZODB.tests.MinPO import MinPO
from ZODB.tests.StorageTestBase import zodb_unpickle, zodb_pickle, snooze
from ZODB.tests.StorageTestBase import handle_serials
from ZODB.utils import p64, u64, load_current

import transaction
Expand Down Expand Up @@ -146,16 +145,13 @@ def helper(tid, revid, x):
t = transaction.Transaction()
try:
self._storage.tpc_begin(t, p64(tid))
r1 = self._storage.store(oid, revid, data, '', t)
self._storage.store(oid, revid, data, '', t)
# Finish the transaction
r2 = self._storage.tpc_vote(t)
newrevid = handle_serials(oid, r1, r2)
serial = self._storage.tpc_finish(t)
self._storage.tpc_vote(t)
newrevid = self._storage.tpc_finish(t)
except:
self._storage.tpc_abort(t)
raise
if serial is not None and newrevid is None:
newrevid = serial
return newrevid
revid1 = helper(1, None, 1)
revid2 = helper(2, revid1, 2)
Expand Down
44 changes: 1 addition & 43 deletions src/ZODB/tests/StorageTestBase.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,45 +101,6 @@ def zodb_unpickle(data):
inst.__setstate__(state)
return inst

def handle_all_serials(oid, *args):
"""Return dict of oid to serialno from store() and tpc_vote().

Raises an exception if one of the calls raised an exception.

The storage interface got complicated when ZEO was introduced.
Any individual store() call can return None or a sequence of
2-tuples where the 2-tuple is either oid, serialno or an
exception to be raised by the client.

The original interface just returned the serialno for the
object.

The updated multi-commit API returns nothing from store(), and
returns a sequence of resolved oids from tpc_vote.
"""
d = {}
for arg in args:
if isinstance(arg, bytes):
d[oid] = arg
elif arg:
for t in arg:
if isinstance(t, bytes):
# This will be the tid returned by tpc_finish.
pass
else:
oid, serial = t
if not isinstance(serial, bytes):
raise serial # error from ZEO server
d[oid] = serial
return d

def handle_serials(oid, *args):
"""Return the serialno for oid based on multiple return values.

A helper for function _handle_all_serials().
"""
return handle_all_serials(oid, *args).get(oid)

def import_helper(name):
__import__(name)
return sys.modules[name]
Expand Down Expand Up @@ -194,10 +155,7 @@ def _dostore(self, oid=None, revid=None, data=None,
r1 = self._storage.store(oid, revid, data, '', t)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't use r1 and r2, so why assign them?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was trying to make the diff as minimal as possible. I can clean that up.

# Finish the transaction
r2 = self._storage.tpc_vote(t)
revid = handle_serials(oid, r1, r2)
serial = self._storage.tpc_finish(t)
if serial is not None and revid is None:
revid = serial
revid = self._storage.tpc_finish(t)
except:
self._storage.tpc_abort(t)
raise
Expand Down