Florent Guillaume wrote:
Brian Sutherland wrote:
On Tue, Apr 04, 2006 at 10:37:57AM +0200, j.kartnaller wrote:
Here is how I automate the commit process :
from zope.interface import implements
from transaction import manager
from transaction.interfaces import IDataManager, ISynchronizer
from sqlalchemy import objectstore
"""Takes care of the transaction process in zope.
def tpc_begin(self, trans):
def commit(self, trans):
def tpc_vote(self, trans):
def tpc_finish(self, trans):
Er, just something I learnt the hard way from working on SQLOS, is that
you should send all the SQL over the line in the first phase of the TPC
but save the final "COMMIT" until the last phase.
Actually this code will never be correct if SQLAlchemy doesn't implement
two-phase commit. You *have* to have a real vote phase and a commit
phase in the actual data manager. Otherwise you'll sometime commit data
in SQL even though another data manager, like a connection to a
FileStorage, aborts the transaction (in case of conflict error for
You are right.
I already changed this code completely but must verify if it is tpc save or not.
I currently use the engine to enclose everythin in a transaction and use
objectstore.commit() for the first phase.
I'm also not sure where to put the first phase commit :
In commit or in tpc_vote ?
And last time I looked, SQLAlchemy didn't implement TPC (but it's moving
fast, this may have changed).
def tpc_abort(self, trans):
"""Synchronizer to add a alchemy data manager to the new
Let's check that it implements the interface correctly:
>>> from zope.interface import verify
>>> synch = CacheSynchronizer()
>>> verify.verifyObject(ISynchronizer, synch)
def afterCompletion(self, transaction):
def beforeCompletion(self, transaction):
def newTransaction(self, trans):
_synch = TransactionSynchronizer()
You also copied one of my bugs here;) If you are working in a
threaded environment, the synchronizer needs to be registered
in every thread.
It automatically commits or aborts as ZODB would do.
I borrowed most of it from SQLOS.
Warning : this code is not tested under all circumstances !
from interfaces import IUser
Zope3-users mailing list