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
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
......@@ -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
......
......@@ -1286,7 +1286,7 @@ large-record-size option in a configuration file) to specify a larger
size.
"""
class TransactionMetaData:
class TransactionMetaData(object):
def __init__(self, user=u'', description=u'', extension=b''):
self.user = user
......
......@@ -469,7 +469,7 @@ class DB(object):
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:
......
......@@ -182,7 +182,7 @@ class BasicStorage:
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)
......
......@@ -150,7 +150,7 @@ class PackableStorageBase:
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)
......@@ -575,7 +575,7 @@ class PackableUndoStorage(PackableStorageBase):
root = conn.root()
txn = transaction.get()
txn.note('root')
txn.note(u'root')
txn.commit()
now = packtime = time.time()
......@@ -587,12 +587,12 @@ class PackableUndoStorage(PackableStorageBase):
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)
......@@ -601,7 +601,7 @@ class PackableUndoStorage(PackableStorageBase):
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()
......
......@@ -73,15 +73,15 @@ class RecoveryStorage(IteratorDeepCompare):
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)
......
......@@ -171,7 +171,7 @@ class StorageTestBase(ZODB.tests.util.TestCase):
# 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)
......
......@@ -17,6 +17,8 @@ Any storage that supports undo() must pass these tests.
"""
import time
from six import PY3
from persistent import Persistent
import transaction
from transaction import Transaction
......@@ -412,7 +414,7 @@ class TransactionalUndoStorage:
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:
......@@ -421,12 +423,12 @@ class TransactionalUndoStorage:
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()
......@@ -444,7 +446,7 @@ class TransactionalUndoStorage:
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()
......@@ -471,14 +473,14 @@ class TransactionalUndoStorage:
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()
......@@ -490,7 +492,7 @@ class TransactionalUndoStorage:
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()
......@@ -522,7 +524,7 @@ class TransactionalUndoStorage:
transaction.commit()
rt["test"] = MinPO(3)
txn = transaction.get()
txn.note("root of undo")
txn.note(u"root of undo")
txn.commit()
packtimes = []
......@@ -530,7 +532,7 @@ class TransactionalUndoStorage:
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()
......@@ -647,9 +649,9 @@ class TransactionalUndoStorage:
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()
......@@ -734,7 +736,8 @@ class TransactionalUndoStorage:
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)]
......
......@@ -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)
......@@ -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()
......
......@@ -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
......
......@@ -84,7 +84,7 @@ class MVCCTests:
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))
......@@ -110,7 +110,7 @@ class MVCCTests:
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))
......
......@@ -48,7 +48,7 @@ class ZODBTests(ZODB.tests.util.TestCase):
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()
......@@ -67,7 +67,7 @@ class ZODBTests(ZODB.tests.util.TestCase):
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'
......@@ -424,7 +424,7 @@ class ZODBTests(ZODB.tests.util.TestCase):
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
......@@ -433,7 +433,7 @@ class ZODBTests(ZODB.tests.util.TestCase):
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()
......
......@@ -49,7 +49,7 @@ Let's add a BTree:
>>> 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>
......
......@@ -76,7 +76,7 @@ Let's add a BTree and try again:
>>> 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)
......@@ -104,7 +104,7 @@ One more, storing a reference in the BTree back to the root object:
>>> 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)
......
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