Data synchronization method and apparatus

By detecting incremental data identifiers during database migration and synchronizing them to the corresponding master table, the problem of data synchronization failure during database migration is solved, and higher data synchronization reliability is achieved.

CN115098590BActive Publication Date: 2025-10-10CETC JINCANG (BEIJING) TECH CO LTD
View PDF 1 Cites 0 Cited by

Patent Information

Application Number
CN202210709954.4
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2022-06-22
Publication Date
2025-10-10
Estimated Expiration
2042-06-22

AI Technical Summary

Technical Problem

During the database migration process, due to syntax differences between the first and second databases, the partition table of the second database only includes the main table but not the sub-tables, resulting in data synchronization failure.

Method used

By detecting the incremental data identifier in the first database, querying the second identifier of the first main table associated with it, and synchronizing the incremental data to the second main table in the second database, the table structure is ensured to be the same and the reliability of data synchronization is achieved.

Benefits of technology

Improves the reliability of successful data synchronization, ensuring that incremental data can be successfully synchronized even if the secondary database lacks sub-tables.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN115098590B_ABST
    Figure CN115098590B_ABST
Patent Text Reader

Abstract

The application provides a data synchronization method and device, and relates to data processing technology. The data synchronization method detects that there is incremental data in a first database, wherein the incremental data is associated with a first identifier of a first table of the incremental data in the first database. According to the first identifier, a second identifier of a first master table having a mapping relationship with the first table is queried, wherein the first master table is associated with a plurality of sub-tables, and the first master table includes the contents of the plurality of sub-tables. When the second identifier of the first master table is queried, the incremental data is synchronized into a second master table in a second database, wherein third identity information of the second master table has a mapping relationship with the second identifier of the first master table, and the table structures of the first database and the second database are the same, thereby improving the reliability of successful data synchronization.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to data processing technology, and in particular to a data synchronization method and device. Background Art

[0002] Currently, when an electronic device runs an operating system or application, it records the data generated by the operating system or application in a subtable and main table of one of the partition tables of the first database. Simultaneously, the electronic device records the data logs generated by the operating system or application during operation in a designated folder. To prevent data loss in the first database if a problem occurs, the electronic device can also migrate the first database to obtain a second database. At this point, the electronic device can also synchronize the data in the first database to the second database based on the data logs to complete the data backup of the first database.

[0003] However, during the electronic device's migration of the first database, due to differences in syntax between the first and second databases, each partition table in the second database may only include the main table, but not the sub-tables. Typically, each data entry in a data log only includes the identity information of the sub-table in the first database. Consequently, the electronic device cannot find the sub-table associated with this identity information in the second database. Consequently, synchronization of some data in the data log to the second database fails. Summary of the Invention

[0004] The present application provides a data synchronization method and device to solve the problem of failure in synchronizing part of the data in a first database to a second database.

[0005] In a first aspect, the present application provides a data synchronization method, comprising: detecting the presence of incremental data in a first database, wherein the incremental data is associated with a first identifier of a first table in the first database. Based on the first identifier, querying the second identifier of a first master table that has a mapping relationship with the first table, wherein the first master table is associated with multiple sub-tables, and the first master table includes the contents of the multiple sub-tables. When the second identifier of the first master table is queried, synchronizing the incremental data to the second master table in the second database, wherein the third identity information of the second master table is mapped to the second identifier of the first master table, and the table structures of the first database and the second database are the same.

[0006] The data synchronization method provided by this application can query the second identifier of a first master table belonging to the same partition table as the first table based on the first identifier of the first table in the first database associated with the incremental data. Because the table structures of the first and second databases are identical, even if the second database does not have a subtable associated with the first identifier, the incremental data can still be synchronized to the second master table associated with the second identifier in the second database, thereby improving the reliability of successful data synchronization.

[0007] In an optional embodiment, querying, based on the first identifier, a second identifier of a first master table that has a mapping relationship with the first table includes: querying, based on the first identifier, a first parameter in a first database, where the first parameter indicates whether the first master table belongs to the same partition table as the first table. When the first parameter indicates that the first master table exists, querying, based on the first identifier, the second identifier of the first master table in the first database.

[0008] Since the first database contains complete mappings between the identity information of the sub-tables in each partition table and the identity information of the main table, the reliability of querying the second identifier of the first main table from the first database according to the first identifier is higher.

[0009] In an optional embodiment, before querying the first database for the first parameter based on the first identifier, the method further includes: determining, based on the first identifier, whether a second identifier of a first master table belonging to the same partition table as the first table exists in the cache. Querying the first parameter in the first database based on the first identifier includes: querying the first database for the first parameter based on the first identifier when the second identifier does not exist in the cache.

[0010] In an optional embodiment, the method provided by the present application further includes: when the first parameter is used to indicate the existence of the first main table, establishing a mapping relationship between the first identifier and the second identifier, and storing the mapped first identifier and the second identifier in a cache.

[0011] In this way, when the incremental data of the data log is detected to carry the first identifier of the first table in the first database next time, since the amount of data in the cache is small, the cache is searched for the second identifier of the first main table, which is efficient.

[0012] In an optional embodiment, querying the second identifier of the first main table that has a mapping relationship with the first table according to the first identifier includes: querying the second identifier of the first main table that belongs to the same partition table as the first table from the cache according to the first identifier.

[0013] Since the amount of data in the cache is small, searching the cache for the second identifier of the first main table is efficient.

[0014] In an alternative embodiment, after querying the second identifier of the first master table belonging to the same partition table as the first table from the cache, the method further comprises: deleting data in the cache that meets a preset condition when the remaining storage space of the cache is less than a set threshold.

[0015] In this way, the storage space of the cache can be saved, and when the cache is full of data, the function of data synchronization can be prevented from malfunctioning.

[0016] In an alternative embodiment, the data that meets the preset condition is: data stored in the cache at the earliest time. Or, data stored in the cache for a time greater than a preset time. Or, data stored in the cache before the data stored at the latest time.

[0017] In a second aspect, the application further provides a data synchronization device, comprising: a data detection unit configured to detect that there is incremental data in a first database, wherein the incremental data is associated with a first identifier of a first table in the first database. A data query unit configured to query a second identifier of a first master table associated with the first table according to the first identifier, wherein the first master table is associated with a plurality of sub-tables, and the first master table includes the contents of the plurality of sub-tables. A data synchronization unit configured to synchronize the incremental data to a second master table in a second database when the second identifier of the first master table is queried, wherein the third identity information of the second master table and the second identifier of the first master table have a mapping relationship, and the table structures of the first database and the second database are the same.

[0018] In a third aspect, the application further provides an electronic device, comprising:

[0019] a processor;

[0020] a memory for storing instructions executable by the processor;

[0021] The processor is configured to execute the instructions to implement the data synchronization method provided in the first aspect of the application.

[0022] In a fourth aspect, the application further provides a storage medium, when the instructions in the storage medium are executed by the processor of the electronic device, the terminal device can execute the data synchronization method provided in the first aspect of the application.

[0023] In a fifth aspect, the application further provides a computer program product, comprising a computer program, which, when executed by a processor, implements the data synchronization method provided in the first aspect. BRIEF DESCRIPTION OF DRAWINGS

[0024] The accompanying drawings, which are incorporated herein and form a part of the specification, illustrate embodiments consistent with the present application and, together with the description, further serve to explain the principles of the application.

[0025] Figure 1 One of flowcharts of a data synchronization method provided by an embodiment of the present application;

[0026] Figure 2 Another one of flowcharts of a data synchronization method provided by an embodiment of the present application;

[0027] Figure 3 A functional module block diagram of a data synchronization device provided by an embodiment of the present application;

[0028] Figure 4 A hardware block diagram of an electronic device provided by an embodiment of the present application.

[0029] The above-described drawings show specific embodiments of the present application, which will be described in more detail hereinafter. These drawings and the written description are not intended to restrict the scope of the present application in any way, but are merely to illustrate specific embodiments of the present application to those skilled in the art. DETAILED DESCRIPTION

[0030] The exemplary embodiments will be described in detail herein below with reference to the drawings. The following description is merely exemplary in nature and is not intended to limit the present application or the application and uses of the present application. Furthermore, there is no intention to be bound by any theory of operation of the present application.

[0031] First, the terms related to the present application are explained:

[0032] Partition table: A database can include a plurality of partition tables. Each partition table of the database is generally used to store the same type of data. Among them, the partition table can include a main table and sub-tables, and each sub-table is used to store a more subdivided type of data. The main table includes data of each sub-table belonging to the same partition table, and the main table and each sub-table have a mapping relationship.

[0033] Relational database: refers to a database that uses a relational model to organize data, which stores data in the form of rows and columns to facilitate user understanding. This series of rows and columns of the relational database is called a table, and a group of tables constitutes a database.

[0034] A linked list is a non-contiguous, non-sequential storage structure in physical memory. The logical order of data elements is achieved through the order of pointer links in the linked list. A linked list consists of a series of nodes (each element in the linked list is called a node), which can be dynamically generated at runtime. Each node consists of two parts: a data field for storing the data element and a pointer field for storing the address of the next node.

[0035] Currently, electronic devices record data generated by the operating system or the same application in a subtable and main table of one of the partition tables of the first database. Furthermore, electronic devices record data logs generated by the operating system or application during operation in a designated folder. Furthermore, electronic devices can migrate the first database to obtain a second database. In this case, the electronic device can also synchronize data from the first database to the second database based on the data logs, completing the backup of the data in the first database.

[0036] However, during the electronic device's migration of the first database, due to syntactic differences between the first and second databases for data with the same attributes, each partition table in the second database may only include the main table, but not the sub-tables. Typically, each piece of data in a data log only includes the identity information of the sub-table in the first database. Consequently, the electronic device cannot find the sub-table associated with this identity information in the second database. Consequently, synchronization of some data in the data log to the second database fails.

[0037] In view of this, the present application provides a data synchronization method, in which an electronic device detects that there is incremental data in a first database, wherein the incremental data is associated with a first identifier of a first table of the incremental data in the first database. Based on the first identifier, the electronic device queries the second identifier of the first main table that has a mapping relationship with the first table, wherein the first main table is associated with multiple sub-tables, and the first main table includes the contents of the multiple sub-tables. When the second identifier of the first main table is queried, the electronic device synchronizes the incremental data to the second main table in the second database, wherein the third identity information of the second main table is mapped to the second identifier of the first main table, and the table structure of the first database and the second database is the same, thereby improving the reliability of successful data synchronization.

[0038] The following specific embodiments describe in detail the technical solution of the present application and how the technical solution of the present application solves the above-mentioned technical problems. The following specific embodiments can be combined with each other, and the same or similar concepts or processes may not be repeated in some embodiments. The embodiments of the present application will be described below in conjunction with the accompanying drawings.

[0039] In a first aspect, the present application provides a data synchronization method, which is applied to an electronic device. The electronic device runs a first database. The first database is a relational database. For example, the first database can be a MySQL database, an Oracle database, etc., which are not limited here. Specifically, the electronic device can be a server. The data synchronization method provided in an embodiment of the present application includes:

[0040] S101: It is detected that there is incremental data in a first database, wherein the incremental data is associated with a first identifier of a first table of the incremental data in the first database.

[0041] The incremental data may include modifications, additions, and deletions to content in the first database. The incremental data includes a first identifier of a first table in the first database. The first identifier of the first table may include, but is not limited to, a table name and a schema name of the first table, where the schema name indicates the type of the first table.

[0042] Exemplarily, the presence of incremental data in the first database is detected by detecting the presence of incremental data in a data log of the operating system or the target application.

[0043] For example, when the electronic device is a server, the server can receive incremental data generated by the operating system or target application running on the terminal device sent from the terminal device. After the server receives the incremental data from the terminal device, it writes the incremental data into the first table of the partition table associated with the type of incremental data in the first database according to the type of incremental data. Furthermore, the server writes the incremental data in the folder used to record data logs. It can be understood that the incremental data written to the folder at this time carries the first identifier of the first table. In this way, the server can detect the presence of incremental data in the data log of the operating system or target application in the folder.

[0044] In addition, the target application may be an instant messaging application, a live broadcast application, a news browsing application, etc., which is not limited here.

[0045] S102: According to the first identifier, query the second identifier of the first main table that has a mapping relationship with the first table.

[0046] The first main table is a second table including contents of multiple sub-tables belonging to the same partition table as the first main table.

[0047] That is, based on the first identifier, it can be determined whether there is a first main table that belongs to the same partition table as the first table. In other words, based on the first identifier, it can be determined whether the first table is a sub-table of the partition table.

[0048] Specifically, the implementation of S102 includes but is not limited to the following two methods:

[0049] The first method: Based on the first identifier, a first parameter is queried in the first database. The first parameter is used to indicate whether a first primary table belonging to the same partition table as the first table exists. For example, the first parameter can be the "INHPARENT" field. When the value of the "INHPARENT" field is "TURE", the "INHPARENT" field indicates that a first primary table belonging to the same partition table as the first table exists; when the value of the "INHPARENT" field is "FALSE", the "INHPARENT" field indicates that a first primary table belonging to the same partition table as the first table does not exist. The schema name and table name of the first table can be used as a "where condition" to query the first parameter in the first database.

[0050] When the first parameter indicates the existence of a first primary table, the first database is queried for a second identifier corresponding to the first primary table based on the first identifier. For example, the first database can be queried for the schema name and table name of the first primary table based on the schema name and table name of the first table. The schema and table name of the first primary table can be understood as the second identifier of the first primary table.

[0051] Understandably, since the first database contains complete mappings between the identity information of the sub-tables in each partition table and the identity information of the main table, the reliability of querying the second identifier of the first main table from the first database based on the first identifier is higher.

[0052] Further, based on the first identifier, it is determined whether there is a second identifier of a first main table belonging to the same partition table as the first table in the cache. If the second identifier does not exist in the cache, the first parameter is queried in the first database based on the first identifier.

[0053] In addition, when the first parameter indicates that the first main table exists, a mapping relationship is established between the first identifier and the second identifier, and the first identifier and the second identifier with the established mapping relationship are stored in a cache.

[0054] For example, the table name and schema name of the first table can be used as the key value, and the table name and schema name of the first master table can be used as the value to store them in a cached hash table HashMap. This way, the next time incremental data in the data log is detected, it will contain the first identifier of the first table in the first database. Since the amount of data in the cache is small, searching the cache for the second identifier of the first master table is efficient. Alternatively, the aforementioned HashMap can be replaced with a BiMap.

[0055] The second method: Based on the first identifier, the second identifier of the first master table belonging to the same partitioned table as the first table is queried from the cache. Based on the first identifier, the second identifier of the first master table belonging to the same partitioned table as the first table is queried from the cache. As can be understood, due to the small amount of data in the cache, querying the cache for the second identifier of the first master table is more efficient.

[0056] Optionally, after querying the cache for the second identifier of the first master table belonging to the same partition table as the first table, the method provided by the present application further includes: when the remaining storage space in the cache is less than a set threshold, deleting data in the cache that meets a preset condition. This can conserve cache storage space and avoid further data being stored in the cache when the cache is full, which could cause data synchronization to malfunction.

[0057] In an optional embodiment, the data that meets the preset condition is: the earliest data stored in the cache; or data stored in the cache for a period longer than a preset period; or data stored in the cache before the latest data stored in the cache.

[0058] Exemplarily, the oldest data stored in the cache can be deleted by placing the retrieved second identifier of the first main table at the head of the linked list in the cache each time it is queried from the first database, and so on. In this way, the second identifier at the end of the linked list is the oldest data stored in the cache. Furthermore, the second identifier at the end of the linked list can be deleted. This process can be called deleting the oldest data stored in the cache based on the Least Recently Used (LRU) algorithm.

[0059] In addition, the above-mentioned LRU algorithm can be replaced by: LRU-K algorithm, LRU-Two (LRU-Two queues) algorithm, LRU-Multi (LRU-Multi queues) algorithm, LFU (Least Frequently Used) algorithm, LRUF (Least Recently / Frequently Used) algorithm, Adaptive Replacement Cache ARC (Adaptive Replacement Cache) algorithm, etc., which are not limited here.

[0060] S103: When the second identifier of the first main table is found, the incremental data is synchronized to the second main table in the second database, wherein the third identity information of the second main table is mapped to the second identifier of the first main table.

[0061] The first database and the second database have the same table structure. Optionally, the second database is also a relational database. The second database may be obtained by migrating data from the first database using a data migration tool. The second database and the first database are syntactically different. Exemplarily, the second database may be a DB2 database or a SQL Server database.

[0062] In addition, in the embodiment of the present application, before S301, the following steps may be included:

[0063] Detect the second parameter, which is used to indicate whether entry into the preset mode is allowed. S301-S303 can only be executed in the preset mode. For example, when the second parameter is a binary number "1", it indicates that S301-S303 are allowed to be executed; when the second parameter is a binary number "0", it indicates that S301-S303 are not allowed to be executed. When it is detected that the second parameter is used to indicate that S301-S303 is allowed to be executed, the subsequent S301-S303 can be executed. It should be noted that the second parameter can also be a control parameter, which is not limited here.

[0064] It should be noted that if Figure 2 As shown, the data synchronization method provided in the embodiment of the present application can be summarized as follows:

[0065] S201: Determine whether a preset control parameter is used to indicate entering a preset mode. If yes, execute S202.

[0066] S202: querying the value corresponding to the key value from the cache using the schema name and table name of the first table as the key value.

[0067] S203: Determine whether the queried value is empty. If not, execute S204; if yes, execute S206.

[0068] S204: Determine the queried value as the schema name and table name of the queried first main table.

[0069] S205: Synchronize the incremental data to a second main table in the second database that is associated with the schema name and table name of the first main table.

[0070] S206: According to the schema name and table name of the first table, a first parameter is queried in the first database. The first parameter is used to indicate whether there is a first main table belonging to the same partition table as the first table. If yes, execute S207.

[0071] S207: Based on the schema name and table name of the first table, the schema name and table name of the first main table are searched in the first database. Then, S205 is executed.

[0072] In summary, the data synchronization method provided in the embodiments of the present application enables an electronic device to query a second identifier of a first main table belonging to the same partition table as the first table based on a first identifier of a first table in a first database associated with incremental data. Because the table structures of the first database and the second database are identical, even if the second database does not have a subtable associated with the first identifier, the electronic device can still synchronize the incremental data to the second main table associated with the second identifier in the second database, thereby improving the reliability of successful data synchronization.

[0073] See also Figure 3 , the present application also provides a data synchronization device 300, which is applied to electronic devices. Among them, the electronic device can be a server, which is not limited here. It should be noted that the data synchronization device 300 provided in the embodiment of the present application has the same technical effect as the above embodiment. For the sake of brief description, for parts not mentioned in the embodiment of the present application, please refer to the corresponding content in the above embodiment. The data synchronization device 300 includes a data detection unit 301, a data query unit 302, and a data synchronization unit 303. Among them,

[0074] The data detection unit 301 is configured to detect that incremental data exists in the first database, wherein the incremental data is associated with a first identifier of a first table of the incremental data in the first database.

[0075] The data query unit 302 is configured to query a second identifier of a first main table that is mapped to a first table according to the first identifier, wherein the first main table is associated with multiple sub-tables and includes contents of the multiple sub-tables.

[0076] In an optional embodiment, the data query unit 302 may be specifically configured to query the first database for a first parameter based on the first identifier, where the first parameter indicates whether a first primary table that belongs to the same partition table as the first table exists. When the first parameter indicates that the first primary table exists, a second identifier corresponding to the first primary table is queryed in the first database based on the first identifier.

[0077] In another optional embodiment, the data query unit 302 can also be specifically used to query the second identifier of the first main table that belongs to the same partition table as the first table based on the first identifier; and query the second identifier of the first main table that belongs to the same partition table as the first table from the cache based on the first identifier.

[0078] Furthermore, the data synchronization device 300 provided in the present application may also include: a data deletion unit 304, which is used to delete data in the cache that meets preset conditions when the remaining storage space of the cache is less than a set threshold.

[0079] The data that meets the preset conditions may be: the earliest data stored in the cache, or data stored in the cache for a period longer than a preset period, or data stored in the cache before the latest data stored in the cache.

[0080] The data synchronization unit 303 is configured to synchronize the incremental data to the second main table in the second database when the second identifier of the first main table is found.

[0081] There is a mapping relationship between the third identity information of the second main table and the second identifier of the first main table, and the table structures of the first database and the second database are the same.

[0082] Figure 4 1 is a block diagram of an electronic device according to an exemplary embodiment. The electronic device includes one or more of the following components: a processing component 402 , a memory 404 , a power supply component 406 , an input / output (I / O) interface 412 , and a communication component 416 .

[0083] The processing component 402 generally controls the overall operation of the apparatus 400. The processing component 402 may include one or more processors 420 to execute instructions to perform all or part of the steps of the above-described method. In addition, the processing component 402 may include one or more modules to facilitate interaction between the processing component 402 and other components.

[0084] The memory 404 is configured to store various types of data to support operations on the device 400. Examples of such data include instructions for any application or method operating on the device 400, contact data, phone book data, messages, pictures, videos, etc. The memory 404 can be implemented by any type of volatile or non-volatile storage device, or a combination thereof, such as static random access memory (SRAM), electrically erasable programmable read-only memory (EEPROM), erasable programmable read-only memory (EPROM), programmable read-only memory (PROM), read-only memory (ROM), magnetic memory, flash memory, magnetic disk, or optical disk.

[0085] The power supply component 406 provides power to the various components of the device 400. The power supply component 406 may include a power management system, one or more power supplies, and other components associated with generating, managing, and distributing power to the device 400.

[0086] I / O interface 412 provides an interface between processing component 402 and peripheral interface modules, such as a keyboard, click wheel, buttons, etc. These buttons may include but are not limited to: a home button, volume buttons, a start button, and a lock button.

[0087] Communication component 416 is configured to facilitate wired or wireless communication between apparatus 400 and other devices. Apparatus 400 can access a wireless network based on a communication standard. In an exemplary embodiment, apparatus 400 can be implemented by one or more application-specific integrated circuits (ASICs), digital signal processors (DSPs), digital signal processing devices (DSPDs), programmable logic devices (PLDs), field programmable gate arrays (FPGAs), controllers, microcontrollers, microprocessors, or other electronic components to perform the above methods.

[0088] In an exemplary embodiment, a non-transitory computer-readable storage medium including instructions is also provided, such as a memory 404 including instructions, and the instructions can be executed by the processor component 420 of the apparatus 400 to perform the above method. For example, the non-transitory computer-readable storage medium can be a ROM, a random access memory (RAM), a CD-ROM, a magnetic tape, a floppy disk, and an optical data storage device. When the instructions in the non-transitory computer-readable storage medium are executed by the processor of the terminal device, the electronic device can perform Figure 1 The data synchronization method shown.

[0089] The present application also provides a computer program product, comprising a computer program, which, when executed by a processor, Figure 1 The data synchronization method shown.

[0090] Those skilled in the art will readily appreciate other embodiments of the present application after considering the specification and practicing the invention disclosed herein. This application is intended to cover any variations, uses, or adaptations of the present application that follow the general principles of the present application and include common knowledge or customary techniques in the art not disclosed herein. The description and examples are to be considered as exemplary only, and the true scope and spirit of the present application are indicated by the following claims.

[0091] It should be understood that the present application is not limited to the exact structure described above and shown in the drawings, and that various modifications and changes may be made without departing from the scope thereof. The scope of the present application is limited only by the appended claims.

Claims

1. A data synchronization method, characterized in that: The method comprises: It is detected that there is incremental data in the first database, wherein the incremental data is associated with a first identifier of a first table of the incremental data in the first database; the first table is a subtable of a partition table in the first database; querying, based on the first identifier, a second identifier of a first main table that is in a mapping relationship with the first table, wherein the first main table is associated with a plurality of sub-tables, and the first main table includes contents of the plurality of sub-tables; When the second identifier of the first master table is queried, the incremental data is synchronized to the second master table in the second database, wherein the synchronization to the second master table is performed in response to determining that a second sub-table corresponding to the first identifier does not exist in the second database, the third identity information of the second master table is mapped to the second identifier of the first master table, and the table structure of the first database and the second database are the same.

2. The method according to claim 1, characterized in that Querying, based on the first identifier, a second identifier of a first main table that has a mapping relationship with the first table, including: According to the first identifier, a first parameter is queried in the first database, where the first parameter is used to indicate whether the first main table belongs to the same partition table as the first table; When the first parameter indicates that the first main table exists, the second identifier of the first main table is queried in the first database according to the first identifier.

3. The method according to claim 2, characterized in that Before querying the first database for the first parameter based on the first identifier, the method includes: determining, based on the first identifier, whether there is a second identifier of the first main table that belongs to the same partition table as the first table in the cache; The querying the first parameter in the first database according to the first identifier includes: when the second identifier does not exist in the cache, querying the first parameter in the first database according to the first identifier.

4. The method according to claim 3, characterized in that The method further comprises: When the first parameter is used to indicate the existence of the first master table, establishing a mapping relationship between the first identifier and the second identifier; The first identifier and the second identifier that establish the mapping relationship are stored in the cache.

5. The method according to claim 1, wherein Querying, based on the first identifier, a second identifier of a first main table that has a mapping relationship with the first table, including: According to the first identifier, a second identifier of a first main table belonging to the same partition table as the first table is queried from the cache.

6. The method according to claim 5, characterized in that After querying the cache for a second identifier of a first main table belonging to the same partition table as the first table, the method further includes: When the remaining storage space of the cache is less than a set threshold, the data in the cache that meets the preset conditions is deleted.

7. The method according to claim 6, characterized in that The data that meets the preset conditions are: The earliest data stored in the cache; Alternatively, the data is stored in the cache for a period longer than a preset period; Alternatively, the data stored in the cache is before the latest data stored in the cache.

8. A data synchronization device, characterized in that: The device comprises: a data detection unit, configured to detect the presence of incremental data in the first database, wherein the incremental data is associated with a first identifier of a first table of the incremental data in the first database; the first table being a subtable of a partition table in the first database; a data query unit, configured to query, based on the first identifier, a second identifier of a first main table that is in a mapping relationship with the first table, wherein the first main table is associated with a plurality of sub-tables, and the first main table includes contents of the plurality of sub-tables; A data synchronization unit is used to synchronize the incremental data to the second main table in the second database when the second identifier of the first main table is queried, wherein the synchronization to the second main table is performed in response to determining that the second sub-table corresponding to the first identifier does not exist in the second database, the third identity information of the second main table is mapped to the second identifier of the first main table, and the table structure of the first database and the second database are the same.

9. An electronic device, characterized in that: include: processor; a memory for storing instructions executable by the processor; The processor is configured to execute the instructions to implement the data synchronization method according to any one of claims 1 to 7.

10. A storage medium, characterized in that: When the instructions in the storage medium are executed by a processor of an electronic device, the terminal device is enabled to execute the data synchronization method according to any one of claims 1 to 7.

Citation Information

Patent Citations

  • Data synchronization method and device based on table structure relationship

    CN113326266A