The design pattern of cloud computing (III.)--Compensation trading mode

Source: Internet
Author: User

the design pattern of cloud computing (III.)--Compensation trading mode
undobya series of steps, they jointlylimits thefinally consistentoperation, assume thataor more stepsfailedrun the work. according tofinally consistentmodel,BusinessImplementComplex BusinessProcesses and workflowsThe Cloudhosted ApplicationsChina and Africa often see。


Background and problem



in the Cloud running the application Frequent Change Data .

this Data can cross in various Location of The data that is maintained Source of the a Variety spread.

to avoid contention , and Improve in a distributed environment , such as This performance , the application should not try to provide Strong transactional consistency. Instead, the application should achieve finally consistency .

in thein this model,A typical businessOperationby a series ofof theindependent ofstep. andare running theseStepsof thesystemStatusof theOverall Diagramit could be inconsistent.. However, whenOperation CompleteandAll Stepshave been run. System shouldonce again becameconsistent.



Note:

consistency of dataprovides aGetting StartedWhyDistributed Transactionsdoes not extend very wella lot of otherInformation,andConsolidatethefinally consistentModelthe principle.



in thefinally consistentmodel ofasignificantlythe challenge ishow to deal withfailednot to be undonethe next step. in thesuch a case, you may need toUndo AllthroughIn the operation ofthe previous stepsthe work completed. However, the datacannot simplybe rolled back, because the applicationof theotherConcurrent Instancesmay havechange, asit. even indata has not beenthroughaConcurrencyExampleChangethe case. undoaStepsprobably not .Simple toRestore OriginalStatusthe problem. may needapply a different businessSpecific Rules(SeeExamples of embodimentspart of the description of the narrativeTravelsite).



Assuming implementation finally consistent Operation spanning multiple Heterogeneous data Storage . Unlocking The steps in This operation will require access to each data store in the turn. the work that runs in each data store must be reliably restored to Prevent inconsistencies in the rest of the system .

not affected by Implement finally consistent the Operation all the data may be in the database proceed.

in the Service-Oriented architecture ( SOA ) in the environment the Operation may be called a Service Action , and cause by the service Keep changes in State .

to undo of the Operation , such a state the Change must also be Undone . This may involve Invoking the service again and running the first effect of the reversal There's one more action .

How to solve



Implementation Compensation Transactions . in a compensating transaction , the steps must be undone for the original operation The impact of the steps .

Compensation Transactions may not Simple to with the national of the system in the Execution , since such a method may be overwritten by the other application Concurrent Instances The changes that you made Start instead of the immediate state.

instead, it must be a the Smart in the process . Take into account whatever work is done in the concurrency situation . This process is typically application-specific and is performed by the original Operation . The nature of the work to drive.



a common approach come to Implement of the , finally consistent the operation. The required compensation is the workflow used . because the original action is carried out. the system records each step , and how to pass This step The finished work can undo the information .

Assuming that the operation failed, at whatever time , in the workflow Inverted Roll back through it's finished . the steps . and run reverse every step of the work. attention. Compensating Transactions may not undo The exact mirror of the original operation the reverse order works , and it may run some parallel Undo Step .



Note:

such a method similar to Legendary Heroes policy.

This strategy Descriptive Narrative of is a Clemens vasters 's Blog available on-line.





Compensation Transactions itself is a finally consistent with Operation . It may also fail . The system should be able to resume compensating transactions at the point of failure and continue.

may be necessary repeated The problem occurs Steps , so in Compensation Transactions the steps should be defined as Power, etc. 's command. for Specific information about idempotent , please refer to Jonathan Oliver's blog Power, etc. Mode ??。



in the in some cases, may not from the has failed , unless through Manual Intervention the steps in the recovery.

in such a case , the system should issue an alert , and provide as many Information as Understand Failure of cause.

Issues and considerations



in deciding How to achieve this mode , please consider The following points :
? It may not be easy determine when in implementing finally consistent the action of Steps has failed. A step may not fail immediately , but it can prevent .

may be necessaryTo achieve some form ofof theTimeout mechanism.
?compensationLogic does notEasy Promotion. Compensation Transactionsis aApplication-specific;it relies onhaveenough information. So that you canundoin theafailed Actionseach step ofthe effectof theApplication.
? Youshould definethe stepsin theCompensation Transactionsof thePower, etc.command. this makes, assumingCompensation Transactionsitselfcan'tbe repeatedthe steps.
?processinginOriginal Operationthe steps. As wellthe saidCompensation Transactionsof theBasic Facilities. must beresilient. itmust notlost, to compensateThe problem occursStepsThe need forInformation, and it mustcan bereliably toMonitoringcompensation Logicthe progress.
? ACompensation Transactionsdoes not necessarilyin the systemReturn Datathe Stateis ain theOriginalStart of Operation.

instead. It compensates for by that completed successfully operation failed before The work of is run in the step.
? in Compensating Transactions Steps in The is not in the order must be Mirrors instead of , in the original action The steps for the . such as . One data store can be inconsistent than there is another more sensitive, thereby undo Changes to the store in the Compensating Transactions Steps for should first occurs .


? in finished Action Required Each resource for Placement one Short-term time-out-based Lock, and in advance Get these resources , to Help Add the likelihood of . The overall activity succeeds . This work should run all resources are acquired .

All actions must complete lock expires before .
? Consider using retry logic more than normal many other tolerant . Minimize triggering compensating transactions failed . assume an action step . To implement finally consistency failed, try process failure for an over exception, and repeat above Steps . has only abort operation . Suppose a step repeats or irrevocably failed, start Compensating Transactions .





Note:

very much of the Challenges and Implementation Compensation Transactions of the problem is same Care Implement finally consistent . Please refer to the note for The consistency of the data. Getting Started finally consistent A lot of other information.


whenUsethis mode



Use this Mode only available for Suppose they fail . . The action that must be undone .

assuming it's possible. , Design Solutions, avoids the need Compensation Transactions the complexity (for specific information , please read Data Consistency Primer ) .

Sample Example

a Tourist Sites . Make the customer book a trip.

a single Itinerary can contain a range of Flights and hotels of the . A customer travels from Seattle to London and Paris to create A trip , run the following steps :
1. Booking a seat on the F1 Flight from Seattle flights to London .
2. Booking a seat on the F2 Flight from London to Paris .


3. Booksoccupying seatF3Flightfrom Parisflights to Seattle.
4. Bookingthe roomin theLondon hotelsH1.
5. Bookingin ParisaGuest Roomof HotelsH2.

these stepsconstitute afinallyconsistent withOperation, thoughevery stepis basicallyin their own righta separateAtomic Operation. so,as wellWhen you run these stepswhen the systemmust alsoRecordnecessaryundoeachIn caseCustomer DecisionCancelItineraryStepscounterthe operation. necessary OperationcounterOperationstep. then be able toas aCompensation Transactionsif necessaryrun.

Please note that theCompensation Transactionsthe steps inprobably not .the originalStepstotally the opposite .,and inCompensation Transactionseach one ofStepsmust take into account theno matter whatBusiness-specificLogical Rules. like. "unbooking Cancel Reservation"seatson theFlightmay benot a customerhavetoPaymentno matter what the moneyRefund Completed.

watermark/2/text/ahr0cdovl2jsb2cuy3nkbi5uzxqvewfuz3pozw5waw5n/font/5a6l5l2t/fontsize/400/fill/i0jbqkfcma==/ Dissolve/70/gravity/center ">

Figure 1 - Build a Compensation Transactions undo a long-time execution of transactions Booking Travel Itinerary

Note :

It may be in the Parallel Run of the Compensation Transactions the steps . It depends on how you design the compensation logic for each step .





in themanyBusiness Solutions. in a single-stepfailure does notalwaysnecessaryRollingSystem BackwithCompensation Transactions. For example, havingin theTourist Sitesthe situation. Customer iscan'tBookingto the HotelH1BookingFlightF1,F2 and F3words. later. Better beprovideCustomerin the same citythe roomin theDifferent hotelsand notCancelflight. Customercan stillSelect Cancel(in thesuch a case,Compensation TransactionsExecution. and undomadeabout FlightsF1,f2and theF3 in theBooking). Butthe decisionshould beby the customerand not bysystemproceed.

This article is translated from msdn:http://msdn.microsoft.com/en-us/library/dn589804.aspx

The design pattern of cloud computing (III.)--Compensation trading mode

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.