Transaction processing method and device, and computer-readable storage medium
Through two-stage processing and distributed lock and database technology, the problem of low fault tolerance in traditional accounting processing is solved, high reliability and high concurrency accounting processing is achieved, and automatic retry and recovery of transactions in abnormal situations are ensured.
Patent Information
- Application Number
- CN202210228368.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-03-08
- Publication Date
- 2025-09-23
- Estimated Expiration
- 2042-03-08
AI Technical Summary
Traditional accounting processing methods use a single-stage processing approach when handling transactions, resulting in low transaction processing fault tolerance. When the transfer-out account and the transfer-in account are not in the same database, there is a distributed transaction problem, resulting in the risk of transaction rollback.
A two-stage processing method is adopted, namely the first transaction stage and the second transaction stage. The successful completion of each stage is ensured by locking processing and verification mechanisms. Redisson distributed locks and Sharding-JDBC are used to implement locking and sharding of account resources. The failure retry mechanism and scheduled task compensation mechanism are combined to ensure the ultimate success of the transaction.
It improves the fault tolerance of transactions, ensures the reliability and concurrency of transactions, realizes automatic retry and recovery in abnormal situations, and improves the success rate of account processing.
Smart Images

Figure CN114675941B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of data processing, and in particular to a transaction processing method and device, and a computer-readable storage medium. Background Art
[0002] Traditional accounting processing methods process both outgoing and incoming accounts at the same stage, resulting in cumbersome business processes and inflexible differentiation between outgoing and incoming account processes. Furthermore, processing errors can lead to unnecessary transaction rollbacks. For example, if a transfer transaction succeeds for the outgoing account but fails for the incoming account, all the processed steps for both the outgoing and incoming accounts must be rolled back. If account data is sharded, and the outgoing and incoming accounts are not in the same database, this can lead to distributed transaction issues, creating the risk of transaction rollback failures.
[0003] To address the above-mentioned problems, no effective solutions have been proposed so far. Summary of the Invention
[0004] The embodiments of the present invention provide a transaction processing method and device, and a computer-readable storage medium, to at least solve the technical problem in the related art of adopting a single-stage processing method when processing transaction transactions, resulting in a low transaction processing fault tolerance rate.
[0005] According to one aspect of an embodiment of the present invention, a method for processing a transaction is provided, comprising: obtaining transaction information of the transaction, wherein the transaction includes at least two transaction stages; and when it is determined that the transaction is in an unsuccessfully processed state based on a verification result of the transaction information, processing the transaction in accordance with processing methods corresponding to the at least two transaction stages.
[0006] Optionally, before obtaining the transaction information of the transaction, the method further includes: initializing the transaction information.
[0007] Optionally, determining that the transaction is in an unsuccessful processing state based on the verification result of the transaction information includes: verifying the transaction information to obtain the verification result; and when the verification result indicates that the transaction information is successfully verified, determining that the transaction is in an unsuccessful processing state.
[0008] Optionally, the at least two transaction stages include: a first transaction stage and a second transaction stage, and the transaction transaction is processed according to the processing methods corresponding to the at least two transaction stages, including: judging whether the first transaction stage has been completed and obtaining a judgment result; if the judgment result is that the first transaction stage has not been successfully completed, locking the transaction object of the first transaction stage to obtain a first locking processing result; after the first locking processing result indicates that the transaction object of the first transaction stage is successfully locked, processing the transaction corresponding to the first transaction stage; after determining that the transaction transaction processing of the first transaction stage is completed, controlling the transaction to enter the second transaction stage to process the transaction using the processing method corresponding to the second transaction stage.
[0009] Optionally, the transaction is controlled to enter the second transaction stage to process the transaction using the processing method corresponding to the second transaction stage, including: locking the transaction object of the second transaction stage to obtain a second locking processing result; after the second locking processing result indicates that the transaction object of the second transaction stage is successfully locked, processing the transaction corresponding to the second transaction stage.
[0010] Optionally, after determining that the transaction processing of the first transaction stage is completed, the method further includes: unlocking the transaction object of the first transaction stage.
[0011] Optionally, after processing the transaction corresponding to the second transaction stage, the method further includes: unlocking the transaction object of the second transaction stage.
[0012] Optionally, the method further includes: when it is determined that locking processing of the transaction object in the first transaction phase or the transaction object in the second transaction phase fails, reacquiring a resource lock based on a predetermined algorithm, wherein the predetermined algorithm at least includes: a Redisson distributed algorithm; and using the resource lock to relock the transaction object in the first transaction phase or the transaction object in the second transaction phase.
[0013] According to another aspect of an embodiment of the present invention, a device for processing transaction transactions is also provided, including: an acquisition module for acquiring transaction information of the transaction transaction, wherein the transaction transaction includes at least two transaction stages; a processing module for processing the transaction transaction in accordance with the processing methods corresponding to the at least two transaction stages when it is determined that the transaction transaction is in an unsuccessful processing state based on a verification result of the transaction information.
[0014] Optionally, the device further includes: an initialization module, configured to initialize the transaction information before obtaining the transaction information of the transaction.
[0015] Optionally, the processing module includes: a verification unit for verifying the transaction information to obtain the verification result; and a determination unit for determining that the transaction is in an unsuccessful processing state when the verification result indicates that the transaction information is successfully verified.
[0016] Optionally, the processing module includes: a judgment unit for judging whether the first transaction stage has been completed and obtaining a judgment result; a locking unit for locking the transaction object of the first transaction stage and obtaining a first locking processing result when the judgment result is that the first transaction stage has not been successfully completed; a processing unit for processing the transaction transaction corresponding to the first transaction stage after the first locking processing result indicates that the transaction object of the first transaction stage has been successfully locked; and a control unit for controlling the transaction transaction to enter the second transaction stage after determining that the transaction transaction processing of the first transaction stage is completed, so as to process the transaction transaction using the processing method corresponding to the second transaction stage.
[0017] Optionally, the control unit includes: a locking subunit, used to lock the transaction object of the second transaction stage to obtain a second locking processing result; a processing subunit, used to process the transaction transaction corresponding to the second transaction stage after the second locking processing result indicates that the transaction object of the second transaction stage is successfully locked.
[0018] Optionally, the device further includes: a first unlocking module, configured to unlock the transaction object of the first transaction phase after determining that the transaction transaction processing of the first transaction phase is completed.
[0019] Optionally, the device further includes: a second unlocking module, configured to unlock the transaction object in the second transaction phase after processing the transaction transaction corresponding to the second transaction phase.
[0020] Optionally, the device further includes: a resource lock acquisition module, configured to reacquire the resource lock based on a predetermined algorithm when it is determined that the locking process of the transaction object in the first transaction phase or the transaction object in the second transaction phase has failed, wherein the predetermined algorithm at least includes: a Redisson distributed algorithm; and a re-locking module, configured to use the resource lock to re-lock the transaction object in the first transaction phase or the transaction object in the second transaction phase.
[0021] According to another aspect of an embodiment of the present invention, a computer-readable storage medium is also provided, wherein the computer-readable storage medium includes a stored computer program, wherein when the computer program is executed by a processor, the device where the computer-readable storage medium is located is controlled to execute any one of the above-mentioned transaction processing methods.
[0022] According to another aspect of an embodiment of the present invention, a processor is further provided, wherein the processor is configured to run a computer program, wherein the computer program executes any one of the above-mentioned transaction processing methods when running.
[0023] In an embodiment of the present invention, transaction information of a transaction is obtained, wherein the transaction includes at least two transaction stages; when it is determined based on the verification result of the transaction information that the transaction is in an unsuccessful processing state, the transaction is processed according to the processing methods corresponding to the at least two transaction stages. The transaction processing method provided by the embodiment of the present invention achieves the purpose of processing the transaction in multiple stages based on the acquired transaction information, thereby achieving the technical effect of improving the fault tolerance rate of transaction processing, and further solves the technical problem of adopting a single-stage processing method when processing transaction in related technologies, resulting in a low fault tolerance rate of transaction processing. BRIEF DESCRIPTION OF THE DRAWINGS
[0024] The drawings described herein are used to provide a further understanding of the present invention and constitute a part of this application. The exemplary embodiments of the present invention and their descriptions are used to explain the present invention and do not constitute an improper limitation of the present invention. In the drawings:
[0025] Figure 1 is a flow chart of a method for processing a transaction according to an embodiment of the present invention;
[0026] Figure 2 is a flow chart of a preferred transaction processing method according to an embodiment of the present invention;
[0027] Figure 3 2 is a schematic diagram of a transaction processing device according to an embodiment of the present invention. DETAILED DESCRIPTION
[0028] In order to enable those skilled in the art to better understand the solutions of the present invention, 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 embodiments described are only part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without making creative efforts should fall within the scope of protection of the present invention.
[0029] It should be noted that the terms "first", "second", etc. in the description and claims of the present invention and the above-mentioned drawings are used to distinguish similar objects and are not necessarily used to describe a specific order or sequence. It should be understood that the numbers used in this way can be interchanged where appropriate, so that the embodiments of the present invention described herein can be implemented in an order other than those illustrated or described herein. In addition, the terms "including" and "having" and any variations thereof are intended to cover non-exclusive inclusions. For example, a process, method, system, product or device that includes a series of steps or units is not necessarily limited to those steps or units clearly listed, but may include other steps or units that are not clearly listed or inherent to these processes, methods, products or devices.
[0030] Example 1
[0031] According to an embodiment of the present invention, a method embodiment of a method for processing transaction transactions is provided. It should be noted that the steps shown in the flowchart of the accompanying drawings can be executed in a computer system such as a set of computer-executable instructions, and although a logical order is shown in the flowchart, in some cases, the steps shown or described can be executed in an order different from that shown here.
[0032] Figure 1 Flowchart of a method for processing a transaction according to an embodiment of the present invention. Figure 1 As shown, the method includes the following steps:
[0033] Step S102: Acquire transaction information of a transaction, wherein the transaction includes at least two transaction stages.
[0034] Optionally, in the above steps, transaction transactions include but are not limited to: all transaction transactions between transaction entities and other transaction entities, and their transactions can be completed in at least two stages; transaction information refers to the identification information of the transaction and the completion status information of the transaction (i.e., whether the transaction has started, and if it has started, at which stage the transaction has reached).
[0035] Step S104: When it is determined based on the verification result of the transaction information that the transaction is in an unsuccessful processing state, the transaction is processed according to the processing methods corresponding to at least two transaction stages.
[0036] Optionally, in the above steps, after obtaining the transaction information, the transaction transaction is verified based on the transaction information to determine whether the transaction transaction has been successfully processed. If it has not been successfully processed, the verification passes and the transaction transaction continues to be processed according to the processing methods corresponding to the multiple transaction stages.
[0037] As can be seen from the above, in an embodiment of the present invention, first, the transaction information of the transaction can be obtained, wherein the transaction includes at least two transaction stages; then, when it is determined based on the verification result of the transaction information that the transaction is in an unsuccessful processing state, the transaction can be processed according to the processing methods corresponding to the at least two transaction stages. The transaction processing method provided by the embodiment of the present invention achieves the purpose of processing the transaction in multiple stages based on the acquired transaction information, thereby achieving the technical effect of improving the fault tolerance rate of transaction processing, and further solving the technical problem of adopting a single-stage processing method when processing transaction transactions in related technologies, resulting in a low fault tolerance rate of transaction processing.
[0038] As an optional embodiment, before obtaining the transaction information of the transaction, the method for processing the transaction further includes: initializing the transaction information.
[0039] In the above optional embodiment, when obtaining transaction information, since it is uncertain whether the data will be used for other processing, which will affect its format and other aspects and affect the subsequent verification and processing of the data, the transaction information is initialized and then the transaction information is processed to increase the reliability of the data.
[0040] As an optional embodiment, determining that the transaction is in an unsuccessful processing state based on the verification result of the transaction information includes: verifying the transaction information to obtain a verification result; when the verification result indicates that the transaction information is successfully verified, determining that the transaction is in an unsuccessful processing state.
[0041] In the above optional embodiment, the transaction information may be verified first. If the verification result shows that the transaction has not been successfully processed, the verification is passed; otherwise, the verification fails.
[0042] As an optional embodiment, the at least two transaction stages include: a first transaction stage and a second transaction stage, and the transaction affairs are processed according to the processing methods corresponding to the at least two transaction stages, including: judging whether the first transaction stage has been completed and obtaining the judgment result; if the judgment result is that the first transaction stage has not been successfully completed, locking the transaction object of the first transaction stage to obtain a first locking processing result; after the first locking processing result indicates that the transaction object of the first transaction stage is successfully locked, processing the transaction affairs corresponding to the first transaction stage; after determining that the transaction affairs processing of the first transaction stage is completed, controlling the transaction affairs to enter the second transaction stage, so as to process the transaction affairs using the processing method corresponding to the second transaction stage.
[0043] In the above optional embodiment, it is first possible to determine whether the first transaction stage has been completed. If it has been completed, the second stage of processing is entered; if it has not been completed, the transaction object of the first transaction stage is locked, and after the locking is completed, the transaction transaction is processed (for example, including but not limited to: processing of the transfer-out account, processing of the transaction of the active initiating transaction object, etc.). After the processing is completed, the transaction transaction is controlled to enter the second transaction stage, and the transaction transaction is processed in the corresponding processing method of the second transaction stage.
[0044] As an optional embodiment, the transaction is controlled to enter the second transaction stage, so as to process the transaction using the processing method corresponding to the second transaction stage, including: locking the transaction object of the second transaction stage to obtain a second locking processing result; after the second locking processing result indicates that the transaction object of the second transaction stage is successfully locked, the transaction corresponding to the second transaction stage is processed.
[0045] In the above optional embodiment, when the transaction reaches the second transaction stage, the transaction is locked, and after confirming that the locking is successful, the transaction is processed in the second transaction stage.
[0046] As an optional embodiment, after determining that the transaction transaction processing of the first transaction stage is completed, the transaction processing method further includes: unlocking the transaction object of the first transaction stage.
[0047] In the above optional embodiment, after the transaction transaction of the first transaction phase is completed, a contact resource lock is performed on the transaction object of the first transaction phase.
[0048] As an optional embodiment, after processing the transaction corresponding to the second transaction stage, the method for processing the transaction further includes: unlocking the transaction object of the second transaction stage.
[0049] In the above optional embodiment, after the transaction transaction of the second transaction phase is completed, a contact resource lock is performed on the transaction object of the second transaction phase.
[0050] As an optional embodiment, the transaction processing method further includes: when it is determined that locking processing of the transaction object in the first transaction phase or the transaction object in the second transaction phase fails, reacquiring a resource lock based on a predetermined algorithm, wherein the predetermined algorithm at least includes: a Redisson distributed algorithm; and using the resource lock to relock the transaction object in the first transaction phase or the transaction object in the second transaction phase.
[0051] It should be noted that when implementing the transaction processing method provided in the embodiments of the present invention, Redisson distributed locks were used to implement the locking and releasing of account resources during accounting processing. Redisson distributed locks support lock reentry, blocking waits, and atomic operations through Lua scripting, meeting the requirements of the transaction processing method provided in the embodiments of the present invention. Sharding-JDBC was also used to implement parallel sharding of accounting data. Redisson is a Java in-memory data grid (In-Memory Data Grid) implemented on top of Redis.
[0052] Figure 2 Flowchart of a preferred transaction processing method according to an embodiment of the present invention. Figure 2 As shown, the method provided in the embodiment of the present invention takes the transfer between two accounts as an example to illustrate the two-stage account processing process. The specific transfer processing process is as follows:
[0053] First, the transaction parameters are verified and initialized.
[0054] Then, based on the unique identifier and current status of the processing flow, an idempotency check is performed. If successful, the process continues; otherwise, the process ends directly.
[0055] Finally, determine whether the first stage has been processed: if it has been processed, perform on-site recovery of the intermediate state of the first stage and enter the second stage; if it has not been processed, enter the first stage.
[0056] The specific process of the first stage is:
[0057] (1) The current thread attempts to acquire the transfer-out account resource lock. If the lock is successful, it proceeds to the next step. If the lock fails, it retries to acquire the lock according to the Redisson distributed lock method.
[0058] (2) Processing of transactions related to the transfer-out account.
[0059] (3) The current thread releases the transfer-out account lock and records that the first phase has been successfully executed.
[0060] (4) The intermediate status of the first stage is retained on site.
[0061] The specific process of the second stage is:
[0062] (1) The current thread attempts to acquire the transferred account resource lock. If the lock is successful, it proceeds to the next step. If the lock fails, it retry to acquire the lock according to the Redisson distributed lock method.
[0063] (2) Processing of transactions related to the transferred account.
[0064] (3) The current thread releases the transfer account lock.
[0065] It should be noted that, in addition to the above-mentioned processing flow, the transaction processing method provided by the embodiment of the present invention also provides other safeguards to ensure the successful and efficient processing of account transactions. Specific measures include: (1) Failure retry mechanism: When the account transaction processing fails in the first or second stage, the retry mechanism is activated according to the pre-set number of retries. (2) Scheduled task compensation mechanism: For processes that have not been successfully processed after retries, they are re-promoted through scheduled tasks. The triggering frequency, number of executed data items, and query time range of the scheduled tasks can be configured according to actual business needs.
[0066] From the above, it can be seen that the transaction processing method provided by the embodiment of the present invention proposes a highly reliable and retryable two-stage accounting processing method and device, which combines distributed locks, database sharding, idempotent verification and failure retry compensation and other technical means to meet the high concurrency and data consistency of accounting processing, and realizes the requirement that abnormal failed accounting processing transactions can be retried to promote success.
[0067] Furthermore, the transaction processing method provided by the embodiment of the present invention has the following advantages:
[0068] (1) Account resource locking: In order to ensure that the accuracy of the account data is not affected by other requests, the account resources need to be locked first when performing accounting processing to ensure that only one thread among the concurrent threads can hold the resource lock of the current account. The lock will be released after the relevant accounting processing is completed.
[0069] (2) Horizontal partitioning of account data: In the accounting system, the amount of account data will be very large. In order to improve the concurrency of account accounting processing, the account data will be partitioned horizontally in the database.
[0070] (3) Idempotence Verification: For each accounting transaction, idempotence verification is performed using a unique identifier to ensure that the same accounting transaction is only successfully executed once when executed multiple times. On this basis, a retry mechanism is used to ensure that failed accounting transactions can be correctly pushed again.
[0071] (4) On-site preservation and recovery of intermediate states: When processing accounts in two stages, it is possible that the first stage succeeds but the second stage fails. For example, in a transfer transaction, the outgoing account is successfully processed, but the lock fails when processing the incoming account, resulting in the failure of the second stage of the incoming transfer. Although the server has processed the account balance information at this time and the user is unaware of this failure, the transaction needs to be successfully processed on the consumer side. At this time, the intermediate state of the successful first stage processing needs to be preserved on-site so that the intermediate state can be restored on-site when the transaction is pushed again.
[0072] (5) Scheduled task compensation: For transactions that succeeded in the first stage but failed in the second stage, as well as transactions that failed in the first stage, they are all re-promoted through scheduled tasks to ensure the final successful processing of the accounting process.
[0073] Example 2
[0074] According to another aspect of an embodiment of the present invention, a transaction processing device is provided. Figure 3 Schematic diagram of a transaction processing device according to an embodiment of the present invention. Figure 3 As shown, it includes: an acquisition module 31 and a processing module 33.
[0075] The acquisition module 31 is configured to acquire transaction information of a transaction, wherein the transaction includes at least two transaction stages.
[0076] The processing module 33 is configured to process the transaction in accordance with processing methods corresponding to at least two transaction stages when it is determined based on the verification result of the transaction information that the transaction is in an unsuccessful processing state.
[0077] It should be noted that the acquisition module 31 and the processing module 33 correspond to steps S102 to S104 in Example 1. The examples and application scenarios implemented by the modules and the corresponding steps are the same, but are not limited to the contents disclosed in Example 1. It should be noted that the modules, as part of the apparatus, can be executed in a computer system such as a set of computer-executable instructions.
[0078] As can be seen from the above, in the embodiment of the present invention, first, the transaction information of the transaction can be obtained by means of the acquisition module 31, wherein the transaction includes at least two transaction stages; then, when the transaction is determined to be in an unsuccessful processing state based on the verification result of the transaction information, the transaction is processed according to the processing methods corresponding to the at least two transaction stages by means of the processing module 33. The transaction processing device provided by the embodiment of the present invention achieves the purpose of processing transactions in multiple stages based on the acquired transaction information, thereby achieving the technical effect of improving the fault tolerance rate of transaction processing, and further solving the technical problem of adopting a single-stage processing method when processing transaction transactions in related technologies, resulting in a low fault tolerance rate of transaction processing.
[0079] Optionally, the transaction processing device further includes: an initialization module, configured to initialize the transaction information before obtaining the transaction information of the transaction.
[0080] Optionally, the processing module includes: a verification unit for verifying the transaction information and obtaining a verification result; and a determination unit for determining that the transaction is in an unsuccessful processing state when the verification result indicates that the transaction information is successfully verified.
[0081] Optionally, the processing module includes: a judgment unit for judging whether the first transaction stage has been completed and obtaining a judgment result; a locking unit for locking the transaction object of the first transaction stage when the judgment result is that the first transaction stage has not been successfully completed, and obtaining a first locking processing result; a processing unit for processing the transaction transaction corresponding to the first transaction stage after the first locking processing result indicates that the transaction object of the first transaction stage has been successfully locked; and a control unit for controlling the transaction transaction to enter the second transaction stage after determining that the transaction transaction processing of the first transaction stage is completed, so as to process the transaction transaction using the processing method corresponding to the second transaction stage.
[0082] Optionally, the control unit includes: a locking subunit, used to lock the transaction object of the second transaction phase to obtain a second locking processing result; a processing subunit, used to process the transaction transaction corresponding to the second transaction phase after the second locking processing result indicates that the transaction object of the second transaction phase is successfully locked.
[0083] Optionally, the transaction processing device further includes: a first unlocking module, configured to unlock the transaction object of the first transaction phase after determining that the transaction processing of the first transaction phase is completed.
[0084] Optionally, the transaction processing device further includes: a second unlocking module, configured to unlock the transaction object of the second transaction phase after processing the transaction corresponding to the second transaction phase.
[0085] Optionally, the transaction processing device further includes: a resource lock acquisition module, which is used to re-acquire the resource lock based on a predetermined algorithm when it is determined that the locking process of the transaction object of the first transaction phase or the transaction object of the second transaction phase has failed, wherein the predetermined algorithm at least includes: a Redisson distributed algorithm; and a re-locking module, which is used to use the resource lock to re-lock the transaction object of the first transaction phase or the transaction object of the second transaction phase.
[0086] Example 3
[0087] According to another aspect of an embodiment of the present invention, a computer-readable storage medium is also provided, which includes a stored computer program, wherein when the computer program is executed by a processor, the device where the computer-readable storage medium is located is controlled to execute any one of the above-mentioned transaction processing methods.
[0088] Example 4
[0089] According to another aspect of an embodiment of the present invention, a processor is further provided, which is configured to run a computer program, wherein the computer program executes any one of the above-mentioned transaction processing methods when running.
[0090] The serial numbers of the above embodiments of the present invention are for description only and do not represent the advantages or disadvantages of the embodiments.
[0091] In the above embodiments of the present invention, the description of each embodiment has its own focus. For parts that are not described in detail in a certain embodiment, reference can be made to the relevant descriptions of other embodiments.
[0092] In the several embodiments provided in this application, it should be understood that the disclosed technical content can be implemented in other ways. Among them, the device embodiments described above are only exemplary. For example, the division of the units can be a logical function division. In actual implementation, there may be other division methods, such as 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 interfaces, indirect coupling or communication connection of units or modules, which can be electrical or other forms.
[0093] The units described as separate components may or may not be physically separate, and the components shown as units may or may not be physical units, that is, they may be located in one place or distributed across multiple units. Some or all of the units may be selected according to actual needs to achieve the purpose of the present embodiment.
[0094] In addition, the functional units in the various embodiments of the present invention may be integrated into a single processing unit, each unit may exist physically separately, or two or more units may be integrated into a single unit. The aforementioned integrated units may be implemented in the form of hardware or software functional units.
[0095] If the integrated unit is implemented in the form of a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of the present invention, or the part that contributes to the prior art, or all or part of the technical solution can be embodied in the form of a software product. The computer software product is stored in a storage medium and includes several instructions for enabling a computer device (which can be a personal computer, server or network device, etc.) to perform all or part of the steps of the method described in each embodiment of the present invention. The aforementioned storage medium includes: U disk, read-only memory (ROM, Read-Only Memory), random access memory (RAM, Random Access Memory), mobile hard disk, magnetic disk or optical disk, etc. Various media that can store program codes.
[0096] The above is only a preferred embodiment of the present invention. It should be pointed out that for ordinary technicians in this technical field, several improvements and modifications can be made without departing from the principles of the present invention. These improvements and modifications should also be regarded as within the scope of protection of the present invention.
Claims
1. A method for processing a transaction, characterized in that: include: Acquiring transaction information of a transaction, wherein the transaction includes at least two transaction stages; When it is determined based on the verification result of the transaction information that the transaction is in an unsuccessful processing state, processing the transaction according to the processing methods corresponding to the at least two transaction stages; The at least two transaction phases include: a first transaction phase and a second transaction phase, and processing the transaction in accordance with processing methods corresponding to the at least two transaction phases, including: determining whether the first transaction phase has been completed and obtaining a determination result; if the determination result is that the first transaction phase has not been successfully completed, performing a locking process on the transaction object of the first transaction phase to obtain a first locking process result; after the first locking process result indicates that the transaction object of the first transaction phase has been successfully locked, processing the transaction corresponding to the first transaction phase; after determining that the transaction processing of the first transaction phase has been completed, controlling the transaction to enter the second transaction phase to process the transaction using the processing method corresponding to the second transaction phase; Controlling the transaction to enter the second transaction stage to process the transaction using the processing method corresponding to the second transaction stage, including: locking the transaction object of the second transaction stage to obtain a second locking processing result; after the second locking processing result indicates that the transaction object of the second transaction stage is successfully locked, processing the transaction corresponding to the second transaction stage.
2. The method according to claim 1, characterized in that Before obtaining the transaction information of the transaction, the method further includes: Initialize the transaction information.
3. The method according to claim 1, characterized in that Determining that the transaction is in an unsuccessful processing state based on a verification result of the transaction information includes: Verifying the transaction information to obtain the verification result; When the verification result indicates that the transaction information is successfully verified, it is determined that the transaction is in an unsuccessful processing state.
4. The method according to claim 1, wherein After determining that the transaction processing of the first transaction stage is completed, the method further includes: Unlock the transaction object of the first transaction stage.
5. The method according to claim 1, wherein After processing the transaction corresponding to the second transaction stage, the method further includes: Unlock the transaction object of the second transaction stage.
6. The method according to claim 1, characterized in that The method further comprises: If it is determined that locking the transaction object of the first transaction phase or the transaction object of the second transaction phase fails, reacquiring the resource lock based on a predetermined algorithm, wherein the predetermined algorithm at least includes: a Redisson distributed algorithm; The resource lock is used to re-lock the transaction object in the first transaction phase or the transaction object in the second transaction phase.
7. A transaction processing device, characterized in that: include: An acquisition module, configured to acquire transaction information of a transaction, wherein the transaction includes at least two transaction stages; a processing module configured to process the transaction in accordance with processing methods corresponding to the at least two transaction stages when it is determined based on the verification result of the transaction information that the transaction is in an unsuccessful processing state; The at least two transaction phases include: a first transaction phase and a second transaction phase, and the processing module includes: a judgment unit for judging whether the first transaction phase has been completed and obtaining a judgment result; a locking unit for, if the judgment result is that the first transaction phase has not been successfully completed, performing a locking process on the transaction object of the first transaction phase to obtain a first locking process result; a processing unit for, after the first locking process result indicates that the transaction object of the first transaction phase has been successfully locked, processing the transaction corresponding to the first transaction phase; and a control unit for, after determining that the transaction processing of the first transaction phase is completed, controlling the transaction to enter the second transaction phase, so as to process the transaction using the processing method corresponding to the second transaction phase; The control unit includes: a locking subunit, which is used to lock the transaction object of the second transaction stage to obtain a second locking processing result; and a processing subunit, which is used to process the transaction transaction corresponding to the second transaction stage after the second locking processing result indicates that the transaction object of the second transaction stage is successfully locked.
8. A computer-readable storage medium, characterized in that The computer-readable storage medium includes a stored computer program, wherein when the computer program is executed by a processor, the device where the computer-readable storage medium is located is controlled to execute the transaction processing method according to any one of claims 1 to 6.
9. A processor, characterized in that: The processor is configured to run a computer program, wherein the computer program, when running, executes the transaction processing method according to any one of claims 1 to 6.
Citation Information
Patent Citations
Micro-service calling supervision system and method capable of guaranteeing idempotent
CN111241112A
Transaction processing method for distributed transactions and related equipment
CN111694851A