如何测试存储过程的两阶段提交行为?

发布于 2024-09-10 11:36:11 字数 301 浏览 0 评论 0原文

这个特定的存储过程会进行存档清除:
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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

你的笑 2024-09-17 11:36:11

为了强制出现运行时错误,我通常在代码中放入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 the COMMIT of your choice and watch the fireworks that result!

合约呢 2024-09-17 11:36:11

如果涉及到唯一的密钥,您可以放置​​一条记录,这会导致重复密钥违规。

If you have unique keys involved you can put a record in place that would cause a duplicate key violiation.

失眠症患者 2024-09-17 11:36:11

希望这会帮助别人!
我最近发现最好的方法是通过信号。
在删除阶段的中间,我输入了一个错误信号,因此进程将在该令牌上失败并退出循环,因此它应该回滚在该令牌的插入阶段插入的任何内容。

DECLARE rollback_on_token_101 CONDITION FOR SQLSTATE '99001';

在删除阶段的循环中间

IF TOKEN_SUCCESS_COUNT=100 THEN
  SIGNAL rollback_on_token_101 
  SET MESSAGE_TEXT = 'rolling back on mid-delete phase on token # 101 ';
END IF;

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.

DECLARE rollback_on_token_101 CONDITION FOR SQLSTATE '99001';

inside the loop middle of delete phase

IF TOKEN_SUCCESS_COUNT=100 THEN
  SIGNAL rollback_on_token_101 
  SET MESSAGE_TEXT = 'rolling back on mid-delete phase on token # 101 ';
END IF;
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文