Skip to content

Commit

Permalink
Lots of changes to work with newly persnickity transactions
Browse files Browse the repository at this point in the history
  • Loading branch information
Jim Fulton committed Nov 15, 2016
1 parent 32c8436 commit 539e5f8
Show file tree
Hide file tree
Showing 14 changed files with 45 additions and 42 deletions.
4 changes: 2 additions & 2 deletions doc/guide/transactions-and-threading.rst
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ statement. Transaction managers are context managers, so we can use
them with the ``with`` statement directly::

with my_transaction_manager as trans:
trans.note("incrementing x")
trans.note(u"incrementing x")
conn.root.x += 1

.. -> src
Expand Down Expand Up @@ -181,7 +181,7 @@ So, for example, if we wanted to set a transaction note::


with db.transaction() as conn2:
conn2.transaction_manager.get().note("incrementing x again")
conn2.transaction_manager.get().note(u"incrementing x again")
conn2.root.x += 1

.. -> src
Expand Down
2 changes: 1 addition & 1 deletion src/ZODB/Connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -1286,7 +1286,7 @@ def __repr__(self):
size.
"""

class TransactionMetaData:
class TransactionMetaData(object):

def __init__(self, user=u'', description=u'', extension=b''):
self.user = user
Expand Down
2 changes: 1 addition & 1 deletion src/ZODB/DB.py
Original file line number Diff line number Diff line change
Expand Up @@ -469,7 +469,7 @@ def __init__(self,
self.large_record_size = large_record_size

# Make sure we have a root:
with self.transaction('initial database creation') as conn:
with self.transaction(u'initial database creation') as conn:
try:
conn.get(z64)
except KeyError:
Expand Down
2 changes: 1 addition & 1 deletion src/ZODB/tests/BasicStorage.py
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ def checkNote(self):
oid = self._storage.new_oid()
t = TransactionMetaData()
self._storage.tpc_begin(t)
t.note('this is a test')
t.note(u'this is a test')
self._storage.store(oid, ZERO, zodb_pickle(MinPO(5)), '', t)
self._storage.tpc_vote(t)
self._storage.tpc_finish(t)
Expand Down
10 changes: 5 additions & 5 deletions src/ZODB/tests/PackableStorage.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ def _initroot(self):
p.dump((PersistentMapping, None))
p.dump({'_container': {}})
t=Transaction()
t.description='initial database creation'
t.description = u'initial database creation'
self._storage.tpc_begin(t)
self._storage.store(ZERO, None, file.getvalue(), '', t)
self._storage.tpc_vote(t)
Expand Down Expand Up @@ -575,7 +575,7 @@ def checkPackUnlinkedFromRoot(self):
root = conn.root()

txn = transaction.get()
txn.note('root')
txn.note(u'root')
txn.commit()

now = packtime = time.time()
Expand All @@ -587,12 +587,12 @@ def checkPackUnlinkedFromRoot(self):

root['obj'] = obj
txn = transaction.get()
txn.note('root -> o1')
txn.note(u'root -> o1')
txn.commit()

del root['obj']
txn = transaction.get()
txn.note('root -x-> o1')
txn.note(u'root -x-> o1')
txn.commit()

self._storage.pack(packtime, referencesf)
Expand All @@ -601,7 +601,7 @@ def checkPackUnlinkedFromRoot(self):
tid = log[0]['id']
db.undo(tid)
txn = transaction.get()
txn.note('undo root -x-> o1')
txn.note(u'undo root -x-> o1')
txn.commit()

conn.sync()
Expand Down
6 changes: 3 additions & 3 deletions src/ZODB/tests/RecoveryStorage.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,15 +73,15 @@ def checkPackWithGCOnDestinationAfterRestore(self):
root = conn.root()
root.obj = obj1 = MinPO(1)
txn = transaction.get()
txn.note('root -> obj')
txn.note(u'root -> obj')
txn.commit()
root.obj.obj = obj2 = MinPO(2)
txn = transaction.get()
txn.note('root -> obj -> obj')
txn.note(u'root -> obj -> obj')
txn.commit()
del root.obj
txn = transaction.get()
txn.note('root -X->')
txn.note(u'root -X->')
txn.commit()
# Now copy the transactions to the destination
self._dst.copyTransactionsFrom(self._storage)
Expand Down
2 changes: 1 addition & 1 deletion src/ZODB/tests/StorageTestBase.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ def _undo(self, tid, expected_oids=None, note=None):
# Undo a tid that affects a single object (oid).
# This is very specialized.
t = TransactionMetaData()
t.note(note or "undo")
t.note(note or u"undo")
self._storage.tpc_begin(t)
undo_result = self._storage.undo(tid, t)
vote_result = self._storage.tpc_vote(t)
Expand Down
27 changes: 15 additions & 12 deletions src/ZODB/tests/TransactionalUndoStorage.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
"""
import time

from six import PY3

from persistent import Persistent
import transaction
from transaction import Transaction
Expand Down Expand Up @@ -412,7 +414,7 @@ def checkTransactionalUndoAfterPackWithObjectUnlinkFromRoot(self):
root['obj'] = o1
o1.obj = o2
txn = transaction.get()
txn.note('o1 -> o2')
txn.note(u'o1 -> o2')
txn.commit()
now = packtime = time.time()
while packtime <= now:
Expand All @@ -421,12 +423,12 @@ def checkTransactionalUndoAfterPackWithObjectUnlinkFromRoot(self):
o3 = C()
o2.obj = o3
txn = transaction.get()
txn.note('o1 -> o2 -> o3')
txn.note(u'o1 -> o2 -> o3')
txn.commit()

o1.obj = o3
txn = transaction.get()
txn.note('o1 -> o3')
txn.note(u'o1 -> o3')
txn.commit()

log = self._storage.undoLog()
Expand All @@ -444,7 +446,7 @@ def checkTransactionalUndoAfterPackWithObjectUnlinkFromRoot(self):
tid = log[0]['id']
db.undo(tid)
txn = transaction.get()
txn.note('undo')
txn.note(u'undo')
txn.commit()
# undo does a txn-undo, but doesn't invalidate
conn.sync()
Expand All @@ -471,14 +473,14 @@ def set_pack_time():
root["key1"] = MinPO(1)
root["key2"] = MinPO(2)
txn = transaction.get()
txn.note("create 3 keys")
txn.note(u"create 3 keys")
txn.commit()

set_pack_time()

del root["key1"]
txn = transaction.get()
txn.note("delete 1 key")
txn.note(u"delete 1 key")
txn.commit()

set_pack_time()
Expand All @@ -490,7 +492,7 @@ def set_pack_time():
L = db.undoInfo()
db.undo(L[0]["id"])
txn = transaction.get()
txn.note("undo deletion")
txn.note(u"undo deletion")
txn.commit()

set_pack_time()
Expand Down Expand Up @@ -522,15 +524,15 @@ def checkPackAfterUndoManyTimes(self):
transaction.commit()
rt["test"] = MinPO(3)
txn = transaction.get()
txn.note("root of undo")
txn.note(u"root of undo")
txn.commit()

packtimes = []
for i in range(10):
L = db.undoInfo()
db.undo(L[0]["id"])
txn = transaction.get()
txn.note("undo %d" % i)
txn.note(u"undo %d" % i)
txn.commit()
rt._p_deactivate()
cn.sync()
Expand Down Expand Up @@ -647,9 +649,9 @@ def undo(i):
def checkUndoLogMetadata(self):
# test that the metadata is correct in the undo log
t = transaction.get()
t.note('t1')
t.note(u't1')
t.setExtendedInfo('k2', 'this is transaction metadata')
t.setUser('u3',path='p3')
t.setUser(u'u3',path=u'p3')
db = DB(self._storage)
conn = db.open()
root = conn.root()
Expand Down Expand Up @@ -734,7 +736,8 @@ def checkUndoMultipleConflictResolution(self, reverse=False):

for i in range(4):
with db.transaction() as conn:
conn.transaction_manager.get().note(str(i))
conn.transaction_manager.get().note(
(str if PY3 else unicode)(i))
conn.root.x.inc()

ids = [l['id'] for l in db.undoLog(1, 3)]
Expand Down
12 changes: 6 additions & 6 deletions src/ZODB/tests/dangle.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,19 +30,19 @@ def create_dangling_ref(db):
rt = db.open().root()

rt[1] = o1 = P()
transaction.get().note("create o1")
transaction.get().note(u"create o1")
transaction.commit()

rt[2] = o2 = P()
transaction.get().note("create o2")
transaction.get().note(u"create o2")
transaction.commit()

c = o1.child = P()
transaction.get().note("set child on o1")
transaction.get().note(u"set child on o1")
transaction.commit()

o1.child = P()
transaction.get().note("replace child on o1")
transaction.get().note(u"replace child on o1")
transaction.commit()

time.sleep(2)
Expand All @@ -53,11 +53,11 @@ def create_dangling_ref(db):

print(repr(c._p_oid))
o2.child = c
transaction.get().note("set child on o2")
transaction.get().note(u"set child on o2")
transaction.commit()

def main():
fs = FileStorage("dangle.fs")
fs = FileStorage(u"dangle.fs")
db = DB(fs)
create_dangling_ref(db)
db.close()
Expand Down
2 changes: 1 addition & 1 deletion src/ZODB/tests/testConnection.py
Original file line number Diff line number Diff line change
Expand Up @@ -494,7 +494,7 @@ def doctest_transaction_retry_convenience():
>>> import ZODB.POSException
>>> for attempt in transaction.manager.attempts():
... with attempt as t:
... t.note('test')
... t.note(u'test')
... six.print_(dm['ntry'], ntry)
... ntry += 1
... dm['ntry'] = ntry
Expand Down
4 changes: 2 additions & 2 deletions src/ZODB/tests/testMVCCMappingStorage.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ def checkCrossConnectionIsolation(self):

storage = c1._storage
t = transaction.Transaction()
t.description = 'isolation test 1'
t.description = u'isolation test 1'
c1.tpc_begin(t)
c1.commit(t)
storage.tpc_vote(t.data(c1))
Expand All @@ -110,7 +110,7 @@ def checkCrossConnectionIsolation(self):

storage = c1._storage
t = transaction.Transaction()
t.description = 'isolation test 2'
t.description = u'isolation test 2'
c1.tpc_begin(t)
c1.commit(t)
storage.tpc_vote(t.data(c1))
Expand Down
8 changes: 4 additions & 4 deletions src/ZODB/tests/testZODB.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ def populate(self):
root['test'] = pm = PersistentMapping()
for n in range(100):
pm[n] = PersistentMapping({0: 100 - n})
transaction.get().note('created test data')
transaction.get().note(u'created test data')
transaction.commit()
conn.close()

Expand All @@ -67,7 +67,7 @@ def checkExportImport(self, abort_it=False):

def duplicate(self, conn, abort_it):
transaction.begin()
transaction.get().note('duplication')
transaction.get().note(u'duplication')
root = conn.root()
ob = root['test']
assert len(ob) > 10, 'Insufficient test data'
Expand Down Expand Up @@ -424,7 +424,7 @@ def checkMultipleUndoInOneTransaction(self):
for state_num in range(6):
transaction.begin()
root['state'] = state_num
transaction.get().note('root["state"] = %d' % state_num)
transaction.get().note(u'root["state"] = %d' % state_num)
transaction.commit()

# Undo all but the first. Note that no work is actually
Expand All @@ -433,7 +433,7 @@ def checkMultipleUndoInOneTransaction(self):
log = self._db.undoLog()
self._db.undoMultiple([log[i]['id'] for i in range(5)])

transaction.get().note('undo states 1 through 5')
transaction.get().note(u'undo states 1 through 5')

# Now attempt all those undo operations.
transaction.commit()
Expand Down
2 changes: 1 addition & 1 deletion src/ZODB/tests/test_fsdump.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
>>> root = db.open().root()
>>> root['tree'] = OOBTree()
>>> txn.get().note('added an OOBTree')
>>> txn.get().note(u'added an OOBTree')
>>> txn.get().commit()
>>> fsdump(path) #doctest: +ELLIPSIS
Trans #00000 tid=... time=... offset=<OFFSET>
Expand Down
4 changes: 2 additions & 2 deletions src/ZODB/tests/testfsoids.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@
>>> root = db.open().root()
>>> root['tree'] = OOBTree()
>>> txn.get().note('added an OOBTree')
>>> txn.get().note(u'added an OOBTree')
>>> txn.get().commit()
>>> t = Tracer(path)
>>> t.register_oids(0, 1)
Expand Down Expand Up @@ -104,7 +104,7 @@
>>> tree = root['tree']
>>> tree['root'] = root
>>> txn.get().note('circling back to the root')
>>> txn.get().note(u'circling back to the root')
>>> txn.get().commit()
>>> t = Tracer(path)
>>> t.register_oids(0, 1, 2)
Expand Down

0 comments on commit 539e5f8

Please sign in to comment.