Data synchronization method and device based on remote multi-active system
By using vector clock mechanism to mark the operation logic clock in the off-site multi-living system, the problem of concurrent conflicts in data synchronization is solved, and the data synchronization efficiency and consistency of off-site multi-living system is improved.
Patent Information
- Application Number
- CN202111299131.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-11-04
- Publication Date
- 2024-11-15
- Estimated Expiration
- 2041-11-04
AI Technical Summary
Existing off-site multi-active systems are prone to concurrent conflicts during data synchronization, resulting in data inconsistency. The existing solutions are inefficient and complex, making it difficult to achieve efficient data synchronization.
By introducing a vector clock mechanism in a remote multi-active system, the logical clock for each operation is recorded, ensuring that conflicts are handled based on clock marks when data synchronization is performed, and data consistency and efficiency are ensured.
It effectively resolves the problem of concurrent conflicts, improves the data synchronization efficiency of off-site multi-living systems, and ensures data consistency and accuracy.
Smart Images

Figure CN113971181B_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of computer technology, and in particular to a data synchronization method and device based on a remote multi-active system. Background Art
[0002] With the rapid development of the Internet industry, the use of remote multi-active systems to deploy services has become a mainstream trend. Generally speaking, a remote multi-active system includes multiple business devices set up in different geographical areas. Based on the geographical area where the user is located, the business access or business request initiated by the user will be sent to the business device in the corresponding geographical area for processing.
[0003] In order to prevent users from accessing services across regions, each service device needs to synchronize data regularly to ensure data consistency. In the prior art, in order to avoid concurrency conflicts during data synchronization, each service device will split the data involved in service access to ensure that the service operation data in each service device is different, avoiding concurrency conflicts during subsequent data synchronization.
[0004] However, this processing method requires modification of the business itself, and due to the complex business logic in the multi-site active-active system, this processing method is prone to omission of business data, and the implementation efficiency is low and the accuracy is poor. Therefore, how to provide an efficient and simple data synchronization method has become a difficult problem. Summary of the invention
[0005] The embodiments of the present application provide a data synchronization method and device based on a remote multi-active system, so as to provide an efficient data synchronization method for the remote multi-active system.
[0006] In a first aspect, the present application provides a data synchronization method based on a remote multi-active system, wherein the remote multi-active system includes a plurality of business devices respectively located in a plurality of geographical areas, and the data synchronization method is executed by a target business device among the plurality of business devices;
[0007] The data synchronization method comprises:
[0008] Obtaining a first operation instruction for a target service and determining an initial vector clock of a current synchronization cycle;
[0009] updating the initial vector clock to obtain a first vector clock, and performing a first operation on the initial data of the target service according to the first vector clock and the first operation instruction to obtain first operation data of the target service;
[0010] Receiving second synchronization information sent by other service devices in the remote multi-active system, where the second synchronization information includes a second vector clock and variable data of a second operation, where the second vector clock is obtained by updating the initial vector clock by the other service devices, and the variable data of the second operation is used to represent a change in data of a target service of the other service devices before and after the second operation;
[0011] According to the second synchronization information, the first operation data and the first vector clock of the target service are synchronized respectively to obtain the synchronization data and synchronization vector clock of the target service in the current synchronization cycle. The synchronization vector clock of the current synchronization cycle will be used as the initial vector clock of the next synchronization cycle.
[0012] In an optional implementation manner, the first operation instruction includes an operation type;
[0013] The updating of the initial vector clock to obtain a first vector clock includes:
[0014] According to the operation type of the first operation instruction, the logical clock of the target service device in the initial vector clock is updated, and the updated vector clock is the first vector clock.
[0015] In an optional implementation manner, the updating, according to the operation type of the first operation instruction, the logical clock of the target service device in the initial vector clock includes:
[0016] If the operation type is an assignment operation, adding one to the logical clock of the target service device in the initial vector clock to obtain the first vector clock as the logical clock of the target service device in the first vector clock;
[0017] If the operation type is a delete operation, the logical clock of the target service device in the initial vector clock is directly used as the logical clock of the target service device in the first vector clock to obtain the first vector clock.
[0018] In an optional implementation manner, synchronizing the first vector clock according to the second synchronization information to obtain a synchronous vector clock of a current synchronization period includes:
[0019] According to the logical clock corresponding to the second vector clock in the other service equipment in the second synchronization information, the logical clock corresponding to the first vector clock in the other service equipment is overwritten to obtain the synchronous vector clock of the current synchronization cycle.
[0020] In an optional implementation manner, the initial data includes at least one initial triplet data, each of which includes a data value, an execution device identifier, and a logical clock of the execution device when creating the initial triplet data;
[0021] The first operation instruction also includes an operation value;
[0022] The performing a first operation on the initial data of the target service according to the first vector clock and the first operation instruction to obtain first operation data of the target service includes:
[0023] If the operation type is an assignment operation, generating assignment triplet data according to the operation value, the target service device identifier, and the logical clock of the target service device in the first vector clock, and the assignment triplet data and the initial triplet data in the initial data will constitute the first operation data of the target service;
[0024] If the operation type is a deletion operation, the data value to be deleted is found in each data value of the initial triplet data according to the operation value, and the initial triplet data corresponding to the data value to be deleted in the initial data is deleted, and the remaining initial triplet data in the initial data is the first operation data of the target business.
[0025] In an optional implementation manner, the variable data of the second operation includes a change type of the variable data and the variable triplet data;
[0026] Wherein, the change type includes a deletion type or an assignment type;
[0027] The variable triplet data includes an operation value of the second operation, identifiers of other service devices, and logical clocks of other service devices in the second vector clock;
[0028] Synchronizing the first operation data of the target service according to the second synchronization information to obtain synchronization data of the target service in the current synchronization period includes:
[0029] If the change type of the variable data of the second operation in the second synchronization information is an assignment type, the variable triplet data of the variable data in the second synchronization information and the triplet data in the first operation data constitute the synchronization data of the target service in the current synchronization period;
[0030] If the change type of the variable data of the second operation in the second synchronization information is a deletion type, then the triplet data identical to the variable triplet data is deleted in each triplet data of the first operation data, and the remaining triplet data in the first operation data constitutes the synchronization data of the target service in the current synchronization cycle.
[0031] In an optional implementation manner, after obtaining the first operation data of the target service, the method further includes:
[0032] Determine variable data of the first operation, and generate first synchronization information according to the variable data of the first operation and the first vector clock; the variable data of the first operation is used to represent the change amount of the target service data of the target service device before and after the first operation;
[0033] The first synchronization information is sent to the other service equipment, so that the other service equipment can synchronize the second operation data and the second vector clock of the target service respectively according to the first synchronization information, and obtain the synchronization data and the synchronization vector clock of the target service in the current synchronization cycle, and the synchronization vector clock of the current synchronization cycle will be used as the initial vector clock of the next synchronization cycle;
[0034] The second operation data is obtained by the other service device performing a second operation on the initial data of the target service according to the second vector clock and the second operation instruction.
[0035] In an optional implementation manner, the determining variable data of the first operation includes:
[0036] Determine variable triplet data between initial triplet data of the initial data and each triplet data of the first operation data; wherein the variable triplet data includes an operation value of the first operation, a target service device identifier, and a logical clock of the target service device in the first vector clock;
[0037] According to the operation type in the first operation instruction, the change type of the variable data is determined.
[0038] In a second aspect, the present application provides a business device, the business device belongs to a remote multi-active system, the remote multi-active system includes different business devices located in different geographical areas, and the data synchronization method is executed by a target business device among the multiple business devices;
[0039] The business equipment includes:
[0040] A transceiver module, used for obtaining a first operation instruction for a target service;
[0041] A synchronization processing module, used to determine an initial vector clock of a current synchronization period, and update the initial vector clock to obtain a first vector clock;
[0042] an execution module, configured to execute a first operation on the initial data of the target service according to the first vector clock and the first operation instruction, so as to obtain first operation data of the target service;
[0043] The transceiver module is further used to receive second synchronization information sent by other service devices of the remote multi-active system, where the second synchronization information includes a second vector clock and variable data of a second operation, where the second vector clock is obtained by updating the initial vector clock by the other service devices, and the variable data of the second operation is used to represent a change in data of a target service of the other service devices before and after the second operation;
[0044] A synchronization processing module is used to synchronize the first operation data and the first vector clock of the target service respectively according to the second synchronization information, so as to obtain the synchronization data and synchronization vector clock of the target service in the current synchronization cycle. The synchronization vector clock of the current synchronization cycle will be used as the initial vector clock of the next synchronization cycle.
[0045] In an optional implementation manner, the first operation instruction includes an operation type;
[0046] The synchronization processing module is specifically used to update the logical clock of the target service device in the initial vector clock according to the operation type of the first operation instruction, and the updated vector clock is the first vector clock.
[0047] In an optional implementation manner, the synchronization processing module is specifically used to:
[0048] If the operation type is an assignment operation, adding one to the logical clock of the target service device in the initial vector clock to obtain the first vector clock as the logical clock of the target service device in the first vector clock;
[0049] If the operation type is a delete operation, the logical clock of the target service device in the initial vector clock is directly used as the logical clock of the target service device in the first vector clock to obtain the first vector clock.
[0050] In an optional implementation, the synchronization processing module is used to overwrite the logical clock corresponding to the first vector clock in the other business equipment according to the logical clock corresponding to the second vector clock in the other business equipment in the second synchronization information, so as to obtain the synchronous vector clock of the current synchronization cycle.
[0051] In an optional implementation manner, the initial data includes at least one initial triplet data, each of which includes a data value, an execution device identifier, and a logical clock of the execution device when creating the initial triplet data;
[0052] The first operation instruction also includes an operation value;
[0053] The execution module is specifically used for:
[0054] If the operation type is an assignment operation, generating assignment triplet data according to the operation value, the target service device identifier, and the logical clock of the target service device in the first vector clock, and the assignment triplet data and the initial triplet data in the initial data will constitute the first operation data of the target service;
[0055] If the operation type is a deletion operation, the data value to be deleted is found in each data value of the initial triplet data according to the operation value, and the initial triplet data corresponding to the data value to be deleted in the initial data is deleted, and the remaining initial triplet data in the initial data is the first operation data of the target business.
[0056] In an optional implementation manner, the variable data of the second operation includes a change type of the variable data and the variable triplet data;
[0057] Wherein, the change type includes a deletion type or an assignment type;
[0058] The variable triplet data includes an operation value of the second operation, identifiers of other service devices, and logical clocks of other service devices in the second vector clock;
[0059] A synchronization processing module, specifically configured to, if the change type of the variable data of the second operation in the second synchronization information is an assignment type, then the variable triplet data of the variable data in the second synchronization information and the triplet data in the first operation data constitute the synchronization data of the target service in the current synchronization cycle;
[0060] If the change type of the variable data of the second operation in the second synchronization information is a deletion type, then the triplet data identical to the variable triplet data is deleted in each triplet data of the first operation data, and the remaining triplet data in the first operation data constitutes the synchronization data of the target service in the current synchronization cycle.
[0061] In an optional embodiment, after obtaining the first operation data of the target service, the synchronization processing module is further used to:
[0062] Determine variable data of the first operation, and generate first synchronization information according to the variable data of the first operation and the first vector clock; the variable data of the first operation is used to represent the change amount of the target service data of the target service device before and after the first operation;
[0063] The transceiver module is further used to send the first synchronization information to the other service equipment, so that the other service equipment can synchronize the second operation data and the second vector clock of the target service respectively according to the first synchronization information, and obtain the synchronization data and the synchronization vector clock of the target service in the current synchronization cycle, and the synchronization vector clock of the current synchronization cycle will be used as the initial vector clock of the next synchronization cycle;
[0064] The second operation data is obtained by the other service device performing a second operation on the initial data of the target service according to the second vector clock and the second operation instruction.
[0065] In an optional implementation manner, the synchronization processing module is further used to:
[0066] Determine the variable triplet data between the initial triplet data of the initial data and the triplet data of the first operation data; wherein the variable triplet data includes the operation value of the first operation, the target business device identifier, and the logical clock of the target business device in the first vector clock; determine the change type of the variable data according to the operation type in the first operation instruction.
[0067] In a third aspect, the present application provides an electronic device, comprising: at least one processor and a memory;
[0068] The memory stores computer-executable instructions;
[0069] The at least one processor executes the computer-executable instructions stored in the memory, so that the at least one processor performs the method according to the first aspect.
[0070] In a fourth aspect, the present application provides a computer-readable storage medium, wherein the computer-readable storage medium stores computer-executable instructions. When a processor executes the computer-executable instructions, the method described in the first aspect is implemented.
[0071] In a fifth aspect, the present application provides a computer program product, including a computer program, which implements the method described in the first aspect when executed by a processor.
[0072] The embodiment of the present application provides a data synchronization method and device based on a multi-site active-active system. The target service device obtains a first operation instruction for the target service and determines the initial vector clock of the current synchronization cycle; updates the initial vector clock to obtain a first vector clock, and performs a first operation on the initial data of the target service according to the first vector clock and the first operation instruction to obtain the first operation data of the target service; receives second synchronization information sent by other service devices in the multi-site active-active system, the second synchronization information includes a second vector clock and variable data of a second operation, the second vector clock is obtained by updating the initial vector clock by the other service devices, and the variable data of the second operation is used to represent the change in the data of the target service of the other service devices before and after the second operation; synchronizes the first operation data and the first vector clock of the target service according to the second synchronization information, respectively, to obtain the synchronization data and synchronization vector clock of the target service in the current synchronization cycle, and the synchronization vector clock of the current synchronization cycle will be used as the initial vector clock of the next synchronization cycle. This solution uses vector clocks to mark the data obtained from operations performed by different business devices, so that when data is synchronized for each business device, conflicting operations can be effectively processed and resolved based on the vector clock marking of the data, effectively improving the data synchronization efficiency of the multi-site active-active system. BRIEF DESCRIPTION OF THE DRAWINGS
[0073] The accompanying drawings, which are incorporated in and constitute a part of this specification, illustrate embodiments consistent with the present application and, together with the description, serve to explain the principles of the present application.
[0074] Figure 1 It is a schematic diagram of the data synchronization process of a multi-active system in different locations in the prior art;
[0075] Figure 2 A schematic diagram of a network architecture on which this application is based;
[0076] Figure 3 It is a flowchart of a data synchronization method based on a remote multi-active system provided by the present application;
[0077] Figure 4 A flowchart of a data synchronization method based on a remote multi-active system for processing concurrent assignment conflicts provided in an embodiment of the present application;
[0078] Figure 5 A flowchart of another data synchronization method based on a remote multi-active system provided in an embodiment of the present application for processing concurrent assignment conflicts;
[0079] Figure 6A flow chart of a data synchronization method based on a remote multi-active system provided in an embodiment of the present application for processing concurrent assignment and deletion conflicts;
[0080] Figure 7 A flowchart of another data synchronization method based on a remote multi-active system provided in an embodiment of the present application for processing concurrent assignment and deletion conflicts;
[0081] Figure 8 A schematic diagram of the structure of a service device provided in an embodiment of the present application;
[0082] Fig. 9 A schematic diagram of the structure of an electronic device provided by an embodiment of the present invention.
[0083] The above drawings have shown clear embodiments of the present application, which will be described in more detail later. These drawings and text descriptions are not intended to limit the scope of the present application in any way, but to illustrate the concept of the present application to those skilled in the art by referring to specific embodiments. DETAILED DESCRIPTION
[0084] Exemplary embodiments will be described in detail herein, examples of which are shown in the accompanying drawings. When the following description refers to the drawings, unless otherwise indicated, the same numbers in different drawings represent the same or similar elements. The implementations described in the following exemplary embodiments do not represent all implementations consistent with the present application. Instead, they are merely examples of systems and methods consistent with some aspects of the present application as detailed in the appended claims.
[0085] With the rapid development of the Internet industry, the use of remote multi-active systems to deploy services has become a mainstream trend. Generally speaking, a remote multi-active system includes multiple business devices set up in different geographical areas. Based on the geographical area where the user is located, the business access or business request initiated by the user will be sent to the business device in the corresponding geographical area for processing.
[0086] In order to prevent users from accessing services across regions, each business device needs to synchronize data regularly to ensure data consistency.
[0087] However, since each business device in the remote multi-active system is in the business data processing state at the same time, a business concurrency conflict may occur at a certain moment, which will lead to the destruction of data consistency between the business devices. Figure 1 FIG. 1 is a schematic diagram of the data synchronization process of a multi-site active-active system in the prior art. Figure 1 As shown, the remote multi-active system includes business equipment A and business equipment B.
[0088] At time t0 when time is 0, the data in service device A and service device B are consistent, and both are "s=a".
[0089] At time t1 when time is 1, service device A obtains an operation instruction in the received service request, namely "set s=b". Service device A will execute the operation instruction, and the data in it will become "s=b". At the same time, service device B obtains another operation instruction in the received service request, namely "del s". Service device B will execute the operation instruction, and the data in it will become "s=NULL".
[0090] At time t2 when time is 2, service device A and service device B will trigger a data synchronization process. Service device A will receive the synchronization information from service device B, that is, "del s", and service device A will execute "del s" to obtain the synchronization result of "s=NULL"; while service device B will receive the synchronization information from service device A, that is, "s=b", and service device B will execute "s=b" to obtain the synchronization result of "s=b".
[0091] Obviously, at time t1, business device A and business device B had a concurrent conflict, that is, different operations were performed on the same data, and there was a certain contradiction between the two operations. This also makes data synchronization in this case
[0092] For the data "s", operation instructions with certain conflicts are executed respectively, resulting in data inconsistency after data synchronization.
[0093] In the face of this problem, in the prior art, each service device will split the data involved in the service access, that is, the data can be represented as: As and Bs. When executing a service request, the service device only processes the service with its own identification, and will not process the service without its own identification.
[0094] However, this processing method requires modifying the business data itself, and since the business logic in the multi-site active-active system is relatively complex, this processing method is prone to omissions of business logic and is inefficient. Therefore, how to provide an efficient and simple data synchronization method becomes a problem.
[0095] In response to the above problems, the embodiments of the present application utilize vector clocks to mark the data obtained from operations performed by different business devices, so that when data is synchronized for each business device, conflicting operations can be effectively processed and resolved based on the vector clock marking of the data, thereby effectively improving the data synchronization efficiency of the multi-site active-active system.
[0096] Specifically, for the target device in the remote multi-active system, it will first obtain the first operation instruction for the target service and determine the initial vector clock of the current synchronization cycle; update the initial vector clock to obtain the first vector clock, and perform the first operation on the initial data of the target service according to the first vector clock and the first operation instruction to obtain the first operation data of the target service. When the synchronization is triggered, the target service device will receive the second synchronization information sent by other service devices in the remote multi-active system, the second synchronization information includes the second vector clock and the variable data of the second operation, the second vector clock is obtained by the other service devices updating the initial vector clock, and the variable data of the second operation is used to represent the change in the data of the target service of the other service devices before and after the second operation. Finally, the target service device will synchronize the first operation data and the first vector clock of the target service respectively according to the second synchronization information, obtain the synchronization data and synchronization vector clock of the target service in the current synchronization cycle, and the synchronization vector clock of the current synchronization cycle will be used as the initial vector clock of the next synchronization cycle.
[0097] In this way, the data obtained from each operation on the target business in the business device will be effectively recorded with the vector clock of the operation. During synchronization, the synchronization information sent by other business devices will also record the vector clocks of other business devices when performing operations. By synchronizing the data through these two vector clocks, the order and scope of operations of different business devices when operating the data of the same target business can be effectively distinguished, thereby effectively solving the above-mentioned Figure 1 The problem of concurrency conflicts mentioned.
[0098] The method provided in this application will be described below in combination with different implementation modes.
[0099] refer to Figure 2 , Figure 2 A schematic diagram of a network architecture based on this application, Figure 2 The network architecture shown may specifically include a remote multi-active system 1 and a user terminal 2;
[0100] Specifically, the remote multi-active system 1 may include multiple business devices. These business devices 11 will be set up in different geographical areas, and each business device can provide services to multiple user terminals 2 at the same time.
[0101] The user terminal 2 may specifically be a hardware device that can be used to execute service request sending or trigger service operations, including but not limited to a desktop computer, a tablet computer, and a cloud computing platform.
[0102] In the present application, for each service device in the remote multi-active system 1, in order to improve service processing efficiency, a database is locally set up to quickly respond to service access requests initiated by the user terminal 2.
[0103] Generally speaking, the user terminal 2 will access the business equipment in the geographical area corresponding to the location based on the user's location. However, in order to avoid the situation where the user's cross-region access fails due to the suspension of some business equipment, the data of the business of the entire geographical area needs to be stored in the database of each business device. At this time, the remote multi-active system 1 needs to synchronize the data between the business devices according to a preset time period or in real time to ensure the consistency of the business data in the database of each business device. In this process, each business device will respectively use the data synchronization method provided by the present application to perform corresponding processing to achieve data synchronization with each other.
[0104] For the sake of convenience, this application will take the target business device as the execution subject and describe the data synchronization method based on the remote multi-active system in this case in combination with the attached drawings. For other business devices, the data synchronization method based on the remote multi-active system is similar to the data synchronization method used by the target business device, and this application will not repeat it.
[0105] Embodiment 1
[0106] Figure 3 1 is a flow chart of a data synchronization method based on a remote multi-active system provided by the present application. In the embodiment of the present application, the remote multi-active system includes multiple business devices located in multiple geographical areas. Figure 3 The execution subject of the process shown is a target service device among multiple service devices.
[0107] like Figure 3 As shown, the data synchronization method includes:
[0108] Step 301: Obtain a first operation instruction for a target service, and determine an initial vector clock of a current synchronization cycle.
[0109] Step 302: Update the initial vector clock to obtain a first vector clock, and perform a first operation on the initial data of the target service according to the first vector clock and the first operation instruction to obtain first operation data of the target service.
[0110] Step 303: Receive second synchronization information sent by other business devices in the remote multi-active system, where the second synchronization information includes a second vector clock and variable data of a second operation, where the second vector clock is obtained by updating the initial vector clock by the other business devices, and the variable data of the second operation is used to represent the change in data of the target business of the other business devices before and after the second operation.
[0111] Step 304: synchronize the first operation data and the first vector clock of the target service respectively according to the second synchronization information to obtain the synchronization data and synchronization vector clock of the target service in the current synchronization cycle. The synchronization vector clock of the current synchronization cycle will be used as the initial vector clock of the next synchronization cycle.
[0112] The data synchronization method based on the remote multi-active system provided by the present application can be specifically applied to any service device in the remote multi-active system. However, this embodiment will be described with the target service device as the execution subject.
[0113] It should be noted that in the implementation of the present application, other business devices refer to devices other than the target business device in the remote multi-active system, and the number of the other business devices can be at least one. In the present application, the number of other business devices is 1 as an example. In the case where the number of other business devices is multiple, the data synchronization process is similar to the embodiment itself, and the present application will not elaborate on it.
[0114] In addition, each business device in the remote multi-active system must use the data synchronization method provided in the embodiment of the present application to perform data synchronization, so as to avoid data concurrency conflicts during synchronization.
[0115] In the embodiment of the present application, in step 301, the target service device first interacts with the user terminal and obtains a request including a service access request or a service processing request from the user terminal. These requests generally include the requested service, i.e., the target service, and the operation to be performed on the requested service, i.e., the first operation instruction.
[0116] The vector clock is a matrix set that can record the logic of event occurrence. The vector clock will record the logical clock of each business device at the last operation. In step 301, the target business device will also update the initial vector clock of the current synchronization cycle. The initial vector clock of the current synchronization cycle refers to the synchronous vector clock obtained by the target business device in the previous synchronization cycle after completing the data synchronization processing of the previous synchronization cycle.
[0117] Since the first operation instruction is received and needs to be executed, the target service device will update the initial vector clock once in step 302 to obtain the first vector clock. Subsequently, the target service device will process the initial data of the target service using the first vector clock and the first operation instruction to obtain the first operation data of the target service. The initial data refers to the synchronization data obtained in the previous synchronization cycle.
[0118] In step 303, the target service device acquires the second synchronization information sent from other service devices. It can be seen that in order to avoid concurrent conflicts, the second synchronization information is generated according to the second vector clock and the variable data of the second operation.
[0119] Similar to the first vector clock, the second vector clock is obtained by updating the initial vector clock after the other service device obtains the second operation instruction for the target service. In particular, the initial vector clock in the other service device is exactly the same as the initial vector clock in the target service device.
[0120] The variable data of the second operation is used to represent the change in the data of the target service of the other service device before and after the second operation. For example, if the second operation is a deletion operation, the variable data may represent the data of the deleted target service after the second operation; for another example, if the second operation is an assignment operation, the variable data may represent the current data of the target service after the assignment by the second operation.
[0121] In step 304, the target service device will use the obtained second synchronization information to synchronize the aforementioned first operation data, and obtain the synchronization data of the target service of the current synchronization cycle, which will be used as the initial data of the target service of the next synchronization cycle. At the same time, the target service device will also use the second synchronization information to update the first synchronization vector clock, so as to obtain the synchronization vector clock of the current synchronization cycle, and use it as the initial vector clock of the next synchronization cycle. During synchronization, since the vector clock at the time of operation is recorded in both the variable data in the second synchronization information and the first operation data, there will be no data synchronization conflicts such as concurrent assignment conflicts or concurrent assignment and deletion conflicts when the data is synchronously updated between the two.
[0122] On the basis of the above embodiments, in the implementation mode of the present application, the operation type of the operation instruction for the target service is different, and under different operation types, the target service device will update the vector clock in different ways. Therefore, in an optional implementation mode, the first operation instruction includes the operation type; updating the initial vector clock in step 302 to obtain the first vector clock may specifically include: updating the logical clock of the target service device in the initial vector clock according to the operation type of the first operation instruction, and the updated vector clock is the first vector clock.
[0123] Vector clocks are generally used to indicate the creation time of a value. The operation type in the first operation instruction is an assignment operation, where an assignment operation refers to an operation of assigning a value to a target service, which also means that a new value will be created and stored in the target service. In this case, the target service device can add one to the logical clock of the target service device in the initial vector clock as the logical clock of the target service device in the first vector clock to obtain the first vector clock.
[0124] Specifically, the vector clock is composed of the logical clocks of different service devices, that is, the vector clock is expressed as [VA, VB]. The value corresponding to "VA" is the logical clock corresponding to service device A, and the value corresponding to "VB" is the logical clock corresponding to service device B.
[0125] For example, assume that the initial vector clock is represented as [0,1], where "0" is used as the logical clock of the target business device in the initial vector clock, and "1" is used as the logical clock of other business devices in the initial vector clock. At this time, if the target business device obtains the operation type of the first operation instruction as an assignment operation, the target business device will add one to the logical clock in the initial vector clock to obtain "1", and form the first vector clock with the logical clocks of other business devices in the initial vector clock, that is, [1,1].
[0126] Correspondingly, when the operation type in the first operation instruction indicates a delete operation, it indicates that the first operation instruction is an instruction for deleting the value currently assigned in the target service. Since the value deleted by the first operation instruction is a value created and stored at a historical moment, that is, this first operation will not create new data in the target service. In this case, the target service device directly uses the logical clock of the target service device in the initial vector clock as the logical clock of the target service device in the first vector clock to obtain the first vector clock.
[0127] For example, it is still assumed that the initial vector clock is represented as [0,1], where "0" is used as the logical clock of the target business device in the initial vector clock, and "1" is used as the logical clock of other business devices in the initial vector clock. At this time, if the target business device obtains that the operation type of the first operation instruction is a delete operation, then the target business device will directly use the logical clock "0" in the initial vector clock and the logical clocks of other business devices in the initial vector clock to form the first vector clock, that is, [0,1].
[0128] Of course, the update of the first vector clock is based on the second vector clock. In an optional implementation, the target service device will overwrite the logical clock corresponding to the first vector clock in the other service device according to the logical clock corresponding to the second vector clock in the other service device in the second synchronization information, so as to obtain the synchronous vector clock of the current synchronization cycle.
[0129] For example, assuming that the first vector clock is represented as [1,1], where "1" is used as the logical clock of the target service device in the first vector clock, and "1" is used as the logical clock of other service devices in the first vector clock, then if the second vector clock of the target service device that obtains the second synchronization information is represented as [0,2], then the target service device will determine the logical clock of other service devices in the second vector clock, that is, "2". Then, the target service device will use the logical clock "2" in the second vector clock and the logical clock of the target service device in the first vector clock to form a synchronous vector clock, that is, [1,2].
[0130] It should be noted that after each data synchronization is completed, the synchronization vector clocks of different service devices are the same. In the above example, the initial vector clocks of the target service device and other service devices are [0,1]. After the first operation and the second operation are performed respectively, the first vector clock of the target service device is [1,1], and the second vector clocks of other service devices are [0,2].
[0131] During data synchronization, the target service device will update the first vector clock [1,1] according to the second vector clock [0,2] to obtain the synchronized vector clock [1,2]; and other service devices will update the second vector clock [0,2] according to the first vector clock [1,1] to obtain the synchronized vector clock [1,2]. At this point, the target service device and other service devices obtain the same synchronized vector clock in the current synchronization cycle, and the synchronized vector clock will be used as the initial vector clock of the target service device and other service devices in the next synchronization cycle.
[0132] The above-mentioned method of updating the vector clock can ensure that the vector clocks in each service device remain consistent, which is conducive to each service device effectively processing the data of its own target service according to its own vector clock.
[0133] On the basis of the above-mentioned implementation modes, in the implementation mode of the present application, the data of the target service can be stored in the form of triple data, and the triple data composed of different elements also constitute different data elements of the target service. In order to ensure that there is no conflict during data synchronization, the triple data will include elements based on the vector clock to distinguish the values obtained by each operation.
[0134] In an optional implementation manner, the initial data includes at least one initial triplet data, each of which includes a data value, an execution device identifier, and a logical clock of the execution device when creating the initial triplet data; the first operation instruction also includes an operation value;
[0135] Under different operation types, the results of the first operation are also different:
[0136] If the operation type is an assignment operation, performing a first operation on the initial data of the target service according to the first vector clock and the first operation instruction in step 301 to obtain first operation data of the target service specifically includes:
[0137] According to the operation value, the target service device identifier, and the logical clock of the target service device in the first vector clock, assignment triplet data is generated, and the assignment triplet data and the initial triplet data in the initial data will constitute the first operation data of the target service.
[0138] Specifically, assuming that the initial data is represented as {a, 1, A}{b, 1, B}, it means that when the logical clock of business device A (target business device) is 1, business device A assigns the target business to a, and when the logical clock of business device B is 1, business device B assigns the target business to b; the initial vector clock is represented as [1,1].
[0139] If service device A (target service device) obtains the first operation instruction, the first operation instruction is an assignment operation, and its operation is to assign the target service to c. The target service device will update the initial vector clock to obtain the first vector clock [2,1] (the update process can refer to the above implementation).
[0140] At this time, business device A will generate an assignment triplet data {c, 2, A} based on the operation value "c" in the first operation instruction, the target business device identifier "A", and the logical clock "2" of the target business device in the first vector clock, and the assignment triplet data {c, 2, A} and the initial triplet data {a, 1, A}{b, 1, B} in the initial data will constitute the first operation data of the target business, that is, the first operation data includes: {a, 1, A}{b, 1, B}{c, 2, A}.
[0141] If the operation type is a delete operation, performing a first operation on the initial data of the target service according to the first vector clock and the first operation instruction in step 301 to obtain first operation data of the target service specifically includes:
[0142] According to the operation value, the data value to be deleted is found in each data value of the initial triplet data, and the initial triplet data corresponding to the data value to be deleted in the initial data is deleted. The remaining initial triplet data in the initial data is the first operation data of the target business.
[0143] Specifically, assuming that the initial data is represented as {a, 1, A}{b, 1, B}, it means that when the logical clock of business device A (target business device) is 1, business device A assigns the target business to a, and when the logical clock of business device B is 1, business device B assigns the target business to b; the initial vector clock is represented as [1,1].
[0144] If service device A (target service device) obtains the first operation instruction, the first operation instruction is a delete operation, and the operation is to delete the data assigned to b in the target service. The target service device will update the initial vector clock to obtain the first vector clock [1,1] (the update process can be referred to the above implementation).
[0145] At this time, business device A will directly find the data value "b" to be deleted in each data value of each initial triplet data {a, 1, A}{b, 1, B} according to the operation value "b" in the first operation instruction, and delete the initial triplet data corresponding to the data value to be deleted in the initial data, that is, {b, 1, B}. The remaining initial triplet data in the initial data is the first operation data of the target business, that is, the first operation data is {a, 1, A}.
[0146] The above embodiments describe how to perform a first operation on the initial data of the target service in the target service device based on different first operation instructions and in combination with a vector clock to obtain first operation data. Based on the above embodiments, how to perform data synchronization on the first operation data obtained above based on different types of second synchronization information sent by other service devices will be described below.
[0147] In an optional implementation, the variable data of the second operation includes a change type of the variable data and the variable triplet data; wherein the change type includes a deletion type or an assignment type; the variable triplet data includes an operation value of the second operation, other business device identifiers, and the logical clock of other business devices in the second vector clock.
[0148] Among them, when the change type indicated by the variable data of the second operation in the second synchronization information is an assignment type, the target business device in step 304 synchronizes the first operation data of the target business according to the second synchronization information to obtain the synchronization data of the target business in the current synchronization period, which may specifically include: the target business device uses the variable triplet data of the variable data in the second synchronization information and the triplet data in the first operation data to form the synchronization data of the target business in the current synchronization period.
[0149] For example, assume that the initial data is represented as {a, 1, A}{b, 1, B}, and the initial vector clock is represented as [1, 1]. In the current synchronization cycle, as shown in the above implementation, service device A (target service device) executes the first operation instruction (assignment operation) to obtain the first operation data {a, 1, A}{b, 1, B}{c, 2, A}, and the first vector clock represents [2, 1]. Service device B (other service device) will execute the second operation instruction represented as the assignment operation (such as assigning the target service to d), and obtain the second operation data {a, 1, A}{b, 1, B}{d, 2, B}, and the second vector clock represents [1, 2].
[0150] When data synchronization is triggered, service device A (target service device) will receive the second synchronization information sent from service device B (other service device), wherein the second synchronization information will include the variable triplet data "{d, 2, B}" of the variable data and the change type "assignment type" of the variable data. Based on the change type of the variable data being the assignment type, service device A (target service device) will merge the variable triplet data {d, 2, B} with the triplet data {a, 1, A}{b, 1, B}{c, 2, A} in its original first operation data to obtain the synchronization data {a, 1, A}{b, 1, B}{c, 2, A}{d, 2, B} of the target service in the current synchronization cycle. At the same time, the first vector clock [2, 1] is updated to obtain the synchronous vector clock [2, 2].
[0151] Among them, when the change type indicated by the variable data of the second operation in the second synchronization information is a deletion type, the target business device in step 304 synchronizes the first operation data of the target business according to the second synchronization information to obtain the synchronization data of the target business in the current synchronization period, which may specifically include: the target business device deletes the triplet data that is identical to the variable triplet data in each triplet data of the first operation data, and the remaining triplet data in the first operation data constitutes the synchronization data of the target business in the current synchronization period.
[0152] For example, it is still assumed that the initial data is represented as {a, 1, A}{b, 1, B}, and the initial vector clock is represented as [1, 1]. In the current synchronization cycle, as shown in the above implementation, service device A (target service device) executes the first operation instruction (assignment operation) to obtain the first operation data {a, 1, A}{b, 1, B}{c, 2, A}, and the first vector clock represents [2, 1]. Service device B (other service device) will execute the second operation instruction represented as a deletion operation (such as deleting the data assigned to b in the target service) and obtain the second operation data {a, 1, A}, and the second vector clock represents [1, 1].
[0153] When data synchronization is triggered, service device A (target service device) will receive the second synchronization information sent from service device B (other service device), wherein the second synchronization information will include the variable triplet data "{b, 1, B}" of the variable data and the change type "deletion type" of the variable data. Based on the fact that the change type of the variable data is the deletion type, service device A (target service device) will find the triplet data that is consistent with the variable triplet data {b, 1, B} from its current triplet data and delete the triplet data {b, 1, B}. The remaining triplet data in the first operation data is the synchronization data, i.e., the synchronization data {a, 1, A} of the target service in the current synchronization cycle. At the same time, the first vector clock [2, 1] is updated to obtain the synchronous vector clock [2, 1].
[0154] Of course, based on the above-mentioned implementation modes, the target business device will also send the first synchronization information including the variable data of the first operation and the change type of the variable data to other business devices, so that the other business devices can use the same method as the target business device to perform data synchronization, so as to ensure that the synchronization data and synchronization vector clock obtained by different business devices in the same synchronization cycle are exactly the same.
[0155] Based on this, in an optional implementation manner, after obtaining the first operation data of the target business, the target business device further includes: determining the variable data of the first operation, and generating first synchronization information based on the variable data of the first operation and the first vector clock; the variable data of the first operation is used to represent the change in the data of the target business of the target business device before and after the first operation; sending the first synchronization information to the other business devices, so that the other business devices can synchronize the second operation data and the second vector clock of the target business according to the first synchronization information, respectively, to obtain the synchronization data and synchronization vector clock of the target business in the current synchronization cycle, and the synchronization vector clock of the current synchronization cycle will be used as the initial vector clock of the next synchronization cycle; wherein, the second operation data is obtained by the other business devices performing a second operation on the initial data of the target business according to the second vector clock and the second operation instruction.
[0156] Furthermore, the target business device needs to determine the variable data of the first operation, that is, determine the variable triplet data between the initial triplet data of the initial data and the triplet data of the first operation data; wherein the variable triplet data includes the operation value of the first operation, the target business device identifier, and the logical clock of the target business device in the first vector clock; and determine the change type of the variable data according to the operation type in the first operation instruction.
[0157] For example, assuming that the initial data is represented as {a, 1, A}{b, 1, B}, and the initial vector clock is represented as [1, 1]. In the current synchronization cycle, as shown in the above implementation, the service device A (target service device) executes the first operation instruction (assignment operation) to obtain the first operation data {a, 1, A}{b, 1, B}{c, 2, A}, and the first vector clock represents [2, 1].
[0158] The variable triplet data between the initial triplet data and each triplet data of the first operation data is {c, 2, A}. Since the first operation is an assignment operation, the change type of the variable data is the assignment type. At this time, the first synchronization information determined by the target business device is: {c, 2, A}, assignment type, [2, 1]. The first synchronization information will be sent to other business devices for data synchronization processing.
[0159] In order to better describe the present application, the data synchronization method provided by the present application will be further explained below using different examples.
[0160] Figure 4 A flowchart of a data synchronization method based on a remote multi-active system for processing concurrent assignment conflicts provided in an embodiment of the present application. Figure 4 Data processing is based on set type.
[0161] like Figure 4 As shown, the remote multi-active system includes a service device A and a service device B. The service device A is used as a target service device, and the service device B is used as another service device.
[0162] At time t0 (the initial time of the current synchronization cycle), the initial data of the target service in service device A and service device B are both null values, and the initial vector clock is represented as [0,0].
[0163] At time t1, service device A receives a first operation instruction "add a (assign value to a)", and at the same time, service device B receives a second operation instruction "add b (assign value to b)".
[0164] At this time, since both the first operation instruction and the second operation instruction are assignment operations, service device A will update its initial vector clock [0,0] to [1,0], and service device B will update its initial vector clock [0,0] to [0,1]. At the same time, service device A executes the first operation instruction to obtain the first operation data {a,1,A}; service device B executes the second operation instruction to obtain the second operation data {b,1,B}.
[0165] At time t2, business device A and business device B simultaneously trigger data synchronization processing. Based on the data synchronization method provided in the present application, at this time, business device A will send the first synchronization information to business device B: {a, 1, A}, assignment type, [1, 0]; business device B will send the second synchronization information to business device A: {b, 1, B}, assignment type, [0, 1].
[0166] For business device A, since the change type of the variable data in the second synchronization information is the assignment type, it will add the variable data {b,1,B} to the data set so that the set of the first operation data and the variable data constitutes the synchronization data, that is, {a,1,A}{b,1,B}. At the same time, business device A will update its first vector clock [1,0] according to the second vector clock [0,1] to obtain the synchronous vector clock [1,1].
[0167] At the same time, for business device B, since the change type of the variable data in the first synchronization information is the assignment type, it will add the variable data {a,1,A} to the data set so that the set of second operation data and variable data constitutes synchronization data, that is, {a,1,A}{b,1,B}. At the same time, business device B will update its second vector clock [0,1] according to the first vector clock [1,0] to obtain the synchronous vector clock [1,1].
[0168] At this point, the data synchronization processing of this synchronization cycle is completed, and service device A and service device B will obtain exactly the same synchronization data and synchronization vector clock, which will also be used as the initial data and initial vector clock of the next synchronization cycle.
[0169] Figure 5 Another data synchronization method based on a remote multi-active system provided in the present application is a flow chart of processing concurrent assignment conflicts. Figure 5 Data processing is based on the String type.
[0170] and Figure 4 The difference is that Figure 5 In this way, a timestamp may be additionally recorded in the triplet data of the data, so that the data can be better recorded and conflicts can be handled.
[0171] like Figure 5 As shown, the remote multi-active system includes a service device A and a service device B. The service device A is used as a target service device, and the service device B is used as another service device.
[0172] At time t0 (the initial time of the current synchronization cycle), the initial data of the target service in service device A and service device B are both null values, and the initial vector clock is represented as [0,0].
[0173] At time t1, service device A receives the first operation instruction "set key = a (assign Key to a)". Since the first operation instruction is an assignment operation, service device A updates its initial vector clock [0,0] to [1,0]. Service device A executes the first operation instruction and obtains the first operation data key = {a, (1, A), t1};
[0174] At time t2, service device B receives the second operation instruction "set key = b (assign Key to b)". Since the second operation instructions are all assignment operations, service device B will update its initial vector clock [0,0] to [0,1]. At the same time, service device B executes the second operation instruction and obtains the second operation data key = {b, (1, B), t2}.
[0175] At time t3, business device A and business device B simultaneously trigger data synchronization processing. At this time, since both the first operation data and the second operation data include timestamps, and by comparing the timestamps, it can be seen that the execution time of the second operation instruction is later than the execution time of the first operation instruction. At this time, the key in the final synchronization data should be assigned the value of b.
[0176] During synchronization, service device A will send the first synchronization information to service device B: key = {a, (1, A), t1}, assignment type, [1, 0]; service device B will send the second synchronization information to service device A: key = {b, (1, B), t2}, assignment type, [0, 1].
[0177] For business device A, since the change type of the variable data in the second synchronization information is the assignment type, it will add the variable data key = {b, (1, B), t2} to the data set, so that the set of the first operation data and the variable data constitutes the synchronization data, that is, key = {a, (1, A), t1} and key = {b, (1, B), t2}. Since in string type data, the same element key cannot have two values, at this time, business device A will use the data with a later timestamp as the key value, and update its logical clock to finally obtain key = {b, (1, A), (1, B), t2}.
[0178] At the same time, service device A updates its first vector clock [1,0] according to the second vector clock [0,1] to obtain the synchronous vector clock [1,1].
[0179] At the same time, for business device B, since the change type of the variable data in the first synchronization information is the assignment type, it will add the variable data key = {a, (1, A), t1} to the data set, so that the set of the second operation data and the variable data constitutes the synchronization data, that is, key = {a, (1, A), t1} and key = {b, (1, B), t2}. Since in string type data, the same element key cannot have two values, at this time, business device B will use the data with a later timestamp as the key value, and update its logical clock to finally obtain key = {b, (1, A), (1, B), t2}.
[0180] At the same time, service device B updates its second vector clock [0,1] according to the first vector clock [1,0] to obtain a synchronous vector clock [1,1].
[0181] At this point, the data synchronization processing of this synchronization cycle is completed, and service device A and service device B will obtain exactly the same synchronization data and synchronization vector clock, which will also be used as the initial data and initial vector clock of the next synchronization cycle.
[0182] Figure 6 A flowchart of a data synchronization method based on a remote multi-active system provided in an embodiment of the present application for handling concurrent assignment and deletion conflicts. Figure 6 Data processing is based on set type.
[0183] like Figure 6 As shown, the remote multi-active system includes a service device A and a service device B. The service device A is used as a target service device, and the service device B is used as another service device.
[0184] At time t0 (the initial time of the current synchronization cycle), the initial data of the target service in service device A and service device B are both {a,1,A}{b,1,B}{b,2,A}, and the initial vector clock is expressed as [2,1].
[0185] At time t1, service device A receives a first operation instruction "add b (assign value to b)", and at the same time, service device B receives a second operation instruction "rem b (delete b)".
[0186] At this time, since the first operation instruction is an assignment operation and the second operation instruction is a deletion operation, service device A will update its initial vector clock [2,1] to [3,1], and service device B will update its initial vector clock [2,1] to [2,1].
[0187] At the same time, business device A executes the first operation instruction and obtains first operation data {a, 1, A} {b, 1, B} {b, 2, A} {b, 3, A}; business device B executes the second operation instruction and obtains second operation data {a, 1, A}.
[0188] At time t2, business device A and business device B simultaneously trigger data synchronization processing. Based on the data synchronization method provided in the present application, at this time, business device A will send the first synchronization information to business device B: {b,3,A}, assignment type, [3,1]; business device B will send the second synchronization information to business device A: {b,1,B}{b,2,A}, deletion type, [2,1].
[0189] For business device A, since the change type of the variable data in the second synchronization information is the deletion type, it will delete the variable data {b,1,B}{b,2,A} from the data set of the first operation data to obtain the synchronization data, namely {a,1,A}{b,3,A}. At the same time, business device A will update its first vector clock [3,1] according to the second vector clock [2,1] to obtain the synchronous vector clock [3,1].
[0190] At the same time, for business device B, since the change type of the variable data in the first synchronization information is the assignment type, it will add the variable data {b,3,A} to the data set so that the set of the second operation data and the variable data constitutes the synchronization data, that is, {a,1,A}{b,3,A}. At the same time, business device B will update its second vector clock [2,1] according to the first vector clock [3,1] to obtain the synchronous vector clock [3,1].
[0191] At this point, the data synchronization processing of this synchronization cycle is completed, and service device A and service device B will obtain exactly the same synchronization data and synchronization vector clock, which will also be used as the initial data and initial vector clock of the next synchronization cycle.
[0192] Figure 7 Another data synchronization method based on a remote multi-active system provided in the present application is a flowchart for processing concurrent assignment and deletion conflicts. Figure 7 Data processing is based on the String type.
[0193] and Figure 6 The difference is that Figure 7 In this way, a timestamp may be additionally recorded in the triplet data of the data, so that the data can be better recorded and conflicts can be handled.
[0194] like Figure 7As shown, the remote multi-active system includes a service device A and a service device B. The service device A is used as a target service device, and the service device B is used as another service device.
[0195] At time t3 (the initial time of the current synchronization cycle), the initial data of the target service in service device A and service device B are both key = {b, (1, A), (1, B), t2}, and the initial vector clock is represented as [1, 1].
[0196] At time t4, service device A receives the first operation instruction "set key = c (assign Key to c)". Since the first operation instruction is an assignment operation, service device A updates its initial vector clock [1,1] to [2,1]. Service device A executes the first operation instruction and obtains the first operation data key = {c, (2, A), (1, B), t4}.
[0197] At time t5, service device B receives the second operation instruction "del key (delete the Key value)". Since the second operation instruction is a delete operation, service device B updates its initial vector clock [1,1] to [1,1]. At the same time, service device B executes the second operation instruction and obtains the second operation data key={}.
[0198] At time t6, business device A and business device B simultaneously trigger data synchronization processing. At this time, business device A will send the first synchronization information to business device B: key = {c, (2, A), t4}, assignment type, [2, 1]; business device B will send the second synchronization information to business device A: key = {b, (1, A), (1, B), t5}, deletion type, [1, 1].
[0199] For business device A, since the change type of the variable data in the second synchronization information is deletion type, it will delete the variable data key = {b, (1, A), (1, B), t2} from the data set of the first operation data to obtain synchronization data, that is, key = {c, (2, A), t4}.
[0200] At the same time, service device A updates its first vector clock [2, 1] according to the second vector clock [1, 1] to obtain the synchronous vector clock [2, 1].
[0201] At the same time, for business device B, since the change type of the variable data in the first synchronization information is the assignment type, it will add the variable data key = {c, (2, A), t4} to the data set so that the set of the second operation data and the variable data constitutes the synchronization data, that is, key = {c, (2, A), t4}.
[0202] At the same time, service device B updates its second vector clock [1, 1] according to the first vector clock [2, 1] to obtain the synchronous vector clock [2, 1].
[0203] At this point, the data synchronization processing of this synchronization cycle is completed, and service device A and service device B will obtain exactly the same synchronization data and synchronization vector clock, which will also be used as the initial data and initial vector clock of the next synchronization cycle.
[0204] The method provided above can effectively record the vector clock of the operation in the data obtained from each operation on the target business in the business device. During synchronization, the synchronization information sent by other business devices will also record the vector clocks of other business devices when performing operations. By synchronizing the data through the two vector clocks, the order and scope of operations of different business devices when operating the data of the same target business can be effectively distinguished, thereby effectively solving the above-mentioned Figure 1 The problem of concurrency conflicts mentioned.
[0205] Embodiment 2
[0206] Corresponding to the data synchronization method based on the remote multi-active system in the above embodiment, Figure 8 A schematic diagram of the structure of a business device provided in an embodiment of the present application, wherein the business device belongs to a remote multi-active system, wherein the remote multi-active system includes different business devices located in different geographical areas, and the data synchronization method is executed by a target business device among the multiple business devices; Figure 8 As shown, the service device includes: a transceiver module 10 , a synchronization processing module 20 and an execution module 30 .
[0207] The transceiver module 10 is used to obtain a first operation instruction for a target service;
[0208] The synchronization processing module 20 is used to determine the initial vector clock of the current synchronization period and update the initial vector clock to obtain a first vector clock;
[0209] An execution module 30, configured to perform a first operation on the initial data of the target service according to the first vector clock and the first operation instruction to obtain first operation data of the target service;
[0210] The transceiver module 10 is further used to receive second synchronization information sent by other service devices of the remote multi-active system, where the second synchronization information includes a second vector clock and variable data of a second operation, where the second vector clock is obtained by updating the initial vector clock by the other service devices, and the variable data of the second operation is used to represent the change amount of the target service data of the other service devices before and after the second operation;
[0211] The synchronization processing module 20 is used to synchronize the first operation data and the first vector clock of the target service respectively according to the second synchronization information, so as to obtain the synchronization data and synchronization vector clock of the target service in the current synchronization cycle. The synchronization vector clock of the current synchronization cycle will be used as the initial vector clock of the next synchronization cycle.
[0212] In an optional implementation manner, the first operation instruction includes an operation type;
[0213] The synchronization processing module 20 is specifically configured to update the logical clock of the target service device in the initial vector clock according to the operation type of the first operation instruction, and the updated vector clock is the first vector clock.
[0214] In an optional implementation manner, the synchronization processing module 20 is specifically used to:
[0215] If the operation type is an assignment operation, adding one to the logical clock of the target service device in the initial vector clock to obtain the first vector clock as the logical clock of the target service device in the first vector clock;
[0216] If the operation type is a delete operation, the logical clock of the target service device in the initial vector clock is directly used as the logical clock of the target service device in the first vector clock to obtain the first vector clock.
[0217] In an optional implementation, the synchronization processing module 20 is used to overwrite the logical clock corresponding to the first vector clock in the other business equipment according to the logical clock corresponding to the second vector clock in the other business equipment in the second synchronization information, so as to obtain the synchronous vector clock of the current synchronization cycle.
[0218] In an optional implementation manner, the initial data includes at least one initial triplet data, each of which includes a data value, an execution device identifier, and a logical clock of the execution device when creating the initial triplet data;
[0219] The first operation instruction also includes an operation value;
[0220] The execution module 30 is specifically used for:
[0221] If the operation type is an assignment operation, generating assignment triplet data according to the operation value, the target service device identifier, and the logical clock of the target service device in the first vector clock, and the assignment triplet data and the initial triplet data in the initial data will constitute the first operation data of the target service;
[0222] If the operation type is a deletion operation, the data value to be deleted is found in each data value of the initial triplet data according to the operation value, and the initial triplet data corresponding to the data value to be deleted in the initial data is deleted, and the remaining initial triplet data in the initial data is the first operation data of the target business.
[0223] In an optional implementation manner, the variable data of the second operation includes a change type of the variable data and the variable triplet data;
[0224] Wherein, the change type includes a deletion type or an assignment type;
[0225] The variable triplet data includes an operation value of the second operation, identifiers of other service devices, and logical clocks of other service devices in the second vector clock;
[0226] A synchronization processing module 20, specifically configured to, if the change type of the variable data of the second operation in the second synchronization information is an assignment type, then the variable triplet data of the variable data in the second synchronization information and the triplet data in the first operation data constitute the synchronization data of the target service in the current synchronization cycle;
[0227] If the change type of the variable data of the second operation in the second synchronization information is a deletion type, then the triplet data identical to the variable triplet data is deleted in each triplet data of the first operation data, and the remaining triplet data in the first operation data constitutes the synchronization data of the target service in the current synchronization cycle.
[0228] In an optional embodiment, after obtaining the first operation data of the target service, the synchronization processing module 20 is further configured to:
[0229] Determine variable data of the first operation, and generate first synchronization information according to the variable data of the first operation and the first vector clock; the variable data of the first operation is used to represent the change amount of the target service data of the target service device before and after the first operation;
[0230] The transceiver module 10 is further used to send the first synchronization information to the other service equipment, so that the other service equipment can synchronize the second operation data and the second vector clock of the target service respectively according to the first synchronization information, and obtain the synchronization data and the synchronization vector clock of the target service in the current synchronization cycle, and the synchronization vector clock of the current synchronization cycle will be used as the initial vector clock of the next synchronization cycle;
[0231] The second operation data is obtained by the other service device performing a second operation on the initial data of the target service according to the second vector clock and the second operation instruction.
[0232] In an optional implementation manner, the synchronization processing module 20 is further used to:
[0233] Determine the variable triplet data between the initial triplet data of the initial data and the triplet data of the first operation data; wherein the variable triplet data includes the operation value of the first operation, the target business device identifier, and the logical clock of the target business device in the first vector clock; determine the change type of the variable data according to the operation type in the first operation instruction.
[0234] An embodiment of the present application provides a business device based on a multi-site active-active system, wherein a first operation instruction for a target business is obtained, and an initial vector clock of a current synchronization cycle is determined; the initial vector clock is updated to obtain a first vector clock, and a first operation is performed on the initial data of the target business according to the first vector clock and the first operation instruction to obtain first operation data of the target business; second synchronization information sent by other business devices in the multi-site active-active system is received, the second synchronization information includes a second vector clock and variable data of a second operation, the second vector clock is obtained by updating the initial vector clock by the other business devices, and the variable data of the second operation is used to represent the change in the data of the target business of the other business devices before and after the second operation; the first operation data and the first vector clock of the target business are synchronized respectively according to the second synchronization information to obtain the synchronization data and synchronization vector clock of the target business in the current synchronization cycle, and the synchronization vector clock of the current synchronization cycle will be used as the initial vector clock of the next synchronization cycle. This solution uses vector clocks to mark the data obtained from operations performed by different business devices, so that when data is synchronized for each business device, conflicting operations can be effectively processed and resolved based on the vector clock marking of the data, effectively improving the data synchronization efficiency of the multi-site active-active system.
[0235] Embodiment 3
[0236] Fig. 9A schematic diagram of the structure of an electronic device provided by an embodiment of the present invention, such as Fig. 9 As shown, an embodiment of the present invention further provides an electronic device 1400, including: a memory 1401, a processor 1402 and a computer program.
[0237] The computer program is stored in the memory 1401 and is configured to be executed by the processor 1402 to implement the data synchronization method based on the remote multi-active system provided by any embodiment of the present invention. The relevant description can be understood by referring to the relevant descriptions and effects corresponding to the steps in the accompanying drawings, and no further details are given here.
[0238] In this embodiment, the memory 1401 and the processor 1402 are connected via a bus.
[0239] Embodiment 4
[0240] An embodiment of the present invention provides a computer-readable storage medium having a computer program stored thereon. The computer program is executed by a processor to implement a data synchronization method based on a remote multi-active system provided by any embodiment of the present invention.
[0241] In the several embodiments provided by the present invention, it should be understood that the disclosed systems and methods can be implemented in other ways. For example, the system embodiments described above are only schematic, for example, the division of modules is only a logical function division, and there may be other division methods in actual implementation, such as multiple modules or components can be combined or integrated into another system, or some features can be ignored or not executed. Another point is that the mutual coupling or direct coupling or communication connection shown or discussed can be through some interfaces, indirect coupling or communication connection of systems or modules, which can be electrical, mechanical or other forms.
[0242] The modules described as separate components may or may not be physically separated, and the components shown as modules may or may not be physical modules, that is, they may be located in one place or distributed on multiple network modules. Some or all of the modules may be selected according to actual needs to achieve the purpose of the solution of this embodiment.
[0243] In addition, each functional module in each embodiment of the present invention may be integrated into one processing module, or each module may exist physically separately, or two or more modules may be integrated into one module. The above-mentioned integrated module may be implemented in the form of hardware or in the form of hardware plus software functional modules.
[0244] The program code for implementing the method of the present invention may be written in any combination of one or more programming languages. These program codes may be provided to a processor or controller of a general-purpose computer, a special-purpose computer, or other programmable question-answering system, so that when the program code is executed by the processor or controller, the functions / operations specified in the flow chart and / or block diagram are implemented. The program code may be executed entirely on the machine, partially on the machine, partially on the machine and partially on a remote machine as a stand-alone software package, or entirely on a remote machine or server.
[0245] In the context of the present invention, a machine-readable medium may be a tangible medium that may contain or store a program for use by or in conjunction with an instruction execution system, system, or device. A machine-readable medium may be a machine-readable signal medium or a machine-readable storage medium. A machine-readable medium may include, but is not limited to, an electronic, magnetic, optical, electromagnetic, infrared, or semiconductor system, system, or device, or any suitable combination of the foregoing. A more specific example of a machine-readable storage medium may 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.
[0246] In addition, the present application provides a computer program product, including a computer program, which, when executed by a processor, implements the aforementioned data synchronization method based on a remote multi-active system.
[0247] In addition, although each operation is described in a specific order, this should be understood as requiring such operation to be performed in the specific order shown or in a sequential order, or requiring that all illustrated operations should be performed to obtain desired results. Under certain circumstances, multitasking and parallel processing may be advantageous. Similarly, although some specific implementation details are included in the above discussion, these should not be interpreted as limiting the scope of the present disclosure. Some features described in the context of a separate embodiment can also be implemented in a single implementation in combination. On the contrary, the various features described in the context of a single implementation can also be implemented in multiple implementations individually or in any suitable sub-combination mode.
[0248] 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.
Claims
1. A data synchronization method based on a remote multi-active system, characterized in that: The remote multi-active system includes a plurality of business devices respectively located in a plurality of geographical areas, and the data synchronization method is executed by a target business device among the plurality of business devices; The data synchronization method comprises: Obtaining a first operation instruction for a target service, and determining an initial vector clock of a current synchronization cycle; the first operation instruction includes an operation type; According to the operation type of the first operation instruction, the logical clock of the target service device in the initial vector clock is updated to obtain a first vector clock, and according to the first vector clock and the first operation instruction, a first operation is performed on the initial data of the target service to obtain first operation data of the target service; Receiving second synchronization information sent by other service devices in the remote multi-active system, where the second synchronization information includes a second vector clock and variable data of a second operation, where the second vector clock is obtained by updating the initial vector clock by the other service devices, and the variable data of the second operation is used to represent a change in data of a target service of the other service devices before and after the second operation; According to the second synchronization information, the first operation data and the first vector clock of the target service are synchronized respectively to obtain the synchronization data and synchronization vector clock of the target service in the current synchronization cycle. The synchronization vector clock of the current synchronization cycle will be used as the initial vector clock of the next synchronization cycle.
2. The data synchronization method according to claim 1, characterized in that: The updating of the logical clock of the target service device in the initial vector clock according to the operation type of the first operation instruction includes: If the operation type is an assignment operation, adding one to the logical clock of the target service device in the initial vector clock to obtain the first vector clock as the logical clock of the target service device in the first vector clock; If the operation type is a delete operation, the logical clock of the target service device in the initial vector clock is directly used as the logical clock of the target service device in the first vector clock to obtain the first vector clock.
3. The data synchronization method according to claim 1, characterized in that: Synchronizing the first vector clock according to the second synchronization information to obtain a synchronization vector clock of a current synchronization period includes: According to the logical clock corresponding to the second vector clock in the other service equipment in the second synchronization information, the logical clock corresponding to the first vector clock in the other service equipment is overwritten to obtain the synchronous vector clock of the current synchronization cycle.
4. The data synchronization method according to any one of claims 1 to 3, characterized in that: The initial data includes at least one initial triplet data, each of which includes a data value, an execution device identifier, and a logical clock of the execution device when creating the initial triplet data; The first operation instruction also includes an operation value; The performing a first operation on the initial data of the target service according to the first vector clock and the first operation instruction to obtain first operation data of the target service includes: If the operation type is an assignment operation, generating assignment triplet data according to the operation value, the target service device identifier, and the logical clock of the target service device in the first vector clock, and the assignment triplet data and the initial triplet data in the initial data will constitute the first operation data of the target service; If the operation type is a deletion operation, the data value to be deleted is found in each data value of the initial triplet data according to the operation value, and the initial triplet data corresponding to the data value to be deleted in the initial data is deleted, and the remaining initial triplet data in the initial data is the first operation data of the target business.
5. The data synchronization method according to claim 4, characterized in that: The variable data of the second operation includes a change type of the variable data and variable triplet data; Wherein, the change type includes a deletion type or an assignment type; The variable triplet data includes an operation value of the second operation, identifiers of other service devices, and logical clocks of other service devices in the second vector clock; Synchronizing the first operation data of the target service according to the second synchronization information to obtain synchronization data of the target service in the current synchronization period includes: If the change type of the variable data of the second operation in the second synchronization information is an assignment type, the variable triplet data of the variable data in the second synchronization information and the triplet data in the first operation data constitute the synchronization data of the target service in the current synchronization period; If the change type of the variable data of the second operation in the second synchronization information is a deletion type, then the triplet data identical to the variable triplet data is deleted in each triplet data of the first operation data, and the remaining triplet data in the first operation data constitutes the synchronization data of the target service in the current synchronization cycle.
6. The data synchronization method according to claim 1, characterized in that: After obtaining the first operation data of the target business, the method further includes: Determine variable data of the first operation, and generate first synchronization information according to the variable data of the first operation and the first vector clock; the variable data of the first operation is used to represent the change amount of the target service data of the target service device before and after the first operation; The first synchronization information is sent to the other service equipment, so that the other service equipment can synchronize the second operation data and the second vector clock of the target service respectively according to the first synchronization information, and obtain the synchronization data and the synchronization vector clock of the target service in the current synchronization cycle, and the synchronization vector clock of the current synchronization cycle will be used as the initial vector clock of the next synchronization cycle; The second operation data is obtained by the other service device performing a second operation on the initial data of the target service according to the second vector clock and the second operation instruction.
7. The data synchronization method according to claim 6, characterized in that: The determining of the variable data of the first operation includes: Determine variable triplet data between initial triplet data of the initial data and each triplet data of the first operation data; wherein the variable triplet data includes an operation value of the first operation, a target service device identifier, and a logical clock of the target service device in the first vector clock; According to the operation type in the first operation instruction, the change type of the variable data is determined.
8. A service device, characterized in that: The business equipment belongs to a remote multi-active system, and the remote multi-active system includes different business equipment located in different geographical areas; The business equipment includes: A transceiver module, configured to obtain a first operation instruction for a target service; the first operation instruction includes an operation type; A synchronization processing module, used to determine an initial vector clock of a current synchronization cycle, and update a logical clock of a target service device in the initial vector clock according to an operation type of the first operation instruction to obtain a first vector clock; an execution module, configured to execute a first operation on the initial data of the target service according to the first vector clock and the first operation instruction, so as to obtain first operation data of the target service; The transceiver module is further used to receive second synchronization information sent by other service devices of the remote multi-active system, where the second synchronization information includes a second vector clock and variable data of a second operation, where the second vector clock is obtained by updating the initial vector clock by the other service devices, and the variable data of the second operation is used to represent a change in data of a target service of the other service devices before and after the second operation; A synchronization processing module is used to synchronize the first operation data and the first vector clock of the target service respectively according to the second synchronization information, so as to obtain the synchronization data and synchronization vector clock of the target service in the current synchronization cycle. The synchronization vector clock of the current synchronization cycle will be used as the initial vector clock of the next synchronization cycle.
9. An electronic device, characterized in that: include: at least one processor and memory; The memory stores computer-executable instructions; The at least one processor executes the computer-executable instructions stored in the memory, so that the at least one processor performs the method according to any one of claims 1 to 7.
10. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores computer-executable instructions, and when the processor executes the computer-executable instructions, the method according to any one of claims 1 to 7 is implemented.
11. A computer program product, comprising a computer program, characterized in that When the computer program is executed by a processor, the method according to any one of claims 1 to 7 is implemented.
