A double-write technology method and system based on transaction id

The transaction ID-based dual-write technology method and system addresses the high cost and data inconsistency issues in cross-IDC replication by ensuring successful local and remote writes, thereby maintaining data consistency and reducing operational costs.

CN114048268BActive Publication Date: 2024-12-27BAIRONG FINANCIAL INFORMATION SERVICE CO LTD
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202111397471.7
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2021-11-23
Publication Date
2024-12-27
Estimated Expiration
2041-11-23

AI Technical Summary

Technical Problem

Existing solutions for cross-IDC data replication in rediscluster are costly and fail to ensure data consistency across different Internet Data Centers (IDCs).

Method used

A transaction ID-based dual-write technology method and system that involves obtaining client request parameters, parsing them through an API encapsulation client redis component, performing local and remote redis writes with transaction operation identifiers, and ensuring successful execution before deleting the identifiers to maintain data consistency.

Benefits of technology

Provides a low-cost dual-write solution that ensures data consistency across IDCs, avoiding data inconsistency and achieving higher synchronization efficiency with lower latency.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN114048268B_ABST
    Figure CN114048268B_ABST
Patent Text Reader

Abstract

The present invention discloses a double-write technical method and system based on transaction ID, which parses the first client request parameter through the API encapsulation client redis component to obtain the first transaction operation identifier OID; writes the first transaction operation identifier OID to the local redis queue through the local redis cluster client, and returns execution failure if the write fails; when the write succeeds, writes the redis command of the first parsing result through the local redis cluster client, and when the first write result is executed successfully, writes the redis command of the first parsing result through the remote redis cluster client, and when the second write result is executed successfully, deletes the first transaction operation identifier OID of the local redis cluster client, and returns execution success. The technical problem that the solution cost is too high and the data consistency across IDCs cannot be guaranteed in the prior art is solved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of recording carrier processing, and in particular to a transaction ID-based double-write technology method and system. Background Art

[0002] Internet Data Center, referred to as IDC, is a place where telecommunications departments provide hosting for enterprises, merchants or website servers. With the development of Internet technology, especially the in-depth application of financial technology, more and more financial technology companies, especially Internet financial technology companies, have put forward more stringent requirements for data security and service stability. In order to improve the enterprise application experience, cache technologies represented by rediscluster are widely used and practiced in major software architectures. With the demand for cross-IDC deployment, rediscluster's active-active technology in the same city is also valued by more and more enterprises. Some Internet companies customize the implementation of redis log replication technology. Most of these solutions are very complex to implement and have high requirements for the redis version. However, rediscluster is currently used more in most enterprises with version 3.x, while versions 4.x and above are rarely put into production. Version changes have a greater impact on the solution.

[0003] However, the inventors of this application found that the above technology has at least the following technical problems in the process of implementing the technical solution of the invention in the embodiment of this application:

[0004] The existing technology has the problem that the solution cost is too high and the data consistency across IDCs cannot be guaranteed. Summary of the invention

[0005] The embodiment of the present application provides a transaction id-based dual-write technical method and system to solve the technical problems in the prior art that the solution cost is too high and the data consistency across IDCs cannot be guaranteed, thereby achieving the technical effect of providing a low-cost dual-write solution and ensuring the data consistency across IDCs while controlling the cost.

[0006] In view of the above problems, an embodiment of the present application provides a double-write technology method and system based on transaction ID.

[0007] In the first aspect, the present application provides a double-write technical method based on transaction ID, wherein the method includes: obtaining a first client request parameter; parsing the first client request parameter through an API encapsulation client redis component to obtain a first parsing result; obtaining a first transaction operation identifier OID according to the first parsing result; performing a local redis write of the first transaction operation identifier OID through a local redis cluster client, and when the write fails, returning an execution failure; when the write succeeds, performing a redis command write of the first parsing result through the local redis cluster client to obtain a first write result; judging whether the first write result is executed successfully, and when the first write result is executed successfully, performing a redis command write of the first parsing result through a remote redis cluster client to obtain a second write result; judging whether the second write result is executed successfully, and when the second write result is executed successfully, deleting the first transaction operation identifier OID of the local redis cluster client, and returning an execution success.

[0008] On the other hand, the present application also provides a transaction ID-based dual-write technology system, the system comprising: a first obtaining unit, the first obtaining unit is used to obtain a first client request parameter; a second obtaining unit, the second obtaining unit is used to parse the first client request parameter through an API encapsulation client redis component to obtain a first parsing result; a third obtaining unit, the third obtaining unit is used to obtain a first transaction operation identifier OID according to the first parsing result; a fourth obtaining unit, the fourth obtaining unit is used to perform a local redis write of the first transaction operation identifier OID through a local redis cluster client, and when the write fails, the execution failure is returned; when the write is successful, the redis command of the first parsing result is written through the local redis cluster client to obtain the first write result; a first judgment unit, the first judgment unit is used to judge whether the first write result is executed successfully, and when the first write result is executed successfully, the redis command of the first parsing result is written through a remote redis cluster client to obtain a second write result; a second judgment unit, the second judgment unit is used to judge whether the second write result is executed successfully, and when the second write result is executed successfully, the first transaction operation identifier OID of the local redis cluster client is deleted, and the execution success is returned.

[0009] In a third aspect, the present invention provides a double-write technology system based on transaction ID, comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor implements the steps of the method described in the first aspect when executing the program.

[0010] One or more technical solutions provided in the embodiments of the present application have at least the following technical effects or advantages:

[0011] The method adopts the following steps: obtaining the first client request parameter; parsing the first client request parameter through the API encapsulation client redis component to obtain the first parsing result; obtaining the first transaction operation identifier oid according to the first parsing result; performing the local redis write of the first transaction operation identifier oid through the local redis cluster client, and returning execution failure when the write fails; when the write succeeds, performing the redis command write of the first parsing result through the local redis cluster client to obtain the first write result; judging whether the first write result is executed successfully, and when the first write result is executed successfully, performing the redis command write of the first parsing result through the remote redis cluster client to obtain the second write result; judging whether the second write result is executed successfully, and when the second write result is executed successfully, deleting the first transaction operation identifier oid of the local redis cluster client, and returning execution success. The method provides a low-cost dual-write solution, and ensures the data consistency across IDCs under the premise of controlling costs.

[0012] The above description is only an overview of the technical solution of the present application. In order to more clearly understand the technical means of the present application, it can be implemented in accordance with the contents of the specification. In order to make the above and other purposes, features and advantages of the present application more obvious and easy to understand, the specific implementation methods of the present application are listed below. BRIEF DESCRIPTION OF THE DRAWINGS

[0013] Figure 1 A flowchart of a double-write technology method based on transaction ID according to an embodiment of the present application;

[0014] Figure 2 A schematic diagram of a process of determining whether the first writing result is successfully executed in a dual writing technical method based on a transaction ID according to an embodiment of the present application;

[0015] Figure 3 A schematic diagram of a process of obtaining a first transaction operation identifier OID according to the first parsing result in a double-write technical method based on a transaction ID according to an embodiment of the present application;

[0016] Figure 4 A schematic diagram of a process of writing the first transaction operation identifier oid into a local redis queue through a local redis cluster client in a double-write technical method based on a transaction id according to an embodiment of the present application;

[0017] Figure 5A flowchart of a compensation method based on a transaction id double-write technology according to an embodiment of the present application;

[0018] Figure 6 A flowchart of further analysis of a transaction compensation method based on a transaction ID double-write technology according to an embodiment of the present application;

[0019] Figure 7 A schematic diagram of a flow chart of a double-write technical method based on a transaction ID according to an embodiment of the present application, for matching command types according to the second parsing result;

[0020] Figure 8 This is a structural diagram of a dual-write technology system based on transaction ID according to an embodiment of the present application;

[0021] Fig. 9 It is a schematic diagram of the structure of an exemplary electronic device according to an embodiment of the present application.

[0022] Explanation of the accompanying drawings: first obtaining unit 11, second obtaining unit 12, third obtaining unit 13, fourth obtaining unit 14, first judging unit 15, second judging unit 16, electronic device 50, processor 51, memory 52, input device 53, output device 54. DETAILED DESCRIPTION

[0023] The embodiment of the present application provides a transaction id-based dual-write technical method and system to solve the technical problem that the non-open source solution in the prior art is too expensive and cannot ensure data consistency across IDCs, thereby providing a low-cost dual-write solution to achieve the technical effect of ensuring data consistency across IDCs while controlling costs. The embodiments of the present application are described below in conjunction with the accompanying drawings. It is known to those skilled in the art that with the development of technology and the emergence of new scenarios, the technical solution provided in the embodiment of the present application is also applicable to similar technical problems.

[0024] The terms "first", "second", etc. in the specification and claims of the present application 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 terms used in this way can be interchanged under appropriate circumstances. This is merely a way of distinguishing objects with the same properties when describing the embodiments of the present application. In addition, the terms "including" and "having" and any variations thereof are intended to cover non-exclusive inclusions, so that a process, method, system, product, or device that includes a series of units is not necessarily limited to those units, but may include other units that are not explicitly listed or inherent to these processes, methods, products, or devices.

[0025] Application Overview

[0026] Internet Data Center, referred to as IDC, is a place where telecommunications departments provide hosting for enterprises, merchants or website servers. With the development of Internet technology, especially the in-depth application of financial technology, more and more financial technology companies, especially Internet financial technology companies, have put forward more stringent requirements for data security and service stability. In order to improve the enterprise application experience, cache technologies represented by rediscluster are widely used and practiced in major software architectures. With the demand for cross-IDC deployment, rediscluster's active-active technology in the same city is also valued by more and more enterprises. Some Internet companies customize the implementation of redis log replication technology. Most of these solutions are very complex to implement and have high requirements for the redis version. However, rediscluster is currently used more in most enterprises with version 3.x, while versions 4.x and above are rarely put into production. Version changes have a greater impact on the solution.

[0027] As the business scale grows, the business carrying capacity of a single computer room is limited, and multiple IDCs are needed to share the processing capacity. Failure in a single computer room will cause all business interruptions. Cross-IDC deployment can cope with various uncontrollable factors such as power outages in a single computer room and cable digging, ensuring service stability and business continuity. Compared with multi-site active-active, active-active in the same city has lower costs, more stable network quality, and relatively lower requirements for technical implementation. However, the solutions in the existing technology have technical problems such as high cost and inability to ensure data consistency across IDCs.

[0028] In response to the above technical problems, the overall idea of ​​the technical solution provided by this application is as follows:

[0029] An embodiment of the present application provides a double-write technical method based on transaction ID, wherein the method includes: obtaining a first client request parameter; parsing the first client request parameter through an API encapsulation client redis component to obtain a first parsing result; obtaining a first transaction operation identifier OID according to the first parsing result; writing the first transaction operation identifier OID to a local redis queue through a local redis cluster client to obtain a first write result; judging whether the first write result is executed successfully, and when the first write result is executed successfully, writing a redis command of the first parsing result through a remote redis cluster client to obtain a second write result; judging whether the second write result is executed successfully, and when the second write result is executed successfully, deleting the first transaction operation identifier OID of the local redis cluster client, and returning execution success.

[0030] After introducing the basic principles of the present application, various non-limiting implementation methods of the present application will be specifically described below in conjunction with the drawings in the specification.

[0031] Embodiment 1

[0032] like Figure 1 As shown, the embodiment of the present application provides a dual-write technical method based on transaction id, wherein the method includes:

[0033] Step S100: obtaining a first client request parameter;

[0034] Step S200: parsing the first client request parameter by encapsulating the client redis component through the API to obtain a first parsing result;

[0035] Specifically, the first client request parameter refers to the request information of the request cache or hosting of the enterprise side or the business side. The API encapsulation client redis component is a component for jedis client simulation, and jedis is a general client of the redis component java language. After obtaining the request parameters of the first client, the jedis client is performed through the API encapsulation client redis component to parse the first client request parameters. Generally speaking, the first client request parameters include: set, setEx, setNx, expireAt, del, hset, hdel commands. The process of parsing parameters is a parameter processing process, that is, the operations of each type of interface are converted into oid. OID includes two types of string and hash. Set, setEx, setNx, expireAt, del are string types, that is, string type is the first type of command, and its oid composition rule is: {uuid}_s_key. Hset and hdel correspond to hash types, and hash types are second type commands. Its oid composition rule is: {uuid}_h_keyfield, where key needs to be base64 encoded to avoid separation ambiguity.

[0036] Step S300: Obtain a first transaction operation identifier oid according to the first parsing result;

[0037] Step S400: write the first transaction operation identifier oid to local redis through the local redis cluster client, and when the write fails, return execution failure; when the write succeeds, write the first parsing result to redis command through the local redis cluster client to obtain a first write result;

[0038] Specifically, according to the first parsing result, a transaction operation identifier OID is generated based on the business namespace rule, that is, the first transaction operation identifier OID, and the first transaction operation identifier OID is written to the local redis queue corresponding to the business namespace through the local redis cluster client. When the write fails, the execution failure is returned. When the write succeeds, the redis command of the first parsing result is written through the local redis cluster client to obtain the first write result.

[0039] Step S500: determining whether the first writing result is executed successfully. When the first writing result is executed successfully, performing a redis command writing of the first parsing result through a remote redis cluster client to obtain a second writing result.

[0040] Furthermore, if Figure 2 As shown, the step S500 of determining whether the first writing result is executed successfully in the embodiment of the present application further includes:

[0041] Step S510: when the first writing result fails to be executed, obtaining a first deletion instruction;

[0042] Step S520: Delete the first transaction operation identifier oid according to the first deletion instruction, and return execution failure.

[0043] Specifically, the write result of the redis command writing the first parsing result on the local redis cluster client is judged, and when the write result is successful, the redis command writing of the first parsing result is performed through the remote redis cluster client to obtain the second write result. When the write result is an execution failure, a first deletion instruction is obtained at this time, and the first transaction operation identifier oid is deleted in the local redis cluster client according to the first deletion instruction, and regardless of whether the deletion is successful, the execution result of the execution failure is fed back.

[0044] Step S600: Determine whether the second write result is executed successfully. When the second write result is executed successfully, delete the first transaction operation identifier oid of the local redis cluster client and return execution success.

[0045] Specifically, the remote redis command write of the first parsing result is performed through the remote redis cluster client to obtain the second write result, wherein the second write result includes two situations: write success and write failure. When the second write result is write success, the first transaction operation identifier oid of the local redis cluster client is deleted, and the execution result of successful execution is returned. When the second write result is write failure, the remote execution failure result is fed back, and transaction compensation is performed through the transaction compensator. A low-cost dual-write solution is provided to achieve the technical effect of ensuring data consistency across IDCs while controlling costs.

[0046] Furthermore, if Figure 3 As shown, the first transaction operation identifier oid is obtained according to the first parsing result, and step S300 of the embodiment of the present application further includes:

[0047] Step S310: Obtaining business namespace rules;

[0048] Step S320: Generate the first transaction operation identifier oid based on the business namespace rule according to the first parsing result.

[0049] Furthermore, if Figure 4 As shown, the local redis queue writing of the first transaction operation identifier oid is performed through the local redis cluster client, and step S400 of the embodiment of the present application also includes:

[0050] Step S410: Obtaining a first business namespace corresponding to the first parsing result according to the business namespace rule;

[0051] Step S420: Obtain the local redis queue according to the first business namespace, and write the first transaction operation identifier oid into the local redis queue.

[0052] Specifically, the business namespace rule refers to a rule that divides the memory so that structures with the same name in different memory areas coexist, thereby solving the problem of duplicate name structures that may occur in large projects. According to the first parsing result, a first transaction operation identifier oid of the first parsing result is generated based on the business namespace rule. Through the business space rule, the first parsing result and the first transaction operation identifier oid have a unique corresponding relationship. Further, based on the business namespace rule, the first parsing result has a business namespace that uniquely corresponds to it, that is, the first business namespace, and the local redis queue is obtained according to the first business namespace. The local redis queue has a corresponding relationship with the first business namespace, and the first transaction operation identifier oid is written to the local redis queue.

[0053] Further, such as Figure 5 As shown, step S700 of the embodiment of the present application also includes:

[0054] Step S710: Obtain a transaction operation identifier oid detection instruction, perform oid detection of the local redis cluster client according to the transaction operation identifier oid detection instruction, and obtain a first detection result;

[0055] Step S720: when the first detection result is that the first transaction operation identifier oid has not been deleted, obtaining the first consumer end according to the local redis queue corresponding to the first transaction operation identifier oid;

[0056] Step S730: parsing the first transaction operation identifier oid based on the first consumer end to obtain a second parsing result;

[0057] Step S740: Perform transaction compensation according to the second analytical solution result.

[0058] Specifically, the transaction operation identifier oid detection instruction is an instruction for detecting the local redis cluster oid. According to the transaction operation identifier oid detection instruction, the oid detection of the local redis cluster client is performed to obtain a first detection result. When the first detection result is that the first transaction operation identifier oid has not been deleted, a message that the local redis cluster oid has not been deleted appears, indicating that a half-transaction has occurred. At this time, the transaction executor may be unexpectedly down or the remote redis cluster client command execution is unsuccessful. At this time, the first consumer end is started through the local redis queue corresponding to the first transaction operation identifier oid, and the first transaction operation identifier oid is parsed based on the first consumer end to obtain a second parsing result, wherein the second parsing result includes the command and parameters corresponding to the first transaction operation identifier oid, and transaction compensation is performed based on the result obtained by parsing to ensure local and remote consistency. Further, the transaction compensation process is to subscribe to the message queue, start a subscription thread for each transaction queue to independently process the data to be compensated corresponding to the business, and use blpop to obtain the queue head element oid of the corresponding queue from the message queue through the message subscription thread corresponding to each business, and perform transaction compensation according to the parsed commands and parameters.

[0059] Further, such as Figure 6 As shown, the transaction compensation is performed according to the second analytical solution result, and step S740 of the embodiment of the present application further includes:

[0060] Step S741: performing command type matching according to the second parsing result;

[0061] Step S742: when the matching result is a first type of command, compare the data and ttl corresponding to the key of the local redis cluster client and the remote redis cluster client to obtain a first comparison result;

[0062] Step S743: when the first comparison result and the data corresponding to the key of the local redis cluster client and the ttl meet the first preset condition, the remote redis cluster client is set according to the data corresponding to the key of the local redis cluster client and the ttl;

[0063] Step S744: When the first comparison result and the data and ttl corresponding to the key of the local redis cluster client do not meet the first preset condition, the data and ttl corresponding to the key of the remote redis cluster client are deleted.

[0064] Specifically, the first type of command includes: set, setEx, setNx, expireAt, del commands, and the command type is matched according to the second parsing result. When the match is one of the first type of commands, it is distributed to the string processor for processing. The string processor compares the data and ttl corresponding to the key of the local redis cluster client and the remote redis cluster client to obtain a first comparison result. When the first comparison result is inconsistent and the data and ttl corresponding to the key of the local redis cluster client have not expired, it is judged that the first preset condition is met. At this time, the data and ttl queried by the local redis are set to the remote redis cluster client. When the first comparison result is consistent or the data and ttl corresponding to the key of the local redis cluster client have expired, the data and ttl corresponding to the key of the remote redis cluster client are deleted.

[0065] For example, if the local ttl corresponding to the key obtained by the local redis cluster client is -2, it means that the key does not exist, and the remote redis cluster client executes the delete command to delete the key; if ttl is -1, it means that the key has no expiration time, the local redis cluster client obtains the local value corresponding to the key, and the remote redis cluster client executes the set command; if ttl<3; it means that it is about to expire, sleep3s to re-obtain ttl for processing; if ttl>=3, it means that the expiration time is after 3s, the absolute expiration time is calculated, the local redis cluster client obtains the local value corresponding to the key, and the remote redis cluster client executes the setEx command.

[0066] Further, such as Figure 7 As shown, step S741 of the embodiment of the present application also includes:

[0067] Step S7411: when the matching result is a second type of command, compare the data and ttl corresponding to the key field of the local redis cluster client and the remote redis cluster client to obtain a second comparison result;

[0068] Step S7412: When the second comparison result and the data corresponding to the key field of the local redis cluster client and the ttl meet the second preset condition, the remote redis cluster client is set up through the data corresponding to the key field of the local redis cluster client and the ttl.

[0069] Specifically, the second type of command includes hset and hdel commands. When the matching result is the second type of command, it is distributed to the hash processor for processing. The data corresponding to the key field of the local redis cluster client and the remote redis cluster client are compared with the ttl to obtain a second comparison result. When the second comparison result and the data corresponding to the key field of the local redis cluster client and the ttl meet the second preset condition, when the local redis cluster client compares the data corresponding to the key field and the ttl with the remote redis cluster client, if the comparison results are inconsistent and the data corresponding to the key field of the local redis cluster client and the ttl are not expired or exist, it is considered that the second preset condition is met. At this time, the data and ttl queried by the local redis cluster client are set to the remote redis cluster client. When the second preset condition is not met, the key field of the remote redis cluster client is deleted.

[0070] For example, through the hash processor, the local redis cluster client uses the hexists command to confirm whether the field corresponding to the key exists. If the return value is 1, it means it exists. The hget command is used to obtain the value, and the remote redis cluster client executes the hset command to set the value. If the return value is 0, it means that the key does not exist, or the field corresponding to the key does not exist, the remote redis client executes the hdel command to delete the field corresponding to the key. Through transaction compensation, the consistency of rediscluster data across IDCs can be guaranteed, avoiding data inconsistency problems caused by double writing or asynchronous writing, and achieving higher synchronization efficiency. If the local execution is successful, it will be synchronized to the remote location immediately to achieve a lower latency effect.

[0071] In summary, the transaction id-based dual-write technology method and system provided in the embodiments of the present application have the following technical effects:

[0072] 1. Due to the adoption of obtaining the first client request parameter; parsing the first client request parameter through the API encapsulation client redis component to obtain the first parsing result; obtaining the first transaction operation identifier oid according to the first parsing result; writing the first transaction operation identifier oid to the local redis queue through the local redis cluster client, and returning execution failure when the write fails; when the write succeeds, writing the redis command of the first parsing result through the local redis cluster client to obtain the first write result. Obtain the first write result; determine whether the first write result is executed successfully, and when the first write result is executed successfully, write the redis command of the first parsing result through the remote redis cluster client to obtain the second write result; determine whether the second write result is executed successfully, and when the second write result is executed successfully, delete the first transaction operation identifier oid of the local redis cluster client and return execution success. A low-cost dual-write solution is provided to ensure data consistency across IDCs while controlling costs.

[0073] 2. Transaction compensation can ensure the consistency of rediscluster data across IDCs, avoid data inconsistency caused by double writing or asynchronous writing, and achieve higher synchronization efficiency. If the local execution is successful, it will be synchronized to the remote location immediately, achieving a lower latency effect.

[0074] Embodiment 2

[0075] Based on the same inventive concept as the double-write technology method based on transaction ID in the aforementioned embodiment, the present invention also provides a double-write technology system based on transaction ID, such as Figure 8 As shown, the system comprises:

[0076] A first obtaining unit 11, wherein the first obtaining unit 11 is used to obtain a first client request parameter;

[0077] A second obtaining unit 12, wherein the second obtaining unit 12 is used to parse the first client request parameter by encapsulating the client redis component through the API to obtain a first parsing result;

[0078] A third obtaining unit 13, the third obtaining unit 13 is used to obtain a first transaction operation identifier oid according to the first parsing result;

[0079] The fourth obtaining unit 14 is used to write the first transaction operation identifier oid to local redis through the local redis cluster client, and when the writing fails, return the execution failure; when the writing succeeds, write the redis command of the first parsing result through the local redis cluster client to obtain the first writing result;

[0080] A first judgment unit 15, the first judgment unit 15 is used to judge whether the first writing result is executed successfully, and when the first writing result is executed successfully, a redis command writing of the first parsing result is performed through a remote redis cluster client to obtain a second writing result;

[0081] The second judgment unit 16 is used to judge whether the second writing result is executed successfully. When the second writing result is executed successfully, the first transaction operation identifier oid of the local redis cluster client is deleted, and execution success is returned.

[0082] Furthermore, the system also includes:

[0083] A fifth obtaining unit, the fifth obtaining unit being used to obtain a service namespace rule;

[0084] A sixth obtaining unit, the sixth obtaining unit is used to generate the first transaction operation identifier oid according to the first parsing result and based on the business namespace rule.

[0085] Furthermore, the system also includes:

[0086] a seventh obtaining unit, configured to obtain, according to the business namespace rule, a first business namespace corresponding to the first parsing result;

[0087] An eighth obtaining unit, wherein the eighth obtaining unit is used to obtain the local redis queue according to the first business namespace, and write the first transaction operation identifier oid into the local redis queue.

[0088] Furthermore, the system also includes:

[0089] a ninth obtaining unit, configured to obtain a first deletion instruction when the execution of the first writing result fails;

[0090] A tenth obtaining unit, wherein the tenth obtaining unit is used to delete the first transaction operation identifier oid according to the first deletion instruction and return an execution failure.

[0091] Furthermore, the system also includes:

[0092] an eleventh obtaining unit, the eleventh obtaining unit being used to obtain a transaction operation identifier OID detection instruction, and to perform an OID detection of the local redis cluster client according to the transaction operation identifier OID detection instruction to obtain a first detection result;

[0093] A twelfth obtaining unit, wherein the twelfth obtaining unit is used to obtain a first consumer end according to the local redis queue corresponding to the first transaction operation identifier oid when the first detection result is that the first transaction operation identifier oid is not deleted;

[0094] a thirteenth obtaining unit, the thirteenth obtaining unit being configured to obtain a second parsing result by parsing the first transaction operation identifier oid based on the first consumer end;

[0095] A first compensation unit is used to perform transaction compensation according to the second analytical solution result.

[0096] Furthermore, the system also includes:

[0097] a first matching unit, the first matching unit being configured to perform command type matching according to the second parsing result;

[0098] A fourteenth obtaining unit, wherein the fourteenth obtaining unit is used to compare the data corresponding to the key of the local redis cluster client and the remote redis cluster client with the ttl to obtain a first comparison result when the matching result is a first type of command;

[0099] A fifteenth obtaining unit, wherein the fifteenth obtaining unit is used to perform remote redis cluster client settings through the data corresponding to the key of the local redis cluster client and the ttl when the first comparison result and the data corresponding to the key of the local redis cluster client and the ttl meet a first preset condition;

[0100] The sixteenth obtaining unit is used to delete the data and ttl corresponding to the key of the remote redis cluster client when the first comparison result and the data and ttl corresponding to the key of the local redis cluster client do not meet the first preset condition.

[0101] Furthermore, the system also includes:

[0102] A seventeenth obtaining unit, wherein the seventeenth obtaining unit is used to compare the data and TTL corresponding to the field of the key of the local redis cluster client and the remote redis cluster client to obtain a second comparison result when the matching result is a second type of command;

[0103] An eighteenth obtaining unit, wherein the eighteenth obtaining unit is used to perform remote redis cluster client settings through the data corresponding to the key field of the local redis cluster client and the ttl when the second comparison result and the data corresponding to the key field of the local redis cluster client and the ttl meet the second preset condition.

[0104] The foregoing Figure 1 The various variations and specific examples of a double-write technology method based on transaction ID in Example 1 are also applicable to a double-write technology system based on transaction ID in this embodiment. Through the above detailed description of a double-write technology method based on transaction ID, technical personnel in this field can clearly know the implementation method of a double-write technology system based on transaction ID in this embodiment, so for the sake of brevity of the specification, it will not be described in detail here.

[0105] Exemplary Electronic Devices

[0106] Reference below Fig. 9 To describe the electronic device of the embodiment of the present application.

[0107] Fig. 9 The figure shows a schematic structural diagram of an electronic device according to an embodiment of the present application.

[0108] Based on the inventive concept of a double-write technology method based on transaction ID in the above embodiment, the present invention also provides a double-write technology system based on transaction ID. Fig. 9 The electronic device according to the embodiment of the present application is described. The electronic device may be a mobile device itself, or a stand-alone device independent of the mobile device, on which a computer program is stored, and when the program is executed by a processor, the steps of any of the above methods are implemented.

[0109] like Fig. 9 As shown, the electronic device 50 includes one or more processors 51 and a memory 52 .

[0110] The processor 51 may be a central processing unit (CPU) or other forms of processing units having data processing capabilities and / or instruction execution capabilities, and may control other components in the electronic device 50 to perform desired functions.

[0111] The memory 52 may include one or more computer program products, which may include various forms of computer-readable storage media, such as volatile memory and / or non-volatile memory. The volatile memory may include, for example, a random access memory (RAM) and / or a cache memory (cache), etc. The non-volatile memory may include, for example, a read-only memory (ROM), a hard disk, a flash memory, etc. One or more computer program instructions may be stored on the computer-readable storage medium, and the processor 51 may execute the program instructions to implement the methods of the various embodiments of the present application described above and / or other desired functions.

[0112] In one example, the electronic device 50 may further include: an input device 53 and an output device 54, and these components are interconnected via a bus system and / or other forms of connection mechanisms (not shown).

[0113] The embodiment of the present invention provides a double-write technical method based on transaction ID, wherein the method includes: obtaining a first client request parameter; parsing the first client request parameter through an API encapsulation client redis component to obtain a first parsing result; obtaining a first transaction operation identifier oid according to the first parsing result; performing a local redis write of the first transaction operation identifier oid through a local redis cluster client, and returning execution failure when the write fails; when the write succeeds, performing a redis command write of the first parsing result through a local redis cluster client to obtain a first write result; judging whether the first write result is executed successfully, when the first write result is executed successfully, performing a redis command write of the first parsing result through a remote redis cluster client to obtain a second write result; judging whether the second write result is executed successfully, when the second write result is executed successfully, deleting the first transaction operation identifier oid of the local redis cluster client, and returning execution success. The invention solves the technical problem that the solution cost is too high and the data consistency across IDCs cannot be guaranteed in the prior art, and achieves the technical effect of providing a low-cost double-write solution to ensure data consistency across IDCs under the premise of controlling costs.

[0114] Through the description of the above implementation methods, the technicians in the relevant field can clearly understand that the present application can be implemented by means of software plus necessary general hardware, and of course, it can also be implemented by special hardware including special integrated circuits, special CPUs, special memories, special components, etc. In general, all functions completed by computer programs can be easily implemented with corresponding hardware, and the specific hardware structures used to implement the same function can also be various, such as analog circuits, digital circuits or special circuits. However, for the present application, software program implementation is a better implementation method in more cases. Based on such an understanding, the technical solution of the present application is essentially or the part that contributes to the prior art can be embodied in the form of a software product, which is stored in a readable storage medium, such as a computer floppy disk, U disk, mobile hard disk, ROM, RAM, disk or optical disk, etc., including a number of instructions to enable a computer device to execute the methods described in each embodiment of the present application.

[0115] In the above embodiments, all or part of the embodiments may be implemented by software, hardware, firmware or any combination thereof. When implemented by software, all or part of the embodiments may be implemented in the form of a computer program product.

[0116] The computer program product includes one or more computer instructions. When the computer program instructions are loaded and executed on a computer, the process or function described in the embodiment of the present application is generated in whole or in part. The computer may be a general-purpose computer, a special-purpose computer, a computer network, or other programmable devices. The computer instructions may be stored in a computer-readable storage medium, or transmitted from a computer-readable storage medium to another computer-readable storage medium, and the available medium may be a magnetic medium, (e.g., a floppy disk, a hard disk, a magnetic tape), an optical medium (e.g., a DVD), or a semiconductor medium (e.g., a solid-state drive (SSD)), etc.

[0117] It should be understood that "one embodiment" or "an embodiment" mentioned throughout the specification means that specific features, structures or characteristics related to the embodiment are included in at least one embodiment of the present application. Therefore, "in one embodiment" or "in an embodiment" appearing throughout the specification does not necessarily refer to the same embodiment. In addition, these specific features, structures or characteristics can be combined in one or more embodiments in any suitable manner. It should be understood that in various embodiments of the present application, the size of the sequence number of the above-mentioned processes does not mean the order of execution, and the execution order of each process should be determined by its function and internal logic, and should not constitute any limitation on the implementation process of the embodiment of the present application.

[0118] In addition, the terms "system" and "network" are often used interchangeably in this article. The term "and / or" in this article is only a description of the association relationship of the associated objects, indicating that there can be three relationships. For example, A and / or B can mean: A exists alone, A and B exist at the same time, and B exists alone. In addition, the character " / " in this article generally indicates that the associated objects before and after are in an "or" relationship.

[0119] It should be understood that in the embodiment of the present application, "B corresponding to A" means that B is associated with A, and B can be determined according to A. However, it should also be understood that determining B according to A does not mean determining B only according to A, and B can also be determined according to A and / or other information.

[0120] Those of ordinary skill in the art will appreciate that the units and algorithm steps of each example described in conjunction with the embodiments disclosed herein can be implemented in electronic hardware, computer software, or a combination of the two. In order to clearly illustrate the interchangeability of hardware and software, the composition and steps of each example have been generally described in terms of function in the above description. Whether these functions are performed in hardware or software depends on the specific application and design constraints of the technical solution. Professional and technical personnel can use different methods to implement the described functions for each specific application, but such implementation should not be considered to be beyond the scope of this application.

[0121] In short, the above is only a preferred embodiment of the technical solution of this application, and is not intended to limit the protection scope of this application. Any modification, equivalent replacement, improvement, etc. made within the spirit and principle of this application should be included in the protection scope of this application.

Claims

1. A double-write technology method based on transaction id, wherein: The method comprises: Obtaining first client request parameters; Parsing the first client request parameter by encapsulating the client redis component through the API to obtain a first parsing result; Obtain a first transaction operation identifier oid according to the first parsing result; Writing the first transaction operation identifier oid to local redis through the local redis cluster client, and returning execution failure when the writing fails; and writing the first parsing result to redis command through the local redis cluster client to obtain a first writing result when the writing succeeds; Determine whether the first writing result is executed successfully. When the first writing result is executed successfully, write the redis command of the first parsing result through the remote redis cluster client to obtain a second writing result; Determine whether the second write result is executed successfully. If the second write result is executed successfully, delete the first transaction operation identifier oid of the local redis cluster client and return execution success; The obtaining the first transaction operation identifier oid according to the first parsing result includes: Get business namespace rules; According to the first parsing result, the first transaction operation identifier oid is generated based on the business namespace rule.

2. The method of claim 1, wherein: The writing of the first transaction operation identifier OID to the local redis queue through the local redis cluster client also includes: Obtaining a first business namespace corresponding to the first parsing result according to the business namespace rule; The local redis queue is obtained according to the first business namespace, and the first transaction operation identifier oid is written into the local redis queue.

3. The method of claim 1, wherein: The determining whether the first writing result is executed successfully also includes: When the first writing result fails to be executed, obtaining a first deletion instruction; The first transaction operation identifier oid is deleted according to the first deletion instruction, and execution failure is returned.

4. The method of claim 2, wherein: The method further comprises: Obtain a transaction operation identifier oid detection instruction, perform oid detection of the local redis cluster client according to the transaction operation identifier oid detection instruction, and obtain a first detection result; When the first detection result is that the first transaction operation identifier oid has not been deleted, obtaining the first consumer end according to the local redis queue corresponding to the first transaction operation identifier oid; Obtaining a second parsing result based on the first consumer end parsing the first transaction operation identifier oid; Transaction compensation is performed according to the second parsing result.

5. The method of claim 4, wherein: The performing transaction compensation according to the second parsing result also includes: Perform command type matching according to the second parsing result; When the matching result is a first type of command, the data and TTL corresponding to the key of the local redis cluster client and the remote redis cluster client are compared to obtain a first comparison result; When the first comparison result and the data corresponding to the key of the local redis cluster client and the ttl meet the first preset condition, the remote redis cluster client is set according to the data corresponding to the key of the local redis cluster client and the ttl; When the first comparison result and the data and ttl corresponding to the key of the local redis cluster client do not meet the first preset condition, the data and ttl corresponding to the key of the remote redis cluster client are deleted.

6. The method of claim 5, wherein: The method further comprises: When the matching result is a second type of command, the data and ttl corresponding to the key field of the local redis cluster client and the remote redis cluster client are compared to obtain a second comparison result; When the second comparison result and the data corresponding to the key field of the local redis cluster client and the ttl meet the second preset condition, the remote redis cluster client is set according to the data corresponding to the key field of the local redis cluster client and the ttl.

7. A dual-write technology system based on transaction id, wherein: The system comprises: A first obtaining unit, the first obtaining unit is used to obtain a first client request parameter; A second obtaining unit, the second obtaining unit is used to parse the first client request parameter by encapsulating the client redis component through the API to obtain a first parsing result; A third obtaining unit, the third obtaining unit is used to obtain a first transaction operation identifier oid according to the first parsing result; A fourth obtaining unit, wherein the fourth obtaining unit is used to write the first transaction operation identifier oid to local redis through a local redis cluster client, and when the writing fails, return execution failure; when the writing succeeds, write the redis command of the first parsing result through the local redis cluster client to obtain a first writing result; A first judgment unit, the first judgment unit is used to judge whether the first writing result is executed successfully, and when the first writing result is executed successfully, a redis command writing of the first parsing result is performed through a remote redis cluster client to obtain a second writing result; A second judgment unit, wherein the second judgment unit is used to judge whether the second writing result is executed successfully. When the second writing result is executed successfully, the first transaction operation identifier oid of the local redis cluster client is deleted, and execution success is returned; The third obtaining unit comprises: A fifth obtaining unit, the fifth obtaining unit being used to obtain a service namespace rule; A sixth obtaining unit, the sixth obtaining unit is used to generate the first transaction operation identifier oid according to the first parsing result and based on the business namespace rule.

8. A double-write technology system based on transaction ID, comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein: When the processor executes the program, the steps of the method according to any one of claims 1 to 6 are implemented.

Citation Information

Patent Citations

  • Data management method and system, electronic equipment and storage medium

    CN109600430A

  • Method, device and equipment for data backup of redis cluster across machine rooms and storage medium

    CN109684406A