CN112463786A - Data synchronization method, system, server and storage medium - Google Patents

Data synchronization method, system, server and storage medium Download PDF

Info

Publication number
CN112463786A
CN112463786A CN202011455862.5A CN202011455862A CN112463786A CN 112463786 A CN112463786 A CN 112463786A CN 202011455862 A CN202011455862 A CN 202011455862A CN 112463786 A CN112463786 A CN 112463786A
Authority
CN
China
Prior art keywords
data
service data
source database
server
data content
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.)
Granted
Application number
CN202011455862.5A
Other languages
Chinese (zh)
Other versions
CN112463786B (en
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.)
Shanghai Jining Computer Technology Co ltd
Original Assignee
Shanghai Jining Computer 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 Shanghai Jining Computer Technology Co ltd filed Critical Shanghai Jining Computer Technology Co ltd
Priority to CN202011455862.5A priority Critical patent/CN112463786B/en
Publication of CN112463786A publication Critical patent/CN112463786A/en
Application granted granted Critical
Publication of CN112463786B publication Critical patent/CN112463786B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

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/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/21Design, administration or maintenance of databases
    • G06F16/219Managing data history or versioning
    • 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/2358Change logging, detection, and notification
    • 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/24Querying
    • G06F16/245Query processing
    • G06F16/2458Special types of queries, e.g. statistical queries, fuzzy queries or distributed queries
    • G06F16/2474Sequence data queries, e.g. querying versioned data
    • 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)
  • Physics & Mathematics (AREA)
  • General Physics & Mathematics (AREA)
  • General Engineering & Computer Science (AREA)
  • Data Mining & Analysis (AREA)
  • Computing Systems (AREA)
  • Quality & Reliability (AREA)
  • Fuzzy Systems (AREA)
  • Mathematical Physics (AREA)
  • Probability & Statistics with Applications (AREA)
  • Software Systems (AREA)
  • Computational Linguistics (AREA)
  • Information Retrieval, Db Structures And Fs Structures Therefor (AREA)

Abstract

The embodiment of the invention relates to the technical field of data processing, and discloses a data synchronization method, a data synchronization system, a server and a storage medium. In the invention, local service data is deduced according to the current updating operation; comparing the local service data with the service data of the source database, and recording new updating operation according to the comparison result; and sending the new updating operation to the target database for the target database to carry out data synchronization according to the new updating operation. The network transmission quantity of the target database and the server only comprises the step that the server sends the new updating operation to the server, so that the network transmission quantity between the server and the target database is reduced, the synchronization speed can be improved, the server does not need to compare the local service data with the service data of the source data after the target database sends a data synchronization request, the server can send the new updating operation to the target database immediately after recording the new updating operation according to the comparison result, and the synchronization speed is also improved.

Description

Data synchronization method, system, server and storage medium
Technical Field
The embodiment of the invention relates to the technical field of data processing, in particular to a data synchronization method, a data synchronization system, a server and a storage medium.
Background
The data synchronization refers to synchronizing the service data in the source database into one or more target databases, so that the service data in the target databases and the service data in the source database are kept consistent. In the process of data synchronization, because the target database and the source database are generally in different local area networks, the target database and the source database cannot be directly communicated with each other, the target database and the source database need to be transferred through a server in two local area networks at the same time, that is, the target database sends a data request to the server, the server sends the data request to the source database, the source database sends the latest service data to the target database through the server, so that the target database compares the latest service data according to the service data and updates the target database, thereby the service data in the target database and the service data in the source database are kept consistent, however, the server needs to send all the latest service data of the source database to the target database, which results in a large network transmission amount between the server and the target database, when the network transmission amount is large, the transmission speed is slow, so that the synchronization speed is slow, and the server requests the latest service data from the server when the target database needs to perform data synchronization, so that a certain time is occupied, and the synchronization speed is slow.
Disclosure of Invention
Embodiments of the present invention provide a data synchronization method, system, server, and storage medium, which can reduce the network transmission amount between a server and a target database and improve the synchronization speed.
In order to solve the foregoing technical problem, an embodiment of the present invention provides a data synchronization method, which is applied to a server in a data synchronization system, where the data synchronization system further includes a source database and a target database that are respectively connected to the server, and the method includes: deducing local service data according to the current updating operation; comparing the local service data with the service data of the source database, and recording new updating operation according to the comparison result; and sending the new updating operation to a target database for the target database to carry out data synchronization according to the new updating operation.
The embodiment of the invention also provides a data synchronization method, which is applied to a target database in a data synchronization system, the data synchronization system also comprises a server connected with the target database and the target database connected with the server, and the method comprises the following steps: receiving a new updating operation sent by the server; the new updating operation is obtained by comparing the local service data with the service data of the source database by the server side and recording according to a comparison result; and carrying out data synchronization according to the new updating operation.
An embodiment of the present invention further provides a data synchronization system, including: a source database, a server and a target database; the source database is used for providing service data of the source data; the server is used for deducing local service data according to the current updating operation; comparing the local service data with the service data of the source database, and recording new updating operation according to the comparison result; sending the new updating operation to a target database for data synchronization of the target database; and the target database is used for receiving the new updating operation sent by the server and carrying out data synchronization according to the new updating operation.
An embodiment of the present invention further provides a server, including: at least one processor; and a memory communicatively coupled to the at least one processor; wherein the memory stores instructions executable by the at least one processor to enable the at least one processor to perform the data synchronization method described above.
Embodiments of the present invention further provide a computer-readable storage medium, which stores a computer program, and when the computer program is executed by a processor, the computer program implements the data synchronization method described above.
Compared with the prior art, the embodiment of the invention deduces local service data according to the current updating operation; comparing the local service data with the service data of the source database, and recording new updating operation according to the comparison result; and sending the new updating operation to the target database for data synchronization of the target database. By the method, the network transmission quantity of the target database and the server only comprises the step that the server sends the new updating operation to the server, and the server does not need to send all the service data of the source database acquired from the source database to the target database, so that the network transmission quantity between the server and the target database is reduced, the transmission speed is higher as the network transmission quantity is smaller, the synchronization speed can be improved, the server does not need to compare the local service data with the service data of the source data after the target database sends a data synchronization request, and the server can immediately send the new updating operation to the target database according to the comparison result, and the synchronization speed is also improved.
Additionally, the new update operation comprises a delete operation; comparing the local service data with the service data of the source database, and recording a new updating operation according to a comparison result, including: traversing the data content in the local service data, searching the currently traversed data content in the service data of the source database, and recording the deletion operation of deleting the currently traversed data content if the currently traversed data content is not searched. If the data content in the service data of the source database is deleted, the data content does not exist in the service data of the source database any more, so that the deletion operation can be accurately determined by traversing the data content in the local service data so as to record the deletion operation, and after the deletion operation is recorded, the recorded deletion operation only needs to be sent to the target database, so that the network transmission quantity between the server and the target database is reduced, and the synchronization speed is also improved.
Additionally, the new update operation comprises an add operation; comparing the local service data with the service data in the source database, and recording a new updating operation according to a comparison result, including: traversing the data content in the service data of the source database, searching the currently traversed data content in the local service data, and recording the newly-added operation of newly-added currently traversed data content if the currently traversed data content is not searched. If the data content in the service data of the source database is subjected to new adding operation, the data content does not exist in the local service data, so that the new adding operation can be accurately determined by traversing the data content in the service data of the source database so as to record the new adding operation, and after the new adding operation is recorded, the recorded new adding operation only needs to be sent to the target database, so that the network transmission quantity between the server side and the target database is reduced, and the synchronization speed is also improved.
In addition, if the data content in the service data respectively has a primary key, the new updating operation also comprises a modifying operation; comparing the local service data with the service data in the source database, and recording a new updating operation according to a comparison result, including: traversing data contents in local service data, searching a main key in the currently traversed data contents in the service data of the source database, and if the main key in the currently traversed data contents is found and the data contents in the service data of the source database, which have the same main key as the currently traversed data contents, are not completely consistent with the currently traversed data contents, recording and modifying operation according to the data contents in the service data of the source database, which have the same main key as the currently traversed data contents; or traversing the data content in the service data of the source database, searching the main key in the currently traversed data content in the local service data, and if the main key in the currently traversed data content is found and the data content in the local service data, which has the same main key as the currently traversed data content, is not completely consistent with the currently traversed data content, recording and modifying operation according to the currently traversed data content. If the data contents in the service data respectively have the primary keys, the primary keys are unique in characteristic, so that when the currently traversed primary keys in the data contents exist in the service data of the source database, the modification operation can be recorded by comparing whether the data contents are completely consistent and accurately determining which modification operation is performed, and after the modification operation is recorded, the recorded modification operation only needs to be sent to the target database, so that the network transmission quantity between the server and the target database is reduced, and the synchronization speed is also improved.
In addition, if the data content in the service data respectively has a primary key, in the searching of the currently traversed data content, the primary key in the currently traversed data content is searched, and if the primary key in the currently traversed data content is not searched, it indicates that the currently traversed data content is not searched. If the data content in the service data is respectively provided with the main key, the deletion operation can be determined only by searching the main key, at the moment, only the main key of the data content in the local service data needs to be obtained, the workload is reduced, the server only needs to search the main key from the source database, the network transmission quantity between the server and the source database is reduced, and after the deletion operation is recorded, only the recorded deletion operation needs to be sent to the target database, the operation is simple, and the network transmission quantity between the server and the target database is reduced, so that the overall network transmission quantity is reduced, the synchronization speed is also improved, or the newly-added operation can be determined only by searching the main key, at the moment, only the main key of the data content in the service data of the source database needs to be obtained, the work is reduced, and the server only needs to search the main key from the source database, the network transmission quantity between the server and the target database is reduced by only sending the recorded new operation to the target database after the new operation is recorded, so that the overall network transmission quantity is reduced, and the synchronization speed is also improved.
In addition, if the service data of the source database has a version control column, the data content in the service data of the source database is determined in the following manner: inquiring the latest version number of the current updating operation to obtain a first latest version number; and searching the data content corresponding to the version number greater than the first latest version number from the version control column of the service data of the source database to obtain a first search result, and taking the first search result as the data content in the service data of the source database. If the service data of the source database has the version control column, which data contents in the source database are updated can be known according to the version control column, then the data contents corresponding to the version number greater than the first latest version number are searched from the version control column of the service data in the source database, and at this time, the data contents in the service data of the source database, which are searched by traversing, are the data contents of the updated service data, so that the network transmission quantity between the server and the source database is reduced, and the synchronization speed is further improved.
In addition, if the new updating operation is a modifying operation, the modifying operation only includes modified data content. By the method, the record of the modification operation only comprises the modified data content, and the whole data content of the service data does not need to be recorded in the modification operation, so that the data volume recorded in the modification operation can be reduced, and the network transmission volume is further reduced.
In addition, before the pushing the local service data according to the current updating operation, the method further includes: and receiving a monitoring request sent by the target database, wherein the monitoring request is used for representing that the server side sends a new updating operation to the target database when monitoring that the new updating operation exists. By the method, the server does not need to forward the data synchronization request of the target database to the source database, and only sends the new update operation to the target database when the new update operation exists, so that the network transmission quantity between the server and the source database can be reduced, and the whole network transmission quantity is reduced.
In addition, the method further comprises: inquiring a latest version number corresponding to data content in the service data of the target database to obtain a second latest version number; if the data content corresponding to the second latest version number in the service data of the target database is judged to be synchronous and complete, searching for the updating operation corresponding to the version number larger than the second latest version number from the current updating operation to obtain a second searching result; if the synchronization of the data content corresponding to the second latest version number in the service data of the target database is judged to be incomplete, searching for the updating operation corresponding to the version number not less than the second latest version number from the current updating operation to obtain a second searching result; and sending the second search result to the target database for the target database to perform data synchronization according to the second search result. By the method, the possibility that all the updating operations are sent to the target database can be improved, the updating operations are prevented from being missed, and the integrity of the updating operations received by the target database is improved, so that the integrity of data contents in the service data of the target database in the data synchronization process is improved, and the accuracy of data synchronization is improved.
In addition, after comparing the local service data with the service data of the source database and recording a new update operation according to a comparison result, the method further includes: and sending the number of the new updating operations to a target database, so that the target database can verify whether the synchronous data content is complete according to the number of the new updating operations. By the method, the server side also sends the number of the new updating operations to the target database, so that the target database can verify whether the synchronous data content is complete according to the number of the new updating operations, thereby verifying whether the data synchronization is complete, improving the integrity of the data content in the service data of the target database in the data synchronization process and improving the accuracy of the data synchronization.
Drawings
One or more embodiments are illustrated by way of example in the accompanying drawings, which correspond to the figures in which like reference numerals refer to similar elements and which are not to scale unless otherwise specified.
Fig. 1 is a flow chart of a data synchronization method according to a first embodiment of the present invention;
FIG. 2 is a flow chart of a data synchronization method according to a second embodiment of the present invention;
FIG. 3 is a flow chart of a data synchronization method according to a third embodiment of the present invention;
FIG. 4 is a flow chart of a data synchronization method according to a fourth embodiment of the present invention;
FIG. 5 is a schematic diagram of a data synchronization system according to a fifth embodiment of the present invention;
fig. 6 is a schematic structural diagram of a server in a sixth embodiment according to the present invention.
Detailed Description
In order to make the objects, technical solutions and advantages of the embodiments of the present invention more apparent, the embodiments of the present invention will be described in detail with reference to the accompanying drawings. However, it will be appreciated by those of ordinary skill in the art that in various embodiments of the invention, numerous technical details are set forth in order to provide a better understanding of the present application. However, the technical solution claimed in the present application can be implemented without these technical details and various changes and modifications based on the following embodiments. The following embodiments are divided for convenience of description, and should not constitute any limitation to the specific implementation manner of the present invention, and the embodiments may be mutually incorporated and referred to without contradiction.
A first embodiment of the present invention relates to a data synchronization method, which is applied to a server in a data synchronization system, where the data synchronization system further includes a source database and a target database respectively connected to the server, and a specific process is shown in fig. 1, and includes:
and step 101, deducing local service data according to the current updating operation.
Specifically, in this embodiment, the number of the servers in the data synchronization system is one, and the update operation is stored in a local cache area of the server, where the update operation at least includes one of the following operations or any combination thereof: deleting operation, adding operation and modifying operation, wherein the updating operation at least comprises data type, data content and version number, the version number of the updating operation recorded in the same comparison process is the same, and the version number of the new updating operation recorded in the comparison process is larger than the version number of the new updating operation recorded in the comparison process at the last time. The server may deduce local service data through the current update operation in the cache, for example: the current update operations include: the new [ ID ] [ a ], [ name ] [ A ], [ age ] [16], version [1], new [ ID ] [ B ], [ name ] [ B ], [ age ] [17], version [1], new [ ID ] [ C ], [ name ] [ C ], [ age ] [18], version [1], delete [ ID ] [ a ], version [2], modified [ ID ] [ C ], [ age ] [19], version [2], new [ ID ] [ D ], [ name ] [ D ], [ age ] [19], version [2], is deduced according to the current update operation, and [ ID ] is [ a ] which comprises two update operations: adding [ ID ] [ a ], [ name ] [ A ], [ age ] [16], version [1], deleting [ ID ] [ a ], and version [2], and knowing that the data content is deleted; [ ID ] is [ b ] includes an update operation: newly adding [ ID ] [ B ], [ name ] [ B ], [ age ] [17] and version [1], thus obtaining a piece of local data content [ ID ] [ B ], [ name ] [ B ], [ age ] [17 ]; [ ID ] is [ c ] includes two update operations: newly adding [ ID ] [ C ], [ name ] [ C ], [ age ] [18], version [1], modifying [ ID ] [ C ], [ age ] [19] and version [2], thus obtaining a piece of local data content [ ID ] [ C ], [ name ] [ C ], [ age ] [19 ]; [ ID ] is [ c ] includes an update operation: adding [ ID ] [ D ], [ name ] [ D ], [ age ] [19] and version [1], obtaining a piece of local data content [ ID ] [ D ], [ name ] [ D ], [ age ] [19], and deducing local service data, wherein the step of adding [ ID ] [ D ], [ name ] [ D ], [ age ] [19], comprises the following steps: [ ID ] [ B ], [ name ] [ B ], [ age ] [17], [ ID ] [ C ], [ name ] [ C ], [ age ] [19], [ ID ] [ D ], [ name ] [ D ], [ age ] [19 ]. In an example, the server may also update the local service data in real time according to the new update operation when recording the new update operation, and store the local service data, so that the local service data can be directly used when needed. In one example, the update operation includes one or any combination of the following in addition to the data type, data content and version number: a hash of the time and bytes is generated. In one example, the update operation is stored in memory at the server side, which may enable caching and cache retrieval as compared to storing the update operation to disk. In one example, the update operations for different forms may be stored in the same cache or may be stored in different caches.
And 102, comparing the local service data with the service data of the source database, and recording new updating operation according to the comparison result.
Specifically, after the local service data is derived, the server may compare the local service data with the service data of the source database in real time, or compare the local service data with the service data of the source database according to a preset period, where the preset period may be set according to actual needs, and this embodiment is not limited specifically. In the process of data comparison, the server records the updating operation in the process of data comparison to obtain a new updating operation.
In one example, the new update operation includes a delete operation, comparing the local service data with the service data in the source database, and recording the new update operation according to the comparison result, including: traversing the data content in the local service data, searching the currently traversed data content in the service data of the source database, and recording the deletion operation of deleting the currently traversed data content if the currently traversed data content is not searched.
In one example, if the data content in the service data has the primary key, in searching the currently traversed data content, the primary key in the currently traversed data content is searched, and if the primary key in the currently traversed data content is not searched, it indicates that the currently traversed data content is not searched. Specifically, the primary key is data content for identifying an Identity, i.e., the primary key is an Identity card (ID), and has uniqueness. As will be described in more detail below with reference to an example, the current update operation includes: adding [ ID ] [ a ], [ name ] [ A ], [ age ] [16], version [1], adding [ ID ] [ B ], [ name ] [ B ], [ age ] [17], version [1], adding [ ID ] [ C ], [ name ] [ C ], [ age ] [18] and version [1], deducing local service data as shown in table one, wherein table two is the service data of the source database; traversing data contents in local service data, acquiring a main key 'a' when traversing the data contents 'a, A and 16', searching 'a' in the service data of a source database, and recording deletion operations of 'deleting [ ID ] [ a ], version [2 ]' when 'a' which is not searched indicates that the currently traversed data contents are not searched; when the data content 'B, B, 17' is traversed, the main key 'B' is obtained, the 'B' is searched in the service data of the source database, and the data is ignored when the 'B' is searched at the moment; when traversing to the data content 'C, 18', acquiring the primary key 'C', searching 'C' in the service data of the source database, if the data is ignored when the primary key 'C' is found, acquiring a new updating operation as follows: "delete [ ID ] [ a ], version [2 ]".
ID Name (I) Age (age)
a A 16
b B 17
c C 18
Table one: local service data
ID Name (I) Age (age)
b B 17
c C 19
Table two: service data of source database
In one example, in the searching of the currently traversed data content, all data contents in the currently traversed data content are searched, and if all data contents in the currently traversed data content are not searched, it indicates that the currently traversed data content is not searched. Specifically, as will be described in more detail below with reference to an example, the current update operation includes, in a second example: the name [ A ], [ age ] [16], the version [1], [ name ] [ B ], [ age ] [17], the version [1], [ name ] [ C ], [ age ] [18], and the version [1], then local business data is deduced as shown in the third table, and the fourth table is the business data of the source database; traversing each data content in the local service data, searching for the data content A, 16 in the source database when traversing the data content A, 16, not searching for the data content A, 16 at the moment, and recording deletion operations of deleting the name, the age and the version 2; when the data content 'B, 17' is traversed, searching 'B, 17' in the source database, and if the 'B, 17' is searched, ignoring the data; when traversing to the data content "C, 18", searching for "C, 18" in the source database, at this time, not searching for "C, 18", recording the deletion operation of "delete [ name ] [ C ], [ age ] [18], version [2 ]", and then obtaining a new update operation as: "delete [ name ] [ A ], [ age ] [16], version [2 ]" and "delete [ name ] [ C ], [ age ] [18], version [2 ]".
Name (I) Age (age)
A 16
B 17
C 18
Table three: local service data
Name (I) Age (age)
B 17
C 19
Table four: service data of source database
In one example, the new update operation comprises an add operation; comparing the local service data with the service data in the source database, and recording new updating operation according to the comparison result, wherein the updating operation comprises the following steps: traversing the data content in the service data of the source database, searching the currently traversed data content in the local service data, and recording the newly-added operation of newly-added currently traversed data content if the currently traversed data content is not searched.
In one example, if the data content in the service data has the primary key, in searching the currently traversed data content, the primary key in the currently traversed data content is searched, and if the primary key in the currently traversed data content is not searched, it indicates that the currently traversed data content is not searched. Specifically, as will be described in detail below with reference to an example, in a third example, the current update operation includes: newly adding [ ID ] [ a ], [ name ] [ A ], [ age ] [16], version [1], newly adding [ ID ] [ B ], [ name ] [ B ], [ age ] [17], version [1], newly adding [ ID ] [ C ], [ name ] [ C ], [ age ] [18], version [1], deducing local service data as shown in table one, wherein table five is service data of a source database, at the moment, the service data of the source database does not have a version control column, traversing all data contents in the service data of the source database, acquiring a main key "B" when traversing to the data contents "B, B and 17", searching "B" in the local service data, and ignoring the data when searching "B" at the moment; when data content 'C, C, 19' is traversed, a main key 'C' is obtained, the 'C' is searched in local service data, and the data is ignored when the 'C' is searched; when traversing the data content 'D, D, 19', acquiring the primary key 'D', searching the local service data for 'D', not searching the local service data for 'D', recording the new operations of 'newly adding [ ID ] [ D ], [ name ] [ D ], [ age ] [19], and version [2],' and then acquiring new updating operations as follows: "newly added [ ID ] [ D ], [ name ] [ D ], [ age ] [19], version [2 ]".
ID Name (I) Age (age)
b B 17
c C 19
d D 19
Table five: service data of source database
In one example, in the searching of the currently traversed data content, all data contents in the currently traversed data content are searched, and if all data contents in the currently traversed data content are not searched, it indicates that the currently traversed data content is not searched. Specifically, as will be described in detail below with reference to an example, in a fourth example, the current update operation includes: the name [ A ], [ age ] [16], the version [1], [ name ] [ B ], [ age ] [17], the version [1], [ name ] [ C ], [ age ] [18], and the version [1], then local business data is deduced as shown in the third table, and the sixth table is the business data of the source database; when the service data of the source database does not have the version control column, traversing all data contents in the service data of the source database, and when the data content 'B, 17' is traversed, finding the 'B, 17' at the moment, ignoring the data; when traversing to the data content "C, 19", the new operation of "new [ name ] [ C ], [ age ] [19], version [2] is not found at this time, the new operation of" new [ name ] [ D ], [ age ] [19], version [2] is recorded when traversing to the data content "D, 19", and then the new update operation is obtained: "New [ name ] [ C ], [ age ] [19], version [2 ]" and "New [ name ] [ D ], [ age ] [19], version [2 ]".
Name (I) Age (age)
B 17
C 19
D 19
Table six: service data of source database
In one example, if the data content in the service data respectively has a primary key, the new update operation further includes a modification operation; comparing the local service data with the service data in the source database, and recording new updating operation according to the comparison result, wherein the updating operation comprises the following steps: traversing the data content in the local service data, searching the main key in the currently traversed data content in the service data of the source database, and if the main key in the currently traversed data content is found and the data content in the service data of the source database, which has the same main key as the currently traversed data content, is not completely consistent with the currently traversed data content, recording and modifying operation according to the data content in the service data of the source database, which has the same main key as the currently traversed data content.
Specifically, as will be described in detail below with reference to an example, in the fifth example, if [ ID ] [ a ], [ name ] [ a ], [ age ] [16], version [1], new [ ID ] [ B ], [ name ] [ B ], [ age ] [17], version [1], new [ ID ] [ C ], [ name ] [ C ], [ age ] [18], and version [1] are added, local service data is derived as shown in table one, and table two is service data of the source database; traversing data contents in local service data, searching for 'a' in the service data of the source database when traversing the data contents 'a, A and 16', acquiring a main key 'a', and ignoring the data when not searching for 'a'; when the data content 'B, B, 17' is traversed, searching 'B' in the service data of the source database, acquiring a primary key 'B', searching 'B' at the moment, wherein the data content with the same primary key 'B' in the service data of the source database is 'B, B, 17', which is completely consistent with the currently traversed data content, and ignoring the data; when traversing the data content 'C, 18', acquiring the primary key 'C', searching the 'C' in the service data of the source database, searching the 'C', wherein the data content with the same primary key 'C' in the service data of the source database is 'C, 19', which is not completely consistent with the currently traversed data content, and then modifying the [ ID ] [ C ] name [ C ] age [19] and the version [2] according to the record of 'C, 19', and obtaining a new updating operation as follows: "Modify [ ID ] [ C ] name [ C ] age [19], version [2 ]". In one example, if only the modified data content is included in the modification operation, then the modification operation of "modify [ ID ] [ c ] age [19], version [2] is recorded.
In one example, if the data content in the service data respectively has a primary key, the new update operation further includes a modification operation; comparing the local service data with the service data in the source database, and recording new updating operation according to the comparison result, wherein the updating operation comprises the following steps: and traversing the data content in the service data of the source database, searching the main key in the currently traversed data content in the data content of the local service data, and recording modification operation according to the currently traversed data content if the main key in the currently traversed data content is found and the data content of the local service data, which has the same main key as the currently traversed data content, is not completely consistent with the currently traversed data content.
Specifically, as will be described in detail below with reference to an example, in the sixth example, if [ ID ] [ a ], [ name ] [ a ], [ age ] [16], version [1], new [ ID ] [ B ], [ name ] [ B ], [ age ] [17], version [1], new [ ID ] [ C ], [ name ] [ C ], [ age ] [18], and version [1] are added, local service data is derived as shown in table one, and table five is service data of the source database; traversing data content in service data of a source database, acquiring a main key 'B' when traversing the data content 'B, B, 17', searching 'B' in local service data, searching 'B' at the moment, wherein the data content with the same main key 'B' in the local service data is 'B, B, 17', which is completely consistent with the currently traversed data content, and ignoring the data; when traversing the data content ' C, 19 ', acquiring the primary key ' C ', searching ' C ' in the service data of the source database, searching ' C ' at the moment, wherein the data content with the same primary key ' C ' in the service data of the source database is ' C, 18 ', which is not completely consistent with the currently traversed data content, acquiring the primary key ' D ' according to the ' C, 19 ' record ' modification of the [ ID ] [ C ] name [ C ] age [19], version [2], when traversing the data content ' D, D, 19 ', acquiring the primary key ' D ', not searching ' D ' in the local service data, not searching ' D ' at the moment, and ignoring the data to obtain a new updating operation as follows: "Modify [ ID ] [ C ] name [ C ] age [19], version [2 ]". In one example, if only the modified data content is included in the modification operation, then the modification operation of "modify [ ID ] [ c ] age [19], version [2] is recorded.
In one example, if the service data of the source database has a version control column, the data content in the service data of the source database is determined by the following method: inquiring the latest version number of the current updating operation to obtain a first latest version number; and searching the data content corresponding to the version number greater than the first latest version number from the version control column of the service data of the source database to obtain a first search result, and taking the first search result as the data content in the service data of the source database.
Specifically, the service data of the source database records a version number of the data content through a version control column, where table seven is the service data of the source database, a fourth column in table seven is a version control column, the version control column is not the data content of the service data and is only used to identify the version number of the data content of the service data, when the data content of the source database is subjected to a new addition and modification operation, the version number of the data content subjected to the new addition and modification operation changes, and the version numbers of the service data subjected to the new addition and modification operation in the same update process are the same, and the version number of the update operation recorded in the update process is greater than the version number of the update operation recorded in the previous update process, for example: the version number corresponding to "B, 17" in the service data of the source database is 1, and the version number corresponding to "C, 18" is 1; in the first updating process, "18" in "C" is modified to "19", and for the data content subjected to the modifying operation, the version number corresponding to "C, 19" is 2, and "D, 19" is newly added, and for the data content subjected to the adding operation, the version number corresponding to "D, 19" is 2, as shown in table eight, it is the service data of the source database after the first updating, in the second updating process, "19" in "B" is modified to "20", as shown in table nine, the version number corresponding to "B, 20" is 3, as shown in table nine, it is the service data of the source database after the second updating. In the process of data comparison, the latest version number of the current updating operation is inquired, and if the current updating operation has: adding 'a, A, 16', the version number is 1; newly adding 'B, B, 17', wherein the version number is 1; and if the service data of the source database is shown as table eight, searching the data content corresponding to the version number with the version number greater than 1 from the version control column of the service data of the source database according to the table eight to obtain search results of "C, 19" and "D, 19", and traversing "C, 19" and "D, 19". The server compares the local service data with the service data of the source database, and records a new update operation according to the comparison result, where the version number of the new update operation record is consistent with the version number of the version control column, for example: when data content ' D, D, 19 ' is traversed, a primary key ' D ' is obtained, the ' D ' is searched in local service data, the ' D ' is not searched at the moment, and new operations of ' newly adding [ ID ] [ D ], [ name ] [ D ], [ age ] [19], [ version number ] [2] are recorded; the setting rule of the version number may be set according to actual needs, and may be represented by an arabic number or a letter, which is not specifically limited in this embodiment. By the method, if the service data of the source database has the version control column, which data content in the source database is updated can be known according to the version control column, the data content corresponding to the version number greater than the first latest version number is searched from the version control column of the service data in the source database, and at this time, the data content in the service data of the source database, i.e., the data content of the service data which is updated, only needs to be searched in a traversal manner, so that the local workload can be reduced, and after the new adding operation is recorded, only the recorded new adding operation needs to be sent to the target database, so that the network transmission quantity between the server and the target database is reduced, and the synchronization speed is also improved.
ID Name (I) Age (age) Version control
a A 16 1
b B 17 1
c C 18 1
TABLE VII: service data of source database
ID Name (I) Age (age) Version control
b B 17 1
c C 19 2
d D 19 2
Table eight: service data of source database after first updating
ID Name (I) Age (age) Version control
b B 20 3
c C 19 2
d D 19 2
Table nine: the service data of the source database after the second update
In one example, if the data content in the service data respectively has a primary key, traversing the data content in the local service data, searching the primary key in the currently traversed data content in the service data of the source database, if the primary key in the currently traversed data content is not found, indicating that the currently traversed data content is not found, recording a deletion operation for deleting the currently traversed data content, and if the primary key in the currently traversed data content is found and the data content in the service data of the source database, which has the same primary key as the currently traversed data content, is not completely consistent with the currently traversed data content, recording and modifying the traversal operation according to the data content in the service data of the source database, which has the same primary key as the currently traversed data content; and then, local service data is deduced according to the current updating operation, the data content in the service data of the source database is traversed, the main key in the currently traversed data content is searched in the local service data, and if the main key in the currently traversed data content is not searched, the newly added operation of newly adding the currently traversed data content is recorded.
Specifically, as will be described in detail below with reference to an example, in a seventh example, the current update operation includes: adding [ ID ] [ a ], [ name ] [ A ], [ age ] [16], version [1], adding [ ID ] [ B ], [ name ] [ B ], [ age ] [17], version [1], adding [ ID ] [ C ], [ name ] [ C ], [ age ] [18] and version [1], deducing local service data as shown in table one, wherein table five is the service data of the source database; traversing data contents in local service data, acquiring a main key 'a' when traversing the data contents 'a, A and 16', searching 'a' in the service data of a source database, and recording deletion operations of 'deleting [ ID ] [ a ], version [2 ]' when 'a' which is not searched indicates that the currently traversed data contents are not searched; when the data content 'B, B, 17' is traversed, acquiring the primary key 'B', searching 'B' in the service data of the source database, searching 'B' at the moment, wherein the data content with the same primary key 'B' in the service data of the source database is 'B, B, 17', and the data is ignored if the data content is completely consistent with the data content traversed currently; when traversing to the data content "C, 18", acquiring the primary key "C", searching "C" in the service data of the source database, and at this time, searching "C", wherein the data content having the same primary key "C" in the service data of the source database is "C, 19", which is not completely consistent with the currently traversed data content, and then modifying the modification operations of [ ID ] [ C ] age [19] and version [2] according to the record of "C, 19", and then the new updating operation includes: delete [ ID ] [ a ], version [2], modify [ ID ] [ C ] name [ C ] age [19], version [2], so the current update operation: adding [ ID ] [ a ], [ name ] [ A ], [ age ] [16], version [1], adding [ ID ] [ B ], [ name ] [ B ], [ age ] [17], version [1], adding [ ID ] [ C ], [ name ] [ C ], [ age ] [18], version [1], deleting [ ID ] [ a ], version [2], modifying [ ID ] [ C ] age [19], version [2], deducing local service data as shown in a table, traversing data content in the service data of a source database, acquiring a primary key "B" when traversing the data content "B, B and 17", searching "B" in the local service data, and ignoring the data when searching "B" at the moment; when data content 'C, C, 19' is traversed, a main key 'C' is obtained, the 'C' is searched in local service data, and the data is ignored when the 'C' is searched; when traversing the data content "D, 19", acquiring the primary key "D", searching "D" in the local service data, not searching "D" at this time, recording the new adding operation of "newly adding [ ID ] [ D ], [ name ] [ D ], [ age ] [19], version [2 ]", and then all the new updating operations include: delete [ ID ] [ a ], version [2], modify [ ID ] [ c ] age [19], version [2], add [ ID ] [ D ], [ name ] [ D ], [ age ] [19], version [2 ]. By the method, due to the judgment of the deletion operation and the modification operation which are carried out firstly, the data content of the local service data is reduced when the deletion operation exists, so that the comparison of the data content can be reduced when the judgment of the new addition operation is carried out subsequently, and the synchronization speed is further improved.
ID Name (I) Age (age)
b B 17
c C 19
TABLE Ten: local service data
In one example, if the data content in the service data has a primary key, traversing the data content in the local service data, searching the primary key in the currently traversed data content in the service data of the source database, if the primary key in the currently traversed data content is not found, indicating that the currently traversed data content is not found, recording a deletion operation for deleting the currently traversed data content; and then, local service data is deduced according to the current updating operation, data content in the service data of the source database is traversed, a primary key in the currently traversed data content is searched in the local service data, if the primary key in the currently traversed data content is not searched, the newly-added operation of newly-added currently-traversed data content is recorded, and if the primary key in the currently-traversed data content is searched and the data content in the local service data, which has the same primary key as the currently-traversed data content, is not completely consistent with the currently-traversed data content, the modification operation is recorded according to the currently-traversed data content.
In one example, if the data content in the service data respectively has a primary key, traversing the data content in the service data of the source database, searching the primary key in the currently traversed data content in the local service data, if the primary key in the currently traversed data content is not found, indicating that the currently traversed data content is not found, and recording a new adding operation for adding the currently traversed data content; and then, pushing local service data according to the current updating operation, traversing the data content in the local service data, searching the main key in the currently traversed data content in the service data of the source database, recording deletion operation for deleting the currently traversed data content if the main key in the currently traversed data content is not searched, and recording modification operation according to the data content in the service data of the source database, which has the same main key as the currently traversed data content, if the main key in the currently traversed data content is searched and the data content in the service data of the source database, which has the same main key as the currently traversed data content, is not completely consistent with the currently traversed data content.
Specifically, as will be described in detail below with reference to an example, in an eighth example, the current update operation includes: adding [ ID ] [ a ], [ name ] [ A ], [ age ] [16], version [1], adding [ ID ] [ B ], [ name ] [ B ], [ age ] [17], version [1], adding [ ID ] [ C ], [ name ] [ C ], [ age ] [18] and version [1], deducing local service data as shown in table one, wherein table five is the service data of the source database; firstly, traversing data content in service data of a source database, acquiring a main key 'B' when traversing the data content 'B, B, 17', searching 'B' in local service data, and ignoring the data when searching 'B' at the moment; when data content 'C, C, 19' is traversed, a main key 'C' is obtained, the 'C' is searched in local service data, and the data is ignored when the 'C' is searched; when traversing the data content 'D, D, 19', acquiring the primary key 'D', searching the local service data for 'D', not searching the local service data for 'D', recording the new operations of 'newly adding [ ID ] [ D ], [ name ] [ D ], [ age ] [19], and version [2],' and then acquiring new updating operations as follows: "newly added [ ID ] [ D ], [ name ] [ D ], [ age ] [19], version [2 ]"; and traversing the data content in the local service data, so that the current updating operation: adding [ ID ] [ a ], [ name ] [ A ], [ age ] [16], version [1], adding [ ID ] [ B ], [ name ] [ B ], [ age ] [17], version [1], adding [ ID ] [ C ], [ name ] [ C ], [ age ] [18], version [1], adding [ ID ] [ D ], [ name ] [ D ], [ age ] [19], version [2], deducing local service data as shown in a table eleven, traversing data contents in the local service data, acquiring a primary key "a" when traversing data contents "a, A and 16", searching "a" in service data of a source database, wherein the condition that the "a" is not searched at the moment indicates that the currently traversed data content is not searched, and recording deletion operation of "deleting [ ID ] [ a ], version [2 ]; when the data content 'B, B, 17' is traversed, acquiring the primary key 'B', searching 'B' in the service data of the source database, searching 'B' at the moment, wherein the data content with the same primary key 'B' in the service data of the source database is 'B, B, 17', and the data is ignored if the data content is completely consistent with the data content traversed currently; when the data content 'C, C, 18' is traversed, the primary key 'C' is obtained, the 'C' is searched in the service data of the source database, the data content with the same primary key 'C' in the service data of the source database is 'C, C, 19', which is not completely consistent with the data content traversed currently, then according to the 'C, C, 19' record 'modify [ ID ] [ C ] age [19], version [2 ]' modification operation, when the data content 'D, D, 19' is traversed, the primary key 'D' is obtained, searching for 'D' in the service data of the source database, searching for 'D' at the moment, wherein the data content with the same primary key 'D' in the service data of the source database is 'D, D, 19', if the data content is completely consistent with the data content traversed currently, the data is ignored, and a new update operation is obtained as follows: delete [ ID ] [ a ], version [2], modify [ ID ] [ c ] age [19], version [2], then all new update operations include: delete [ ID ] [ a ], version [2], modify [ ID ] [ c ] age [19], version [2], add [ ID ] [ D ], [ name ] [ D ], [ age ] [19], version [2 ].
ID Name (I) Age (age)
a A 16
b B 17
c C 18
d D 19
Table eleven: local service data
In one example, if the data content in the service data respectively has a primary key, traversing the data content in the service data of the source database, searching the primary key in the currently traversed data content in the local service data, if the primary key in the currently traversed data content is not found, indicating that the currently traversed data content is not found, recording an addition operation for adding the currently traversed data content, and if the primary key in the currently traversed data content is found and the data content in the local service data, which has the same primary key as the currently traversed data content, is not completely consistent with the currently traversed data content, recording a modification operation according to the currently traversed data content; and then, local service data is deduced according to the current updating operation, data contents in the local service data are traversed, a primary key in the currently traversed data contents is searched in the service data of the source database, if the primary key in the currently traversed data contents is not searched, the currently traversed data contents are not searched, and deletion operation for deleting the currently traversed data contents is recorded.
In one example, traversing data content in local service data, searching currently traversed data content in service data of a source database, and recording deletion operation for deleting the currently traversed data content if the currently traversed data content is not found; and then, local service data is deduced according to the current updating operation, the data content in the service data of the source database is traversed, the currently traversed data content is searched in the local service data, and if the currently traversed data content is not searched, the newly added operation of newly adding the currently traversed data content is recorded.
In one example, firstly traversing data content in service data of a source database, searching currently traversed data content in local service data, and recording a new adding operation for adding the currently traversed data content if the currently traversed data content is not searched; and then, local service data is deduced according to the current updating operation, data contents in the local service data are traversed, the currently traversed data contents are searched in the service data of the source database, and if the currently traversed data contents are not searched, deleting operation for deleting the currently traversed data contents is recorded.
In one example, if the data content in the service data respectively has a primary key, traversing the data content in the local service data, searching the primary key in the currently traversed data content in the service data of the source database, if the primary key in the currently traversed data content is not found, indicating that the currently traversed data content is not found, recording a deletion operation for deleting the currently traversed data content, and if the primary key in the currently traversed data content is found and the data content in the service data of the source database, which has the same primary key as the currently traversed data content, is not completely consistent with the currently traversed data content, recording and modifying operation according to the data content in the service data of the source database, which has the same primary key as the currently traversed data content.
In one example, if the data content in the service data respectively has a primary key, traversing the data content in the service data of the source database, searching the primary key in the currently traversed data content in the local service data, if the primary key in the currently traversed data content is not found, indicating that the currently traversed data content is not found, recording an addition operation for adding the currently traversed data content, and if the primary key in the currently traversed data content is found and the data content in the local service data having the same primary key as the currently traversed data content is not completely consistent with the currently traversed data content, recording a modification operation according to the currently traversed data content.
It should be noted that, when determining whether the new update operation includes a delete operation, an add operation, and a modify operation according to the comparison result, the order of the determination is not limited, that is, when determining the operation type, any combination may be performed, including but not limited to the following: determining a delete operation and a modify operation before determining a new operation, determining a delete operation before determining a new operation and a modify operation, determining a new operation before determining a delete and a modify operation, determining a delete operation before determining a new operation, determining a new operation before determining a delete operation, determining a delete operation and a modify operation, determining a new operation and a modify operation, and the like.
And 103, sending the new updating operation to the target database, so that the target database can perform data synchronization according to the new updating operation.
Specifically, in this embodiment, the number of the target databases is one, and the server sends a new update operation to the target databases, so that the target databases perform data synchronization according to the new update operation. In one example, the number of the target databases is more than one, the server sends a new update operation to all the target databases, so that the target databases perform data synchronization according to the new update operation, at this time, although the number of the target databases to be synchronized is more than one, the server only compares the local service data with the service data of the source database once to obtain a new update operation, and directly sends the new update operation to all the target databases, so that the data synchronization of all the target databases according to the new update operation can be realized. In one example, if the target database needs to be bridged to the server through the corresponding client, the server sends a new update operation to the client, and the client synchronizes data of the corresponding target database according to the new update operation.
In one example, after comparing the local service data with the service data of the source database and recording a new update operation according to the comparison result, the method further includes: and sending the number of the new updating operations to the target database, so that the target database can verify whether the synchronous data content is complete according to the number of the new updating operations. Specifically, the server may send the number of new update operations first, and then send the new update operations; or sending new updating operation first and then sending the number of the new updating operation; the new update operation and the number of new update operations may also be sent simultaneously. The target database carries out data synchronization after receiving new updating operations, the number of the updated updating operations can be obtained when the data synchronization is finished, if the number of the updated updating operations in the target database is not consistent with the number of the new updating operations sent by the server, the incomplete updating, namely the incomplete synchronized data content is shown, the target database requests the server for the new updating operations again, and if the number of the updated updating operations in the target database is consistent with the number of the new updating operations sent by the server, the complete updating, namely the complete synchronized data content is shown. For example: the number of new update operations is 10, data synchronization is performed after the new update operations are received, incomplete update is described if the number of update operations updated in the target database is 5 when data synchronization is completed, data synchronization is performed after the new update operations are received, and complete update is described if the number of update operations updated in the target database is 10 when data synchronization is completed. By the method, the server side also sends the number of the new updating operations to the target database, so that the target database can verify whether the synchronized data content is complete according to the number of the new updating operations, thereby verifying whether the data synchronization is complete, improving the integrity of the data content in the service data of the target database in the data synchronization process and improving the accuracy of the data synchronization. In one example, the number of the service ends in the data synchronization system is more than one, all the service ends form a service end cluster, each service end is deployed in a distributed architecture mode, and a distributed lock is adopted to ensure that only one service end performs the same data synchronization task in the service end cluster and the service end with the best current performance performs the task, if the service end fails, the data synchronization task is continuously performed by other service ends, namely, the other service ends deduce local service data according to the current updating operation; comparing the local service data with the service data of the source database, recording new updating operation according to the comparison result, and sending the new updating operation to the target database, so that the target database can perform data synchronization according to the new updating operation until the execution is successful or all the service terminals in the service terminal cluster are in failure; the server side in the server side cluster finds and communicates with each other through a Transmission Control Protocol (TCP) or an Internet Protocol (IP) built in the server side, and the connection and work of the server side in the server side cluster are automatically realized.
In this embodiment, local service data is derived according to the current update operation; comparing the local service data with the service data of the source database, and recording new updating operation according to the comparison result; and sending the new updating operation to the target database for the target database to carry out data synchronization according to the new updating operation. By the method, the network transmission quantity of the target database and the server only comprises the step that the server sends the new updating operation to the server, and the server does not need to send all the service data of the source database acquired from the source database to the target database, so that the network transmission quantity between the server and the target database is reduced, the transmission speed is higher as the network transmission quantity is smaller, the synchronization speed can be improved, the server does not need to compare the local service data with the service data of the source data after the target database sends a data synchronization request, and the server can immediately send the new updating operation to the target database according to the comparison result, and the synchronization speed is also improved.
A second embodiment of the present invention relates to a data synchronization method, and is substantially the same as the first embodiment, with the main difference that: receiving a monitoring request sent by a target database, where a specific flowchart is shown in fig. 2, and the specific flowchart includes:
step 201, receiving a monitoring request sent by a target database, where the monitoring request is used to characterize that when a server monitors that a new update operation exists, the server sends the new update operation to the target database.
Specifically, the target database sends a monitoring request to the server to monitor the update operation of the server, and the server sends a new update operation to the target database when monitoring that the new update operation exists. In one example, the target database needs to be bridged to the server side through the corresponding client side, the client side sends a monitoring request to the server side, the server side sends a new updating operation to the client side when monitoring that the new updating operation exists, and the client side enables the corresponding target database to perform data synchronization according to the new updating operation.
And step 202, deducing local service data according to the current updating operation.
Step 203, comparing the local service data with the service data of the source database, and recording a new updating operation according to the comparison result.
And step 204, sending the new updating operation to the target database, so that the target database can carry out data synchronization according to the new updating operation.
Step 202-204 is similar to step 101-103, and will not be described herein.
In this embodiment, the server does not need to forward the request for data synchronization of the target database to the source database, and the server only sends the new update operation to the target database when the new update operation exists, so that network transmission between the server and the source database can be reduced, and overall network transmission is reduced.
A third embodiment of the present invention relates to a data synchronization method, and is substantially the same as the first embodiment, with the main difference that: and sending the second search result to the target database for the target database to perform data synchronization according to the second search result, where a specific flowchart is shown in fig. 3 and includes:
step 301, querying the latest version number of the data content in the service data of the target database to obtain a second latest version number.
Step 302, if the data content corresponding to the second latest version number in the service data of the target database is judged to be synchronous and complete, searching for the updating operation corresponding to the version number greater than the second latest version number from the current updating operation to obtain a second searching result; and if the synchronization of the data content corresponding to the second latest version number in the service data of the target database is judged to be incomplete, searching for the updating operation corresponding to the version number not less than the second latest version number from the current updating operation, and obtaining a second searching result.
And step 303, sending the second search result to the target database, so that the target database performs data synchronization according to the second search result.
Specifically, during one data synchronization, a problem that a target database fails to receive a complete new update operation in the data synchronization process, or an interruption occurs during the data synchronization process, so that the data synchronization cannot be completely performed, or when a newly added target database exists, the newly added target database does not receive a new update operation before the data synchronization process, and so on, which may cause a part of the update operations to be unsuccessfully sent to the target database, so that, each time a client performs data synchronization, the server first queries the latest version number of data content in the service data of the target database to obtain a second latest version number, and determines the first version number according to the number of update operations corresponding to the second latest version number in the server and the number of update operations corresponding to the second latest version number in the target database, where the second latest version number is updated Whether the data contents corresponding to the two latest version numbers are synchronous and complete or not is judged, if the number of the updating operations corresponding to the second latest version number in the server side is equal to the number of the updating operations of the second latest version number in the target database, the data contents corresponding to the second latest version number in the target database are complete, whether the updating operations corresponding to the version number larger than the second latest version number can be found in the current updating operations of the server side is determined, if the updating operations corresponding to the version number larger than the second latest version number are found, a second searching result is obtained, if the target database is not updated to the latest version number, the obtained second searching result is sent to the target database, if the number of the updating operations corresponding to the second latest version number in the server side is larger than the number of the updating operations of the second latest version number in the target database, if the data content corresponding to the second latest version number in the target database is incomplete, searching for the updating operation corresponding to the version number not less than the second latest version number from the current updating operation to obtain a second searching result, and sending the second searching result to the target database; the server may send the second search result to the target database all at once, or may send the second search result to the target database multiple times according to the version number, for example: the second latest version number is 2, if the number of the updated update operations corresponding to the second latest version number in the target database is 5, and the number of the update operations corresponding to the second latest version number at the server is 5, the data content corresponding to the second latest version number is complete, and the update operation with the version number of 3 and the update operation with the version number of 4 are found from the current update operation, the update operation with the version number of 3 and the update operation with the version number of 4 can be completely sent to the target database once, or the update operation with the version number of 3 can be newly sent to the target database, and then the update operation with the version number of 4 is sent to the target database, so that the target database performs data synchronization according to the second search result; and if the number of the update operations of the second latest version number, which are updated, in the target database is 5, and the number of the update operations of the second latest version number, which are updated, in the server is 10, the data content corresponding to the second latest version number is incomplete, and the update operation of the version number 2, the update operation of the version number 3, and the update operation of the version number 4 are found from the current update operation.
In an example, the server may also enter step 301 after receiving a data request including the latest version of the data content in the service data of the target database sent by the target database, where the server may know the latest version number of the data content in the service data of the target database by querying the content in the data request.
And step 304, deducing local service data according to the current updating operation.
And 305, comparing the local service data with the service data of the source database, and recording a new updating operation according to the comparison result.
And step 306, sending the new updating operation to the target database, so that the target database can perform data synchronization according to the new updating operation.
The steps 304-306 are similar to the steps 101-103 in the first embodiment, and are not described herein again.
It should be noted that, the data transmission between the server and the target database is realized by the subscription service, and the data transmission between the server and the target can be performed at any time after the subscription service is established between the server and the target database, so that the step 301 and 303 can be performed in any step, that is, the step 301 and 303 can be performed after the step 304, or after the step 305, or after the step 306.
In the embodiment, all the updating operations can be sent to the target database, so that the intermediate updating operations are avoided from being missed, and the integrity of the updating operations received by the target database is ensured, thereby ensuring the integrity of data contents in the service data of the target database in the data synchronization process and improving the accuracy of data synchronization.
A fourth embodiment of the present invention relates to a data synchronization method, which is applied to a target database in a data synchronization system, where the data synchronization system further includes a server connected to the target database and the target database connected to the server, and a specific flow is shown in fig. 4, and includes:
step 401, receiving a new update operation sent by a server; the new updating operation is obtained by the server comparing the local service data with the service data of the source database and recording according to the comparison result;
step 402, data synchronization is performed according to the new update operation.
The steps of the above methods are divided for clarity, and the implementation may be combined into one step or split some steps, and the steps are divided into multiple steps, so long as the same logical relationship is included, which are all within the protection scope of the present patent; it is within the scope of the patent to add insignificant modifications to the algorithms or processes or to introduce insignificant design changes to the core design without changing the algorithms or processes.
A fifth embodiment of the present invention is directed to a data synchronization system, including: a source database 501, a server 502 and a target database 503;
a source database 501 for providing service data of source data;
the server 502 is configured to deduce local service data according to the current update operation; comparing the local service data with the service data of the source database, and recording new updating operation according to the comparison result; sending the new updating operation to a target database for the target database to carry out data synchronization according to the new updating operation;
and the target database 503 is configured to receive a new update operation sent by the server, and perform data synchronization according to the new update operation.
In one example, the number of the service terminals in the data synchronization system is more than one, all the service terminals form a service terminal cluster, each service terminal is deployed in a distributed architecture mode, and a distributed lock is adopted to ensure that only one service terminal in the service terminal cluster performs the same data synchronization task and the service terminal with the best current performance performs the same task, if the service terminal fails, the data synchronization task is continuously performed by other service terminals, the updating operation in the data synchronization process is recorded, and the updating operation is sent to a target database for the target database to perform data synchronization until the data synchronization is successfully performed or all the service terminals in the service terminal cluster fail; the server side in the server side cluster finds and communicates with each other through a Transmission Control Protocol (TCP) or an Internet Protocol (IP) built in the server side, and the connection and work of the server side in the server side cluster are automatically realized.
In one example, the number of the target databases is more than one, the server sends a new update operation to all the target databases to synchronize the data of the target databases, at this time, although the number of the target databases to be synchronized is more than one, the server only compares the local service data with the service data of the source database once to obtain a new update operation, and directly sends the new update operation to all the target databases, so that the data synchronization of all the target databases according to the new update operation can be realized.
In one example, if the target database needs to be bridged to the server side through the corresponding client side, the server side sends the update operation to the client side, and the client side synchronizes data of the corresponding target database according to the update operation.
It should be understood that the present embodiment is a system embodiment corresponding to the first, second, and third embodiments, and the present embodiment can be implemented in cooperation with the first, second, and third embodiments. The related technical details mentioned in the first, second and third embodiments are still valid in this embodiment, and are not described herein again in order to reduce repetition. Accordingly, the related-art details mentioned in the present embodiment can also be applied to the first embodiment, the second embodiment, and the third embodiment.
A sixth embodiment of the invention is directed to a server, as shown in fig. 6, comprising at least one processor 602; and, a memory 601 communicatively coupled to the at least one processor; the memory 601 stores instructions executable by the at least one processor 602, and the instructions are executed by the at least one processor 602 to enable the at least one processor 602 to perform the data synchronization method.
Where the memory 601 and the processor 602 are coupled by a bus, the bus may comprise any number of interconnected buses and bridges that couple one or more of the various circuits of the processor 602 and the memory 601 together. The bus may also connect various other circuits such as peripherals, voltage regulators, power management circuits, and the like, which are well known in the art, and therefore, will not be described any further herein. A bus interface provides an interface between the bus and the transceiver. The transceiver may be one element or a plurality of elements, such as a plurality of receivers and transmitters, providing a means for communicating with various other apparatus over a transmission medium. Data processed by processor 602 is transmitted over a wireless medium through an antenna, which receives the data and transmits the data to processor 602.
The processor 602 is responsible for managing the bus and general processing and may also provide various functions including timing, peripheral interfaces, voltage regulation, power management, and other control functions. And memory 601 may be used to store data used by processor 602 in performing operations.
A seventh embodiment of the present invention relates to a computer-readable storage medium storing a computer program. The computer program realizes the above-described method embodiments when executed by a processor.
That is, as can be understood by those skilled in the art, all or part of the steps in the method for implementing the embodiments described above may be implemented by a program instructing related hardware, where the program is stored in a storage medium and includes several instructions to enable a device (which may be a single chip, a chip, or the like) or a processor (processor) to execute all or part of the steps of the method described in the embodiments of the present application. And the aforementioned storage medium includes: a U-disk, a removable hard disk, a Read-Only Memory (ROM), a Random Access Memory (RAM), a magnetic disk or an optical disk, and other various media capable of storing program codes.
It will be understood by those of ordinary skill in the art that the foregoing embodiments are specific embodiments for practicing the invention, and that various changes in form and details may be made therein without departing from the spirit and scope of the invention in practice.

Claims (10)

1. A data synchronization method is applied to a server in a data synchronization system, the data synchronization system further comprises a source database and a target database which are respectively connected with the server, and the method comprises the following steps:
deducing local service data according to the current updating operation;
comparing the local service data with the service data of the source database, and recording new updating operation according to the comparison result;
and sending the new updating operation to a target database for the target database to perform data synchronization according to the new updating operation.
2. The data synchronization method of claim 1, wherein the new update operation comprises a delete operation; comparing the local service data with the service data of the source database, and recording a new updating operation according to a comparison result, including:
traversing the data content in the local service data, searching the currently traversed data content in the service data of the source database, and recording the deletion operation of deleting the currently traversed data content if the currently traversed data content is not searched.
3. The data synchronization method of claim 1, wherein the new update operation comprises an add operation; comparing the local service data with the service data in the source database, and recording a new updating operation according to a comparison result, including:
traversing the data content in the service data of the source database, searching the currently traversed data content in the local service data, and recording the newly-added operation of newly-added currently traversed data content if the currently traversed data content is not searched.
4. The data synchronization method according to claim 1, wherein if the data contents in the service data respectively have primary keys, the new update operation further comprises a modification operation; comparing the local service data with the service data in the source database, and recording a new updating operation according to a comparison result, including:
traversing data contents in local service data, searching a main key in the currently traversed data contents in the service data of the source database, and if the main key in the currently traversed data contents is found and the data contents in the service data of the source database, which have the same main key as the currently traversed data contents, are not completely consistent with the currently traversed data contents, recording and modifying operation according to the data contents in the service data of the source database, which have the same main key as the currently traversed data contents;
alternatively, the first and second electrodes may be,
and traversing the data content in the service data of the source database, searching the main key in the currently traversed data content in the local service data, and recording and modifying operation according to the currently traversed data content if the main key in the currently traversed data content is found and the data content in the local service data, which has the same main key as the currently traversed data content, is not completely consistent with the currently traversed data content.
5. The data synchronization method according to claim 2 or 3, wherein if the data contents in the service data respectively have a primary key, in the searching of the currently traversed data contents, the primary key in the currently traversed data contents is searched, and if the primary key in the currently traversed data contents is not searched, it indicates that the currently traversed data contents are not searched.
6. The data synchronization method according to claim 3 or 4, wherein if the service data of the source database has a version control column, the data content in the service data of the source database is determined by:
inquiring the latest version number of the current updating operation to obtain a first latest version number;
and searching the data content corresponding to the version number greater than the first latest version number from the version control column of the service data of the source database to obtain a first search result, and taking the first search result as the data content in the service data of the source database.
7. A data synchronization method is applied to a target database in a data synchronization system, the data synchronization system further comprises a server connected with the target database and the target database connected with the server, and the method comprises the following steps:
receiving a new updating operation sent by the server; the new updating operation is obtained by comparing the local service data with the service data of the source database by the server side and recording according to a comparison result;
and carrying out data synchronization according to the new updating operation.
8. A data synchronization system, comprising: a source database, a server and a target database;
the source database is used for providing service data of the source data;
the server is used for deducing local service data according to the current updating operation; comparing the local service data with the service data of the source database, and recording new updating operation according to the comparison result; sending the new updating operation to a target database for the target database to perform data synchronization according to the new updating operation;
and the target database is used for receiving the new updating operation sent by the server and carrying out data synchronization according to the new updating operation.
9. A server, comprising:
at least one processor; and the number of the first and second groups,
a memory communicatively coupled to the at least one processor; wherein the content of the first and second substances,
the memory stores instructions executable by the at least one processor to enable the at least one processor to perform a data synchronization method as claimed in any one of claims 1 to 6 or to perform a data synchronization method as claimed in any one of claims 7.
10. A computer-readable storage medium, in which a computer program is stored which, when being executed by a processor, carries out the data synchronization method of any one of claims 1 to 6 or carries out the data synchronization method of any one of claim 7.
CN202011455862.5A 2020-12-10 2020-12-10 Data synchronization method, system, server and storage medium Active CN112463786B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202011455862.5A CN112463786B (en) 2020-12-10 2020-12-10 Data synchronization method, system, server and storage medium

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202011455862.5A CN112463786B (en) 2020-12-10 2020-12-10 Data synchronization method, system, server and storage medium

Publications (2)

Publication Number Publication Date
CN112463786A true CN112463786A (en) 2021-03-09
CN112463786B CN112463786B (en) 2021-08-13

Family

ID=74800145

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202011455862.5A Active CN112463786B (en) 2020-12-10 2020-12-10 Data synchronization method, system, server and storage medium

Country Status (1)

Country Link
CN (1) CN112463786B (en)

Cited By (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
WO2023089485A1 (en) * 2021-11-18 2023-05-25 International Business Machines Corporation Maintaining at target database system copy of source table of source database system

Citations (14)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20030217081A1 (en) * 2002-05-14 2003-11-20 Ken White System and method of maintaining functional client side data cache coherence
CN101551801A (en) * 2008-03-31 2009-10-07 国际商业机器公司 Data synchronization method and data synchronization system
CN101697169A (en) * 2009-10-23 2010-04-21 中兴通讯股份有限公司 Method, device and system for data synchronization between source database and destination database
CN101771723A (en) * 2010-01-05 2010-07-07 深圳中兴网信科技有限公司 Data synchronization method
CN103905561A (en) * 2014-04-14 2014-07-02 北京君正集成电路股份有限公司 Method and system for synchronizing data
CN104615759A (en) * 2015-02-13 2015-05-13 厦门雅迅网络股份有限公司 Data synchronization method for different business system platforms
CN105183860A (en) * 2015-09-10 2015-12-23 北京京东尚科信息技术有限公司 Data synchronization method and system
CN106325933A (en) * 2016-08-24 2017-01-11 明算科技(北京)股份有限公司 Method and device for synchronizing batch data
CN106407321A (en) * 2016-08-31 2017-02-15 东软集团股份有限公司 Data synchronization method and device
CN106682002A (en) * 2015-11-05 2017-05-17 中兴通讯股份有限公司 Database synchronization method and system, source data and target data synchronization device
CN107071005A (en) * 2017-03-24 2017-08-18 厦门中控生物识别信息技术有限公司 A kind of method of data synchronization and system
CN108259562A (en) * 2017-12-11 2018-07-06 杭州品茗安控信息技术股份有限公司 A kind of method of data synchronization and device based on multi-endpoint
CN109788027A (en) * 2018-12-13 2019-05-21 平安科技(深圳)有限公司 Method of data synchronization, device, server and computer storage medium
CN111818117A (en) * 2019-11-22 2020-10-23 北京嘀嘀无限科技发展有限公司 Data updating method and device, storage medium and electronic equipment

Patent Citations (14)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20030217081A1 (en) * 2002-05-14 2003-11-20 Ken White System and method of maintaining functional client side data cache coherence
CN101551801A (en) * 2008-03-31 2009-10-07 国际商业机器公司 Data synchronization method and data synchronization system
CN101697169A (en) * 2009-10-23 2010-04-21 中兴通讯股份有限公司 Method, device and system for data synchronization between source database and destination database
CN101771723A (en) * 2010-01-05 2010-07-07 深圳中兴网信科技有限公司 Data synchronization method
CN103905561A (en) * 2014-04-14 2014-07-02 北京君正集成电路股份有限公司 Method and system for synchronizing data
CN104615759A (en) * 2015-02-13 2015-05-13 厦门雅迅网络股份有限公司 Data synchronization method for different business system platforms
CN105183860A (en) * 2015-09-10 2015-12-23 北京京东尚科信息技术有限公司 Data synchronization method and system
CN106682002A (en) * 2015-11-05 2017-05-17 中兴通讯股份有限公司 Database synchronization method and system, source data and target data synchronization device
CN106325933A (en) * 2016-08-24 2017-01-11 明算科技(北京)股份有限公司 Method and device for synchronizing batch data
CN106407321A (en) * 2016-08-31 2017-02-15 东软集团股份有限公司 Data synchronization method and device
CN107071005A (en) * 2017-03-24 2017-08-18 厦门中控生物识别信息技术有限公司 A kind of method of data synchronization and system
CN108259562A (en) * 2017-12-11 2018-07-06 杭州品茗安控信息技术股份有限公司 A kind of method of data synchronization and device based on multi-endpoint
CN109788027A (en) * 2018-12-13 2019-05-21 平安科技(深圳)有限公司 Method of data synchronization, device, server and computer storage medium
CN111818117A (en) * 2019-11-22 2020-10-23 北京嘀嘀无限科技发展有限公司 Data updating method and device, storage medium and electronic equipment

Non-Patent Citations (1)

* Cited by examiner, † Cited by third party
Title
陈杨: "JTangSpider:一种高性能Oracle数据库同步平台设计与实现", 《中国优秀硕士学位论文全文数据库 信息辑(月刊)》 *

Cited By (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
WO2023089485A1 (en) * 2021-11-18 2023-05-25 International Business Machines Corporation Maintaining at target database system copy of source table of source database system
US11669535B1 (en) 2021-11-18 2023-06-06 International Business Machines Corporation Maintaining at a target database system a copy of a source table of a source database system

Also Published As

Publication number Publication date
CN112463786B (en) 2021-08-13

Similar Documents

Publication Publication Date Title
US6643669B1 (en) Method for optimization of synchronization between a client's database and a server database
US8694472B2 (en) System and method for rebuilding indices for partitioned databases
CN112765262B (en) Data redistribution method, electronic equipment and storage medium
CN108874803B (en) Data storage method, device and storage medium
US20070282878A1 (en) System and method for online reorganization of a database using flash image copies
CN112463786B (en) Data synchronization method, system, server and storage medium
CN111767297B (en) Big data processing method, device, equipment and medium
CN114661816A (en) Data synchronization method and device, electronic equipment and storage medium
CN114185991A (en) Method and related device for realizing data synchronization based on distributed database
JP6586174B2 (en) Database system, transaction management node, method and program
CN111767282A (en) MongoDB-based storage system, data insertion method and storage medium
CN116684416A (en) Mirror image distribution method, device and system in network element cluster
CN115587114A (en) System and query method
CN110798492B (en) Data storage method and device and data processing system
CN112395284A (en) Data processing method and device, database system, electronic equipment and storage medium
CN110912979B (en) Method for solving multi-server resource synchronization conflict
CN114328591A (en) Transaction execution method, device, equipment and storage medium
CN113961592A (en) Data query method, device, equipment and storage medium based on master-slave database
CN113641761A (en) Data synchronization method and device
CN112148739A (en) Ciphertext indexing method and system independent of encryption database
CN113297263A (en) Data processing method, device, system, electronic equipment and storage medium
JPH103418A (en) Data coincidence system between electronic computer systems
CN117472918B (en) Data processing method, system, electronic device and storage medium
CN115809301B (en) Database processing method and device, electronic equipment and readable storage medium
KR102460910B1 (en) Data storage method for preventing data duplication and data platform applying the same

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
GR01 Patent grant
GR01 Patent grant
PE01 Entry into force of the registration of the contract for pledge of patent right

Denomination of invention: Data synchronization method, system, server and storage medium

Effective date of registration: 20221220

Granted publication date: 20210813

Pledgee: Shanghai Pudong Development Bank Co.,Ltd. Xuhui sub branch

Pledgor: Shanghai Jining Computer Technology Co.,Ltd.

Registration number: Y2022310000389

PE01 Entry into force of the registration of the contract for pledge of patent right
PC01 Cancellation of the registration of the contract for pledge of patent right

Granted publication date: 20210813

Pledgee: Shanghai Pudong Development Bank Co.,Ltd. Xuhui sub branch

Pledgor: Shanghai Jining Computer Technology Co.,Ltd.

Registration number: Y2022310000389