data synchronization method and device
Technical Field
The application relates to the technical field of internet information processing, in particular to data synchronization method and device.
Background
With the development of internet technology, cross-regional services have emerged. By cross-regional service may be meant services that are carried out or executed in different regions, such as: payment services across regions, purchase services across regions, and the like.
For the cross-regional service, central servers are needed to aggregate the service data generated by the cross-regional service in each region, so as to ensure the service data uniformity of the cross-regional service in each region.
However, in practical applications, for cross-region services, the central server receives the update data sent by the servers in each region, but when data synchronization update is performed, due to different times for generating the update data by the servers in each region, the central server is prone to have a problem that the update sequence is disordered when data synchronization update is performed, so that errors occur in data synchronization of the central server.
Disclosure of Invention
In view of this, the embodiments of the present application provide data synchronization methods and apparatuses, which are used to solve the problem in the prior art that the data synchronization sequence is out of order when data synchronization is completed across regional services.
The embodiment of the present application provides data synchronization methods, including:
receiving data to be synchronized, and determining data version information corresponding to the data to be synchronized;
when determining that the data version information corresponding to the data to be synchronized does not exist or the data version information corresponding to the data to be synchronized exists and is not overdue, locking the data version information corresponding to the data to be synchronized;
and performing data synchronization operation by using the locked data version information.
The embodiment of the present application further provides kinds of data synchronization devices, including:
the receiving unit is used for receiving data to be synchronized and determining data version information corresponding to the data to be synchronized;
the locking unit is used for locking the data version information corresponding to the data to be synchronized when the data version information corresponding to the data to be synchronized does not exist or the data version information corresponding to the data to be synchronized exists and is not overdue;
and a synchronization unit performing a data synchronization operation using the locked data version information.
The above-mentioned at least technical scheme that this application embodiment adopted can reach following beneficial effect:
the method comprises the steps of receiving data to be synchronized, determining data version information corresponding to the data to be synchronized, locking the data version information corresponding to the data to be synchronized when it is determined that the data version information corresponding to the data to be synchronized does not exist or the data version information corresponding to the data to be synchronized exists and is not expired, and performing data synchronization operation by using the locked data version information, wherein the data version information corresponding to the data to be synchronized is determined for the data to be synchronized, so that when data synchronization is performed, the data version information of the data to be synchronized is identified, the synchronization sequence of the data to be synchronized can be guaranteed, the problem of sequence disorder in the existing data synchronization process is avoided, particularly the problem of sequence disorder when data synchronization is performed on the same data in a distribution system is avoided, and the accuracy of the data synchronization is effectively improved.
Drawings
The accompanying drawings, which are incorporated herein and constitute part of this application and are included to provide a further understanding of the application, section of the application, illustrate embodiments of the application and together with the description serve to explain the application and not to limit the application.
Fig. 1 is a schematic flowchart of an data synchronization method according to an embodiment of the present application;
fig. 2 is a schematic flowchart of an data synchronization method according to an embodiment of the present application;
fig. 3 is a schematic structural diagram of data synchronization apparatuses according to an embodiment of the present application.
Detailed Description
In order to achieve the purpose of the present application, an embodiment of the present application provides data synchronization methods and apparatuses, which receive data to be synchronized, determine data version information corresponding to the data to be synchronized, lock the data version information corresponding to the data to be synchronized when it is determined that the data version information corresponding to the data to be synchronized does not exist, or the data version information corresponding to the data to be synchronized exists and is not expired, perform data synchronization operation using the locked data version information, determine corresponding data version information for the data to be synchronized with respect to the data to be synchronized sent by different apparatuses, so that when data synchronization is performed, by identifying the data version information of the data to be synchronized, a sequential synchronization order of the data to be synchronized can be ensured, a problem of a sequential disorder occurring in a current data synchronization process is avoided, particularly, a problem of a sequential disorder occurring when data synchronization is performed with respect to data in a distribution system is avoided, and accuracy of the data synchronization is effectively improved.
In this embodiment of the present application, version processors may be included for determining data version information of different pieces of service data, if service data is abstracted to records, then for the same service, data version information of pieces of latest service data for the service is stored in the version processor, and for different services, data version information of the latest service data of which the service type corresponds to the service type is stored in the version processor, and the storage manner may be a distributed storage manner, which is not specifically limited herein.
The present disclosure will now be described more fully hereinafter with reference to the detailed description of the preferred embodiments of the present disclosure and the accompanying drawings, in which some, but not all embodiments of are shown and described.
The technical solutions provided by the embodiments of the present application are described in detail below with reference to the accompanying drawings.
Example 1
Fig. 1 is a schematic flowchart of data synchronization methods provided in an embodiment of the present application.
Step 101: receiving data to be synchronized, and determining data version information corresponding to the data to be synchronized.
In step 101, receiving data to be synchronized may refer to receiving file data to be synchronized; or receiving message data to be synchronized; the method may also refer to receiving service data to be synchronized, and the type of the received service data to be synchronized is not limited herein.
After receiving the data to be synchronized, determining the service type of the received data to be synchronized, and further determining the data version information corresponding to the data to be synchronized.
Specifically, determining a service type of the data to be synchronized, and determining a service version identifier corresponding to the service type;
triggering a version processor corresponding to the service version identification according to the service version identification, and generating a data version identification for the data to be synchronized;
and taking the service version identification and the data version identification as data version information corresponding to the data to be synchronized.
The version processor is used for determining the service Type corresponding to Data when determining the Data version information of every Data, so that the service version identification (represented by version Biz Type) corresponding to the Data is determined based on the service Type, meanwhile, the version processor is used for assembling the Data version identification (represented by version Data ID) of the Data based on the service characteristics of the Data, and the Data version identification has -only property under the service version identification and can determine the Data only .
It should be noted that, in the same service types, only version information can exist for the same data, that is, the data version information corresponding to the service version identifier and the data version identifier can only identify data, so that, for multiple data version information of the same data to be synchronized, the problem of order disorder in the process of concurrently invoking synchronization in a distributed environment can be effectively avoided.
And 102, judging whether the data version information corresponding to the data to be synchronized exists, if so, executing to execute 103, otherwise, executing 105.
In step 102, according to the service version identifier and the data version identifier included in the data version to be synchronized, searching whether data version information caused by the service version identifier and the data version identifier exists in locally stored data version information;
if the data version information corresponding to the service version identification and the data version identification is found, judging that the data version information corresponding to the data to be synchronized exists;
if the data version information caused by the service version identifier and the data version identifier cannot be found, it is determined that the data version information corresponding to the data to be synchronized does not exist.
For example, according to the service version identifier contained in the data version to be synchronized, whether data version information caused by the service version identifier exists is searched;
if the data version information corresponding to the service version identifier is found, then step is performed to determine whether the found data version identifier of the data version information corresponding to the service version identifier corresponds to the data version identifier included in the data version to be synchronized, if not , it is determined that the data version information corresponding to the data to be synchronized does not exist, and if , it is determined that the data version information corresponding to the data to be synchronized exists.
Or, according to the data version identifier included in the data version to be synchronized, searching whether data version information caused by the data version identifier exists;
if the data version information corresponding to the data version identifier is found, then step is performed to determine whether the service version identifier of the found data version information corresponding to the data version identifier corresponds to the service version identifier included in the data version to be synchronized, if not , it is determined that the data version information corresponding to the data to be synchronized does not exist, and if , it is determined that the data version information corresponding to the data to be synchronized exists.
Step 103: judging whether the data version information corresponding to the data to be synchronized is overdue, and if so, executing step 104; if not, go to step 105.
In step 103, comparing the generation time corresponding to the data version information corresponding to the data to be synchronized with the generation date corresponding to the locally stored data version information;
if the generation time corresponding to the data version information corresponding to the data to be synchronized is later than the generation date corresponding to the locally stored data version information, determining that the data version information corresponding to the data to be synchronized is not expired;
and if the generation time corresponding to the data version information corresponding to the data to be synchronized is earlier than the generation date corresponding to the locally stored data version information, determining that the data version information corresponding to the data to be synchronized is expired.
In the embodiment of the present application, the manner of determining whether the data version information corresponding to the data to be synchronized is expired may be summarized as a logical comparison of the data version information, and then the corresponding comparison result may pass; may be pending; or may be outdated.
If the comparison result is passed, the data version information corresponding to the data to be synchronized is the current latest version information; if the comparison result is suspension, indicating that the data version information corresponding to the data to be synchronized is the current latest version information but the data version information currently executing data synchronization exists; and if the comparison result is overdue, indicating that the data version information corresponding to the data to be synchronized is not the latest version information.
In the embodiment of the present application, the version comparison rules corresponding to different types of data version information may also be different. For example: if the type of the data version information corresponding to the data to be synchronized is a digital type, comparing the data to be synchronized according to an ascending order, and if the number is larger, the version corresponding to the data to be synchronized is newer; if the type of the data version information corresponding to the data to be synchronized is a character type, comparing the data version information according to the descending order of the dictionary, and indicating that the version corresponding to the character is newer after the character is later; the type of the data version information corresponding to the data to be synchronized is a number type + a character type, and the larger the number is, the later the character is, the newer the corresponding version is.
Step 104: and when determining that the data version information corresponding to the data to be synchronized exists and is out of date, abandoning the data to be synchronized.
In step 104, when it is determined that the data version information corresponding to the data to be synchronized exists and is expired, it indicates that the data to be synchronized does not need to perform a synchronization operation, and the data to be synchronized is discarded.
Step 105: and when determining that the data version information corresponding to the data to be synchronized does not exist or the data version information corresponding to the data to be synchronized exists and is not overdue, locking the data version information corresponding to the data to be synchronized.
In step 105, when it is determined that the data version information corresponding to the data to be synchronized does not exist, or the data version information corresponding to the data to be synchronized exists and is not expired, it is indicated that the data version information corresponding to the data to be synchronized is the current latest version, and the database may be locked in a locking manner, that is, a Lock function is started.
It should be noted that, when it is determined that the data version information corresponding to the data to be synchronized does not exist, the data version information corresponding to the data to be synchronized may be directly stored, and the Lock function in the data version information is started.
Step 106: and performing data synchronization operation by using the locked data version information.
In step 106, a data synchronization operation is performed using the locked data version information, and when the data synchronization operation is completed, the Lock is released, that is, the Lock function is changed from the locked state to the unlocked state.
According to the scheme recorded in the embodiment of the application, the data to be synchronized is received, the data version information corresponding to the data to be synchronized is determined, when the data version information corresponding to the data to be synchronized does not exist or the data version information corresponding to the data to be synchronized exists and is not expired, the data version information corresponding to the data to be synchronized is locked, data synchronization operation is performed by using the locked data version information, the corresponding data version information is determined for the data to be synchronized aiming at the data to be synchronized sent by different equipment, so that when data synchronization is performed, the sequential synchronization sequence of the data to be synchronized can be guaranteed by identifying the data version information of the data to be synchronized, the problem of sequence disorder in the existing data synchronization process is avoided, particularly the problem of sequence disorder when data synchronization is performed on data in a distribution system is avoided, and the accuracy of the data synchronization is effectively improved.
It should be noted that the execution subject of each step of the method provided in embodiment 1 may be the same device, or different devices may also be used as the execution subject of the method, for example, the execution subject of step 101 and step 102 may be device 1, and the execution subject of step 103 may be device 2, for example, the execution subject of step 101 may be device 1, and the execution subject of step 102 and step 103 may be device 2, and so on.
Example 2
Fig. 2 is a schematic flow chart of data synchronization methods provided in the embodiments of the present application.
Step 201: data to be synchronized is received.
Step 202: and determining data version information corresponding to the data to be synchronized.
Step 203: judging whether the data version information corresponding to the data to be synchronized exists, if so, executing step 206; otherwise, step 204 is performed.
Step 204: and saving data version information corresponding to the data to be synchronized.
Step 205: and locking the data version information corresponding to the data to be synchronized, and performing data synchronization operation by using the locked data version information.
Step 206: judging whether the data version information corresponding to the data to be synchronized is overdue, if so, executing 207; otherwise, 208 is performed.
Step 207: and when determining that the data version information corresponding to the data to be synchronized exists and is out of date, abandoning the data to be synchronized.
Step 208: and when the data version information corresponding to the data to be synchronized exists and is not overdue, locking the data version information corresponding to the data to be synchronized.
Step 209: and performing data synchronization operation by using the locked data version information.
Example 3
Fig. 3 is a schematic structural diagram of data synchronization devices provided in an embodiment of the present application, where the data synchronization device includes a receiving unit 31, a locking unit 32, and a synchronization unit 33, where:
the receiving unit 31 receives data to be synchronized and determines data version information corresponding to the data to be synchronized;
a locking unit 32, configured to lock the data version information corresponding to the data to be synchronized when it is determined that the data version information corresponding to the data to be synchronized does not exist or the data version information corresponding to the data to be synchronized exists and is not expired;
a synchronization unit 33 for performing a data synchronization operation using the locked data version information.
In another embodiments of the present application, the determining, by the receiving unit 31, data version information corresponding to the data to be synchronized includes:
determining the service type of the data to be synchronized, and determining a service version identifier corresponding to the service type;
triggering a version processor corresponding to the service version identification according to the service version identification, and generating a data version identification for the data to be synchronized;
and taking the service version identification and the data version identification as data version information corresponding to the data to be synchronized.
In another embodiments of the present application, the data synchronization apparatus further includes a judging unit 34, wherein:
the judging unit 34, after determining the data version information corresponding to the data to be synchronized, judges whether the data version information corresponding to the data to be synchronized exists;
if yes, step is performed to determine whether the data version information corresponding to the data to be synchronized has expired.
In another embodiments of the present application, the determining unit 34 determines whether data version information corresponding to the data to be synchronized exists, including:
according to the service version identification and the data version identification contained in the data version to be synchronized, whether data version information caused by the service version identification and the data version identification exists in locally stored data version information is searched;
if the data version information corresponding to the service version identification and the data version identification is found, judging that the data version information corresponding to the data to be synchronized exists;
if the data version information caused by the service version identifier and the data version identifier cannot be found, it is determined that the data version information corresponding to the data to be synchronized does not exist.
In another embodiments of the present application, the determining unit 34 determines whether the data version information corresponding to the data to be synchronized has expired, including:
comparing the generation time corresponding to the data version information corresponding to the data to be synchronized with the generation date corresponding to the locally stored data version information;
if the generation time corresponding to the data version information corresponding to the data to be synchronized is later than the generation date corresponding to the locally stored data version information, determining that the data version information corresponding to the data to be synchronized is not expired;
and if the generation time corresponding to the data version information corresponding to the data to be synchronized is earlier than the generation date corresponding to the locally stored data version information, determining that the data version information corresponding to the data to be synchronized is expired.
In another embodiments of the present application, the data synchronization device further comprises a discarding unit 35, wherein:
the discarding unit 35 discards the data to be synchronized when it is determined that the data version information corresponding to the data to be synchronized exists and is expired.
The data synchronization device determines corresponding data version information for the data to be synchronized, so that when data synchronization is performed, by identifying the data version information of the data to be synchronized, the sequential synchronization sequence of the data to be synchronized can be ensured, the problem of sequence disorder in the existing data synchronization process is avoided, especially the problem of sequence disorder when data synchronization is performed on data in a distribution system is avoided, and the accuracy of the data synchronization is effectively improved.
Furthermore, the present invention may take the form of a computer program product embodied on or more computer-usable storage media (including, but not limited to, disk storage, CD-ROM, optical storage, etc.) having computer-usable program code embodied therein.
It is to be understood that each flow and/or block in the flow diagrams and/or block diagrams, and combinations of flows and/or blocks in the flow diagrams and/or block diagrams, can be implemented by computer program instructions which can be provided to a processor of a general purpose computer, special purpose computer, embedded processor, or other programmable data processing apparatus to produce a machine, such that the instructions, which execute via the processor of the computer or other programmable data processing apparatus, create means for implementing the functions specified in the flow diagram flow or flows and/or block diagram block or blocks.
These computer program instructions may also be stored in a computer-readable memory that can direct a computer or other programmable data processing apparatus to function in a particular manner, such that the instructions stored in the computer-readable memory produce an article of manufacture including instruction means which implement the function specified in the flowchart flow or flows and/or block diagram block or blocks.
These computer program instructions may also be loaded onto a computer or other programmable data processing apparatus to cause a series of operational steps to be performed on the computer or other programmable apparatus to produce a computer implemented process such that the instructions which execute on the computer or other programmable apparatus provide steps for implementing the functions specified in the flowchart flow or flows and/or block diagram block or blocks.
In typical configurations, a computing device includes or more processors (CPUs), input/output interfaces, network interfaces, and memory.
The memory may include forms of volatile memory in a computer readable medium, Random Access Memory (RAM) and/or non-volatile memory, such as Read Only Memory (ROM) or flash memory (flash RAM). Memory is an example of a computer-readable medium.
Computer-readable media, including both non-transitory and non-transitory, removable and non-removable media, may implement information storage by any method or technology. The information may be computer readable instructions, data structures, modules of a program, or other data. Examples of computer storage media include, but are not limited to, phase change memory (PRAM), Static Random Access Memory (SRAM), Dynamic Random Access Memory (DRAM), other types of Random Access Memory (RAM), Read Only Memory (ROM), Electrically Erasable Programmable Read Only Memory (EEPROM), flash memory or other memory technology, compact disc read only memory (CD-ROM), Digital Versatile Discs (DVD) or other optical storage, magnetic cassettes, magnetic tape magnetic disk storage or other magnetic storage devices, or any other non-transmission medium that can be used to store information that can be accessed by a computing device. As defined herein, a computer readable medium does not include a transitory computer readable medium such as a modulated data signal and a carrier wave.
It should also be noted that the terms "comprises," "comprising," or any other variation thereof, are intended to cover a non-exclusive inclusion, such that a process, method, article, or apparatus that comprises the series of elements does not include only those elements but may include other elements not expressly listed or inherent to such process, method, article, or apparatus.
Moreover, the present application may take the form of a computer program product embodied on or more computer-usable storage media (including but not limited to disk storage, CD-ROM, optical storage, etc.) having computer-usable program code embodied therein.
The above description is only an example of the present application and is not intended to limit the present application. Various modifications and changes may occur to those skilled in the art. Any modification, equivalent replacement, improvement, etc. made within the spirit and principle of the present application should be included in the scope of the claims of the present application.