具有检查点和恢复的事务服务的设计模式

发布于 2024-09-26 12:43:51 字数 336 浏览 12 评论 0原文

我有一个多步骤过程,其中每个步骤都会执行一些网络 IO(Web 服务调用),然后保留一些数据。我想以容错的方式设计它,以便如果服务因系统崩溃或其中一个步骤失败而失败,我能够从上一个无错误的步骤恢复并重新启动。

以下是我考虑解决这个问题的方法(这是相当高的级别):

  1. 将每个步骤的状态(NOT_STARTED、IN_PROGRESS、FAILED)存储在数据库表中
  2. 如果步骤失败,则将其及其依赖步骤标记为“FAILED”并移动到下一个非依赖步骤
  3. 通过阅读此表进行恢复(例如在应用程序的引导部分中)

我想知道是否有一些设计模式、框架和算法可以解决此问题。

I have a multistep process where each step does some network IO (web service call) and then persists some data. I want to design it in a fault tolerant way so that if the service fails, either because of a system crash or one of the steps fails, I am able to recover and re-start from the last error free step.

Here is how I am thinking of addressing this (this is pretty high level):

  1. Stored the state of each step (NOT_STARTED, IN_PROGRESS, FAILED) in a database table
  2. If a step fails mark it and its dependent step as "FAILED" and move to the next non dependent step
  3. Recover by reading this table (e.g in a bootstrap portion of the application)

I was wondering if there are some design patterns, frameworks and algorithms that address this problem.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(4

撧情箌佬 2024-10-03 12:43:51

这是一篇很好的论文,“基于检查点的恢复的设计模式 ”,这解决了问题。

This is a nice paper, "Design patterns for checkpoint based recovery", that addresses the problem.

念﹏祤嫣 2024-10-03 12:43:51

您可以考虑责任链设计模式:http://en.wikipedia.org/wiki /责任链_模式

You may consider the Chain Of Responsibility Design Pattern: http://en.wikipedia.org/wiki/Chain-of-responsibility_pattern

妄司 2024-10-03 12:43:51

Memento (GoF) 可用于在可能失败的调用之前存储状态。

一个很好的搜索关键字是transactions。这允许您将由于故障而发生的更改回滚到最近的“稳定”状态。这是您的数据库将提供的一件事。

命令模式也有已知的事务用途。

Memento (GoF) could be used to store the state before a potentially failing call.

One good keyword to search for would be transactions. That allows you to roll-back changes that occurred on account of a failure to the nearest "stable" state. This is one thing your DB would be providing.

The Command pattern also has known uses of transactions.

一绘本一梦想 2024-10-03 12:43:51

在行为设计模式方面,我建议研究以下内容,因为它们似乎很好地满足了您的需求。请记住,此列表基于对您的实现的非常高层次的理解。

如果您还不熟悉,我强烈建议查找模型视图-ControllerModel-View-Presenter 模式,因为它们将让您的开发体验更加愉快。

如果您有任何后续问题,请随时询问。 :)

In terms of behavioral design patterns, I would recommend looking into the following, as they seem well equipped for your needs. Keep in mind that this list is based off of a very high-level understanding of your implementation.

  • Template method - For defining program skeletons
  • Strategy - For swapping algorithms as needed
  • Memento - For restoring objects to their previous states
  • State - Coupled with the memento patterns

If you're not already familiar, I would STRONGLY recommend looking up the Model-View-Controller and Model-View-Presenter patterns, as they will make your development experience much more enjoyable.

If you have any followup questions, feel free to ask. :)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文