CN117369955A - Transaction processing method and device and electronic equipment - Google Patents

Transaction processing method and device and electronic equipment Download PDF

Info

Publication number
CN117369955A
CN117369955A CN202210757083.3A CN202210757083A CN117369955A CN 117369955 A CN117369955 A CN 117369955A CN 202210757083 A CN202210757083 A CN 202210757083A CN 117369955 A CN117369955 A CN 117369955A
Authority
CN
China
Prior art keywords
transaction
database
target
processed
message
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.)
Pending
Application number
CN202210757083.3A
Other languages
Chinese (zh)
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.)
China Telecom Corp Ltd
Original Assignee
China Telecom Corp 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 China Telecom Corp Ltd filed Critical China Telecom Corp Ltd
Priority to CN202210757083.3A priority Critical patent/CN117369955A/en
Publication of CN117369955A publication Critical patent/CN117369955A/en
Pending legal-status Critical Current

Links

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
    • 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/54Interprogram communication
    • G06F9/546Message passing systems or structures, e.g. queues

Landscapes

  • Engineering & Computer Science (AREA)
  • Software Systems (AREA)
  • Theoretical Computer Science (AREA)
  • Physics & Mathematics (AREA)
  • General Engineering & Computer Science (AREA)
  • General Physics & Mathematics (AREA)
  • Information Retrieval, Db Structures And Fs Structures Therefor (AREA)

Abstract

The embodiment of the invention provides a transaction processing method, a transaction processing device and electronic equipment, and relates to the technical field of computer software. In processing transactions with respect to a target database, a transaction to be processed for target data in the target database may first be determined; then executing the transaction to be processed, and submitting the transaction after the transaction to be processed is successfully executed; thus, after the transaction is submitted successfully, the database log of the target database can be updated; then, reading an execution result about the target data from the database log; and further, generating a message to be sent according to the execution result, and sending the message to be sent to a designated message queue. Compared with the prior art, the scheme provided by the embodiment of the invention can reduce the implementation difficulty of two systems of the database and the message queue in the same transaction.

Description

Transaction processing method and device and electronic equipment
Technical Field
The present invention relates to the field of computer software technologies, and in particular, to a transaction processing method, a transaction processing device, and an electronic device.
Background
A Transaction (Transaction) is a basic unit of data recovery and concurrency control, and one Transaction may include one or more operations therein, while individual operations belonging to the same Transaction are successful or failed simultaneously. Wherein a data processing operation and a messaging operation may be included in a database transaction, and when one of the two operations fails, the transaction is considered to fail, i.e., both the data update operation and the messaging operation fail.
In the prior art, data processing operations and messaging operations in databases are typically implemented simultaneously by introducing a distributed transaction mechanism (Distributed Transaction) to place the data processing operations and messaging operations in the same transaction. Wherein, the distributed transaction mechanism means that a participant of a transaction, a server supporting the transaction, a resource server and a transaction manager are respectively located on different nodes of different distributed systems.
However, in the prior art, a distributed transaction mechanism is introduced, which increases the complexity of a service program and causes code intrusion to the existing service code, so that the code for processing the transaction is complex, and more computing resources are required to be consumed, thereby increasing the implementation difficulty of two systems of a database and a message queue in the same transaction.
Disclosure of Invention
The embodiment of the invention aims to provide a transaction processing method, a transaction processing device and electronic equipment, so as to reduce the implementation difficulty of two systems of a database and a message queue in the same transaction. The specific technical scheme is as follows:
in a first aspect, an embodiment of the present invention provides a transaction processing method, where the method includes:
Determining a transaction to be processed for target data in a target database;
executing the transaction to be processed, and performing transaction submission after the transaction to be processed is successfully executed;
after the transaction is submitted successfully, updating a database log of the target database;
reading an execution result about the target data from the database log;
and generating a message to be sent according to the execution result, and sending the message to be sent to a designated message queue.
Optionally, in a specific implementation manner, after the transaction is submitted successfully, updating a database log of the target database includes:
after the transaction is submitted successfully, the execution result of the transaction to be processed is persisted to the database log;
the method further comprises the steps of:
and when the message to be sent fails to be sent to the appointed message queue, returning to the step of generating the message to be sent according to the execution result and sending the message to be sent to the appointed message queue until the message to be sent is successfully sent to the appointed message queue.
Optionally, in a specific implementation manner, the method further includes:
And rolling back when the execution of the transaction to be processed fails.
Optionally, in a specific implementation manner, after the transaction is submitted successfully, updating a database log of the target database includes:
writing a data change target table about the target data in a database log of the target database after successful transaction submission;
the reading the execution result of the target data from the database log comprises the following steps:
and reading the database log, and obtaining the data change target table to obtain an execution result related to the target data.
Optionally, in a specific implementation manner, the electronic device for executing the method includes: a business processing component, a target database and an analysis component;
wherein the determining a transaction to be processed for target data in a target database comprises:
the business processing component determines a transaction to be processed for target data in a target database;
the executing the transaction to be processed, and performing transaction submission after the transaction to be processed is successfully executed, includes:
the business processing component executes the transaction to be processed and performs transaction submission after the transaction to be processed is successfully executed;
After the transaction is submitted successfully, updating the database log of the target database, which comprises the following steps:
the target database receives the transaction submitted by the service processing component and updates the database log;
the reading the execution result of the target data from the database log comprises the following steps:
the analysis component reads an execution result about the target data from the database log;
generating a message to be sent according to the execution result, and sending the message to be sent to a designated message queue, including:
and the analysis component generates the message to be sent according to the execution result and sends the message to be sent to the appointed message queue.
Optionally, in a specific implementation manner, before the service processing component determines the transaction to be processed for the target data of the target database, the method further includes:
configuring the service processing component to be connected with the target database;
configuring read rights of the parsing component with respect to the database log of the target database.
In a second aspect, an embodiment of the present invention provides a transaction processing apparatus, including:
A business processing component for determining a transaction to be processed for target data in a target database; executing the transaction to be processed, and performing transaction submission after the transaction to be processed is successfully executed;
the target database is used for updating the database log of the target database after the transaction is submitted successfully;
the analysis component is used for reading the execution result of the target data from the database log; and generating a message to be sent according to the execution result, and sending the message to be sent to a designated message queue.
Optionally, in a specific implementation manner, the target database is specifically configured to:
after the transaction is submitted successfully, the execution result of the transaction to be processed is persisted to the database log;
the parsing component is further configured to:
and when the message to be sent fails to be sent to the appointed message queue, returning to the step of generating the message to be sent according to the execution result and sending the message to be sent to the appointed message queue until the message to be sent is successfully sent to the appointed message queue.
Optionally, in a specific implementation manner, the service processing component is further configured to:
And rolling back when the execution of the transaction to be processed fails.
Optionally, in a specific implementation manner, the target database is specifically configured to:
writing a data change target table about the target data in a database log after the transaction is submitted successfully;
the parsing component is specifically configured to:
and reading the database log, and obtaining the data change target table to obtain an execution result related to the target data.
Optionally, in a specific implementation manner, the apparatus further includes:
and the initialization module is used for configuring the business processing component to be connected with the target database and configuring the reading authority of the analysis component on the database log of the target database before the business processing component determines the transaction to be processed of the target data of the target database.
In a third aspect, an embodiment of the present invention provides an electronic device, including a processor, a communication interface, a memory, and a communication bus, where the processor, the communication interface, and the memory complete communication with each other through the communication bus;
a memory for storing a computer program;
and the processor is used for realizing the steps of any method embodiment when executing the program stored in the memory.
In a fourth aspect, embodiments of the present invention provide a computer readable storage medium having a computer program stored therein, which when executed by a processor, implements the steps of any of the method embodiments described above.
In a fifth aspect, embodiments of the present invention also provide a computer program product comprising instructions which, when run on a computer, cause the computer to perform the steps of any of the method embodiments described above.
The embodiment of the invention has the beneficial effects that:
the above can be seen that, by applying the technical scheme provided by the embodiment of the invention, when updating the target data in the target database, the transaction to be processed for the target data in the target database can be determined first; then executing the transaction to be processed, and submitting the transaction after the transaction to be processed is successfully executed; thus, after the transaction is submitted successfully, the database log of the target database can be updated; then, reading an execution result about the target data from the database log; and further, generating a message to be sent according to the execution result, and sending the message to be sent to a designated message queue.
Based on the above, by applying the technical scheme provided by the embodiment of the invention, the processing of the target data is realized by establishing the transaction to be processed about the target data and executing the transaction to be processed. And the established transaction to be processed only comprises the operation of carrying out data processing on the target data in the target database, and after the execution of the transaction to be processed is completed, the operation of generating a message to be sent according to the execution result and sending the message to be executed to the designated message queue is executed. In this way, the data processing operation and the message sending operation are executed as two steps, and a distributed transaction mechanism is not required to be introduced, so that the complexity of a service program can be prevented from being increased due to the introduction of the distributed transaction mechanism, and the risk of code intrusion caused by codes of the distributed transaction mechanism to the existing service codes is reduced, thereby reducing the implementation difficulty of two systems of a database and a message queue in the same transaction.
Drawings
In order to more clearly illustrate the embodiments of the invention or the technical solutions in the prior art, the drawings used in the embodiments or the description of the prior art will be briefly described below, and it is obvious that the drawings in the following description are only some embodiments of the invention, and other embodiments may be obtained according to these drawings to those skilled in the art.
FIG. 1 is a schematic flow chart of a transaction processing method according to an embodiment of the present invention;
FIG. 2 is a schematic diagram of another transaction processing method according to an embodiment of the present invention;
FIG. 3 is a schematic flow chart of a transaction processing method according to an embodiment of the present invention;
FIG. 4 is a schematic diagram of a specific example of a transaction method according to an embodiment of the present invention;
FIG. 5 is a schematic diagram of transaction execution code according to an embodiment of the present invention;
FIG. 6 is a schematic diagram of a transaction processing device according to an embodiment of the present invention;
fig. 7 is a schematic structural diagram of an electronic device according to an embodiment of the present invention.
Detailed Description
The following description of the embodiments of the present invention will be made clearly and completely with reference to the accompanying drawings, in which it is apparent that the embodiments described are only some embodiments of the present invention, but not all embodiments. Based on the embodiments of the present invention, those of ordinary skill in the art will be able to devise all other embodiments that are obtained based on this application and are within the scope of the present invention.
In the prior art, data processing operations and messaging operations in a database are typically implemented simultaneously by introducing a distributed transaction mechanism to place the data processing operations and the messaging operations in the same transaction. Wherein, the distributed transaction mechanism means that a participant of a transaction, a server supporting the transaction, a resource server and a transaction manager are respectively located on different nodes of different distributed systems. However, in the prior art, a distributed transaction mechanism is introduced, which increases the complexity of a service program and causes code intrusion to the existing service code, so that the code for processing the transaction is complex, and more computing resources are required to be consumed, thereby increasing the implementation difficulty of two systems of a database and a message queue in the same transaction.
In order to solve the above technical problems, an embodiment of the present invention provides a transaction processing method.
The method can be suitable for various application scenes with database transaction processing requirements, and when the method is applied, the transaction to be executed on the database can be firstly established, and the data update of the database can be realized by executing the transaction to be executed. The device where the designated message queue is located and the device executing the transaction processing method may be the same device or different devices.
Based on this, the embodiment of the present invention does not specifically limit the application scenario and execution subject of the method.
The transaction processing method provided by the embodiment of the invention can comprise the following steps:
determining a transaction to be processed for target data in a target database;
executing the transaction to be processed, and performing transaction submission after the transaction to be processed is successfully executed;
after the transaction is submitted successfully, updating a database log of the target database;
reading an execution result about the target data from the database log;
and generating a message to be sent according to the execution result, and sending the message to be sent to a designated message queue.
The above can be seen that, by applying the technical scheme provided by the embodiment of the invention, when updating the target data in the target database, the transaction to be processed for the target data in the target database can be determined first; then executing the transaction to be processed, and submitting the transaction after the transaction to be processed is successfully executed; thus, after the transaction is submitted successfully, the database log of the target database can be updated; then, reading an execution result about the target data from the database log; and further, generating a message to be sent according to the execution result, and sending the message to be sent to a designated message queue.
Based on the above, by applying the technical scheme provided by the embodiment of the invention, the processing of the target data is realized by establishing the transaction to be processed about the target data and executing the transaction to be processed. And the established transaction to be processed only comprises the operation of carrying out data processing on the target data in the target database, and after the execution of the transaction to be processed is completed, the operation of generating a message to be sent according to the execution result and sending the message to be executed to the designated message queue is executed. In this way, the data processing operation and the message sending operation are executed as two steps, and a distributed transaction mechanism is not required to be introduced, so that the complexity of a service program can be prevented from being increased due to the introduction of the distributed transaction mechanism, and the risk of code intrusion caused by codes of the distributed transaction mechanism to the existing service codes is reduced, thereby reducing the implementation difficulty of two systems of a database and a message queue in the same transaction.
A transaction processing method provided by the embodiment of the present invention is specifically described below with reference to the accompanying drawings.
Fig. 1 is a flow chart of a transaction processing method according to an embodiment of the present invention, as shown in fig. 1, the method may include the following steps S101 to S105.
S101: determining a transaction to be processed for target data in a target database;
upon receiving a processing request for target data in a target database, a transaction to be processed for the target data in the target database may be established for the processing request. Thus, when the transaction to be processed is processed, the operation indicated by the processing request can be executed in the database on the target data.
The processing request may be used to instruct to perform data processing on the target data in the target database, and it is reasonable that the data processing may include operations such as creation, deletion, and update of the target data, which are not specifically limited in the embodiment of the present invention.
S102: executing the transaction to be processed, and submitting the transaction after the transaction to be processed is successfully executed;
after the transaction to be processed is determined, the transaction to be processed can be executed, and when the transaction to be processed is executed successfully, an execution result of the transaction to be processed is obtained, and transaction submission is carried out on the transaction to be processed.
For example, the transaction to be processed is used for indicating that the target data a in the target database is modified to A1, and when the transaction to be processed is executed and the modification of the target data a to A1 is successful, the transaction to be processed is submitted.
Optionally, in a specific implementation manner, the transaction processing method provided by the embodiment of the present invention may further include the following step 11:
step 11: and rolling back when the execution of the transaction to be processed fails.
In this particular implementation, rollback may occur when executing a pending transaction fails. The rollback is an operation of returning to the correct state last time when the program update fails. That is, when the execution of the transaction to be processed fails, the target database and the target data in the target database are rolled back to the state before the execution of the transaction to be processed.
For example, the current state of the target data is state B, the transaction to be processed is executed to update the state of the target data from state B to state C, when the transaction to be processed is successfully executed, the state of the target data is updated to state C, and when the transaction to be processed is failed to be executed, rollback is performed to restore the state of the target data to state B.
Optionally, after the execution of the pending transaction fails and the rollback is performed to a state before the execution, a first notification message about rollback of the pending transaction may be output to prompt the relevant staff that the execution of the pending transaction fails.
Wherein, the outputting the first notification message may be: displaying the first notification message on a connected display screen; it may also be: it is reasonable to send out the alert sound related to the first notification message, and the embodiment of the present invention is not particularly limited.
S103: after the transaction is submitted successfully, updating a database log of the target database;
after the transaction is successfully submitted, the database log of the target database may be updated. That is, after the transaction is submitted to the transaction to be processed and the transaction is successfully submitted, it may indicate that the target data in the target database has been operated as the state of the target data indicated by the transaction to be processed, that is, after the transaction is submitted successfully, the data processing operation for the target data in the target database has been completed, so that the execution result about the target data obtained by executing the transaction to be processed for the target data in the target database has been determined, and further, the execution result may be written into the database log of the target database, thereby updating the database log of the target database.
When the database log of the target database is updated, the execution result of the target data may be written into the database log. When the transaction to be processed includes an operation on a plurality of target data, the execution result of each target data may be written into the database log sequentially according to the operation order on the plurality of target data.
Optionally, when the rollback occurs to the pending transaction, the transaction delivery is unsuccessful, and no writing is performed in the database log of the target database.
S104: reading an execution result about the target data from the database log;
and writing the execution result of the transaction to be processed into the database log, and after the database log is updated, obtaining the execution result about the target data by reading the database log.
Optionally, in a specific implementation manner, as shown in fig. 2, step S103 may further include the following step S1031:
s1031: writing a data change target table related to target data in a database log of a target database after the transaction is submitted successfully;
accordingly, in this specific implementation manner, the step S104 may further include the following step S1041:
s1041: and reading the database log, and obtaining a data change target table to obtain an execution result about target data.
In this specific implementation manner, after the transaction is submitted successfully, a data change target table related to the target data may be written in a database log of the target database. Then, the database log may be read, and the data change target table for the target data may be obtained from the database log, thereby obtaining an execution result for the target data.
S105: and generating a message to be sent according to the execution result, and sending the message to be sent to a designated message queue.
According to the execution result of the target data, a message to be sent about the target data can be generated, and the message to be sent can be sent to a designated message queue.
After the execution result about the target data is obtained, the execution result about the target data may be fed back to the related staff, and further, a message to be sent about the execution result about the target data may be generated based on the execution result, and the message to be sent may be sent to a designated message queue.
Optionally, the message to be sent is sent to the relevant staff member through a designated message queue, so as to prompt the relevant staff member about the execution result of the target data about the target data.
In the process of sending the message to be sent to the designated message queue, the sending failure may be caused by multiple factors such as equipment failure, network failure, sending error, etc.
Optionally, when the sending of the message to be sent fails, a second notification message about the sending failure of the message to be sent may be generated, and the second notification message is output, so as to prompt the relevant staff to know that the message to be sent is not sent to the designated message queue.
Wherein, the outputting the second notification message may be: displaying the second notification message on a connected display screen; it may also be: it is reasonable to send out the alert sound related to the second notification message, and the embodiment of the present invention is not particularly limited.
Alternatively, the relevant staff may look at the specified message queue to determine the execution result about the target data.
Optionally, in a specific implementation manner, as shown in step S103 in fig. 3, the following step S1032 may be included:
s1032: after the transaction is submitted successfully, the execution result aiming at the transaction to be processed is persisted to a database log;
the transaction processing method provided by the embodiment of the invention further comprises the following step S106:
and when the message to be sent fails to be sent to the appointed message queue, returning to the step of generating the message to be sent according to the execution result and sending the message to be sent to the appointed message queue until the message to be sent is successfully sent to the appointed message queue.
Among these, persistence is a mechanism for converting program data between a persistent state and an instantaneous state. That is, the transient data is persisted as persistent data.
After the transaction is submitted successfully, the submitted execution result aiming at the transaction to be processed can be persisted into a database log of a target database, so that the execution result of the transaction to be processed is recorded in the database log for a long time, and the execution result can be read at any time.
When the message to be sent generated based on the execution result fails to be sent to the designated message queue, the message to be sent is disappeared, and in order to send the message to be sent about the execution result to the designated message queue, the steps of generating the message to be sent according to the execution result and sending the message to be sent to the designated message queue can be returned, and a new message to be sent is generated again based on the execution result and sent to the designated message queue.
Repeating the steps until the message to be sent is successfully sent to the appointed message queue.
The above can be seen that, by applying the technical solution provided by the embodiment of the present invention, the processing of the target data is implemented by establishing a transaction to be processed about the target data, and executing the transaction to be processed. And the established transaction to be processed only comprises the operation of carrying out data processing on the target data in the target database, and after the execution of the transaction to be processed is completed, the operation of generating a message to be sent according to the execution result and sending the message to be executed to the designated message queue is executed. In this way, the data processing operation and the message sending operation are executed as two steps, and a distributed transaction mechanism is not required to be introduced, so that the complexity of a service program can be prevented from being increased due to the introduction of the distributed transaction mechanism, and the risk of code intrusion caused by codes of the distributed transaction mechanism to the existing service codes is reduced, thereby reducing the implementation difficulty of two systems of a database and a message queue in the same transaction.
Optionally, in a specific implementation manner, an electronic device for executing a transaction processing method provided by the embodiment of the present invention may include: a business processing component, a target database and an analysis component;
wherein, the step S101 described above, determining the transaction to be processed for the target data in the target database may include the following step 21:
step 21: the business processing component determines a transaction to be processed for target data in a target database;
step S102, executing the transaction to be processed, and performing the transaction submitting after the transaction to be processed is executed successfully, may include the following steps 22:
step 22: the business processing component executes the transaction to be processed, and performs transaction submission after the transaction to be processed is successfully executed;
step S103, after the transaction is submitted successfully, updating the database log of the target database, which may include the following step 23:
step 23: the target database receives the transaction submitted by the service processing component and updates the database log;
the step S104 may be the step of reading the execution result of the target data from the database log, and may include the following step 24:
step 24: the analysis component reads the execution result of the target data from the database log;
Step S105, according to the execution result, generates a message to be sent, and sends the message to be sent to the designated message queue, which may include the following step 25:
step 25: and the analysis component generates a message to be sent according to the execution result and sends the message to be sent to a designated message queue.
In this specific implementation manner, an electronic device for executing a transaction processing method provided by the embodiment of the present invention may include: the business processing component, the target database and the analysis component, wherein the business processing component firstly determines the transaction to be processed aiming at the target data in the target database, then executes the transaction to be processed, and performs transaction submission after the transaction to be processed is executed successfully; the target database receives the transaction submitted by the service processing component and updates the database log; the analysis component reads the execution result of the target data from the database log, generates a message to be sent according to the execution result, and sends the message to be sent to the appointed message queue.
When the service processing component receives a processing request for target data in the target database, the service processing component may establish a transaction to be processed for the target data in the target database based on the processing request. And then executing the transaction to be processed, executing the operation indicated by the processing request on the target data in the target database, and further performing transaction submission to the target database when the transaction to be processed is successfully executed.
The target database receives the execution result submitted by the service processing component, writes the execution result into a database log based on the execution result, and writes the change result of the target data into the database log.
When the analysis component detects that the database log sends new writing, the analysis component can read the execution result of the target data from the database log, further, according to the execution result, generate a message to be sent of the target data, and send the message to be sent to a designated message queue.
The specific implementation manner of the steps 21 to 25 is the same as that of the steps S101 to S105, and will not be repeated here.
Optionally, in a specific implementation manner, before the step 21, the method may further include the following steps 26 to 27:
step 26: the configuration service processing component is connected with the target database;
step 27: the parsing component is configured with respect to read rights of a database log of the target database.
In this particular implementation, the business processing component, the target database and the parsing component may be initialized first before the business processing component processes the object.
I.e. before processing the object, a service processing component may be configured and connected to the above-mentioned service processing component and the target database. In addition, in order to facilitate the above-mentioned analysis component to detect and read the database log of the target database, the analysis component may be first configured to give the analysis component authority to read the database log of the target database, and to send the specified message queue of the message to be processed.
To facilitate an understanding of the above steps 21-27, the following describes in detail the interaction procedure between the components of an electronic device performing a transaction method according to an embodiment of the present invention, in connection with fig. 4. Wherein mysql (relational database management system) is the target database.
Firstly, configuring a service processing component, an analysis component and a designated message queue, so that the service processing component can be connected with mysql, for example, configuring JBCD (Java DataBase Connectivity, java database connection) parameters, database addresses, database usernames, database passwords and the like of the mysql into the service processing component; the database log authority of the mysql is configured to the parsing component, for example, the parsing component is given authority to read the binlog (binary log) of the mysql through the configured mysql address, account password and the like. And, parameters specifying a message queue, such as kafka (open source stream processing platform) cluster address, target topic (rule), serialization parameters, and the like, are configured.
When the service processing component receives a service request sent by a user, the service processing component can acquire a JDBC connection and start a transaction to be processed aiming at target data in mysql through the JDBC connection.
Thereafter, the business processing component submits SQL (Structured Query Language ) statement operational data changes for the target data using the JDBC connection in the pending transaction. And when the execution of the transaction to be processed is successful, performing transaction submission to mysql by using a JDBC connection commit (database operation), and if the execution of the transaction to be processed fails, performing rollback by using a JDBC connection rollback (rollback transaction), and rollback target data in the mysql to a state before the execution of the transaction to be processed.
Among them, rollback is commonly used in conjunction with commit in mysql to maintain the integrity and uniformity of database data. In the execution process of the transaction to be processed, when the transaction processing fails, the roller back restores the data into the data before processing; the commit operates on the database when the transaction is successful.
When the transaction is successfully submitted, mysql writes the change result of the target data in the submitted pending transaction into binlog.
The analysis component monitors the binlog, reads the binlog when new writing exists in the binlog, acquires a target table in the binlog, further determines a change result about target data, generates a change message about the target data, sends the change message to a designated message queue, and records the position of the read binlog.
The process of sending the change message to the designated message queue may fail, and the change result may be regenerated and the change may be resent because the change result is already persisted to binlog. Thus, the user can acquire the change message through the specified message queue and perform subsequent processing and the like.
The processing of the transaction to be processed may be implemented by the code shown in fig. 5, and the modification of the target data may be implemented by executing the code shown in fig. 5.
Based on the same inventive concept, the embodiment of the invention further provides a transaction processing device corresponding to the transaction processing method shown in fig. 1 provided by the embodiment of the invention.
Fig. 6 is a schematic structural diagram of a transaction processing device according to an embodiment of the present invention, as shown in fig. 6, the device may include:
a business processing component 610 for determining transactions to be processed for target data in a target database; executing the transaction to be processed, and performing transaction submission after the transaction to be processed is successfully executed;
a target database 620, configured to update a database log of the target database after successful transaction delivery;
A parsing component 630, configured to read, from the database log, an execution result about the target data; and generating a message to be sent according to the execution result, and sending the message to be sent to a designated message queue.
The above can be seen that, by applying the technical solution provided by the embodiment of the present invention, the processing of the target data is implemented by establishing a transaction to be processed about the target data, and executing the transaction to be processed. And the established transaction to be processed only comprises the operation of carrying out data processing on the target data in the target database, and after the execution of the transaction to be processed is completed, the operation of generating a message to be sent according to the execution result and sending the message to be executed to the designated message queue is executed. In this way, the data processing operation and the message sending operation are executed as two steps, and a distributed transaction mechanism is not required to be introduced, so that the complexity of a service program can be prevented from being increased due to the introduction of the distributed transaction mechanism, and the risk of code intrusion caused by codes of the distributed transaction mechanism to the existing service codes is reduced, thereby reducing the implementation difficulty of two systems of a database and a message queue in the same transaction.
Optionally, in a specific implementation manner, the target database 620 is specifically configured to:
after the transaction is submitted successfully, the execution result of the transaction to be processed is persisted to the database log;
the parsing component 630 is further configured to:
and when the message to be sent fails to be sent to the appointed message queue, returning to the step of generating the message to be sent according to the execution result and sending the message to be sent to the appointed message queue until the message to be sent is successfully sent to the appointed message queue.
Optionally, in a specific implementation manner, the service processing component 610 is further configured to:
and rolling back when the execution of the transaction to be processed fails.
Optionally, in a specific implementation manner, the target database 620 is specifically configured to:
writing a data change target table about the target data in a database log after the transaction is submitted successfully;
the parsing component 630 is specifically configured to:
and reading the database log, and obtaining the data change target table to obtain an execution result related to the target data.
Optionally, in a specific implementation manner, the apparatus further includes:
And the initialization module is used for configuring the business processing component to be connected with the target database and configuring the reading authority of the analysis component on the database log of the target database before the business processing component determines the transaction to be processed of the target data of the target database.
The embodiment of the present invention further provides an electronic device, as shown in fig. 7, including a processor 701, a communication interface 702, a memory 703 and a communication bus 704, where the processor 701, the communication interface 702, and the memory 703 perform communication with each other through the communication bus 704,
a memory 703 for storing a computer program;
the processor 701 is configured to implement the steps of any of the transaction processing methods provided in the embodiments of the present invention when executing the program stored in the memory 703.
The communication bus mentioned above for the electronic devices may be a peripheral component interconnect standard (Peripheral Component Interconnect, PCI) bus or an extended industry standard architecture (Extended Industry Standard Architecture, EISA) bus, etc. The communication bus may be classified as an address bus, a data bus, a control bus, or the like. For ease of illustration, the figures are shown with only one bold line, but not with only one bus or one type of bus.
The communication interface is used for communication between the electronic device and other devices.
The Memory may include random access Memory (Random Access Memory, RAM) or may include Non-Volatile Memory (NVM), such as at least one disk Memory. Optionally, the memory may also be at least one memory device located remotely from the aforementioned processor.
The processor may be a general-purpose processor, including a central processing unit (Central Processing Unit, CPU), a network processor (Network Processor, NP), etc.; but also digital signal processors (Digital Signal Processor, DSP), application specific integrated circuits (Application Specific Integrated Circuit, ASIC), field programmable gate arrays (Field-Programmable Gate Array, FPGA) or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components.
In yet another embodiment of the present invention, there is also provided a computer readable storage medium having stored therein a computer program which, when executed by a processor, implements the steps of any of the transaction processing methods described above.
In yet another embodiment of the present invention, there is also provided a computer program product containing instructions which, when run on a computer, cause the computer to perform any of the transaction methods of the above embodiments.
In the above embodiments, it may be implemented in whole or in part by software, hardware, firmware, or any combination thereof. When implemented in software, may be implemented in whole or in part in the form of a computer program product. The computer program product includes one or more computer instructions. When loaded and executed on a computer, produces a flow or function in accordance with embodiments of the present invention, in whole or in part. The computer may be a general purpose computer, a special purpose computer, a computer network, or other programmable apparatus. The computer instructions may be stored in or transmitted from one computer-readable storage medium to another, for example, by wired (e.g., coaxial cable, optical fiber, digital Subscriber Line (DSL)), or wireless (e.g., infrared, wireless, microwave, etc.). The computer readable storage medium may be any available medium that can be accessed by a computer or a data storage device such as a server, data center, etc. that contains an integration of one or more available media. The usable medium may be a magnetic medium (e.g., floppy Disk, hard Disk, magnetic tape), an optical medium (e.g., DVD), or a semiconductor medium (e.g., solid State Disk (SSD)), etc.
It is noted that relational terms such as first and second, and the like are used solely to distinguish one entity or action from another entity or action without necessarily requiring or implying any actual such relationship or order between such entities or actions. Moreover, the terms "comprises," "comprising," or any other variation thereof, are intended to cover a non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements does not include only those elements but may include other elements not expressly listed or inherent to such process, method, article, or apparatus. Without further limitation, an element defined by the phrase "comprising one … …" does not exclude the presence of other like elements in a process, method, article, or apparatus that comprises the element.
In this specification, each embodiment is described in a related manner, and identical and similar parts of each embodiment are all referred to each other, and each embodiment mainly describes differences from other embodiments. In particular, for the apparatus embodiments, the electronic device embodiments, the computer-readable storage medium embodiments, and the computer program product embodiments, the description is relatively simple, and reference should be made to the description of method embodiments in part, since they are substantially similar to the method embodiments.
The foregoing description is only of the preferred embodiments of the present invention and is not intended to limit the scope of the present invention. Any modification, equivalent replacement, improvement, etc. made within the spirit and principle of the present invention are included in the protection scope of the present invention.

Claims (13)

1. A method of transaction processing, the method comprising:
determining a transaction to be processed for target data in a target database;
executing the transaction to be processed, and performing transaction submission after the transaction to be processed is successfully executed;
after the transaction is submitted successfully, updating a database log of the target database;
reading an execution result about the target data from the database log;
and generating a message to be sent according to the execution result, and sending the message to be sent to a designated message queue.
2. The method of claim 1, wherein updating the database log of the target database after the transaction is successfully submitted comprises:
after the transaction is submitted successfully, the execution result of the transaction to be processed is persisted to the database log;
the method further comprises the steps of:
and when the message to be sent fails to be sent to the appointed message queue, returning to the step of generating the message to be sent according to the execution result and sending the message to be sent to the appointed message queue until the message to be sent is successfully sent to the appointed message queue.
3. The method according to claim 1, wherein the method further comprises:
and rolling back when the execution of the transaction to be processed fails.
4. The method of claim 1, wherein updating the database log of the target database after the transaction is successfully submitted comprises:
writing a data change target table about the target data in a database log of the target database after successful transaction submission;
the reading the execution result of the target data from the database log comprises the following steps:
and reading the database log, and obtaining the data change target table to obtain an execution result related to the target data.
5. The method of claim 1, wherein the electronic device performing the method comprises: a business processing component, a target database and an analysis component;
wherein the determining a transaction to be processed for target data in a target database comprises:
the business processing component determines a transaction to be processed for target data in a target database;
the executing the transaction to be processed, and performing transaction submission after the transaction to be processed is successfully executed, includes:
The business processing component executes the transaction to be processed and performs transaction submission after the transaction to be processed is successfully executed;
after the transaction is submitted successfully, updating the database log of the target database, which comprises the following steps:
the target database receives the transaction submitted by the service processing component and updates the database log;
the reading the execution result of the target data from the database log comprises the following steps:
the analysis component reads an execution result about the target data from the database log;
generating a message to be sent according to the execution result, and sending the message to be sent to a designated message queue, including:
and the analysis component generates the message to be sent according to the execution result and sends the message to be sent to the appointed message queue.
6. The method of claim 5, wherein prior to the business processing component determining a transaction to be processed for target data of a target database, the method further comprises:
configuring the service processing component to be connected with the target database;
configuring read rights of the parsing component with respect to the database log of the target database.
7. A transaction processing device, the device comprising:
a business processing component for determining a transaction to be processed for target data in a target database; executing the transaction to be processed, and performing transaction submission after the transaction to be processed is successfully executed;
the target database is used for updating the database log of the target database after the transaction is submitted successfully;
the analysis component is used for reading the execution result of the target data from the database log; and generating a message to be sent according to the execution result, and sending the message to be sent to a designated message queue.
8. The apparatus of claim 7, wherein the target database is specifically configured to:
after the transaction is submitted successfully, the execution result of the transaction to be processed is persisted to the database log;
the parsing component is further configured to:
and when the message to be sent fails to be sent to the appointed message queue, returning to the step of generating the message to be sent according to the execution result and sending the message to be sent to the appointed message queue until the message to be sent is successfully sent to the appointed message queue.
9. The apparatus of claim 7, wherein the service processing component is further configured to:
and rolling back when the execution of the transaction to be processed fails.
10. The apparatus of claim 7, wherein the target database is specifically configured to:
writing a data change target table about the target data in a database log after the transaction is submitted successfully;
the parsing component is specifically configured to:
and reading the database log, and obtaining the data change target table to obtain an execution result related to the target data.
11. The apparatus of claim 7, wherein the apparatus further comprises:
and the initialization module is used for configuring the business processing component to be connected with the target database and configuring the reading authority of the analysis component on the database log of the target database before the business processing component determines the transaction to be processed of the target data of the target database.
12. The electronic equipment is characterized by comprising a processor, a communication interface, a memory and a communication bus, wherein the processor, the communication interface and the memory are communicated with each other through the communication bus;
A memory for storing a computer program;
a processor for carrying out the method steps of any one of claims 1-6 when executing a program stored on a memory.
13. A computer-readable storage medium, characterized in that the computer-readable storage medium has stored therein a computer program which, when executed by a processor, implements the method steps of any of claims 1-6.
CN202210757083.3A 2022-06-30 2022-06-30 Transaction processing method and device and electronic equipment Pending CN117369955A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202210757083.3A CN117369955A (en) 2022-06-30 2022-06-30 Transaction processing method and device and electronic equipment

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202210757083.3A CN117369955A (en) 2022-06-30 2022-06-30 Transaction processing method and device and electronic equipment

Publications (1)

Publication Number Publication Date
CN117369955A true CN117369955A (en) 2024-01-09

Family

ID=89395134

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202210757083.3A Pending CN117369955A (en) 2022-06-30 2022-06-30 Transaction processing method and device and electronic equipment

Country Status (1)

Country Link
CN (1) CN117369955A (en)

Similar Documents

Publication Publication Date Title
US20180150230A1 (en) State machine abstraction for log-based consensus protocols
US10122598B2 (en) Subscription watch lists for event handling
CN111782440B (en) Data processing method and device and electronic equipment
CN109241128B (en) Automatic triggering method and system for overdue event
CN111818145B (en) File transmission method, device, system, equipment and storage medium
US11775358B2 (en) Tenant copy operation in a microservice architecture
CN111338834B (en) Data storage method and device
CN111666134A (en) Method and system for scheduling distributed tasks
CN112835885B (en) Processing method, device and system for distributed form storage
CN109299124B (en) Method and apparatus for updating a model
CN111782502A (en) Automatic testing method and device
CN112598529B (en) Data processing method and device, computer readable storage medium and electronic equipment
US9031969B2 (en) Guaranteed in-flight SQL insert operation support during an RAC database failover
CN113238815A (en) Interface access control method, device, equipment and storage medium
CN112445860B (en) Method and device for processing distributed transaction
CN110795495A (en) Data processing method and device, electronic equipment and computer readable medium
CN112825525A (en) Method and apparatus for processing transactions
CN117369955A (en) Transaction processing method and device and electronic equipment
CN114036218A (en) Data model switching method and device, server and storage medium
CN113220342A (en) Centralized configuration method and device, electronic equipment and storage medium
CN112596867A (en) Suspension transaction processing method and distributed database system
CN112765188A (en) Configuration information processing method, configuration management system, electronic device, and storage medium
CN112711602A (en) Running method and device of storage process, database system and storage medium
CN117131071B (en) Data processing method, device, electronic equipment and computer readable medium
CN111639089B (en) Transaction processing method, transaction processing device, electronic equipment and computer readable storage 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