事务校对方式

By admin in 亚洲必赢app在哪下载 on 2019年2月6日

Undo the work performed by a series of steps, which together define an
eventually consistent operation, if one or more of the steps fail.
Operations that follow the eventual consistency model are commonly found
in cloud-hosted applications that implement complex business processes
and workflows.

取消由一层层步骤执行的做事,一起定义一个最终一致的操作,假若一个或多少个步骤败北。在云托管的应用程序,已毕复杂的事务和做事流程,平时操作是安份守己的末尾一致性模型。

Context and Problem 背景和题材

Applications running in the cloud frequently modify data. This data may
be spread across an assortment of data sources held in a variety of
geographic locations. To avoid contention and improve performance in a
distributed environment such as this, an application should not attempt
to provide strong transactional consistency. Rather, the application
should implement eventual consistency. In this model, a typical
business operation consists of a series of autonomous steps. While these
steps are being performed the overall view of the system state may be
inconsistent, but when the operation has completed and all of the steps
have been executed the system should become consistent again.

在云端运行的应用程序常常修改数据,此数量或许会疏散在分裂地理地方的数目源中。为了防止竞争和拉长品质,如在分布式环境中,应用程序不该总结提供强大的事情一致性。相反,应用程序应该落成最后的一致性。在这些模型中,一个超级的政工操作由一三种的独立步骤组成。就算那些手续正在拓展系统状态的完好视图可能是不一致的,但当操作已经完毕,并已推行的有所手续的系统应成为平等。

Note:

The Data Consistency
Primer
provides
more information about why distributed transactions do not scale well,
and the principles that underpin the eventual consistency model.

A significant challenge in the eventual consistency model is how to
handle a step that has failed irrecoverably. In this case it may be
necessary to undo all of the work completed by the previous steps in the
operation. However, the data cannot simply be rolled back because other
concurrent instances of the application may have since changed it. Even
in cases where the data has not been changed by a concurrent instance,
undoing a step might not simply be a matter of restoring the original
state. It may be necessary to apply various business-specific rules (see
the travel website described in the
Example
section).

在最终一致性模型的一个主要的挑衅是怎么着处理一个挫折的手续。在那种景色下,它恐怕是少不了的吊销所有的办事到位的前一步操作。不过,数据无法简单地回滚,因为应用程序的别的并发实例可能早就改成了它。即使没有收获数码的出现处境的转移,打消一步可能不仅是还原原来的情景。它恐怕是少不了的,适用于各类事情的实际规则(见例子)。

If an operation that implements eventual consistency spans several
heterogeneous data stores, undoing the steps in such an operation will
require visiting each data store in turn. The work performed in every
data store must be undone reliably to prevent the system from remaining
inconsistent.

一经完成末了一致性跨越三个异构数据存储操作,废除步骤等操作须求各类走访每个数据存储。在每个数据存储中施行的工作都必须被撤废,避防范系统的不雷同。

Not all data affected by an operation that implements eventual
consistency might be held in a database. In a Service Oriented
Architecture (SOA) environment an operation may invoke an action in a
service, and cause a change in the state held by that service. To undo
the operation, this state change must also be undone. This may involve
invoking the service again and performing another action that reverses
the effects of the first.

并不是持有的多少都会潜移默化到终极的一致性,可能在一个数据库中展开。在面向服务的连串布局(SOA)环境下的操作可能在服务调用动作,而致使的劳务场地的生成。废除该操作,该意况更改也非得被撤回。那也许波及再一次调用服务,并推行另一个五花大绑的震慑的行动。

Solution 解决方案

Implement a compensating transaction. The steps in a compensating
transaction must undo the effects of the steps in the original
operation. A compensating transaction might not be able to simply
replace the current state with the state the system was in at the start
of the operation because this approach could overwrite changes made by
other concurrent instances of an application. Rather, it must be an
intelligent process that takes into account any work done by concurrent
instances. This process will usually be application-specific, driven by
the nature of the work performed by the original operation.

兑现互补工作。补偿工作中的步骤必须打消原操作步骤的熏陶。一个补偿工作可能不可见简单地更迭当前运行情状的情形,因为那种方法可以覆盖应用程序的其他并发实例进行更改。相反,它必须是一个智能的历程,要求考虑到其余工作所做的面世实例。那么些进程一般是特定于应用程序的,由原操作实践的做事的习性驱动的。

A common approach to implementing an eventually consistent operation
that requires compensation is to use a workflow. As the original
operation proceeds, the system records information about each step and
how the work performed by that step can be undone. If the operation
fails at any point, the workflow rewinds back through the steps it has
completed and performs the work that reverses each step. Note that a
compensating transaction might not have to undo the work in the exact
mirror-opposite order of the original operation, and it may be possible
to perform some of the undo steps in parallel.

一种常见的措施来促成一个末尾一致的操作,须要补充操作是选取一个工作流。作为土生土长的操作进行,系统记录有关每一步的音讯,以及怎么做到该步骤所进行的行事。假若在其他时候操作败北,工作流将回来到步骤已经形成和推行工作的每一步。请留心,补偿工作可能不需求在本来的操作的镜像相反的次第中收回工作,并可能有可能举行一些互为的吊销步骤。

Note:

亚洲必赢app在哪下载,This approach is similar to the Sagas strategy. A description of this
strategy is available online in Clemens Vasters’
blog
.

A compensating transaction is itself an eventually consistent operation
and it could also fail. The system should be able to resume the
compensating transaction at the point of failure and continue. It may be
necessary to repeat a step that has failed, so the steps in a
compensating transaction should be defined as idempotent commands. For
more information about idempotency, see Idempotency
Patterns

on Jonathan Oliver’s blog.

补偿性事务本身就是一种最终一致的操作,也可能破产。该连串应该力所能及过来在故障点的补偿性操作,并继承。可能须要再行失利步骤,那么在补偿工作的步骤应定义为幂等的指令。关于幂等性的更加多音信,参见Idempotency
Patterns

on Jonathan Oliver’s blog。

In some cases it may not be possible to recover from a step that has
failed except through manual intervention. In these situations the
system should raise an alert and provide as much information as possible
about the reason for the failure.

在好几意况下,它或许无法復苏从一个难倒的手续,除了通过人工干预。在那种情景下,系统应该提供预警,并尽可能为破产的缘由提供多的新闻。

Issues and Considerations 难点和注意事项

Consider the following points when deciding how to implement this
pattern:

在控制怎么样促成那个形式时,考虑以下几点:

  • It might not be easy to determine when a step in an operation that
    implements eventual consistency has failed. A step might not fail
    immediately, but instead it could block. It may be necessary to
    implement some form of time-out mechanism.
  • 那也许不易于决断,在一个末段一致性操作的某步骤的操作战败。一个步骤可能不会立即战败,但它反而被堵塞。它或许必要落成某种格局的晚点机制。
  • Compensation logic is not easily generalized. A compensating
    transaction is application-specific; it relies on the application
    having sufficient information to be able to undo the effects of each
    step in a failed operation.
  • 填补论理是不便于普及的。补偿工作是应用程序特定的,它依靠于应用程序有丰硕的新闻,可以取消五回破产的操作中的每一步的震慑。
  • You should define the steps in a compensating transaction as
    idempotent commands. This enables the steps to be repeated if the
    compensating transaction itself fails.
  • 你应有定义一个补给工作为幂等的一声令下。那使得可以再度的步子,倘诺补偿本身败北。
  • The infrastructure that handles the steps in the original operation,
    and the compensating transaction, must be resilient. It must not
    lose the information required to compensate for a failing step, and
    it must be able to reliably monitor the progress of the compensation
    logic.
  • 拍卖在本来操作中的步骤和增补工作的基础必须是有弹性的。它无法失去所需的音讯以弥补一个受挫的手续,它必须可以可信地监测补偿论理的长河。
  • A compensating transaction does not necessarily return the data in
    the system to the state it was in at the start of the original
    operation. Instead, it compensates for the work performed by the
    steps that completed successfully before the operation failed.
  • 补充工作不必重返到原来操作起来时的系统中的数据。相反,它弥补了办事成功的步调,在操作败北从前形成的行事。
  • The order of the steps in the compensating transaction does not
    necessarily have to be the mirror opposite of the steps in the
    original operation. For example, one data store may be more
    sensitive to inconsistencies than another, and so the steps in the
    compensating transaction that undo the changes to this store should
    occur first.
  • 在补充工作中步骤的顺序不自然是在原先的操作步骤的镜像。例如,一个数码存储可能比另一个更是敏感,由此,在补偿工作中,撤废对该存储的改观的步子应该率头阵出。
  • Placing a short-term timeout-based lock on each resource that is
    required to complete an operation, and obtaining these resources in
    advance, can help increase the likelihood that the overall activity
    will succeed. The work should be performed only after all the
    resources have been acquired. All actions must be finalized before
    the locks expire.
  • 在每一个资源上放置一个长时间的超时锁,来成功一个操作,并提前收获那么些资源,可以扶助扩大全部活动的可能性。所有的资源都被买断后,才开展那工作。所有行动必须在锁到期前形成。
  • Consider using retry logic that is more forgiving than usual to
    minimize failures that trigger a compensating transaction. If a step
    in an operation that implements eventual consistency fails, try
    handling the failure as a transient exception and repeat the step.
    Only abort the operation and initiate a compensating transaction if
    a step fails repeatedly or irrecoverably.
  • 考虑选择重试逻辑,经常是的更易于的,以压缩故障,触发一个填补工作。即便在一个操作中落成最后的一致性的步骤失利,试着处理故障作为一个暂时的非常,然后再一次步骤。只有废弃操作,假如一个手续战败或者频仍地开行补偿工作。

Note:

Many of the challenges and issues of implementing a compensating
transaction are the same as those concerned with implementing eventual
consistency. See the section Considerations for Implementing Eventual
Consistency in the Data Consistency
Primer
for more
information.

When to Use this Pattern 何时利用那种情势

Use this pattern only for operations that must be undone if they fail.
If possible, design solutions to avoid the complexity of requiring
compensating transactions (for more information, see the Data
Consistency
Primer
).

利用此方式仅用于操作必须是只要她们不可能收回。如若可能的话,设计缓解方案以幸免复杂的渴求补偿工作(越来越多新闻,见数据一致性引物)。

Example 例子

A travel website enables customers to book itineraries. A single
itinerary may comprise a series of flights and hotels. A customer
traveling from Seattle to London and then on to Paris could perform the
following steps when creating an itinerary:

一个游历网站,使客户定购行程。一个单纯的路途可概括一多重的航班和酒店。一位顾客从塞尔维亚Bell格莱德到London,然后到法国巴黎,在成立行程时,可以执行以下步骤:

  1. Book a seat on flight F1 from Seattle to London.
  2. Book a seat on flight F2 from London to Paris.
  3. Book a seat on flight F3 from Paris to Seattle.
  4. Reserve a room at hotel H1 in London.
  5. Reserve a room at hotel H2 in Paris.

预约一张从格拉茨到London的航班F1。
预约一张从London到法国巴黎的航班F2。
预约一张从法国巴黎到天津的航班F3。
储备在London一间旅社H1。
在法国首都饭庄预定一个屋子。

These steps constitute an eventually consistent operation, although each
step is essentially a separate atomic action in its own right.
Therefore, as well as performing these steps, the system must also
record the counter operations necessary to undo each step in case the
customer decides to cancel the itinerary. The steps necessary to perform
the counter operations can then run as a compensating transaction if
necessary.

那一个步骤构成最后一致性操作,即便每一步基本上是在大团结的义务单独的原子动作。由此,以及在实施那个步骤时,系统还非得记录须求撤废在情形下,客户决定撤除行程的各样步骤中的计数器的操作。然后必须执行计数器操作步骤可以在须求时运行补偿性事务。

Notice that the steps in the compensating transaction might not be the
exact opposite of the original steps, and the logic in each step in the
compensating transaction must take into account any business-specific
rules. For example, “unbooking” a seat on a flight might not entitle the
customer to a complete refund of any money paid.

请小心,在补偿工作的步骤可能不是本来的步调完全相反,并且在补偿工作的各样步骤都必须考虑到任何特定的政工规则逻辑。例如,“订舱”在航班上的席位可能没有身份客户开发的其他款项全额退款。

亚洲必赢app在哪下载 1

Figure 1 – Generating a compensating transaction to undo a long-running
transaction to book a travel itinerary

图1 – 生成补偿事务取消长日子运作的事体预约旅游行程

Note:

It may be possible for the steps in the compensating transaction to be
performed in parallel, depending on how you have designed the
compensating logic for each step.

有可能在补充工作的步骤并行取决于你怎样筹划用来每个步骤中的补偿论理被实施。

In many business solutions, failure of a single step does not always
necessitate rolling the system back by using a compensating transaction.
For example, if—after having booked flights F1, F2, and F3 in the travel
website scenario—the customer is unable to reserve a room at hotel H1,
it is preferable to offer the customer a room at a different hotel in
the same city rather than cancelling the flights. The customer may still
elect to cancel (in which case the compensating transaction runs and
undoes the bookings made on flights F1, F2, and F3), but this decision
should be made by the customer rather than by the system.

在广大事情解决方案,单步的挫折并不总是必不可少采用补偿工作滚动系统復苏。例如,具有预订航班F1,F2和F3在游历网站情景客户不能预约时客栈H1若是-之后,最好是能为客户提供在同一个都会的屋子在不一样的小吃摊而不是吊销航班。客户依然可以选拔裁撤(在那种景观下,补偿工作中运行,并打消关于航班F1,F2和F3作出的预约),但该决定应由用户,而不是由系统开展。

Related Patterns and Guidance 相关格局和指引

The following patterns and guidance may also be relevant when
implementing this pattern:

  • Data Consistency
    Primer
    . The
    Compensating Transaction pattern is frequently used to undo
    operations that implement the eventual consistency model. This
    primer provides more information on the benefits and tradeoffs of
    eventual consistency.
  • Scheduler-Agent-Supervisor
    Pattern
    .
    This pattern describes how to implement resilient systems that
    perform business operations that utilize distributed services and
    resources. In some circumstances, it may be necessary to undo the
    work performed by an operation by using a compensating transaction.
  • Retry
    Pattern
    .
    Compensating transactions can be expensive to perform, and it may be
    possible to minimize their use by implementing an effective policy
    of retrying failing operations by following the Retry pattern.

More Information 越来越多新闻

发表评论

电子邮件地址不会被公开。 必填项已用*标注

网站地图xml地图
Copyright @ 2010-2019 亚洲必赢app官方下载 版权所有