Data synchronization method and system, program product, electronic equipment and storage medium
By configuring filtering rules and related fields in the data synchronization system, filtering and combining data to be synchronized to form a data list, the problem that data synchronization in the existing technology is not adjustable and difficult to synchronize complex databases is solved, and efficient and refined are achieved data synchronization.
Patent Information
- Application Number
- CN202411542900.9
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-10-31
- Publication Date
- 2025-02-18
Smart Images

Figure CN119474204A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of data processing technology, and in particular to a data synchronization method, system, program product, electronic device and storage medium. Background Art
[0002] At present, many enterprises need to synchronize data between multiple different databases according to their own business needs. The existing data synchronization method usually directly synchronizes all the changed data in the source database to the destination database. This data synchronization method can only synchronize all the changed data, and the data synchronization operation is not controllable. It is difficult to adapt to the diverse business needs of enterprises to synchronize the data required by the enterprise business in a targeted manner. Moreover, this data synchronization method can only simply map the source database and the destination database for data synchronization. If the database stores data tables with complex dependencies such as master-slave tables, it is difficult to ensure successful and complete data synchronization, which limits the efficiency of data synchronization to a certain extent. Summary of the invention
[0003] The purpose of the embodiments of the present application is to provide a data synchronization method, system, program product, electronic device and storage medium to achieve the technical effect of improving data synchronization efficiency.
[0004] In a first aspect, an embodiment of the present application provides a data synchronization method, applicable to a first terminal, the method comprising:
[0005] Acquire a screening rule, a first primary key field, a first synchronization field, and a first synchronization direction configured for a first database of the first terminal;
[0006] Filtering the data to be synchronized in the first database according to the screening rule, and determining the data operation type of the data to be synchronized;
[0007] Obtaining a data list according to the field value of the data to be synchronized corresponding to the first primary key field, the field value of the data to be synchronized corresponding to the first synchronization field, the data operation type, and the master-slave relationship of the data tables in the first database;
[0008] The data list is sent to a second terminal, so that the second terminal performs data synchronization according to the data list; wherein the second terminal is determined according to the first synchronization direction.
[0009] In the above implementation process, by pre-configuring filtering rules, the first primary key field, the first synchronization field, the first synchronization direction and other configuration data for the first database, the first terminal filters the data to be synchronized in the first database according to the filtering rules, and sends the field value of the data to be synchronized corresponding to the first primary key field, the field value of the data to be synchronized corresponding to the first synchronization field, the data operation type of the data to be synchronized and the master-slave relationship of the data table in the first database and other related data to the second terminal, so that the second terminal performs data synchronization according to the related data, can process data synchronization tasks in a refined manner, and improve data synchronization efficiency.
[0010] Further, filtering the data to be synchronized in the first database according to the filtering rule includes:
[0011] When a collection period within the effective period arrives, the data to be synchronized is filtered according to the filtering rule.
[0012] In the above implementation process, when the collection period within the effective period arrives, the first terminal can filter the data to be synchronized according to the filtering rules, so that data synchronization can be performed regularly, which is conducive to further meeting diverse data synchronization needs.
[0013] Furthermore, the number of the data to be synchronized is at least one;
[0014] The obtaining of the data list according to the field value of the to-be-synchronized data corresponding to the first primary key field, the field value of the to-be-synchronized data corresponding to the first synchronization field, the data operation type and the master-slave relationship of the data tables in the first database comprises:
[0015] For each of the to-be-synchronized data, combining the field value of the to-be-synchronized data corresponding to the first primary key field, the field value of the to-be-synchronized data corresponding to the first synchronization field, and the data operation type, to obtain initial data corresponding to the to-be-synchronized data;
[0016] An additional field value is added to the initial data to obtain target data corresponding to the data to be synchronized in the data list; wherein the additional field value is used to characterize the master-slave relationship of the data table.
[0017] In the above implementation process, the first terminal organizes the field values of each data to be synchronized corresponding to the first primary key field, the field values of each data to be synchronized corresponding to the first synchronization field, the data operation type of each data to be synchronized, and the additional field value used to characterize the master-slave relationship of the data table of the first database terminal into a data list, thereby ensuring that the second terminal can completely obtain the associated data of each data to be synchronized for data synchronization, thereby further improving the data synchronization efficiency.
[0018] Furthermore, the method further comprises:
[0019] When the data synchronization result returned by the second terminal is received, the data synchronization result is verified to obtain a first data verification result, and a front-end display page of the first data verification result is generated.
[0020] In the above implementation process, when the first terminal receives the data synchronization result returned by the second terminal, it verifies the data synchronization result to obtain the first data verification result, and generates a front-end display page of the first data verification result, which can facilitate the user to intuitively view the first data verification result on the first terminal.
[0021] In a second aspect, an embodiment of the present application provides a data synchronization method, applicable to a second terminal, the method comprising:
[0022] Acquire a second primary key field, a second synchronization field, and a second synchronization direction configured for a second database of the second terminal;
[0023] Receiving a data list sent by a first terminal; wherein the first terminal is determined according to the second synchronization direction;
[0024] According to the data table type of the target data table, the field value of the data to be synchronized in the data list corresponding to the first synchronization field, the data operation type of the data to be synchronized, and the master-slave relationship of the data table in the first database of the first terminal, the field value under the second synchronization field in the target data table is updated; wherein the target data table is determined based on the second primary key field.
[0025] In the above implementation process, the second terminal obtains the second primary key field, the second synchronization field and the second synchronization direction configured for the second database of the second terminal, receives the data list sent by the first terminal determined based on the second synchronization direction, and updates the field value under the second synchronization field in the target data table according to the data table type determined based on the second primary key field, the field value of the data to be synchronized in the data list corresponding to the first synchronization field, the data operation type of the data to be synchronized and the master-slave relationship of the data table in the first database of the first terminal, thereby being able to process data synchronization tasks in a refined manner and improve data synchronization efficiency.
[0026] Further, before updating the field value under the second synchronization field in the target data table according to the data table type of the target data table, the field value of the data to be synchronized in the data list corresponding to the first synchronization field, the data operation type of the data to be synchronized, and the master-slave relationship of the data table in the first database of the first terminal, the method further includes:
[0027] Obtaining a conflict handling strategy configured for the second database;
[0028] Determine whether the data to be synchronized exists in the second database, or whether the conflict handling strategy is an overwrite handling strategy, so that if there is no data to be synchronized in the second database, or the conflict handling strategy is an overwrite handling strategy, update the field value under the second synchronization field in the target data table according to the data table type, the field value of the data to be synchronized corresponding to the first synchronization field, the data operation type and the master-slave relationship of the data table.
[0029] In the above implementation process, when there is no data to be synchronized in the second database by the second terminal, or the conflict handling strategy configured for the second database is an overwrite handling strategy, the field value under the second synchronization field in the target data table is updated according to the data table type, the field value of the data to be synchronized corresponding to the first synchronization field, the data operation type and the master-slave relationship of the data table, thereby effectively avoiding data synchronization conflicts and further improving data synchronization efficiency.
[0030] Further, updating the field value under the second synchronization field in the target data table according to the data table type of the target data table, the field value of the data to be synchronized in the data list corresponding to the first synchronization field, the data operation type of the data to be synchronized, and the master-slave relationship of the data table in the first database of the first terminal includes:
[0031] Determine a synchronization mode according to the data table type, the data operation type and the master-slave relationship of the data table;
[0032] According to the synchronization mode, the field value under the second synchronization field in the target data table is updated to the field value of the to-be-synchronized data corresponding to the first synchronization field.
[0033] In the above implementation process, the second terminal determines the synchronization mode according to the data table type, data operation type and master-slave relationship of the data table, and updates the field value under the second synchronization field in the target data table to the field value of the first synchronization field corresponding to the data to be synchronized according to the synchronization mode, thereby ensuring accurate and complete data synchronization and further improving data synchronization efficiency.
[0034] Furthermore, the method further comprises:
[0035] When a data synchronization result is obtained, returning the data synchronization result to the first terminal; and / or,
[0036] The data synchronization result is verified to obtain a second data verification result, and a front-end display page of the second data verification result is generated.
[0037] In the above implementation process, when the second terminal obtains the data synchronization result, it returns the data synchronization result to the first terminal, and / or verifies the data synchronization result to obtain the second data verification result, and generates a front-end display page of the second data verification result, which can facilitate users to intuitively view the data verification result.
[0038] In a third aspect, an embodiment of the present application provides a data synchronization device, applicable to a first terminal, the device comprising:
[0039] A first configuration acquisition module, used to acquire a screening rule, a first primary key field, a first synchronization field and a first synchronization direction configured for a first database of the first terminal;
[0040] a to-be-synchronized data determination module, configured to filter the to-be-synchronized data in the first database according to the filtering rule, and determine a data operation type of the to-be-synchronized data;
[0041] a data list acquisition module, configured to obtain a data list according to the field value of the data to be synchronized corresponding to the first primary key field, the field value of the data to be synchronized corresponding to the first synchronization field, the data operation type, and the master-slave relationship of the data tables in the first database;
[0042] The data list sending module is used to send the data list to the second terminal, so that the second terminal performs data synchronization according to the data list; wherein the second terminal is determined according to the first synchronization direction.
[0043] In a fourth aspect, an embodiment of the present application provides a data synchronization device, applicable to a second terminal, the device comprising:
[0044] A second configuration acquisition module, used to acquire a second primary key field, a second synchronization field, and a second synchronization direction configured for a second database of the second terminal;
[0045] A data list receiving module, configured to receive a data list sent by a first terminal; wherein the first terminal is determined according to the second synchronization direction;
[0046] A data synchronization processing module is used to update the field value under the second synchronization field in the target data table according to the data table type of the target data table, the field value of the data to be synchronized in the data list corresponding to the first synchronization field, the data operation type of the data to be synchronized and the master-slave relationship of the data table in the first database of the first terminal; wherein the target data table is determined based on the second primary key field.
[0047] In a fifth aspect, an embodiment of the present application provides a data synchronization system, including a first terminal and a second terminal;
[0048] The first terminal is used to execute the method described in the first aspect above;
[0049] The second terminal is used to execute the method described in the second aspect above.
[0050] In a sixth aspect, an embodiment of the present application provides a computer program product, wherein the computer program product comprises instructions, and when the instructions are executed by a computer, the computer implements the method described in the first aspect or the method described in the second aspect.
[0051] In the seventh aspect, an embodiment of the present application provides an electronic device, comprising a processor, a memory, and a computer program stored in the memory and configured to be executed by the processor; when the processor executes the computer program, it implements the method described in the first aspect or the method described in the second aspect.
[0052] In an eighth aspect, an embodiment of the present application provides a computer-readable storage medium, wherein the computer-readable storage medium includes a stored computer program; wherein, when the computer program is running, the device where the computer-readable storage medium is located is controlled to execute the method described in the first aspect above or the method described in the second aspect above. BRIEF DESCRIPTION OF THE DRAWINGS
[0053] In order to more clearly illustrate the technical solutions of the embodiments of the present application, the drawings required for use in the embodiments of the present application will be briefly introduced below. It should be understood that the following drawings only show certain embodiments of the present application and therefore should not be regarded as limiting the scope. For ordinary technicians in this field, other related drawings can be obtained based on these drawings without paying creative work.
[0054] Figure 1 A flowchart of a data synchronization method provided in the first embodiment of the present application;
[0055] Figure 2 A flowchart of a data synchronization method provided in the second embodiment of the present application;
[0056] Figure 3 A schematic diagram of the structure of a data synchronization device provided in the third embodiment of the present application;
[0057] Figure 4 A schematic diagram of the structure of a data synchronization device provided in the fourth embodiment of the present application;
[0058] Figure 5 A structural diagram of a data synchronization system provided in the fifth embodiment of the present application;
[0059] Figure 6 A schematic structural diagram of an electronic device provided in accordance with the sixth embodiment of the present application. DETAILED DESCRIPTION
[0060] The technical solutions in the embodiments of the present application will be described below in conjunction with the drawings in the embodiments of the present application.
[0061] It should be noted that in the description of this application, the terms "first", "second", etc. are only used to distinguish the description and cannot be understood as indicating or implying relative importance. At the same time, the step numbers in the text are only for the convenience of explaining the embodiments of this application and do not serve to limit the order of execution of the steps.
[0062] Please see Figure 1 , Figure 1 A flowchart of a data synchronization method provided in the first embodiment of the present application. The first embodiment of the present application provides a data synchronization method, which is applicable to a first terminal, and the method includes steps S101 to S104:
[0063] S101. Obtain a screening rule, a first primary key field, a first synchronization field, and a first synchronization direction configured for a first database of a first terminal.
[0064] As an example, the first terminal is a server or other computer that provides data management services, and the first terminal has at least one database. After the user selects a database as the first database from at least one database of the first terminal in advance according to actual application requirements and configures task configuration information such as a screening rule, a first primary key field, a first synchronization field, and a first synchronization direction for the first database, the first terminal obtains task configuration information such as the screening rule, the first primary key field, the first synchronization field, and the first synchronization direction configured for the first database.
[0065] In actual applications, the user can select a database from at least one database of the first terminal as the first database in advance according to actual application requirements, and determine the data source definition information such as the server information of the first database, the account information of the user accessing the first database, and the database type of the first database, and send the data source definition information to the first terminal. Among them, the server information of the first database includes the server IP address (Internet Protocol Address); the account information of the user accessing the first database includes the user name and password. After receiving the data source definition information, the first terminal queries the data table stored in the first database according to the data source definition information, and returns the data table stored in the first database to the user. At this time, the user can continue to configure the screening rules for the data table stored in the first database according to the actual application requirements, select at least part of the primary key field of the data table as the first primary key field, select at least part of any field of the data table as the first synchronization field, and configure the first synchronization direction. Among them, the filtering rule refers to the rule used to filter the data that needs to be synchronized in the data table, for example, the filtering rule is: if there is data in the data table corresponding to the field value of the first synchronization field that meets the regular expression corresponding to the first synchronization field, then at most N (N is a positive integer) data are filtered from these data as the data to be synchronized; the primary key field refers to the combination of one or more fields in the data table, and the primary key field value can uniquely identify each row in the data table and can be used as an index for data table synchronization; the first synchronization direction refers to the transmission direction of data during the synchronization process, such as the unidirectional synchronization direction from the first database to one or more databases of the second terminal, or the bidirectional synchronization direction between the first database and one or more databases of the second terminal.
[0066] S102: Filter the data to be synchronized in the first database according to the filtering rule, and determine the data operation type of the data to be synchronized.
[0067] As an exemplary embodiment, after acquiring the screening rule configured for the first database, the first terminal screens and determines the data to be synchronized in the first database according to the screening rule, and determines the data operation type of the data to be synchronized.
[0068] It should be noted that the data operation type of the data to be synchronized is determined according to the user's editing operation on the data to be synchronized in the first database, and the data operation type of the data to be synchronized includes one or more of adding, deleting and modifying.
[0069] In actual applications, if the first synchronization direction is a bidirectional synchronization direction transmitted between a first database and one or more databases of a second terminal, then in order to avoid data synchronization confusion, for the first terminal side, the user who defines the data source cannot be the same as the user who edits the data to be synchronized, and because the second terminal can also execute the data synchronization method in the same way as the first terminal, for the second terminal side, the user who defines the data source cannot be the same as the user who edits the data to be synchronized.
[0070] S103: Obtain a data list according to the field value of the to-be-synchronized data corresponding to the first primary key field, the field value of the to-be-synchronized data corresponding to the first synchronization field, the data operation type, and the master-slave relationship of the data tables in the first database.
[0071] As an example, after determining the data to be synchronized and the data operation type of the data to be synchronized, the first terminal determines the field value of the data to be synchronized corresponding to the first primary key field, the field value of the data to be synchronized corresponding to the first synchronization field, and the master-slave relationship of the data table in the first database.
[0072] It should be noted that the master-slave relationship of the data tables in the first database refers to the master-slave relationship between the data tables in the first database. For example, if there are data tables 1, 2 and 3 in the first database, the primary key of data table 1 is A, the primary key of data table 2 is B, the primary key of data table 3 is C and the foreign keys are A and B, then the master-slave relationship of the data tables in the first database is that data table 1 and data table 2 are the master tables, and data table 3 is the slave table of data table 1 and data table 2.
[0073] A data list is obtained according to the field value of the data to be synchronized corresponding to the first primary key field, the field value of the data to be synchronized corresponding to the first synchronization field, the data operation type of the data to be synchronized and the master-slave relationship of the data tables in the first database.
[0074] S104. Send a data list to the second terminal, so that the second terminal performs data synchronization according to the data list; wherein the second terminal is determined according to the first synchronization direction.
[0075] As an exemplary example, after obtaining the data list, the first terminal determines the second terminal according to the first synchronization direction, and sends the data list to the second terminal, so that the second terminal can perform data synchronization according to the data list.
[0076] Similarly, the second terminal is a server or other computer that provides data management services. The second terminal has at least one database. After receiving the data list, the second terminal performs data synchronization on one or more databases of the second terminal in a refined manner according to the field value of the data to be synchronized corresponding to the first primary key field in the data list, the field value of the data to be synchronized corresponding to the first synchronization field, the data operation type of the data to be synchronized, and the master-slave relationship of the data table in the first database.
[0077] In the embodiment of the present application, by pre-configuring filtering rules, a first primary key field, a first synchronization field, a first synchronization direction and other configuration data for the first database, the first terminal filters the data to be synchronized in the first database according to the filtering rules, and sends to the second terminal the field value of the data to be synchronized corresponding to the first primary key field, the field value of the data to be synchronized corresponding to the first synchronization field, the data operation type of the data to be synchronized and the master-slave relationship of the data table in the first database and other related data, so that the second terminal performs data synchronization according to the related data, can process data synchronization tasks in a refined manner, and improve data synchronization efficiency.
[0078] In an optional embodiment, filtering the data to be synchronized in the first database according to the filtering rules includes: when a collection period within the effective period arrives, filtering the data to be synchronized according to the filtering rules.
[0079] As an example, considering that in actual applications it may be necessary to perform data synchronization periodically within a certain period of time, the user can configure the effective period and collection cycle for the first database.
[0080] After being started, the first terminal periodically detects whether the current time is within the effective period. If the current time is within the effective period, when the collection cycle arrives, the data to be synchronized in the first database is filtered according to the filtering rules; if the current time is not within the effective period, no processing is performed.
[0081] In the embodiment of the present application, when a collection period within the effective period arrives, the first terminal filters the data to be synchronized according to the filtering rules, so that data synchronization can be performed regularly, which is beneficial to further meet diverse data synchronization needs.
[0082] In an optional embodiment, the number of data to be synchronized is at least one; the data list is obtained according to the field value of the data to be synchronized corresponding to the first primary key field, the field value of the data to be synchronized corresponding to the first synchronization field, the data operation type, and the master-slave relationship of the data table in the first database, including: for each data to be synchronized, combining the field value of the data to be synchronized corresponding to the first primary key field, the field value of the data to be synchronized corresponding to the first synchronization field, and the data operation type to obtain the initial data corresponding to the data to be synchronized; adding additional field values to the initial data to obtain target data corresponding to the data to be synchronized in the data list; wherein the additional field values are used to characterize the master-slave relationship of the data table.
[0083] As an example, after the first terminal determines at least one data to be synchronized, the data operation type of each data to be synchronized in at least one data to be synchronized, and the additional field value used to characterize the master-slave relationship of the data table in the first database, for each data to be synchronized, the field value of the data to be synchronized corresponding to the first primary key field, the field value of the data to be synchronized corresponding to the first synchronization field, and the data operation type of the data to be synchronized are combined to obtain the initial data corresponding to the data to be synchronized, and the additional field value is added to the initial data to obtain the target data corresponding to the data to be synchronized, thereby sorting out the target data corresponding to each data to be synchronized to obtain a data list.
[0084] In the embodiment of the present application, the first terminal organizes the field value of each data to be synchronized corresponding to the first primary key field, the field value of each data to be synchronized corresponding to the first synchronization field, the data operation type of each data to be synchronized, and the additional field value used to characterize the master-slave relationship of the data table of the first database terminal into a data list, so as to ensure that the second terminal can completely obtain the associated data of each data to be synchronized for data synchronization, thereby further improving the data synchronization efficiency.
[0085] In an optional embodiment, the method further includes step S105:
[0086] S105. When receiving the data synchronization result returned by the second terminal, verify the data synchronization result to obtain a first data verification result, and generate a front-end display page of the first data verification result.
[0087] As an example, after sending a data list to the second terminal, the first terminal waits to receive the data synchronization result returned by the second terminal. Upon receiving the data synchronization result returned by the second terminal, the first terminal verifies the data synchronization result to obtain a first data verification result, and generates a front-end display page of the first data verification result to facilitate the user to intuitively view the first data verification result.
[0088] In actual applications, the verification of data synchronization results includes one or more of the following: verifying whether the data list received by the second terminal is complete and correct based on the data source definition information, task configuration information and the user's editing operations on the synchronized data; directly comparing the data list obtained by the first terminal with the data list received by the second terminal for consistency; and comparing the consistency between the data to be synchronized and the data after synchronization with the second terminal.
[0089] In the embodiment of the present application, when the first terminal receives the data synchronization result returned by the second terminal, the first terminal verifies the data synchronization result to obtain the first data verification result, and generates a front-end display page of the first data verification result, so that the user can intuitively view the first data verification result on the first terminal.
[0090] Please see Figure 2 The second embodiment of the present application provides a data synchronization method, which is applicable to a second terminal. The method includes steps S201 to S203:
[0091] S201. Acquire a second primary key field, a second synchronization field, and a second synchronization direction configured in a second database for a second terminal.
[0092] As an example, the second terminal is a server or other computer that provides data management services, and the second terminal has at least one database. For the first terminal side, the user selects a database as the first database from at least one database of the first terminal in advance according to actual application requirements, and configures the source-side task configuration information such as the screening rule, the first primary key field, the first synchronization field, and the first synchronization direction for the first database. For the second terminal side, the user selects one or more databases as the second database from at least one database of the second terminal in advance according to actual application requirements, and configures the second primary key field, the second synchronization field, and the second synchronization direction for the second database. At this time, the second terminal can obtain the destination-side task configuration information such as the second primary key field, the second synchronization field, and the second synchronization direction configured for the second database.
[0093] In actual applications, the user can select one or more databases as the second database from at least one database of the second terminal in advance according to actual application requirements, and determine the data source definition information such as the server information of the second database, the account information of the user accessing the second database, and the database type of the second database, and send the data source definition information to the second terminal. Among them, the server information packet of the second database; the account information of the user accessing the second database includes the user name and password. After receiving the data source definition information, the second terminal queries the data table stored in the second database according to the data source definition information, and returns the data table stored in the second database to the user. At this time, the user can continue to select the primary key field of at least part of the data table as the second primary key field, select any field of at least part of the data table as the second synchronization field, and configure the second synchronization direction for the data table stored in the second database according to actual application requirements. Among them, the primary key field refers to the combination of one or more fields in the data table, and the primary key field value can uniquely identify each row in the data table, which can be used as an index for data table synchronization; the second synchronization direction refers to the transmission direction of data during the synchronization process, such as the unidirectional synchronization direction from the first database to one or more databases of the second terminal, or the bidirectional synchronization direction between the first database and one or more databases of the second terminal.
[0094] S202. Receive a data list sent by a first terminal; wherein the first terminal is determined according to a second synchronization direction.
[0095] As an example, after acquiring the second synchronization direction configured for the second database, the second terminal can determine the data source required in the data synchronization process of the second database, determine the first terminal according to the second synchronization direction, and receive the data list sent by the first terminal.
[0096] S203. Update the field value under the second synchronization field in the target data table according to the data table type of the target data table, the field value of the data to be synchronized in the data list corresponding to the first synchronization field, the data operation type of the data to be synchronized, and the master-slave relationship of the data table in the first database of the first terminal; wherein the target data table is determined based on the second primary key field.
[0097] As an example, after obtaining the second primary key field and the second synchronization field configured for the second database, the second terminal determines the target data table in the second database whose primary key field is the same as the second primary key field, and after receiving the data list sent by the first terminal, obtains from the data list the field value of the data to be synchronized in the first database corresponding to the first synchronization field, the data operation type of the data to be synchronized, and the master-slave relationship of the data table in the first database; according to the field value of the data to be synchronized corresponding to the first synchronization field, the data operation type of the data to be synchronized, and the master-slave relationship of the data table in the first database, the field value under the second synchronization field in the target data table is updated, thereby completing the data synchronization task of the destination end.
[0098] In actual applications, the data table in the first database has a corresponding relationship with the data table in the second database. The second terminal can determine the master-slave relationship of the target data table based on the master-slave relationship of the data table corresponding to the target data table in the first database, and then update the field value under the second synchronization field in the target data table based on the field value of the data to be synchronized corresponding to the first synchronization field, the data operation type of the data to be synchronized, and the master-slave relationship of the target data table.
[0099] The embodiment of the present application obtains the second primary key field, the second synchronization field and the second synchronization direction configured for the second database of the second terminal by the second terminal, receives the data list sent by the first terminal determined based on the second synchronization direction, and updates the field value under the second synchronization field in the target data table according to the data table type of the target data table determined based on the second primary key field, the field value of the data to be synchronized in the data list corresponding to the first synchronization field, the data operation type of the data to be synchronized and the master-slave relationship of the data table in the first database of the first terminal, so as to process the data synchronization tasks in a refined manner and improve the data synchronization efficiency.
[0100] In an optional embodiment, before updating the field value under the second synchronization field in the target data table according to the data table type of the target data table, the field value of the data to be synchronized corresponding to the first synchronization field in the data list, the data operation type of the data to be synchronized, and the master-slave relationship of the data table in the first database of the terminal, it also includes: obtaining the conflict handling strategy configured for the second database; determining whether there is data to be synchronized in the second database, or whether the conflict handling strategy is an overwrite handling strategy, so as to update the field value under the second synchronization field in the target data table according to the data table type, the field value of the data to be synchronized corresponding to the first synchronization field, the data operation type, and the master-slave relationship of the data table when there is no data to be synchronized in the second database or the conflict handling strategy is an overwrite handling strategy.
[0101] As an example, considering that in actual applications, the second database may contain data identical to the data to be synchronized, in order to avoid conflicts in subsequent data synchronization, the user can also configure conflict handling rules for the second database, such as overwriting the handling strategy or ignoring the handling strategy.
[0102] After obtaining the second primary key field, the second synchronization field and the conflict handling strategy configured for the second database and receiving the data list sent by the first terminal, the second terminal determines whether there is data to be synchronized in the data list in the second database, and determines whether the conflict handling strategy is an overwrite handling strategy or an ignore handling strategy. If there is data to be synchronized in the second database and the conflict handling strategy is an ignore handling strategy, no processing is performed; if there is no data to be synchronized in the second database, or the conflict handling strategy is an overwrite handling strategy, data synchronization is performed, and a target data table in the second database whose primary key field is the same as the second primary key field is determined, and the field value of the data to be synchronized corresponding to the first synchronization field, the data operation type of the data to be synchronized, and the master-slave relationship of the data table in the first database are obtained from the data list; according to the field value of the data to be synchronized corresponding to the first synchronization field, the data operation type of the data to be synchronized, and the master-slave relationship of the data table in the first database, the field value under the second synchronization field in the target data table is updated, thereby completing the data synchronization task of the destination end.
[0103] In the embodiment of the present application, when there is no data to be synchronized in the second database, or the conflict handling strategy configured for the second database is an overwrite handling strategy, the second terminal updates the field value under the second synchronization field in the target data table according to the data table type, the field value of the data to be synchronized corresponding to the first synchronization field, the data operation type and the master-slave relationship of the data table, thereby effectively avoiding data synchronization conflicts and further improving data synchronization efficiency.
[0104] In an optional embodiment, the updating of the field value under the second synchronization field in the target data table according to the data table type of the target data table, the field value of the data to be synchronized in the data list corresponding to the first synchronization field, the data operation type of the data to be synchronized, and the master-slave relationship of the data table in the first database of the first terminal includes: determining the synchronization mode according to the data table type, the data operation type, and the master-slave relationship of the data table; and updating the field value under the second synchronization field in the target data table to the field value of the data to be synchronized corresponding to the first synchronization field according to the synchronization mode.
[0105] As an example, considering different master-slave relationships of data tables and different data operation types, the data synchronization methods may also be different. Different synchronization modes may be configured in advance for different master-slave relationships of data tables and different data operation types.
[0106] After determining the data table type of the target data table, the field value of the data to be synchronized in the data list corresponding to the first synchronization field, the data operation type of the data to be synchronized, and the master-slave relationship of the data tables in the first database, the second terminal determines the synchronization mode according to the data table type of the target data table, the data operation type of the data to be synchronized, and the master-slave relationship of the data tables in the first database, and updates the field value under the second synchronization field in the target data table to the field value of the data to be synchronized corresponding to the first synchronization field according to the synchronization mode.
[0107] For example, when the data table type of the target data table is a slave table with a foreign key, and the data operation type of the data to be synchronized is addition or modification, determine the synchronization mode of first checking the master table of the synchronized target data table and then synchronizing the target data table, determine the master table to which the target data table belongs according to the foreign key field of the target data table, determine the data table corresponding to the master table in the first database according to the correspondence between the data table in the first database and the data table in the second database, query the field value m of the M field in the data table, and determine whether the primary key field value of the master table exists. If not, first insert m into the primary key field value of the master table, and then update the field value under the second synchronization field in the target data table to the field value corresponding to the first synchronization field of the data to be synchronized; if it exists, directly update the field value under the second synchronization field in the target data table to the field value corresponding to the first synchronization field of the data to be synchronized. When the data table type of the target data table is a main table with a primary key associated with other data tables, and the data operation type of the data to be synchronized is deletion or modification, determine the synchronization mode of first checking the slave table of the target data table and then synchronizing the target data table and its slave table, determine the data table corresponding to the target data table in the first database according to the corresponding relationship between the data table in the first database and the data table in the second database, query the field N corresponding to the primary key field in the data table, obtain the field value n1 before the field N is deleted or modified, and the field value n2 after the field N is modified, and judge whether the foreign key field value n1 of the slave table of the target data table exists. If it exists, first delete all data whose foreign key field value is n1 in the slave table of the target data table, and then delete or update the field value under the second synchronization field in the target data table to the field value n2 corresponding to the first synchronization field of the data to be synchronized. When the operation updates the field value n2, n2 needs to be inserted into the foreign key field value of the slave table of the target data table; if it does not exist, directly delete or update the field value under the second synchronization field in the target data table to the field value corresponding to the first synchronization field of the data to be synchronized.
[0108] The embodiment of the present application determines the synchronization mode by the second terminal according to the data table type, data operation type and the master-slave relationship of the data table, and updates the field value under the second synchronization field in the target data table to the field value of the first synchronization field corresponding to the data to be synchronized according to the synchronization mode, thereby ensuring accurate and complete data synchronization and further improving data synchronization efficiency.
[0109] In an optional embodiment, the method further includes step S204:
[0110] S204. When a data synchronization result is obtained, the data synchronization result is returned to the first terminal; and / or, the data synchronization result is verified to obtain a second data verification result, and a front-end display page of the second data verification result is generated.
[0111] As an example, when the second terminal completes the data synchronization task of the destination end and obtains the data synchronization result, it can return the data synchronization result to the first terminal, and the first terminal will perform a series of processes such as verification and display on the data synchronization result. It can also directly verify the data synchronization result to obtain a second data verification result, and generate a front-end display page for the second data verification result, so that the user can intuitively view the second data verification result on the second terminal.
[0112] In actual applications, the verification of data synchronization results includes one or more of the following: verifying whether the data list received by the second terminal is complete and correct based on the data source definition information, task configuration information and the user's editing operations on the synchronized data on the first terminal side; directly comparing the data list obtained by the first terminal with the data list received by the second terminal for consistency; and comparing the consistency between the data to be synchronized and the data after synchronization with the second terminal.
[0113] It should be noted that returning the data synchronization result to the first terminal, and / or verifying the data synchronization result to obtain the second data verification result, and generating a front-end display page for the second data verification result includes the following three situations: returning the data synchronization result to the first terminal; verifying the data synchronization result to obtain the second data verification result, and generating a front-end display page for the second data verification result; both returning the data synchronization result to the first terminal and verifying the data synchronization result to obtain the second data verification result, and generating a front-end display page for the second data verification result.
[0114] In the embodiment of the present application, when the data synchronization result is obtained, the second terminal returns the data synchronization result to the first terminal, and / or verifies the data synchronization result to obtain a second data verification result, and generates a front-end display page of the second data verification result, so that the user can intuitively view the data verification result.
[0115] Please see Figure 3 , Figure 3A structural diagram of a data synchronization device provided for the third embodiment of the present application. The third embodiment of the present application provides a data synchronization device, which is applicable to a first terminal, and the device includes: a first configuration acquisition module 301, which is used to obtain the screening rules, the first primary key field, the first synchronization field and the first synchronization direction configured for the first database of the first terminal; a module for determining data to be synchronized 302, which is used to filter the data to be synchronized in the first database according to the screening rules, and determine the data operation type of the data to be synchronized; a data list acquisition module 303, which is used to obtain a data list according to the field value of the data to be synchronized corresponding to the first primary key field, the field value of the data to be synchronized corresponding to the first synchronization field, the data operation type and the master-slave relationship of the data table in the first database; a data list sending module 304, which is used to send the data list to the second terminal, so that the second terminal performs data synchronization according to the data list; wherein the second terminal is determined according to the first synchronization direction.
[0116] In an optional embodiment, filtering the data to be synchronized in the first database according to the filtering rules includes: when a collection period within the effective period arrives, filtering the data to be synchronized according to the filtering rules.
[0117] In an optional embodiment, the number of data to be synchronized is at least one; the data list is obtained according to the field value of the data to be synchronized corresponding to the first primary key field, the field value of the data to be synchronized corresponding to the first synchronization field, the data operation type, and the master-slave relationship of the data table in the first database, including: for each data to be synchronized, combining the field value of the data to be synchronized corresponding to the first primary key field, the field value of the data to be synchronized corresponding to the first synchronization field, and the data operation type to obtain the initial data corresponding to the data to be synchronized; adding additional field values to the initial data to obtain target data corresponding to the data to be synchronized in the data list; wherein the additional field values are used to characterize the master-slave relationship of the data table.
[0118] In an optional embodiment, the device further includes: a first result display module, which is used to verify the data synchronization result when receiving the data synchronization result returned by the second terminal, obtain a first data verification result, and generate a front-end display page of the first data verification result.
[0119] The implementation process of the functions and effects of each module in the above-mentioned device is specifically described in the implementation process of the corresponding steps in the method described in the first embodiment of the present application, and will not be repeated here.
[0120] Please see Figure 4 , Figure 4A structural diagram of a data synchronization device provided for the fourth embodiment of the present application. The fourth embodiment of the present application provides a data synchronization device, which is applicable to a second terminal, and the device includes: a second configuration acquisition module 401, which is used to acquire a second primary key field, a second synchronization field, and a second synchronization direction configured for a second database of the second terminal; a data list receiving module 402, which is used to receive a data list sent by a first terminal; wherein the first terminal is determined according to the second synchronization direction; a data synchronization processing module 403, which is used to update the field value under the second synchronization field in the target data table according to the data table type of the target data table, the field value of the data to be synchronized in the data list corresponding to the first synchronization field, the data operation type of the data to be synchronized, and the master-slave relationship of the data table in the first database of the first terminal; wherein the target data table is determined according to the second primary key field.
[0121] In an optional embodiment, the data synchronization processing module 403 is also used to obtain a conflict handling strategy configured for the second database before updating the field value under the second synchronization field in the target data table according to the data table type of the target data table, the field value of the data to be synchronized corresponding to the first synchronization field in the data list, the data operation type of the data to be synchronized, and the master-slave relationship of the data table in the first database of the terminal; determine whether there is data to be synchronized in the second database, or whether the conflict handling strategy is an overwrite processing strategy, so as to update the field value under the second synchronization field in the target data table according to the data table type, the field value of the data to be synchronized corresponding to the first synchronization field, the data operation type, and the master-slave relationship of the data table when there is no data to be synchronized in the second database or the conflict handling strategy is an overwrite processing strategy.
[0122] In an optional embodiment, the updating of the field value under the second synchronization field in the target data table according to the data table type of the target data table, the field value of the data to be synchronized in the data list corresponding to the first synchronization field, the data operation type of the data to be synchronized, and the master-slave relationship of the data table in the first database of the first terminal includes: determining the synchronization mode according to the data table type, the data operation type, and the master-slave relationship of the data table; and updating the field value under the second synchronization field in the target data table to the field value of the data to be synchronized corresponding to the first synchronization field according to the synchronization mode.
[0123] In an optional embodiment, the device also includes: a second result display module, which is used to return the data synchronization result to the first terminal when the data synchronization result is obtained; and / or verify the data synchronization result to obtain a second data verification result, and generate a front-end display page for the second data verification result.
[0124] The implementation process of the functions and effects of each module in the above-mentioned device is specifically described in the implementation process of the corresponding steps in the method described in the first embodiment of the present application, and will not be repeated here.
[0125] Please see Figure 5 , Figure 5 A structural diagram of a data synchronization system provided in the fifth embodiment of the present application. The fifth embodiment of the present application provides a data synchronization system, including a first terminal 501 and a second terminal 502; the first terminal 501 is used to execute the method described in the first embodiment of the present application; the second terminal 502 is used to execute the method described in the second embodiment of the present application.
[0126] The implementation process of the functions and effects of the first terminal in the above-mentioned system is specifically detailed in the implementation process of the corresponding steps in the method described in the first embodiment of the present application, and the implementation process of the functions and effects of the second terminal is specifically detailed in the implementation process of the corresponding steps in the method described in the second embodiment of the present application, which will not be repeated here.
[0127] The sixth embodiment of the present application provides a computer program product, which includes instructions. When the instructions are executed by a computer, the computer implements the method described in the first embodiment of the present application or the method described in the second embodiment of the present application, and can achieve the same beneficial effects.
[0128] Please see Figure 6 , Figure 6 The seventh embodiment of the present application provides an electronic device 60, comprising a processor 601, a memory 602, and a computer program stored in the memory 602 and configured to be executed by the processor 601; the memory 602 is coupled to the processor 601, and when the processor 601 executes the computer program, the method described in the first embodiment of the present application or the method described in the second embodiment of the present application is implemented, and the same beneficial effects can be achieved.
[0129] When the processor 601 reads a computer program from the memory 602 through the bus 603 and executes the computer program, the method described in the first embodiment of the present application or the method described in the second embodiment of the present application can be implemented as any of the embodiments included in the method.
[0130] Processor 601 can process digital signals and can include various computing structures, such as complex instruction set computer structure, reduced instruction set computer structure, or a structure that implements a combination of multiple instruction sets. In some examples, processor 601 can be a microprocessor.
[0131] The memory 602 may be used to store instructions executed by the processor 601 or data related to the execution of instructions. These instructions and / or data may include codes for implementing some functions or all functions of one or more modules described in the embodiments of the present application. The processor 601 of the disclosed embodiment may be used to execute instructions in the memory 602 to implement the method described in the first embodiment of the present application or the method described in the second embodiment of the present application. The memory 602 includes a dynamic random access memory, a static random access memory, a flash memory, an optical memory, or other memory known to those skilled in the art.
[0132] The eighth embodiment of the present application provides a computer-readable storage medium, which includes a stored computer program; wherein, when the computer program is running, the device where the computer-readable storage medium is located is controlled to execute the method described in the first embodiment of the present application or the method described in the second embodiment of the present application, and can achieve the same beneficial effects.
[0133] The method described in the first embodiment of the present application or the method described in the second embodiment of the present application can be implemented in whole or in part by software, hardware, firmware or any combination thereof. When implemented using software, it can be implemented in whole or in part in the form of a computer program product. The computer program product includes one or more computer programs or instructions. When the computer program or instruction is loaded and executed on a computer, the process or function described in each embodiment of the present application is executed in whole or in part. The computer can be a general-purpose computer, a special-purpose computer, a computer network, a network device, a user device, a core network device, an OAM (Open Application Model) or other programmable device.
[0134] The computer program or instructions may be stored in a computer-readable storage medium, or transmitted from one computer-readable storage medium to another computer-readable storage medium, for example, the computer program or instructions may be transmitted from one website, computer, server or data center to another website, computer, server or data center by wired or wireless means. The computer-readable storage medium may be any available medium that can be accessed by a computer or a data storage device such as a server or data center that integrates one or more available media. The available medium may be a magnetic medium, such as a floppy disk, a hard disk, or a magnetic tape; it may also be an optical medium, such as a digital video disk; it may also be a semiconductor medium, such as a solid-state drive. The computer-readable storage medium may be a volatile or non-volatile storage medium, or may include both volatile and non-volatile types of storage media.
[0135] In summary, the embodiments of the present application provide a data synchronization method, system, program product, electronic device and storage medium. The data synchronization method is applicable to a first terminal, and the method includes: obtaining a screening rule, a first primary key field, a first synchronization field and a first synchronization direction configured for a first database for the first terminal; screening the data to be synchronized in the first database according to the screening rule, and determining the data operation type of the data to be synchronized; obtaining a data list according to the field value of the data to be synchronized corresponding to the first primary key field, the field value of the data to be synchronized corresponding to the first synchronization field, the data operation type and the master-slave relationship of the data table in the first database; sending the data list to the second terminal, so that the second terminal performs data synchronization according to the data list; wherein the second terminal is determined according to the first synchronization direction. In the embodiment of the present application, by pre-configuring filtering rules, a first primary key field, a first synchronization field, a first synchronization direction and other configuration data for the first database, the first terminal filters the data to be synchronized in the first database according to the filtering rules, and sends to the second terminal the field value of the data to be synchronized corresponding to the first primary key field, the field value of the data to be synchronized corresponding to the first synchronization field, the data operation type of the data to be synchronized and the master-slave relationship of the data table in the first database and other related data, so that the second terminal performs data synchronization according to the related data, can process data synchronization tasks in a refined manner, and improve data synchronization efficiency.
[0136] In several embodiments provided in the present application, it should be understood that the disclosed devices and methods can also be implemented in other ways. The device embodiments described above are merely schematic. For example, the flowcharts and block diagrams in the accompanying drawings show the possible architecture, functions and operations of the devices, methods and computer program products according to multiple embodiments of the present application. In this regard, each box in the flowchart or block diagram can represent a module, a program segment or a part of a code, and the module, a program segment or a part of a code contains one or more executable instructions for implementing the specified logical function. It should also be noted that in some alternative implementations, the functions marked in the box can also occur in a different order from the order marked in the accompanying drawings. For example, two consecutive boxes can actually be executed substantially in parallel, and they can sometimes be executed in the opposite order, depending on the functions involved. It should also be noted that each box in the block diagram and / or flowchart, and the combination of boxes in the block diagram and / or flowchart can be implemented with a dedicated hardware-based system that performs a specified function or action, or can be implemented with a combination of dedicated hardware and computer instructions.
[0137] In addition, the functional modules in the various embodiments of the present application may be integrated together to form an independent part, or each module may exist separately, or two or more modules may be integrated to form an independent part.
[0138] If the functions are implemented in the form of software function modules and sold or used as independent products, they can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of the present application can be essentially or partly embodied in the form of a software product that contributes to the prior art. The computer software product is stored in a storage medium, including several instructions to enable a computer device (which can be a personal computer, a server, or a network device, etc.) to perform all or part of the steps of the methods described in each embodiment of the present application. The aforementioned storage medium includes: various media that can store program codes, such as a USB flash drive, a mobile hard disk, a read-only memory (ROM), a random access memory (RAM), a magnetic disk or an optical disk.
[0139] The above is only a specific implementation of the present application, but the protection scope of the present application is not limited thereto. Any person skilled in the art who is familiar with the present technical field can easily think of changes or substitutions within the technical scope disclosed in the present application, which should be included in the protection scope of the present application. Therefore, the protection scope of the present application should be based on the protection scope of the claims.
Claims
1. A data synchronization method, characterized in that: Applicable to a first terminal, the method includes: Acquire a screening rule, a first primary key field, a first synchronization field, and a first synchronization direction configured for a first database of the first terminal; Filtering the data to be synchronized in the first database according to the screening rule, and determining the data operation type of the data to be synchronized; Obtaining a data list according to the field value of the data to be synchronized corresponding to the first primary key field, the field value of the data to be synchronized corresponding to the first synchronization field, the data operation type, and the master-slave relationship of the data tables in the first database; The data list is sent to a second terminal, so that the second terminal performs data synchronization according to the data list; wherein the second terminal is determined according to the first synchronization direction.
2. The method according to claim 1, characterized in that The filtering the data to be synchronized in the first database according to the filtering rule includes: When a collection period within the effective period arrives, the data to be synchronized is filtered according to the filtering rule.
3. The method according to claim 1, characterized in that The number of the data to be synchronized is at least one; The obtaining of the data list according to the field value of the to-be-synchronized data corresponding to the first primary key field, the field value of the to-be-synchronized data corresponding to the first synchronization field, the data operation type and the master-slave relationship of the data tables in the first database comprises: For each of the to-be-synchronized data, combining the field value of the to-be-synchronized data corresponding to the first primary key field, the field value of the to-be-synchronized data corresponding to the first synchronization field, and the data operation type, to obtain initial data corresponding to the to-be-synchronized data; An additional field value is added to the initial data to obtain target data corresponding to the data to be synchronized in the data list; wherein the additional field value is used to characterize the master-slave relationship of the data table.
4. The method according to any one of claims 1 to 3, characterized in that: The method further comprises: When the data synchronization result returned by the second terminal is received, the data synchronization result is verified to obtain a first data verification result, and a front-end display page of the first data verification result is generated.
5. A data synchronization method, characterized in that: Applicable to the second terminal, the method includes: Acquire a second primary key field, a second synchronization field, and a second synchronization direction configured for a second database of the second terminal; Receiving a data list sent by a first terminal; wherein the first terminal is determined according to the second synchronization direction; According to the data table type of the target data table, the field value of the data to be synchronized in the data list corresponding to the first synchronization field, the data operation type of the data to be synchronized, and the master-slave relationship of the data table in the first database of the first terminal, the field value under the second synchronization field in the target data table is updated; wherein the target data table is determined based on the second primary key field.
6. The method according to claim 5, characterized in that Before updating the field value under the second synchronization field in the target data table according to the data table type of the target data table, the field value of the to-be-synchronized data in the data list corresponding to the first synchronization field, the data operation type of the to-be-synchronized data, and the master-slave relationship of the data table in the first database of the first terminal, the method further includes: Obtaining a conflict handling strategy configured for the second database; Determine whether the data to be synchronized exists in the second database, or whether the conflict handling strategy is an overwrite handling strategy, so that if there is no data to be synchronized in the second database, or the conflict handling strategy is an overwrite handling strategy, update the field value under the second synchronization field in the target data table according to the data table type, the field value of the data to be synchronized corresponding to the first synchronization field, the data operation type and the master-slave relationship of the data table.
7. The method according to claim 5, characterized in that The updating of the field value under the second synchronization field in the target data table according to the data table type of the target data table, the field value of the data to be synchronized in the data list corresponding to the first synchronization field, the data operation type of the data to be synchronized, and the master-slave relationship of the data table in the first database of the first terminal includes: Determine a synchronization mode according to the data table type, the data operation type and the master-slave relationship of the data table; According to the synchronization mode, the field value under the second synchronization field in the target data table is updated to the field value of the to-be-synchronized data corresponding to the first synchronization field.
8. The method according to any one of claims 5 to 7, characterized in that: The method further comprises: When a data synchronization result is obtained, returning the data synchronization result to the first terminal; and / or, The data synchronization result is verified to obtain a second data verification result, and a front-end display page of the second data verification result is generated.
9. A data synchronization system, characterized in that: comprising a first terminal and a second terminal; The first terminal is used to execute the method according to any one of claims 1 to 4; The second terminal is used to execute the method according to any one of claims 5 to 8.
10. A computer program product, characterized in that The computer program product comprises instructions which, when executed by a computer, cause the computer to implement the method according to any one of claims 1 to 4 or the method according to any one of claims 5 to 8.
11. An electronic device, characterized in that: The method comprises a processor, a memory, and a computer program stored in the memory and configured to be executed by the processor; when the processor executes the computer program, the method according to any one of claims 1 to 4 or the method according to any one of claims 5 to 8 is implemented.
12. A computer-readable storage medium, characterized in that: The computer-readable storage medium includes a stored computer program; wherein, when the computer program is executed, the device where the computer-readable storage medium is located is controlled to execute the method according to any one of claims 1 to 4 or the method according to any one of claims 5 to 8.