A data synchronization method and device, electronic equipment and storage medium
By scanning the data page linked list of the master database and generating cache state information, and synchronizing it to the slave database, the problem of slow cache recovery in MySQL HA was solved, achieving fast response and performance improvement.
Patent Information
- Application Number
- CN202011399280.X
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2020-12-04
- Publication Date
- 2025-10-28
- Estimated Expiration
- 2040-12-04
AI Technical Summary
During MySQL master-slave replication, when the master database experiences high availability (HA), the cache of the slave database becomes inconsistent with that of the master database. This causes the slave database to need to load data from disk into the cache, which takes a long time. As a result, the system cannot respond to user requests quickly, affecting access performance.
By scanning the data page linked list in the cache instance of the primary database, the tablespace identifier and page number set are determined, cache status information is generated, and it is synchronized to the cache of the secondary database, thus achieving accurate and fast recovery of the primary database cache.
It shortens the warm-up time from the database cache pool, ensuring that the system responds quickly to user requests after HA, avoiding performance degradation and improving user experience.
Smart Images

Figure CN114595286B_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of computer technology, and in particular to a data synchronization method, apparatus, electronic device, and storage medium. Background Technology
[0002] Master-slave replication refers to a system where one server acts as the master database server, and one or more other servers act as slave database servers. Data in the master database server is automatically replicated to the slave database servers. MySQL is a relational database management system. MySQL HA (Highly Available) means that to ensure high availability, if the master MySQL database goes down for some reason, read and write traffic to the standby slave database will be switched to the backup slave database, allowing the slave database to continue providing services.
[0003] In related technologies, MySQL master-slave replication is based on the master database recording modification records in a binary log, and the slave database automatically performs updates based on the master database's binary log. The MySQL master database typically accepts read and write access from business processes, while the slave database, while replaying data change operations from the master database through the binary log file, typically accepts read-only access or no access at all. Therefore, the caches of the MySQL master database and the slave database are different. When MySQL experiences high availability (HA), because the slave database's cache differs from the master database's cache, the slave database needs to load the data required for read and write access from its disk into its cache. This process can typically take several hours, causing the system to be unable to respond quickly to user read and write requests, resulting in degraded system performance. Summary of the Invention
[0004] To address the problems of existing technologies, embodiments of this application provide a data synchronization method, apparatus, server, and storage medium. The technical solution is as follows:
[0005] On the one hand, a data synchronization method is provided, the method comprising:
[0006] Scan the linked list of data pages in the cache instance of the main database;
[0007] Based on the tablespace identifier and page number corresponding to each data page in the data page linked list, determine the page number set corresponding to each tablespace identifier;
[0008] Based on the page number set corresponding to each tablespace identifier, determine the target data record range of the tablespace corresponding to each tablespace identifier in the master data file;
[0009] Based on the target data record range of the tablespace corresponding to each tablespace identifier in the master data file, generate the cache status information of the master database;
[0010] Identify the data page to be loaded from the data file that matches the cache status information of the master database, and load the data page to be loaded into the cache of the slave database.
[0011] On the other hand, a data synchronization device is provided, the device comprising:
[0012] The scanning module is used to scan the linked list of data pages in the cache of the database instance corresponding to the main database.
[0013] The first determining module is used to determine the set of page numbers corresponding to each tablespace identifier based on the tablespace identifier and page number corresponding to each data page in the data page linked list;
[0014] The second determining module is used to determine the target data record range of the tablespace corresponding to each tablespace identifier in the master data file based on the page number set corresponding to each tablespace identifier.
[0015] The cache status generation module is used to generate cache status information of the main database based on the target data record range of the tablespace corresponding to each tablespace identifier in the main data file.
[0016] The synchronization module is used to determine the data page to be loaded from the data file that matches the cache status information of the master database, and load the data page to be loaded into the cache of the slave database.
[0017] As one possible implementation, the second determining module includes:
[0018] The third determining module is used to determine the tablespace corresponding to the tablespace identifier in the master data file for each tablespace identifier, wherein multiple data pages in the tablespace form a tree data structure in logical order;
[0019] The page number range determination module is used to determine at least one page number range based on the adjacency relationship of the leaf nodes corresponding to the page numbers in the page number set corresponding to the tablespace identifier in the tree data structure; each page number range is limited by a minimum page number and a maximum page number.
[0020] The fourth determining module is used to determine the first data page corresponding to the smallest page number and the second data page corresponding to the largest page number in each page number range;
[0021] The fifth determining module is used to obtain the data record sub-range corresponding to each page number range based on the first data record with the smallest primary key value in the first data page and the second data record with the largest primary key value in the second data page;
[0022] The sixth determining module is used to obtain the target data record range of the tablespace based on the data record sub-range corresponding to each page number range.
[0023] As one possible implementation, the page number range determination module includes:
[0024] The structure creation module is used to create a structure that represents a page number range, the structure including a minimum page number variable and a maximum page number variable;
[0025] The selection module is used to select a first page number from the page number set corresponding to the tablespace identifier. If a first leaf node corresponding to the first page number exists in the tree data structure, the first page number is assigned to the minimum page number variable and the maximum page number variable respectively.
[0026] The deletion module is used to delete the first page number from the page number set;
[0027] The recursive search module is used to recursively search the leaf nodes to the left and right of the first leaf node based on the tree data structure. During the recursive search, if the page number corresponding to the adjacent leaf node is in the page number set, the value of the corresponding variable in the structure is updated to the page number corresponding to the adjacent leaf node, and the page number corresponding to the adjacent leaf node is deleted from the page number set. If the page number corresponding to the adjacent leaf node is not in the page number set, the recursive search ends.
[0028] The loop module is used to repeatedly execute the steps of creating the structure and assigning and updating the values of the variables in the structure until the page number set is empty, if the page number set is not empty when the recursive search ends.
[0029] As one possible implementation, the cache state generation module includes:
[0030] The table name determination module is used to determine the table name of the table space corresponding to each table space identifier in the master data file;
[0031] The index name determination module is used to determine the index name corresponding to each data record subrange in the target data record range of each tablespace.
[0032] The generation submodule is used to generate the cache status information of the main database based on the table name of each tablespace, the index name of each data record subrange of each tablespace, and each data record subrange of each tablespace.
[0033] As one possible implementation, the generation submodule includes:
[0034] The query statement parsing module is used to parse the index names of each data record subrange of each tablespace and each data record subrange of each tablespace into query statements, so as to obtain the query statement set corresponding to each tablespace.
[0035] The seventh determination module is used to obtain the cache status information of the main database based on the table name of each tablespace and the query statement set corresponding to each tablespace.
[0036] As one possible implementation, the device further includes:
[0037] A connection establishment module is used to establish a connection with the master database through the transmission thread of the slave database;
[0038] The request sending module is used to send a cache status information retrieval request from the slave database to the master database via the slave database's transmission thread;
[0039] The cache status information sending module is used to send the cache status information of the main database to the slave database when the cache status information of the main database meets the preset conditions.
[0040] As one possible implementation, the synchronization module includes:
[0041] The reading module is used to read the cache status information of the main database to obtain the target data record range of the tablespace;
[0042] The positioning module is used to locate the range of target leaf nodes that match the target data record range in the matching tree data structure of the data file; the matching tree data structure matches the tablespace of the target data record range;
[0043] The module for obtaining the data page to be loaded is used to obtain the data page within the target leaf node range based on the link pointers of each leaf node within the target leaf node range, thereby obtaining the data page to be loaded.
[0044] On the other hand, an electronic device is provided, including a processor and a memory, wherein the memory stores at least one instruction or at least one program, the at least one instruction or the at least one program being loaded and executed by the processor to implement the above-described data synchronization method.
[0045] On the other hand, a computer-readable storage medium is provided, wherein at least one instruction or at least one program is stored therein, the at least one instruction or the at least one program being loaded and executed by a processor to implement the data synchronization method as described above.
[0046] On the other hand, a computer program product or computer program is provided, which includes computer instructions stored in a computer-readable storage medium. A processor of a computer device reads the computer instructions from the computer-readable storage medium and executes the computer instructions, causing the computer device to perform the data synchronization methods provided in the various optional implementations described above.
[0047] This embodiment of the application scans the data page linked list in the cache instance of the primary database, determines the page number set corresponding to each tablespace identifier based on the tablespace identifier and page number corresponding to each data page in the linked list, and determines the target data record range of the tablespace corresponding to each tablespace identifier in the primary data file based on the page number set corresponding to each tablespace identifier. Based on the target data record range of the tablespace, the cache status information of the primary database is generated, and then the data page to be loaded that matches the cache status information of the primary database in the data file is determined and loaded into the cache of the secondary database. This allows for accurate, fast, and proactive recovery of cached data from the primary database from the secondary database, avoiding the lengthy process of passively warming up the secondary database cache pool with primary database business traffic. This ensures a rapid response to user read and write requests after HA occurs, avoids a decrease in system access performance, and greatly improves the user experience after MySQL HA occurs. Attached Figure Description
[0048] To more clearly illustrate the technical solutions in the embodiments of this application, the accompanying drawings used in the description of the embodiments will be briefly introduced below. Obviously, the accompanying drawings described below are only some embodiments of this application. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.
[0049] Figure 1 This is a schematic diagram of an implementation environment provided in an embodiment of this application;
[0050] Figure 2 This is a flowchart illustrating a data synchronization method provided in an embodiment of this application;
[0051] Figure 3 This is a schematic diagram of an optional process for determining the target data record range of each tablespace identifier in the master data file, provided in an embodiment of this application.
[0052] Figure 4 This is a schematic diagram of an optional process for determining at least one page number range based on the adjacency relationship of the leaf nodes corresponding to the page numbers in the page number set corresponding to the tablespace identifier in a tree data structure, provided by an embodiment of this application.
[0053] Figure 5This is an example of cached state information stored in the ib_bp_info file local to the main database provided in this application embodiment;
[0054] Figure 6 This is a flowchart illustrating another data synchronization method provided in an embodiment of this application;
[0055] Figure 7 This is a schematic diagram of an optional process for determining a data page to be loaded from a data file that matches the cached state information of the main database, provided in an embodiment of this application.
[0056] Figure 8 This is a structural block diagram of a data synchronization device provided in an embodiment of this application;
[0057] Figure 9 This is a hardware structure block diagram of an electronic device provided in an embodiment of this application. Detailed Implementation
[0058] The technical solutions of the embodiments of this application will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of this application, and not all embodiments. Based on the embodiments of this application, all other embodiments obtained by those of ordinary skill in the art without creative effort are within the scope of protection of this application.
[0059] It should be noted that the terms "first," "second," etc., in the specification, claims, and accompanying drawings of this application are used to distinguish similar objects and are not necessarily used to describe a specific order or sequence. It should be understood that such data can be interchanged where appropriate so that the embodiments of this application described herein can be implemented in orders other than those illustrated or described herein. Furthermore, the terms "comprising" and "having," and any variations thereof, are intended to cover non-exclusive inclusion; for example, a process, method, system, product, or server that comprises a series of steps or units is not necessarily limited to those steps or units explicitly listed, but may include other steps or units not explicitly listed or inherent to such processes, methods, products, or devices.
[0060] Please see Figure 1 The diagram illustrates an implementation environment provided in this application embodiment. This implementation environment may include a master database 110 and a slave database 120. The master database 110 is used to accept read and write access from services, and the slave database 120 serves as a backup of the master database, used to continue providing the services provided by the master database when the master database fails.
[0061] In one possible implementation, both the master database 110 and the slave database 120 can be node devices in a blockchain system, capable of sharing acquired and generated information with other node devices in the blockchain system, thus achieving information sharing among multiple node devices. Multiple node devices in the blockchain system can be configured with the same blockchain, which consists of multiple blocks, and adjacent blocks are related, ensuring that any data tampering in any block can be detected by the next block, thereby preventing data tampering in the blockchain and guaranteeing the security and reliability of the data in the blockchain.
[0062] A "database" is a collection of data stored together in a certain way, shared by multiple users, with minimal redundancy, and independent of application programs. A Database Management System (DBMS) is a computer software system designed to manage databases, generally possessing basic functions such as storage, retrieval, security, and backup. DBMSs can be classified according to the database model they support, such as relational or XML (Extensible Markup Language); or according to the type of computer they support, such as server clusters or mobile phones; or according to the query language used, such as SQL (Structured Query Language) or XQuery; or according to performance priorities, such as maximum scale or maximum operating speed; or other classification methods. Regardless of the classification method used, some DBMSs can cross categories, for example, simultaneously supporting multiple query languages.
[0063] In this embodiment, both the master database 110 and the slave database 120 can be MySQL, a relational database management system. The master database 110 and the slave database 120 can be independent physical servers, server clusters or distributed systems composed of multiple physical servers, or cloud servers providing basic cloud computing services such as cloud services, cloud databases, cloud computing, cloud functions, cloud storage, network services, cloud communication, middleware services, domain name services, security services, CDN, and big data and artificial intelligence platforms.
[0064] The following section introduces several related concepts involved in the embodiments of this application.
[0065] A B+ tree is a tree-like data structure, a variation of the B-tree. Leaf nodes in a B+ tree store primary key values and corresponding data records, while the levels above the leaf nodes serve as indexes. The key characteristic of a B+ tree is its ability to maintain stable and ordered data. Its insertion and modification operations have a relatively stable logarithmic time complexity, making it commonly used in databases and file systems of operating systems.
[0066] InnoDB is one of the database engines in MySQL and is currently the default storage engine for MySQL. Different InnoDB data files correspond to different tablespaces, distinguished by a SpaceID. A tablespace corresponds to a portion of external storage, and different tablespaces correspond to different storage spaces. A tablespace is a logical storage concept; the data in a tablespace is actually stored in the corresponding storage space, and reading or writing data to each tablespace is equivalent to reading or writing data to the corresponding storage space on external storage for that tablespace.
[0067] InnoDB data files consist of multiple B+ trees. All data is stored at the leaf node level of the B+ trees, and adjacent leaf nodes are connected by a doubly linked list. Each B+ tree is composed of data pages, with each node corresponding to a page. Each page has a unique page number (PageNumber). A data page in an InnoDB data file can be uniquely identified using SpaceID + PageNumber.
[0068] The Buffer Pool (BP) is a data page cache pool provided by the InnoDB storage engine. When querying or updating data, operations need to be performed on the InnoDB data pages in the BP cache pool. If the data page being accessed is already in the BP cache pool, the operation can be performed directly on that data page. If the data page being accessed is not in the BP cache pool, the data page needs to be read from the InnoDB data file (stored on the corresponding external disk) and then the data operation can be performed.
[0069] The content stored in the cache pool (BP) is affected by the instance's usage scenario; the content stored in the BP varies depending on the traffic flow. The BP is implemented using multiple cache instances, each consisting of a Flush list, an LRU list, and a Free list. The Free list stores unused free pages. InnoDB retrieves pages from the Free list when needed. If the Free list is empty (no free pages), pages are reclaimed from the LRU and Flush lists by evicting old pages and flushing dirty pages. The LRU list caches pages newly read from data files and manages them using the LRU (Least Recently Used) strategy. The Free list stores modified, dirty data pages that haven't yet been flushed to disk.
[0070] Buffer pool warmup refers to the process of loading frequently accessed data into the buffer pool.
[0071] In related technologies, when MySQL experiences high availability (HA), because the cache of the slave database is different from that of the master database, the slave database needs to load the data required for read and write access from its disk into its cache. The slave database usually needs several hours to complete the cache pool warm-up. During this period, the system cannot respond to users' read and write requests quickly, and users will clearly experience a decrease in system access performance.
[0072] To shorten the warm-up time of the database cache pool after MySQL HA occurs and reduce the impact of HA on system access performance, this application provides a data synchronization method. This method can synchronize the cache of the master database to the cache of the slave database, thereby accurately, quickly, and proactively restoring the cached data of the master database from the slave database. This avoids the lengthy process of passively warming up the slave database cache pool with the business traffic of the master database, ensuring a fast response to user read and write requests after HA occurs, avoiding a decrease in system access performance, and greatly improving the user experience after MySQL HA occurs.
[0073] In the process of developing this application, the inventors discovered that MySQL supports a cache pool preheating function to shorten the cache pool preheating time after a cache instance restart. Specifically, when running the `bufferpooldump` command on the cache instance, the tablespace identifiers and page numbers of the data pages in the LRU linked lists of all cache instances in the cache pool are exported to the `ib_buffer_pool` file on the local disk. When the cache pool state needs to be restored, the `bufferpoolload` command is called to load all data pages in the `ib_buffer_pool` file sequentially into the cache pool. The `ib_buffer_pool` file uses SpaceID + PageNumber to describe the position of each data page in the cache pool in the external data file. However, since the data file corresponding to the MySQL master database (hereinafter referred to as the master data file) and the data file corresponding to the slave database (hereinafter referred to as the slave data file) are only the same in content, but completely different in data distribution, that is, the SpaceID and PageNumber of the master data file do not correspond one-to-one with the SpaceID and PageNumber of the slave data file, it is impossible to use the `ib_buffer_pool` file of the master database to preheat the cache pool on the slave database.
[0074] In view of this, please refer to Figure 2 The diagram illustrates a data synchronization method according to an embodiment of this application. This method can be applied to systems including master and slave databases. It should be noted that this specification provides the operational steps of the method described in the embodiments or flowcharts, but more or fewer operational steps may be included based on conventional or non-inventive methods. The order of steps listed in the embodiments is merely one possible execution order among many and does not represent the only execution order. In actual system or product execution, the method can be executed sequentially or in parallel (e.g., in a parallel processor or multi-threaded processing environment) as shown in the embodiments or drawings. Specifically, as... Figure 2 As shown, the method may include:
[0075] Step S201: Scan the data page linked list in the cache instance of the main database.
[0076] The data page list is an LRU list, where each data page corresponds to a tablespace ID and a page number (PageNumber). The scan can be performed in real-time or periodically, with a set scan cycle, such as daily or weekly.
[0077] Step S203: Determine the set of page numbers corresponding to each tablespace identifier based on the tablespace identifier and page number corresponding to each data page in the data page linked list.
[0078] Specifically, during the scanning of the LRU linked list, the tablespace identifier SpaceID and page number PageNumber of each data page in the LRU linked list are obtained. Based on the tablespace identifier SpaceID and page number PageNumber, the page number set corresponding to each tablespace identifier is determined. That is, the page numbers PageNumber are clustered based on the tablespace identifier SpaceID, and page numbers PageNumber corresponding to the same tablespace identifier SpaceID are placed into the same page number set, thereby obtaining the page number set corresponding to each tablespace identifier.
[0079] In practical applications, the tablespace identifier and the corresponding page number set can be stored in key-value pair format. That is, the Space ID is used as the key and the page number set corresponding to the Space ID is used as the value for corresponding storage (key = SpaceID, value = {PageNumber}).
[0080] Step S205: Determine the target data record range of the tablespace corresponding to each tablespace identifier in the master data file based on the page number set corresponding to each tablespace identifier.
[0081] As one possible implementation, for each tablespace identifier, the following can be adopted: Figure 3 The method shown determines the target data record range for each tablespace identifier in the master data file. This method may include:
[0082] S301, for each tablespace identifier, determine the tablespace corresponding to the tablespace identifier in the master data file.
[0083] In this application embodiment, multiple data pages in the tablespace are arranged in a logical order to form a tree data structure, which can be a B+ tree structure.
[0084] S303, determine at least one page number range based on the adjacency relationship between the page numbers in the page number set corresponding to the tablespace identifier and the corresponding leaf nodes in the tree data structure.
[0085] Each page number range is defined by a minimum page number and a maximum page number.
[0086] In a B+ tree structure, nodes at the leaf node level are leaf nodes; intermediate nodes and the root node are not. Data pages are stored at the leaf node level, and adjacent leaf nodes are connected by a doubly linked list. At the leaf node, the data records within a data page are arranged in a singly linked list according to their primary key values, from smallest to largest. The primary key value of the next leaf node is greater than that of the previous leaf node. Each data page also has a minimum record and a maximum record. The minimum record stores the minimum primary key value of the data page, and the maximum record stores the maximum primary key value. These minimum and maximum records are used to identify the boundaries of the data page for easy querying.
[0087] As a possible implementation, when determining at least one page number range based on the adjacency relationship of the leaf nodes corresponding to the page numbers in the page number set corresponding to the tablespace identifier in the tree data structure, the following approach can be adopted: Figure 4 The method shown includes:
[0088] S401, Create a structure to represent the page number range, the structure including a minimum page number variable and a maximum page number variable.
[0089] For example, a structure named range(left_page_no, right_page_no) can be created, where left_page_no is the minimum page number variable and right_page_no is the maximum page number variable.
[0090] S403, select a first page number from the page number set corresponding to the tablespace identifier. If a first leaf node corresponding to the first page number exists in the tree data structure, assign the first page number to the minimum page number variable and the maximum page number variable respectively.
[0091] The first page number can be any page number in the page number set corresponding to the tablespace identifier.
[0092] Specifically, key = Space ID, value = {PageNumber}. For each Space ID's {PageNumber}, randomly select a page number X from {PageNumber} and determine whether there exists a matching leaf node X in the B+ tree structure of the tablespace corresponding to the Space ID. If a leaf node X exists, it indicates that the data page corresponding to page number X is stored on the leaf node X. At this time, page number X can be assigned to left_page_no and right_page_no respectively, that is, left_page_no = page number X, right_page_no = page number X, and steps S405 to S407 are executed. If there is no matching leaf node for page number X in the B+ tree structure, then page number X is deleted from the page number set {PageNumber} of the Space ID, and another page number is randomly selected from the deleted {PageNumber} to repeat this step.
[0093] S405, delete the first page number from the page number set.
[0094] S407, based on the tree data structure, recursively search the leaf nodes to the left and right of the first leaf node respectively. During the recursive search, if the page number corresponding to the adjacent leaf node is in the page number set, then update the value of the corresponding variable in the structure to the page number corresponding to the adjacent leaf node, and delete the page number corresponding to the adjacent leaf node from the page number set. If the page number corresponding to the adjacent leaf node is not in the page number set, then end the recursive search.
[0095] Specifically, we can first perform a left recursive search to the leaf nodes to the left of the first leaf node. After the left recursive search is completed, we can then perform a right recursive search to the leaf nodes to the right of the first leaf node. When the right recursive search is completed, the recursive search corresponding to the first leaf node ends. Alternatively, we can first perform a right recursive search to the leaf nodes to the right of the first leaf node. After the right recursive search is completed, we can then perform a left recursive search to the leaf nodes to the left of the first leaf node. When the left recursive search is completed, the recursive search corresponding to the first leaf node ends.
[0096] The left recursive search process is as follows:
[0097] (1) Determine the leaf node Y that is the left neighbor of the first leaf node. 左 Corresponding page number Y 左 Check if it is in the page number set {PageNumber}. If it is, execute steps (2) to (3). If it is not, end the left recursive search.
[0098] (2) Update the value of left_page_no to the value of the leaf node Y. 左 Corresponding page number Y 左 That is, left_page_no = page number Y 左 At the same time, page number Y 左 Remove from the page number set {PageNumber}.
[0099] (3) Move the leaf node Y 左 The left neighbor leaf node Z 左 As the first leaf node in step (1), repeat step (1) above.
[0100] The right recursive search process is as follows:
[0101] (1) Determine the leaf node Y that is the right neighbor of the first leaf node. 右 Corresponding page number Y 右 If the page number is in the set {PageNumber}, proceed with steps (2) to (3); otherwise, end the right recursive search.
[0102] (2) Update the value of right_page_no to the value of the leaf node Y. 右 Corresponding page number Y 右 That is, right_page_no = page number Y 右 At the same time, page number Y 右 Remove from the page number set {PageNumber}.
[0103] (3) Move the leaf node Y 右 The right neighbor leaf node Z 右 As the first leaf node in step (1), repeat step (1) above.
[0104] S409, when the recursive search ends, determine whether the page number set is empty. If it is not empty, then repeatedly execute the steps of creating the structure and assigning and updating the values of the variables in the structure until the page number set is empty.
[0105] Specifically, at the end of each recursive search, the range(left_page_no, right_page_no) corresponding to that recursive search can be obtained. All range(left_page_no, right_page_no) under this tablespace ID can be stored in key-value pairs, with the tablespace ID as the key and the array of all range(left_page_no, right_page_no) as the value. For example, it can be represented as key = Space ID, value = vector <range>Thus, for each tablespace identifier, at least one page number range (range(left_page_no, right_page_no)) can be determined.
[0106] S305, determine the first data page corresponding to the smallest page number and the second data page corresponding to the largest page number in each page number range.
[0107] Specifically, for each range (left_page_no, right_page_no), the corresponding data page can be read from the corresponding B+ tree based on the left_page_no in the range, and the corresponding data page can be read from the corresponding B+ tree based on the right_page_no in the range, thus obtaining the first data page corresponding to the minimum page number and the second data page corresponding to the maximum page number.
[0108] S307, based on the first data record with the smallest primary key value in the first data page and the second data record with the largest primary key value in the second data page, obtain the data record sub-range corresponding to each page number range.
[0109] That is, the data record subrange corresponding to each page number range is <the first data record with the smallest primary key value in the first data page, and the second data record with the largest primary key value in the second data page>.
[0110] S309, based on the data record sub-range corresponding to each page number range, the target data record range of the tablespace is obtained.
[0111] Specifically, the target data record range for each tablespace includes the sub-ranges of data records corresponding to that tablespace.
[0112] Step S207: Generate cache status information of the main database according to the target data record range of the tablespace corresponding to each tablespace identifier in the main data file.
[0113] The cache status information of the primary database represents the actual cached data pages in the cache instance of the primary database. As one possible implementation, the cache status information of the primary database can be generated by combining the sub-ranges of data records included in the target data record range, specifically including:
[0114] Determine the table name of the corresponding table space in the master data file for each tablespace identifier.
[0115] Determine the index name corresponding to each sub-range of data records within the target data record range of each tablespace. Since each tablespace has many indexes, and each index corresponds to a B+ tree, for each sub-range of data records, it is necessary to record the index name corresponding to that sub-range of data records so that the corresponding B+ tree can be found in the tablespace from the data file later by using that index name.
[0116] Based on the table name, the index name of each data record subrange in each tablespace, and the data record subranges in each tablespace, the cache status information of the main database is generated. Specifically, a mapping relationship can be established between table names, data record subranges, and corresponding index names, and this mapping relationship can be stored in the ib_bp_info file local to the main database, such as... Figure 5 The image shows an example of cached state information stored in the ib_bp_info file on the primary database.
[0117] As another possible implementation, when generating the cache status information of the main database based on the table name of each tablespace, the index name of each data record subrange of each tablespace, and each data record subrange of each tablespace, the index name of each data record subrange of each tablespace and each data record subrange of each tablespace can also be parsed into query statements to obtain the query statement set corresponding to each tablespace; then, based on the table name of each tablespace and the query statement set corresponding to each tablespace, the cache status information of the main database can be obtained. For example, the above query statement can be a structured query statement. Taking a structured query statement as an example, it can be parsed into the following structured query statement: `select index_column from table use(index)where(key between left_value and right_value)`, where `left_value` is the first data record in the data record subrange, and `right_value` is the second data record in the corresponding data record subrange.
[0118] As a possible implementation, before generating the cached state information of the master data, it can be determined whether a preset generation condition is met. If the preset generation condition is met, the cached state information of the master database is generated according to the target data record range of the tablespace corresponding to each tablespace identifier in the master data file. The preset generation condition can be that a preset generation time interval has been reached, meaning that the cached state information of the master database can be generated every preset generation time interval; alternatively, the preset generation condition can be that the amount of change in the cached data in the master database cache reaches a preset change threshold, triggering the generation of the cached state information of the master database when the preset change threshold is reached.
[0119] Step S209: Determine the data page to be loaded from the data file that matches the cache status information of the master database, and load the data page to be loaded into the cache of the slave database.
[0120] In this embodiment, the cache status information of the master database can be transmitted to the slave database, so that the slave database can load the matching data pages from the slave data file into the cache of the slave database according to the cache status information of the master database, thereby realizing the recovery of the master database cache from the slave database cache.
[0121] To improve system efficiency, avoid error risks, and mitigate the security vulnerabilities associated with frequent manual copying, as a possible implementation method, such as... Figure 6 A flowchart illustrating another data synchronization method is provided. Before determining the data page to be loaded from the data file that matches the cached state information of the main database, the method may further include:
[0122] S601 establishes a connection with the main database through the transfer thread from the database.
[0123] Specifically, in addition to slave IO, slave SQL, and slave worker threads, a new transmission thread similar to the slave IO thread, slave transmit, can be created on the database to establish a connection with the master database. This transmission thread, slave transmit, starts when the slave database starts and shuts down when the slave database stops running, thus establishing a connection with the master database. For example, this connection may include, but is not limited to, a TCP connection.
[0124] S603, the transmission thread of the slave database sends a cache status information retrieval request to the master database.
[0125] Specifically, the slave transmit thread is responsible for sending cache status information retrieval requests to the master database. For example, if the master database's cache status information is stored in a local ib_bp_info file, the slave transmit thread can send a retrieval request for the ib_bp_info file to the master database. For instance, the slave transmit thread can periodically send cache status retrieval requests to the master database at preset time intervals. This preset time interval can be set according to actual needs. Generally, the shorter the preset time interval, the more timely the communication between the slave and master databases, thus ensuring that the master database's cache status information is transmitted to the slave database in a timely manner, which is beneficial for achieving high synchronization between the slave database's cache and the master database.
[0126] S605, when the cache status information of the master database meets the preset conditions, the cache status information of the master database is sent to the slave database.
[0127] Specifically, when responding to the aforementioned cache status retrieval request, it can be determined whether the cache status information of the primary database meets a preset condition. If the preset condition is met, the cache status information of the primary database is sent to the secondary database. The preset condition can be that there is currently no cache status information that has not been sent. That is, when there is unsent cache status information, it is sent to the secondary database; if there is no unsent cache status information, a response indicating no updated information can be returned to the secondary database's transmission thread.
[0128] The automatic copying and transmission of the cached state information of the main database by the aforementioned transmission thread replaces the frequent manual copying of this information by the operation and maintenance personnel, thereby improving system efficiency, avoiding the risk of errors, and mitigating the security risks of frequent remote copying.
[0129] For example, after receiving the cache status information from the master database, the slave database can restore the master database cache based on that information. In practical applications, the timing of master database cache restoration on the slave database can vary depending on the application scenario. For instance, in scenarios where the slave database has no read / write traffic and users are sensitive to data access performance after HA, step S209 can be executed each time new cache status information, such as the ib_bp_info file, is sent to the slave database to restore the master database cache on the slave database, thereby achieving real-time replay of the master database cache status. Real-time replay increases slave database IO, thus increasing system costs to some extent. Conversely, in scenarios where the slave database has read / write traffic or is sensitive to system costs, step S209 can be executed after HA occurs to restore the master database cache on the slave database.
[0130] As a possible implementation, step S209 above, when determining the data page to be loaded from the data file that matches the cached state information of the main database, can employ the following methods: Figure 7 The method shown includes the following steps:
[0131] S701, Read the cache status information of the main database to obtain the target data record range of the tablespace.
[0132] S703, in the matching tree data structure of the data file, locate the range of target leaf nodes that match the range of target data records.
[0133] The matching tree data structure is matched with the tablespace of the target data record range.
[0134] S705, based on the link pointers of each leaf node within the target leaf node range, obtain the data page within the target leaf node range, and obtain the data page to be loaded.
[0135] Since the data page to be loaded is determined from the data file based on the target data record range, the impact of different distributions of master and slave data files on the accuracy of determining the data page to be loaded can be effectively resolved, ensuring that the cache of the master database is completely and accurately restored to the cache of the slave database.
[0136] by Figure 5 Taking the cached state information of the main database as an example, based on the table name, a tablespace matching the table name can be found in the data file. Then, for each index name corresponding to the table name, the corresponding B+ tree is found in the data file. In the B+ tree, a binary search is used to locate the first data record (i.e., the value of left_page_no) and the second data record (i.e., the value of right_page_no) in the data record subrange corresponding to the index name to the corresponding leaf nodes of the B+ tree. This yields the leaf node subrange (left leaf page, right leaf page) corresponding to the data record subrange. Thus, the bidirectional pointers between the leaf nodes within the leaf node subrange (left leaf page, right leaf page) can be used to obtain the data pages on each leaf node within the leaf node subrange as the data pages to be loaded.
[0137] As another possible implementation, if the cache state information of the master database is parsed into the aforementioned set of query statements, such as the set of structured query statements, the query statements in the set of query statements, such as the structured query statement SQL statements, can be run directly on the slave database. By running these query statements, the cache state of the master data can be quickly restored from the cache of the slave database.
[0138] As can be seen from the above technical solutions of the embodiments of this application, the embodiments of this application can not only synchronize the cache of the master database to the cache of the slave database, but also perform accurate, fast and proactive recovery of the cache of the master database from the slave database, avoiding the long process of passively warming up the cache of the slave database with the business traffic of the master database, and greatly improving the user experience after MySQL HA.
[0139] Corresponding to the data synchronization methods provided in the above embodiments, this application also provides a data synchronization device. Since the data synchronization device provided in this application corresponds to the data synchronization methods provided in the above embodiments, the implementation methods of the aforementioned data synchronization methods are also applicable to the data synchronization device provided in this embodiment, and will not be described in detail in this embodiment.
[0140] Please see Figure 8 The diagram shown is a structural schematic of a data synchronization device provided in an embodiment of this application. This device 800 has the function of implementing the data synchronization method in the above-described method embodiments. This function can be implemented by hardware or by hardware executing corresponding software. Figure 8 As shown, the device 800 may include:
[0141] The scanning module 810 is used to scan the linked list of data pages in the cache of the database instance corresponding to the main database;
[0142] The first determining module 820 is used to determine the set of page numbers corresponding to each tablespace identifier based on the tablespace identifier and page number corresponding to each data page in the data page chain list.
[0143] The second determining module 830 is used to determine the target data record range of the tablespace corresponding to each tablespace identifier in the master data file based on the page number set corresponding to each tablespace identifier.
[0144] The cache status generation module 840 is used to generate cache status information of the main database based on the target data record range of the tablespace corresponding to each tablespace identifier in the main data file.
[0145] The synchronization module 850 is used to determine the data page to be loaded from the data file that matches the cache status information of the master database, and load the data page to be loaded into the cache of the slave database.
[0146] As one possible implementation, the second determining module 830 may include:
[0147] The third determining module is used to determine the tablespace corresponding to the tablespace identifier in the master data file for each tablespace identifier, wherein multiple data pages in the tablespace form a tree data structure in logical order;
[0148] The page number range determination module is used to determine at least one page number range based on the adjacency relationship of the leaf nodes corresponding to the page numbers in the page number set corresponding to the tablespace identifier in the tree data structure; each page number range is limited by a minimum page number and a maximum page number.
[0149] The fourth determining module is used to determine the first data page corresponding to the smallest page number and the second data page corresponding to the largest page number in each page number range;
[0150] The fifth determining module is used to obtain the data record sub-range corresponding to each page number range based on the first data record with the smallest primary key value in the first data page and the second data record with the largest primary key value in the second data page;
[0151] The sixth determining module is used to obtain the target data record range of the tablespace based on the data record sub-range corresponding to each page number range.
[0152] As one possible implementation, the page range determination module may include:
[0153] The structure creation module is used to create a structure that represents a page number range, the structure including a minimum page number variable and a maximum page number variable;
[0154] The selection module is used to select a first page number from the page number set corresponding to the tablespace identifier. If a first leaf node corresponding to the first page number exists in the tree data structure, the first page number is assigned to the minimum page number variable and the maximum page number variable respectively.
[0155] The deletion module is used to delete the first page number from the page number set;
[0156] The recursive search module is used to recursively search the leaf nodes to the left and right of the first leaf node based on the tree data structure. During the recursive search, if the page number corresponding to the adjacent leaf node is in the page number set, the value of the corresponding variable in the structure is updated to the page number corresponding to the adjacent leaf node, and the page number corresponding to the adjacent leaf node is deleted from the page number set. If the page number corresponding to the adjacent leaf node is not in the page number set, the recursive search ends.
[0157] The loop module is used to repeatedly execute the steps of creating the structure and assigning and updating the values of the variables in the structure until the page number set is empty, if the page number set is not empty when the recursive search ends.
[0158] As one possible implementation, the cache state generation module 840 may include:
[0159] The table name determination module is used to determine the table name of the table space corresponding to each table space identifier in the master data file;
[0160] The index name determination module is used to determine the index name corresponding to each data record subrange in the target data record range of each tablespace.
[0161] The generation submodule is used to generate the cache status information of the main database based on the table name of each tablespace, the index name of each data record subrange of each tablespace, and each data record subrange of each tablespace.
[0162] As one possible implementation, the generation submodule may include:
[0163] The query statement parsing module is used to parse the index names of each data record subrange of each tablespace and each data record subrange of each tablespace into query statements, so as to obtain the query statement set corresponding to each tablespace.
[0164] The seventh determination module is used to obtain the cache status information of the main database based on the table name of each tablespace and the query statement set corresponding to each tablespace.
[0165] As one possible implementation, the device 800 may further include:
[0166] A connection establishment module is used to establish a connection with the master database through the transmission thread of the slave database;
[0167] The request sending module is used to send a cache status information retrieval request from the slave database to the master database via the slave database's transmission thread;
[0168] The cache status information sending module is used to send the cache status information of the main database to the slave database when the cache status information of the main database meets the preset conditions.
[0169] As one possible implementation, the synchronization module 850 may include:
[0170] The reading module is used to read the cache status information of the main database to obtain the target data record range of the tablespace;
[0171] The positioning module is used to locate the range of target leaf nodes that match the target data record range in the matching tree data structure of the data file; the matching tree data structure matches the tablespace of the target data record range;
[0172] The module for obtaining the data page to be loaded is used to obtain the data page within the target leaf node range based on the link pointers of each leaf node within the target leaf node range, thereby obtaining the data page to be loaded.
[0173] It should be noted that the apparatus provided in the above embodiments is only illustrated by the division of the above functional modules when implementing its functions. In actual applications, the above functions can be assigned to different functional modules as needed, that is, the internal structure of the device can be divided into different functional modules to complete all or part of the functions described above. In addition, the apparatus and method embodiments provided in the above embodiments belong to the same concept, and the specific implementation process can be found in the method embodiments, which will not be repeated here.
[0174] The data synchronization device in this application embodiment can accurately, quickly, and proactively restore cached data from the master database from the slave database, avoiding the lengthy process of passively warming up the slave database cache pool with the master database business traffic. This ensures a rapid response of the system to user read and write requests after HA occurs, avoids a decrease in system access performance, and greatly improves the user experience after MySQL HA occurs.
[0175] This application provides an electronic device including a processor and a memory. The memory stores at least one instruction or at least one program segment, which is loaded and executed by the processor to implement the data synchronization method provided in the above method embodiments.
[0176] The memory can be used to store software programs and modules. The processor executes various functional applications and data synchronization by running the software programs and modules stored in the memory. The memory can mainly include a program storage area and a data storage area. The program storage area can store the operating system, application programs required for the functions, etc.; the data storage area can store data created according to the use of the device, etc. In addition, the memory can include high-speed random access memory, and can also include non-volatile memory, such as at least one disk storage device, flash memory device, or other volatile solid-state storage device. Accordingly, the memory can also include a memory controller to provide the processor with access to the memory.
[0177] The methods and embodiments provided in this application can be executed on a computer terminal, server, or similar computing device. Taking running on a server as an example, Figure 9 This is a hardware structure block diagram of a server running a method provided in an embodiment of this application, such as... Figure 9 As shown, the server 900 can vary significantly due to different configurations or performance. It may include one or more central processing units (CPUs) 910 (CPUs 910 may include, but are not limited to, microprocessors such as MCUs or programmable logic devices such as FPGAs), a memory 930 for storing data, and one or more storage media 920 (e.g., one or more mass storage devices) for storing application programs 923 or data 922. The memory 930 and storage media 920 may be temporary or persistent storage. The program stored in the storage media 920 may include one or more modules, each module may include a series of instruction operations on the server. Furthermore, the CPU 910 may be configured to communicate with the storage media 920 and execute the series of instruction operations stored in the storage media 920 on the server 900. Server 900 may also include one or more power supplies 960, one or more wired or wireless network interfaces 950, one or more input / output interfaces 940, and / or one or more operating systems 921, such as Windows Server™, Mac OS X™, Unix™, Linux™, FreeBSD™, etc.
[0178] The input / output interface 940 can be used to receive or send data via a network. Specific examples of the network described above may include a wireless network provided by the communication provider of server 900. In one example, the input / output interface 940 includes a Network Interface Controller (NIC), which can connect to other network devices via a base station to communicate with the Internet. In another example, the input / output interface 940 may be a radio frequency (RF) module for wireless communication with the Internet.
[0179] Those skilled in the art will understand that Figure 9 The structure shown is for illustrative purposes only and does not limit the structure of the aforementioned electronic device. For example, server 900 may also include... Figure 9 The more or fewer components shown, or having the same Figure 9 The different configurations shown.
[0180] Embodiments of this application also provide a computer-readable storage medium that can be disposed in an electronic device to store at least one instruction or at least one program related to implementing a data synchronization method, wherein the at least one instruction or the at least one program is loaded and executed by the processor to implement the data synchronization method provided in the above-described method embodiments.
[0181] Optionally, in this embodiment, the storage medium may include, but is not limited to, various media capable of storing program code, such as USB flash drives, read-only memory (ROM), random access memory (RAM), portable hard drives, magnetic disks, or optical disks.
[0182] This application also provides a computer program product or computer program that includes computer instructions stored in a computer-readable storage medium. A processor of a computer device reads the computer instructions from the computer-readable storage medium and executes the computer instructions, causing the computer device to perform the methods provided in the various optional implementations described above.
[0183] It should be noted that the order of the embodiments described above is merely for descriptive purposes and does not represent the superiority or inferiority of the embodiments. Furthermore, specific embodiments have been described above. Other embodiments are within the scope of the appended claims. In some cases, the actions or steps described in the claims can be performed in a different order than that shown in the embodiments and still achieve the desired result. Additionally, the processes depicted in the drawings do not necessarily require a specific or sequential order to achieve the desired result. In some embodiments, multitasking and parallel processing are also possible or may be advantageous.
[0184] The various embodiments in this specification are described in a progressive manner. Similar or identical parts between embodiments can be referred to mutually. Each embodiment focuses on describing the differences from other embodiments. In particular, the apparatus embodiments are basically similar to the method embodiments, so the description is relatively simple; relevant parts can be referred to the descriptions of the method embodiments.
[0185] Those skilled in the art will understand that all or part of the steps of the above embodiments can be implemented by hardware or by a program instructing related hardware. The program can be stored in a computer-readable storage medium, such as a read-only memory, a disk, or an optical disk.
[0186] The above description is only a preferred embodiment of this application and is not intended to limit this application. Any modifications, equivalent substitutions, improvements, etc., made within the spirit and principles of this application should be included within the protection scope of this application.< / range>
Claims
1. A data synchronization method, characterized in that, The method includes: Scan the linked list of data pages in the cache instance of the main database; Based on the tablespace identifier and page number corresponding to each data page in the data page linked list, determine the page number set corresponding to each tablespace identifier; Based on the page number set corresponding to each tablespace identifier, the target data record range of the tablespace corresponding to each tablespace identifier in the master data file is determined: For each tablespace identifier, the tablespace corresponding to the tablespace identifier in the master data file is determined, and multiple data pages in the tablespace are arranged in a tree data structure according to logical order; based on the adjacency relationship of the leaf nodes corresponding to the page numbers in the page number set corresponding to the tablespace identifier in the tree data structure, at least one page number range is determined; each page number range is limited by a minimum page number and a maximum page number; within each page number range, the first data page corresponding to the minimum page number and the second data page corresponding to the maximum page number are determined; based on the first data record with the smallest primary key value in the first data page and the second data record with the largest primary key value in the second data page, a data record sub-range corresponding to each page number range is obtained; based on the data record sub-range corresponding to each page number range, the target data record range of the tablespace is obtained; Based on the target data record range of the tablespace corresponding to each tablespace identifier in the master data file, generate the cache status information of the master database; Identify the data page to be loaded from the data file that matches the cache status information of the master database, and load the data page to be loaded into the cache of the slave database.
2. The data synchronization method according to claim 1, characterized in that, Determining at least one page number range based on the adjacency relationship of the leaf nodes corresponding to the page numbers in the page number set corresponding to the tablespace identifier in the tree data structure includes: Create a structure to represent the page number range, the structure including a minimum page number variable and a maximum page number variable; Select the first page number from the set of page numbers corresponding to the tablespace identifier. If the first leaf node corresponding to the first page number exists in the tree data structure, assign the first page number to the minimum page number variable and the maximum page number variable respectively. Delete the first page number from the page number set; Based on the tree data structure, a recursive search is performed on the leaf nodes to the left and right of the first leaf node. During the recursive search, if the page number corresponding to the adjacent leaf node is in the page number set, the value of the corresponding variable in the structure is updated to the page number corresponding to the adjacent leaf node, and the page number corresponding to the adjacent leaf node is deleted from the page number set. If the page number corresponding to the adjacent leaf node is not in the page number set, the recursive search ends. When the recursive search ends, if the page number set is not empty, the steps of creating the structure and assigning and updating the values of the variables in the structure are executed repeatedly until the page number set is empty.
3. The data synchronization method according to claim 1, characterized in that, The step of generating the cache status information of the main database based on the target data record range of the tablespace corresponding to each tablespace identifier in the main data file includes: Determine the table name of the table space corresponding to each tablespace identifier in the master data file; Determine the index names corresponding to each sub-range of data records within the target data record range of each tablespace; The cache status information of the main database is generated based on the table name of each tablespace, the index name of each data record subrange of each tablespace, and each data record subrange of each tablespace.
4. The data synchronization method according to claim 3, characterized in that, The step of generating the cache status information of the main database based on the table name of each tablespace, the index name of each data record subrange of each tablespace, and each data record subrange of each tablespace includes: The index names of each data record subrange in each tablespace and each data record subrange in each tablespace are parsed into structured query statements to obtain the query statement set corresponding to each tablespace. The cache status information of the main database is obtained based on the table name of each tablespace and the set of query statements corresponding to each tablespace.
5. The data synchronization method according to claim 1, characterized in that, Before determining the data page to be loaded from the data file that matches the cached state information of the main database, the method further includes: A connection is established between the primary database and the secondary database via the transmission thread of the secondary database; The transmission thread from the slave database sends a request to the master database to retrieve cached status information. When the cache status information of the master database meets the preset conditions, the cache status information of the master database is sent to the slave database.
6. The data synchronization method according to claim 1, characterized in that, The process of determining the data page to be loaded that matches the cache state information of the main database from the data file includes: Read the cache status information of the main database to obtain the target data record range of the tablespace; In the matching tree data structure of the data file, locate the range of target leaf nodes that match the target data record range; the matching tree data structure matches the tablespace of the target data record range; Based on the link pointers of each leaf node within the target leaf node range, obtain the data pages within the target leaf node range to obtain the data pages to be loaded.
7. A data synchronization device, characterized in that, The device includes: The scanning module is used to scan the linked list of data pages in the cache of the database instance corresponding to the main database. The first determining module is used to determine the set of page numbers corresponding to each tablespace identifier based on the tablespace identifier and page number corresponding to each data page in the data page linked list; The second determining module is used to determine the target data record range of the tablespace corresponding to each tablespace identifier in the master data file based on the page number set corresponding to each tablespace identifier. The cache status generation module is used to generate cache status information of the main database based on the target data record range of the tablespace corresponding to each tablespace identifier in the main data file. The synchronization module is used to determine the data page to be loaded that matches the cache status information of the master database in the data file, and load the data page to be loaded into the cache of the slave database; The second determining module includes: The third determining module is used to determine the tablespace corresponding to the tablespace identifier in the master data file for each tablespace identifier, wherein multiple data pages in the tablespace form a tree data structure in logical order; The page number range determination module is used to determine at least one page number range based on the adjacency relationship of the leaf nodes corresponding to the page numbers in the page number set corresponding to the tablespace identifier in the tree data structure; each page number range is limited by a minimum page number and a maximum page number. The fourth determining module is used to determine the first data page corresponding to the smallest page number and the second data page corresponding to the largest page number in each page number range; The fifth determining module is used to obtain the data record sub-range corresponding to each page number range based on the first data record with the smallest primary key value in the first data page and the second data record with the largest primary key value in the second data page; The sixth determining module is used to obtain the target data record range of the tablespace based on the data record sub-range corresponding to each page number range.
8. The data synchronization device according to claim 7, characterized in that, The page number range determination module includes: The structure creation module is used to create a structure that represents a page number range, the structure including a minimum page number variable and a maximum page number variable; The selection module is used to select a first page number from the page number set corresponding to the tablespace identifier. If a first leaf node corresponding to the first page number exists in the tree data structure, the first page number is assigned to the minimum page number variable and the maximum page number variable respectively. The deletion module is used to delete the first page number from the page number set; The recursive search module is used to recursively search the leaf nodes to the left and right of the first leaf node based on the tree data structure. During the recursive search, if the page number corresponding to the adjacent leaf node is in the page number set, the value of the corresponding variable in the structure is updated to the page number corresponding to the adjacent leaf node, and the page number corresponding to the adjacent leaf node is deleted from the page number set. If the page number corresponding to the adjacent leaf node is not in the page number set, the recursive search ends. The loop module is used to repeatedly execute the steps of creating the structure and assigning and updating the values of the variables in the structure until the page number set is empty, if the page number set is not empty when the recursive search ends.
9. The data synchronization device according to claim 7, characterized in that, The cache state generation module includes: The table name determination module is used to determine the table name of the table space corresponding to each table space identifier in the master data file; The index name determination module is used to determine the index name corresponding to each data record subrange in the target data record range of each tablespace. The generation submodule is used to generate the cache status information of the main database based on the table name of each tablespace, the index name of each data record subrange of each tablespace, and each data record subrange of each tablespace.
10. The data synchronization device according to claim 9, characterized in that, The generation submodule includes: The query statement parsing module is used to parse the index names of each data record subrange of each tablespace and each data record subrange of each tablespace into query statements, so as to obtain the query statement set corresponding to each tablespace. The seventh determination module is used to obtain the cache status information of the main database based on the table name of each tablespace and the query statement set corresponding to each tablespace.
11. The data synchronization device according to claim 7, characterized in that, The device further includes: A connection establishment module is used to establish a connection with the master database through the transmission thread of the slave database; The request sending module is used to send a cache status information retrieval request from the slave database to the master database via the slave database's transmission thread; The cache status information sending module is used to send the cache status information of the main database to the slave database when the cache status information of the main database meets the preset conditions.
12. The data synchronization device according to claim 7, characterized in that, The synchronization module includes: The reading module is used to read the cache status information of the main database to obtain the target data record range of the tablespace; The positioning module is used to locate the range of target leaf nodes that match the target data record range in the matching tree data structure of the data file; the matching tree data structure matches the tablespace of the target data record range; The module for obtaining the data page to be loaded is used to obtain the data page within the target leaf node range based on the link pointers of each leaf node within the target leaf node range, thereby obtaining the data page to be loaded.
13. An electronic device, characterized in that, The system includes a processor and a memory, wherein the memory stores at least one instruction or at least one program, the at least one instruction or the at least one program being loaded and executed by the processor to implement the data synchronization method as described in any one of claims 1 to 6.
14. A computer-readable storage medium, characterized in that, The computer-readable storage medium stores at least one instruction or at least one program, which is loaded and executed by a processor to implement the data synchronization method as described in any one of claims 1 to 6.
15. A computer program product, characterized in that, The computer program product includes computer instructions stored in a computer-readable storage medium, and a processor of a computer device reads from and executes the computer instructions to cause the computer device to perform the data synchronization method as described in any one of claims 1 to 6.
Citation Information
Patent Citations
Database synchronization method and device, server, and storage medium
CN109271450A
Data synchronization processing method and apparatus, electronic device and computer storage medium
WO2020238748A1