In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/02 Report--
In this issue, the editor will bring you solutions about what is micro-service architecture and distributed transactions. The article is rich in content and analyzes and describes it from a professional point of view. I hope you can get something after reading this article.
Among the four isolation levels of transactions, read uncommitted is the lowest, there is no guarantee that read committed can avoid dirty reading repeatable_read can avoid dirty reading, unrepeatable reading Serializable can avoid dirty reading, unrepeatable reading and phantom reading the four characteristics of transactions atomicity in computer programs, atomicity means that the operation of a group of data is indivisible as a whole. Consistent classic transfer instructions, A to B10000, then An account less than 10000, B account more than 10000, can not appear B account more than 10000 yuan, and the amount of An account has not changed isolation or that transfer example shows that A to B transfer 10000, C to D transfer 50000 QAB, CD these two groups are directly unrelated, is isolated. Persistence is persistence, and there's nothing to say about it. Seven Propagation behaviors of transaction propagation_requeired if there is a transaction, the current transaction is supported, if there is no transaction, a new transaction is opened propagation_supports if there is a transaction, support the current transaction, if there is no transaction, then non-transaction execution, but for transaction synchronous transaction managers, propagation_supports is slightly different from not using transactions propagation_mandatory if there is a transaction, support the current transaction If there is no active transaction, the exception propagation_requires_new always opens a new transaction, if a transaction already exists, the existing transaction is suspended propagation_never is always executed non-transactionally, if there is an active transaction, the exception propagation_not_supported is always non-transactional, and any existing transaction propagation_nested is suspended if an active transaction exists Is run in a nested transaction, and if there is no active transaction, the distributed transaction is executed according to the TransactionDefinition.PROPAGATION_REQUIRED property
Distributed transaction appears under the architecture of distributed architecture and micro-service. Distributed transaction is to process the transactions of multiple nodes as a whole.
Distributed transactions are generally composed of transaction participants, resource servers, transaction managers, etc.
What are the scenarios of distributed transactions in eg. Place orders, reduce inventory, pay
Distributed transaction does not emphasize transaction, it depends on the transaction mechanism of each single point, it emphasizes the distribution of transaction. How to solve distributed transaction
Realization idea
2PC 3PC, also known as two-segment, three-segment transactions
Distributed transaction based on XA
Final consistency Scheme based on message
TCC programming is to compensate for transactions (a more common distributed solution)
Two-stage transaction 2PC
Look at the figure. The first stage is a transaction manager. In the first stage, the transaction manager sends prepare commands to two resource managers. If one of the two resource managers does not have ready, you have to wait. Wait until both resource managers reply the ready command to the transaction manager, then the first phase is over. Next, in the second phase, the transaction manager sends a commit command to both resource managers, if both resource managers receive the command and commit the committed
Then the transaction is a set of transactions OK, but if one of them does not have a committed, then there is a problem. There are many other problems with this 2PC distributed transaction.
Let's take a look at 3PC.
Three-stage commit 3PC: a three-stage transaction adds a layer of "beforehand" > between the preparation and commit of the two-stage transaction.
2PC and 3PC are generally not used in formal distributed systems
Distributed transaction based on XA
The distributed transaction of xa is the evolution of 2PC.
Message-based consistency scheme
As shown in the figure below, An is the payment system, and B is the order system. A sends a preliminary message to mq,mq to receive the preliminary message to save, and returns to system A to say, "I mq has received your preparatory message, and you can execute your business logic." then system A starts to execute local transactions and sends a submission message to mq, and mq receives a submission message from system A (at this time the payment system has been paid) Mq sends a message to order system B, saying that system A has paid, you hurry to change the status of the order for me, and mq calls back to system A to let A do what needs to be done. Someone here may ask, what if system B fails to change the status of the order? Yes, what should we do? in fact, in fact, before system A sends a submission message, you can set up another thread and let it hang for a while. After suspending, you can tell system B that An is about to submit. Please change the status of the order immediately. When B has finished modifying the order status, A will submit the payment. If the B modification fails, A will roll back locally.
The message-based consistency scheme is a strong consistency scheme, which must succeed or fail at the same time, and nothing else will happen. the disadvantage is that the payment business of system A will be suspended, and B will wait until it is modified. but you can't afford to wait. Let's talk about TCC later.
TCC compensatory transaction T try, C confirm, C cancel Chinese simple explanation is: attempt to execute, confirm operation, cancel operation
If service An in the figure above is to deduct inventory, and service B is to create an order to deduct inventory to create an order, let's talk about TCC.
In the first step, app tells the transaction coordinator to start a transaction, then calls the try interface, service A try interface deducts inventory, and service B creates an order. Finally, app receives the execution result of the two try interfaces of AB. If one fails, app tells the transaction coordinator that the transaction just failed, you can call the Cancel interface; if both are successful, app tells the transaction coordinator to call the Confirm interface.
The core idea of TCC is resources, the core is in the Try phase, resources must be reserved (lock, version number, distributed lock, etc.), why must be reserved, if not reserved, it can not be compensated in the Cancel phase, which goes against the original intention of TCC design. If you do not have enough control over resources, it is not recommended to use TCC. If resources cannot be reserved, there is no optimistic lock, no status and other fields, you cannot reserve and you cannot use TCC.
Tcc compensatory and message-based distributed transaction tables
Message-based distributed transactions are strongly consistent, and there will be a waste of resources; because there will be waiting, the only biggest advantage is strong consistency. In actual business, you may have to dock Alipay, WeChat Pay, UnionPay and wait. This kind of informational transaction can still be used.
TCC emphasizes the reservation of resources in the try phase.
TCC releases resources during the confirmation and cancellation phases
If it is the confirmation phase, then delete the resources, if it is the cancellation phase, then we need to reverse the compensation of these resources.
With messaging transactions, TCC has high timeliness
This is what the editor shares with you about the micro-service architecture and the solution for distributed transactions. If you happen to have similar doubts, please refer to the above analysis to understand. If you want to know more about it, you are welcome to follow the industry information channel.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.