Two or three things you know about a business from a real scene

Source: Internet
Author: User

Real-world scenario: in the company-to-consumer app testing process, the front-end test found a bug--from the virtual wallet transfer to the successful collection, the virtual wallet amount no deduction
1. The misunderstanding of cognition one: the resources in the transaction can be rollback.

The problem code logic is as follows

// Pseudo Code begin translation // Call the Payment interface boolean callresult= remote.transf (...); if (callresult) {   // operations Local Database   boolean payresult= local.pay (...);    if (Payresult)   {      commit;   }    Else    {     rollback;   }} Else {  Rollback}end translation



problem reason : The transfer interface does not support rollback for the caller, so this is a "pseudo transaction",
The real transaction should be whether it is a local transaction or a distributed transaction
The resources associated with any of the resource managers involved in a transaction are support for commit and rollback;

Resolution : Adjust the call order

// Pseudo Code begin translation // operation Local Database Boolean callresult = local.pay (...); if (callresult) {   // Call the Payment interface   boolean payresult= remote.transf (...);    if (Payresult)   {      commit;   }    Else    {     rollback;   }} Else {  Rollback}end translation


2. Misunderstanding two: The business is effective
Http://www.cnblogs.com/xiaoyuanding/p/3947986.html

Distributed transactions can be simplified to local transactions
Does simplifying work for local transactions?
Because the operation of deleting files is called two times, the local transaction does not work regardless of how the call order is adjusted, so the use of transactions is the same as without transaction results

Solution: Delete the file with the persistent Message Queuing post message or the timed task + message Status field, and, if unsuccessful, retry continuously until successful.

Two or three things you know about a business from a real scene

Related Article

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.