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 .
https://dtm.pub/practice/barrier.html
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
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]");
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);
}
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
Talk about it DTM Sub transaction barrier function SQL Server More related articles in
- Cloud database RDS SQL Server edition
Cloud database RDS SQL Server Version is a flexible online database service , And has automatic monitoring . Backup . A complete set of solutions for disaster recovery , Thoroughly solve the trouble of database operation and maintenance Please watch the video introduction SQL Server It is the earliest distributor ...
- [ turn ]JIRA 7.2.6 And Confluence 6.0.3 Installation and configuration of MS SQL Server edition
Relevant software version information explain : The software below can click the link , Download through Baidu cloud disk . operating system :Windows 10( password :foht) perhaps Windows Server 2012( password :lsad): database :SQL S ...
- According to the database help class, insert the picture into sql server In the database
We define the database as image type , Then read the picture as a character stream , And then save it in the database , First, we define a public class for reading pictures , This public class will be used later , So you can create corresponding help classes public static byte[] Rea ...
- use ArcMap Release ArcGIS Server Feature Server Feature Access service SQL Server edition
1. install Desktop, 2. install ArcGIS Server 3. install SQLServer2017 4. ArcMap in Catalog Register in ArcGIS Server 5. System T ...
- Everyone is DBA(VI)SQL Server Transaction log
SQL Server Database engine through transaction services (Transaction Services) To provide a transaction ACID Property support .ACID Properties include : Atomicity (Atomicity) Uniformity (Consisten ...
- sql server In the lock Transaction lock Update lock Keep the lock Shared lock You know what? ?
Lock a table in the database SELECT * FROM table WITH (HOLDLOCK) Be careful : The difference between locking a table in a database SELECT * FROM table WITH (HOLDLOCK) Its ...
- SQL SERVER The past and this life -- Function comparison of different versions
background Today's Data Amp At the conference , Microsoft emphasized to developers that How data affects their applications and services , By the way, I also announced a few small news . This free webinar not only shows the future of machine learning , Also released SQL Serve ...
- SQL Server Transaction isolation level
One . The transaction isolation level controls the following performance of transactions : Whether the lock is occupied when reading data and the type of lock requested . Take up the time to read the lock . Whether the read operation of the row modified by referencing other transactions : Block other transactions before the exclusive lock on the row is released . Retrieve the starting statement or transaction ...
- SQL Server 2008 Medium CDC(Change Data Capture) Function use and explanation
SQL Server 2008 Medium CDC(Change Data Capture) Function use and explanation key word :CDC original text :http://www.cnblogs.com/chenxizhang/arc ...
- SQL Data synchronization to ELK( Four )- utilize SQL SERVER Track Data Related functions synchronize data ( On )
One . The related documents Old rules , To avoid my explanation misleading you , Please know more about it through the official website SQL SERVER Related functions . Document address : The overall introduction document :https://docs.microsoft.com/en-us/ ...
Random recommendation
- summary -eclipse
1.eclipse Of workspace Historical record open eclipse/configuration/.settings/org.eclipse.ui.ide.prefs, hold RECENT_WORKSPACE ...
- stay CentOS It's the most ^1024 Basic Nginx Reverse server
Yesterday, a former colleague suddenly asked me , He was in CentOS7 In the last experiment, the reverse server was not built successfully . Now let's share the simplest construction steps : 0. Introduction to the environment This cluster includes the following servers 192.168.1.107:nginx Reverse server ...
- -bash: rz: command not found
rz,sz yes Linux/Unix Same as Windows Conduct ZModem Command line tools for file transfer . The advantage is that there is no need to open another one sftp Tools log in to upload and download files . sz: Send selected files (send) To local machine rz: Run the command ...
- PLSQL Go to Oracle After the database is inserted into Chinese, it becomes a question mark and start-up PLSQL Prompt when NLS_LANG In the client can not determine the solution
PLSQL Go to Oracle After the database is inserted into Chinese, it becomes a question mark and start-up PLSQL Prompt when NLS_LANG In the client can not determine the solution 1. Check the server's character encoding Select * from V$NLS_PARAMETE ...
- hdu2007
import java.util.*;class Main{public static void main(String args[]){Scanner cin=new Scanner(System. ...
- [ turn ] Closure of functional programming (Closure)
Closures are often used in function programming . What is a closure , How did it come into being and what problems did it solve . Give a literal definition First : A closure is an entity composed of a function and its associated reference environment ( namely : Closure = function + Citation environment ). This is difficult to understand literally , Especially for one ...
- stay Blade Combination of Chinese and Western Medicine gperftools Check for memory leaks
Blade We developed a large-scale C++ Project building tools . gperftools yes google Developed performance tools , By efficient memory allocator ,CPU Performance Analyzer , Heap Analyzer , Heap checker and other tools . Unlike other build tools , combination gtes ...
- Two hosts ,ssh Different ports , How to copy files
A host ip:172.26.225.199 ssh port 12995 B host ip:172.26.225.200 ssh port 12991 take B Copy the files of the host to A host [[email protected] s ...
- u-boot transplant ( 8、 ... and )--- Code changes --- Storage controller --MMU
One .MMU Introduce 1.1 Virtual address and physical address Build two applications ,hello1.c and hello2.c, And then run : hello1.c hello2.c The operation results are as follows : You can see that the addresses of the two results are the same , all ...
- LeetCode22. Bracket generation JavaScript
give n Represents the logarithm of the generated bracket , Please write a function , Make it possible to generate all possible and valid combinations of parentheses . for example , give n = 3, The generated result is : [ "((()))", "(()())& ...