Understand seata distributed transactions

1. If I have nothing to do on weekends, I want to know about the seata framework. First, run through the example 1 provided by its official website.
Because I already have a k8s cluster, I will follow the k8s installation steps for a highly available server. About the working principle of seata, you can go to Official website understanding: seata official website address . Note that if you use the latest docker image, the parameter settings in the official website steps will not take effect. By using the docker cp command to copy the image to the local, you will find that it has used the yaml file to set the parameters.
2. The working mode of seata service:
insert image description here

3. All services avoid single point of failure. Seate has three modes, file, db, and redis. I choose the database mode here, and change it to the redis mode for later stress testing. The redis mode is highly efficient. Service registration uses nacos, you can modify it according to your needs.
4. For deployment on k8s, I modified the version number 1.4.2 and registered the seata service to nocas. Some yaml files are as follows: 5.
insert image description here
Nocas service construction, which can be seen from the official website, is also the k8s method, the result of successful deployment As follows:
insert image description here
From the figure above, you can see that mysql also has one master and two slaves. The seata service is provided by three instances. Both nacos and mysql are stateful pods (statefulSet). Then expose this service for external use through ingress. If you only use it inside the k8s cluster, you can use the service directly. The interface between the ingress service and the browser access is as follows: After we log in, we can check whether the service on the seata server has been successful
insert image description here
insert image description here
. The registration went up. In production, the seata service should be a separate cluster and provided externally as a service. Remember that before running and registering seata, you need to add the parameters to nacos according to the steps on the official website. The official website provides a script to directly import. After the import is successful, the interface is as follows: modify the store.mode=db inside, and modify the parameter store
insert image description here
inside .db.url is the mysql database deployed above.
When the seata-ha-server service runs successfully, you can see its registration information in nacos, and you will see that there are 3 instances of the seata-server service to provide services: 6. Now that the seata server has been configured, it can
insert image description here
provide Control of distributed transaction services.
7. Let's take an example from the official website of seata to test this service. I have taken a spring-boot and dubbo example from github and pulled it locally
insert image description here
Because I use jenkins to deploy directly to k8s, I directly add the deployed yaml to the code management, as shown in the figure below:
insert image description here
Refer to the configuration of the client on the official website of seata, and add an undo_log table to each module, as shown in the figure below:
insert image description here
After modifying the relevant configuration, submit the code to github, test the code , and then open jenkins. You can also set jenkins to build regularly. The interface is as follows:
insert image description here
you can update, build and deploy a module individually, or you can update and deploy the entire project ( my-parallel2), the pods running after deployment are as follows:
insert image description here
You will find that there are four deployments: account-deployment, logic-deployment, order-deployment, storage-deployment, and whether the service of our current module has been registered to nacos Now, pay attention to the registration of the seata client in your code. You also need to specify nacos, and specify the nacos address. After the seata client registers nacos successfully, as shown in the figure below: You can find the provider, consumer, and each module here
insert image description here
. Only one instance is deployed, and you can cut and expand at will. This is the advantage of K8s. We can look at the management interface of the k8s background: we can
insert image description here
also see the running status of each service from the k8s management console.
8. Now we can test whether this test can be used normally. I use postman to send a request to http://logic.yuanzhibin.com:9080/business/dubbo/buy, and the transaction is successful:
insert image description here
9. Let’s check the status of the database order , can it match the account, amount, and inventory? When testing, we can make it fail every 10 transactions:
insert image description here
10. In the next chapter, we will introduce service idempotence, reference redis, introduce caching, and use jmeter to test the pressure For this seata service, measure its transaction throughput.

Guess you like

Origin blog.csdn.net/u013326684/article/details/123316639