Method, apparatus, device and computer-readable medium for achieving data consistency
By adding rollback annotation information in the distributed system and using SpringAop aspects to perform data rollback, the complex problem of data consistency integration in the distributed system is solved, and simplified development and efficient data consistency processing are achieved.
Patent Information
- Application Number
- CN202410167993.5
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-02-06
- Publication Date
- 2025-09-26
- Estimated Expiration
- 2044-02-06
AI Technical Summary
When implementing data consistency in a distributed system, existing technologies have problems such as complex integration, difficulty in understanding, and high maintenance costs, especially for simple business systems.
By adding target rollback annotation information to the target business processing method of the business system, detecting remote call events, and using SpringAop aspects combined with remote call records to perform data rollback, the consistency of business data in multiple external systems is ensured.
It achieves business data consistency between distributed systems, simplifies the development and integration process, reduces maintenance costs, and is suitable for the rapid implementation of simple business systems.
Smart Images

Figure CN117992546B_ABST
Abstract
Description
Technical Field
[0001] The present application belongs to the field of distributed system application technology, and in particular relates to a method, apparatus, device, and computer-readable medium for achieving data consistency. Background Art
[0002] Currently, in distributed systems, to meet business needs, scenarios often occur where a business system calls multiple external systems. This business need is met through collaboration between systems. In these application scenarios, if a call to an external system fails, the system that has been called to perform related processing needs to be able to roll back correctly, thereby ensuring business data consistency between multiple systems.
[0003] Data consistency solutions based on known technologies ensure data consistency by integrating and using third-party heavyweight components, such as Seata. Seata is an open-source distributed transaction solution dedicated to providing high-performance distributed transaction services within a microservices architecture. Seata primarily achieves data consistency in distributed systems by leveraging transaction resources (such as databases and messaging services) that support the XA (Extended Architecture) protocol and using the XA protocol mechanism to manage branch transactions.
[0004] However, the operation process of integrating Seata is rather cumbersome, and its principles are difficult to understand, resulting in complex development and maintenance, and high maintenance costs. For simple business systems, its implementation is poor. Therefore, providing a simple, fast-integrated, and highly implementable data consistency solution has become a technical problem that urgently needs to be solved in this field. Summary of the Invention
[0005] In view of this, the present application discloses a method, apparatus, device and computer-readable medium for achieving data consistency, which are used to ensure that the solution is simple to implement, fast to integrate and highly feasible while solving the data consistency problem of distributed systems.
[0006] The specific plan is as follows:
[0007] A method for achieving data consistency, comprising:
[0008] In response to a target business processing method of the business system requiring a rollback operation, target rollback annotation information is added to the target business processing method; the target rollback annotation information is used to indicate that data rollback is required if a call failure event to an external system occurs during the execution of the target business processing method;
[0009] Based on the target rollback annotation information, detecting remote call events of the business system to multiple external systems during the process of processing the business request through the target business processing method;
[0010] Record information for each remote call event to obtain a remote call record;
[0011] In response to a call failure event to an external system, performing data rollback matching the call failure event on corresponding systems among the multiple external systems based on the target rollback annotation information, the remote call record, and the target aspect corresponding to the target business processing method, so as to make the business data of the business system and the multiple external systems consistent;
[0012] The target aspect includes a first execution content that needs to be executed to implement the data rollback required by the target business processing method.
[0013] Optionally, the detecting, based on the target rollback annotation information, remote call events of the business system to multiple external systems during the process of the business system processing a business request through the target business processing method includes:
[0014] By intercepting the method carrying the rollback annotation information, the target business processing method executed by the business system is intercepted, and the target rollback annotation information carried by the target business processing method is saved;
[0015] In response to intercepting the target business processing method, remote call events of the business system to multiple external systems are detected during the process of processing the business request through the target business processing method.
[0016] Optionally, the target rollback annotation information includes: rollback content required for the target business processing method in the event of a call failure to the corresponding external system;
[0017] The saving of the target rollback annotation information carried by the target business processing method includes:
[0018] At least the rollback content in the target rollback annotation information is saved to a storage space corresponding to the local thread.
[0019] Optionally, recording information for each remote call event includes:
[0020] The second execution content involved in each remote call event is recorded and saved to the storage space corresponding to the local thread copy; the second execution content includes at least part of the information on the class, method, parameter information used in the method, and call status of whether the call is successful executed by the remote call event.
[0021] Optionally, the first execution content includes: in the event of a call failure to the corresponding external system, the target business processing method corresponding to the required rollback content implements the classes and methods required for data rollback;
[0022] The step of performing data rollback matching the call failure event on a corresponding system among the multiple external systems according to the target rollback annotation information, the remote call record, and the target aspect corresponding to the target business processing method includes:
[0023] Determining, based on the remote call record, a target external system to which the call failed;
[0024] Determining, based on the target rollback annotation information, target rollback content required for the target business processing method when a call to the target external system fails;
[0025] The target class required for data rollback of the target rollback content and the target method required in the target class are obtained from the first execution content of the target aspect, and data rollback matching the call failure event is performed on corresponding systems in the multiple external systems based on the target method in the target class.
[0026] Optionally, performing data rollback on corresponding systems among the multiple external systems that matches the call failure event based on the target method in the target class includes:
[0027] Extracting parameter information required for executing the target method from the remote call record;
[0028] Parameter information required by the target method and the program code of the target method are assembled into corresponding executable codes, and data rollback matching the call failure event is performed on corresponding systems among the multiple external systems by executing the executable codes.
[0029] Optionally, the target aspect is a SpringAop aspect.
[0030] A device for achieving data consistency, comprising:
[0031] An annotation adding unit is used to add target rollback annotation information to the target business processing method in response to the target business processing method of the business system needing to perform a rollback operation; the target rollback annotation information is used to indicate that data rollback is required if a call failure event to an external system occurs during the execution of the target business processing method;
[0032] A detection unit, configured to detect, based on the target rollback annotation information, remote call events of the business system to multiple external systems during the process of the business system processing a business request through the target business processing method;
[0033] A recording unit, used to record information of each remote call event to obtain a remote call record;
[0034] a rollback unit configured to, in response to a call failure event to an external system, perform a data rollback on a corresponding system among the multiple external systems that matches the call failure event based on the target rollback annotation information, the remote call record, and the target aspect corresponding to the target business processing method, so as to make the business data of the business system and the multiple external systems consistent;
[0035] The target aspect includes a first execution content that needs to be executed to implement the data rollback required by the target business processing method.
[0036] An electronic device, comprising:
[0037] a memory for storing at least one set of computer instructions;
[0038] A processor is configured to implement the method for achieving data consistency as described in any one of the above items by executing the instruction set stored in the memory.
[0039] A computer-readable medium stores a computer instruction set, which, when executed by a processor, is used to implement the method for achieving data consistency as described in any one of the above.
[0040] In summary, the present application provides a method, apparatus, device and computer-readable medium for achieving data consistency, wherein the method includes: in response to the target business processing method of the business system needing to perform a rollback action, adding target rollback annotation information to the target business processing method; based on the target rollback annotation information, detecting remote call events of the business system to multiple external systems in the process of processing the business request through the target business processing method; recording information for each remote call event to obtain a remote call record; in response to a call failure event of the external system, according to the target rollback annotation information, the remote call record and the target aspect corresponding to the target business processing method, performing data rollback matching the call failure event on the corresponding system in the multiple external systems to make the business data between the business system and the multiple external systems consistent; wherein, the target aspect includes the corresponding first execution content required for the data rollback of the target business processing method.
[0041] This application adds rollback annotation information to the target business processing method that needs to perform rollback operations, detects remote call events to external systems based on the rollback annotation information, and records remote calls. If an external system call fails, data is rolled back using aspects such as SpringAop aspects combined with rollback annotation information and remote call records, thereby achieving business data consistency between distributed systems. Compared with the heavyweight components of known technologies, the above method provided by this application is simple to implement, and developers can quickly integrate and implement it into the business system. Data consistency processing can be achieved without adding third-party heavyweight components. Therefore, this application not only solves the data consistency problem of distributed systems, but also has technical effects such as simple implementation, fast integration, and high implementation. BRIEF DESCRIPTION OF THE DRAWINGS
[0042] The above and other features, advantages, and aspects of the various embodiments of the present application will become more apparent with reference to the following detailed description in conjunction with the accompanying drawings. Throughout the drawings, the same or similar reference numerals represent the same or similar elements. It should be understood that the drawings are schematic and that the originals and elements are not necessarily drawn to scale.
[0043] Figure 1 This is a flow chart of the method for achieving data consistency provided by this application;
[0044] Figure 2 This is a flowchart of a process for achieving data consistency in an application example provided by this application;
[0045] Figure 3 This is a structural diagram of the device for achieving data consistency provided by this application;
[0046] Figure 4 This is a structural diagram of the electronic device provided in this application. DETAILED DESCRIPTION
[0047] The following describes embodiments of the present application in more detail with reference to the accompanying drawings. Although certain embodiments of the present application are shown in the accompanying drawings, it should be understood that the present application can be implemented in various forms and should not be construed as limited to the embodiments described herein. Instead, these embodiments are provided to provide a more thorough and complete understanding of the present application. It should be understood that the drawings and embodiments of the present application are for illustrative purposes only and are not intended to limit the scope of protection of the present application.
[0048] As used herein, the term "including" and its variations are open-ended, i.e., "including but not limited to." The term "based on" means "based, at least in part, on." The term "one embodiment" means "at least one embodiment," the term "another embodiment" means "at least one additional embodiment," and the term "some embodiments" means "at least some embodiments." Other terms are defined in the following description.
[0049] It should be noted that the concepts of "first" and "second" mentioned in this application are only used to distinguish different devices, modules or units, and are not used to limit the order or interdependence of the functions performed by these devices, modules or units.
[0050] It should be noted that the modifications of "one" and "multiple" mentioned in this application are illustrative rather than restrictive. Those skilled in the art should understand that unless otherwise clearly indicated in the context, they should be understood as "one or more".
[0051] The present invention provides a method, apparatus, device and computer-readable medium for achieving data consistency. Figure 1 The method for achieving data consistency disclosed in the present application includes the following steps:
[0052] Step 101: In response to the target business processing method of the business system needing to perform a rollback operation, target rollback annotation information is added to the target business processing method; the target rollback annotation information is used to indicate that if a call failure event to an external system occurs during the execution of the target business processing method, data rollback is required.
[0053] In an embodiment of the present application, the target business processing method needs to perform a rollback operation. Specifically, when the target business processing method fails to call an external system (other business systems outside the business system to which the target business processing method belongs), data rollback is required.
[0054] Optionally, whether the target business processing method needs to perform a rollback operation can be determined by determining whether the target business processing method needs to execute multiple external system calls during operation. If the target business processing method needs to execute multiple external system calls during operation, it can be determined that the target business processing method needs to perform a rollback operation; otherwise, it can be determined that the target business processing method does not need to perform a rollback operation.
[0055] In the case where the target business processing method needs to perform a rollback operation, the embodiment of the present application adds target rollback annotation information to the target business processing method before calling the target business processing method to process the business request. Optionally, before the business system processes the business request, the target rollback annotation information can be added to the target business processing method of the business system that needs to perform a rollback operation in advance through preprocessing. Alternatively, when the business system obtains a business request and determines that the target business processing method corresponding to the business request needs to perform a rollback operation, the corresponding target rollback annotation information can be added to the target business processing method in real time. There is no restriction on this, as long as the target rollback annotation information of the target business processing method is added before calling the target business processing method to process the business request.
[0056] Among them, adding target rollback annotation information to the target business processing method may specifically refer to adding target rollback annotation information to the relevant implementation code (such as function code) of the target business processing method. The added target rollback annotation information may include but is not limited to the required rollback content corresponding to the target business processing method in the event of a call failure to the corresponding external system.
[0057] The target business processing method corresponds to the required rollback content, which may further include but is not limited to at least part of the following information: the class that needs to be rolled back for the corresponding external system call of the target business processing method, the method that needs to be rolled back in the class that needs to be rolled back, the parameters that need to be rolled back in the method that needs to be rolled back, and other information.
[0058] Taking the business request as an order processing request and the business system as an order system as an example, the target business processing method can correspondingly be an order processing method. Assume that the processing logic of the order processing method is: for the (customer) paid order indicated by the order processing request, the order system calls the points system to assign a certain value of points to the customer through point accumulation processing, and calls the warehousing system to adjust the status of the order to the goods outbound status through notification status processing to carry out goods outbound. That is to say, in the process of processing the business request through the target business processing method, the business system (order system) needs to call multiple external systems including the points system and the warehousing system. When assigning certain points to the customer by calling the points system, it is necessary to ensure that the notification status in the warehousing system is the shipping status so that normal shipment can be carried out. If any of the two processes fails, that is, the call to any external system in the points system and the warehousing system fails, the other external system that has been successfully called and thus executed the corresponding processing should perform data rollback to ensure the consistency of business data between different systems. The target rollback annotation information added to the target business processing method may include: a. In the event that the call to the points system fails, the notification status processing method of the warehousing system and the notification status parameters involved (i.e., the rollback content) need to be rolled back; b. In the event that the call to the warehousing system fails, the points accumulation method of the points system and the accumulation quantity parameters involved (i.e., the rollback content) need to be rolled back.
[0059] Step 102: Based on the target rollback annotation information, detect remote call events of the business system to multiple external systems during the process of processing the business request through the target business processing method.
[0060] Specifically, the method carrying the rollback annotation information can be intercepted to intercept the target business processing method executed by the business system, and the target rollback annotation information carried by the target business processing method can be saved; on this basis, in response to intercepting the target business processing method, the remote call events of the business system to multiple external systems in the process of processing the business request through the business processing method are detected.
[0061] When saving the target rollback annotation information carried by the target business processing method, optionally, at least the rollback content in the target rollback annotation information can be saved to the storage space corresponding to the local thread. The local thread is a local thread used to execute the method for achieving data consistency provided by this application.
[0062] Step 103: Record information for each remote call event to obtain a remote call record.
[0063] Optionally, the second execution content involved in each remote call event can be saved to the storage space corresponding to the local thread copy; the second execution content includes the class and method executed by the remote call event, parameter information used in the method (such as the notification status, the accumulated points value granted to the customer this time, etc.) and at least part of the call status of whether the call is successful.
[0064] Step 104: In response to a call failure event to an external system, data rollback matching the call failure event is performed on corresponding systems in the multiple external systems based on the target rollback annotation information, the remote call record, and the target aspect corresponding to the target business processing method, so as to make the business data between the business system and the multiple external systems consistent.
[0065] Among them, the target aspect includes the first execution content that needs to be executed to implement the data rollback required by the target business processing method.
[0066] In the embodiment of the present application, the aspect used is the target aspect, specifically the SpringAop aspect.
[0067] Optionally, the first execution content may include, but is not limited to, the classes and methods required to implement data rollback for the target business processing method corresponding to the required rollback content in the event of a call failure to the corresponding external system. For example, with respect to the above example, the first execution content may include: the classes and methods required to implement data rollback for the notification status of the warehousing system in the event of a call failure to the points system, and the classes and methods required to implement data rollback for the points accumulation processing of the points system in the event of a call failure to the warehousing system.
[0068] In step 104, in response to a call failure event of an external system, data rollback matching the call failure event can be performed on a corresponding system among the multiple external systems through the following processing:
[0069] 11) Determine the target external system where the call failed based on the remote call record.
[0070] 12) Determine, based on the target rollback annotation information, target rollback content required for the target business processing method in the event that a call to the target external system fails.
[0071] 13) Obtain the target class required for data rollback of the target rollback content and the target method required in the target class from the first execution content of the target aspect, and perform data rollback matching the call failure event on the corresponding systems in the multiple external systems based on the target method in the target class.
[0072] Among them, when executing data rollback matching the call failure event on the corresponding system in the multiple external systems based on the target method in the target class, the parameter information required for executing the target method can be extracted from the remote call record, and the parameter information required for the target method and the program code of the target method can be assembled into a corresponding executable code. By executing the executable code, the data rollback matching the call failure event can be achieved on the corresponding system in the multiple external systems.
[0073] Continuing with the above example, assume that based on the remote call record, it is determined that the target external system where the call failed is the warehousing system. That is, for the (customer) paid order indicated by the order processing request, the order system calls the warehousing system to adjust the notification status from the waiting status (non-shipping status) to the shipping status and fails. In this case, based on the target rollback annotation information of the order processing method, it can be determined that when the warehousing system call fails, the required target rollback content is the points accumulation method and the accumulation quantity parameters involved. On this basis, the target class required to roll back the target rollback content and the target method required in the target class, such as the required points deduction method and the class to which it belongs, can be further obtained from the target aspect corresponding to the order processing method. The cumulative quantity value involved in the points accumulation method can be extracted from the remote call record, and the extracted cumulative quantity value can be used as the points deduction value in the points deduction method and the relevant implementation code (computer program code) of the points deduction method and its corresponding class can be encapsulated into executable code. Then, by running the executable code, the data rollback of the points system that matches the call failure event can be realized, and the consistency between the customer points and the notification status of the warehousing system (the warehousing system call failed, so the notification status corresponding to the order is still in the waiting state, not the outbound state) can be maintained.
[0074] In summary, this application adds rollback annotation information to the target business processing method that needs to perform rollback operations, detects remote call events to external systems based on the rollback annotation information, and records remote calls. If an external system call fails, data is rolled back using aspects such as SpringAop aspects combined with rollback annotation information and remote call records, thereby achieving business data consistency between distributed systems. Compared with the heavyweight components of known technologies, the above method provided by this application is simple to implement, and developers can quickly integrate and implement it into the business system. Data consistency processing can be achieved without adding third-party heavyweight components. Therefore, this application not only solves the data consistency problem of distributed systems, but also has technical effects such as simple implementation, fast integration, and high landing.
[0075] An application example of the method for achieving data consistency of the present application is provided below.
[0076] This example provides a system for achieving data consistency. The system mainly includes the following three modules: SpringAop execution method interception module, local thread copy record execution method module, and RPC call rollback module.
[0077] Among them, before the business processing method of the business system is called, the method is marked based on the rollback annotation information whether it needs to perform data rollback (such as data rollback in the event of an external system call failure). If rollback is required, when a remote call is made within the business system, the name of the implementation class and method required for the rollback of the current method can be indicated on the interface of the corresponding remote call (as a section). When making a remote call, the SpringAop execution method interception module in the system intercepts the method with the rollback annotation information added, and the local thread copy record execution method module automatically records the remote call content executed by the intercepted method to form a remote call record. When a remote call fails, the rpc call rollback module rolls back the remote call that has been successfully executed according to the corresponding class and method that implements the rollback.
[0078] An example of achieving data consistency is as follows Figure 2 As shown, the specific processing flow includes the following:
[0079] 1. Business system X obtains the user's business request;
[0080] 1.1. In response to the need to perform a rollback operation on the target business processing method corresponding to the business request, add rollback annotation information to the target business processing method and execute the target business processing method with the annotation;
[0081] 1.1.1-1.1.3, Business system X makes remote RPC (Remote Procedure Call) calls to external systems A, B, and C;
[0082] 1.1.4. Monitor each RPC remote call, record and encapsulate the corresponding remote call records;
[0083] 1.2. In response to detecting a failure in an RPC remote call to an external system, execute the corresponding RPC call rollback to ensure consistency of business data in each system;
[0084] 1.2.1-1.2.3, RPC call rollback.
[0085] Corresponding to the above-mentioned method for achieving data consistency, the embodiment of the present application also provides a device for achieving data consistency, the composition structure of which is as follows: Figure 3 As shown, including:
[0086] An annotation adding unit 301 is configured to add target rollback annotation information to a target business processing method of a business system in response to the target business processing method requiring a rollback operation; the target rollback annotation information is used to indicate that a data rollback is required if a call failure to an external system occurs during the execution of the target business processing method;
[0087] A detection unit 302 is configured to detect, based on the target rollback annotation information, remote call events of the business system to multiple external systems during the process of the business system processing a business request through the target business processing method;
[0088] The recording unit 303 is used to record information of each remote call event to obtain a remote call record;
[0089] A rollback unit 304 is configured to, in response to a call failure event to an external system, perform a data rollback on a corresponding system among the multiple external systems that matches the call failure event based on the target rollback annotation information, the remote call record, and the target aspect corresponding to the target business processing method, so as to make the business data of the business system and the multiple external systems consistent;
[0090] The target aspect includes a first execution content that needs to be executed to implement the data rollback required by the target business processing method.
[0091] In an optional embodiment, the above device further includes a storage processing unit;
[0092] The detection unit 302 is specifically configured to:
[0093] By intercepting the method carrying the rollback annotation information, the target business processing method executed by the business system is intercepted, and the storage processing unit is triggered to save the target rollback annotation information carried by the target business processing method;
[0094] In response to intercepting the target business processing method, remote call events of the business system to multiple external systems are detected during the process of processing the business request through the target business processing method.
[0095] In an optional implementation, the target rollback annotation information includes: rollback content required for the target business processing method in the event of a call failure to the corresponding external system;
[0096] When saving the target rollback annotation information carried by the target business processing method, the storage processing unit is specifically configured to: save at least the rollback content in the target rollback annotation information to a storage space corresponding to a local thread.
[0097] In an optional implementation manner, the recording unit 303 is specifically configured to:
[0098] The second execution content involved in each remote call event is recorded and saved to the storage space corresponding to the local thread copy; the second execution content includes at least part of the information on the class, method, parameter information used in the method, and call status of whether the call is successful executed by the remote call event.
[0099] In an optional embodiment, the first execution content includes: in the event of a call failure to the corresponding external system, the target business processing method corresponding to the required rollback content implements the classes and methods required for data rollback;
[0100] The rollback unit 304 is specifically configured to:
[0101] Determining, based on the remote call record, a target external system to which the call failed;
[0102] Determining, based on the target rollback annotation information, target rollback content required for the target business processing method when a call to the target external system fails;
[0103] The target class required for data rollback of the target rollback content and the target method required in the target class are obtained from the first execution content of the target aspect, and data rollback matching the call failure event is performed on corresponding systems in the multiple external systems based on the target method in the target class.
[0104] In an optional implementation, the rollback unit 304, when performing data rollback on a corresponding system among the multiple external systems matching the call failure event based on the target method in the target class, is specifically configured to:
[0105] Extracting parameter information required for executing the target method from the remote call record;
[0106] Parameter information required by the target method and the program code of the target method are assembled into corresponding executable codes, and data rollback matching the call failure event is performed on corresponding systems among the multiple external systems by executing the executable codes.
[0107] In an optional implementation, the target aspect is a SpringAop aspect.
[0108] As for the device for achieving data consistency provided in the embodiment of the present application, since it corresponds to the method for achieving data consistency provided in the above method embodiment, the description is relatively simple. For relevant similarities, please refer to the description of the above method embodiment, and no further details will be given here.
[0109] The present application also provides an electronic device, the composition structure of the electronic device is as follows: Figure 4 As shown, including at least:
[0110] Memory 10, for storing a computer instruction set;
[0111] A set of computer instructions can be implemented in the form of a computer program.
[0112] The processor 20 is configured to implement the method for achieving data consistency as disclosed in any of the above method embodiments by executing a computer instruction set.
[0113] The processor 20 may be a central processing unit (CPU), an application-specific integrated circuit (ASIC), a digital signal processor (DSP), an application-specific integrated circuit (ASIC), a field programmable gate array (FPGA), or other programmable logic devices.
[0114] The electronic device includes a display device and / or a display interface and can be connected to an external display device.
[0115] Optionally, the electronic device further includes a camera assembly, and / or is connected to an external camera assembly.
[0116] In addition, the electronic device may also include components such as a communication interface and a communication bus. The memory, processor, and communication interface communicate with each other via the communication bus.
[0117] Communication interfaces are used for communication between electronic devices and other devices. The communication bus can be a Peripheral Component Interconnect (PCI) bus or an Extended Industry Standard Architecture (EISA) bus. This communication bus can be divided into an address bus, a data bus, and a control bus.
[0118] In addition, the present application also provides a computer-readable medium having a computer instruction set stored thereon, which, when executed by a processor, is used to implement the method for achieving data consistency as disclosed in any of the method embodiments above.
[0119] The computer instruction set may be in the form of a computer program, which includes program codes for executing the method for achieving data consistency as provided in any of the above method embodiments.
[0120] In the context of the present application, a computer-readable medium (machine-readable medium) can be a tangible medium that can contain or store a program for use by or in conjunction with an instruction execution system, device or equipment. A machine-readable medium can be a machine-readable signal medium or a machine-readable storage medium. A machine-readable medium can include, but is not limited to, an electronic, magnetic, optical, electromagnetic, infrared, or semiconductor system, device or equipment, or any suitable combination of the foregoing. A more specific example of a machine-readable storage medium can include an electrical connection based on one or more lines, 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 foregoing.
[0121] It should be noted that the computer-readable medium mentioned above in this application can be a computer-readable signal medium or a computer-readable storage medium, or any combination of the two. The computer-readable storage medium can be, for example, but not limited to, an electrical, magnetic, optical, electromagnetic, infrared, or semiconductor system, device, or device, or any combination of the above. More specific examples of computer-readable storage media can include, but are not limited to: 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 this application, a computer-readable storage medium can be any tangible medium that contains or stores a program that can be used by or in conjunction with an instruction execution system, device, or device. In this application, a computer-readable signal medium can include a data signal propagated in baseband or as part of a carrier wave, which carries computer-readable program code. This propagated data signal can take a variety of forms, including but not limited to electromagnetic signals, optical signals, or any suitable combination of the above. A computer-readable signal medium may also be any computer-readable medium other than a computer-readable storage medium that can transmit, propagate, or transport a program for use by or in conjunction with an instruction execution system, apparatus, or device. The program code contained on the computer-readable medium may be transmitted using any suitable medium, including but not limited to wires, optical cables, RF (radio frequency), etc., or any suitable combination thereof.
[0122] The computer-readable medium may be included in the electronic device, or may exist independently without being incorporated into the electronic device.
[0123] In summary, the method, apparatus, device, and computer-readable medium for achieving data consistency provided by this application have at least the following technical advantages:
[0124] 1. Integrability: Business systems only need to focus on the business objectives to be executed and the targets to be rolled back in case of failure. The processing logic of this application method is simple to integrate with business systems and has strong implementation for business systems, especially simple business systems.
[0125] 2. Business decoupling: During implementation, for this application, it is possible to develop an implementation logic without writing a bunch of exception handling in the business code, and the exception handling can be handed over to the framework outside the business system.
[0126] 3. Data consistency: This application avoids the risk of data inconsistency to a large extent in simple business.
[0127] It should be noted that although the subject matter has been described in language specific to structural features and / or methodological logical actions, it should be understood that the subject matter defined in the appended claims is not necessarily limited to the specific features or actions described above. On the contrary, the specific features and actions described above are merely example forms of implementing the claims.
[0128] Although several specific implementation details are included in the above discussion, these should not be construed as limiting the scope of this application. Certain features described in the context of separate embodiments may also be implemented in combination in a single embodiment. Conversely, various features described in the context of a single embodiment may also be implemented in multiple embodiments individually or in any suitable sub-combination.
[0129] The above description is merely a preferred embodiment of the present application and an illustration of the technical principles employed. Those skilled in the art should understand that the scope of application involved in this application is not limited to the technical solutions formed by a specific combination of the above-mentioned technical features, but also encompasses other technical solutions formed by any combination of the above-mentioned technical features or their equivalents without departing from the above-mentioned application concept. For example, a technical solution formed by replacing the above-mentioned features with (but not limited to) technical features with similar functions applied for in this application.
Claims
1. A method for achieving data consistency, characterized in that: include: In response to a target business processing method of the business system needing to perform a rollback action, adding target rollback annotation information to relevant implementation code of the target business processing method; The target rollback annotation information is used to indicate that if a call failure to an external system occurs during the execution of the target business processing method, data rollback is required; The target rollback annotation information includes: the rollback content required for the target business processing method in the event of a call failure to the corresponding external system; By intercepting a method carrying rollback annotation information, the target business processing method executed by the business system is intercepted, and at least the rollback content in the target rollback annotation information is saved to the storage space corresponding to the local thread; in response to intercepting the target business processing method, remote call events of the business system to multiple external systems are detected during the process of processing a business request through the target business processing method; Recording and saving the second execution content involved in each remote call event to the storage space corresponding to the local thread copy; the second execution content includes at least part of the information of the class and method executed by the remote call event, parameter information used in the method, and the call status of whether the call is successful; In response to a call failure event to an external system, performing a data rollback matching the call failure event on corresponding systems among the multiple external systems based on the target rollback annotation information, the remote call record, and the target aspect corresponding to the target business processing method, so as to make the business data of the business system and the multiple external systems consistent; The target aspect includes a first execution content that needs to be executed to implement the data rollback required by the target business processing method.
2. The method for achieving data consistency according to claim 1, wherein: The first execution content includes: in the event of a call failure to the corresponding external system, the target business processing method corresponding to the required rollback content implements the classes and methods required for data rollback; The step of performing data rollback matching the call failure event on a corresponding system among the multiple external systems according to the target rollback annotation information, the remote call record, and the target aspect corresponding to the target business processing method includes: Determining, based on the remote call record, a target external system to which the call failed; Determining, based on the target rollback annotation information, target rollback content required for the target business processing method when a call to the target external system fails; The target class required for data rollback of the target rollback content and the target method required in the target class are obtained from the first execution content of the target aspect, and data rollback matching the call failure event is performed on corresponding systems in the multiple external systems based on the target method in the target class.
3. The method for achieving data consistency according to claim 2, wherein: The performing data rollback on a corresponding system among the multiple external systems that matches the call failure event based on the target method in the target class includes: Extracting parameter information required for executing the target method from the remote call record; Parameter information required by the target method and the program code of the target method are assembled into corresponding executable codes, and data rollback matching the call failure event is performed on corresponding systems among the multiple external systems by executing the executable codes.
4. The method for achieving data consistency according to claim 1, wherein: The target aspect is the SpringAop aspect.
5. A device for achieving data consistency, characterized in that: include: An annotation adding unit, configured to add target rollback annotation information to relevant implementation codes of a target business processing method in response to a target business processing method of the business system needing to perform a rollback action; The target rollback annotation information is used to indicate that if a call failure to an external system occurs during the execution of the target business processing method, data rollback is required; The target rollback annotation information includes: the rollback content required for the target business processing method in the event of a call failure to the corresponding external system; a detection unit configured to intercept the target business processing method executed by the business system by intercepting a method carrying rollback annotation information, and save at least the rollback content in the target rollback annotation information to a storage space corresponding to a local thread; in response to intercepting the target business processing method, detect remote call events of the business system to multiple external systems during the process of processing a business request through the target business processing method; a recording unit, configured to record and save a second execution content related to each remote call event to a storage space corresponding to the local thread copy; the second execution content including at least part of information about the class and method executed by the remote call event, parameter information used in the method, and a call status indicating whether the call was successful; a rollback unit configured to, in response to a call failure event to an external system, perform a data rollback on a corresponding system among the multiple external systems that matches the call failure event based on the target rollback annotation information, the remote call record, and the target aspect corresponding to the target business processing method, so as to make the business data of the business system and the multiple external systems consistent; The target aspect includes a first execution content that needs to be executed to implement the data rollback required by the target business processing method.
6. An electronic device, characterized in that: include: a memory for storing at least one set of computer instructions; A processor, configured to implement the method for achieving data consistency according to any one of claims 1 to 4 by executing the instruction set stored in the memory.
7. A computer-readable medium, characterized in that A computer instruction set is stored thereon, and when the computer instruction set is executed by a processor, it is used to implement the method for achieving data consistency according to any one of claims 1 to 4.
Citation Information
Patent Citations
Distributed transaction processing method and device, computer equipment and readable storage medium
CN111722946A
Multi-data-source transaction management method, system and device and medium
CN116244043A