如何使用 SQLAlchemy 处理两阶段提交
我正在尝试使用 SQLalchemy 0.6.8 和 Postgresql 8.3.4 进行两阶段提交,但我认为我错过了一些东西......
工作流程如下:
session = sessionmaker(engine)(autocommit=True)
tx = session.connection().begin_twophase(xid) # Doesn't issue any SQL
session.begin()
session.add(obj1)
session.flush()
tx.prepare()
然后从另一个会话
session = sessionmaker(engine)(autocommit=True)
session.connection().commit_prepared(xid, recover=True) # recover=True because otherwise it complains that you can't issue a COMMIT PREPARED from inside a transaction
这不会引发任何错误,但也不会向表中写入任何内容... O_o 我缺少什么?
我什至尝试在 prepare()
之后阻止应用程序,并从 pgadmin 发出 COMMIT PREPARED 'xid'
,但仍然没有写入任何内容。
I'm trying to do a two-phase commit using SQLalchemy 0.6.8 with Postgresql 8.3.4, but I think I'm missing something...
The workflow goes like this:
session = sessionmaker(engine)(autocommit=True)
tx = session.connection().begin_twophase(xid) # Doesn't issue any SQL
session.begin()
session.add(obj1)
session.flush()
tx.prepare()
then from another session
session = sessionmaker(engine)(autocommit=True)
session.connection().commit_prepared(xid, recover=True) # recover=True because otherwise it complains that you can't issue a COMMIT PREPARED from inside a transaction
This doesn't raise any error, but doesn't write anything to the table either... O_o
What am I missing?
I tried even blocking the application after the prepare()
and issuing a COMMIT PREPARED 'xid'
from pgadmin, but still nothing gets written.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我设法让它工作,方法如下:
然后从另一个会话
I managed to get it working, here's how:
then from another session