[Zope3-checkins] CVS: Zope3/src/transaction -
_transaction.py:1.1.2.33 _manager.py:1.1.2.3 __init__.py:1.4.8.3
Jeremy Hylton
jeremy at zope.com
Wed Mar 31 16:58:56 EST 2004
Update of /cvs-repository/Zope3/src/transaction
In directory cvs.zope.org:/tmp/cvs-serv14763/src/transaction
Modified Files:
Tag: jeremy-txn-branch
_transaction.py _manager.py __init__.py
Log Message:
Add single-threaded TM and cleanup some Transaction implementation details.
Rename TransactionManager to ThreadTransactionManager. Replace
TransactionManager with a simple implementation that doesn't know
about threads.
Add some comments and a few log.debug() calls to the Transaction
implementation.
Catch errors in tpc_finish() and log a critical error. This doesn't
provide the "hosed" feature, but hoser stoppage was disabled on the
trunk a while ago.
=== Zope3/src/transaction/_transaction.py 1.1.2.32 => 1.1.2.33 ===
--- Zope3/src/transaction/_transaction.py:1.1.2.32 Tue Mar 30 17:25:59 2004
+++ Zope3/src/transaction/_transaction.py Wed Mar 31 16:58:56 2004
@@ -173,6 +173,8 @@
def join(self, resource):
if self.status != Status.ACTIVE:
+ # XXX Should it be possible to join a committing transaction?
+ # I think some users want it.
raise ValueError("expected txn status %r, but it's %r" % (
Status.ACTIVE, self.status))
# XXX the prepare check is a bit of a hack, perhaps it would
@@ -214,8 +216,10 @@
self._resources.append(adapter)
def begin(self):
- # If nothing has happened yet, it's fine. Otherwise, abort
- # this transaction and let the txn manager create a new one.
+ # XXX I'm not sure how this should be implemented. Not doing
+ # anything now, but my best guess is: If nothing has happened
+ # yet, it's fine. Otherwise, abort this transaction and let
+ # the txn manager create a new one.
pass
def commit(self, subtransaction=False):
@@ -243,6 +247,7 @@
self._manager.free(self)
for s in self._synchronizers:
s.afterCompletion()
+ self.log.debug("commit")
def _commitResources(self, subtransaction):
# Execute the two-phase commit protocol.
@@ -262,14 +267,25 @@
rm.tpc_begin(self, subtransaction)
for rm in L:
rm.commit(self)
+ self.log.debug("commit %r" % rm)
if not subtransaction:
# Not sure why, but it is intentional that you do not
# call tpc_vote() for subtransaction commits.
for rm in L:
rm.tpc_vote(self)
self._voted[id(rm)] = True
- for rm in L:
- rm.tpc_finish(self)
+
+ try:
+ for rm in L:
+ rm.tpc_finish(self)
+ except:
+ # XXX do we need to make this warning stronger?
+ # XXX It would be nice if the system could be configured
+ # to stop committing transactions at this point.
+ self.log.critical("A storage error occured during the second "
+ "phase of the two-phase commit. Resources "
+ "may be in an inconsistent state.")
+ raise
except:
# If an error occurs committing a transaction, we try
# to revert the changes in each of the resource managers.
@@ -373,6 +389,7 @@
self._manager.free(self)
for s in self._synchronizers:
s.afterCompletion()
+ self.log.debug("abort")
if tb is not None:
raise t, v, tb
=== Zope3/src/transaction/_manager.py 1.1.2.2 => 1.1.2.3 ===
--- Zope3/src/transaction/_manager.py:1.1.2.2 Fri Mar 19 16:07:13 2004
+++ Zope3/src/transaction/_manager.py Wed Mar 31 16:58:56 2004
@@ -22,6 +22,33 @@
from transaction._transaction import Transaction
class TransactionManager(object):
+
+ def __init__(self):
+ self._txn = None
+ self._synchs = []
+
+ def begin(self):
+ if self._txn is not None:
+ self._txn.abort()
+ self._txn = Transaction(self._synchs, self)
+ return self._txn
+
+ def get(self):
+ if self._txn is None:
+ self._txn = Transaction(self._synchs, self)
+ return self._txn
+
+ def free(self, txn):
+ assert txn is self._txn
+ self._txn = None
+
+ def registerSynch(self, synch):
+ self.synchs.append(synch)
+
+ def unregisterSynch(self, synch):
+ self._synchs.remove(synch)
+
+class ThreadTransactionManager(object):
"""Thread-aware transaction manager.
Each thread is associated with a unique transaction.
=== Zope3/src/transaction/__init__.py 1.4.8.2 => 1.4.8.3 ===
--- Zope3/src/transaction/__init__.py:1.4.8.2 Fri Mar 19 15:28:23 2004
+++ Zope3/src/transaction/__init__.py Wed Mar 31 16:58:56 2004
@@ -13,9 +13,9 @@
############################################################################
from transaction._transaction import Transaction
-from transaction._manager import TransactionManager
+from transaction._manager import TransactionManager, ThreadTransactionManager
-manager = TransactionManager()
+manager = ThreadTransactionManager()
def get():
return manager.get()
@@ -29,4 +29,5 @@
def abort():
manager.get().abort()
+# XXX Issue deprecation warning if this variant is used?
get_transaction = get
More information about the Zope3-Checkins
mailing list