Distributed Transaction Processing Method, Device, Electronic Device and Computer Storage Medium

By calling preset proxy classes in a distributed system to intercept transaction requests and performing corresponding processing methods, the invasive problem of business code in the prior art is solved, and the distributed transaction processing efficiency and system performance are improved.

CN114625488BActive Publication Date: 2025-06-17ASIAINFO TECH CHINA INC
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202110009098.7
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2021-01-05
Publication Date
2025-06-17
Estimated Expiration
2041-01-05

AI Technical Summary

Technical Problem

When solving the transaction consistency problem in distributed systems, the prior art has invasiveness to business code, which affects system performance and development efficiency.

Method used

By calling the preset proxy class in the distributed transaction open state, intercepting transaction requests, determining transaction types and executing corresponding processing methods, reducing invasiveness to business code, and completing transaction requests through asynchronous message notification.

Benefits of technology

It improves the efficiency of distributed transaction processing, reduces the invasiveness of business code, and improves the performance of business system through asynchronous message notification.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN114625488B_ABST
    Figure CN114625488B_ABST
Patent Text Reader

Abstract

The present application provides a distributed transaction processing method, apparatus, device, and computer medium, relating to the field of distributed technologies. The method includes: when the distributed transaction is in an open state, calling a stored preset proxy class; where the preset proxy class includes processing methods corresponding to transaction requests of different transaction types respectively; intercepting the current transaction request, and determining the current transaction type corresponding to the current transaction request; determining the current processing method for the current transaction request in the preset proxy class; receiving a notification from the server, and executing the current processing method based on the notification content. The distributed transaction processing method in the present application reduces the intrusion into the business code.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This application relates to the technical field of distributed systems. Specifically, this application relates to a distributed transaction processing method, apparatus, electronic device, and computer-readable storage medium. Background Art

[0002] With the popularity and prevalence of distributed service architectures, multiple logical operations that were originally executed in a monolithic application are now split into remote calls between multiple services. The resulting challenge is the distributed transaction problem. Since each service uses its own separately maintained database, operations on data during remote calls between different services are not within the same transaction, which can lead to transaction inconsistency issues.

[0003] In the prior art, for the transaction consistency problem in distributed systems, the industry can adopt strong consistency or eventual consistency solutions, but the solutions in the prior art have a certain degree of invasiveness to business code. Summary of the Invention

[0004] This application provides a method, apparatus, electronic device, and computer-readable storage medium for distributed transaction processing, which can solve the problem of the invasiveness of the distributed system framework to business code. The technical solutions are as follows:

[0005] In a first aspect, a method for distributed transaction processing is provided. The method includes:

[0006] When the distributed transaction is in an open state, call a stored preset proxy class; where the preset proxy class includes processing methods respectively corresponding to transaction requests of different transaction types;

[0007] Intercept the current transaction request and determine the current transaction type corresponding to the current transaction request;

[0008] Determine the current processing method for the current transaction request in the preset proxy class;

[0009] Receive a notification from the server and execute the current processing method based on the notification content.

[0010] In a second aspect, a device for distributed transaction processing is provided. The device includes:

[0011] A call module, configured to call a stored preset proxy class when the distributed transaction is in an open state; where the preset proxy class includes processing methods respectively corresponding to transaction requests of different transaction types;

[0012] An interception module, configured to intercept the current transaction request and determine the current transaction type corresponding to the current transaction request;

[0013] A determination module, configured to determine a current processing method for a current transaction request in a preset proxy class;

[0014] An execution module, configured to receive a notification from a server and execute the current processing method based on the notification content.

[0015] In a third aspect, an electronic device is provided, which includes:

[0016] One or more processors;

[0017] A memory;

[0018] One or more applications, where one or more applications are stored in the memory and are configured to be executed by one or more processors, and one or more programs are configured to execute the distributed transaction processing method of the first aspect of this application.

[0019] In a fourth aspect, a computer-readable storage medium is provided, on which a computer program is stored, and when the program is executed by a processor, the method for distributed transaction processing shown in the first aspect of this application is implemented.

[0020] The beneficial effects brought by the technical solution provided in this application are:

[0021] In this application, when the distributed transaction is in an open state, a stored preset proxy class is called, and by proxying the connections in the distributed transaction, data snapshots in the distributed transaction can be automatically recorded; and by using the processing methods corresponding to the transaction requests of different transaction types included in the preset proxy class to determine the current processing method of the intercepted current transaction request, the processing efficiency of the distributed transaction can be improved, and the transaction proxy is implemented using javaagent to reduce the intrusion into the business code; then receive the notification from the server and execute the current processing method based on the notification, and completing the current transaction request through the asynchronous message notification method can improve the performance of the business system. Description of the Drawings

[0022] In order to more clearly illustrate the technical solutions in the embodiments of this application, the following will briefly introduce the drawings required for description in the embodiments of this application.

[0023] Figure 1 It is a schematic flowchart of a distributed transaction processing method provided by an embodiment of this application;

[0024] Figure 2 It is a relationship diagram of a transaction control center client, a memory and a preset proxy class provided by an embodiment of this application;

[0025] Figure 3 It is a schematic flowchart of another distributed transaction processing method provided by an embodiment of this application;

[0026] Figure 4 Schematic flowchart of another distributed transaction processing method provided by an embodiment of the present application;

[0027] Figure 5 Schematic structural diagram of a distributed transaction processing device provided by an embodiment of the present application;

[0028] Figure 6 Schematic structural diagram of an electronic device for distributed transaction processing provided by an embodiment of the present application. Detailed implementation manners

[0029] The embodiments of the present application will be described in detail below. Examples of the embodiments are shown in the accompanying drawings, where the same or similar reference numerals denote the same or similar elements or elements having the same or similar functions throughout. The embodiments described below with reference to the accompanying drawings are exemplary and are only used to explain the present application, and should not be construed as a limitation of the present invention.

[0030] Those skilled in the art of the present technology can understand that, unless specifically stated otherwise, the singular forms "a", "an", "the" and "said" used herein may also include the plural forms. It should be further understood that the term "comprising" used in the specification of the present application means the presence of the described features, integers, steps, operations, elements and / or components, but does not exclude the presence or addition of one or more other features, integers, steps, operations, elements, components and / or groups thereof. It should be understood that when we say that an element is "connected" or "coupled" to another element, it can be directly connected or coupled to other elements, or there may also be intermediate elements. In addition, the "connection" or "coupling" used herein may include wireless connection or wireless coupling. The phrase "and / or" used herein includes all or any unit and all combinations of one or more related listed items.

[0031] To make the objectives, technical solutions and advantages of the present application clearer, the embodiments of the present application will be further described in detail below with reference to the accompanying drawings.

[0032] The distributed transaction processing method, device, electronic device and computer-readable storage medium provided by the present application are intended to solve the above technical problems in the prior art.

[0033] The technical solutions of the present application and how the technical solutions of the present application solve the above technical problems will be described in detail below with specific embodiments. These specific embodiments may be combined with each other, and the same or similar concepts or processes may not be repeated in some embodiments. The embodiments of the present application will be described below with reference to the accompanying drawings.

[0034] An embodiment of the present application provides a method for distributed transaction processing, as Figure 1As shown in the figure, the method includes:

[0035] Step S101: When the distributed transaction is in an open state, call the stored preset proxy class; where the preset proxy class includes processing methods corresponding to transaction requests of different transaction types respectively.

[0036] First of all, it should be noted that a distributed transaction means that the participants of the transaction, the servers supporting the transaction, the resource servers, and the transaction manager are respectively located on different nodes of different distributed systems. The distributed transaction processing method provided in the embodiments of the present application is applied to the transaction manager, such as the client of the transaction control center.

[0037] When the distributed transaction is in an open state, the stored preset proxy class can be called. Among them, the preset proxy class can be a custom data connection class, which is responsible for proxying the database connection in the local transaction, and the preset proxy class includes processing methods corresponding to transaction requests of different transaction types respectively, and can be applied in a certain stage of the distributed transaction.

[0038] It can be understood that when operating the application, there will be continuous interaction with the database. When the interaction frequency is too high, the database pressure will be too large, resulting in the application running smoothly. The corresponding data can be retrieved from the database and placed in the memory when the application starts to reduce the database pressure.

[0039] In an embodiment of the present application, the preset proxy class is stored in the memory. When the distributed transaction is in an open state, the client of the transaction control center calls the preset proxy class in the memory, and the data for the distributed transaction retrieved from the database is also stored in the memory, so that the execution operation of the distributed transaction is in the memory, reducing the interaction with the database and reducing the database pressure.

[0040] In an embodiment of the present application, transaction proxy can be implemented using javaagent, that is, it can be provided to the application integration in the form of a java jar package or other language SDK (Software Development Kit) to reduce the intrusion into the business code.

[0041] In addition, when the distributed transaction is in an open state, the transaction identifier of the distributed transaction can also be stored in the memory. It should be noted that the distributed transaction includes multiple local transactions, and the transaction identifier of the distributed transaction is also the transaction identifier of the local transaction. Similarly, the current transaction request also contains this transaction identifier.

[0042] To better understand the solution of the present application, a relationship diagram of the client of the transaction control center, the memory, and the preset proxy class is provided in the embodiments of the present application, as Figure 2 shown.

[0043] Step S102: Intercept the current transaction request and determine the current transaction type corresponding to the current transaction request.

[0044] Step S103: Determine the current processing method for the current transaction request in the preset proxy class.

[0045] Among them, the current transaction request includes requests sent by local applications, and the current transaction request type is carried in the current transaction request. The current transaction type includes strong consistency type or eventual consistency type. Correspondingly, the preset proxy class includes processing methods corresponding to transaction requests of different transaction types respectively. Therefore, when the current transaction request is intercepted and the current transaction type corresponding to the current transaction request is determined, the current processing method for the current transaction request can be determined in the preset proxy class.

[0046] It can be understood that after the transaction control center client intercepts the current transaction request, it can also notify each resource manager participating in the transaction, that is, the database, so that the database prepares the transaction. In the embodiments of the present application, since the data for the distributed transaction retrieved from the database has been saved in the memory, the transaction can be prepared in the memory. Exemplarily, the transaction log can be written, the transaction can be executed, and wait for further notification from the server.

[0047] Step S104: Receive the notification from the server and execute the current processing method based on the notification content.

[0048] It can be understood that when the transaction preparation of the current transaction request is completed or failed in the memory, information on whether it is ready can be sent to the server. The server sends a notification instruction to the control center client according to the information on whether it is ready. It can also be that the control center client listens for the notification instruction sent by the server, and the control center client executes the processing method for the intercepted transaction request according to the notification content.

[0049] In the present application, in the open state of the distributed transaction, the stored preset proxy class is called, and the data snapshot in the distributed transaction can be automatically recorded by proxying the connections in the distributed transaction; and by using the processing methods corresponding to transaction requests of different transaction types included in the preset proxy class to determine the current processing method for the intercepted current transaction request, the processing efficiency of the distributed transaction can be improved, and the intrusion into the business code can be reduced; then receive the notification from the server and execute the current processing method based on the notification. Completing the current transaction request through the asynchronous message notification method can improve the performance of the business system.

[0050] In an embodiment of the present application, the transaction type in the current transaction request is the strong consistency type, the preset proxy class is stored in the memory, and the processing methods for the current transaction request in the preset proxy class include a first commit method and a first rollback method;

[0051] The execution of the current processing method includes:

[0052] If there is no connection corresponding to the current transaction request in the memory, call the first interface of the server to submit the first distributed transaction;

[0053] And / or

[0054] Execute a rollback operation and delete the preset proxy class in the memory.

[0055] It can be understood that the transaction type of the current transaction request is a strong consistency type. For the purpose of ensuring strong consistency, for the execution of the first submission method, the submission operation for the current transaction request does not need to be executed in the preset proxy class, and it can be confirmed in the memory whether there is a connection corresponding to the current transaction request according to the identifier of the current transaction request. If there is no connection corresponding to the current transaction request in the memory, the first interface of the server, such as the submission interface, can be called to submit a distributed transaction to ensure the integrity of the distributed transaction.

[0056] First of all, it should be noted that the rollback command returns the database state to the state at the last commit. For the execution of the first rollback method, the rollback operation for the current transaction request can be executed in the preset proxy class. It can be understood that if the rollback operation is executed, it indicates that the processing method for the current transaction request is incorrect. At this time, the preset proxy class or the data corresponding to the current transaction request can be deleted in the memory to ensure the accuracy of the distributed transaction.

[0057] In an embodiment of the present application, as Figure 3 shown, receiving the notification from the server and executing the current processing method based on the notification content further includes:

[0058] Step S301: Based on the identifier of the current transaction request, obtain at least two preset proxy classes related to the current transaction request from the memory.

[0059] Step S302: Execute the current processing method for the current transaction request in the preset proxy class determined according to the transaction type corresponding to the current transaction request.

[0060] Step S303: Disconnect the preset proxy class from the database, clear the data related to the current transaction request in the memory based on the identifier of the current transaction request, and send the notification completion information to the server.

[0061] Among them, the notification content of the service includes a submission notification and a rollback notification. After receiving the notification from the server for the current transaction request or monitoring the notification from the server for the current transaction request, the transaction control center client can obtain multiple preset proxy classes related to the current transaction request in memory according to the identifier of the current transaction request. It can be understood that the current transaction request is a request in a node of a distributed transaction. In the actual application process, multiple nodes can jointly complete the entire distributed transaction. For the purpose of achieving strong consistency, after receiving the notification from the server, multiple preset proxy classes related to the current transaction request can be obtained in memory, and the first submission method or the first rollback method corresponding to the current transaction type is executed for all of them.

[0062] After executing the processing method in the preset proxy class, in order to enable the database to serve other distributed transactions, the connection between the preset proxy class and the database can be disconnected; and the data related to the current transaction in memory can be cleared according to the identifier of the current transaction request to reduce the resource pressure on the memory; finally, the information indicating that the submission is completed or the rollback is completed can be sent to the server, so that the server can transfer the ended transaction data to other databases, such as a relational database, as a basis for recovery in case of a failure.

[0063] In an embodiment of the present application, when the transaction type in the current transaction request is the eventually consistent type, the distributed transaction processing method further includes:

[0064] (1) The intercepted current transaction request includes a data manipulation language operation, and the execution result corresponding to the operation statement in the data manipulation language is obtained.

[0065] Among them, when the intercepted current transaction request includes a data manipulation language operation, the operation corresponding to the data manipulation language can be directly executed in the preset proxy class. Specifically, since the preset proxy class is connected to the database, the preset proxy class can be used to interact with the database, execute the operation statement in the data manipulation language, and obtain the execution result.

[0066] In an embodiment of the present application, obtaining the execution result corresponding to the operation statement in the data manipulation language includes:

[0067] If the operation statement is a delete or update statement, the delete or update statement is converted into a select statement, and a result set is obtained by querying in the preset proxy class.

[0068] If the operation statement is an insert statement, the table name and the primary key field name are extracted from the structured query language, and the primary key field value is extracted from the variable binding value. Among them, extracting the primary key field name includes querying and extracting from the database system table.

[0069] (2) Add a distributed lock to the current transaction request based on the execution result so that the execution result is temporarily stored in the data snapshot variable of the preset proxy class.

[0070] The name of the distributed lock may be library name_table name_primary key field name_primary key field value. It is understandable that, since the transaction type of the current transaction request is an eventually consistent type, the intermediate execution result may be temporarily stored first.

[0071] In one embodiment of the present application, the transaction type in the current transaction request is an eventually consistent type, the preset proxy class is stored in the memory, and the processing method for the current transaction request in the preset proxy class includes a second commit method and a second rollback method;

[0072] Execution of the current processing method includes:

[0073] Save the data snapshot of the current transaction request, perform the commit operation, and delete the preset proxy class in memory;

[0074] and / or,

[0075] Execute the rollback operation, clean up the data snapshot variables in the preset proxy class, and if there is no connection with the current transaction request in the memory, call the second interface of the server to roll back the second distributed transaction.

[0076] It can be understood that the transaction type of the current transaction request is an eventually consistent type. In order to ensure the purpose of eventual consistency, for executing the second submission method, for example, the snapshot interface can be called to save the data snapshot of the current transaction request, and the data snapshot variable can be cleared, and then the submission operation is performed in the preset proxy class, and the preset proxy class is deleted in the memory.

[0077] For executing the second rollback method, a rollback operation for the current transaction request can be executed in the preset proxy class, and the data snapshot variable can be cleared; then, according to the identifier of the current transaction request, it is confirmed in the memory whether there is a connection with the current transaction request. If there is no connection with the current transaction request in the memory, the second interface of the server, such as the rollback interface, can be called to roll back a distributed transaction.

[0078] In one embodiment of the present application, Figure 4 As shown, receiving a notification from the server, executing the current processing method based on the notification content, and further comprising:

[0079] Step S401: If the notification content is a rollback notification, extract a data snapshot from the notification content, and obtain a data source name from the data snapshot.

[0080] Step S402: connecting to the database based on the data source name, and performing a rollback operation based on the data snapshot in the database.

[0081] Step S403: Disconnect from the database and send the rollback completion information to the server.

[0082] If a rollback notification from the server is received, the rollback indicates that the current stage operation has failed and the database state returns to the state of the last commit. Therefore, the data committed last time can be obtained from the data snapshot. Specifically, when the transaction request of the current transaction is prepared or fails in memory, information on whether it is ready can be sent to the server. Based on the information on whether it is ready, the server sends a notification instruction to the control center client. Therefore, the information of the data snapshot can be extracted from the notification content.

[0083] It can be understood that after obtaining the data snapshot information, the name of the data source can be obtained from the data snapshot information, and then the database can be reconnected based on the data source name, and a rollback operation based on the data snapshot can be executed in the database. Among them, in the eventually consistent type, compared with providing a corresponding rollback interface in the existing business system, in the embodiment of the present application, by executing the rollback operation in the database, there is no need for the original business system to provide an interface, reducing the intrusion into the original business code.

[0084] After the rollback operation is completed, disconnect from the database, release resources, and send the rollback completion information to the server, so that the server can transfer the ended transaction data to other databases, such as a relational database, as a basis for recovery after a failure.

[0085] In an embodiment of the present application, the distributed transaction processing method further includes:

[0086] If a distributed transaction fails, send the exception information to the server, where the exception information includes the cause of the exception and the exception code.

[0087] It can be understood that the transaction center client can also monitor the running state of the distributed transaction. When the distributed transaction fails, the cause of the failure and the exception code can be sent to the server to solve the exception more timely and ensure the normal operation of the distributed transaction.

[0088] The embodiment of the present application provides a distributed transaction processing device, as Figure 5 shown. The distributed transaction processing device 50 may include: a call module 501, an interception module 502, a determination module 503, and an execution module 504, where

[0089] The call module 501 is configured to call a stored preset proxy class in the open state of the distributed transaction; where the preset proxy class includes processing methods corresponding to transaction requests of different transaction types.

[0090] First of all, it should be noted that a distributed transaction means that the participants of the transaction, the servers supporting the transaction, the resource servers, and the transaction manager are respectively located on different nodes of different distributed systems. The distributed transaction processing method provided in the embodiments of the present application is applied to the transaction manager, such as the client of the transaction control center.

[0091] In the state where the distributed transaction is enabled, a stored preset proxy class can be called. Among them, the preset proxy class can be a custom data connection class, which is responsible for proxying the database connection in the local transaction, and the preset proxy class includes processing methods corresponding to transaction requests of different transaction types, which can be applied in a certain stage of the fractional transaction.

[0092] It can be understood that when operating on the application, it will interact with the database continuously. When the interaction frequency is too high, the database pressure will be too large, resulting in the application running smoothly. The corresponding data can be retrieved from the database and placed in the memory when the application starts to reduce the database pressure. In an embodiment of the present application, the preset proxy class is stored in the memory. In the state where the distributed transaction is enabled, the client of the transaction control center calls the preset proxy class in the memory, and the data for the distributed transaction retrieved from the database is also saved in the memory, so that the execution operation of the distributed transaction is in the memory, reducing the interaction with the database and reducing the database pressure.

[0093] In an embodiment of the present application, it can be implemented using javaagent to achieve transaction proxy, that is, it can be provided to the application integration in the form of a java jar package or other language SDK (Software Development Kit), so as to reduce the intrusion into the business code.

[0094] In addition, in the state where the distributed transaction is enabled, the transaction identifier of the distributed transaction can also be saved in the memory. It should be noted that the distributed transaction includes multiple local transactions, and the transaction identifier of the distributed transaction is also the transaction identifier of the local transaction. Similarly, the current transaction request also contains this transaction identifier.

[0095] The interception module 502 is used to intercept the current transaction request and determine the current transaction type corresponding to the current transaction request.

[0096] The determination module 503 is used to determine the current processing method for the current transaction request in the preset proxy class.

[0097] Among them, the current transaction request includes requests sent by local applications, and the current transaction request carries the current transaction request type, where the current transaction type includes strong consistency type or eventual consistency type. Correspondingly, the preset proxy class includes processing methods respectively corresponding to transaction requests of different transaction types. Therefore, when intercepting the current transaction request and determining the current transaction type corresponding to the current transaction request, the current processing method for the current transaction request can be determined in the preset proxy class.

[0098] It can be understood that after the transaction control center client intercepts the current transaction request, it can also notify each resource manager participating in the transaction, that is, the database, so that the database prepares the transaction. In the embodiments of the present application, since the data for the distributed transaction retrieved from the database has been saved in memory, the transaction can be prepared in memory. Exemplarily, the transaction log can be written, the transaction can be executed, and wait for further notification from the server.

[0099] The execution module 504 is configured to receive the notification from the server and execute the current processing method based on the notification content.

[0100] It can be understood that when the transaction preparation of the current transaction request is completed or fails in memory, information on whether it is ready can be sent to the server. The server sends a notification instruction to the control center client based on the information on whether it is ready. Alternatively, the control center client can listen for the notification instruction sent by the server, and the control center client executes the processing method for the intercepted transaction request according to the notification content.

[0101] In the present application, in the open state of the distributed transaction, the stored preset proxy class is called, and the data snapshot in the distributed transaction can be automatically recorded by proxying the connections in the distributed transaction; and by using the processing methods respectively corresponding to transaction requests of different transaction types included in the preset proxy class to determine the current processing method for the intercepted current transaction request, the processing efficiency of the distributed transaction can be improved, and the transaction proxy is implemented using javaagent to reduce the intrusion into the business code; then receive the notification from the server and execute the current processing method based on the notification. Completing the current transaction request through the asynchronous message notification method can improve the performance of the business system.

[0102] In an embodiment of the present application, the transaction type in the current transaction request is the strong consistency type, the preset proxy class is stored in memory, and the processing methods for the current transaction request in the preset proxy class include a first commit method and a first rollback method;

[0103] The execution module includes:

[0104] The first submission sub-module is used to call the first interface of the server to submit the first distributed transaction if there is no connection in the memory that matches the current transaction request.

[0105] And / or

[0106] The first rollback sub-module is used to perform a rollback operation and delete a preset proxy class in the memory.

[0107] In an embodiment of the present application, the execution module further includes:

[0108] The acquisition sub-module is used to acquire at least two preset proxy classes related to the current transaction request from the memory based on the identifier of the current transaction request.

[0109] The first execution sub-module is used to execute the current processing method for the current transaction request in the preset proxy class determined according to the transaction type corresponding to the current transaction request.

[0110] The first sending sub-module is used to disconnect the preset proxy class from the database, clear the data related to the current transaction request in the memory based on the identifier of the current transaction request, and send a notification completion message to the server.

[0111] In an embodiment of the present application, when the transaction type in the current transaction request is the eventually consistent type, the distributed transaction processing device further includes:

[0112] The acquisition module is used to intercept the current transaction request that includes a data manipulation language operation, and acquire the execution result corresponding to the operation statement in the data manipulation language.

[0113] The addition module is used to add a distributed lock to the transaction request according to the execution result, so that the execution result is temporarily stored in the data snapshot variable of the preset proxy class.

[0114] In an embodiment of the present application, the acquisition module includes:

[0115] The query sub-module is used to convert the delete or update statement into a select statement if the operation statement is a delete or update statement, and perform a query in the preset proxy class to obtain a result set.

[0116] The first extraction sub-module is used to extract the table name and the primary key field name from the structured query language and extract the primary key field value from the variable binding value if the operation statement is an insert statement. Among them, extracting the primary key field name includes querying and extracting from the database system table.

[0117] In an embodiment of the present application, when the transaction type in the current transaction request is the eventually consistent type, the preset proxy class is stored in the memory, and the processing methods for the current transaction request in the preset proxy class include a second submission method and a second rollback method.

[0118] The execution module includes:

[0119] A second submission sub-module, configured to save a data snapshot of the current transaction request, perform a submission operation, and delete a preset proxy class in the memory;

[0120] and / or

[0121] A second rollback module, configured to perform a rollback operation, clean data snapshot variables in the preset proxy class, and if there is no connection to the current transaction request in the memory, call a second interface of the server to roll back the second distributed transaction.

[0122] In an embodiment of the present application, the execution module further includes:

[0123] A second extraction sub-module, configured to extract a data snapshot from the notification content if the notification content is a rollback notification, and obtain a data source name from the data snapshot;

[0124] A second execution sub-module, configured to connect to a database based on the data source name and perform a rollback operation based on the data snapshot in the database;

[0125] A second sending sub-module, configured to disconnect from the database and send rollback completion information to the server.

[0126] The distributed transaction processing device in this embodiment can execute the distributed transaction processing method shown in the above embodiments of the present application, and its implementation principle is similar, which will not be elaborated here.

[0127] An electronic device is provided in an embodiment of the present application. The electronic device includes: a memory and a processor; at least one program, stored in the memory, and when executed by the processor, compared with the prior art, can achieve:

[0128] In the present application, when the distributed transaction is in an open state, a stored preset proxy class is called, and by proxying the connections in the distributed transaction, data snapshots in the distributed transaction can be automatically recorded; and by using the processing methods corresponding to the transaction requests of different transaction types included in the preset proxy class to determine the current processing method of the intercepted current transaction request, the processing efficiency of the distributed transaction can be improved, and the transaction proxy is implemented using javaagent to reduce the intrusion into the business code; then receive a notification from the server and execute the current processing method based on the notification, and completing the current transaction request through an asynchronous message notification method can improve the performance of the business system.

[0129] In an optional embodiment, an electronic device is provided, as Figure 6 shown Figure 6The electronic device 4000 shown includes: a processor 4001 and a memory 4003. Among them, the processor 4001 and the memory 4003 are connected, such as through a bus 4002. Optionally, the electronic device 4000 may further include a transceiver 4004. It should be noted that in actual applications, the transceiver 4004 is not limited to one, and the structure of the electronic device 4000 does not constitute a limitation on the embodiments of the present application.

[0130] The processor 4001 may be a CPU (Central Processing Unit), a general-purpose processor, a DSP (Digital Signal Processor), an ASIC (Application Specific Integrated Circuit), an FPGA (Field Programmable Gate Array), or other programmable logic devices, transistor logic devices, hardware components, or any combination thereof. It can implement or execute various exemplary logic blocks, modules, and circuits described in connection with the disclosure of the present application. The processor 4001 may also be a combination that implements computing functions, such as a combination including one or more microprocessors, a combination of a DSP and a microprocessor, etc.

[0131] The bus 4002 may include a path for transmitting information between the above components. The bus 4002 may be a PCI (Peripheral Component Interconnect) bus or an EISA (Extended Industry Standard Architecture) bus, etc. The bus 4002 may be divided into an address bus, a data bus, a control bus, etc. For the sake of representation, Figure 6 only a thick line is used to represent it in the figure, but it does not mean that there is only one bus or one type of bus.

[0132] The memory 4003 can be a ROM (Read Only Memory), or other types of static storage devices that can store static information and instructions, a RAM (Random Access Memory), or other types of dynamic storage devices that can store information and instructions. It can also be an EEPROM (Electrically Erasable Programmable Read Only Memory), a CD-ROM (Compact Disc Read Only Memory), or other optical disc storage, optical disc storage (including compact discs, laser discs, optical discs, digital versatile discs, Blu-ray discs, etc.), magnetic disk storage media, or other magnetic storage devices, or any other medium that can be used to carry or store the desired program code in the form of instructions or data structures and can be accessed by a computer, but is not limited thereto.

[0133] The memory 4003 is used to store the application program code for executing the solution of this application, and is controlled by the processor 4001 for execution. The processor 4001 is used to execute the application program code stored in the memory 4003 to implement the content shown in the foregoing method embodiments.

[0134] The embodiment of this application provides a computer-readable storage medium, on which a computer program is stored. When it runs on a computer, it enables the computer to execute the corresponding content in the foregoing method embodiments. Compared with the prior art,

[0135] In the open state of the distributed transaction of this application, a stored preset proxy class is called. By proxying the connections in the distributed transaction, the data snapshot in the distributed transaction can be automatically recorded; and by using the processing methods corresponding to the transaction requests of different transaction types included in the preset proxy class, the current processing method of the intercepted current transaction request is determined, which can improve the processing efficiency of the distributed transaction, and use javaagent to implement transaction proxy to reduce the intrusion into the business code; then the notification from the server is received, and the current processing method is executed based on the notification. Completing the current transaction request through the asynchronous message notification method can improve the performance of the business system.

[0136] It should be understood that although the steps in the flowcharts of the accompanying drawings are shown sequentially as indicated by the arrows, these steps are not necessarily executed sequentially in the order indicated by the arrows. Unless there is a clear indication in this document, there is no strict order restriction for the execution of these steps, and they can be executed in other orders. Moreover, at least a part of the steps in the flowcharts of the accompanying drawings may include multiple sub-steps or multiple stages. These sub-steps or stages are not necessarily executed at the same time, but can be executed at different times, and their execution order is not necessarily sequential, but can be executed alternately or in turn with at least a part of other steps or sub-steps or stages of other steps.

[0137] The above are only some embodiments of the present invention. It should be noted that for those of ordinary skill in the art, without departing from the principle of the present invention, several improvements and refinements can be made, and these improvements and refinements should also be regarded as the protection scope of the present invention.

Claims

1. A distributed transaction processing method, characterized in that, Including: When the distributed transaction is in an open state, call the stored preset proxy class; wherein, the preset proxy class includes processing methods corresponding to transaction requests of different transaction types; Intercept the current transaction request and determine the current transaction type corresponding to the current transaction request; Determine the current processing method for the current transaction request in the preset proxy class; Receive a notification from the server and execute the current processing method based on the notification content; When the transaction type in the current transaction request is the eventually consistent type, the method further includes: The intercepted current transaction request includes a data manipulation language operation, and obtain the execution result corresponding to the operation statement in the data manipulation language; Add a distributed lock to the transaction request according to the execution result, so that the execution result is temporarily stored in the data snapshot variable of the preset proxy class; The obtaining the execution result corresponding to the operation statement in the data manipulation language includes: Interact with the database through the preset proxy class, execute the operation statement in the data manipulation language in the preset proxy class and obtain the execution result.

2. The method according to claim 1, characterized in that, When the transaction type in the current transaction request is the strongly consistent type, the preset proxy class is stored in memory, and the processing methods for the current transaction request in the preset proxy class include a first commit method and a first rollback method; The executing the current processing method includes: If there is no connection to the current transaction request in the memory, call the first interface of the server to submit a first distributed transaction; And / or Execute a rollback operation and delete the preset proxy class from the memory.

3. The method according to claim 2, characterized in that, The receiving a notification from the server and executing the current processing method based on the notification content further includes: Based on the identifier of the current transaction request, obtain at least two preset proxy classes related to the current transaction request from the memory; Execute the current processing method for the current transaction request in the preset proxy class determined according to the transaction type corresponding to the current transaction request; Disconnect the preset proxy class from the database, clear the data related to the current transaction request in the memory based on the identifier of the current transaction request, and send a notification completion message to the server.

4. The method according to claim 1, characterized in that, The obtaining the execution result corresponding to the operation statement in the data manipulation language includes: If the operation statement is a delete or update statement, convert the delete or update statement into a select statement and perform a query in the preset proxy class to obtain a result set; If the operation statement is an insert statement, extract the table name and primary key field name from the structured query language, and extract the primary key field value from the variable binding value, wherein extracting the primary key field name includes querying and extracting from the database system table.

5. The method according to claim 4, characterized in that, When the transaction type in the current transaction request is the eventually consistent type, the preset proxy class is stored in memory, and the processing methods for the current transaction request in the preset proxy class include a second commit method and a second rollback method; The executing the current processing method includes: Save the data snapshot of the current transaction request, execute a commit operation, and delete the preset proxy class from the memory; And / or Perform a rollback operation to clean up the data snapshot variable in the preset proxy class. If there is no connection in the memory corresponding to the current transaction request, call the second interface of the server to roll back the second distributed transaction.

6. The method according to claim 5, characterized in that, The receiving of the notification from the server and the execution of the current processing method based on the notification content further includes: If the notification content is a rollback notification, extract the data snapshot from the notification content and obtain the data source name from the data snapshot; Connect to the database based on the data source name and perform a rollback operation based on the data snapshot in the database; Disconnect from the database and send the rollback completion information to the server.

7. A distributed transaction processing device, characterized in that, It includes: A calling module for calling the stored preset proxy class in the open state of the distributed transaction; wherein, the preset proxy class includes processing methods corresponding to transaction requests of different transaction types respectively; An interception module for intercepting the current transaction request and determining the current transaction type corresponding to the current transaction request; A determination module for determining the current processing method for the current transaction request in the preset proxy class; An execution module for receiving the notification from the server and executing the current processing method based on the notification content; When the transaction type in the current transaction request is the eventually consistent type, the device further includes: An acquisition module for intercepting that the current transaction request includes a data manipulation language operation and acquiring the execution result corresponding to the operation statement in the data manipulation language; An addition module for adding a distributed lock to the transaction request according to the execution result, so that the execution result is temporarily stored in the data snapshot variable of the preset proxy class; The acquisition module is specifically used for: Interacting with the database through the preset proxy class, executing the operation statement in the data manipulation language in the preset proxy class and obtaining the execution result.

8. An electronic device, characterized in that, It includes: One or more processors; A memory; One or more applications, wherein the one or more applications are stored in the memory and configured to be executed by the one or more processors, and the one or more programs are configured to: execute the distributed transaction processing method according to any one of claims 1 to 6.

9. A computer-readable storage medium, on which a computer program is stored, characterized in that, When the program is executed by the processor, it implements the distributed transaction processing method according to any one of claims 1 - 6.

Citation Information

Patent Citations

  • Big data cluster transaction implementation method based on distributed cache

    CN110134704A

  • Distributed transaction processing method and device, computer equipment and storage medium

    CN111857978A