如何测试存储过程的两阶段提交行为?
这个特定的存储过程会进行存档清除:
1) 从事务数据库中选择令牌
2)将令牌放入临时表中
3)循环标记:
3.1)使用临时表中的令牌,从事务表中检索数据并插入到单独存档数据库中的表中(通过联合)
3.2) COMMIT 插入。
3.3)然后这次使用相同的令牌从事务中删除数据
3.4) COMMIT 删除。
两阶段提交允许我们在循环结束时只有一次提交
我的问题是如何模拟场景以使 proc 在插入阶段或删除阶段失败?这是为了确保即使运行失败,数据仍保持完整性 - 没有半处理的令牌等。
this particular stored procedure does an archive purge:
1) select tokens from transactional db
2) put tokens in temp table
3) loop through tokens:
3.1)using tokens from temp table, retrieve data from transactional tables and insert to tables in a separate archive db (via federation)
3.2) COMMIT inserts.
3.3) then using same token this time delete the data from the transactional
3.4) COMMIT deletes.
2 phase commit allows us to have just one commit at the end of the loop
my question is how to simulate scenarios to make proc fail in the insert phase or delete phase? this is to ensure that even though run has failed, data retains integrity - no half-processed tokens or such.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
为了强制出现运行时错误,我通常在代码中放入
SELECT 0/0
。只需将其放在您选择的COMMIT
之前,然后观看由此产生的烟花!to force a run-time error, I usually put in a
SELECT 0/0
in the code. just put this in before theCOMMIT
of your choice and watch the fireworks that result!如果涉及到唯一的密钥,您可以放置一条记录,这会导致重复密钥违规。
If you have unique keys involved you can put a record in place that would cause a duplicate key violiation.
希望这会帮助别人!
我最近发现最好的方法是通过信号。
在删除阶段的中间,我输入了一个错误信号,因此进程将在该令牌上失败并退出循环,因此它应该回滚在该令牌的插入阶段插入的任何内容。
在删除阶段的循环中间
Hope this will help somebody else!
I just recently found that the best way was via signals.
In the middle of the delete phase, I put in an error signal so process would fail on that token and exit the loop, so it should rollback whatever it has inserted in the insert phase for that token.
inside the loop middle of delete phase