CN113971181A - Data synchronization method and device based on remote multi-active system - Google Patents

Data synchronization method and device based on remote multi-active system Download PDF

Info

Publication number
CN113971181A
CN113971181A CN202111299131.0A CN202111299131A CN113971181A CN 113971181 A CN113971181 A CN 113971181A CN 202111299131 A CN202111299131 A CN 202111299131A CN 113971181 A CN113971181 A CN 113971181A
Authority
CN
China
Prior art keywords
data
vector clock
synchronization
target service
initial
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Pending
Application number
CN202111299131.0A
Other languages
Chinese (zh)
Inventor
罗明
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Jingdong Technology Information Technology Co Ltd
Original Assignee
Jingdong Technology Information Technology Co Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Jingdong Technology Information Technology Co Ltd filed Critical Jingdong Technology Information Technology Co Ltd
Priority to CN202111299131.0A priority Critical patent/CN113971181A/en
Publication of CN113971181A publication Critical patent/CN113971181A/en
Pending legal-status Critical Current

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/20Information retrieval; Database structures therefor; File system structures therefor of structured data, e.g. relational data
    • G06F16/23Updating
    • G06F16/2365Ensuring data consistency and integrity
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/20Information retrieval; Database structures therefor; File system structures therefor of structured data, e.g. relational data
    • G06F16/21Design, administration or maintenance of databases
    • G06F16/215Improving data quality; Data cleansing, e.g. de-duplication, removing invalid entries or correcting typographical errors
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/20Information retrieval; Database structures therefor; File system structures therefor of structured data, e.g. relational data
    • G06F16/27Replication, distribution or synchronisation of data between databases or within a distributed database system; Distributed database system architectures therefor

Landscapes

  • Engineering & Computer Science (AREA)
  • Theoretical Computer Science (AREA)
  • Databases & Information Systems (AREA)
  • Data Mining & Analysis (AREA)
  • Physics & Mathematics (AREA)
  • General Engineering & Computer Science (AREA)
  • General Physics & Mathematics (AREA)
  • Quality & Reliability (AREA)
  • Computer Security & Cryptography (AREA)
  • Computing Systems (AREA)
  • Synchronisation In Digital Transmission Systems (AREA)

Abstract

According to the data synchronization method and device based on the remote multi-active system, the first operation instruction for the target service is obtained, and the initial vector clock of the current synchronization period is determined; updating the initial vector clock to obtain a first vector clock, and executing a first operation on 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; and receiving second synchronous information sent by other service equipment of the remote multi-active system, wherein the second synchronous information comprises a second vector clock and variable data of a second operation, and synchronizing the first operation data and the first vector clock of the target service respectively according to the second synchronous information to obtain synchronous data and a synchronous vector clock of the target service in the current synchronous period. According to the scheme, the vector clock is utilized to mark data obtained by operations executed by different business devices, so that the data synchronization efficiency of the multi-active system in different places is effectively improved.

Description

Data synchronization method and device based on remote multi-active system
Technical Field
The present application relates to the field of computer technologies, and in particular, to a data synchronization method and apparatus based on a remote multi-active system.
Background
With the rapid development of the internet industry, it is a mainstream trend to deploy services by using a remote multi-active system. Generally, a remote multi-active system includes a plurality of service devices disposed in different geographic areas, and based on the geographic area where a user is located, a service access or a service request initiated by the user is sent to the service device in the corresponding geographic area for processing.
In order to avoid cross-regional service access of users, each service device needs to perform data synchronization at regular time to ensure data consistency. In the prior art, in order to avoid a concurrency conflict occurring in a data synchronization process, each service device performs data splitting on data related to service access, so as to ensure that service operation data in each service device are different, and avoid a concurrency conflict occurring in a subsequent data synchronization process.
However, such a processing method needs to modify the service itself, and since the service logic in the remote multi-active system is relatively complex, such a processing method easily causes omission of service data, and is not efficient and accurate. Therefore, it is difficult to provide an efficient and simple data synchronization method.
Disclosure of Invention
The embodiment of the application provides a data synchronization method and device based on a remote multi-active system, and is used for providing an efficient data synchronization method for the remote multi-active system.
In a first aspect, the present application provides a data synchronization method based on a remote multi-active system, where the remote multi-active system includes a plurality of service devices respectively located in a plurality of geographic areas, and the data synchronization method is performed by a target service device in the plurality of service devices;
the data synchronization method comprises the following steps:
acquiring a first operation instruction of a target service, and determining an initial vector clock of a current synchronization period;
updating the initial vector clock to obtain a first vector clock, and executing 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;
receiving second synchronization information sent by other service equipment of the remote multi-active system, wherein the second synchronization information comprises a second vector clock and second operated variable data, the second vector clock is obtained by updating the initial vector clock by the other service equipment, and the second operated variable data is used for representing the variable quantity of the target service data of the other service equipment before second operation and after the second operation;
and respectively synchronizing the first operation data of the target service and the first vector clock according to the second synchronization information to obtain the synchronization data and the synchronization vector clock of the target service in the current synchronization period, wherein the synchronization vector clock of the current synchronization period is used as the initial vector clock of the next synchronization period.
In an alternative embodiment, the first operation instruction includes an operation type;
the updating the initial vector clock to obtain a first vector clock includes:
and updating the logic clock of the target service equipment in the initial vector clock according to the operation type of the first operation instruction, wherein the updated vector clock is the first vector clock.
In an optional implementation manner, the updating, according to the operation type of the first operation instruction, a logic clock of a target service device in the initial vector clock includes:
if the operation type is assignment operation, adding one to a logic clock of a target service device in the initial vector clock to serve as the logic clock of the target service device in the first vector clock to obtain the first vector clock;
and if the operation type is deleting operation, directly using the logic clock of the target service equipment in the initial vector clock as the logic clock of the target service equipment in the first vector clock to obtain the first vector clock.
In an optional implementation manner, synchronizing the first vector clock according to the second synchronization information to obtain a synchronization vector clock of a current synchronization period includes:
and according to the logic clocks corresponding to the second vector clock in the second synchronization information in the other service devices, covering the logic clocks corresponding to the first vector clock in the other service devices to obtain the synchronization vector clock of the current synchronization period.
In an optional embodiment, the initial data includes at least one initial triple data, each initial triple data includes a data value, an execution device identifier, and a logic clock of the execution device when the initial triple data is created;
the first operation instruction further comprises 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 assignment operation, generating assignment ternary group data according to the operation value, a target service device identifier and a logic clock of the target service device in the first vector clock, wherein the assignment ternary group data and initial ternary group data in the initial data form first operation data of the target service;
if the operation type is a deletion operation, finding a data value to be deleted in each data value of each initial ternary group data according to the operation value, deleting the initial ternary group data corresponding to the data value to be deleted in the initial data, wherein the remaining initial ternary group data in the initial data is the first operation data of the target service.
In an alternative embodiment, the variable data of the second operation includes a variation type of the variable data and the variable triple data;
wherein the change type comprises a deletion type or an assignment type;
the variable ternary group data comprises an operation value of a second operation, other service equipment identifiers and logic clocks of other service equipment in the second vector clock;
synchronizing the first operation data of the target service according to the second synchronization information to obtain the synchronization data of the target service in the current synchronization period, including:
if the change type of the variable data of the second operation in the second synchronization information is an assignment type, the variable triple data of the variable data in the second synchronization information and the triple data in the first operation data form the synchronization data of the target service in the current synchronization period;
and if the change type of the variable data of the second operation in the second synchronization information is a deletion type, deleting triple data identical to the variable triple data in each triple data of the first operation data, wherein the residual triple data in the first operation data form the synchronization data of the target service in the current synchronization period.
In an optional embodiment, after obtaining the first operation data of the target service, the method further includes:
determining variable data of the first operation, and generating 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 for representing the variation of the data of the target service equipment before the first operation and after the first operation;
sending the first synchronization information to the other service equipment, so that the other service equipment synchronizes second operation data of the target service and the second vector clock respectively according to the first synchronization information to obtain synchronous data and a synchronous vector clock of the target service in a current synchronization period, wherein the synchronous vector clock in the current synchronization period is used as an initial vector clock of a next synchronization period;
and the second operation data is obtained by the other service equipment executing a second operation on the initial data of the target service according to the second vector clock and a second operation instruction.
In an optional embodiment, the determining variable data of the first operation includes:
determining variable triple data between initial triple data of the initial data and each triple data of the first operation data; the variable ternary group data comprises an operation value of a first operation, a target service device identification and a logic clock of the target service device in the first vector clock;
and determining the change type of the variable data according to the operation type in the first operation instruction.
In a second aspect, the present application provides a service device, where the service device belongs to a different-place multi-active system, where the different-place multi-active system includes different service devices respectively located in different geographic areas, and the data synchronization method is executed by a target service device in the multiple service devices;
the service device includes:
the receiving and sending module is used for acquiring a first operation instruction of a target service;
the synchronous processing module is used for determining an initial vector clock of the current synchronous period and updating the initial vector clock to obtain a first vector clock;
the execution module is used for executing 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;
the transceiver module is further configured 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 second operated variable data, the second vector clock is obtained by updating the initial vector clock by the other service devices, and the second operated variable data is used to indicate a variation amount of data of a target service of the other service devices before a second operation and after the second operation;
and the synchronization processing module is used for synchronizing the first operation data of the target service and the first vector clock respectively according to the second synchronization information to obtain the synchronization data of the target service and the synchronization vector clock of the current synchronization period, wherein the synchronization vector clock of the current synchronization period is used as the initial vector clock of the next synchronization period.
In an alternative embodiment, the first operation instruction includes an operation type;
and the synchronous processing module is specifically configured to update a logic clock of the target service device in the initial vector clock according to the operation type of the first operation instruction, where the updated vector clock is the first vector clock.
In an optional embodiment, the synchronization processing module is specifically configured to:
if the operation type is assignment operation, adding one to a logic clock of a target service device in the initial vector clock to serve as the logic clock of the target service device in the first vector clock to obtain the first vector clock;
and if the operation type is deleting operation, directly using the logic clock of the target service equipment in the initial vector clock as the logic clock of the target service equipment in the first vector clock to obtain the first vector clock.
In an optional embodiment, the synchronization processing module is configured to cover the logic clocks corresponding to the first vector clock in the other service devices according to the logic clocks corresponding to the second vector clock in the second synchronization information in the other service devices, so as to obtain the synchronization vector clock of the current synchronization period.
In an optional embodiment, the initial data includes at least one initial triple data, each initial triple data includes a data value, an execution device identifier, and a logic clock of the execution device when the initial triple data is created;
the first operation instruction further comprises an operation value;
the execution module is specifically configured to:
if the operation type is assignment operation, generating assignment ternary group data according to the operation value, a target service device identifier and a logic clock of the target service device in the first vector clock, wherein the assignment ternary group data and initial ternary group data in the initial data form first operation data of the target service;
if the operation type is a deletion operation, finding a data value to be deleted in each data value of each initial ternary group data according to the operation value, deleting the initial ternary group data corresponding to the data value to be deleted in the initial data, wherein the remaining initial ternary group data in the initial data is the first operation data of the target service.
In an alternative embodiment, the variable data of the second operation includes a variation type of the variable data and the variable triple data;
wherein the change type comprises a deletion type or an assignment type;
the variable ternary group data comprises an operation value of a second operation, other service equipment identifiers and logic clocks of other service equipment in the second vector clock;
the synchronization processing module is specifically configured to, if the change type of the variable data of the second operation in the second synchronization information is an assignment type, form the synchronization data of the target service in the current synchronization period by the variable triple data of the variable data in the second synchronization information and the triple data in the first operation data;
and if the change type of the variable data of the second operation in the second synchronization information is a deletion type, deleting triple data identical to the variable triple data in each triple data of the first operation data, wherein the residual triple data in the first operation data form the synchronization data of the target service in the current synchronization period.
In an optional embodiment, after obtaining the first operation data of the target service, the synchronization processing module is further configured to:
determining variable data of the first operation, and generating 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 for representing the variation of the data of the target service equipment before the first operation and after the first operation;
the transceiver module is further configured to send the first synchronization information to the other service devices, so that the other service devices synchronize second operation data of the target service and the second vector clock according to the first synchronization information, to obtain synchronization data and a synchronization vector clock of the target service in a current synchronization period, where the synchronization vector clock in the current synchronization period is to be used as an initial vector clock of a next synchronization period;
and the second operation data is obtained by the other service equipment executing a second operation on the initial data of the target service according to the second vector clock and a second operation instruction.
In an optional embodiment, the synchronization processing module is further configured to:
determining variable triple data between initial triple data of the initial data and each triple data of the first operation data; the variable ternary group data comprises an operation value of a first operation, a target service device identification and a logic clock of the target service device in the first vector clock; and determining the change type of the variable data according to the operation type in the first operation instruction.
In a third aspect, the present application provides an electronic device, comprising: at least one processor and memory;
the memory stores computer-executable instructions;
the at least one processor executing the computer-executable instructions stored by the memory causes the at least one processor to perform the method of the first aspect.
In a fourth aspect, the present application provides a computer-readable storage medium having stored thereon computer-executable instructions that, when executed by a processor, implement the method of the first aspect.
In a fifth aspect, the present application provides a computer program product comprising a computer program which, when executed by a processor, implements the method of the first aspect.
The embodiment of the application provides a data synchronization method and a data synchronization device based on a multi-active system at different places, wherein target service equipment acquires a first operation instruction of a target service and determines an initial vector clock of a current synchronization period; updating the initial vector clock to obtain a first vector clock, and executing 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; receiving second synchronization information sent by other service equipment of the remote multi-active system, wherein the second synchronization information comprises a second vector clock and second operated variable data, the second vector clock is obtained by updating the initial vector clock by the other service equipment, and the second operated variable data is used for representing the variable quantity of the target service data of the other service equipment before second operation and after the second operation; and respectively synchronizing the first operation data of the target service and the first vector clock according to the second synchronization information to obtain the synchronization data and the synchronization vector clock of the target service in the current synchronization period, wherein the synchronization vector clock of the current synchronization period is used as the initial vector clock of the next synchronization period. According to the scheme, the vector clock is utilized to mark the data obtained by the operation executed by different business equipment, so that when the data of each business equipment is synchronized, the operation with conflict can be effectively processed and solved based on the vector clock mark of the data, and the data synchronization efficiency of the multi-active system at different places is effectively improved.
Drawings
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 application.
FIG. 1 is a diagram illustrating a data synchronization process of a prior art displaced multi-active system;
FIG. 2 is a schematic diagram of a network architecture upon which the present application is based;
FIG. 3 is a flow chart of a data synchronization method based on a remote multi-active system provided by the present application;
fig. 4 is a schematic flowchart of a data synchronization method for a multi-site multi-active system according to an embodiment of the present application when a concurrent assignment conflict is handled;
fig. 5 is a schematic flowchart illustrating a process of processing a concurrent assignment conflict by another data synchronization method based on a remote multi-active system according to an embodiment of the present application;
fig. 6 is a schematic flowchart of a data synchronization method for a multi-place and multi-active system according to an embodiment of the present application when a concurrent assignment deletion conflict is handled;
fig. 7 is a schematic flowchart illustrating a process of processing a concurrent assignment deletion conflict by another data synchronization method based on a remote multi-active system according to an embodiment of the present application;
fig. 8 is a schematic structural diagram of a service device according to an embodiment of the present application;
fig. 9 is a schematic structural diagram of an electronic device according to an embodiment of the present invention.
With the above figures, there are shown specific embodiments of the present application, which will be described in more detail below. These drawings and written description are not intended to limit the scope of the inventive concepts in any manner, but rather to illustrate the inventive concepts to those skilled in the art by reference to specific embodiments.
Detailed Description
Reference will now be made in detail to the exemplary embodiments, examples of which are illustrated in the accompanying drawings. When the following description refers to the accompanying drawings, like numbers in different drawings represent the same or similar elements unless otherwise indicated. The embodiments described in the following exemplary embodiments do not represent all embodiments consistent with the present application. Rather, they are merely examples of systems and methods consistent with certain aspects of the present application, as detailed in the appended claims.
With the rapid development of the internet industry, it is a mainstream trend to deploy services by using a remote multi-active system. Generally, a remote multi-active system includes a plurality of service devices disposed in different geographic areas, and based on the geographic area where a user is located, a service access or a service request initiated by the user is sent to the service device in the corresponding geographic area for processing.
In order to avoid cross-regional service access of users, each service device needs to perform data synchronization at regular time to ensure data consistency.
However, since each service device in the remote multi-active system is in a service data processing state at the same time, a situation of service concurrent conflict may occur at a certain time, which may cause data consistency among each service device to be destroyed. Fig. 1 is a schematic diagram of a data synchronization process of a remote multi-active system in the prior art, as shown in fig. 1, a service device a and a service device B are included in the remote multi-active system.
At time t0 when time is 0, the data in service device a and service device B are consistent, both "s ═ a".
At time t1 when time is 1, service device a obtains an operation instruction, i.e., "set s ═ b", from the received service request, and service device a executes the operation instruction, and data in service device a becomes "s ═ b". Meanwhile, the service device B obtains another operation instruction, i.e., "del s", according to the received service request, and the service device B executes the operation instruction, and the data in the service device B becomes "s ═ NULL" at this time.
At time t2 when time is 2, service device a and service device B will trigger a data synchronization process. The service equipment a receives synchronization information, namely 'del s', from the service equipment B, and executes the 'del s' to obtain a synchronization result of's ═ NULL'; and the service device B will receive the synchronization information from the service device a, i.e. "s-B", and the service device B will execute "s-B", resulting in a synchronization result of "s-B".
Obviously, at time t1, a service device a and a service device B have a concurrent conflict, that is, different operations are performed on the same data, and there is a certain contradiction between the two operations. This also enables data synchronization in this case
For the data "s", operation instructions with certain conflict are respectively executed, so that the problem of data inconsistency occurs after data synchronization.
In the prior art, in order to solve such a problem, each service device splits data related to service access, that is, the data may be represented as: a-s and B-s. When executing the service request, the service device only processes the service with the self-identification, and does not process the service without the self-identification.
However, such a processing method needs to modify the service data itself, and since the service logic in the remote multi-active system is relatively complex, such a processing method easily causes omission of the service logic, and the implementation efficiency is not high. Therefore, it is difficult to provide an efficient and simple data synchronization method.
In view of the above problems, in the embodiments of the present application, a vector clock is used to mark data obtained by operations executed by different service devices, so that when data synchronization is performed on each service device, conflicting operations can be effectively processed and solved based on the vector clock mark of the data, and the data synchronization efficiency of a multi-active system in a different place is effectively improved.
Specifically, for a target device in a remote multi-active system, a first operation instruction for a target service is obtained first, and an initial vector clock of a current synchronization period is determined; and updating the initial vector clock to obtain a first vector clock, and executing 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. When the synchronization is triggered, the target service device receives 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 second operated variable data, the second vector clock is obtained by updating the initial vector clock by the other service devices, and the second operated variable data is used to indicate a variation of target service data of the other service devices before and after the second operation. And finally, the target service equipment synchronizes the first operation data of the target service and the first vector clock respectively according to the second synchronization information to obtain the synchronization data of the target service and the synchronization vector clock of the current synchronization period, wherein the synchronization vector clock of the current synchronization period is used as the initial vector clock of the next synchronization period.
By the method, the vector clock of the operation is effectively recorded in the data obtained by each operation on the target service in the service equipment, and during synchronization, the vector clocks of the other service equipment when the operation is executed are also recorded in the synchronization information sent by the other service equipment, and the sequence and the operation range of the operation of different service equipment when the data of the same target service is operated can be effectively distinguished by performing synchronization processing on the data through the two vector clocks, so that the problem of the concurrency conflict mentioned in the above fig. 1 is effectively solved.
The method provided by the present application will be described below with reference to different implementations.
Referring to fig. 2, fig. 2 is a schematic diagram of a network architecture based on the present application, and the network architecture shown in fig. 2 may specifically include a remote multi-active system 1 and a client 2;
the remote multi-active system 1 may specifically include a plurality of service devices, the service devices 11 are to be disposed in different geographical areas, and each service device may provide services for a plurality of user terminals 2 at the same time.
The client 2 may specifically be a hardware device that can be used to execute service request sending or trigger service operation, which includes but is not limited to a desktop computer, a tablet computer, and a cloud computing platform.
In the present application, for each service device in the remote multi-active system 1, in order to improve the service processing efficiency, a database is locally provided, so as to quickly respond to a service access request initiated by the user end 2.
Generally, the user terminal 2 will access the service devices in the geographical area corresponding to the location of the user based on the location of the user. However, in order to avoid the situation that the cross-regional access of the user fails due to the suspension of the operation of part of the service devices, the database of each service device needs to store the service data of the whole geographic area. At this time, the remote multi-service system 1 needs to perform data synchronization processing on data between the service devices according to a preset time period or in real time, so as to ensure consistency of service data in the database of each service device. In the process, each service device respectively adopts the data synchronization method provided by the application to execute corresponding processing so as to realize data synchronization between each service device and each other.
For convenience of description, the present application will describe a data synchronization method based on a remote multi-active system with a target service device as an execution subject and with reference to the accompanying drawings. For other service devices, the data synchronization method based on the remote multi-active system is similar to the data synchronization method used by the target service device, and details thereof are not repeated in the present application.
Example one
Fig. 3 is a schematic flowchart of a data synchronization method based on a remote multi-active system according to the present application. In this embodiment of the present application, the remote multi-active system includes a plurality of service devices respectively located in a plurality of geographic areas, and an execution subject of the flow shown in fig. 3 is a target service device in the plurality of service devices.
As shown in fig. 3, the data synchronization method includes:
step 301, obtaining a first operation instruction for a target service, and determining an initial vector clock of a current synchronization period.
Step 302, 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.
Step 303, receiving 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 indicate a variation of data of a target service of the other service devices before the second operation and after the second operation.
And step 304, synchronizing the first operation data of the target service and the first vector clock respectively according to the second synchronization information to obtain the synchronization data of the target service and a synchronization vector clock of the current synchronization period, wherein the synchronization vector clock of the current synchronization period is used as an initial vector clock of a next synchronization period.
The data synchronization method based on the remote multi-active system can be particularly applied to any business equipment in the remote multi-active system. The embodiment will be described with the target service device as the execution subject.
It should be noted that, in the embodiment of the present application, the other service devices refer to devices other than the target service device in the remote multi-active system, the number of the other service devices may be at least one, and the number of the other service devices is 1 example in the present application. For the case that the number of other service devices is multiple, the data synchronization process is similar to that in the embodiment of the present application, and details thereof will not be described herein.
In addition, the data synchronization method provided by the embodiment of the application is needed to be adopted for data synchronization aiming at each service device in the remote multi-service system, so that the problem of data concurrency conflict during synchronization is avoided.
In this embodiment of the present application, in step 301, the target service device first interacts with the user end and obtains a request including a service access request or a service processing request from the user end. The request service of the request, namely the target service, and the operation which needs to be performed on the request service at this time, namely the first operation instruction are generally kept in the requests.
And the vector clock is a matrix set of recordable event occurrence logic. The logical clock of the last operation of each service device will be recorded in the vector clock. In step 301, the target service device will also update the initial vector clock of the current synchronization period. The initial vector clock of the current synchronization period is a synchronous vector clock obtained by the target service device in the previous synchronization period after the data synchronization processing of the previous synchronization period is completed.
Since the first operation instruction is received and needs to be executed, the target service device updates the initial vector clock once in step 302 to obtain the first vector clock. Subsequently, the target service device processes the initial data of the target service by using the first vector clock and the first operation instruction to obtain first operation data of the target service. The initial data refers to the synchronization data obtained in the previous synchronization period.
In step 303, the target service device may obtain second synchronization information sent from other service devices. It is known that, in order to avoid a concurrency conflict, the second synchronization information is generated from the second vector clock and the variable data of the second operation.
And the second vector clock is obtained by updating the initial vector clock after the other service equipment acquires the second operation instruction of the target service, similar to the first vector clock. Specifically, the initial vector clock in the other service device is identical to the initial vector clock in the target service device.
And the variable data of the second operation is used for representing the variation of the data of the target service of the other service equipment before and after the second operation. For example, if the second operation is a delete operation, the variable data may represent data of the deleted target traffic after the second operation; for another example, if the second operation is an assignment operation, then the variable data may represent current data of the target service after being assigned by the second operation.
In step 304, the target service device synchronizes the first operation data by using the obtained second synchronization information, to obtain synchronization data of the target service in the current synchronization period, which is used as initial data of the target service in the next synchronization period. Meanwhile, the target service device updates the first synchronization vector clock by using the second synchronization information to obtain the synchronization vector clock of the current synchronization period, and the synchronization vector clock is used as the initial vector clock of the next synchronization period. During synchronization, the vector clocks during operation are recorded in both the variable data in the second synchronization information and the first operation data, so that the problem of data synchronization conflict, such as concurrent assignment conflict or concurrent assignment and deletion conflict, will not occur when the variable data and the first operation data are updated synchronously.
On the basis of the above embodiment, in the embodiment of the present application, since the operation types of the operation instructions for the target service are different, the target service device will update the vector clock in different ways under different operation types. Thus, in an alternative embodiment, the first operation instruction comprises an operation type; the updating the initial vector clock in step 302 to obtain a first vector clock may specifically include: and updating the logic clock of the target service equipment in the initial vector clock according to the operation type of the first operation instruction, wherein the updated vector clock is the first vector clock.
Vector clocks are commonly used to represent the time of creation of a value. The operation type in the first operation instruction is an assignment operation, wherein the assignment operation refers to an operation of assigning a value to the target service, which also means that a new value is to be created and stored in the target service. In this case, the target service device may add one to the logic clock of the target service device in the initial vector clock to be used as the logic clock of the target service device in the first vector clock, so as to obtain the first vector clock.
In particular, for the vector clock, it is composed of the logic clocks of different service devices, i.e. the vector clock is denoted VA, VB. The numerical value corresponding to "VA" is the logic clock corresponding to the service device a, and the corresponding numerical value corresponding to "VB" is the logic clock corresponding to the service device B.
For example, assuming that the initial vector clock is represented as [0,1], where "0" is used as the logic clock of the target service device in the initial vector clock, and "1" is used as the logic clock of the other service devices in the initial vector clock, at this time, if the operation type of the target service device acquiring the first operation instruction is an assignment operation, the target service device adds one to the logic clock in the initial vector clock to obtain "1", and forms the first vector clock, i.e., [1,1], with the logic clocks of the other service devices in the initial vector clock.
Correspondingly, when the operation type in the first operation instruction represents a deletion operation, the operation type represents that the first operation instruction is an instruction for deleting a value currently assigned to the target service. Since the value deleted by the first operation instruction is a value created and stored at a historical time, that is, the first operation does not create new data in the target service this time. In this case, the target service device directly uses the logic clock of the target service device in the initial vector clock as the logic clock of the target service device in the first vector clock to obtain the first vector clock.
For example, it is still assumed that the initial vector clock is represented as [0,1], where "0" is used as the logic clock of the target service device in the initial vector clock, and "1" is used as the logic clock of the other service devices in the initial vector clock, at this time, if the operation type of the target service device acquiring the first operation instruction is the delete operation, the target service device directly uses the logic clock "0" in the initial vector clock and the logic clocks of the other service devices in the initial vector clock to form the first vector clock, i.e., [0,1 ].
Of course, the update of the first vector clock is performed based on the second vector clock. In an optional implementation manner, the target service device covers the logic clocks corresponding to the first vector clock in the other service devices according to the logic clocks corresponding to the second vector clock in the second synchronization information in the other service devices, so as to obtain the synchronization vector clock of the current synchronization period.
For example, assuming that the first vector clock is represented as [1,1], wherein "1" is used as the logic clock of the target service device in the first vector clock, and "1" is used as the logic clock of the other service device in the first vector clock, at this time, if the second vector clock of the target service device acquiring the second synchronization information is represented as [0,2], the target service device determines the logic clock of the other service device in the second vector clock, i.e., "2". Then, the target service device will make the logic clock "2" in the second vector clock and the logic clock of the target service device in the first vector clock form a synchronous vector clock, i.e., [1,2 ].
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 traffic device and other traffic devices are [0,1 ]. After the first operation and the second operation are respectively carried out, the first vector clock of the target service equipment is [1,1], and the second vector clocks of other service equipment are [0,2 ].
When data are synchronized, the target service equipment updates the first vector clock [1,1] according to the second vector clock [0,2] to obtain a synchronous vector clock [1,2 ]; and other service equipment updates the second vector clock [0,2] according to the first vector clock [1,1] to obtain the synchronous vector clock [1,2 ]. At this point, the target service device and other service devices obtain the same synchronous vector clock in the current synchronous period, and the synchronous vector clock is used as the initial vector clock of the target service device and other service devices in the next synchronous period.
The vector clock updating mode can ensure that the vector clocks in the service devices are consistent, and is beneficial to the effective processing of the data of the respective target service by the service devices according to the respective vector clocks.
In addition to the above embodiments, in the embodiments of the present application, the data of the target service may be stored based on the form of triple-tuple data, and triple-tuple data composed of different elements also constitutes different data elements of the target service. In order to ensure that no conflict occurs during data synchronization, the triplet data includes elements based on a vector clock for distinguishing values obtained by each operation.
In an optional embodiment, the initial data includes at least one initial triple data, each initial triple data includes a data value, an execution device identifier, and a logic clock of the execution device when the initial triple data is created; the first operation instruction further comprises an operation value;
the result obtained by the first operation is also different under different operation types:
if the operation type is an assignment operation, the step 301 of 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 specifically includes:
and generating assignment ternary group data according to the operation value, the target service equipment identifier and the logic clock of the target service equipment in the first vector clock, wherein the assignment ternary group data and the initial ternary group data in the initial data form first operation data of the target service.
Specifically, it is assumed that the initial data is represented by { a,1, a } { B,1, B }, which means: when the logic clock of the service equipment A (target service equipment) is 1, the service equipment A assigns the target service as a, and when the logic clock of the service equipment B is 1, the service equipment B assigns the target service as B; the initial vector clock is denoted as [1,1 ].
If the service device a (target service device) obtains the first operation instruction, the first operation instruction is an assignment operation, and the operation is to assign the target service to c. The target service device updates the initial vector clock to obtain the first vector clock [2,1] (for the updating process, see the foregoing embodiment).
At this time, the service device a generates the assignment triple data { c, 2, a } according to the operation value "c" in the first operation instruction, the target service device identifier "a", and the logic clock "2" of the target service device in the first vector clock, and the assignment triple data { c, 2, a } and the initial triple data { a,1, a } { B,1, B } in the initial data form first operation data of the target service, that is, the first operation data includes: { a,1, a } { B,1, B } { c, 2, a }.
If the operation type is a delete operation, the step 301 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 first operation data of the target service, which specifically includes:
and finding a data value to be deleted in each data value of each initial ternary group of data according to the operation value, deleting the initial ternary group of data corresponding to the data value to be deleted in the initial data, wherein the rest initial ternary group of data in the initial data is the first operation data of the target service.
Specifically, it is assumed that the initial data is represented by { a,1, a } { B,1, B }, which means: when the logic clock of the service equipment A (target service equipment) is 1, the service equipment A assigns the target service as a, and when the logic clock of the service equipment B is 1, the service equipment B assigns the target service as B; the initial vector clock is denoted as [1,1 ].
If the 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 with b in the target service. The target service device updates the initial vector clock to obtain the first vector clock [1,1] (for the updating process, see the foregoing embodiment).
At this time, the service device a directly finds the data value "B" to be deleted in each data value of each initial triple data { a,1, a } { B,1, B } according to the operation value "B" in the first operation instruction, deletes the initial triple data, i.e., { B,1, B }, corresponding to the data value to be deleted in the initial data, and the remaining initial triple data in the initial data is the first operation data of the target service, i.e., the first operation data is { a,1, a }.
The above embodiments describe how to perform a first operation on initial data of a target service in a target service device based on a different first operation instruction in combination with a vector clock to obtain first operation data. In addition to the above embodiments, how to synchronize the data of the obtained first operation data based on the acquired second synchronization information of different types sent from other service devices will be described below.
In an alternative embodiment, the variable data of the second operation includes a change type of the variable data and the variable triple data; wherein the change type comprises a deletion type or an assignment type; the variable ternary group data comprises an operation value of a second operation, other service equipment identifications and logic clocks of other service equipment in the second vector clock.
When the change type indicated by the variable data of the second operation in the second synchronization information is an assignment type, the target service device in step 304 synchronizes the first operation data of the target service according to the second synchronization information to obtain the synchronization data of the target service in the current synchronization period, which may specifically include: and the target service equipment forms the synchronous data of the target service in the current synchronization period by the variable triple data of the variable data in the second synchronization information and the triple data in the first operation data.
For example, assume that the initial data is denoted as { a,1, A } { B,1, B }, and the initial vector clock is denoted as [1,1 ]. During the current synchronization cycle, as shown in the foregoing embodiment, 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 ]. And business device B (the other business device) will execute the second operation instruction (e.g., assign d to the target business) represented as the assignment operation and obtain second operation data { a,1, a } { B,1, B } { d, 2, B }, with the second vector clock represented [1,2 ].
When data synchronization is triggered, the service device a (target service device) receives second synchronization information sent by the service device B (other service device), where the second synchronization information includes variable ternary group data "{ d, 2, B }" of variable data and an assignment type of a change type of the variable data. Based on the variable data change type being the assignment type, the service device a (target service device) may merge the variable triple data { d, 2, B } with the triple data { a,1, a } { B,1, B } { c, 2, a } in the 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 period. Meanwhile, the first vector clock [2,1] is updated to obtain a synchronous vector clock [2,2 ].
When the change type indicated by the variable data of the second operation in the second synchronization information is a deletion type, the target service device in step 304 synchronizes the first operation data of the target service according to the second synchronization information to obtain the synchronization data of the target service in the current synchronization period, which may specifically include: and the target service equipment deletes triple data which are the same as the variable triple data in each triple data of the first operation data, wherein the residual triple data in the first operation data form the synchronous data of the target service in the current synchronous period.
For example, assume again that the initial data is denoted as { a,1, A } { B,1, B }, and the initial vector clock is denoted as [1,1 ]. During the current synchronization cycle, as shown in the foregoing embodiment, 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 ]. And service device B (other service device) will execute a second operation instruction (e.g., data assigned B in the delete target service) represented as a delete operation and obtain second operation data { a,1, a }, with the second vector clock represented [1,1 ].
When data synchronization is triggered, service device a (target service device) receives second synchronization information sent from service device B (other service device), where the second synchronization information includes variable ternary group data "{ B,1, B }" of variable data and a change type "deletion type" of variable data. Based on the fact that the change type of the variable data is the deletion type, the service device a (target service device) will find the triple data consistent with the variable triple data { B,1, B } from its current triple data, and delete the triple data { B,1, B }. And the residual ternary group data in the first operation data is synchronous data, namely the synchronous data { a,1, A } of the target service in the current synchronous period. Meanwhile, the first vector clock [2,1] is updated to obtain a synchronous vector clock [2,1 ].
Of course, on the basis of the foregoing embodiments, the target service device may also send the first synchronization information including the variable data of the first operation and the change type of the variable data to other service devices, so that the other service devices perform data synchronization in the same manner as the target service device, so as to ensure that the synchronization data and the synchronization vector clock obtained by the different service devices in the same synchronization period are completely the same.
Based on this, in an optional embodiment, after obtaining the first operation data of the target service, the target service device further includes: determining variable data of the first operation, and generating 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 for representing the variation of the data of the target service equipment before the first operation and after the first operation; sending the first synchronization information to the other service equipment, so that the other service equipment synchronizes second operation data of the target service and the second vector clock respectively according to the first synchronization information to obtain synchronous data and a synchronous vector clock of the target service in a current synchronization period, wherein the synchronous vector clock in the current synchronization period is used as an initial vector clock of a next synchronization period; and the second operation data is obtained by the other service equipment executing a second operation on the initial data of the target service according to the second vector clock and a second operation instruction.
Further, the target service device needs to determine variable data of a first operation, that is, determine variable ternary group data between initial ternary group data of the initial data and each ternary group data of the first operation data; the variable ternary group data comprises an operation value of a first operation, a target service device identification and a logic clock of the target service device in the first vector clock; and determining the change type of the variable data according to the operation type in the first operation instruction.
For example, assume that the initial data is denoted as { a,1, A } { B,1, B }, and the initial vector clock is denoted as [1,1 ]. During the current synchronization cycle, as shown in the foregoing embodiment, 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 ].
The variable ternary group data between the initial ternary group data and each ternary group data of the first operation data is { c, 2, A }, and the variable type of the variable data is an assignment type at the moment because the first operation is an assignment operation. At this time, the first synchronization information determined by the target service device is: { c, 2, A }, assignment type, [2,1 ]. The first synchronization information is sent to other service equipment for data synchronization processing.
In order to better describe the present application, the data synchronization method provided by the present application will be further described below by taking different examples as examples.
Fig. 4 is a schematic flowchart of a data synchronization method based on a remote multi-active system according to an embodiment of the present application when a concurrent assignment conflict is handled. The data processing of fig. 4 is based on set type.
As shown in fig. 4, a service device a and a service device B are included in the remote multi-active system. The service device a is used as a target service device, and the service device B is used as another service device.
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 ].
At time t1, the service device a receives the first operation instruction "add a (assigned as a)", and at the same time, the service device B receives the second operation instruction "add B (assigned as B)".
At this time, since the first operation instruction and the second operation instruction are both assignment operations, the service device a will update its initial vector clock [0,0] to [1,0], and the service device B will update its initial vector clock [0,0] to [0,1 ]. Meanwhile, the service equipment A executes the first operation instruction to obtain first operation data { a,1, A }; and the service equipment B executes the second operation instruction to obtain second operation data { B,1, B }.
At time t2, the service device a and the service device B trigger data synchronization processing at the same time, and based on the data synchronization method provided by the present application, the service device a sends first synchronization information to the service device B: { a,1, a }, assignment type, [1,0 ]; the service device B sends the second synchronization information to the service device a: { B,1, B }, assignment type, [0,1 ].
For the service device a, since the variable data in the second synchronization information is of assignment type, it will add the variable data { B,1, B } into the data set, so that the first operation data and the set of variable data constitute the synchronization data, i.e., { a,1, a } { B,1, B }, and at the same time, the service device a will update its first vector clock [1,0] according to the second vector clock [0,1] to obtain the synchronization vector clock [1,1 ].
Meanwhile, for the service device B, since the variable data in the first synchronization information is of assignment type, it will add the variable data { a,1, a } to the data set, so that the second operation data and the set of variable data constitute the synchronization data, i.e., { a,1, a } { B,1, B }, and at the same time, the service device B will update its second vector clock [0,1] according to the first vector clock [1,0] to obtain the synchronization vector clock [1,1 ].
Thus, the data synchronization processing of the current synchronization cycle is completed, and the service device a and the service device B obtain the same synchronization data and synchronization vector clock, which are also used as the initial data and initial vector clock of the next synchronization cycle.
Fig. 5 is a schematic flowchart of another data synchronization method based on a remote multi-active system according to an embodiment of the present application when a concurrent assignment conflict is handled. The data processing of fig. 5 thereof is based on String type.
In the manner of fig. 5, unlike the manner shown in fig. 4, a time stamp may be additionally recorded in the triple data of the data, so that the data is better recorded and the conflict is handled.
As shown in fig. 5, a service device a and a service device B are included in the remote multi-active system. The service device a is used as a target service device, and the service device B is used as another service device.
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 ].
At time t1, the service device a receives a first operation instruction "set Key ═ a (assigning Key to a)", and since the first operation instruction is an assignment operation, the service device a updates its initial vector clock [0,0] to [1,0], and executes the first operation instruction, so as to obtain first operation data Key ═ { a, (1, a), t1 };
at time t2, the service device B receives the second operation instruction "set Key ═ B (Key is assigned to B)", and since the second operation instruction is an assignment operation, the service device B will update its initial vector clock [0,0] to [0,1 ]. Meanwhile, the service device B executes the second operation instruction, and obtains second operation data key ═ B, (1, B), t2 }.
At time t3, the service device a and the service device B trigger data synchronization processing at the same time, and at this time, since the first operation data and the second operation data both include timestamps, and it can be known by comparing the timestamps 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 last synchronization data should be assigned as B.
During synchronization, the service device a sends first synchronization information to the service device B: key { a, (1, a), t1}, assignment type, [1,0 ]; the service device B sends the second synchronization information to the service device a: key ═ { B, (1, B), t2}, assignment type, [0,1 ].
For the service device a, since the change type of the variable data in the second synchronization information is an assignment type, it adds the variable data key { B, (1, B), t2} into the dataset, so that the first set of operation data and variable data constitutes the synchronization data, i.e., key { a, (1, a), t1} and key { B, (1, B), t2}, since in the string type data, the same element key cannot have two values, and at this time, the service device a takes the data with the later timestamp as the value of the key, and updates its logic clock to obtain the key { B, (1, a), (1, B), t2 }.
Meanwhile, the service device a updates the first vector clock [1,0] thereof according to the second vector clock [0,1] to obtain the synchronous vector clock [1,1 ].
Meanwhile, for the service device B, since the change type of the variable data in the first synchronization information is an assignment type, it adds the variable data key { a, (1, a), t1} to the data set, so that the second operation data and the set of variable data constitute synchronization data, i.e., key { a, (1, a), t1} and key { B, (1, B), t2}, and since the same element key cannot have two values in the string type data, the service device B takes the data with the later timestamp as the value of the key and updates the logic clock thereof to finally obtain key { B, (1, a), (1, B), t2 }.
Meanwhile, the service device B updates the second vector clock [0,1] thereof according to the first vector clock [1,0] to obtain the synchronous vector clock [1,1 ].
Thus, the data synchronization processing of the current synchronization cycle is completed, and the service device a and the service device B obtain the same synchronization data and synchronization vector clock, which are also used as the initial data and initial vector clock of the next synchronization cycle.
Fig. 6 is a schematic flowchart of a data synchronization method based on a remote multi-active system according to an embodiment of the present application when a concurrent assignment deletion conflict is handled. The data processing of fig. 6 is based on set type.
As shown in fig. 6, a service device a and a service device B are included in the remote multi-active system. The service device a is used as a target service device, and the service device B is used as another service device.
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 denoted as [2,1 ].
At time t1, the service device a receives the first operation instruction "add B (assigned as B)", and at the same time, the service device B receives the second operation instruction "rem B (delete B)".
At this time, since the first operation instruction is an assignment operation and the second operation instruction is a deletion operation, the service device a updates its initial vector clock [2,1] to [3,1], and the service device B updates its initial vector clock [2,1] to [2,1 ].
Meanwhile, the service equipment A executes the first operation instruction to obtain first operation data { a,1, A } { B,1, B } { B,2, A } { B,3, A }; and the service equipment B executes the second operation instruction to obtain second operation data { a,1, A }.
At time t2, the service device a and the service device B trigger data synchronization processing at the same time, and based on the data synchronization method provided by the present application, the service device a sends first synchronization information to the service device B: { b,3, a }, assignment type, [3,1 ]; the service device B sends the second synchronization information to the service device a: { B,1, B } { B,2, a }, deletion type, [2,1 ].
For the service device a, since the change type of the variable data in the second synchronization information is a deletion type, it deletes the variable data { B,1, B } { B,2, a } from the data set of the first operation data to obtain the synchronization data, i.e., { a,1, a } { B,3, a }, and at the same time, the service device a updates its first vector clock [3,1] according to the second vector clock [2,1] to obtain the synchronization vector clock [3,1 ].
Meanwhile, for the service device B, since the variable data in the first synchronization information is of assignment type, it will add the variable data { B,3, a } to the data set, so that the second operation data and the set of variable data constitute the synchronization data, i.e., { a,1, a } { B,3, a }, and at the same time, the service device B will update its second vector clock [2,1] according to the first vector clock [3,1] to obtain the synchronization vector clock [3,1 ].
Thus, the data synchronization processing of the current synchronization cycle is completed, and the service device a and the service device B obtain the same synchronization data and synchronization vector clock, which are also used as the initial data and initial vector clock of the next synchronization cycle.
Fig. 7 is a schematic flowchart of another data synchronization method based on a remote multi-active system according to an embodiment of the present application when a concurrent assignment deletion conflict is handled. The data processing of fig. 7 thereof is based on String type.
In contrast to the method shown in fig. 6, in the method shown in fig. 7, a time stamp may be additionally recorded in the triple data of the data, so that the data is better recorded and the conflict is handled.
As shown in fig. 7, a service device a and a service device B are included in the remote multi-active system. The service device a is used as a target service device, and the service device B is used as another service device.
At time t3 (the initial time of the current synchronization cycle), the initial data of the target traffic in traffic device a and traffic device B are both key ═ B, (1, a), (1, B), t2, and the initial vector clock is denoted as [1,1 ].
At time t4, the service device a receives a first operation instruction "set Key ═ c (assigning Key to c)", and since the first operation instruction is an assignment operation, the service device a updates its initial vector clock [1,1] to [2,1], and executes the first operation instruction, so as to obtain first operation data Key ═ { c, (2, a), (1, B), t4 };
at time t5, the service device B receives the second operation instruction "del Key (delete Key assignment)", and since the second operation instruction is a delete operation, the service device B will update its initial vector clock [1,1] to [1,1 ]. Meanwhile, the service device B executes the second operation instruction to obtain second operation data key { }.
At time t6, the service device a and the service device B trigger data synchronization processing at the same time, and at this time, the service device a sends first synchronization information to the service device B: key { c, (2, a), t4}, assignment type, [2,1 ]; the service device B sends the second synchronization information to the service device a: key ═ { B, (1, a), (1, B), t5}, deletion type, [1,1 ].
For the service device a, since the change type of the variable data in the second synchronization information is the deletion type, it deletes the variable data key { B, (1, a), (1, B), t2} from the dataset of the first operation data to obtain the synchronization data, i.e., key { c, (2, a), t4 }.
Meanwhile, the service device a updates the first vector clock [2,1] thereof according to the second vector clock [1,1] to obtain the synchronous vector clock [2,1 ].
Meanwhile, for the service device B, since the variable data in the first synchronization information is of the assignment type, it adds the variable data key { c, (2, a), t4} to the data set, so that the second operation data and the set of variable data constitute the synchronization data, i.e., key { c, (2, a), t4 }.
Meanwhile, the service device B updates the second vector clock [1,1] thereof according to the first vector clock [2,1] to obtain the synchronous vector clock [2,1 ].
Thus, the data synchronization processing of the current synchronization cycle is completed, and the service device a and the service device B obtain the same synchronization data and synchronization vector clock, which are also used as the initial data and initial vector clock of the next synchronization cycle.
By the method, the vector clock of the operation is effectively recorded in the data obtained by the operation on the target service in each time in the service equipment, the vector clocks of the operation executed by other service equipment are also recorded in the synchronization information sent by other service equipment during synchronization, and the sequence and the operation range of the operation of different service equipment during the operation on the data of the same target service can be effectively distinguished by performing synchronization processing on the data through the two vector clocks, so that the problem of the concurrency conflict mentioned in the figure 1 is effectively solved.
Example two
Fig. 8 is a schematic structural diagram of a service device provided in an embodiment of the present application, where the service device belongs to a remote multi-active system, the remote multi-active system includes different service devices respectively located in different geographic areas, and the data synchronization method is executed by a target service device in the multiple service devices; as shown in fig. 8, the service device includes: a transceiver module 10, a synchronization processing module 20 and an execution module 30.
The receiving and sending module 10 is used for acquiring a first operation instruction of a target service;
the synchronization processing module 20 is configured to determine an initial vector clock of a current synchronization period, and update the initial vector clock to obtain a first vector clock;
the execution module 30 is 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 10 is further configured 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 second operated variable data, the second vector clock is obtained by updating the initial vector clock by the other service devices, and the second operated variable data is used to indicate a variation amount of data of a target service of the other service devices before a second operation and after the second operation;
and a synchronization processing module 20, configured to synchronize the first operation data of the target service and the first vector clock according to the second synchronization information, to obtain synchronization data of the target service and a synchronization vector clock in a current synchronization period, where the synchronization vector clock in the current synchronization period is to be used as an initial vector clock in a next synchronization period.
In an alternative embodiment, the first operation instruction includes an operation type;
the synchronization processing module 20 is specifically configured to update a logic clock of the target service device in the initial vector clock according to the operation type of the first operation instruction, where the updated vector clock is the first vector clock.
In an optional embodiment, the synchronization processing module 20 is specifically configured to:
if the operation type is assignment operation, adding one to a logic clock of a target service device in the initial vector clock to serve as the logic clock of the target service device in the first vector clock to obtain the first vector clock;
and if the operation type is deleting operation, directly using the logic clock of the target service equipment in the initial vector clock as the logic clock of the target service equipment in the first vector clock to obtain the first vector clock.
In an optional embodiment, the synchronization processing module 20 is configured to cover the logic clocks corresponding to the first vector clock in the other service devices according to the logic clocks corresponding to the second vector clock in the second synchronization information in the other service devices, so as to obtain the synchronization vector clock of the current synchronization period.
In an optional embodiment, the initial data includes at least one initial triple data, each initial triple data includes a data value, an execution device identifier, and a logic clock of the execution device when the initial triple data is created;
the first operation instruction further comprises an operation value;
the execution module 30 is specifically configured to:
if the operation type is assignment operation, generating assignment ternary group data according to the operation value, a target service device identifier and a logic clock of the target service device in the first vector clock, wherein the assignment ternary group data and initial ternary group data in the initial data form first operation data of the target service;
if the operation type is a deletion operation, finding a data value to be deleted in each data value of each initial ternary group data according to the operation value, deleting the initial ternary group data corresponding to the data value to be deleted in the initial data, wherein the remaining initial ternary group data in the initial data is the first operation data of the target service.
In an alternative embodiment, the variable data of the second operation includes a variation type of the variable data and the variable triple data;
wherein the change type comprises a deletion type or an assignment type;
the variable ternary group data comprises an operation value of a second operation, other service equipment identifiers and logic clocks of other service equipment in the second vector clock;
the synchronization processing module 20 is specifically configured to, if the change type of the variable data of the second operation in the second synchronization information is an assignment type, form the synchronization data of the target service in the current synchronization period by the variable triple data of the variable data in the second synchronization information and the triple data in the first operation data;
and if the change type of the variable data of the second operation in the second synchronization information is a deletion type, deleting triple data identical to the variable triple data in each triple data of the first operation data, wherein the residual triple data in the first operation data form the synchronization data of the target service in the current synchronization period.
In an optional embodiment, after obtaining the first operation data of the target service, the synchronous processing module 20 is further configured to:
determining variable data of the first operation, and generating 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 for representing the variation of the data of the target service equipment before the first operation and after the first operation;
the transceiver module 10 is further configured to send the first synchronization information to the other service devices, so that the other service devices synchronize second operation data of the target service and the second vector clock according to the first synchronization information, to obtain synchronization data and a synchronization vector clock of the target service in a current synchronization period, where the synchronization vector clock in the current synchronization period is to be used as an initial vector clock of a next synchronization period;
and the second operation data is obtained by the other service equipment executing a second operation on the initial data of the target service according to the second vector clock and a second operation instruction.
In an optional embodiment, the synchronization processing module 20 is further configured to:
determining variable triple data between initial triple data of the initial data and each triple data of the first operation data; the variable ternary group data comprises an operation value of a first operation, a target service device identification and a logic clock of the target service device in the first vector clock; and determining the change type of the variable data according to the operation type in the first operation instruction.
The embodiment of the application provides service equipment based on a remote multi-active system, wherein an initial vector clock of a current synchronization period is determined by acquiring a first operation instruction of a target service; updating the initial vector clock to obtain a first vector clock, and executing 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; receiving second synchronization information sent by other service equipment of the remote multi-active system, wherein the second synchronization information comprises a second vector clock and second operated variable data, the second vector clock is obtained by updating the initial vector clock by the other service equipment, and the second operated variable data is used for representing the variable quantity of the target service data of the other service equipment before second operation and after the second operation; and respectively synchronizing the first operation data of the target service and the first vector clock according to the second synchronization information to obtain the synchronization data and the synchronization vector clock of the target service in the current synchronization period, wherein the synchronization vector clock of the current synchronization period is used as the initial vector clock of the next synchronization period. According to the scheme, the vector clock is utilized to mark the data obtained by the operation executed by different business equipment, so that when the data of each business equipment is synchronized, the operation with conflict can be effectively processed and solved based on the vector clock mark of the data, and the data synchronization efficiency of the multi-active system at different places is effectively improved.
EXAMPLE III
Fig. 9 is a schematic structural diagram of an electronic device according to an embodiment of the present invention, and as shown in fig. 9, an electronic device 1400 according to an embodiment of the present invention includes: memory 1401, processor 1402, and computer programs.
Wherein the computer program is stored in the memory 1401 and configured to be executed by the processor 1402 to implement the data synchronization method based on the remote multi-live system according to any one of the embodiments of the present invention. The related descriptions and effects corresponding to the steps in the drawings can be correspondingly understood, and redundant description is not repeated here.
In this embodiment, the memory 1401 and the processor 1402 are connected by a bus.
Example four
The embodiment of the invention provides a computer readable storage medium, on which a computer program is stored, and the computer program is executed by a processor to implement the data synchronization method based on the remote multi-active system provided by any embodiment of the invention.
In the embodiments provided in the present invention, it should be understood that the disclosed system and method can be implemented in other ways. For example, the above-described system embodiments are merely illustrative, and for example, a division of modules is merely a logical division, and an actual implementation may have another division, for example, multiple modules or components may be combined or integrated into another system, or some features may be omitted, or not implemented. In addition, the shown or discussed mutual coupling or direct coupling or communication connection may be an indirect coupling or communication connection through some interfaces, systems or modules, and may be in an electrical, mechanical or other form.
Modules described as separate parts may or may not be physically separate, and parts displayed as modules may or may not be physical modules, may be located in one place, or may be distributed on a plurality of network modules. Some or all of the modules may be selected according to actual needs to achieve the purpose of the solution of the present embodiment.
In addition, functional modules in the embodiments of the present invention may be integrated into one processing module, or each of the modules may exist alone physically, or two or more modules are integrated into one module. The integrated module can be realized in a hardware form, and can also be realized in a form of hardware and a software functional module.
Program code for implementing the methods 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, special purpose computer, or other programmable question answering system, such that the program codes, when executed by the processor or controller, cause the functions/operations specified in the flowchart and/or block diagram to be performed. The program code may execute entirely on the machine, partly on the machine, as a stand-alone software package partly on the machine and partly on a remote machine or entirely on the remote machine or server.
In the context of the present invention, a machine-readable medium may be a tangible medium that can contain, or store a program for use by or in connection with an instruction execution system, or device. The 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, or device, or any suitable combination of the foregoing. More specific examples of a machine-readable storage medium would include an electrical connection based on one or more wires, a portable computer diskette, 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 disc read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the foregoing.
Furthermore, the present application provides a computer program product comprising a computer program which, when executed by a processor, implements the aforementioned method for data synchronization based on a displaced multi-live system.
Further, while operations are depicted in a particular order, this should be understood as requiring that such operations be performed in the particular order shown or in sequential order, or that all illustrated operations be performed, to achieve desirable results. Under certain circumstances, multitasking and parallel processing may be advantageous. Likewise, while several specific implementation details are included in the above discussion, these should not be construed as limitations on the scope of the disclosure. Certain features that are described in the context of separate embodiments can also be implemented in combination in a single implementation. Conversely, various features that are described in the context of a single implementation can also be implemented in multiple implementations separately or in any suitable subcombination.
Although the subject matter has been described in language specific to structural features and/or methodological acts, it is to be understood that the subject matter defined in the appended claims is not necessarily limited to the specific features or acts described above. Rather, the specific features and acts described above are disclosed as example forms of implementing the claims.

Claims (12)

1. A data synchronization method based on a remote multi-active system is characterized in that the remote multi-active system comprises a plurality of service devices respectively located in a plurality of geographic areas, and the data synchronization method is executed by a target service device in the plurality of service devices;
the data synchronization method comprises the following steps:
acquiring a first operation instruction of a target service, and determining an initial vector clock of a current synchronization period;
updating the initial vector clock to obtain a first vector clock, and executing 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;
receiving second synchronization information sent by other service equipment of the remote multi-active system, wherein the second synchronization information comprises a second vector clock and second operated variable data, the second vector clock is obtained by updating the initial vector clock by the other service equipment, and the second operated variable data is used for representing the variable quantity of the target service data of the other service equipment before second operation and after the second operation;
and respectively synchronizing the first operation data of the target service and the first vector clock according to the second synchronization information to obtain the synchronization data and the synchronization vector clock of the target service in the current synchronization period, wherein the synchronization vector clock of the current synchronization period is used as the initial vector clock of the next synchronization period.
2. The data synchronization method according to claim 1, wherein the first operation instruction includes an operation type;
the updating the initial vector clock to obtain a first vector clock includes:
and updating the logic clock of the target service equipment in the initial vector clock according to the operation type of the first operation instruction, wherein the updated vector clock is the first vector clock.
3. The data synchronization method according to claim 2, wherein the updating the logic clock of the target service device in the initial vector clock according to the operation type of the first operation instruction comprises:
if the operation type is assignment operation, adding one to a logic clock of a target service device in the initial vector clock to serve as the logic clock of the target service device in the first vector clock to obtain the first vector clock;
and if the operation type is deleting operation, directly using the logic clock of the target service equipment in the initial vector clock as the logic clock of the target service equipment in the first vector clock to obtain the first vector clock.
4. The data synchronization method according to claim 2, wherein synchronizing the first vector clock according to the second synchronization information to obtain a synchronization vector clock of a current synchronization period comprises:
and according to the logic clocks corresponding to the second vector clock in the second synchronization information in the other service devices, covering the logic clocks corresponding to the first vector clock in the other service devices to obtain the synchronization vector clock of the current synchronization period.
5. The data synchronization method according to any one of claims 2 to 4, wherein the initial data comprises at least one initial triple data, each initial triple data comprises a data value, an execution device identification, and a logical clock of the execution device when the initial triple data is created;
the first operation instruction further comprises 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 assignment operation, generating assignment ternary group data according to the operation value, a target service device identifier and a logic clock of the target service device in the first vector clock, wherein the assignment ternary group data and initial ternary group data in the initial data form first operation data of the target service;
if the operation type is a deletion operation, finding a data value to be deleted in each data value of each initial ternary group data according to the operation value, deleting the initial ternary group data corresponding to the data value to be deleted in the initial data, wherein the remaining initial ternary group data in the initial data is the first operation data of the target service.
6. The data synchronization method according to claim 5, wherein the variable data of the second operation includes a type of change of the variable data, and the variable triple data;
wherein the change type comprises a deletion type or an assignment type;
the variable ternary group data comprises an operation value of a second operation, other service equipment identifiers and logic clocks of other service equipment in the second vector clock;
synchronizing the first operation data of the target service according to the second synchronization information to obtain the synchronization data of the target service in the current synchronization period, including:
if the change type of the variable data of the second operation in the second synchronization information is an assignment type, the variable triple data of the variable data in the second synchronization information and the triple data in the first operation data form the synchronization data of the target service in the current synchronization period;
and if the change type of the variable data of the second operation in the second synchronization information is a deletion type, deleting triple data identical to the variable triple data in each triple data of the first operation data, wherein the residual triple data in the first operation data form the synchronization data of the target service in the current synchronization period.
7. The data synchronization method according to claim 1, further comprising, after obtaining the first operation data of the target service:
determining variable data of the first operation, and generating 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 for representing the variation of the data of the target service equipment before the first operation and after the first operation;
sending the first synchronization information to the other service equipment, so that the other service equipment synchronizes second operation data of the target service and the second vector clock respectively according to the first synchronization information to obtain synchronous data and a synchronous vector clock of the target service in a current synchronization period, wherein the synchronous vector clock in the current synchronization period is used as an initial vector clock of a next synchronization period;
and the second operation data is obtained by the other service equipment executing a second operation on the initial data of the target service according to the second vector clock and a second operation instruction.
8. The data synchronization method of claim 7, wherein the determining the variable data of the first operation comprises:
determining variable triple data between initial triple data of the initial data and each triple data of the first operation data; the variable ternary group data comprises an operation value of a first operation, a target service device identification and a logic clock of the target service device in the first vector clock;
and determining the change type of the variable data according to the operation type in the first operation instruction.
9. A service device, wherein the service device belongs to a remote multi-active system, the remote multi-active system includes different service devices respectively located in different geographical areas, and the data synchronization method is executed by a target service device of the plurality of service devices;
the service device includes:
the receiving and sending module is used for acquiring a first operation instruction of a target service;
the synchronous processing module is used for determining an initial vector clock of the current synchronous period and updating the initial vector clock to obtain a first vector clock;
the execution module is used for executing 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;
the transceiver module is further configured 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 second operated variable data, the second vector clock is obtained by updating the initial vector clock by the other service devices, and the second operated variable data is used to indicate a variation amount of data of a target service of the other service devices before a second operation and after the second operation;
and the synchronization processing module is used for synchronizing the first operation data of the target service and the first vector clock respectively according to the second synchronization information to obtain the synchronization data of the target service and the synchronization vector clock of the current synchronization period, wherein the synchronization vector clock of the current synchronization period is used as the initial vector clock of the next synchronization period.
10. An electronic device, comprising: at least one processor and memory;
the memory stores computer-executable instructions;
the at least one processor executing the computer-executable instructions stored by the memory causes the at least one processor to perform the method of any one of claims 1-8.
11. A computer-readable storage medium having computer-executable instructions stored thereon which, when executed by a processor, implement the method of any one of claims 1-8.
12. A computer program product comprising a computer program, characterized in that the computer program realizes the method of any of claims 1-8 when executed by a processor.
CN202111299131.0A 2021-11-04 2021-11-04 Data synchronization method and device based on remote multi-active system Pending CN113971181A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202111299131.0A CN113971181A (en) 2021-11-04 2021-11-04 Data synchronization method and device based on remote multi-active system

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202111299131.0A CN113971181A (en) 2021-11-04 2021-11-04 Data synchronization method and device based on remote multi-active system

Publications (1)

Publication Number Publication Date
CN113971181A true CN113971181A (en) 2022-01-25

Family

ID=79589606

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202111299131.0A Pending CN113971181A (en) 2021-11-04 2021-11-04 Data synchronization method and device based on remote multi-active system

Country Status (1)

Country Link
CN (1) CN113971181A (en)

Similar Documents

Publication Publication Date Title
CN109492013B (en) Data processing method, device and system applied to database cluster
CN111399764B (en) Data storage method, data reading device, data storage equipment and data storage medium
CN113204598B (en) Data synchronization method, system and storage medium
CN105608126A (en) Method and apparatus for establishing secondary indexes for massive databases
CN114443294B (en) Big data service component deployment method, system, terminal and storage medium
CN113672692B (en) Data processing method, data processing device, computer equipment and storage medium
CN110099128B (en) Authentication data synchronization method and device
US8892535B2 (en) Database management method
CN111090803A (en) Data processing method and device, electronic equipment and storage medium
CN113971181A (en) Data synchronization method and device based on remote multi-active system
CN111427950A (en) Data transmitting and receiving method, corresponding device, equipment and storage medium
CN113590643B (en) Data synchronization method, device, equipment and storage medium based on dual-track database
CN111966650B (en) Operation and maintenance big data sharing data table processing method and device and storage medium
CN110569231B (en) Data migration method, device, equipment and medium
JP2004265081A (en) Information processing method and device
CN113392074B (en) Internet of things equipment security management method adopting memory documents
CN114116672B (en) Data synchronization method and related device
CN113449035B (en) Data synchronization method, device, computer equipment and readable storage medium
CN114827275B (en) Management platform of federal tenant and resource management method of federal tenant
CN109582288B (en) Method, system and storage medium for producing configuration reflux
CN111666338B (en) Data replication method, control node and electronic equipment
CN117608921A (en) Backup method, recovery method and related equipment of cloud database
CN116245639A (en) Method, device, equipment and medium for updating transaction state
CN115062000A (en) Data isolation method and device, computer equipment and storage medium
CN117472928A (en) Database management method, device, electronic equipment and computer storage medium

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination