A control method, device, equipment and storage medium for distributed transaction
By using the transaction lock configuration table to lock and unlock the target account in the distributed system, the problem of low transaction processing consistency in the distributed system is solved, and the reentrancy and data consistency of the account are achieved.
Patent Information
- Application Number
- CN202211477471.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-11-23
- Publication Date
- 2024-10-25
- Estimated Expiration
- 2042-11-23
AI Technical Summary
The parallel operation of multiple nodes in a distributed system results in low consistency in transaction processing and affects the processing of other transactions.
By configuring the transaction ID and lock table name in the transaction lock configuration table, the target account can be locked and unlocked to ensure consistency in transaction processing.
It effectively improves the processing consistency of distributed transaction transactions, prevents data corruption and inter-process deadlock caused by concurrent operations, and supports reentrancy of the same account.
Smart Images

Figure CN115719274B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of distributed technology, and in particular to a control method, device, equipment and storage medium for distributed transaction. Background Art
[0002] In order to improve the operating efficiency of financial systems such as banks, the core business systems of financial systems currently generally adopt a microservice architecture to split the core business systems so that multiple operations corresponding to a transaction request for a channel can be implemented through calls between multiple distributed microservices.
[0003] A distributed system composed of multiple independent microservices (nodes) can run in parallel. Therefore, at the same time, there may be multiple nodes or multiple processes in a node requesting to operate the same transaction. This can easily lead to abnormalities in transaction processing, resulting in low consistency in transaction processing and affecting the processing of other transactions based on this transaction processing. Summary of the invention
[0004] In view of this, an object of the present invention is to provide a control method, device, equipment and storage medium for distributed transaction so as to improve the consistency of transaction processing.
[0005] In a first aspect, an embodiment of the present invention provides a method for controlling distributed transaction transactions, including:
[0006] Receiving a distributed transaction processing request, obtaining a transaction identifier corresponding to the transaction of the distributed transaction processing request, and determining whether the transaction identifier is configured in a pre-set transaction lock configuration table;
[0007] If yes, extract multiple accounts included in the transaction, query the locked table name in the transaction lock configuration table, and determine the locked target account based on the extracted account and the locked table name;
[0008] Lock the target account, and add the transaction information corresponding to the target account to the transaction lock configuration table;
[0009] Processing the transaction according to the process corresponding to the transaction;
[0010] After the transaction is completed, the target account is unlocked.
[0011] In combination with the first aspect, an embodiment of the present invention provides a first possible implementation of the first aspect, wherein determining the target account to be locked based on the extracted account and the locked table name includes:
[0012] For each extracted account, determine whether the account exists in the locked table name;
[0013] If so, determine whether the locked table name contains the transaction information of the account;
[0014] If not recorded, determine that the account is the target account.
[0015] In combination with the first possible implementation of the first aspect, the embodiment of the present invention provides a second possible implementation of the first aspect, wherein the method further includes:
[0016] If the locked table name records the serial number information of the account, obtain the serial number recorded in the account and the current serial number of the account;
[0017] Determine whether the recorded serial number is consistent with the current serial number;
[0018] If they are consistent, execute the process corresponding to the transaction;
[0019] If they are inconsistent, wait according to the waiting time in the transaction lock configuration table to wait for the account corresponding to the serial number of the record to be unlocked.
[0020] In combination with the second possible implementation of the first aspect, an embodiment of the present invention provides a third possible implementation of the first aspect, wherein the waiting according to the waiting time in the transaction lock configuration table includes:
[0021] Read the current number of retries of the current serial number recorded in the stored transaction lock configuration table;
[0022] If the current number of retries exceeds the number of retries in the transaction lock configuration table, output an exception message;
[0023] If not, after waiting for the waiting time, query whether the account corresponding to the recorded serial number has been unlocked; if so, execute the process corresponding to the transaction transaction to determine that the account corresponding to the recorded serial number is the target account; if not, add 1 to the current number of retries recorded in the stored transaction lock configuration table, and execute the step of reading the current number of retries of the current serial number recorded in the stored transaction lock configuration table.
[0024] In combination with the first aspect, an embodiment of the present invention provides a fourth possible implementation of the first aspect, wherein after the transaction is completed, unlocking the target account includes:
[0025] If the operation result of the transaction is success or failure, clear the transaction information corresponding to the target account in the transaction lock configuration table, and the operation result includes: success, failure or exception;
[0026] If the operation result of the transaction is abnormal, the transaction is subjected to final state processing. If the final state processing is successful, the transaction flow information corresponding to the target account in the transaction lock configuration table is cleared. The final state includes success or failure.
[0027] In combination with the fourth possible implementation manner of the first aspect, the embodiment of the present invention provides a fifth possible implementation manner of the first aspect, wherein the method further includes:
[0028] If it is monitored that the transaction flow information corresponding to the transaction in the transaction lock configuration table cannot be cleared, after waiting for the preset clearing time threshold, it is determined that the operation result of the transaction is successful or failed, and then the transaction flow information corresponding to the target account in the transaction lock configuration table is cleared.
[0029] In combination with the first aspect and any possible implementation manner of the first aspect to the fifth possible implementation manner of the first aspect, the embodiment of the present invention provides a sixth possible implementation manner of the first aspect, wherein the method further includes:
[0030] The locking time is counted. If the timing time exceeds the timing time threshold set in the transaction lock configuration table, the target account has not been unlocked, and an abnormal information is output to a preset terminal.
[0031] In a second aspect, an embodiment of the present invention further provides a control device for distributed transaction, including:
[0032] A transaction code matching module is used to receive a distributed transaction processing request, obtain a transaction identifier corresponding to the transaction of the distributed transaction processing request, and determine whether the transaction identifier is configured in a pre-set transaction lock configuration table;
[0033] An account matching module, configured to extract the account included in the transaction, query the locked table name in the transaction lock configuration table, and determine the locked target account based on the extracted account and the locked table name;
[0034] A locking module, used to lock the target account and add the transaction information corresponding to the target account to the transaction lock configuration table;
[0035] The unlocking module is used to process the transaction according to the process corresponding to the transaction, and unlock the target account after the transaction is completed.
[0036] In a third aspect, an embodiment of the present application provides a computer device, comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor implements the steps of the above method when executing the computer program.
[0037] In a fourth aspect, an embodiment of the present application provides a computer-readable storage medium, on which a computer program is stored, and when the computer program is executed by a processor, the steps of the above method are executed.
[0038] The control method, device, equipment and storage medium of distributed transaction provided by the embodiment of the present invention receive a distributed transaction processing request, obtain the transaction identifier corresponding to the transaction of the distributed transaction processing request, and determine whether the transaction identifier is configured in the pre-set transaction lock configuration table; if so, extract the account included in the transaction, query the lock table name in the transaction lock configuration table, and determine the locked target account based on the extracted account and the lock table name; lock the target account, add the transaction information corresponding to the target account to the transaction lock configuration table; after the transaction is completed, unlock the target account. Therefore, by pre-setting the transaction lock configuration table, the transaction identifier of the transaction that needs to be locked and the lock table name that needs to be locked in the transaction are configured in the transaction lock configuration table to lock the target account, so that when the target account processes the transaction, it prevents other accounts from requesting to operate the transaction, and avoids abnormalities in the transaction processing, thereby achieving the consistency of distributed transaction and effectively improving the consistency of transaction processing.
[0039] In order to make the above-mentioned objects, features and advantages of the present invention more obvious and easy to understand, preferred embodiments are given below and described in detail with reference to the accompanying drawings. BRIEF DESCRIPTION OF THE DRAWINGS
[0040] In order to more clearly illustrate the technical solutions of the embodiments of the present invention, the drawings required for use in the embodiments are briefly introduced below. It should be understood that the following drawings only show certain embodiments of the present invention and therefore should not be regarded as limiting the scope. For ordinary technicians in this field, other related drawings can be obtained based on these drawings without creative work.
[0041] Figure 1 A schematic diagram of the flow of a distributed transaction control method provided by an embodiment of the present invention is shown;
[0042] Figure 2 A schematic diagram showing a specific flow chart of a distributed transaction control method provided by an embodiment of the present invention;
[0043] Figure 3 A schematic diagram of the unlocking process of a distributed transaction provided by an embodiment of the present invention is shown;
[0044] Figure 4 A schematic diagram of the structure of a control device for distributed transaction transactions provided by an embodiment of the present invention is shown;
[0045] Figure 5 A schematic diagram of the structure of a computer device 500 provided in an embodiment of the present application. DETAILED DESCRIPTION
[0046] In order to make the purpose, technical solutions and advantages of the embodiments of the present invention clearer, the technical solutions in the embodiments of the present invention will be clearly and completely described below in conjunction with the drawings in the embodiments of the present invention. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of the embodiments. The components of the embodiments of the present invention generally described and shown in the drawings here can be arranged and designed in various different configurations. Therefore, the following detailed description of the embodiments of the present invention provided in the drawings is not intended to limit the scope of the claimed invention, but merely represents selected embodiments of the present invention. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without making creative work belong to the scope of protection of the present invention.
[0047] At present, distributed transaction processing generally achieves transaction consistency based on a single node. Taking transaction as a data processing operation as an example, if there are multiple concurrent processes in the single node requesting data processing operations for the transaction, the corresponding data processing operations can be obtained by setting a lock on the transaction, thereby achieving single-node synchronization, mutual exclusion and other operations. However, since a distributed system has multiple nodes, each node is independent of each other, and each node independently processes a distributed transaction. Therefore, the single-node lock method cannot achieve operational management of the distributed system.
[0048] In the embodiment of the present invention, considering that multiple nodes in a distributed system run in parallel, it is necessary to manage and control the multiple nodes running in parallel to avoid problems such as data corruption and deadlock between processes, which lead to the inability to achieve consistency of transaction transactions. A global lock mechanism is added to the account transaction (account) of the distributed transaction transaction, so that the same account can only wait or retry the triggered concurrent operations before the entire account transaction operation is completed, and support the reentry of the same account during the entire account transaction operation process.
[0049] Embodiments of the present invention provide a method, apparatus, device and storage medium for controlling distributed transaction, which are described below through embodiments.
[0050] Figure 1 The following is a schematic diagram showing the flow of a distributed transaction control method provided by an embodiment of the present invention. Figure 1 As shown, the method includes:
[0051] Step 101, receiving a distributed transaction processing request, obtaining a transaction identifier corresponding to the transaction of the distributed transaction processing request, and determining whether the transaction identifier is configured in a pre-set transaction lock configuration table;
[0052] In the embodiment of the present invention, the core business system of the financial system is taken as an example, that is, the core business system runs the present method, and the core business system implements transaction processing through microservices. The core business system needs to process transactions for all microservices, and the microservices can be deployed in intelligent terminals, such as computers. For example, if the account transaction performs a real-time debit and credit balance check, the microservice on the computer sends a distributed transaction transaction processing request to the core business system, requesting a debit and credit balance check. If at this moment, the deposit customer who has been credited to the account fails to realize compensation due to timeout or other reasons when making compensation, and another concurrent account transaction performs a withdrawal operation for the deposit customer, therefore, when performing transaction compensation, since the deposit customer fails to make compensation due to timeout, when the concurrent account transaction performs a withdrawal operation, it may fail due to insufficient balance and cannot reach a final consistent state. Among them, the core business system can be a server, or a cluster thereof, or a distributed cluster, so as to realize the interaction between the intelligent terminal and the server.
[0053] In an embodiment of the present invention, by statistically analyzing various processing procedures involved in the transaction processing of the financial system, the transaction that needs to be configured with a transaction lock and the table that needs to be configured with a transaction lock contained in each transaction are determined, or, when developing a transaction, it is determined in advance whether the transaction needs to be controlled by a transaction lock, for example, for an account transaction in a transaction, it is determined that a transaction lock (locking) control is required. Among them, the table is a table that needs to be locked involved in each process of transaction processing, which is filled in the transaction lock configuration table, and for each transaction, or each table, or for all transactions, the waiting time, number of retries, and timeout time for waiting to be unlocked are set. For example, based on the core business system and / or the distributed transactions processed by the distributed system, cluster analysis is performed, and combined with manual process analysis of the clustering results, the transactions and tables that need to be configured with a transaction lock are determined and filled in the transaction lock configuration table.
[0054] In an embodiment of the present invention, as an optional embodiment, the transaction lock configuration table includes: transaction identification, lock table name, waiting time, number of retries, timeout time and other information, wherein the transaction identification is used to identify the transaction. As an optional embodiment, the transaction identification includes a transaction code. For example, for transactions such as deposits, withdrawals, and transfers, the bank will pre-set a unique corresponding transaction code for each transaction. The lock table name is the name of the table that needs to be configured with a transaction lock. The waiting time is the time required to wait for the current transaction to continue to execute if there is a transaction lock conflict. The number of retries is the number of times the current transaction can be attempted to execute in the event of a transaction lock conflict. The timeout time is the lock time set for the transaction, which cannot exceed the timeout time. If exceeded, the transaction is automatically unlocked.
[0055] In the embodiment of the present invention, as an optional embodiment, the lock table name is the name of the account table. The account table is a table composed of accounts that need to be locked in the transaction. In the table, for the locked account, the transaction information of the account is recorded. As an optional embodiment, each transaction corresponds to an account table.
[0056] In the embodiment of the present invention, if the transaction identifier corresponding to the transaction transaction of the distributed transaction processing request is not configured in the transaction lock configuration table, it indicates that no transaction lock control is required and corresponding processing is performed directly according to the distributed transaction processing request.
[0057] In an embodiment of the present invention, as an optional embodiment, the transaction lock configuration table is stored in a cache or a memory, so that the real-time change of the transaction lock configuration can be quickly realized and the query performance can be maximized.
[0058] Step 102: If yes, extract multiple accounts included in the transaction, query the locked table name in the transaction lock configuration table, and determine the locked target account based on the extracted account and the locked table name;
[0059] In an embodiment of the present invention, as an optional embodiment, determining a locked target account based on the extracted account and the locked table name includes:
[0060] For each extracted account, determine whether the account exists in the locked table name;
[0061] If so, determine whether the locked table name contains the transaction information of the account;
[0062] If not recorded, determine that the account is the target account.
[0063] In the embodiment of the present invention, as another optional embodiment, the method further includes:
[0064] If the locked table name records the serial number information of the account, obtain the serial number recorded in the account and the current serial number of the account;
[0065] Determine whether the recorded serial number is consistent with the current serial number;
[0066] If they are consistent, execute the process corresponding to the transaction;
[0067] If they are inconsistent, wait according to the waiting time in the transaction lock configuration table to wait for the account corresponding to the serial number of the record to be unlocked.
[0068] In the embodiment of the present invention, after the account of the transaction needs to be locked, since the transaction may involve multiple accounts, it is necessary to determine whether the multiple accounts corresponding to the transaction have been locked. If there is no corresponding flow information record in the lock table, it indicates that the account has no lock record, that is, at this time, the account does not have concurrent operations for the transaction. Therefore, when processing the transaction, the account is locked to prevent the transaction from being inconsistent due to subsequent operation requests for the transaction. If there is a record, it means that the transaction has been locked. Under the locked transaction, whether the process corresponding to the current transaction can be executed, it is also necessary to obtain the flow number of the current transaction and the flow information stored in the lock table name of the transaction lock configuration table to determine whether it is the same flow. If the flow number is consistent (same), it indicates that it is multiple operations of the same transaction, and the transaction is processed; if it is not the same flow, it means that it is a concurrent transaction operation of the account, and it is necessary to determine whether to wait for retry or directly report an error according to the information in the transaction lock configuration table. When waiting for retry, check the number of retries, and exit with an error until the number is exhausted and the lock cannot be locked.
[0069] In the embodiment of the present invention, as an optional embodiment, the serial information includes but is not limited to: the serial number and the lock creation time.
[0070] In an embodiment of the present invention, as an optional embodiment, waiting according to the waiting time in the transaction lock configuration table includes:
[0071] Read the current number of retries of the current serial number recorded in the stored transaction lock configuration table;
[0072] If the current number of retries exceeds the number of retries in the transaction lock configuration table, output an exception message;
[0073] If not, after waiting for the waiting time, query whether the account corresponding to the recorded serial number has been unlocked; if so, execute the process corresponding to the transaction transaction to determine that the account corresponding to the recorded serial number is the target account; if not, add 1 to the current number of retries recorded in the stored transaction lock configuration table, and execute the step of reading the current number of retries of the current serial number recorded in the stored transaction lock configuration table.
[0074] Step 103, lock the target account, and add the transaction information corresponding to the target account to the transaction lock configuration table;
[0075] In the embodiment of the present invention, taking transfer as an example, assuming that a transaction is a transfer from account A to account B, and at the same time, account C needs to collect a certain transfer fee from account B, the process involved in the transaction includes: deducting account A, increasing account B, deducting account B, and increasing account C, wherein account A and account B are accounts that need to be locked. In the transaction, account A and account B are locked, and the corresponding information is written into the transaction lock configuration table; if at the same time or after account A transfers money to account B, another transaction is a transfer from account A to account C, by querying the transaction lock configuration table, The transaction is configured in the transaction lock configuration table, and the corresponding account A has a corresponding record in the transaction lock configuration table. Since the serial numbers of the two transactions are different, if account A is not unlocked, the transfer from account A to account C can only be executed after the transaction from account A to account B is completed, that is, according to the waiting time set in the transaction lock configuration table, a check is performed. If the lock set for account A has been released after the waiting time, the process of transferring from account A to account C can be executed, and the corresponding information is updated in the transaction lock configuration table.
[0076] In the embodiment of the present invention, in order to prevent the locked transaction from being locked for other reasons, thereby causing other subsequent transactions based on the transaction to be in waiting and retrying, as another optional embodiment, after locking the target account and adding the transaction information corresponding to the target account to the transaction lock configuration table, the method further includes:
[0077] The locking time is counted. If the timing time exceeds the timing time threshold set in the transaction lock configuration table, the target account has not been unlocked, and an abnormal information is output to a preset terminal.
[0078] In the embodiment of the present invention, the total locking time is calculated based on the information in the transaction lock configuration table to determine whether the total locking time exceeds the timing time threshold. If the lock is not unlocked after exceeding the timing time threshold, an exception is thrown for manual processing.
[0079] In the embodiment of the present invention, as an optional embodiment, the lock is a mutual exclusion lock, which can effectively ensure that only one thread can access it at any time.
[0080] Step 104, processing the transaction according to the process corresponding to the transaction;
[0081] In the embodiment of the present invention, for each business transaction, there is a corresponding business transaction process, according to which the business transaction is processed, and the operation result of the business transaction is stored in a preset storage area.
[0082] Step 105: After the transaction is completed, unlock the target account.
[0083] In an embodiment of the present invention, as an optional embodiment, after the transaction is completed, unlocking the target account includes:
[0084] If the operation result of the transaction is success or failure, clear the transaction information corresponding to the target account in the transaction lock configuration table, and the operation result includes: success, failure or exception.
[0085] In the embodiment of the present invention, for unlocking a transaction with a clear transaction status, such as success or failure, after the transaction is completed, the data corresponding to the transaction in the transaction lock configuration table is cleared. As an optional embodiment, the data (flow information) in the transaction lock configuration table is deleted through an asynchronous thread.
[0086] In an embodiment of the present invention, the running result of a transaction is one of success, failure or exception. If the transaction can be completed within a preset execution time threshold, the corresponding running result is success or failure. If the transaction cannot be completed within the preset execution time threshold, for example, the network is abnormal or the server crashes during the execution process, the corresponding running result is exception.
[0087] In the embodiment of the present invention, as another optional embodiment, the method further includes:
[0088] If it is monitored that the transaction flow information corresponding to the transaction in the transaction lock configuration table cannot be cleared, after waiting for the preset clearing time threshold, it is determined that the operation result of the transaction is successful or failed, and then the transaction flow information corresponding to the target account in the transaction lock configuration table is cleared.
[0089] In the embodiment of the present invention, if the transaction information corresponding to the transaction (target account) in the transaction lock configuration table cannot be deleted due to various situations such as system abnormalities, the timing thread performs asynchronous cleaning at intervals (clearing time threshold). Before asynchronous cleaning, it is necessary to check the business status of the transaction according to the transaction serial number to ensure that the operation result of the transaction is a final state (success or failure) before cleaning. In the case where the transaction information cannot be deleted due to non-system abnormalities, it can be connected to the alarm platform for manual processing.
[0090] In an embodiment of the present invention, as an optional embodiment, after the transaction is completed, unlocking the target account includes:
[0091] If the operation result of the transaction is abnormal, the transaction is subjected to final state processing. If the final state processing is successful, the transaction flow information corresponding to the target account in the transaction lock configuration table is cleared. The final state includes success or failure.
[0092] In an embodiment of the present invention, when a transaction does not return a clear status (operation result), for example, when a microservice call times out during transaction processing, a preset error reconciliation processing mechanism can be used to perform final state processing on the transaction. If the final state processing of the transaction is successful, data cleanup can be performed. If the final state processing of the transaction is unsuccessful and further processing is required, the lock time (timeout time) of the transaction can be extended and processed according to a pre-set strategy.
[0093] Figure 2 The following is a schematic diagram showing a specific flow chart of the distributed transaction control method provided by an embodiment of the present invention. Figure 2 As shown, the method includes:
[0094] Step 201, determine whether the transaction lock configuration table is locked, if so, execute step 202, if not, execute step 212;
[0095] In the embodiment of the present invention, based on the received distributed transaction processing request, it is determined whether the transaction lock configuration table stores a transaction identifier corresponding to the distributed transaction processing request. If yes, it is determined that the transaction lock configuration table needs to be locked.
[0096] Step 202, determine whether the transaction is locked, if so, execute step 203, if not, execute step 212;
[0097] In the embodiment of the present invention, it is queried whether the transaction lock configuration table stores the locked table name. If so, it is determined that the transaction needs to be locked.
[0098] Step 203, determine whether the global transaction table lock information stores data of the corresponding account, if so, execute step 204, if not, execute step 211;
[0099] In the embodiment of the present invention, it is determined whether the account of the distributed transaction processing request is stored in the locked table name. If it is stored, it indicates that the data of the corresponding account is stored in the global transaction table lock information.
[0100] Step 204, determine whether the serial numbers are consistent, if not, execute step 205, if yes, execute step 212;
[0101] In the embodiment of the present invention, it is determined whether the transaction information of the account recorded in the locked table name is consistent with the current transaction information of the account. If not, locking control is required.
[0102] Step 205, obtaining global table lock configuration information;
[0103] In the embodiment of the present invention, the global table lock configuration information includes: waiting time, number of retries, timeout time, retry time, etc.
[0104] Step 206, determine whether the timeout period has expired, if not, execute step 207, if yes, execute step 210;
[0105] In the embodiment of the present invention, within the timeout period, you can wait for the transaction to be unlocked, so that you can operate on the transaction after it is unlocked.
[0106] Step 207, determine whether a retry is required or the number of retries has been exceeded, if not, execute step 208, if yes, execute step 209;
[0107] In the embodiment of the present invention, the current number of retries recorded in the current transaction information is read from the stored transaction lock configuration table to determine whether the current number of retries exceeds the number of retries in the transaction lock configuration table.
[0108] Step 208, throwing an exception message;
[0109] In the embodiment of the present invention, the thrown exception information is transferred to manual processing.
[0110] Step 209, after waiting for the retry time, execute step 207;
[0111] In the embodiment of the present invention, after waiting for the retry time, it is determined again whether a retry is required or the number of retries has been exceeded.
[0112] Step 210, update the serial number and creation time in the global transaction table lock information, and execute step 212;
[0113] Step 211, insert global table lock information;
[0114] In the embodiment of the present invention, the update information is written into the transaction lock configuration table.
[0115] Step 212, end the process.
[0116] Figure 3 The figure shows a schematic diagram of the unlocking process of a distributed transaction provided by an embodiment of the present invention. Figure 3 As shown, the process includes:
[0117] Step 300, determine the operation result of the transaction. If there is no operation result and it has not timed out, execute step 301. If the operation result is success or failure, execute step 306. If there is no operation result and it has timed out, execute step 307.
[0118] Step 301, start the timed unlocking thread;
[0119] In the embodiment of the present invention, after locking, a timed unlocking thread is started to time the locking time and perform unlocking processing.
[0120] Step 302, determine whether it has timed out, if so, execute step 303, if not, execute step 311;
[0121] In the embodiment of the present invention, if the total locking time is timed out, the timed unlocking thread executes the unlocking process.
[0122] Step 303, deleting the global transaction table lock information according to the serial number;
[0123] In the embodiment of the present invention, the global transaction table lock information corresponding to the transaction in the transaction lock configuration table is cleared according to the serial number corresponding to the transaction.
[0124] Step 304, determine whether the deletion is successful, if so, execute step 311, if not, execute step 305;
[0125] In the embodiment of the present invention, due to various situations such as system abnormality, the global transaction table lock information corresponding to the transaction in the transaction lock configuration table may not be deleted. Therefore, it is necessary to determine whether the deletion is successful so as to take timely measures when the deletion is unsuccessful.
[0126] Step 305, the alarm is transferred to manual operation;
[0127] In the embodiment of the present invention, if the global transaction table lock information cannot be deleted due to non-system abnormalities, the alarm platform can be connected to transfer to manual processing.
[0128] Step 306, determine whether the global transaction status is successful or failed, and execute step 303;
[0129] In the embodiment of the present invention, within the timeout period, the transaction has a clear running result.
[0130] Step 307, determine that the global transaction state timeout is unknown, and execute step 308;
[0131] In the embodiment of the present invention, the transaction running time has timed out and there is no clear running result.
[0132] Step 308, perform technical error reconciliation processing;
[0133] In the embodiment of the present invention, error reconciliation is performed on the business transaction.
[0134] Step 309, determine whether it is successful, if so, execute step 303, if not, execute step 310;
[0135] In the embodiment of the present invention, if the error reconciliation process is successful, unlocking is performed.
[0136] Step 310, update the creation time in the global transaction table lock information, and execute step 308;
[0137] Step 311, end the process.
[0138] In the embodiment of the present invention, by presetting the transaction lock configuration table, the transaction identifier of the transaction that needs to be locked and the lock table name that needs to be locked in the transaction are configured in the transaction lock configuration table. For a distributed transaction transaction processing request, it is first determined whether it is a transaction that is pre-set in the transaction lock configuration table. If it is, the target account that needs to be locked is determined according to the lock table name corresponding to the transaction in the transaction lock configuration table. After determining the target account that needs to be locked, it is determined whether the target account has been locked. If it is locked, it is checked whether it is the same transaction through the recorded flow information. If it is the same flow, there is no need to lock the target account twice, and subsequent transaction processing can be directly performed; if it is not the same flow, it is necessary to wait until the locked target account is unlocked; if it is not locked, the target account is locked and the flow information of the target account is registered. In this way, by adding lock control to the target account, the isolation of the same target account during concurrent transaction operations can be ensured, and the capital risk generated in extreme cases can be prevented, thereby achieving the consistency of distributed SAGA transaction transactions, avoiding affecting the processing of other transaction transactions based on the transaction transaction, and effectively improving the consistency of transaction processing. Furthermore, when the target account is locked, if the serial number of the current transaction is different from the serial number of the stored target account, a waiting and retrying operation is performed, which can effectively avoid conflicts, deadlocks and other problems caused by concurrent operations between multiple nodes in a distributed system.
[0139] Figure 4 FIG. 1 is a schematic diagram showing the structure of a control device for distributed transaction provided by an embodiment of the present invention. Figure 4 As shown, the device comprises:
[0140] The transaction code matching module 401 is used to receive a distributed transaction processing request, obtain a transaction identifier corresponding to the transaction of the distributed transaction processing request, and determine whether the transaction identifier is configured in a pre-set transaction lock configuration table;
[0141] In an embodiment of the present invention, as an optional embodiment, the transaction lock configuration table includes: transaction identification, lock table name, waiting time, retry times, timeout time, and is stored in cache or memory.
[0142] In the embodiment of the present invention, as an optional embodiment, the locked table name includes but is not limited to: an account table.
[0143] An account matching module 402 is used to extract the account included in the transaction, query the locked table name in the transaction lock configuration table, and determine the locked target account based on the extracted account and the locked table name;
[0144] In the embodiment of the present invention, as an optional embodiment, the account matching module 402 includes:
[0145] An extraction unit (not shown in the figure), used to extract the accounts included in the transaction;
[0146] A query unit, used to query the locked table name in the transaction lock configuration table;
[0147] A first judgment unit is used to judge, for each extracted account, whether the account exists in the locked table name; if so, notify the second judgment unit;
[0148] The second judgment unit is used to judge whether the transaction information of the account is recorded in the locked table name; if not, determine that the account is the target account.
[0149] In the embodiment of the present invention, as another optional embodiment, the account matching module 402 further includes: a third judgment unit,
[0150] The second judgment unit is further configured to notify the third judgment unit if the transaction information of the account is recorded in the locked table name;
[0151] The third judgment unit is used to obtain the serial number recorded in the account and the current serial number of the account; judge whether the recorded serial number is consistent with the current serial number; if they are consistent, execute the process corresponding to the transaction; if they are inconsistent, wait according to the waiting time in the transaction lock configuration table to wait for the account corresponding to the recorded serial number to be unlocked.
[0152] In the embodiment of the present invention, as an optional embodiment, the serial information includes but is not limited to: the serial number and the lock creation time.
[0153] In an embodiment of the present invention, as an optional embodiment, waiting according to the waiting time in the transaction lock configuration table includes:
[0154] Read the current number of retries of the current serial number recorded in the stored transaction lock configuration table;
[0155] If the current number of retries exceeds the number of retries in the transaction lock configuration table, output an exception message;
[0156] If not, after waiting for the waiting time, query whether the account corresponding to the recorded serial number has been unlocked; if so, execute the process corresponding to the transaction transaction to determine that the account corresponding to the recorded serial number is the target account; if not, add 1 to the current number of retries recorded in the stored transaction lock configuration table, and execute the step of reading the current number of retries of the current serial number recorded in the stored transaction lock configuration table.
[0157] The locking module 403 is used to lock the target account and add the transaction information corresponding to the target account to the transaction lock configuration table;
[0158] The unlocking module 404 is used to process the transaction according to the process corresponding to the transaction, and unlock the target account after the transaction is completed.
[0159] In the embodiment of the present invention, as an optional embodiment, the unlocking module 404 includes:
[0160] A first unlocking unit (not shown in the figure) clears the transaction information corresponding to the target account in the transaction lock configuration table if the operation result of the transaction is success or failure, and the operation result includes: success, failure or exception;
[0161] The second unlocking unit performs final state processing on the transaction if the operation result of the transaction is abnormal. If the final state processing is successful, the transaction flow information corresponding to the target account in the transaction lock configuration table is cleared, and the final state includes success or failure.
[0162] In the embodiment of the present invention, as an optional embodiment, the unlocking module 404 further includes:
[0163] The third unlocking unit, if it is monitored that the transaction information corresponding to the transaction in the transaction lock configuration table cannot be cleared, waits for a preset clearing time threshold, determines whether the operation result of the transaction is successful or failed, and then executes the clearing of the transaction information corresponding to the target account in the transaction lock configuration table.
[0164] In an embodiment of the present invention, as an optional embodiment, the device further includes:
[0165] The lock timeout processing module (not shown in the figure) is used to time the lock time. If the time exceeds the time threshold set in the transaction lock configuration table, the target account has not been unlocked, and an abnormal information is output to a preset terminal.
[0166] In the embodiment of the present invention, as an optional embodiment, the lock is a mutex lock.
[0167] like Figure 5 As shown, an embodiment of the present application provides a computer device 500 for executing Figure 1 The invention relates to a method for controlling distributed transaction transactions in a device, wherein the device comprises a memory 501, a processor 502 connected to the memory 501 via a bus, and a computer program stored in the memory 501 and executable on the processor 502, wherein the steps of the method for controlling distributed transaction transactions are implemented when the processor 502 executes the computer program.
[0168] Specifically, the above-mentioned memory 501 and processor 502 can be general-purpose memories and processors, which are not specifically limited here. When the processor 502 runs the computer program stored in the memory 501, it can execute the above-mentioned distributed transaction control method.
[0169] Corresponds to Figure 1 The distributed transaction control method in the present application also provides a computer-readable storage medium, on which a computer program is stored, and when the computer program is executed by a processor, the steps of the distributed transaction control method are executed.
[0170] Specifically, the storage medium can be a general storage medium, such as a mobile disk, a hard disk, etc. When the computer program on the storage medium is run, the above-mentioned distributed transaction control method can be executed.
[0171] In the embodiments provided in the present application, it should be understood that the disclosed systems and methods can be implemented in other ways. The system embodiments described above are merely schematic. For example, the division of the units is only a logical function division. There may be other division methods in actual implementation. For example, multiple units or components can be combined or integrated into another system, or some features can be ignored or not executed. Another point is that the mutual coupling or direct coupling or communication connection shown or discussed can be through some communication interfaces, indirect coupling or communication connection of systems or units, which can be electrical, mechanical or other forms.
[0172] The units described as separate components may or may not be physically separated, and the components shown as units may or may not be physical units, that is, they may be located in one place or distributed on multiple network units. Some or all of the units may be selected according to actual needs to achieve the purpose of the solution of this embodiment.
[0173] In addition, each functional unit in the embodiments provided in the present application may be integrated into one processing unit, or each unit may exist physically separately, or two or more units may be integrated into one unit.
[0174] If the functions are implemented in the form of software functional units and sold or used as independent products, they can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of the present application can be essentially or partly embodied in the form of a software product that contributes to the prior art. The computer software product is stored in a storage medium and includes several instructions for a computer device (which can be a personal computer, a server, or a network device, etc.) to perform all or part of the steps of the methods described in each embodiment of the present application. The aforementioned storage medium includes: various media that can store program codes, such as a USB flash drive, a mobile hard disk, a read-only memory (ROM), a random access memory (RAM), a magnetic disk or an optical disk.
[0175] It should be noted that similar numbers and letters represent similar items in the following figures. Therefore, once an item is defined in one figure, it does not need to be further defined and explained in subsequent figures. In addition, the terms "first", "second", "third", etc. are only used to distinguish the description and are not to be understood as indicating or implying relative importance.
[0176] Finally, it should be noted that the above-described embodiments are only specific implementation methods of the present application, which are used to illustrate the technical solutions of the present application, rather than to limit them. The protection scope of the present application is not limited thereto. Although the present application is described in detail with reference to the above-mentioned embodiments, ordinary technicians in the field should understand that any technician familiar with the technical field can still modify the technical solutions recorded in the above-mentioned embodiments within the technical scope disclosed in the present application, or can easily think of changes, or make equivalent replacements for some of the technical features therein; and these modifications, changes or replacements do not make the essence of the corresponding technical solutions deviate from the spirit and scope of the technical solutions of the embodiments of the present application. They should all be included in the protection scope of the present application. Therefore, the protection scope of the present application shall be subject to the protection scope of the claims.
Claims
1. A distributed transaction control method, characterized in that: include: Receive a distributed transaction processing request, obtain a transaction identifier corresponding to the transaction of the distributed transaction processing request, and determine whether the transaction identifier is configured in a pre-set transaction lock configuration table; If yes, extract multiple accounts included in the transaction corresponding to the transaction request, query the locked table name in the transaction lock configuration table, and determine the locked target account based on the extracted account and the locked table name; The step of determining the target account to be locked based on the extracted account and the locked table name includes: For each extracted account, determine whether the account exists in the locked table name; If so, determine whether the locked table name contains the transaction information of the account; If not recorded, determine that the account is the target account; Lock the target account, and add the transaction information corresponding to the target account to the transaction lock configuration table; Processing the transaction according to the process corresponding to the transaction; After the transaction is completed, unlocking the target account; The method further comprises: If the locked table name records the serial number information of the account, obtain the serial number recorded in the account and the current serial number of the account; Determine whether the recorded serial number is consistent with the current serial number; If they are consistent, execute the process corresponding to the transaction; After the transaction is completed, unlocking the target account includes: If the operation result of the transaction is success or failure, clear the transaction information corresponding to the target account in the transaction lock configuration table, and the operation result includes: success, failure or exception; If the operation result of the transaction is abnormal, the transaction is finalized, and if the finalization is successful, the transaction transaction is cleared from the transaction lock configuration table. The finalization includes success or failure. The method further comprises: If it is monitored that the transaction flow information corresponding to the transaction in the transaction lock configuration table cannot be cleared, after waiting for the preset clearing time threshold, it is determined that the operation result of the transaction is successful or failed, and then the transaction flow information corresponding to the target account in the transaction lock configuration table is cleared.
2. The method according to claim 1, characterized in that The method further comprises: If they are inconsistent, wait according to the waiting time in the transaction lock configuration table to wait for the account corresponding to the serial number of the record to be unlocked.
3. The method according to claim 2, characterized in that The waiting according to the waiting time in the transaction lock configuration table includes: Read the current number of retries of the current serial number recorded in the stored transaction lock configuration table; If the current number of retries exceeds the number of retries in the transaction lock configuration table, output an exception message; If not, after waiting for the waiting time, query whether the account corresponding to the recorded serial number has been unlocked; if so, execute the process corresponding to the transaction transaction to determine that the account corresponding to the recorded serial number is the target account; if not, add 1 to the current number of retries recorded in the stored transaction lock configuration table, and execute the step of reading the current number of retries of the current serial number recorded in the stored transaction lock configuration table.
4. The method according to any one of claims 1 to 3, characterized in that: The method further comprises: The locking time is counted. If the timing time exceeds the timing time threshold set in the transaction lock configuration table, the target account has not been unlocked, and an abnormal information is output to a preset terminal.
5. A distributed transaction control device, characterized in that: include: A transaction code matching module is used to receive a distributed transaction processing request, obtain a transaction identifier corresponding to the transaction of the distributed transaction processing request, and determine whether the transaction identifier is configured in a pre-set transaction lock configuration table; An account matching module, configured to extract the account included in the transaction, query the locked table name in the transaction lock configuration table, and determine the locked target account based on the extracted account and the locked table name; A locking module, used to lock the target account and add the transaction information corresponding to the target account to the transaction lock configuration table; An unlocking module, used to process the transaction according to the process corresponding to the transaction, and unlock the target account after the transaction is completed; The account matching module includes: A first judgment unit is used to judge, for each extracted account, whether the account exists in the locked table name; if so, notify the second judgment unit; A second judgment unit is used to judge whether the transaction information of the account is recorded in the locked table name; if not, determine that the account is the target account; The account matching module further includes: a third judgment unit, The second judgment unit is further configured to notify the third judgment unit if the transaction information of the account is recorded in the locked table name; A third judgment unit is used to obtain the serial number recorded in the account and the current serial number of the account; judge whether the recorded serial number is consistent with the current serial number; if they are consistent, execute the process corresponding to the transaction; Unlock modules include: A first unlocking unit, if the operation result of the transaction is success or failure, clears the transaction information corresponding to the target account in the transaction lock configuration table, the operation result including success, failure or exception; A second unlocking unit, if the operation result of the transaction is abnormal, performs final state processing on the transaction, and if the final state processing is successful, clears the transaction flow information corresponding to the target account in the transaction lock configuration table, and the final state includes success or failure; The unlock module also includes: The third unlocking unit, if it is monitored that the transaction information corresponding to the transaction in the transaction lock configuration table cannot be cleared, waits for a preset clearing time threshold, determines whether the operation result of the transaction is successful or failed, and then executes the clearing of the transaction information corresponding to the target account in the transaction lock configuration table.
6. A computer device, characterized in that: include: A processor, a memory and a bus, wherein the memory stores machine-readable instructions executable by the processor, and when the computer device is running, the processor and the memory communicate via the bus, and when the machine-readable instructions are executed by the processor, the steps of the control method for distributed transaction transactions as described in any one of claims 1 to 4 are performed.
7. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores a computer program, which, when executed by a processor, executes the steps of the distributed transaction control method as described in any one of claims 1 to 4.
