2022 year 5 month 24 Japan , We released DBPack v0.1.0 edition , This version mainly release Distributed transaction function . In our plan ,DBPack It is to support all microservice development languages to coordinate distributed transactions , But after community feedback ,dotnet core Does not support . therefore , We are v0.1.1 Yes dotnet core Supported . Here's how to support dotnet core Make a statement .
MySql agreement
First, please allow me to MySql A brief introduction to the communication protocol of .MySql Two protocols are supported , One is text (Text) agreement , One is binary (Binary) agreement .MySql Client side usage COM_QUERY Requests made ,MySql The server will respond to the result with text protocol ; Use COM_STMT_EXECUTE A request from a command , Will respond to the result in binary protocol .
Before we use the program to call MySql Client SDK When making a request , Different MySql Client SDK By default, different protocols will be used to send requests , But most MySql Client SDK Both support text protocol and binary protocol , We can modify the property configuration to change MySql Client SDK Default behavior of . such as :
- JAVA
@Mapper
public interface ProductMapper {
@Update("UPDATE /*+ XID('${xid}') */ `product`.`inventory` SET `available_qty` = `available_qty` - #{qty}, allocated_qty = allocated_qty + #{qty} WHERE product_sysno = #{productSysNo} AND available_qty >= #{qty}")
boolean allocateInventory(@Param("xid") String xid, @Param("productSysNo") long productSysNo, @Param("qty") int qty);
}
stay java In microservices written in , We wrote a method to modify the inventory of goods , When we pass in parameters to submit for execution , Default this SQL The request will be encoded as
update /*+ XID('gs/aggregationSvc/81336085455405058') */ product.inventory set available_qty = available_qty - 2, allocated_qty = allocated_qty + 2 where product_sysno = 1 and available_qty >= 2;
adopt COM_QUERY Give orders .
We can modify the connection string , In the original jdbc:mysql://dbpack2:13307/product Add up useServerPrepStmts=true, Change it to jdbc:mysql://dbpack2:13307/product?useServerPrepStmts=true, When executed again , Will be sent first COM_STMT_PREPARE request :
UPDATE /*+ XID('gs/aggregationSvc/2612341069705662465') */ product.inventory set available_qty = available_qty - ?, allocated_qty = allocated_qty + ? WHERE product_sysno = ? and available_qty >= ?
Get statement id after , then statement id And the request parameters are encoded and passed COM_STMT_EXECUTE Give orders .
- Golang
Golang MySql driver The default is to send with parameters in binary protocol DML Requested , By means of dsn Add parameters interpolateParams=true, Will be sent by text protocol . for example :
dksl:[email protected](127.0.0.1:13306)/employees?interpolateParams=true&timeout=10s&readTimeout=10s&writeTimeout=10s&parseTime=true&loc=Local&charset=utf8mb4,utf8
Dotnet Core
Dotnet core If you use EntityFrameworkCore perhaps Dapper To access the database , At present, the use of Prepared Statement, The next two issue There are relevant instructions :
https://github.com/dotnet/efcore/issues/5459
https://github.com/DapperLib/Dapper/issues/474
stay v0.1.0 edition , We are only right COM_STMT_EXECUTE The request is intercepted , To coordinate distributed transaction problems .dotnet core Use COM_QUERY Submitting a request naturally fails to coordinate distributed transactions , stay v0.1.1 We added COM_QUERY Request coordination support for distributed transactions , In this way, it really supports all microservice languages to coordinate distributed transactions .
dotnet core sample see :https://github.com/CECTC/dbpack-samples/tree/main/dotnet.
Other features
This issue , Also fixed some bug, Added status api Used for query dbpack Operating state :
$ curl http://localhost:9999/status
$ {
"listeners": [{
"protocol_type": "mysql",
"socket_address": {
"address": "0.0.0.0",
"port": 13306
},
"active": true
}],
"distributed_transaction_enabled": true,
"is_master": true
}
thus , We have it.
- /live
- /ready
- /status
- /metrics
these api Help us to view dbpack Operating state .
See the complete version change log https://github.com/CECTC/dbpack/releases.
In the next version , We will increase tracing And audit log functions .
Some links
DBPack Project address :https://github.com/cectc/dbpack
DBPack file :https://cectc.github.io/dbpack-doc/#/
DBPack-samples:https://github.com/cectc/dbpack-samples
DBPack Introduce :https://mp.weixin.qq.com/s/DmXfk5bAcVYdnOwvp8ocHA
Event driven distributed transaction architecture design :https://mp.weixin.qq.com/s/r43JvRY3LCETMoZjrdNxXA
dotnet core It can also coordinate distributed transactions ! More articles about
- .Net Core with Microservices - Distributed transactions - TCC
Last time we explained the of distributed transactions 2PC.3PC . So this time we'll sort it out TCC Business . This time I will explain TCC The principle of .NET It doesn't matter . TCC Try Preparation stage , Try to do business Confirm End ...
- .Net Core with Microservices - Distributed transactions - The final consistency of reliable information
We talked about the of distributed transactions earlier 2PC.3PC , TCC Principle . These transactions are actually trying to simulate database transactions , We can simply think of them as a synchronous row transaction . especially 2PC,3PC They take full advantage of the transactional capabilities of the database , In one ...
- .Net Core with Microservices - Distributed transactions - 2PC、3PC
Busy recently , It hasn't been updated for a long time . This time, let's talk about distributed transactions . Under the microservice system , Our application is divided into multiple services , Each service is configured with a database . If our service division is not perfect , In order to complete the business, there will be many cross database transactions . Even if ...
- .NET Core Event bus , Distributed transaction solutions :CAP
background I believe the previous articles on microservices have also introduced so much , In the process of building micro services, we really need such a thing , Even if it's not building microservices , In the process of building distributed applications, we will also encounter the problem of distributed transactions , that CAP It's against this background ...
- Use TransactionScope Do distributed transaction coordination
// The scenario is to use coordination between multiple databases ,.NET 2.0 Use a new type TransactionScope To coordinate , This is the same as before COM+ Coordination is relatively more convenient // Need to reference a new assembly :System ...
- .NET Core Event bus , Distributed transaction solutions :CAP be based on Kafka
background I believe the previous articles on microservices have also introduced so much , In the process of building micro services, we really need such a thing , Even if it's not building microservices , In the process of building distributed applications, we will also encounter the problem of distributed transactions , that CAP It's against this background ...
- Distributed transaction solutions and .Net Core With the implementation of the ( On )
Data consistency is an important issue to consider when building a business system , In the past, we relied on the database to ensure the consistency of data . But it is a very challenging problem to achieve data consistency in the micro service architecture and distributed environment . Recently, I am studying distributed things , Distributed solutions have a lot of ...
- asp.net core Integrate CAP( Distributed transaction bus )
One . Preface Thanks for Yang Xiaodong's contribution to the community CAP Open source project , The portal is here :.NET Core Event bus , Distributed transaction solutions :CAP as well as How to integrate... In your project CAP[ Hand in hand video tutorial ], I've also encountered distributed in my work before ...
- .net core Distributed transaction lock under
original text :.net core Distributed transaction lock under Catalog The usage of system distributed lock Lock implementation Use of locks API Examples in : Reference link The usage of system distributed lock Distributed lock is a new function of company framework : The king of lock performance : cache > Z ...
- SqlServer & Windows Updatable subscription immediate update enables distributed transaction coordinator (MSDTC)
original text :SqlServer & Windows Updatable subscription immediate update enables distributed transaction coordinator (MSDTC) In an updatable subscription , Set update method in subscription , take " Queuing updates " Set to " ...
Random recommendation
- Log4j Simple application
# The package path of the output log log4j.logger.com=DEBUG,FILE log4j.rootLogger=WARN,stdout # Console log log4j.appender.stdout=org.a ...
- JS Cross source request
One URL About the parts included :scheme://host:port/path?#hash For example, a URL by http://www.xxx.com:8888/school/student.html, ...
- 【 turn 】【 Company investigation 】 Here comes the car APP
http://blog.sina.com.cn/s/blog_83b10acc0102vk7k.html [APP brief introduction ] " Here comes the car " It is an inquiry bus developed by Wuhan Yuanguang Technology Co., Ltd ...
- VBS Read the value of a special character such as a comma in a text file and assign it to a variable
The simulation terminal I use SecureCRT You need to use a script , Support VBS Of . I need to implement the following functions : First, the text file is in the :D:\100.txt The content of the text file is :9 0,randy,9 1,jeff,9 2,sameul ...
- GPU Programming -Thread Hierarchy(3)
1. If the data is two-dimensional or three-dimensional , What should I do ? For , We can do it in two or three dimensions , Organizing threads . Old rules , Code first . Explain later // Kernel definition __global__ voi ...
- Ajax Check whether the user name has been registered
Program function When the user name is entered ( That is, the user name input box loses focus ), utilize Ajax Check whether the user name has been registered ! Implementation process utilize Ajax towards CheckUserServlet Send a request , Determine whether the user name is available . It's just for demonstration Aj ...
- asp.net core series 16 Web host IWebHostBuilder
One . summary stay asp.net core in ,Host The host is responsible for application startup and lifetime management .host The host includes Web host (IWebHostBuilder) And general purpose mainframe (IHostBuilder).Web The host is suitable for ...
- adopt .ibd and .frm recovery mysql data
background : Because the machine is damaged , The index file of the database is damaged . There is only one left mysql Of data Catalog … This method is a prerequisite for recovering data : Table building innodb Indexes remarks : If mysql All the directories are still there , Try... First , take mysq ...
- [ turn ] use GSON Take care of anything in five moves JSON Array
About GSON Entry level use of , I won't mention it here , You can read this blog if you need <Google Gson How to use , Realization Json The mutual transformation of structures > , Write very well , Easy to understand . Why did I write this article ? Because I was with ...
- java Multithreading 12 : unlocked Realization CAS Atomic operation ---- Atomic classes
because java Multithreading 11:volatile Keyword this article says that you can use the case without a lock, that is, to make variables visible without a lock , Here's how to change thread variables without locks CAS Atomicity and visibility operations We know , In a concurrent environment , Be practical ...









