CN111522631A - Distributed transaction processing method, device, server and medium - Google Patents

Distributed transaction processing method, device, server and medium Download PDF

Info

Publication number
CN111522631A
CN111522631A CN202010209587.2A CN202010209587A CN111522631A CN 111522631 A CN111522631 A CN 111522631A CN 202010209587 A CN202010209587 A CN 202010209587A CN 111522631 A CN111522631 A CN 111522631A
Authority
CN
China
Prior art keywords
transaction
service
log
current local
data
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Granted
Application number
CN202010209587.2A
Other languages
Chinese (zh)
Other versions
CN111522631B (en
Inventor
陈龙
尹博学
张森
钱在晨
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Alipay Hangzhou Information Technology Co Ltd
Original Assignee
Alipay Hangzhou Information Technology Co Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Alipay Hangzhou Information Technology Co Ltd filed Critical Alipay Hangzhou Information Technology Co Ltd
Priority to CN202010209587.2A priority Critical patent/CN111522631B/en
Publication of CN111522631A publication Critical patent/CN111522631A/en
Application granted granted Critical
Publication of CN111522631B publication Critical patent/CN111522631B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F9/00Arrangements for program control, e.g. control units
    • G06F9/06Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
    • G06F9/46Multiprogramming arrangements
    • G06F9/466Transaction processing
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/20Information retrieval; Database structures therefor; File system structures therefor of structured data, e.g. relational data
    • G06F16/23Updating
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/20Information retrieval; Database structures therefor; File system structures therefor of structured data, e.g. relational data
    • G06F16/23Updating
    • G06F16/2308Concurrency control
    • G06F16/2336Pessimistic concurrency control approaches, e.g. locking or multiple versions without time stamps
    • G06F16/2343Locking methods, e.g. distributed locking or locking implementation details
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/20Information retrieval; Database structures therefor; File system structures therefor of structured data, e.g. relational data
    • G06F16/24Querying
    • G06F16/242Query formulation
    • G06F16/2433Query languages
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/20Information retrieval; Database structures therefor; File system structures therefor of structured data, e.g. relational data
    • G06F16/24Querying
    • G06F16/245Query processing
    • G06F16/2455Query execution
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/20Information retrieval; Database structures therefor; File system structures therefor of structured data, e.g. relational data
    • G06F16/27Replication, distribution or synchronisation of data between databases or within a distributed database system; Distributed database system architectures therefor
    • YGENERAL TAGGING OF NEW TECHNOLOGICAL DEVELOPMENTS; GENERAL TAGGING OF CROSS-SECTIONAL TECHNOLOGIES SPANNING OVER SEVERAL SECTIONS OF THE IPC; TECHNICAL SUBJECTS COVERED BY FORMER USPC CROSS-REFERENCE ART COLLECTIONS [XRACs] AND DIGESTS
    • Y02TECHNOLOGIES OR APPLICATIONS FOR MITIGATION OR ADAPTATION AGAINST CLIMATE CHANGE
    • Y02DCLIMATE CHANGE MITIGATION TECHNOLOGIES IN INFORMATION AND COMMUNICATION TECHNOLOGIES [ICT], I.E. INFORMATION AND COMMUNICATION TECHNOLOGIES AIMING AT THE REDUCTION OF THEIR OWN ENERGY USE
    • Y02D10/00Energy efficient computing, e.g. low power processors, power management or thermal management

Landscapes

  • Engineering & Computer Science (AREA)
  • Theoretical Computer Science (AREA)
  • Physics & Mathematics (AREA)
  • Databases & Information Systems (AREA)
  • General Engineering & Computer Science (AREA)
  • General Physics & Mathematics (AREA)
  • Data Mining & Analysis (AREA)
  • Computational Linguistics (AREA)
  • Software Systems (AREA)
  • Mathematical Physics (AREA)
  • Computing Systems (AREA)
  • Information Retrieval, Db Structures And Fs Structures Therefor (AREA)

Abstract

The embodiment of the specification provides a distributed transaction processing method, a device, a server and a medium, the method comprises the steps of firstly inquiring a main key of service data to be updated from a service database according to intercepted service SQL, then executing the service SQL to update the service data, generating a row lock according to the inquired main key and a transaction identifier of a current local transaction after the execution is successful, storing the transaction identifier into a log of the service database corresponding to the current local transaction, and if a rollback instruction is received at two stages, searching the transaction update log of the local transaction from the log of the service database according to the transaction identifier contained in the rollback instruction to perform rollback.

Description

Distributed transaction processing method, device, server and medium
Technical Field
Embodiments of the present disclosure relate to the field of computer technologies, and in particular, to a distributed transaction processing method, apparatus, server, and medium.
Background
The distributed transaction means that a participant of the transaction, a server supporting the transaction, a resource server and a transaction manager are respectively positioned on different nodes of different distributed systems. At present, the distributed transaction solution mainly has a solution without invasion and a solution with invasion to the service. Among them, the non-intrusion scheme is widely used because of its advantage of non-intrusion to service codes, but has a high requirement on system performance.
Disclosure of Invention
The embodiment of the specification provides a distributed transaction processing method, a distributed transaction processing device, a server and a medium.
In a first aspect, an embodiment of the present specification provides a distributed transaction processing method, including: inquiring a main key of service data to be updated from a service database according to the intercepted service SQL; updating the service data to be updated by executing the service SQL, generating a row lock aiming at the updated service data according to the inquired main key and the transaction identifier of the current local transaction after the execution is successful, and storing the transaction identifier into a log of the service database corresponding to the current local transaction; and if a rollback instruction is received, inquiring a transaction update log of the current local transaction from the logs of the service database according to a transaction identifier contained in the rollback instruction, and rolling back the current local transaction according to the transaction update log.
In a second aspect, an embodiment of the present specification provides a distributed transaction processing apparatus, including: the query module is used for querying a main key of the service data to be updated from the service database according to the intercepted service SQL; the transaction processing module is used for updating the service data to be updated by executing the service SQL, generating a row lock aiming at the updated service data according to the inquired main key and the transaction identifier of the current local transaction after the execution is successful, and storing the transaction identifier into a log of the service database corresponding to the current local transaction; and the rollback module is used for inquiring the transaction update log of the current local transaction from the logs of the service database according to the transaction identifier contained in the rollback instruction and performing rollback on the current local transaction according to the transaction update log if the rollback instruction is received.
In a third aspect, an embodiment of the present specification provides a server, including: a memory, a processor and a computer program stored on the memory and executable on the processor, the processor implementing the steps of the distributed transaction processing method provided by the first aspect when executing the program.
In a fourth aspect, the present specification provides a computer readable storage medium, on which a computer program is stored, and the program, when executed by a processor, implements the steps of the distributed transaction processing method provided in the first aspect.
In the distributed transaction processing method provided in an embodiment of this specification, a primary key of service data to be updated is queried from a service database according to intercepted service SQL, then the service SQL is executed to update the service data, after the execution is successful, a row lock for the updated service data is generated according to the queried primary key and a transaction identifier of a current local transaction, and the transaction identifier is stored in a log of the service database corresponding to the local transaction, and if a rollback instruction is received at two stages, a transaction update log of the local transaction can be found from the log of the service database according to the transaction identifier included in the rollback instruction to perform rollback. The processing process does not need to specially inquire and store the data mirror image of the business data before and after updating in one stage of the transaction processing, reduces the operation steps of the transaction processing flow, and performs rollback of local transactions according to the transaction update log in two stages of the transaction processing by utilizing a database replication technology. Therefore, the transaction processing flow in the non-intrusive mode can be effectively optimized while the normal realization of the two phases of the distributed transaction is effectively ensured, and the consumption of the system performance is favorably reduced. In addition, because the data mirror does not need to be specially stored in the service database, the system performance consumption is unrelated to the data volume needing to be updated, the influence of the data volume requiring to be updated on the system performance consumption can be eliminated, and the system performance consumption is further reduced.
Drawings
Fig. 1 is a schematic view of an application scenario of a distributed transaction processing method provided in an embodiment of the present specification;
FIG. 2 is a flowchart illustrating steps of a distributed transaction processing method according to a first aspect of an embodiment of the present disclosure;
FIG. 3 is a flowchart illustrating an operation of a distributed transaction processing method according to a first aspect of an embodiment of the present specification;
FIG. 4 is a block diagram of a distributed transaction processing apparatus provided in a second aspect of embodiments of the present specification;
fig. 5 is a schematic structural diagram of a server provided in the third aspect of the embodiment of the present disclosure.
Detailed Description
With the development of services, services become more and more complex, and a plurality of service platforms split services, so that one service activity can be completed only by calling a plurality of services and accessing a plurality of databases. Taking a transfer scene under a financial business scene as an example, the transfer service needs to complete the following operations: 1. calling a transaction system service to create a transaction order; 2. calling a payment system to record payment details; 3. calling an accounting system to execute A money deduction; 4. and calling the accounting system to add money. The above four operations are across three business systems, accessing four databases. In this scenario, data consistency across services and across databases can be addressed through distributed transactional middleware.
The Distributed Transaction middleware has an intrusive mode such as an AT mode of a Distributed Transaction open source product (Seata) or a Framework-managed Transaction (FMT) mode of DTX (Distributed Transaction-eXtended). The greatest advantage of the AT/FMT mode is transparency to applications, non-intrusive, but the disadvantage is the large performance overhead. The embodiment of the specification provides a distributed transaction processing method in a non-intrusive mode, which can effectively optimize a transaction processing flow in the non-intrusive mode and reduce system performance overhead.
Fig. 1 is a schematic diagram illustrating an application scenario of the distributed transaction processing method provided by an embodiment of the present specification. In the distributed system shown in fig. 1, a server 100 as a coordinator, and a server 101 and a server 102 as participants are included. Server 101 and server 102 are each connected to server 100 via a network. There may be a plurality of participants, the specific number is determined according to the actual application scenario, and the number of servers as the participants in fig. 1 is only an illustration and is not limited. When a transaction needs to be split into multiple sub-transactions and executed by multiple different servers, the transaction may become a global transaction, and the corresponding sub-transactions may be referred to as branch transactions. The server responsible for the generation of the global transaction, as well as the processing of the branch transaction, may be referred to as the coordinator. The server responsible for the processing of the branch transaction may act as a participant.
The distributed transaction processing method provided in the embodiment of the present specification can be applied to a server serving as a participant in the distributed system, and serve as a distributed transaction middleware to implement a distributed transaction processing flow that is non-intrusive to a service.
In order to better understand the technical solutions provided by the embodiments of the present specification, the technical solutions of the embodiments of the present specification are described in detail below with reference to the drawings and specific embodiments, and it should be understood that the specific features in the embodiments and examples of the present specification are detailed descriptions of the technical solutions of the embodiments of the present specification, and are not limitations on the technical solutions of the embodiments of the present specification, and the technical features in the embodiments and examples of the present specification may be combined with each other without conflict. In the embodiments of the present specification, the term "plurality" means "two or more", that is, includes two or more.
In a first aspect, fig. 2 shows a flowchart of a distributed transaction processing method provided by an embodiment of the present specification, which is applied to a server as a transaction participant. Referring to fig. 2, the method may include the following steps S101 to S103.
And step S101, inquiring a main key of service data to be updated from a service database according to the intercepted service SQL.
The user triggers business operations needing to be completed by coordination of a plurality of participants, such as payment operations, transfer operations and the like, through an application program installed on a user terminal, namely a client, and the client sends a business processing request to a server terminal of the client. After receiving the service processing request, the server serves as a transaction initiator, namely a coordination direction to register global transaction with the transaction manager. And the transaction manager allocates a transaction identifier, namely txid (transaction id), for uniquely identifying the global transaction to the global transaction, and sends the transaction identifier to the server side of the application program for storage.
After the transaction initiator starts the global transaction, the business operation triggered by the user is realized by calling the participant to execute the business SQL (structured query language). The business SQL is an SQL statement for executing business operations. The global transaction comprises a plurality of transaction branches, each transaction branch corresponds to one participant, and the transaction initiator generates corresponding business SQL aiming at each transaction branch so as to execute the business SQL at the corresponding participant to complete the branch transaction. For example, a global transaction is an A-to-B transfer of 30 elements, then two transaction branches are included. One is deducting 30 yuan from account A, the business SQL executed by the branch transaction is to subtract 30 yuan from the balance of account A in the corresponding business database, and the other is to add 30 yuan to account B, and the business SQL executed by the branch transaction is to add 30 yuan from the balance of account B in the corresponding business database.
In this embodiment of the present description, at a stage of executing a transaction, by intercepting execution of business SQL of a participant, before the business SQL is executed, primary keys of business data to be updated are first queried from a business database according to the intercepted business SQL, so as to generate a row lock according to the primary keys, and ensure that data corresponding to the primary keys are locked before the transaction is finally submitted, so as to avoid dirty data.
Specifically, as shown in fig. 3, the semantics of the business SQL may be parsed and then the table metadata may be extracted. The purpose of analyzing business SQL semantics is to facilitate finding business data to be updated by business, and the purpose of extracting table metadata is to facilitate finding a main key and a uniqueness constraint key of a business table in a business database and generating a row lock. The table metadata may include Schema information for the table, such as the table's primary key, unique key, and column name, among others. Therefore, a select part of the SQL statement can be generated through the column name of the main key of the table, and the where part is intercepted from the business SQL, so that the SQL statement for inquiring the main key can be generated, and the SQL statement is executed to inquire the main key list of the business data to be updated. After the primary key of the service data to be updated is queried, the local transaction of the participant can be started, and the following step S102 is executed without querying and saving the data mirror image of the service data before updating.
It can be understood that the service database managed by the participant stores therein a service table, and the service table is stored in a two-dimensional table form. Each row in the service table is a record, or tuple, and each column is a field, or attribute.
Step S102, the business SQL is executed to update the business data to be updated, after the execution is successful, a row lock aiming at the updated business data is generated according to the inquired main key and the business identifier of the current local business, and the business identifier is stored in the log of the business database corresponding to the current local business.
As shown in fig. 3, after the primary key of the service data to be updated is queried, the local transaction can be opened for the database operation. By executing the service SQL, corresponding service data in the service database (i.e., the service DB in fig. 3) is updated. Moreover, in order to ensure that the data corresponding to the primary keys are locked before the transaction is submitted, so as to avoid dirty data, after the business SQL is successfully executed, a row lock for the updated business data needs to be generated according to the primary key queried in step S101 and the transaction identifier of the current local transaction, and the generated row lock is stored. In the specific implementation process, the generated row lock may be sent to the transaction server for storage, or may be stored in the service database. For example, the FMT co-repository mode is stored in the service database, and the Seata AT mode is stored in the transaction Server.
Thereafter, the local transaction may be committed, i.e., an acknowledgement that the local transaction executed successfully is committed. So that the transaction initiator triggers two-phase commit/rollback operations according to the acknowledgement information submitted by each participant.
It should be noted that, in step S102, after the business SQL is executed, the data mirror of the updated business data does not need to be queried and saved.
In the embodiment of the present specification, the service databases managed by the participants all have a master-slave copy function, and the service databases will automatically generate local transaction logs for recording all local transactions and modifications made to the databases by each local transaction. Therefore, in the execution process of each local transaction, when the business database executes the business SQL, the local transaction log including the data mirror before and after the business data update is automatically generated and stored in the file system of the server where the business database is located. Of course, the local transaction log of the service database record includes other data, such as a timestamp, besides the data mirror before and after the service data update, and the records of different data types are slightly different.
The local transaction log automatically generated by the service database belongs to streaming data and comprises start and end marks of the local transaction. By identifying the start and end markers of the local transactions, the individual local transactions can be distinguished, but the correspondence between the log of the local transaction and the global transaction is unknown. Therefore, in order to find the required local transaction log from the log of the service database, the transaction identifier of the currently executed local transaction needs to be saved in the log corresponding to the local transaction in the service database while generating the row lock. Thus, by matching the transaction identifier inserted in the local transaction log in the log of the traffic database, the transaction update log corresponding to the local transaction currently to be rolled back can be found.
That is, in step S102, the implementation process of generating a row lock for updated service data according to the queried primary key and the transaction identifier of the current local transaction may include: acquiring a transaction identifier of a current local transaction; and inserting the inquired primary key and the transaction identifier into a row lock record table preset in a service database. In the specific implementation process, the table name of the service table in which the updated service data is located and the primary key information of the updated service data in the service table are recorded in the row lock recording table in correspondence with the transaction identifier of the current local transaction. Therefore, the service data is marked in a row lock mode and cannot be accessed by other distributed transactions, dirty data is avoided when the data is accessed, and strong consistency of the data accessed by the distributed transactions is improved. It can be understood that the name of the service table is unique, and the primary key value inside each service table is also unique, so that a piece of data can be uniquely determined by the name of the service table and the primary key information of the updated service data in the service table.
For example, an insert statement in the log may be utilized, with two fields inserted in the insert, one being the transaction identifier and the other being the value of the global lock. The value of the global lock is the table name of the service table where the updated service data is located and the primary key information of the updated service data in the service table, and may be a character string formed by the two. Meanwhile, the insert statement is also recorded in the log of the service database corresponding to the current local transaction, so that the transaction identifier of the current local transaction can be saved in the log of the current local transaction.
The transaction initiator, upon receiving the transaction identifier for the global transaction assigned by the transaction manager, may save the transaction identifier in the context of the thread to which the application belongs. Before executing the above step S101, when the transaction initiator invokes the service provided by the participant to request the participant to execute the corresponding branch transaction, the transaction initiator sends the transaction identifier to the participant, and may intercept the transaction identifier at the service entry of the participant and store the transaction identifier in the context of the thread to which the participant belongs. When a row lock needs to be generated, a transaction identifier may be obtained from the context, and the transaction identifier and the primary key queried in step S101 are correspondingly inserted into a row lock record table preset in the service database.
After the participant commits the local transaction, a phase of transaction processing is completed. If the transaction initiator monitors that more than one participant does not submit the local transaction on time, that is, the participant has an error in one stage, the rollback operation in the two stages is triggered, and a rollback instruction is sent to each participant, so that the participants execute the following step S103. If the transaction initiator monitors that all the participants submit the local transaction, that is, all the participants in the first phase are successfully executed, the transaction initiator triggers the two-phase submission operation and sends a submission instruction to each participant, so that the participants execute the following step S104.
Step S103, if a rollback instruction is received, inquiring a transaction update log of the current local transaction from the logs of the service database according to the transaction identifier contained in the rollback instruction, and rolling back the current local transaction according to the transaction update log.
When receiving the two-stage rollback instruction, the participating party needs to rollback the local transaction submitted in the step S102, and restore the service data updated by the service SQL executed in the step S102 to the state before updating. In the embodiment of the present specification, the before-update and after-update mirror data required for rollback are obtained from a log of the business database. It should be noted that, for different database types, the update logs of the database types are queried in different ways, specifically according to the interface submitted by the actual database type.
The rollback instruction sent by the transaction initiator contains the transaction identifier of the global transaction to be rolled back. The aforementioned process of querying the transaction update log of the current local transaction from the log of the transaction database according to the transaction identifier included in the rollback instruction may include: extracting a transaction identifier from the rollback instruction; in the log of the service database, searching the log containing the transaction identifier, namely searching the local transaction log containing the transaction identifier in the rollback instruction; and taking the searched local transaction log as a transaction update log of the current local transaction.
The logs of the service database comprise a plurality of local transaction logs, namely a plurality of local transaction logs, and different local transaction logs are distinguished through start marks and end marks of the local transactions. Each local transaction log stores a transaction identifier of the local transaction, that is, a transaction identifier of a global transaction associated with the local transaction, so that the local transaction log of the local transaction to be rolled back at this time can be filtered from a plurality of local transaction logs by matching the transaction identifiers.
Further, after finding the transaction update log of the current local transaction, the process of rolling back the current local transaction according to the transaction update log may include: extracting data mirror images of the service data to be updated before and after updating from the transaction update log; and rolling back the current local transaction through the data mirror image before and after updating. It is understood that the transaction update log of the business database may include a timestamp and a data mirror before and after the business data update.
In the specific implementation process, firstly, dirty writes need to be checked. The dirty write checking mode is to compare the updated mirror image data extracted from the transaction update log with the current value of the service data in the service database, if the two data are completely consistent, it indicates that the dirty write does not occur, and if the two data are not consistent, it indicates that the dirty write occurs. If dirty writing occurs, manual processing is required, and the extracted updated mirror image data can not be used for rolling back the service data.
Then, the service data is restored. And if the dirty writing does not occur, rolling back the service data by using the before-update mirror image data extracted from the transaction update log to restore the service data to the before-update value.
Finally, the intermediate data is deleted. After the service data is restored, all the intermediate data stored in one stage can be deleted, and the rollback operation is completed. Since the distributed transaction processing method provided by the embodiment of the present specification only stores row locks at one stage, only row locks need to be deleted.
And step S104, if the participant receives the submission instruction, deleting the generated row lock. Since business SQL is already submitted to the business database in one stage, two-stage submission only needs to delete the intermediate data saved in one stage. Since the distributed transaction processing method provided by the embodiment of the present specification only stores row locks at one stage, only row locks need to be deleted. Compared with the AT mode of Seata or the FMT mode of DTX, the method reduces intermediate data needing to be deleted, is beneficial to reducing the operation steps of a transaction processing flow, and therefore reduces consumption on system performance.
In the distributed transaction processing method provided in the embodiments of the present description, it is not necessary to query and store the data mirror of the service data before and after updating in one stage of the distributed transaction processing, so that the operation steps of the transaction processing flow are reduced, and the transaction update log is searched for by the transaction identifier in the log of the service database to perform rollback in two stages of the transaction processing by using the database replication technology. Compared with the AT mode of Seata or the FMT mode of DTX, the distributed transaction processing method can ensure normal realization of two phases of distributed transactions, effectively optimize the transaction processing flow of a non-intrusive mode and is beneficial to reducing consumption of system performance. In addition, data mirror images before and after service data updating do not need to be specially stored in the data file of the service database, so that the system performance consumption is unrelated to the data volume updated by the service SQL, the influence of the data volume requested to be updated on the system performance consumption can be eliminated, and the system performance consumption is further reduced.
In a second aspect, based on the same inventive concept as the distributed transaction processing method provided in the foregoing first aspect, an embodiment of this specification further provides a distributed transaction processing apparatus operating in a server as a transaction participant. As shown in fig. 4, the distributed transaction processing apparatus 40 includes:
the query module 41 is configured to query a primary key of service data to be updated from the service database according to the intercepted service SQL;
the transaction processing module 42 is configured to update the service data to be updated by executing the service SQL, generate a row lock for the updated service data according to the queried primary key and the transaction identifier of the current local transaction after the execution is successful, and store the transaction identifier in a log of the service database corresponding to the current local transaction;
a rollback module 43, configured to, if a rollback instruction is received, query, according to a transaction identifier included in the rollback instruction, a transaction update log of the current local transaction from logs of the service database, and rollback the current local transaction according to the transaction update log.
In an alternative embodiment, the rollback module 43 comprises: the log query submodule 431 is configured to search a local transaction log containing the transaction identifier in the rollback instruction from logs in the service database; and taking the searched local transaction log as a transaction update log of the local transaction.
In an alternative embodiment, the rollback module 43 comprises:
an extracting submodule 432, configured to extract, from the transaction update log, data mirrors of the service data to be updated before and after updating;
and the rollback sub-module 433 is configured to rollback the current local transaction through the pre-update and post-update data images.
In an alternative embodiment, the transaction module 42 is configured to: acquiring a transaction identifier of the current local transaction; and inserting the inquired primary key and the transaction identifier into a row lock record table preset in the service database.
In an optional embodiment, the distributed transaction processing apparatus 40 further includes: and the submitting module 44 is configured to delete the row lock if a submitting instruction is received.
It should be noted that, in the distributed transaction processing apparatus 40 provided in the embodiment of the present specification, specific ways in which the respective modules perform operations have been described in detail in the method embodiment provided in the foregoing first aspect, and specific implementation processes may refer to the method embodiment provided in the foregoing first aspect, and will not be described in detail here.
In a third aspect, based on the same inventive concept as the distributed transaction processing method provided in the foregoing embodiment, an embodiment of the present specification further provides a server. As shown in fig. 5, the server comprises a memory 504, one or more processors 502 and a computer program stored on the memory 504 and executable on the processors 502, the processor 502 implementing the steps of any of the embodiments of the distributed transaction processing method provided in the first aspect when executing the program.
Where in fig. 5 a bus architecture (represented by bus 500) is shown, bus 500 may include any number of interconnected buses and bridges, and bus 500 links together various circuits including one or more processors, represented by processor 502, and memory, represented by memory 504. The bus 500 may also link together various other circuits such as peripherals, voltage regulators, power management circuits, and the like, which are well known in the art, and therefore, will not be described any further herein. A bus interface 505 provides an interface between the bus 500 and the receiver 501 and transmitter 503. The receiver 501 and the transmitter 503 may be the same element, i.e. a transceiver, providing a means for communicating with various other apparatus over a transmission medium. The processor 502 is responsible for managing the bus 500 and general processing, and the memory 504 may be used for storing data used by the processor 502 in performing operations.
It is to be understood that the configuration shown in fig. 5 is merely an illustration, and that the server provided by the embodiments of the present description may also include more or fewer components than shown in fig. 5, or have a different configuration than shown in fig. 5. The components shown in fig. 5 may be implemented in hardware, software, or a combination thereof.
In a fourth aspect, based on the same inventive concept as the distributed transaction processing method provided in the foregoing embodiments, the present specification embodiment further provides a computer readable storage medium, on which a computer program is stored, which when executed by a processor, implements the steps of any of the embodiments of the distributed transaction processing method provided in the foregoing first aspect.
The foregoing description has been directed to specific embodiments of this disclosure. Other embodiments are within the scope of the following claims. In some cases, the actions or steps recited in the claims may be performed in a different order than in the embodiments and still achieve desirable results. In addition, the processes depicted in the accompanying figures do not necessarily require the particular order shown, or sequential order, to achieve desirable results. In some embodiments, multitasking and parallel processing may also be possible or may be advantageous.
The description has been presented with reference to flowchart illustrations and/or block diagrams of methods, apparatus (systems), and computer program products according to embodiments of the description. It will be understood that each flow and/or block of the flow diagrams and/or block diagrams, and combinations of flows and/or blocks in the flow diagrams and/or block diagrams, can be implemented by computer program instructions. These computer program instructions may be provided to a processor of a general purpose computer, special purpose computer, embedded processor, or other programmable data processing apparatus to produce a machine, such that the instructions, which execute via the processor of the computer or other programmable data processing apparatus, create means for implementing the functions specified in the flowchart flow or flows and/or block diagram block or blocks.
These computer program instructions may also be stored in a computer-readable memory that can direct a computer or other programmable data processing apparatus to function in a particular manner, such that the instructions stored in the computer-readable memory produce an article of manufacture including instruction means which implement the function specified in the flowchart flow or flows and/or block diagram block or blocks.
These computer program instructions may also be loaded onto a computer or other programmable data processing apparatus to cause a series of operational steps to be performed on the computer or other programmable apparatus to produce a computer implemented process such that the instructions which execute on the computer or other programmable apparatus provide steps for implementing the functions specified in the flowchart flow or flows and/or block diagram block or blocks.
While preferred embodiments of the present specification have been described, additional variations and modifications in those embodiments may occur to those skilled in the art once they learn of the basic inventive concepts. Therefore, it is intended that the appended claims be interpreted as including preferred embodiments and all changes and modifications that fall within the scope of the specification.
It will be apparent to those skilled in the art that various changes and modifications may be made in the present specification without departing from the spirit and scope of the specification. Thus, if such modifications and variations of the present specification fall within the scope of the claims of the present specification and their equivalents, the specification is intended to include such modifications and variations.

Claims (12)

1. A distributed transaction processing method, comprising:
inquiring a main key of service data to be updated from a service database according to the intercepted service SQL;
updating the service data to be updated by executing the service SQL, generating a row lock aiming at the updated service data according to the inquired main key and the transaction identifier of the current local transaction after the execution is successful, and storing the transaction identifier into a log of the service database corresponding to the current local transaction;
and if a rollback instruction is received, inquiring a transaction update log of the current local transaction from the logs of the service database according to a transaction identifier contained in the rollback instruction, and rolling back the current local transaction according to the transaction update log.
2. The method of claim 1, wherein the querying a transaction update log of the current local transaction from a log of the traffic database according to a transaction identifier included in the rollback instruction comprises:
searching a local transaction log containing the transaction identifier in the rollback instruction from logs of a service database;
and taking the searched local transaction log as a transaction update log of the current local transaction.
3. The method of claim 1, the rolling back the current local transaction from the transaction update log, comprising:
extracting data mirror images of the service data to be updated before and after updating from the transaction update log;
and rolling back the current local transaction through the data mirror images before and after the update.
4. The method of claim 1, wherein generating a row lock for the updated business data according to the queried primary key and the transaction identifier of the current local transaction comprises:
acquiring a transaction identifier of the current local transaction;
and inserting the inquired primary key and the transaction identifier into a row lock record table preset in the service database.
5. The method of claim 1, further comprising:
and if a submitting instruction is received, deleting the row lock.
6. A distributed transaction processing apparatus, comprising:
the query module is used for querying a main key of the service data to be updated from the service database according to the intercepted service SQL;
the transaction processing module is used for updating the service data to be updated by executing the service SQL, generating a row lock aiming at the updated service data according to the inquired main key and the transaction identifier of the current local transaction after the execution is successful, and storing the transaction identifier into a log of the service database corresponding to the current local transaction;
and the rollback module is used for inquiring the transaction update log of the current local transaction from the logs of the service database according to the transaction identifier contained in the rollback instruction and performing rollback on the current local transaction according to the transaction update log if the rollback instruction is received.
7. The apparatus of claim 6, the rollback module comprising:
the log query submodule is used for searching a local transaction log containing the transaction identifier in the rollback instruction from the logs of the service database; and taking the searched local transaction log as a transaction update log of the local transaction.
8. The apparatus of claim 6, the rollback module comprising:
the extraction submodule is used for extracting data mirror images of the service data to be updated before and after updating from the transaction update log;
and the rollback sub-module is used for rolling back the current local transaction through the data mirror images before and after the update.
9. The apparatus of claim 6, the transaction processing module to:
acquiring a transaction identifier of the current local transaction;
and inserting the inquired primary key and the transaction identifier into a row lock record table preset in the service database.
10. The apparatus of claim 6, further comprising:
and the submitting module is used for deleting the row lock if a submitting instruction is received.
11. A server, comprising: memory, processor and computer program stored on the memory and executable on the processor, the processor implementing the steps of the method of any one of claims 1-5 when executing the program.
12. A computer-readable storage medium, on which a computer program is stored which, when being executed by a processor, carries out the steps of the method of any one of claims 1 to 5.
CN202010209587.2A 2020-03-23 2020-03-23 Distributed transaction processing method, device, server and medium Active CN111522631B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202010209587.2A CN111522631B (en) 2020-03-23 2020-03-23 Distributed transaction processing method, device, server and medium

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202010209587.2A CN111522631B (en) 2020-03-23 2020-03-23 Distributed transaction processing method, device, server and medium

Publications (2)

Publication Number Publication Date
CN111522631A true CN111522631A (en) 2020-08-11
CN111522631B CN111522631B (en) 2024-02-06

Family

ID=71900960

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202010209587.2A Active CN111522631B (en) 2020-03-23 2020-03-23 Distributed transaction processing method, device, server and medium

Country Status (1)

Country Link
CN (1) CN111522631B (en)

Cited By (9)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN112182082A (en) * 2020-09-24 2021-01-05 广州巨杉软件开发有限公司 System and method for realizing strong consistency of transactions across different database engines
CN112395102A (en) * 2020-10-15 2021-02-23 北京仿真中心 Distributed database middleware solution method
CN112764888A (en) * 2021-01-21 2021-05-07 中信银行股份有限公司 Distributed transaction checking and judging method and system based on log analysis
CN112995304A (en) * 2021-02-08 2021-06-18 中国工商银行股份有限公司 Method and device for processing routing service node by two-stage distributed transaction
CN113010495A (en) * 2021-03-19 2021-06-22 北京三快在线科技有限公司 Database optimization method and device
CN113342481A (en) * 2021-07-07 2021-09-03 中国工商银行股份有限公司 Transaction state confirmation method and device
CN114385320A (en) * 2020-10-22 2022-04-22 支付宝(杭州)信息技术有限公司 Distributed transaction processing method and system
CN115905402A (en) * 2022-09-26 2023-04-04 北京奥星贝斯科技有限公司 Method and device for processing transaction log
WO2023134518A1 (en) * 2022-01-17 2023-07-20 北京奥星贝斯科技有限公司 Method and apparatus for querying modified content of transaction in database

Citations (13)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN102831156A (en) * 2012-06-29 2012-12-19 浙江大学 Distributed transaction processing method on cloud computing platform
US20130036136A1 (en) * 2011-08-01 2013-02-07 International Business Machines Corporation Transaction processing system, method and program
US20130262423A1 (en) * 2012-03-29 2013-10-03 Goetz Graefe Controlled lock violation for data transactions
US9171019B1 (en) * 2013-02-19 2015-10-27 Amazon Technologies, Inc. Distributed lock service with external lock information database
CN106033437A (en) * 2015-03-13 2016-10-19 阿里巴巴集团控股有限公司 Method and system for processing distributed transaction
CN106033439A (en) * 2015-03-13 2016-10-19 阿里巴巴集团控股有限公司 Method and system for processing distributed transaction
WO2016180164A1 (en) * 2015-09-29 2016-11-17 中兴通讯股份有限公司 Method and apparatus for rolling back distributed transaction
CN106610876A (en) * 2015-10-23 2017-05-03 中兴通讯股份有限公司 Method and device for recovering data snapshot
US9830223B1 (en) * 2015-01-26 2017-11-28 Intel Corporation Methods for repairing a corrupted database to a new, correct state
US20180137166A1 (en) * 2016-11-17 2018-05-17 Sap Se Database Systems Architecture Incorporating Distributed Log
CN109783204A (en) * 2018-12-28 2019-05-21 咪咕文化科技有限公司 A kind of distributed transaction processing method, device and storage medium
US20190188097A1 (en) * 2017-12-15 2019-06-20 Vmware, Inc. Mirrored write ahead logs for data storage system
CN110888718A (en) * 2019-11-27 2020-03-17 武汉虹旭信息技术有限责任公司 Method and device for realizing distributed transaction

Patent Citations (13)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20130036136A1 (en) * 2011-08-01 2013-02-07 International Business Machines Corporation Transaction processing system, method and program
US20130262423A1 (en) * 2012-03-29 2013-10-03 Goetz Graefe Controlled lock violation for data transactions
CN102831156A (en) * 2012-06-29 2012-12-19 浙江大学 Distributed transaction processing method on cloud computing platform
US9171019B1 (en) * 2013-02-19 2015-10-27 Amazon Technologies, Inc. Distributed lock service with external lock information database
US9830223B1 (en) * 2015-01-26 2017-11-28 Intel Corporation Methods for repairing a corrupted database to a new, correct state
CN106033437A (en) * 2015-03-13 2016-10-19 阿里巴巴集团控股有限公司 Method and system for processing distributed transaction
CN106033439A (en) * 2015-03-13 2016-10-19 阿里巴巴集团控股有限公司 Method and system for processing distributed transaction
WO2016180164A1 (en) * 2015-09-29 2016-11-17 中兴通讯股份有限公司 Method and apparatus for rolling back distributed transaction
CN106610876A (en) * 2015-10-23 2017-05-03 中兴通讯股份有限公司 Method and device for recovering data snapshot
US20180137166A1 (en) * 2016-11-17 2018-05-17 Sap Se Database Systems Architecture Incorporating Distributed Log
US20190188097A1 (en) * 2017-12-15 2019-06-20 Vmware, Inc. Mirrored write ahead logs for data storage system
CN109783204A (en) * 2018-12-28 2019-05-21 咪咕文化科技有限公司 A kind of distributed transaction processing method, device and storage medium
CN110888718A (en) * 2019-11-27 2020-03-17 武汉虹旭信息技术有限责任公司 Method and device for realizing distributed transaction

Non-Patent Citations (1)

* Cited by examiner, † Cited by third party
Title
张淑玉;: "SQL Server数据库的备份与恢复", 潍坊学院学报, no. 06 *

Cited By (12)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN112182082A (en) * 2020-09-24 2021-01-05 广州巨杉软件开发有限公司 System and method for realizing strong consistency of transactions across different database engines
CN112395102A (en) * 2020-10-15 2021-02-23 北京仿真中心 Distributed database middleware solution method
CN114385320A (en) * 2020-10-22 2022-04-22 支付宝(杭州)信息技术有限公司 Distributed transaction processing method and system
CN112764888A (en) * 2021-01-21 2021-05-07 中信银行股份有限公司 Distributed transaction checking and judging method and system based on log analysis
CN112995304A (en) * 2021-02-08 2021-06-18 中国工商银行股份有限公司 Method and device for processing routing service node by two-stage distributed transaction
CN112995304B (en) * 2021-02-08 2022-09-23 中国工商银行股份有限公司 Method and device for processing routing service node by two-stage distributed transaction
CN113010495A (en) * 2021-03-19 2021-06-22 北京三快在线科技有限公司 Database optimization method and device
CN113342481A (en) * 2021-07-07 2021-09-03 中国工商银行股份有限公司 Transaction state confirmation method and device
CN113342481B (en) * 2021-07-07 2024-03-26 中国工商银行股份有限公司 Transaction state confirmation method and device
WO2023134518A1 (en) * 2022-01-17 2023-07-20 北京奥星贝斯科技有限公司 Method and apparatus for querying modified content of transaction in database
CN115905402A (en) * 2022-09-26 2023-04-04 北京奥星贝斯科技有限公司 Method and device for processing transaction log
CN115905402B (en) * 2022-09-26 2023-07-18 北京奥星贝斯科技有限公司 Method and device for processing transaction log

Also Published As

Publication number Publication date
CN111522631B (en) 2024-02-06

Similar Documents

Publication Publication Date Title
CN111522631B (en) Distributed transaction processing method, device, server and medium
CN109739935B (en) Data reading method and device, electronic equipment and storage medium
US9779128B2 (en) System and method for massively parallel processing database
US9672017B2 (en) Object storage and synchronization hooks for occasionally-connected devices
US7366738B2 (en) Method and system for object cache synchronization
US11392588B2 (en) Active queries filter extraction
CN111259083A (en) Distributed transaction processing method and device
US9747356B2 (en) Eager replication of uncommitted transactions
US5920857A (en) Efficient optimistic concurrency control and lazy queries for B-trees and other database structures
US11429599B2 (en) Method and apparatus for updating database by using two-phase commit distributed transaction
CN111143389A (en) Transaction execution method and device, computer equipment and storage medium
CN105608086A (en) Transaction processing method and device of distributed database system
CN111881223B (en) Data management method, device, system and storage medium
US11947524B2 (en) Transaction processing method and apparatus, computer device, and storage medium
US7478112B2 (en) Method and apparatus for initializing data propagation execution for large database replication
CN111597015A (en) Transaction processing method and device, computer equipment and storage medium
CN111062684B (en) System and method for realizing consistency processing of business data and process data under cloud process platform
CN111797121A (en) Strong consistency query method, device and system for read-write separation architecture service system
US20020188624A1 (en) Active control protocol for peer-to-peer database replication
US20050144299A1 (en) System and method for supporting XA 2-phase commit protocols with a loosely coupled clustered database server
US20090100082A1 (en) Replication and mapping mechanism for recreating memory durations
CN112800060A (en) Data processing method and device, computer readable storage medium and electronic equipment
WO2023124242A1 (en) Transaction execution method and apparatus, device, and storage medium
CN114461454A (en) Data recovery method and device, storage medium and electronic equipment
CN114661690A (en) Multi-version concurrency control and log clearing method, node, equipment and medium

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination
GR01 Patent grant
GR01 Patent grant