Idempotent detection method for distributed transaction and related product
By performing multiple executions of each branch transaction of distributed transaction and comparing the data table library collection, it detects its idempotence, and solves the problem of poor data consistency and security in distributed transactions, achieving higher data consistency and security.
Patent Information
- Application Number
- CN202411645023.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-11-18
- Publication Date
- 2025-03-11
AI Technical Summary
Data consistency and security in distributed transactions are relatively poor, especially in the fields of finance and payments, which are difficult to effectively guarantee idempotence.
By obtaining each branch transaction of the distributed transaction to be tested, each branch transaction is executed multiple times, the executed data table library collection is obtained, and the data table library collection is compared. When the data table library set is consistent, branch transactions pass idempotence detection; after all branch transactions pass the detection, the distributed transaction to be tested is instructed to pass idempotence detection.
Improve the consistency and security of data in distributed transactions, and ensure the consistency of data in each branch transaction through idempotence detection, thereby enhancing the reliability and security of the system.
Smart Images

Figure CN119597770A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of detection technology, and in particular to a distributed transaction idempotence detection method and related products. Background Art
[0002] Distributed transactions are a form of transactions that split the core business system to reduce the coupling between modules in the core business system, improve business development, and enhance the scalability of system capacity. Idempotence is one of the important guarantees for improving data consistency and security, especially in the financial and payment fields.
[0003] Distributed transactions involve cross-service transaction issues, and data consistency and security are crucial. However, in related technologies, the data consistency and security of distributed transactions are relatively poor. Summary of the invention
[0004] Based on the above problems, the present application provides a distributed transaction idempotence detection method and related products to improve data consistency and security in distributed transactions.
[0005] The embodiments of the present application disclose the following technical solutions:
[0006] In a first aspect, an embodiment of the present application provides an idempotence detection method for a distributed transaction, characterized in that the method comprises:
[0007] Obtain each branch transaction of the distributed transaction to be tested;
[0008] For each branch transaction, the branch transaction is executed multiple times, and a data table library set after each branch transaction is executed is obtained respectively; each data table library set is compared, and when each data table library set is consistent, the branch transaction passes the idempotence test;
[0009] In the case that each of the branch transactions passes the idempotence test, it is indicated that the distributed transaction to be tested passes the idempotence test.
[0010] Optionally, the data table library set includes at least a first data table library set and a second data table library set, and data table categories in the first data table library set and the second data table library set are consistent; comparing the data table library sets and indicating that the branch transaction passes the idempotence test when the data table library sets are consistent includes:
[0011] Comparing data tables of the same category in the first data table library set and the second data table library set field by field and obtaining a comparison result;
[0012] When the comparison result indicates that all data tables of the same category in the first data table library set and the second data table library set are consistent, it is indicated that the branch transaction passes the idempotence test.
[0013] Optionally, the data table categories in the first data table library set and the second data table library set both include at least customer information data tables, financial information data tables and internal accounting information data tables.
[0014] Optionally, when any of the branch transactions fails the idempotence test, the distributed transaction to be tested fails the idempotence test.
[0015] In a second aspect, an embodiment of the present application provides an idempotence detection device for distributed transactions, the device comprising: an acquisition module, an execution module and an indication module;
[0016] The acquisition module is used to acquire the branch transaction of the distributed transaction to be tested;
[0017] The execution module is used to execute the branch transaction multiple times for each branch transaction, and obtain the data table library set after each branch transaction is executed; compare the data table library sets, and when the data table library sets are consistent, the branch transaction passes the idempotence test;
[0018] The indication module is used to indicate that the distributed transaction to be tested has passed the idempotence test when all the branch transactions have passed the idempotence test.
[0019] Optionally, the execution module is specifically used to compare the data tables of the same category in the first data table library set and the second data table library set field by field and obtain a comparison result, when the data table library set includes at least a first data table library set and a second data table library set, and when the data table categories in the first data table library set and the second data table library set are consistent; when the comparison result indicates that all data tables of the same category in the first data table library set and the second data table library set are consistent, the branch transaction of the distributed transaction to be tested passes the idempotence test.
[0020] Optionally, the data table categories in the first data table library set and the second data table library set both include at least customer information data tables, financial information data tables and internal accounting information data tables.
[0021] Optionally, the indication module is further configured to indicate that the distributed transaction to be tested fails the idempotence test when any of the branch transactions fails the idempotence test.
[0022] 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 when the processor executes the computer program, the idempotence detection method for distributed transactions as described in any embodiment of the first aspect is implemented.
[0023] In a fourth aspect, an embodiment of the present application provides a computer-readable storage medium, in which instructions are stored. When the instructions are executed on a terminal device, the terminal device executes the idempotence detection method for distributed transactions as described in any embodiment of the first aspect.
[0024] Compared with the prior art, this application has the following beneficial effects:
[0025] The embodiment of the present application provides an idempotency detection method for distributed transactions. First, each branch transaction of the distributed transaction to be tested is obtained; then, for each branch transaction, the branch transaction is executed multiple times, and the data table library set after each branch transaction is executed is obtained respectively; each data table library set is compared, and when each data table library set is consistent, the branch transaction passes the idempotency detection; finally, when each branch transaction passes the idempotency detection, it is indicated that the distributed transaction to be tested passes the idempotency detection. In the embodiment of the present application, an idempotency detection is performed on each branch transaction of the distributed transaction, and then, based on the idempotency detection results of each branch transaction, it is determined whether the distributed transaction passes the idempotency detection, thereby realizing the idempotency detection of the distributed transaction, thereby improving the data consistency and data security of the distributed transaction. BRIEF DESCRIPTION OF THE DRAWINGS
[0026] In order to more clearly illustrate the embodiments of the present application or the technical solutions in the prior art, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present application. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative labor.
[0027] Figure 1 A flowchart of a distributed transaction idempotence detection method provided in an embodiment of the present application;
[0028] Figure 2 A schematic diagram of an idempotence detection device for distributed transactions provided in an embodiment of the present application;
[0029] Figure 3 A schematic diagram of the structure of a computer device provided in an embodiment of the present application. DETAILED DESCRIPTION
[0030] In order to enable those skilled in the art to better understand the solution of the present application, the technical solution in the present embodiment will be clearly and completely described below in conjunction with the drawings in the present embodiment. Obviously, the described embodiment is only a part of the embodiments of the present application, not all of the embodiments. Based on the embodiments in the present application, all other embodiments obtained by ordinary technicians in the field without creative work are within the scope of protection of the present application.
[0031] The terms "first" and "second" in the specification and claims of this application are used to distinguish different objects rather than to describe a specific order of objects. For example, a first resistor and a second resistor are used to distinguish different resistors rather than to describe a specific order of resistors.
[0032] In this embodiment, the words "exemplary" or "for example" are used to indicate examples, illustrations or explanations. Any embodiment or design described as "exemplary" or "for example" in this embodiment should not be interpreted as being more preferred or more advantageous than other embodiments or designs. Specifically, the use of words such as "exemplary" or "for example" is intended to present related concepts in a specific way.
[0033] In the description of this embodiment, unless otherwise specified, “multiple” means two or more than two. For example, multiple processing units means two or more processing units, etc.; multiple elements means two or more elements, etc.
[0034] The technical solution of the present application will be introduced below in conjunction with embodiments.
[0035] See also Figure 1 , which is a flow chart of a method for detecting idempotence of distributed transactions provided in an embodiment of the present application.
[0036] like Figure 1 As shown, the method includes:
[0037] S110: Obtain each branch transaction of the distributed transaction to be tested.
[0038] In the embodiments of the present application, the number of branch transactions in the distributed transaction to be tested is not specifically limited. For example, the distributed transaction to be tested includes 3 branch transactions, or the distributed transaction to be tested includes 4 branch transactions. For ease of understanding, the following embodiments will be described by taking the distributed transaction to be tested including 3 branch transactions (a first branch transaction, a second branch transaction, and a third branch transaction) as an example.
[0039] Generally, the system divides the distributed transaction into a first branch transaction, a second branch transaction and a third branch transaction, wherein each branch transaction corresponds to an execution mechanism in the execution computer system, and each execution mechanism receives the corresponding branch transaction.
[0040] S120: For each branch transaction, execute the branch transaction multiple times, and obtain the data table library set after each branch transaction is executed; compare the data table library sets, and when the data table library sets are consistent, the branch transaction passes the idempotence test.
[0041] In the embodiment of the present application, the number of executions of each branch transaction is not specifically limited. For example, the number of executions of the first branch transaction, the second branch transaction, and the third branch transaction may be the same or different. The following will take the first branch transaction, the second branch transaction, and the third branch transaction as an example in which each of the first branch transaction, the second branch transaction, and the third branch transaction is executed twice.
[0042] For the first branch transaction, execute the first branch transaction twice, and obtain the first data table library set after the first branch transaction is executed for the first time, and the second data table library set after the first branch transaction is executed for the second time; compare the first data table library set and the second data table library set, and if the first data table library set and the second data table library set are consistent, the first branch transaction passes the idempotence test; otherwise, the first branch transaction fails the idempotence test.
[0043] In the embodiment of the present application, the data table categories in the data table library are not specifically limited. For example, the data table library includes a customer information data table usr, a financial information data table fin, an internal accounting information data table acc, and other information data tables oth.
[0044] For the first branch transaction, the first data table library includes the customer information data table usr1, the financial information data table fin1, the internal accounting information data table acc1, and the other information data table oth1; the second data table library includes the customer information data table usr2, the financial information data table fin2, the internal accounting information data table acc2, and the other information data table oth2. The execution mechanism corresponding to the first branch transaction compares the customer information data table usr1 with the customer information data table usr2, the financial information data table fin1 with the financial information data table fin2, the internal accounting information data table acc1 with the internal accounting information data table acc2, and the other information data table oth1 and the other information data table oth2 field by field; if the customer information data table usr1 is consistent with the customer information data table usr2, the financial information data table fin1 is consistent with the financial information data table fin2, the internal accounting information data table acc1 is consistent with the internal accounting information data table acc2, and the other information data table oth1 and the other information data table oth2 are consistent, then the first branch transaction passes the idempotence test.
[0045] It should be understood that if any set of data tables is inconsistent, the first branch transaction fails the idempotence test.
[0046] For the second branch transaction, the first data table library includes the customer information data table usr1, the financial information data table fin1, the internal accounting information data table acc1, and the other information data table oth1; the second data table library includes the customer information data table usr2, the financial information data table fin2, the internal accounting information data table acc2, and the other information data table oth2. The execution mechanism corresponding to the first branch transaction compares the customer information data table usr1 with the customer information data table usr2, the financial information data table fin1 with the financial information data table fin2, the internal accounting information data table acc1 with the internal accounting information data table acc2, and the other information data table oth1 and the other information data table oth2 field by field; if the customer information data table usr1 is consistent with the customer information data table usr2, the financial information data table fin1 is consistent with the financial information data table fin2, the internal accounting information data table acc1 is consistent with the internal accounting information data table acc2, and the other information data table oth1 and the other information data table oth2 are consistent, then the second branch transaction passes the idempotence test.
[0047] It should be understood that if any set of data tables is inconsistent, the second branch transaction fails the idempotence test.
[0048] For the third branch transaction, the first data table library includes the customer information data table usr1, the financial information data table fin1, the internal accounting information data table acc1, and the other information data table oth1; the second data table library includes the customer information data table usr2, the financial information data table fin2, the internal accounting information data table acc2, and the other information data table oth2. The execution mechanism corresponding to the first branch transaction compares the customer information data table usr1 with the customer information data table usr2, the financial information data table fin1 with the financial information data table fin2, the internal accounting information data table acc1 with the internal accounting information data table acc2, and the other information data table oth1 and the other information data table oth2 field by field; if the customer information data table usr1 is consistent with the customer information data table usr2, the financial information data table fin1 is consistent with the financial information data table fin2, the internal accounting information data table acc1 is consistent with the internal accounting information data table acc2, and the other information data table oth1 and the other information data table oth2 are consistent, then the third branch transaction passes the idempotence test.
[0049] It should be understood that if any set of data tables is inconsistent, the third branch transaction fails the idempotence test.
[0050] S130: When all branch transactions pass the idempotency test, it is indicated that the distributed transaction to be tested passes the idempotency test.
[0051] When the first branch transaction, the second branch transaction, and the third branch transaction all pass the idempotence test, the distributed transaction to be tested passes the idempotence test.
[0052] If at least one of the first branch transaction, the second branch transaction, and the third branch transaction fails to pass the idempotency test, the distributed transaction to be tested fails the idempotency test. For example, the first branch transaction fails the idempotency test, or the first branch transaction and the second branch transaction fail the idempotency test, etc.
[0053] In an embodiment of the present application, an idempotence test is performed on each branch transaction of a distributed transaction, and then based on the idempotence test results of each branch transaction, it is determined whether the distributed transaction passes the idempotence test, thereby implementing the idempotence test of the distributed transaction, thereby improving the data consistency and data security of the distributed transaction.
[0054] See also Figure 2 , this figure is a schematic diagram of the idempotence detection device for distributed transactions provided in an embodiment of the present application.
[0055] like Figure 2 As shown, the device includes: an acquisition module 210, an execution module 220 and an indication module 230;
[0056] The acquisition module 210 is used to acquire the branch transaction of the distributed transaction to be tested.
[0057] The execution module 220 is used to execute the branch transaction multiple times for each branch transaction, and obtain the data table library set after each branch transaction is executed; compare the data table library sets, and when the data table library sets are consistent, the branch transaction passes the idempotence test.
[0058] Specifically, the execution module 220 is specifically used to compare the data tables of the same category in the first data table library set and the second data table library set field by field and obtain the comparison result when the data table library set includes at least the first data table library set and the second data table library set, and the data table categories in the first data table library set and the second data table library set are consistent; when the comparison result indicates that all data tables of the same category in the first data table library set and the second data table library set are consistent, the branch transaction of the distributed transaction to be tested passes the idempotence test.
[0059] The data table categories in the first data table library set and the second data table library set at least include customer information data tables, financial information data tables and internal accounting information data tables.
[0060] The indication module 230 is used to indicate that the distributed transaction to be tested has passed the idempotence test when all branch transactions have passed the idempotence test.
[0061] In addition, the indication module 230 is further configured to indicate that the distributed transaction to be tested has failed the idempotence test when any branch transaction has failed the idempotence test.
[0062] An embodiment of the present application provides a computer-readable storage medium on which a computer program is stored. When the program is executed by a processor, the idempotence detection method for distributed transactions described in the embodiment of the present application is implemented.
[0063] In practical applications, the computer-readable storage medium can adopt any combination of one or more computer-readable media. The computer-readable medium can be a computer-readable signal medium or a computer-readable storage medium. The computer-readable storage medium can be, for example, but not limited to, a system, device or device of electricity, magnetism, light, electromagnetic, infrared, or semiconductor, or any combination of the above. More specific examples (non-exhaustive list) of computer-readable storage media include: an electrical connection with one or more wires, a portable computer disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the above. In the present embodiment, the computer-readable storage medium can be any tangible medium containing or storing a program, which can be used by an instruction execution system, device or device or used in combination with it.
[0064] Computer-readable signal media may include data signals propagated in baseband or as part of a carrier wave, which carry computer-readable program code. Such propagated data signals may take a variety of forms, including but not limited to electromagnetic signals, optical signals, or any suitable combination of the above. Computer-readable signal media may also be any computer-readable medium other than a computer-readable storage medium, which may send, propagate, or transmit a program for use by or in conjunction with an instruction execution system, apparatus, or device.
[0065] The program code embodied on the computer readable medium may be transmitted using any appropriate medium, including but not limited to wireless, wireline, optical fiber cable, RF, etc., or any suitable combination of the foregoing.
[0066] Computer program code for performing the operations of the present invention may be written in one or more programming languages or a combination thereof, including object-oriented programming languages such as Java, Smalltalk, C++, and conventional procedural programming languages such as "C" or similar programming languages. The program code may be executed entirely on the user's computer, partially on the user's computer, as a separate software package, partially on the user's computer and partially on a remote computer, or entirely on a remote computer or server. In the case of a remote computer, the remote computer may be connected to the user's computer through any type of network, including a local area network (LAN) or a wide area network (WAN), or may be connected to an external computer (e.g., via the Internet using an Internet service provider).
[0067] like Figure 3As shown, a schematic diagram of the structure of a computer device provided in an embodiment of the present application. Figure 3 The computer device 12 shown is only an example and should not bring any limitation to the functions and scope of use of the embodiments of the present invention.
[0068] like Figure 3 As shown, the computer device 12 is in the form of a general-purpose computing device. The components of the computer device 12 may include, but are not limited to: one or more processors or processing units 16, a system memory 28, and a bus 18 that connects various system components (including the system memory 28 and the processing unit 16).
[0069] Bus 18 represents one or more of several types of bus structures, including a memory bus or memory controller, a peripheral bus, an accelerated graphics port, a processor or a local bus using any of a variety of bus architectures. By way of example, these architectures include, but are not limited to, an Industry Standard Architecture (ISA) bus, a Micro Channel Architecture (MAC) bus, an Enhanced ISA bus, a Video Electronics Standards Association (VESA) local bus, and a Peripheral Component Interconnect (PCI) bus.
[0070] The computer device 12 typically includes a variety of computer system readable media. These media can be any available media that can be accessed by the computer device 12, including volatile and non-volatile media, removable and non-removable media.
[0071] The system memory 28 may include computer system readable media in the form of volatile memory, such as random access memory (RAM) 30 and / or cache memory 32. The computer device 12 may further include other removable / non-removable, volatile / non-volatile computer system storage media. By way of example only, the storage system 34 may be used to read and write non-removable, non-volatile magnetic media ( Figure 3 not shown, usually called a "hard drive"). Although Figure 3 Not shown in the figure, a disk drive for reading and writing to a removable non-volatile disk (e.g., a "floppy disk"), and an optical disk drive for reading and writing to a removable non-volatile optical disk (e.g., a CD-ROM, a DVD-ROM, or other optical media) may be provided. In these cases, each drive may be connected to the bus 18 via one or more data medium interfaces. The memory 28 may include at least one program product having a set (e.g., at least one) of program modules that are configured to perform the functions of the various embodiments of the present invention.
[0072] A program / utility 40 having a set (at least one) of program modules 42 may be stored, for example, in the memory 28, such program modules 42 including, but not limited to, an operating system, one or more application programs, other program modules, and program data, each of which or some combination may include an implementation of a network environment. The program modules 42 generally perform the functions and / or methods of the embodiments described herein.
[0073] The computer device 12 may also communicate with one or more external devices 14 (e.g., keyboards, pointing devices, displays 24, etc.), one or more devices that enable a user to interact with the computer device 12, and / or any device that enables the computer device 12 to communicate with one or more other computing devices (e.g., network cards, modems, etc.). Such communication may be performed through an input / output (I / O) interface 22. Furthermore, the computer device 12 may also communicate with one or more networks (e.g., local area networks (LANs), wide area networks (WANs), and / or public networks, such as the Internet) through a network adapter 20. Figure 3 As shown, the network adapter 20 communicates with other modules of the computer device 12 via the bus 18. It should be understood that although Figure 3 Not shown, other hardware and / or software modules may be used in conjunction with computer device 12, including but not limited to microcode, device drivers, redundant processing units, external disk drive arrays, RAID systems, tape drives, and data backup storage systems.
[0074] The processor unit 16 executes various functional applications and data processing by running programs stored in the system memory 28, such as implementing the idempotence detection method for distributed transactions provided in an embodiment of the present application.
[0075] It should be noted that each embodiment in this specification is described in a progressive manner, and the same or similar parts between the embodiments can be referred to each other, and each embodiment focuses on the differences from other embodiments. In particular, for the device embodiment, since it is basically similar to the method embodiment, the description is relatively simple, and the relevant parts can be referred to the partial description of the method embodiment. The device embodiment described above is merely schematic, in which the unit described as a separate component may or may not be physically separated, and the component prompted as a unit may or may not be a physical unit, that is, it may be located in one place, or it may be distributed on multiple network units. Some or all of the modules can be selected according to actual needs to achieve the purpose of the scheme of this embodiment. Ordinary technicians in this field can understand and implement it without paying creative work.
[0076] The above is only a specific implementation of the present application, but the protection scope of the present application is not limited thereto. Any changes or substitutions that can be easily thought of by a person skilled in the art within the technical scope disclosed in the present application should be included in the protection scope of the present application. Therefore, the protection scope of the present application should be based on the protection scope of the claims.
Claims
1. A method for detecting idempotence of distributed transactions, characterized in that: The method comprises: Obtain each branch transaction of the distributed transaction to be tested; For each branch transaction, the branch transaction is executed multiple times, and a data table library set after each branch transaction is executed is obtained respectively; each data table library set is compared, and when each data table library set is consistent, the branch transaction passes the idempotence test; In the case that each of the branch transactions passes the idempotence test, it is indicated that the distributed transaction to be tested passes the idempotence test.
2. The idempotence detection method according to claim 1, characterized in that: The data table library set includes at least a first data table library set and a second data table library set, and the data table categories in the first data table library set and the second data table library set are consistent; The comparing the data table library sets and indicating that the branch transaction passes the idempotence test when the data table library sets are consistent includes: Comparing data tables of the same category in the first data table library set and the second data table library set field by field and obtaining a comparison result; When the comparison result indicates that all data tables of the same category in the first data table library set and the second data table library set are consistent, it is indicated that the branch transaction passes the idempotence test.
3. The idempotence detection method according to claim 1 or 2, characterized in that: The data table categories in the first data table library set and the second data table library set both include at least customer information data tables, financial information data tables, and internal accounting information data tables.
4. The idempotence detection method according to claim 3, characterized in that: In the case that any of the branch transactions fails to pass the idempotence test, the distributed transaction to be tested fails to pass the idempotence test.
5. A distributed transaction idempotence detection device, characterized in that: The device comprises: an acquisition module, an execution module and an indication module; The acquisition module is used to acquire the branch transaction of the distributed transaction to be tested; The execution module is used to execute the branch transaction multiple times for each branch transaction, and obtain the data table library set after each branch transaction is executed; compare the data table library sets, and when the data table library sets are consistent, the branch transaction passes the idempotence test; The indication module is used to indicate that the distributed transaction to be tested has passed the idempotence test when all the branch transactions have passed the idempotence test.
6. The idempotence detection device according to claim 5, characterized in that: The execution module is specifically used to compare the data tables of the same category in the first data table library set and the second data table library set field by field and obtain a comparison result when the data table library set includes at least a first data table library set and a second data table library set, and when the data table categories in the first data table library set and the second data table library set are consistent; when the comparison result indicates that all data tables of the same category in the first data table library set and the second data table library set are consistent, the branch transaction of the distributed transaction to be tested passes the idempotence test.
7. The idempotence detection device according to claim 5 or 6, characterized in that: The data table categories in the first data table library set and the second data table library set both include at least customer information data tables, financial information data tables, and internal accounting information data tables.
8. The idempotence detection device according to claim 7, characterized in that: The indication module is further configured to indicate that the distributed transaction to be tested fails the idempotence test when any of the branch transactions fails the idempotence test.
9. A computer device, characterized in that: include: A memory, a processor, and a computer program stored in the memory and executable on the processor, wherein when the processor executes the computer program, the idempotence detection method for distributed transactions as described in any one of claims 1 to 4 is implemented.
10. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores instructions, and when the instructions are executed on a terminal device, the terminal device executes the idempotence detection method for distributed transactions as described in any one of claims 1 to 4.