Database data synchronization method and device based on data page preloading

By recording the ROWID mapping relationship in the database and using ROWID information to preload data pages, the problem of insufficient precision in batch data preheating in the existing technology is solved, and the efficiency and performance of database data synchronization are improved.

CN114385753BActive Publication Date: 2024-10-18WUHAN DAMENG DATABASE
View PDF 5 Cites 0 Cited by

Patent Information

Application Number
CN202111534746.7
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2021-12-15
Publication Date
2024-10-18
Estimated Expiration
2041-12-15

AI Technical Summary

Technical Problem

Existing database data synchronization technology lacks effective analysis during batch data warm-up, resulting in multiple warm-ups of the same data page, causing unnecessary burden on the target database and affecting synchronization efficiency.

Method used

By recording the ROWID mapping relationship between source and target data, the ROWID positioning method is used to preload data pages during data synchronization, reducing unnecessary preheating operations and improving synchronization performance.

Benefits of technology

By extracting the ROWID information of the operation, the preloading history time difference is judged, and the data page is preloaded only when necessary, thereby reducing the access pressure on the target database, improving synchronization performance and reducing preheating costs.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN114385753B_ABST
    Figure CN114385753B_ABST
Patent Text Reader

Abstract

The present invention relates to a database data synchronization method and device based on data page preloading. The method part mainly includes: the target end data synchronization service creates a ROWID relationship mapping table for each table to be synchronized to record the mapping relationship of the ROWID of the source end data in the target end database; the target end data synchronization service determines the type of operation received from the source end, and determines the historical time of the last preloading according to the ROWID information to determine whether to preload; and executes related operations according to the operation type. The method adopted by the present invention can reduce the probability of accessing cold data during the formal synchronization transaction, thereby improving the synchronization performance. In addition, by extracting the ROWID information involved in the operation and determining the time difference between two loads from the preloading history, the operation of accessing the same data page is preheated only once, which can reduce the access pressure of the preheating operation on the target end database and realize the preheating function of the data page with the minimum access cost.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the technical field of database data processing, and in particular to a database data synchronization method and device based on data page preloading. Background Art

[0002] Currently, heterogeneous database replication technology based on log parsing is widely used. This technology captures database logs at the source end, parses the INSERT, UPDATE, and DELETE operations in the logs, and then sends them to the target end. The target end reversely generates the log information and restores it to SQL statements. Then, it uses the database universal interface and applies it to the target database to achieve data replication. Therefore, in the process of real-time database replication, the execution efficiency of the target end is one of the important factors affecting data synchronization performance.

[0003] When executing a synchronization transaction on the target database, if the data pages related to the operations in the synchronization transaction have been loaded, the efficiency of the transaction execution will be relatively high; otherwise, if the data pages related to the operations in the synchronization transaction are still in the database disk file, accessing these pages requires waiting for the IO module to load the page from the disk, and the efficiency of the transaction execution will become very slow, affecting the efficiency of data synchronization. Therefore, data synchronization can analyze the data on the target database to be accessed after the synchronization operation is performed, so as to improve the synchronization performance during the formal synchronization. The existing technology is relatively blind when performing batch data preheating. In order to reduce the pressure of the data preheating operation on the target database, when synchronizing batch operations, some operations will be randomly selected for analysis and then the data of these operations on the target database will be preheated. The lack of effective analysis of batch operation data leads to multiple preheating of the same data pages, which causes unnecessary burden on the target database.

[0004] Therefore, how to select operations on different pages to achieve a higher preheating effect at a lower cost has become an important technical problem that needs to be solved urgently in the industry. Summary of the invention

[0005] In view of the above defects or improvement needs of the prior art, the present invention provides a database data synchronization method and device based on data page preloading. When data synchronization is initialized, the mapping relationship between the ROWID of the source data (each row of data in the table has a unique identifier, called ROWID) and the ROWID recorded in the target database is recorded. After the data synchronization starts, when the record in the source database changes, the ROWID of the row can be found by changing the ROWID of the row. Then, the data page where the row of data is located is loaded into the database cache by ROWID positioning, thereby preheating the data page and improving its synchronization performance during formal synchronization.

[0006] The embodiment of the present invention adopts the following technical solution:

[0007] In a first aspect, the present invention provides a database data synchronization method based on data page preloading, comprising:

[0008] The target-side data synchronization service creates a ROWID relationship mapping table for each table to be synchronized to record the mapping relationship between the source-side data and the ROWID in the target-side database.

[0009] The target-side data synchronization service determines the type of operation received from the source side and determines the historical time of the last preload based on the ROWID information to determine whether to preload.

[0010] Perform relevant actions based on the action type.

[0011] Furthermore, the target-side data synchronization service determines the type of operation received from the source side, and determines the historical time of the last preload according to the ROWID information to determine whether to perform preload. Specifically, the process includes:

[0012] After receiving the operation sent by the source, the target-side data synchronization service determines the type of operation. If it is an UPDATE or DELETE operation, it extracts the ROWID of the operation and obtains the ROWID information of the operation in the target-side database through the ROWID relationship mapping table.

[0013] The historical time of the last preloading of the data page is searched in the preloading history through the ROWID information. If the corresponding historical time is found, the historical time judgment step is entered; if the corresponding historical time is not found, the data page preloading step is entered;

[0014] Historical time judgment step: judging whether the difference between the historical time and the current time is greater than the set time difference T, if so, entering the data page preloading step, if not, updating the preloading time of the data page to the current time, and not entering the data page preloading step;

[0015] Data page preloading step: preload data page using ROWID information and update the data page preloading time to the current time.

[0016] Preferably, the ROWID information includes a file ID number and a page number of a data page.

[0017] Furthermore, the data page preloading step specifically includes:

[0018] The ROWID of the target database is used as a query condition, and the query is executed in the target database so that the data page corresponding to the ROWID is loaded into the database cache;

[0019] The file ID corresponding to the ROWID of the target database and the page number of the data page are combined and stored in the preload history, and the preload time is updated to the current time.

[0020] Preferably, the ROWID information includes a virtual data page number, and the step of obtaining the virtual data page number specifically includes:

[0021] Get the page size P of the target database data page and the maximum record size R of the table to be synchronized, and by specifying a fill factor F, find the minimum number of rows N that can store records on a single data page: N = (P / R)*F, where F ranges from [0 to 1];

[0022] If the operation is an UPDATE or DELETE operation, the ROWID of the operation is extracted, and the ROWID of the operation in the target database is obtained through the ROWID relationship mapping table. The ROWID is reduced by 1 and divided by the minimum number of rows N to obtain a virtual data page number PAGENO: PAGENO = (ROWID-1) / N.

[0023] Furthermore, the data page preloading step specifically includes:

[0024] The ROWID of the target database is used as a query condition, and the query is executed in the target database so that the data page corresponding to the ROWID is loaded into the database cache;

[0025] The virtual data page number corresponding to the ROWID of the target database is stored in the preload history, and the preload time is updated to the current time.

[0026] Furthermore, in the step of determining the operation type, if the target-side data synchronization service determines that the operation is an INSERT operation, the data page preloading step is not performed.

[0027] Further, the performing of related operations according to the operation type specifically includes:

[0028] After receiving the transaction commit operation, start executing the operations in the transaction;

[0029] When executing an operation, if it is an INSERT operation, a mapping relationship is established between the ROWID of the operation on the source side and the ROWID returned after the INSERT operation is executed on the target side, and the mapping relationship is stored in the ROWID relationship mapping table of the table involved in the operation;

[0030] When executing an operation, if it is a DELETE operation, the ROWID of the operation on the source side is deleted from the ROWID relationship mapping table of the table involved in the operation;

[0031] Complete the synchronization of this transaction.

[0032] Furthermore, the deployment steps are also included:

[0033] The log parsing module of the data synchronization service is deployed in the source database to parse log operations. The data synchronization service is deployed in the target database to receive operations sent by the source data synchronization service and store them in the database.

[0034] On the other hand, the present invention provides a database data synchronization device based on data page preloading, specifically: including at least one processor and a memory, at least one processor and the memory are connected through a data bus, the memory stores instructions that can be executed by at least one processor, and after the instructions are executed by the processor, they are used to complete the database data synchronization method based on data page preloading in the first aspect.

[0035] Compared with the prior art, the beneficial effects of the present invention are as follows: first, when synchronizing a transaction, the target-side data synchronization service generally starts synchronizing the transaction only after receiving the commit operation of the transaction. There is an uncertain time difference between receiving the first operation of the transaction and the last commit operation. The present invention uses this time difference to preheat the data pages of the target-side database that the transaction may need to access before it is officially synchronized. In this way, when the transaction is officially synchronized, the probability of accessing cold data can be reduced, thereby improving the synchronization performance of the transaction.

[0036] Secondly, the transaction operations to be synchronized often involve batch operations. For example, if a batch of operation data is updated in a transaction, this batch of operation data may all belong to the same data page. In this case, when preheating the data page for this batch of operations, it is not necessary to preheat each operation once. By extracting the ROWID information involved in this batch of operations in the target database ROWID, the time difference between the two loads is determined from the preload history. When the time difference is less than the set value, operations accessing the same data page only need to be preheated once. This can greatly reduce the access pressure of the preheating operation on the target database, and achieve the data page preheating function with the minimum access cost. BRIEF DESCRIPTION OF THE DRAWINGS

[0037] In order to more clearly illustrate the technical solutions of the embodiments of the present invention, the following briefly introduces the drawings required for use in the embodiments of the present invention. Obviously, the drawings described below are only some embodiments of the present invention, and for ordinary technicians in this field, other drawings can be obtained based on these drawings without creative work.

[0038] Figure 1 A flow chart of a database data synchronization method based on data page preloading provided in Embodiment 1 of the present invention;

[0039] Figure 2 A specific flow chart of step 200 provided in Example 1 of the present invention;

[0040] Figure 3 A specific flow chart of step 300 provided in Example 1 of the present invention;

[0041] Figure 4 A specific flow chart of step 200 provided for embodiment 2 of the present invention;

[0042] Figure 5 A specific flow chart of step 200 provided in Example 3 of the present invention;

[0043] Figure 6 A schematic diagram of the structure of a database data synchronization device based on data page preloading provided in Example 4 of the present invention. DETAILED DESCRIPTION

[0044] In order to make the purpose, technical solution and advantages of the present invention more clearly understood, the present invention is further described in detail below in conjunction with the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are only used to explain the present invention and are not used to limit the present invention.

[0045] The present invention is an architecture of a specific functional system, so the specific embodiments mainly illustrate the functional logical relationship between the various structural modules, and do not limit the specific software and hardware implementation methods.

[0046] In addition, the technical features involved in the various embodiments of the present invention described below can be combined with each other as long as they do not conflict with each other. The present invention will be described in detail below with reference to the accompanying drawings and embodiments.

[0047] Embodiment 1:

[0048] like Figure 1 As shown, an embodiment of the present invention provides a database data synchronization method based on data page preloading, which specifically includes the following steps.

[0049] Step 100: The target-side data synchronization service creates a ROWID relationship mapping table for each table to be synchronized to record the mapping relationship between the source-side data and the ROWID in the target-side database. For this step, before the table starts to be synchronized, since the table already has data in the source-side database and is an empty table in the target-side database, it is necessary to first insert the table data in the source-side database into the target-side database. During this insertion process, the mapping relationship between the ROWID of the source-side data and the ROWID of the target-side data can be obtained, and this relationship can be saved in the ROWID mapping table for backup.

[0050] Step 200: The target-side data synchronization service determines the type of operation received from the source end, and determines the historical time of the last preload based on the ROWID information to determine whether to preload. This step is the core point. By determining the type of operation and the historical time of the last preload based on the ROWID information, it can avoid the problem of blind preloading and will not preload the same data page twice in a short period of time.

[0051] Step 300: Execute related operations according to the operation type. In this step, after the preloading is completed, the target end data synchronization service executes related operations according to the operation type. Because of the preloading, the probability of accessing cold data can be reduced, thereby improving the synchronization performance of the transaction.

[0052] The above steps utilize the time difference between the first operation received and the last commit operation of the transaction to preheat the data pages of the target database that the transaction may access before it is formally synchronized. In this way, when the transaction is formally synchronized, the probability of accessing cold data can be reduced, thereby improving the synchronization performance of the transaction. In addition, by extracting the ROWID information involved in this batch of operations in the ROWID of the target database, preloading is performed only when the historical time of preloading meets the requirements from the preloading history. In this way, operations accessing the same data page within a certain period of time only need to be preheated once, which can greatly reduce the access pressure of the preheating operation on the target database, and realize the preheating function of the data page with the minimum access cost.

[0053] In this preferred embodiment, before performing step 100, a deployment step is also included: deploying a log parsing module of the data synchronization service in the source database, which is responsible for parsing log operations; deploying a data synchronization service in the target database, which is responsible for receiving operations sent by the source data synchronization service and storing them in the database.

[0054] like Figure 2 As shown, in this preferred embodiment, the above step 200 (the target-side data synchronization service determines the type of operation received from the source end, and determines the historical time of the last preload according to the ROWID information to determine whether to preload) may specifically include the following steps:

[0055] Step 201: After the target-side data synchronization service receives the operation sent by the source, it determines the type of operation. If it is an UPDATE or DELETE operation, it extracts the ROWID of the operation and obtains the ROWID information of the operation in the target-side database through the ROWID relationship mapping table. In this step, the log parsing module of the source is required to first parse the operation log of the source database, parse out its corresponding ROWID and send it together with the operation to the target-side data synchronization service. After the target-side data synchronization service receives the operation sent by the source, it first determines the type of operation. If it is an INSERT operation, it does not enter the data page preloading program, that is, it does not enter the subsequent data page preloading step. This is because the synchronization service cannot determine which file and which block of the target database the data in the INSERT operation will eventually fall on, so it cannot preload the corresponding data page.

[0056] Step 202: Search the preloading history for the last time the data page was preloaded using the ROWID information. If the corresponding historical time is found, enter the historical time judgment step. If the corresponding historical time is not found, enter the data page preloading step. This step is to search the preloading history of the data page using the ROWID information. If it is found, it means that it has a preloading history. It is necessary to further judge whether its historical time meets the conditions. If the historical time is not found, it means that it has no preloading history, so it can directly enter the subsequent data page preloading step.

[0057] Step 203: Historical time judgment step: judge whether the difference between the historical time and the current time is greater than the set time difference T. If so, enter the data page preloading step. If not, update the preloading time of the data page to the current time, and do not enter the data page preloading step. In this step, since there is an elimination mechanism for data pages in the database cache, the data page elimination time is determined by the database operating environment, and the time interval for eliminating data pages in different environments is also different, so it is necessary to dynamically specify the time difference T here. When the time difference between two preloadings is less than T, there is a high possibility that the page will remain in the database cache, so there is no need to load it again, and its preloading time can be directly updated, because the operation corresponding to the ROWID is equivalent to re-preheating the data of the page when it is executed.

[0058] Step 204: Data page preloading step: preloading is performed through ROWID information, and the data page preloading time is updated to the current time. For this step, it is necessary to first use the ROWID of the target database as a query condition, and execute the query in the target database so that the data page corresponding to the ROWID is loaded into the database cache; then the ROWID information corresponding to the ROWID of the target database is stored in the preloading history, and the preloading time is updated to the current time. Among them, the advantage of using ROWID as a query condition over using the column in the operation as a query condition is that ROWID is generally a primary index of the organization table. Using it as a query condition can quickly locate the data. When using the operation column, if the column is not an index column, it is necessary to create an additional primary key or index for the column. Both the primary key and the index belong to the secondary index, and the efficiency of the positioning query is not as high as the primary index such as ROWID.

[0059] like Figure 3 As shown, in this preferred embodiment, the above step 300 (performing related operations according to the operation type) may specifically include the following steps:

[0060] Step 301: After receiving the commit operation of the transaction, the operations in the transaction are started. When synchronizing a transaction, the target-side data synchronization service generally waits until the commit operation of the transaction is received before starting to synchronize the transaction. This step uses this as the dividing line, and uses the time from the first operation of the transaction to the commit operation as the time difference for warming up. After receiving the commit operation, the operations in the transaction are started, that is, synchronization begins.

[0061] Step 302: When executing an operation, if it is an INSERT operation, a mapping relationship is established between the ROWID of the operation at the source end and the ROWID returned after the INSERT operation is executed at the target end, and the mapping relationship is stored in the ROWID relationship mapping table of the table involved in the operation.

[0062] Step 303: When executing an operation, if it is a DELETE operation, the ROWID of the operation at the source end is deleted from the ROWID relationship mapping table of the table involved in the operation.

[0063] It should be noted that when executing an operation, if it is an UPDATE operation, since the UPDATE operation will not modify the ROWID mapping relationship, the ROWID relationship mapping table does not need to be processed when executing the operation.

[0064] Step 304: Complete the synchronization of the transaction.

[0065] The main solution for preloading data pages mentioned above is to use the time difference between the time when the target-side data synchronization service receives the first operation of the transaction and the time when the target-side data synchronization service receives the last commit operation of the transaction to preheat the data pages involved in the transaction in the target-side database in a targeted manner, so as to prevent the data pages involved in the operations to be synchronized in the transaction from being still in the disk file when the target-side data synchronization service starts to execute the transaction after receiving the transaction commit operation. In this case, to execute these operations, the database also needs to load these data pages from the disk file into the data page cache, resulting in reduced synchronization performance. The solution of this embodiment can effectively prevent this situation from happening.

[0066] In summary, this embodiment has the following effects. First, when the database is executing an operation, if the data to be operated is already in the database cache, then accessing this data will achieve relatively high performance; otherwise, when accessing this data, the database needs to wait for the IO module to load this data from the disk file into the cache, and this waiting will reduce the data access performance. When synchronizing transactions, the target-side data synchronization service generally waits until the transaction commit operation is received before starting to synchronize the transaction. There is an uncertain time difference between receiving the first transaction operation and the last commit operation. This embodiment uses this time difference to preheat the data pages that the transaction may need to access in the target-side database before it is officially synchronized. In this way, when the transaction is officially synchronized, the probability of accessing cold data can be reduced, thereby improving the synchronization performance of the transaction.

[0067] Secondly, the transaction operations to be synchronized often involve batch operations. For example, if a batch of operation data is updated in a transaction, this batch of operation data may all belong to the same data page. In this case, when preheating the data page for this batch of operations, it is not necessary to preheat each operation once. By extracting the ROWID information involved in this batch of operations in the target database ROWID, the time difference between the two loads is determined from the preload history. When the time difference is less than the set value, operations accessing the same data page only need to be preheated once. This can greatly reduce the access pressure of the preheating operation on the target database, and achieve the data page preheating function with the minimum access cost.

[0068] Embodiment 2:

[0069] Based on the database data synchronization method based on data page preloading provided in Example 1, this Example 2 further illustrates the method with respect to physical ROWID.

[0070] ROWID is often used by databases to organize data in tables. There are two formats of ROWID. One is the format generated by the physical address. For example, the ROWID of the ORACLE database is a physical ROWID. The other is the logical ROWID, which is a continuously increasing integer to maintain its sequence and uniqueness, such as SQL SERVER and DAMO database.

[0071] This embodiment is mainly for the physical ROWID database to expand, physical ROWID is composed of file ID number, data page number and data in the page line number combination. As long as the ROWID of the accessed data is known, the position of the accessed data in the database data file can be confirmed.

[0072] For a database using physical ROWID, the basic steps of this embodiment are consistent with those of embodiment 1, except that the definition of ROWID information is different when obtaining the corresponding ROWID information. For physical ROWID, the ROWID information obtained in this embodiment includes the file ID number and the page number of the data page.

[0073] In this way, if Figure 4 As shown, step 200 in Embodiment 1 (the target-side data synchronization service determines the type of operation received from the source side, and determines the historical time of the last preload according to the ROWID information to determine whether to preload) is extended as follows in this embodiment:

[0074] Step 211: After receiving the operation sent by the source end, the target end data synchronization service determines the type of operation. If it is an INSERT operation, the subsequent data page preloading step is not performed.

[0075] Step 212: If it is an UPDATE or DELETE operation, extract the ROWID of the operation, and obtain the ROWID of the operation in the target database from the ROWID mapping table of the table where the operation is located, and then split the file ID number and the data page number from the ROWID in the target database. In this step, since the database cache is based on data pages, when splitting the ROWID, only the file ID and the data page number need to be split, and the row number recorded in the data page does not need to be split. Because multiple adjacent ROWIDs may be in the same data page, these operations only need to load the data page once during preloading.

[0076] Step 213: Search the preloading history for the last time the data page was preloaded using the file ID and the page number of the data page. If no corresponding historical time exists, enter the data page preloading step. If a corresponding historical time is found, enter the historical time determination step.

[0077] Step 214: Historical time judgment step: judge whether the difference between the historical time and the current time is greater than the set time difference T. If so, enter the data page preloading step. If not, update the preloading time of the data page to the current time and do not enter the data page preloading step.

[0078] Step 215: Data page preloading step: Use the ROWID of the target database as the query condition, execute the query in the target database, so as to load the data page corresponding to the ROWID into the database cache, and then combine the ID of the file corresponding to the ROWID of the target database and the page number of the data page and store them in the preloading history, and update the preloading time to the current time.

[0079] The other steps of this embodiment 2 are consistent with step 100 and step 300 in embodiment 1, and are not described again here.

[0080] This embodiment extracts the file ID number and data page number involved in the operation in the ROWID of the target database, and determines the time difference between two loads from the preloading history. When the time difference is less than the set value, the operation of accessing the same data page only needs to be preheated once, which can greatly reduce the access pressure of the preheating operation on the target database and realize the preheating function of the data page with the minimum access cost.

[0081] Regarding the above solution of this embodiment 2, this embodiment is described in more detail below through a specific application scenario.

[0082] In this application scenario, the time difference T between two preloads is set to 60 seconds.

[0083] The source database table T1 (OBJ INT, DATA INT) contains 3 rows of data. Its data is distributed in the database as follows:

[0084] ROWID OBJ Column DATA column AAATYnAAEAABxlbAAA 1 11 AAATYnAAEAABxlbAAB 2 22 AAATYnAAEAABxlcAAA 3 33

[0085] For the above table T1, the preheating and synchronization process is as follows:

[0086] 1. First, copy the data of table T1 to the target database for initial synchronization and build a ROWID relationship mapping table.

[0087] First, query the data of table T1 from the source database, and then insert it into the target database by returning the ROWID. By executing the insert statement INSERT INTO T1 VALUES(:1,:2)RETURN ROWID INTO:2, you can get the ROWID of the source table row in the target database, and then build the ROWID relationship mapping table as follows:

[0088] Source ROWID Destination ROWID Document ID Page Number AAATYnAAEAABxlbAAA AAATYnAAEAABxljAAA 4 465251 AAATYnAAEAABxlbAAB AAATYnAAEAABxljAAB 4 465251 AAATYnAAEAABxlcAAA AAATYnAAEAABxlkAAA 4 465252

[0089] 2. Enable data synchronization for table T1.

[0090] 3. Insert a new row of data into the T1 table of the source database and commit it, generating transaction TRX1: INSERT INTO T1VALUES(4, 44), whose ROWID on the source side is AAATYnAAEAABxlcAAB.

[0091] 4. The source-side log parsing module captures the operations of transaction TRX1 and sends them to the target-side data synchronization service.

[0092] 5. The target-side data synchronization service receives the T1 table INSERT operation of transaction TRX1 and determines that its operation type is INSERT, so there is no need to preload the data page.

[0093] 6. The target-side data synchronization service receives the commit operation of transaction TRX1 and starts to execute the transaction. It obtains the ROWID of the row record in the target-side database by executing the statement: INSERT INTO T1 VALUES(4, 44) RETURN ROWID INTO:1: AAATYnAAEAABxlkAAB.

[0094] 7. Since the synchronization is an INSERT operation, the ROWID mapping relationship of the row data in the source database and the target database needs to be saved in the ROWID relationship mapping table to form the following relationship:

[0095]

[0096]

[0097] From the above INSERT operation synchronization process, we can see that the ROWID relationship mapping table of the T1 table changes with the scale of the T1 table in the source database. The ROWID relationship mapping table always saves the mapping relationship of the ROWID of the T1 table in the source database and the target database. The ROWID value in the target database can be found in the ROWID mapping table through the ROWID value in the log operation.

[0098] 8. Perform UPDATE and DELETE operations on T1 in the source database:

[0099] UPDATE T1 SET DATA=111WHERE ROWID=AAATYnAAEAABxlbAAA;

[0100] UPDATE T1 SET DATA=222WHERE ROWID=AAATYnAAEAABxlbAAB;

[0101] DELETE T1 WHERE ROWID=AAATYnAAEAABxlcAAA;

[0102] COMMIT;

[0103] 9. When the target side receives the UPDATE operation with ROWID AAATYnAAEAABxlbAAA on the source side, it finds its ROWID value AAATYnAAEAABxljAAA in the target side database in the ROWID relationship mapping table and extracts its file ID and data page number as 4 and 465251 respectively.

[0104] 10. According to the file ID (4) and the data page number (465251), the last loading time of the page is searched in the preloading history. Since it is the first loading and there is no history record, the statement: SELECT 1 FROM T1 WHERE ROWID = AAATYnAAEAABxljAAA is executed in the target database to preload the data page with data file ID 4 and data page number 465251 into the database cache.

[0105] 11. Store the loading record of the file ID (4) and data page number (465251) with the current time in the preload history.

[0106] 12. When the target side receives the UPDATE operation with ROWID AAATYnAAEAABxlbAAB on the source side, it finds its ROWID value AAATYnAAEAABxljAAB in the target side database in the ROWID relationship mapping table and extracts its file ID and data page number as 4 and 465251 respectively.

[0107] 13. Search the preload history for the last loading time of the page based on the file ID (4) and the data page number (465251), and find the time difference T between the current time and the last loading time. If T is less than 60 seconds, do not load the page, and update the page time in the loading history to the current time.

[0108] In this step, you can see that there are two UPDATE operations on the data page with file ID 4 and data page number 465251. However, the preload module only loads the page once, reducing the number of preload executions and achieving the effect of reducing the pressure on the destination database.

[0109] 14. When the target side receives the DELECT operation with ROWID AAATYnAAEAABxlcAAA from the source side, it finds its ROWID value AAATYnAAEAABxlkAAA in the target side database in the ROWID relationship mapping table and extracts its file ID and data page number as 4 and 465252 respectively.

[0110] 15. According to the file ID (4) and the data page number (465252), the last loading time of the page is searched in the preloading history. Since it is the first loading and there is no history record, the statement: SELECT 1 FROM T1 WHERE ROWID = AAATYnAAEAABxlkAAA is executed in the target database to preload the data page with data file ID 4 and data page number 465252 into the database cache.

[0111] 16. Store the loading record of the file ID (4) and data page number (465252) with the current time in the preload history.

[0112] 17. The target-side data synchronization service receives the commit operation and starts executing the transaction.

[0113] 18. When the transaction executes the DELETE operation, after the DELETE operation is completed, the mapping relationship of the row data is deleted in the ROWID mapping table through the ROWID value AAATYnAAEAABxlcAAA of the log operation. Finally, the mapping relationship of the ROWID mapping table of the table is as follows:

[0114] Source ROWID Destination ROWID Document ID Page Number AAATYnAAEAABxlbAAA AAATYnAAEAABxljAAA 4 465251 AAATYnAAEAABxlbAAB AAATYnAAEAABxljAAB 4 465251 AAATYnAAEAABxlcAAB AAATYnAAEAABxlkAAB 4 465252

[0115] From the above process, we can see that by maintaining the ROWID mapping table, we can clearly know the location distribution of each row of data in the source table T1 on the target database. When synchronizing the operation of table T1, we can accurately load the data page to be operated on the target database through the mapping relationship in the ROWID mapping table. In addition, by comparing the last loading time in the preloading history, we can effectively reduce the number of repeated data page loading times, thereby reducing the pressure on the target database.

[0116] Embodiment 3:

[0117] Based on the database data synchronization method based on data page preloading provided in Example 1, this Example 3 further illustrates the method with respect to logical ROWID.

[0118] ROWID is often used by databases to organize data in tables. There are two formats of ROWID. One is the format generated by the physical address. For example, the ROWID of the ORACLE database is a physical ROWID. The other is the logical ROWID, which is a continuously increasing integer to maintain its sequence and uniqueness, such as SQL SERVER and DAMO database.

[0119] This embodiment is mainly aimed at a database with ROWID in a logical sequence increasing format. The sequential increasing characteristic of ROWID in the database is used to implement preloading of data pages involved in synchronization operations in a targeted manner during data synchronization.

[0120] For a database using logical ROWID, the basic steps of this embodiment are consistent with those of embodiment 1, except that the definition of ROWID information is different when obtaining the corresponding ROWID information. For logical ROWID, the ROWID information obtained in this embodiment includes a virtual data page number.

[0121] In this way, if Figure 5 As shown, step 200 in Embodiment 1 (the target-side data synchronization service determines the type of operation received from the source side, and determines the historical time of the last preload according to the ROWID information to determine whether to preload) is extended as follows in this embodiment:

[0122] Step 221: Get the page size P of the target database data page and the maximum record size R of the table to be synchronized, and specify a fill factor F to obtain the minimum number of rows N for storing records in a single data page: N = (P / R) * F. Wherein, the value range of F is [0 to 1]. The fill factor is used to control the saturation of the records stored in a single data page, and its value range is [0 to 1]. The smaller the specified value, the fewer the number of records stored in a single data page.

[0123] Step 222: After receiving the operation sent by the source end, the target end data synchronization service determines the type of operation. If it is an INSERT operation, the subsequent data page preloading step is not performed.

[0124] Step 223: If it is an UPDATE or DELETE operation, extract the ROWID of the operation, and obtain the ROWID of the operation in the target database through the ROWID relationship mapping table, subtract 1 from the ROWID and divide it by the minimum number of rows N to obtain a virtual data page number PAGENO: PAGENO = (ROWID-1) / N. In this step, since the database cache is in units of data pages, but the logical ROWID cannot represent the data page address of the record in the database, and since the ROWID has the characteristic of increasing in logical order, then when the number of records stored in each page is known, a virtual data page number can be obtained by dividing the ROWID by the number of records, and the records adjacent to the ROWID can be fuzzy matched to the same data page, so as to avoid repeated preheating of the same data page. The result of this fuzzy matching is different from the actual distribution of the data pages recorded in the target database, and it can only have a certain accuracy, so the filling factor F is introduced, and the accuracy of the fuzzy matching can be compensated by adjusting the filling factor F.

[0125] Step 224: Search the preloading history for the last time the data page was preloaded using the virtual data page number. If no corresponding historical time exists, enter the data page preloading step. If a corresponding historical time is found, enter the historical time determination step.

[0126] Step 225: Historical time judgment step: judge whether the difference between the historical time and the current time is greater than the set time difference T. If so, enter the data page preloading step. If not, update the preloading time of the data page to the current time and do not enter the data page preloading step.

[0127] Step 226: Data page preloading step: Use the ROWID of the target database as the query condition, execute the query in the target database, so as to load the data page corresponding to the ROWID into the database cache, and then store the virtual data page number corresponding to the ROWID of the target database into the preloading history, and update the preloading time to the current time.

[0128] The other steps of this embodiment 3 are consistent with step 100 and step 300 in embodiment 1, and are not described again here.

[0129] The main scheme for preloading data pages in this embodiment is to use the sequentially increasing characteristics of the ROWID of the target database, obtain a virtual data page number through the ROWID and the minimum number of records N, and then use this virtual data page number to filter out repeated preloading operations of the same data page, thereby reducing the pressure caused by the preloading operation module to the target database. Due to the uncertainty of the number of records on a single data page, the length of each record on the data page may be different, which will cause some pages to have more records and some pages to have fewer records. In addition, the deletion of records will cause the ROWID distribution of records on the data page to be not completely continuous. These factors will affect the accuracy of calculating the virtual data page number. Therefore, the concept of data page fill factor is added when calculating the virtual data page number through ROWID. If it is increased, there is a greater probability to avoid preloading the same page multiple times, but at the same time, the probability of missing the loading of the data page will also increase; on the contrary, if it is reduced, the probability of missing the loading of the data page can be reduced, but at the same time, the probability of the same data page being preloaded multiple times will increase. When setting it specifically, this factor can be adjusted as needed to find a balance point.

[0130] This embodiment uses fuzzy matching to obtain the virtual data page number involved in the ROWID of the target database, and then determines the time difference between the two loads from the preloading history. When the time difference is less than the set value, the operation of accessing the same data page only needs to be preheated once. This can greatly reduce the access pressure of the preloading operation on the target database, and realize the data page preheating function with the minimum access cost.

[0131] Regarding the above solution of this embodiment 3, this embodiment is described in more detail below through a specific application scenario.

[0132] In this application scenario, the time difference T between two preloads is set to 60 seconds, the data page size P is 4096 bytes, the maximum record length R of the table is 2010 bytes, and the fill factor is 1. The minimum number of records in the T1 table is calculated by the formula N = (4096 / 2010)*1, and N is 2.

[0133] The source database table T1 (OBJ INT, DATA VARCHAR(2000)) contains 3 rows of data. Its data is distributed in the database as follows:

[0134] ROWID OBJ Column DATA column 11 1 2000 1-character 12 2 2000 2 characters 13 3 2000 3-character

[0135] For the above table T1, the preheating and synchronization process is as follows:

[0136] 1. First, copy the data of table T1 to the target database for initial synchronization and build a ROWID relationship mapping table.

[0137] First, query the data of table T1 from the source database, and then insert it into the target database by returning ROWID. By executing the insert statement INSERT INTO T1 VALUES(:1,:2)RETURN ROWID INTO:2, you can get the ROWID of the source table row in the target database. The virtual data page number uses the formula: PAGENO = (ROWID-1) / N, so as to construct the ROWID relationship mapping table as follows:

[0138] Source ROWID Destination ROWID Data page number 11 1 0 12 2 0 13 3 1

[0139] 2. Enable data synchronization for table T1.

[0140] 3. Insert a new row of data into the T1 table of the source database and commit it, generating transaction TRX1: INSERT INTO T1VALUES (4, 2000 4-character values), whose ROWID on the source side is 14.

[0141] 4. The source-side log parsing module captures the operations of transaction TRX1 and sends them to the target-side data synchronization service.

[0142] 5. The target-side data synchronization service receives the T1 table INSERT operation of transaction TRX1 and determines that its operation type is INSERT, so there is no need to preload the data page.

[0143] 6. The target-side data synchronization service receives the commit operation of transaction TRX1 and starts executing the transaction. It obtains the ROWID: 4 of the row record in the target-side database by executing the statement: INSERT INTO T1 VALUES (4, 2000 4-character values) RETURN ROWID INTO: 1.

[0144] 7. Since the synchronization is an INSERT operation, the ROWID mapping relationship of the row data in the source database and the target database needs to be saved in the ROWID relationship mapping table, resulting in the following relationship:

[0145] Source ROWID Destination ROWID Data page number 11 1 0 12 2 0 13 3 1 14 4 1

[0146] From the above INSERT operation synchronization process, we can see that the ROWID relationship mapping table of the T1 table changes with the scale of the T1 table in the source database. The ROWID relationship mapping table always saves the mapping relationship of the ROWID of the T1 table in the source database and the target database. The ROWID value in the target database can be found in the ROWID mapping table through the ROWID value in the log operation.

[0147] 8. Perform UPDATE and DELETE operations on T1 in the source database:

[0148] UPDATE T1 SET DATA=111WHERE ROWID=11;

[0149] UPDATE T1 SET DATA=222WHERE ROWID=12;

[0150] DELETE T1 WHERE ROWID=13;

[0151] COMMIT;

[0152] 9. When the target side receives the UPDATE operation with ROWID 11 on the source side, it finds its ROWID value 1 in the target side database in the ROWID relationship mapping table and extracts its data page number 0.

[0153] 10. According to the data page number (0), the last loading time of the page is searched in the preloading history. Since it is the first loading and there is no history record, the statement: SELECT 1FROM T1 WHERE ROWID=1 is executed in the target database to preload the data page with data page number 0 into the database cache.

[0154] 11. Store the loading record of data page number (0) with the current time in the preloading history.

[0155] 12. When the target side receives the UPDATE operation with ROWID 12 on the source side, it finds its ROWID value 2 in the target side database in the ROWID relationship mapping table and extracts its data page number 0.

[0156] 13. According to the data page number (0), search for the last loading time of the page in the preloading history, and obtain the time difference T between the current time and the last loading time. If T is less than 60 seconds, do not load the page, and update the time of the page in the loading history to the current time.

[0157] In this step, you can see that there are two UPDATE operations on the data page with data page number 0. However, the preloading module only loads the page once, reducing the number of preloading executions and achieving the effect of reducing the pressure on the destination database.

[0158] 14. When the target side receives the DELECT operation with ROWID 13 from the source side, it finds its ROWID value 3 in the target side database in the ROWID relationship mapping table and extracts its data page number 1.

[0159] 15. According to the data page number (1), the last loading time of the page is searched in the preloading history. Since it is the first loading and there is no history record, the statement: SELECT 1FROM T1 WHERE ROWID=3 is executed in the target database to preload the data page with data page number 1 into the database cache.

[0160] 16. Store the loading record of data page number (1) with the current time in the preloading history.

[0161] 17. The target-side data synchronization service receives the commit operation and starts executing the transaction.

[0162] 18. When the transaction executes the DELETE operation, after the DELETE operation is completed, the mapping relationship of the row data is deleted in the ROWID mapping table through the ROWID value 13 of the log operation. Finally, the mapping relationship of the ROWID mapping table of the table is as follows:

[0163] Source ROWID Destination ROWID Data page number 11 1 0 12 2 0 14 4 1

[0164] From the above process, it can be seen that each table to be synchronized needs to maintain the ROWID mapping table and calculate the virtual data page number separately to fuzzily match whether the source record is in the same data page of the target database. When synchronizing table T1, the mapping relationship in the ROWID mapping table can be used to load the data page to be operated on the target database with the fuzzy matching virtual data page number. In addition, by comparing the last loading time in the preloading history, the number of repeated data page loading times can be effectively reduced, thereby reducing the pressure on the target database.

[0165] Embodiment 4:

[0166] Based on the database data synchronization method based on data page preloading provided in the above-mentioned embodiments 1 to 3, the present invention also provides a database data synchronization device based on data page preloading that can be used to implement the above-mentioned method, such as Figure 6 , which is a schematic diagram of the device architecture of an embodiment of the present invention. The database data synchronization device based on data page preloading of this embodiment includes one or more processors 21 and a memory 22. Among them, Figure 6 A processor 21 is taken as an example.

[0167] The processor 21 and the memory 22 may be connected via a bus or other means. Figure 6 The example of connecting through bus is taken in the following.

[0168] The memory 22, as a non-volatile computer-readable storage medium, can be used to store non-volatile software programs, non-volatile computer executable programs and modules, such as the database data synchronization method based on data page preloading in Embodiments 1 to 3. The processor 21 executes various functional applications and data processing of the database data synchronization device based on data page preloading by running the non-volatile software programs, instructions and modules stored in the memory 22, that is, implements the database data synchronization method based on data page preloading in Embodiments 1 to 3.

[0169] The memory 22 may include a high-speed random access memory, and may also include a non-volatile memory, such as at least one disk storage device, a flash memory device, or other non-volatile solid-state storage devices. In some embodiments, the memory 22 may optionally include a memory remotely arranged relative to the processor 21, and these remote memories may be connected to the processor 21 via a network. Examples of the above-mentioned network include, but are not limited to, the Internet, an intranet, a local area network, a mobile communication network, and combinations thereof.

[0170] The program instructions / modules are stored in the memory 22. When executed by one or more processors 21, the database data synchronization method based on data page preloading in the above-mentioned embodiments 1 to 3 is executed. For example, the above-described Figures 1 to 5 The steps shown.

[0171] A person skilled in the art may understand that all or part of the steps in the various methods of the embodiments may be completed by instructing related hardware through a program, and the program may be stored in a computer-readable storage medium, and the storage medium may include: a read-only memory (ROM), a random access memory (RAM), a disk or an optical disk, etc.

[0172] The above description is only a preferred embodiment of the present invention and is not intended to limit the present invention. Any modifications, equivalent substitutions and improvements made within the spirit and principles of the present invention should be included in the protection scope of the present invention.

Claims

1. A database data synchronization method based on data page preloading, characterized in that: include: The target-side data synchronization service creates a ROWID relationship mapping table for each table to be synchronized to record the mapping relationship between the source-side data and the ROWID in the target-side database. The target-side data synchronization service determines the type of operation received from the source side, and determines the historical time of the last preload based on the ROWID information to determine whether to preload; specifically, the target-side data synchronization service determines the type of operation after receiving the operation sent by the source side. If it is an UPDATE or DELETE operation, the ROWID of the operation is extracted, and the ROWID information of the operation in the target-side database is obtained through the ROWID relationship mapping table; the historical time of the last preload of the data page is searched in the preload history through the ROWID information, and if the corresponding historical time is found, the historical time judgment step is entered; if the corresponding historical time is not found, the data page preload step is entered; historical time judgment step: determine whether the difference between the historical time and the current time is greater than the set time difference T, if so, enter the data page preload step, if not, update the preload time of the data page to the current time, and do not enter the data page preload step; data page preload step: preload through the ROWID information, and update the data page preload time to the current time; The ROWID information includes a virtual data page number, and the step of obtaining the virtual data page number specifically includes: obtaining the page size P of the target database data page and the maximum record size R of the table to be synchronized, and by specifying a filling factor F, obtaining the minimum number of rows N of records stored in a single data page: N=(P / R)*F, where F has a value range of [0 to 1]; if the operation is an UPDATE or DELETE operation, extracting the ROWID of the operation, and obtaining the ROWID of the operation in the target database through the ROWID relationship mapping table, subtracting 1 from the ROWID and dividing it by the minimum number of rows N to obtain a virtual data page number PAGENO: PAGENO=(ROWID-1) / N; Execute related operations according to the operation type; specifically, the operations in the transaction are started after receiving the commit operation of the transaction; when executing the operation, if it is an INSERT operation, a mapping relationship is established between the ROWID of the operation at the source end and the ROWID returned after the INSERT operation is executed at the target end, and the mapping relationship is stored in the ROWID relationship mapping table of the table involved in the operation; when executing the operation, if it is a DELETE operation, the ROWID of the operation at the source end is deleted from the ROWID relationship mapping table of the table involved in the operation; and the synchronization of the transaction is completed.

2. The method for synchronizing database data based on data page preloading according to claim 1, characterized in that: The ROWID information includes a file ID number and a page number of a data page.

3. The method for synchronizing database data based on data page preloading according to claim 2, characterized in that: The data page preloading step specifically includes: The ROWID of the target database is used as a query condition, and the query is executed in the target database so that the data page corresponding to the ROWID is loaded into the database cache; The file ID corresponding to the ROWID of the target database and the page number of the data page are combined and stored in the preload history, and the preload time is updated to the current time.

4. The method for synchronizing database data based on data page preloading according to claim 1, characterized in that: The data page preloading step specifically includes: The ROWID of the target database is used as a query condition, and the query is executed in the target database so that the data page corresponding to the ROWID is loaded into the database cache; The virtual data page number corresponding to the ROWID of the target database is stored in the preload history, and the preload time is updated to the current time.

5. The method for synchronizing database data based on data page preloading according to claim 1, characterized in that: In the step of determining the operation type, if the target-side data synchronization service determines that the operation is an INSERT operation, the data page preloading step is not entered.

6. The method for synchronizing database data based on data page preloading according to any one of claims 1 to 5, characterized in that: Also includes deployment steps: The log parsing module of the data synchronization service is deployed in the source database to parse log operations. The data synchronization service is deployed in the target database to receive operations sent by the source data synchronization service and store them in the database.

7. A database data synchronization device based on data page preloading, characterized in that: It includes at least one processor and a memory, the at least one processor and the memory are connected via a data bus, the memory stores instructions that can be executed by the at least one processor, and the instructions, after being executed by the processor, are used to complete the database data synchronization method based on data page preloading as described in any one of claims 1-6.

Citation Information

Patent Citations

  • Database data synchronization method and device based on data page preloading

    CN109977168A

  • Database data synchronization method and device based on data page preloading and rollback

    CN110008284A

  • Page loading method and system based on user permission

    CN113609460A

  • Electronic processing system for electronic document and electronic file

    US20170235757A1

  • Predicting reference frequency / urgency for table pre-loads in large scale data management system using graph community detection

    US20180173755A1