Commit 539e5f82 authored by Jim Fulton's avatar Jim Fulton

Lots of changes to work with newly persnickity transactions

parent 32c8436c
...@@ -139,7 +139,7 @@ statement. Transaction managers are context managers, so we can use ...@@ -139,7 +139,7 @@ statement. Transaction managers are context managers, so we can use
them with the ``with`` statement directly:: them with the ``with`` statement directly::
with my_transaction_manager as trans: with my_transaction_manager as trans:
trans.note("incrementing x") trans.note(u"incrementing x")
conn.root.x += 1 conn.root.x += 1
.. -> src .. -> src
...@@ -181,7 +181,7 @@ So, for example, if we wanted to set a transaction note:: ...@@ -181,7 +181,7 @@ So, for example, if we wanted to set a transaction note::
with db.transaction() as conn2: 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 conn2.root.x += 1
.. -> src .. -> src
......
...@@ -1286,7 +1286,7 @@ large-record-size option in a configuration file) to specify a larger ...@@ -1286,7 +1286,7 @@ large-record-size option in a configuration file) to specify a larger
size. size.
""" """
class TransactionMetaData: class TransactionMetaData(object):
def __init__(self, user=u'', description=u'', extension=b''): def __init__(self, user=u'', description=u'', extension=b''):
self.user = user self.user = user
......
...@@ -469,7 +469,7 @@ class DB(object): ...@@ -469,7 +469,7 @@ class DB(object):
self.large_record_size = large_record_size self.large_record_size = large_record_size
# Make sure we have a root: # Make sure we have a root:
with self.transaction('initial database creation') as conn: with self.transaction(u'initial database creation') as conn:
try: try:
conn.get(z64) conn.get(z64)
except KeyError: except KeyError:
......
...@@ -182,7 +182,7 @@ class BasicStorage: ...@@ -182,7 +182,7 @@ class BasicStorage:
oid = self._storage.new_oid() oid = self._storage.new_oid()
t = TransactionMetaData() t = TransactionMetaData()
self._storage.tpc_begin(t) 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.store(oid, ZERO, zodb_pickle(MinPO(5)), '', t)
self._storage.tpc_vote(t) self._storage.tpc_vote(t)
self._storage.tpc_finish(t) self._storage.tpc_finish(t)
......
...@@ -150,7 +150,7 @@ class PackableStorageBase: ...@@ -150,7 +150,7 @@ class PackableStorageBase:
p.dump((PersistentMapping, None)) p.dump((PersistentMapping, None))
p.dump({'_container': {}}) p.dump({'_container': {}})
t=Transaction() t=Transaction()
t.description='initial database creation' t.description = u'initial database creation'
self._storage.tpc_begin(t) self._storage.tpc_begin(t)
self._storage.store(ZERO, None, file.getvalue(), '', t) self._storage.store(ZERO, None, file.getvalue(), '', t)
self._storage.tpc_vote(t) self._storage.tpc_vote(t)
...@@ -575,7 +575,7 @@ class PackableUndoStorage(PackableStorageBase): ...@@ -575,7 +575,7 @@ class PackableUndoStorage(PackableStorageBase):
root = conn.root() root = conn.root()
txn = transaction.get() txn = transaction.get()
txn.note('root') txn.note(u'root')
txn.commit() txn.commit()
now = packtime = time.time() now = packtime = time.time()
...@@ -587,12 +587,12 @@ class PackableUndoStorage(PackableStorageBase): ...@@ -587,12 +587,12 @@ class PackableUndoStorage(PackableStorageBase):
root['obj'] = obj root['obj'] = obj
txn = transaction.get() txn = transaction.get()
txn.note('root -> o1') txn.note(u'root -> o1')
txn.commit() txn.commit()
del root['obj'] del root['obj']
txn = transaction.get() txn = transaction.get()
txn.note('root -x-> o1') txn.note(u'root -x-> o1')
txn.commit() txn.commit()
self._storage.pack(packtime, referencesf) self._storage.pack(packtime, referencesf)
...@@ -601,7 +601,7 @@ class PackableUndoStorage(PackableStorageBase): ...@@ -601,7 +601,7 @@ class PackableUndoStorage(PackableStorageBase):
tid = log[0]['id'] tid = log[0]['id']
db.undo(tid) db.undo(tid)
txn = transaction.get() txn = transaction.get()
txn.note('undo root -x-> o1') txn.note(u'undo root -x-> o1')
txn.commit() txn.commit()
conn.sync() conn.sync()
......
...@@ -73,15 +73,15 @@ class RecoveryStorage(IteratorDeepCompare): ...@@ -73,15 +73,15 @@ class RecoveryStorage(IteratorDeepCompare):
root = conn.root() root = conn.root()
root.obj = obj1 = MinPO(1) root.obj = obj1 = MinPO(1)
txn = transaction.get() txn = transaction.get()
txn.note('root -> obj') txn.note(u'root -> obj')
txn.commit() txn.commit()
root.obj.obj = obj2 = MinPO(2) root.obj.obj = obj2 = MinPO(2)
txn = transaction.get() txn = transaction.get()
txn.note('root -> obj -> obj') txn.note(u'root -> obj -> obj')
txn.commit() txn.commit()
del root.obj del root.obj
txn = transaction.get() txn = transaction.get()
txn.note('root -X->') txn.note(u'root -X->')
txn.commit() txn.commit()
# Now copy the transactions to the destination # Now copy the transactions to the destination
self._dst.copyTransactionsFrom(self._storage) self._dst.copyTransactionsFrom(self._storage)
......
...@@ -171,7 +171,7 @@ class StorageTestBase(ZODB.tests.util.TestCase): ...@@ -171,7 +171,7 @@ class StorageTestBase(ZODB.tests.util.TestCase):
# Undo a tid that affects a single object (oid). # Undo a tid that affects a single object (oid).
# This is very specialized. # This is very specialized.
t = TransactionMetaData() t = TransactionMetaData()
t.note(note or "undo") t.note(note or u"undo")
self._storage.tpc_begin(t) self._storage.tpc_begin(t)
undo_result = self._storage.undo(tid, t) undo_result = self._storage.undo(tid, t)
vote_result = self._storage.tpc_vote(t) vote_result = self._storage.tpc_vote(t)
......
...@@ -17,6 +17,8 @@ Any storage that supports undo() must pass these tests. ...@@ -17,6 +17,8 @@ Any storage that supports undo() must pass these tests.
""" """
import time import time
from six import PY3
from persistent import Persistent from persistent import Persistent
import transaction import transaction
from transaction import Transaction from transaction import Transaction
...@@ -412,7 +414,7 @@ class TransactionalUndoStorage: ...@@ -412,7 +414,7 @@ class TransactionalUndoStorage:
root['obj'] = o1 root['obj'] = o1
o1.obj = o2 o1.obj = o2
txn = transaction.get() txn = transaction.get()
txn.note('o1 -> o2') txn.note(u'o1 -> o2')
txn.commit() txn.commit()
now = packtime = time.time() now = packtime = time.time()
while packtime <= now: while packtime <= now:
...@@ -421,12 +423,12 @@ class TransactionalUndoStorage: ...@@ -421,12 +423,12 @@ class TransactionalUndoStorage:
o3 = C() o3 = C()
o2.obj = o3 o2.obj = o3
txn = transaction.get() txn = transaction.get()
txn.note('o1 -> o2 -> o3') txn.note(u'o1 -> o2 -> o3')
txn.commit() txn.commit()
o1.obj = o3 o1.obj = o3
txn = transaction.get() txn = transaction.get()
txn.note('o1 -> o3') txn.note(u'o1 -> o3')
txn.commit() txn.commit()
log = self._storage.undoLog() log = self._storage.undoLog()
...@@ -444,7 +446,7 @@ class TransactionalUndoStorage: ...@@ -444,7 +446,7 @@ class TransactionalUndoStorage:
tid = log[0]['id'] tid = log[0]['id']
db.undo(tid) db.undo(tid)
txn = transaction.get() txn = transaction.get()
txn.note('undo') txn.note(u'undo')
txn.commit() txn.commit()
# undo does a txn-undo, but doesn't invalidate # undo does a txn-undo, but doesn't invalidate
conn.sync() conn.sync()
...@@ -471,14 +473,14 @@ class TransactionalUndoStorage: ...@@ -471,14 +473,14 @@ class TransactionalUndoStorage:
root["key1"] = MinPO(1) root["key1"] = MinPO(1)
root["key2"] = MinPO(2) root["key2"] = MinPO(2)
txn = transaction.get() txn = transaction.get()
txn.note("create 3 keys") txn.note(u"create 3 keys")
txn.commit() txn.commit()
set_pack_time() set_pack_time()
del root["key1"] del root["key1"]
txn = transaction.get() txn = transaction.get()
txn.note("delete 1 key") txn.note(u"delete 1 key")
txn.commit() txn.commit()
set_pack_time() set_pack_time()
...@@ -490,7 +492,7 @@ class TransactionalUndoStorage: ...@@ -490,7 +492,7 @@ class TransactionalUndoStorage:
L = db.undoInfo() L = db.undoInfo()
db.undo(L[0]["id"]) db.undo(L[0]["id"])
txn = transaction.get() txn = transaction.get()
txn.note("undo deletion") txn.note(u"undo deletion")
txn.commit() txn.commit()
set_pack_time() set_pack_time()
...@@ -522,7 +524,7 @@ class TransactionalUndoStorage: ...@@ -522,7 +524,7 @@ class TransactionalUndoStorage:
transaction.commit() transaction.commit()
rt["test"] = MinPO(3) rt["test"] = MinPO(3)
txn = transaction.get() txn = transaction.get()
txn.note("root of undo") txn.note(u"root of undo")
txn.commit() txn.commit()
packtimes = [] packtimes = []
...@@ -530,7 +532,7 @@ class TransactionalUndoStorage: ...@@ -530,7 +532,7 @@ class TransactionalUndoStorage:
L = db.undoInfo() L = db.undoInfo()
db.undo(L[0]["id"]) db.undo(L[0]["id"])
txn = transaction.get() txn = transaction.get()
txn.note("undo %d" % i) txn.note(u"undo %d" % i)
txn.commit() txn.commit()
rt._p_deactivate() rt._p_deactivate()
cn.sync() cn.sync()
...@@ -647,9 +649,9 @@ class TransactionalUndoStorage: ...@@ -647,9 +649,9 @@ class TransactionalUndoStorage:
def checkUndoLogMetadata(self): def checkUndoLogMetadata(self):
# test that the metadata is correct in the undo log # test that the metadata is correct in the undo log
t = transaction.get() t = transaction.get()
t.note('t1') t.note(u't1')
t.setExtendedInfo('k2', 'this is transaction metadata') t.setExtendedInfo('k2', 'this is transaction metadata')
t.setUser('u3',path='p3') t.setUser(u'u3',path=u'p3')
db = DB(self._storage) db = DB(self._storage)
conn = db.open() conn = db.open()
root = conn.root() root = conn.root()
...@@ -734,7 +736,8 @@ class TransactionalUndoStorage: ...@@ -734,7 +736,8 @@ class TransactionalUndoStorage:
for i in range(4): for i in range(4):
with db.transaction() as conn: 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() conn.root.x.inc()
ids = [l['id'] for l in db.undoLog(1, 3)] ids = [l['id'] for l in db.undoLog(1, 3)]
......
...@@ -30,19 +30,19 @@ def create_dangling_ref(db): ...@@ -30,19 +30,19 @@ def create_dangling_ref(db):
rt = db.open().root() rt = db.open().root()
rt[1] = o1 = P() rt[1] = o1 = P()
transaction.get().note("create o1") transaction.get().note(u"create o1")
transaction.commit() transaction.commit()
rt[2] = o2 = P() rt[2] = o2 = P()
transaction.get().note("create o2") transaction.get().note(u"create o2")
transaction.commit() transaction.commit()
c = o1.child = P() c = o1.child = P()
transaction.get().note("set child on o1") transaction.get().note(u"set child on o1")
transaction.commit() transaction.commit()
o1.child = P() o1.child = P()
transaction.get().note("replace child on o1") transaction.get().note(u"replace child on o1")
transaction.commit() transaction.commit()
time.sleep(2) time.sleep(2)
...@@ -53,11 +53,11 @@ def create_dangling_ref(db): ...@@ -53,11 +53,11 @@ def create_dangling_ref(db):
print(repr(c._p_oid)) print(repr(c._p_oid))
o2.child = c o2.child = c
transaction.get().note("set child on o2") transaction.get().note(u"set child on o2")
transaction.commit() transaction.commit()
def main(): def main():
fs = FileStorage("dangle.fs") fs = FileStorage(u"dangle.fs")
db = DB(fs) db = DB(fs)
create_dangling_ref(db) create_dangling_ref(db)
db.close() db.close()
......
...@@ -494,7 +494,7 @@ def doctest_transaction_retry_convenience(): ...@@ -494,7 +494,7 @@ def doctest_transaction_retry_convenience():
>>> import ZODB.POSException >>> import ZODB.POSException
>>> for attempt in transaction.manager.attempts(): >>> for attempt in transaction.manager.attempts():
... with attempt as t: ... with attempt as t:
... t.note('test') ... t.note(u'test')
... six.print_(dm['ntry'], ntry) ... six.print_(dm['ntry'], ntry)
... ntry += 1 ... ntry += 1
... dm['ntry'] = ntry ... dm['ntry'] = ntry
......
...@@ -84,7 +84,7 @@ class MVCCTests: ...@@ -84,7 +84,7 @@ class MVCCTests:
storage = c1._storage storage = c1._storage
t = transaction.Transaction() t = transaction.Transaction()
t.description = 'isolation test 1' t.description = u'isolation test 1'
c1.tpc_begin(t) c1.tpc_begin(t)
c1.commit(t) c1.commit(t)
storage.tpc_vote(t.data(c1)) storage.tpc_vote(t.data(c1))
...@@ -110,7 +110,7 @@ class MVCCTests: ...@@ -110,7 +110,7 @@ class MVCCTests:
storage = c1._storage storage = c1._storage
t = transaction.Transaction() t = transaction.Transaction()
t.description = 'isolation test 2' t.description = u'isolation test 2'
c1.tpc_begin(t) c1.tpc_begin(t)
c1.commit(t) c1.commit(t)
storage.tpc_vote(t.data(c1)) storage.tpc_vote(t.data(c1))
......
...@@ -48,7 +48,7 @@ class ZODBTests(ZODB.tests.util.TestCase): ...@@ -48,7 +48,7 @@ class ZODBTests(ZODB.tests.util.TestCase):
root['test'] = pm = PersistentMapping() root['test'] = pm = PersistentMapping()
for n in range(100): for n in range(100):
pm[n] = PersistentMapping({0: 100 - n}) pm[n] = PersistentMapping({0: 100 - n})
transaction.get().note('created test data') transaction.get().note(u'created test data')
transaction.commit() transaction.commit()
conn.close() conn.close()
...@@ -67,7 +67,7 @@ class ZODBTests(ZODB.tests.util.TestCase): ...@@ -67,7 +67,7 @@ class ZODBTests(ZODB.tests.util.TestCase):
def duplicate(self, conn, abort_it): def duplicate(self, conn, abort_it):
transaction.begin() transaction.begin()
transaction.get().note('duplication') transaction.get().note(u'duplication')
root = conn.root() root = conn.root()
ob = root['test'] ob = root['test']
assert len(ob) > 10, 'Insufficient test data' assert len(ob) > 10, 'Insufficient test data'
...@@ -424,7 +424,7 @@ class ZODBTests(ZODB.tests.util.TestCase): ...@@ -424,7 +424,7 @@ class ZODBTests(ZODB.tests.util.TestCase):
for state_num in range(6): for state_num in range(6):
transaction.begin() transaction.begin()
root['state'] = state_num root['state'] = state_num
transaction.get().note('root["state"] = %d' % state_num) transaction.get().note(u'root["state"] = %d' % state_num)
transaction.commit() transaction.commit()
# Undo all but the first. Note that no work is actually # Undo all but the first. Note that no work is actually
...@@ -433,7 +433,7 @@ class ZODBTests(ZODB.tests.util.TestCase): ...@@ -433,7 +433,7 @@ class ZODBTests(ZODB.tests.util.TestCase):
log = self._db.undoLog() log = self._db.undoLog()
self._db.undoMultiple([log[i]['id'] for i in range(5)]) 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. # Now attempt all those undo operations.
transaction.commit() transaction.commit()
......
...@@ -49,7 +49,7 @@ Let's add a BTree: ...@@ -49,7 +49,7 @@ Let's add a BTree:
>>> root = db.open().root() >>> root = db.open().root()
>>> root['tree'] = OOBTree() >>> root['tree'] = OOBTree()
>>> txn.get().note('added an OOBTree') >>> txn.get().note(u'added an OOBTree')
>>> txn.get().commit() >>> txn.get().commit()
>>> fsdump(path) #doctest: +ELLIPSIS >>> fsdump(path) #doctest: +ELLIPSIS
Trans #00000 tid=... time=... offset=<OFFSET> Trans #00000 tid=... time=... offset=<OFFSET>
......
...@@ -76,7 +76,7 @@ Let's add a BTree and try again: ...@@ -76,7 +76,7 @@ Let's add a BTree and try again:
>>> root = db.open().root() >>> root = db.open().root()
>>> root['tree'] = OOBTree() >>> root['tree'] = OOBTree()
>>> txn.get().note('added an OOBTree') >>> txn.get().note(u'added an OOBTree')
>>> txn.get().commit() >>> txn.get().commit()
>>> t = Tracer(path) >>> t = Tracer(path)
>>> t.register_oids(0, 1) >>> t.register_oids(0, 1)
...@@ -104,7 +104,7 @@ One more, storing a reference in the BTree back to the root object: ...@@ -104,7 +104,7 @@ One more, storing a reference in the BTree back to the root object:
>>> tree = root['tree'] >>> tree = root['tree']
>>> tree['root'] = root >>> tree['root'] = root
>>> txn.get().note('circling back to the root') >>> txn.get().note(u'circling back to the root')
>>> txn.get().commit() >>> txn.get().commit()
>>> t = Tracer(path) >>> t = Tracer(path)
>>> t.register_oids(0, 1, 2) >>> t.register_oids(0, 1, 2)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment