当前位置:网站首页>Talk about the SQL server version of DTM sub transaction barrier function
Talk about the SQL server version of DTM sub transaction barrier function
2022-07-04 05:22:00 【catcherwong】
background
I wrote two articles on how to use it C# be based on DTM Make it easy SAGA and TCC Of distributed transactions , There is a sub transaction barrier function , Good handling of null compensation 、 Hang 、 Repeated requests and other abnormal problems .
But the previous examples are based on mysql Of , It was asked if other databases were supported .
Obviously this is supported , Relational databases , except mysql, And support pgsql and sql server .
Some existing systems , There must be a lot more based on sql server Developed , If this batch of systems want to access DTM, There is no need to move the database first and then access .
So next , Lao Huang will take you through the experience based on sql server Version of DTM Sub transaction barrier function .
The example will be based on the previous SAGA Examples of transformation .
Sub transaction barrier table
Use the sub transaction barrier first , It is essential to prepare a sub transaction barrier table , So this sub transaction barrier table should be placed under the database of that instance ?
All you need to do here is make sure , The business data to be operated and the sub transaction barrier can be in the same local transaction .
The following is for SQL Server Table of SQL.
IF EXISTS (SELECT * FROM sysobjects WHERE id = object_id(N’[dbo].[barrier]’) and OBJECTPROPERTY(id, N’IsUserTable’) = 1)
BEGIN
DROP TABLE [dbo].[barrier]
END
GO
CREATE TABLE [dbo].[barrier]
(
[id] bigint NOT NULL IDENTITY(1,1) PRIMARY KEY,
[trans_type] varchar(45) NOT NULL DEFAULT(''),
[gid] varchar(128) NOT NULL DEFAULT(''),
[branch_id] varchar(128) NOT NULL DEFAULT(''),
[op] varchar(45) NOT NULL DEFAULT(''),
[barrier_id] varchar(45) NOT NULL DEFAULT(''),
[reason] varchar(45) NOT NULL DEFAULT(''),
[create_time] datetime NOT NULL DEFAULT(getdate()) ,
[update_time] datetime NOT NULL DEFAULT(getdate())
)
GO
CREATE UNIQUE INDEX[ix_uniq_barrier] ON[dbo].[barrier]
([gid] ASC, [branch_id] ASC, [op] ASC, [barrier_id] ASC)
WITH(IGNORE_DUP_KEY = ON)
GO
Copy code The key here is the unique index , There is one IGNORE_DUP_KEY = ON. This is actually for equivalence mysql Of insert ignore.
In fact, the preparatory work has already been completed here .
Here is an example after the transformation , Not much to do , Just switch some configurations .
Switch configuration
To be in InApi Which specifies the sub transaction barrier Database type and Custom table name .
Perform the following configuration before startup
// Appoint Sub transaction barrier The database type is sql server
Dtmcli.DtmImp.DbSpecialDelegate.Instance.SetCurrentDBType("sqlserver");
// Appoint Table name of the sub transaction barrier table
Dtmcli.BranchBarrier.SetBarrierTableName("[test].[dbo].[barrier]");
Copy code For the table name , Lao Huang suggested adding the name of the library .
PS: This setting should be put into the configuration file later , At this stage, it is basically to maintain and go The version is written in a similar way .
Last but not least is to change the connection string and SqlConnection 了 .
public class Db
{
private static readonly string _conn = "Data Source=127.0.0.1, 1433;Initial Catalog=test;user id=dev;password=123456;TrustServerCertificate=True;";
public static DbConnection GeConn() => new Microsoft.Data.SqlClient.SqlConnection(_conn);
}
Copy code Come here , All the transformation has been completed . Let's take a look at the specific example demonstration .
Example demonstration
Here's a demonstration of Talk about how to use it C# Easily complete a SAGA Distributed transactions There are two problems: null compensation and idempotence .
Let's look at the short compensation .
Let's look at idempotent
The log output and behavior effect are basically consistent .
Finally, look at the data in the database
At the end
In this article , Describes how to use in the sub transaction barrier SQL Server As underlying storage . I hope it will be helpful for you to study distributed transactions .
Sample code of this article : DtmMsSqlSample
Reference material
Follow my public number 「 No, Lao Huang 」, I will share what Lao Huang has seen and heard with you for the first time .
边栏推荐
- Supplement the JS of a video website to decrypt the video
- Flink1.13 SQL basic syntax (I) DDL, DML
- IP时代来临,电竞酒店如何借好游戏的“东风”?
- 2022年A特种设备相关管理(电梯)考试题模拟考试平台操作
- Etcd database source code analysis - initialization overview
- [matlab] matlab simulation modulation system SSB system
- Thread pool: use thread pool to optimize query speed
- Zhongke Panyun - data analysis and forensics packet flag
- How to build your own knowledge engine? Community open application
- Flutter ‘/usr/lib/libswiftCore. dylib‘ (no such file)
猜你喜欢
![[wechat applet] template and configuration (wxml, wxss, global and page configuration, network data request)](/img/78/63ab1a8bb1b6e256cc740f3febe711.jpg)
[wechat applet] template and configuration (wxml, wxss, global and page configuration, network data request)

Flutter calls Gaode map app to realize location search, route planning and reverse geocoding

Build an Internet of things infrared temperature measuring punch in machine with esp32 / rush to work after the Spring Festival? Baa, no matter how hard you work, you must take your temperature first

ping端口神器psping

Useful plug-ins for vscode
![[QT] timer](/img/df/5db6af851ef19f33fd7e7a7ed46586.png)
[QT] timer

补某视频网站的js,进行视频解密

2022年A特种设备相关管理(电梯)考试题模拟考试平台操作

June 2022 summary

Trie number dictionary tree
随机推荐
[matlab] matlab simulation modulation system FM system
Void convolution, deformable convolution, deformable ROI pooling
flink1.13 sql基础语法(一)DDL、DML
[paper summary] zero shot semantic segmentation
Customize a pager needed in your project
[技术发展-25]:广播电视网、互联网、电信网、电网四网融合技术
Detailed comparison of Hynix emmc5.0 and 5.1 series
laravel 中获取刚刚插入的记录的id
Simulink and Arduino serial port communication
Get the ID of the record just inserted from laravel
Simulink与Arduino串口通信
补某视频网站的js,进行视频解密
LM small programmable controller software (based on CoDeSys) note 22: error 4268/4052
2022 t elevator repair operation certificate examination question bank and simulation examination
How to use postman to realize simple interface Association [add, delete, modify and query]
LM小型可编程控制器软件(基于CoDeSys)笔记二十一:错误3703
Evolution of system architecture: differences and connections between SOA and microservice architecture
力扣(LeetCode)184. 部门工资最高的员工(2022.07.03)
Exercise bubble sort
Notepad++--显示相关的配置