Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What is the LCN distributed transaction framework?

2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/02 Report--

This article mainly explains "what is the LCN distributed transaction framework". The content of the article is simple and clear, and it is easy to learn and understand. Please follow the editor's train of thought to study and learn what the LCN distributed transaction framework is.

Today, I stumbled upon a distributed transaction framework, LCN, which is very powerful after reading the online introduction. Take notes here.

I. Environmental basis

The foundation of the LCN framework requires a server as a transaction manager TxManager, as well as Redis and Eureka to cooperate. Eureka is responsible for registering for TxManager, and redis is mainly used for TxManager to store transaction group and compensation information.

Second, the roles involved in a firm

Transaction initiator service

TxManager transaction Manager

Transaction downstream services (there may be multiple)

Third, principle

TxManager is based on local transactions, and here is the concept of a transaction group, which is a collection of local transactions for all the microservices involved.

Its main principle is that through rewriting the close method of dataSource, its own close method needs to close the local transaction, but it does not close the transaction after rewriting, but records the transaction information in the redis of txmanager, and waits for the transaction initiator to notify each service that the local transaction is committed or rolled back when the service execution is completed or abnormal. In the proxy connection pool, not all transactions are committed untruthfully, it can automatically recognize the read or write operation of the connection, and if it is all read operation, it will return the local connection object. If the method is executed repeatedly, the connection can also be reused, and there is also a timeout limit. The participating module will automatically commit or roll back when it waits for notification timeout. (it is not clear whether it is committed or rolled back. It is doubtful for the time being. But look at the compensation mechanism below. It seems to be automatic submission. )

TxManager is similar to two-phase commit, except that the transaction initiator and transaction manager of two-phase commit are on the same machine, while TxManager is used as independent middleware.

IV. Transaction compensation

Transaction compensation means that when the transaction initiator service is abnormal or normally executed, the request closed by the transaction group is sent to TxManager, and the TxManager notifies the downstream service to roll back or commit the transaction. This step in the two-phase model does not solve the problem of whether the end transaction operation can be correctly committed to the resource management side. An automatic compensation mechanism is provided in LCN.

First, take a look at the TxManager background page:

Here, there are two items worth noting. The first is the compensation callback address, which is the callback address of the transaction information to the transaction initiator service when TxManager sends a notification to the downstream service to roll back or commit the transaction failed. The second item is whether automatic compensation is enabled. If compensation is not enabled, TxManager will still call back. How is automatic compensation realized? First, TxManager calls back the transaction initiator service (carrying transaction information and aspect blocking information), then the transaction initiator writes an operation of repeating business in the callback method, which will still simulate the last request. However, for services that have successfully notified commit last time, you need to roll back this time, and only those services that have failed to notify require commit.

5. Summary

Git address: https://github.com/syzpig/tx-lcn

Demo address: https://github.com/codingapi/springcloud-lcn-demo

Official document address: https://txlcn.org/zh-cn/docs/preface.html

Lcn supports springcloud and dubbo. Pull down the demo code of springcloud and see how to use it. After setting up the environment, you only need to use @ TxTransaction (isStart = true) annotation in the transaction initiating method, and then use @ TxTransaction in the downstream service method. The method is very simple, and the code intrusion is very low, so it is recommended.

In addition, it is mentioned that for the form of message queue asynchronous invocation, this framework does not satisfy transaction consistency and needs to be combined with other schemes.

It is found that TCC and TXC modes are also supported in the latest version of Lcn ~

Thank you for reading, the above is the content of "what is the LCN distributed transaction framework". After the study of this article, I believe you have a deeper understanding of what the LCN distributed transaction framework is, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!

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.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report