A method for operating a distributed database, a server, and a storage medium.
By distributing the data nodes of the Merkle B+ tree across multiple sub-servers in a distributed database, and having the master server and sub-servers work together, the data transmission pressure during database operations is solved, achieving load sharing and improved processing capacity.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-11-29
- Publication Date
- 2026-03-13
AI Technical Summary
The database operation based on Merkle B+ tree caused excessive data transmission pressure on the server.
A distributed database architecture is adopted, which distributes the data storage of Merkle B+ tree data nodes to multiple sub-servers. Each sub-server stores a certain number of data pages, while the master server only stores index nodes. The master server determines the data nodes and sends the key-value pairs and page numbers to the sub-servers to perform merge and split operations, thereby reducing the data transmission pressure on the master server.
This effectively distributes the data transmission pressure during database operations, reduces the load on the main server, and avoids excessive data transmission pressure on a single sub-server, thereby improving the system's processing capacity.
Smart Images

Figure CN115934713B_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of database technology, and in particular to a method for operating a distributed database, a server, and a storage medium. Background Technology
[0002] Merkle B+ trees are tree structures improved upon B+ trees. They contain two different types of nodes: index nodes and data nodes, each with a corresponding identifier. The index node's child node list stores the minimum key and hash value of its child nodes, while the data node's child node list stores key-value pairs. The data stored in each node is stored on the server's disk as data pages; that is, each node corresponds to a page number, which is the number of the data page where the data is stored.
[0003] Currently, certain operations on Merkle B+ tree-based databases can place significant data transfer pressure on the server. For example, if N key-value pairs are inserted into the database at once, in the worst-case scenario, these N key-value pairs will fall into N data nodes and N-2N index nodes. This means that read and write operations on 2N-3N data pages will result in very high data transfer pressure. Summary of the Invention
[0004] In view of this, embodiments of this application provide a method for operating a distributed database, a server, and a storage medium, which can reduce the data transmission pressure on the server when operating the database.
[0005] The first aspect of this application provides a method for operating a distributed database applied to a master server, including:
[0006] Obtain key-value pairs to be added to the distributed database; wherein the distributed database is based on a Merkle B+ tree, the master server is connected to at least one sub-server, each sub-server stores a set number of data pages, and the data pages are used to store the data nodes of the Merkle B+ tree;
[0007] Based on the first key of the key-value pair, determine the first data node in the Merkle B+ tree to which the key-value pair needs to be inserted;
[0008] The key-value pair and the first page number corresponding to the first data node are sent to the first sub-server among the at least one sub-servers, so as to instruct the first sub-server to perform key-value pair merging and data node splitting operations on the first data node according to the key-value pair and the first page number, to obtain the data node splitting result, and return the data node splitting result to the master server; wherein, the first page number is the number of the target data page, the target data page stores the data of the first data node, and the first sub-server is the sub-server among the at least one sub-servers that stores the target data page;
[0009] After receiving the data node splitting result, the index node splitting operation of the Merkle B+ tree is performed according to the data node splitting result to complete the operation of adding the key-value pair to the distributed database.
[0010] In this embodiment, a master server and at least one sub-server are configured. Considering that Merkle B+ tree data nodes store large amounts of key-value pairs, while index nodes store only small amounts of index information, the data of the data nodes is distributed among the sub-servers for storage. Each sub-server has a certain number of data pages to store the data of the corresponding data node. When a key-value pair needs to be added to the database, the master server determines the data node to which the key-value pair should be inserted, and then sends the page number and key-value pair corresponding to that data node to the sub-server where the data of that data node resides. Upon receiving the page number and key-value pair, the sub-server performs key-value pair merging and data node splitting operations on that data node, and returns the data node splitting result to the master server. Finally, the master server performs index node splitting operations based on the data node splitting result, thereby completing the operation of adding key-value pairs to the database. This configuration distributes the data transmission pressure of the master server to each sub-server when operating on the database, thereby reducing the data transmission pressure on each server.
[0011] In one implementation of this application, determining the first data node in the Merkle B+ tree to which the key-value pair needs to be inserted based on the first key of the key-value pair may include:
[0012] Based on the first key and the smallest key of each index node in the Merkle B+ tree, the key-value pairs are distributed sequentially from the root node of the Merkle B+ tree until the key-value pairs are distributed to the leaf index nodes of the Merkle B+ tree.
[0013] The first data node is determined from the data nodes of the Merkle B+ tree connected to the leaf index node based on the first key and the minimum key of the leaf index node.
[0014] In one implementation of this application, sending the key-value pair and the first page number corresponding to the first data node to the first sub-server among the at least one sub-server may include:
[0015] Generate a gRPC request carrying the key-value pair and the first page number;
[0016] The gRPC request is sent to the first sub-server.
[0017] In one implementation of this application, the operation method may further include:
[0018] When a data query request for the second key is received, the second data node in the Merkle B+ tree to be queried is determined based on the second key;
[0019] Based on the second page number corresponding to the second data node and the page number range corresponding to the data page stored by each of the sub-servers, determine the second sub-server where the data of the second data node is located from the at least one sub-server;
[0020] Send a key-value query request carrying the second key and the second page number to the second sub-server, instructing the second sub-server to search for the target key value corresponding to the second key in the data page corresponding to the second page number, and return the target key value to the main server.
[0021] A second aspect of this application provides a method for operating a distributed database applied to a first sub-server, including:
[0022] The system receives a first page number and a key-value pair to be added to a distributed database from the master server. The distributed database is based on a Merkle B+ tree. The master server is connected to at least one sub-server. Each sub-server stores a set number of data pages. These data pages store data of data nodes in the Merkle B+ tree. The first page number is the number of the target data page. The target data page stores data of the first data node. The first sub-server is the sub-server among the at least one sub-servers that stores the target data page. The first data node is determined by the master server based on the first key of the key-value pair, and the key-value pair is the data node in the Merkle B+ tree to which the key-value pair needs to be inserted.
[0023] Based on the key-value pair and the first page number, perform key-value pair merging and data node splitting operations on the first data node to obtain the data node splitting result;
[0024] The data node splitting result is returned to the master server to instruct the master server to perform the Merkle B+ tree index node splitting operation based on the data node splitting result after receiving the data node splitting result, so as to complete the operation of adding the key-value pair to the distributed database.
[0025] In one implementation of this application, the step of performing key-value pair merging and data node splitting operations on the first data node based on the key-value pair and the first page number to obtain the data node splitting result may include:
[0026] The key-value pairs are distributed to the first data node according to the first page number, and a key-value pair merging operation is performed on the first data node;
[0027] If the amount of data in the first data node after the key-value pair merging operation exceeds a set threshold, the first data node will be split into at least two new data nodes, such that the data of each new data node can be written into one data page.
[0028] Each new data node is assigned a corresponding page number, and the data of each new data node is written into the data page corresponding to its respective page number.
[0029] The splitting result of the data nodes is determined based on the key value, hash value, and corresponding page number of each new data node.
[0030] Furthermore, the first sub-server records the minimum available page number, the range of available page numbers, and a list of free page numbers; wherein, the minimum available page number is equal to the maximum page number currently allocated to the data node by the first sub-server plus one, the range of available page numbers represents the range of page numbers corresponding to the data pages stored by the first sub-server, and the list of free page numbers records the free page numbers that the first sub-server can currently allocate to the data node.
[0031] The process of assigning a corresponding page number to each new data node may include:
[0032] Check whether the number of free page numbers recorded in the free page number list is greater than or equal to the number of each new data node;
[0033] If the number of free page numbers recorded in the list of free page numbers is greater than or equal to the number of each new data node, then a free page number is assigned to each new data node.
[0034] If the number of free page numbers recorded in the list of free page numbers is less than the number of each of the new data nodes, then each of the new data nodes is divided into a first data node set and a second data node set; wherein, the number of data nodes contained in the first data node set is equal to the number of free page numbers; a free page number is assigned to each data node contained in the first data node set; for any data node contained in the second data node set, it is detected whether the minimum available page number has exceeded the upper limit of the available page number range; if the minimum available page number has not exceeded the upper limit of the page number range, then the minimum available page number is assigned to the arbitrary data node and the minimum available page number is incremented.
[0035] Furthermore, after detecting whether the minimum available page number has exceeded the upper limit of the available page number range, the process may further include:
[0036] If the minimum available page number exceeds the page number limit, the data of the arbitrary data node is sent to a third sub-server (excluding the first sub-server) among the at least one sub-servers, to instruct the third sub-server to allocate a corresponding page number for the arbitrary data node, and to return the allocated page number to the first sub-server.
[0037] A third aspect of this application provides an operating apparatus for a distributed database applied to a master server, comprising:
[0038] The key-value pair acquisition module is used to acquire key-value pairs to be added to the distributed database; wherein the distributed database is based on a Merkle B+ tree, the master server is connected to at least one sub-server, each sub-server stores a set number of data pages, and the data pages are used to store the data nodes of the Merkle B+ tree;
[0039] The data node determination module is used to determine the first data node in the Merkle B+ tree to which the key-value pair needs to be inserted, based on the first key of the key-value pair.
[0040] A key-value pair sending module is used to send the key-value pair and the first page number corresponding to the first data node to the first sub-server among the at least one sub-servers, so as to instruct the first sub-server to perform key-value pair merging and data node splitting operations on the first data node according to the key-value pair and the first page number, to obtain the data node splitting result, and to return the data node splitting result to the master server; wherein, the first page number is the number of the target data page, the target data page stores the data of the first data node, and the first sub-server is the sub-server among the at least one sub-servers that stores the target data page;
[0041] The index node splitting module is used to perform the index node splitting operation of the Merkle B+ tree according to the data node splitting result after receiving the data node splitting result, so as to complete the operation of adding the key-value pair to the distributed database.
[0042] A fourth aspect of this application provides an operating apparatus for a distributed database applied to a first sub-server, comprising:
[0043] A key-value pair receiving module is used to receive a first page number and a key-value pair to be added to the distributed database sent by the master server; wherein, the distributed database is based on a Merkle B+ tree, the master server is connected to at least one sub-server, each sub-server stores a set number of data pages, the data pages are used to store the data of the data nodes of the Merkle B+ tree, the first page number is the number of the target data page, the target data page stores the data of the first data node, the first sub-server is the sub-server among the at least one sub-server that stores the target data page, the first data node is determined by the master server according to the first key of the key-value pair, and the key-value pair is the data node in the Merkle B+ tree to which the key-value pair is to be inserted;
[0044] The data node splitting module is used to perform key-value pair merging and data node splitting operations on the first data node according to the key-value pair and the first page number, so as to obtain the data node splitting result;
[0045] The split result return module is used to return the data node split result to the master server, so as to instruct the master server to perform the index node split operation of the Merkle B+ tree according to the data node split result after receiving the data node split result, so as to complete the operation of adding the key-value pair to the distributed database.
[0046] A fifth aspect of this application provides a server, including a memory, a processor, and a computer program stored in the memory and executable on the processor. When the processor executes the computer program, it implements the operation method provided in the first aspect of this application, or the operation method provided in the second aspect of this application.
[0047] A sixth aspect of this application provides a computer-readable storage medium storing a computer program that, when executed by a processor, implements the operation method provided in the first aspect of this application, or implements the operation method provided in the second aspect of this application.
[0048] A seventh aspect of this application provides a computer program product that, when run on a server, causes the server to execute the operation method provided in the first aspect of this application, or to execute the operation method provided in the second aspect of this application.
[0049] It is understood that the beneficial effects of the second to seventh aspects mentioned above can be found in the relevant descriptions in the first aspect mentioned above, and will not be repeated here. Attached Figure Description
[0050] Figure 1 This is a schematic diagram of a Merkel B+ tree provided in an embodiment of this application;
[0051] Figure 2 This is a schematic diagram of the structure of a server system provided in an embodiment of this application;
[0052] Figure 3 This is a schematic diagram illustrating the setting of the page number range corresponding to the sharding server provided in an embodiment of this application;
[0053] Figure 4 This is a flowchart illustrating an operation method for a distributed database provided in an embodiment of this application;
[0054] Figure 5 This is a schematic diagram illustrating the operation of adding key-value pairs to a distributed database, as provided in an embodiment of this application.
[0055] Figure 6 This is a schematic diagram of an initial state Merkle B+ tree provided in an embodiment of this application;
[0056] Figure 7 This application provides an embodiment of the method for... Figure 6 A schematic diagram illustrating the key-value pair distribution and merging operations performed on a Merkle B+ tree;
[0057] Figure 8 This application provides an embodiment of the method for... Figure 7 A schematic diagram of a Merkle B+ tree performing a node splitting operation;
[0058] Figure 9 This is a schematic diagram illustrating a data rollback operation on a database provided in an embodiment of this application;
[0059] Figure 10 This is a schematic diagram of the structure of an operating device for a distributed database applied to a master server, provided in an embodiment of this application;
[0060] Figure 11 This is a schematic diagram of the structure of an operating device for a distributed database applied to a first sub-server, provided in an embodiment of this application.
[0061] Figure 12 This is a schematic diagram of a server provided in an embodiment of this application. Detailed Implementation
[0062] In the following description, specific details such as particular system architectures and techniques are set forth for illustrative purposes and not for limitation, in order to provide a thorough understanding of the embodiments of this application. However, those skilled in the art will understand that this application can also be implemented in other embodiments without these specific details. In other instances, detailed descriptions of well-known systems, apparatuses, circuits, and methods have been omitted so as not to obscure the description of this application with unnecessary detail. Furthermore, in the description of this application and the appended claims, the terms "first," "second," "third," etc., are used only for distinguishing descriptions and should not be construed as indicating or implying relative importance.
[0063] Merkle B+ trees are based on B+ trees and consist of data nodes at the bottom level and index nodes at each subsequent level. The highest-level index node is called the root node, and the lowest-level (leaf level) index nodes are called leaf index nodes. Each node in a Merkle B+ tree (including data nodes and index nodes) has an ID. The child node list of index nodes stores the minimum key and hash value of each child node, while the child node list of data nodes stores state data key-value pairs [key, value]. The hash value of each node can be calculated from the hash value of the sum of the hash values of its child nodes.
[0064] like Figure 1 The image shown is a schematic diagram of a Merkel B+ tree provided in an embodiment of this application. Figure 1 In this database, nodes n1, n2, and n3 are index nodes, and nodes n4, n5, and n6 are data nodes. Data is stored in the data nodes as key-value pairs. Each node (including data nodes and index nodes) is stored on the server's disk as data pages. To better accommodate disk read / write strategies, the size of each data page can be specified as 4KB (disk page size is typically 4KB). This allows data from a specific node to be read from the disk by calculating the offset of the page number (page ID) multiplied by the page size (4KB). The data stored on the disk includes the index file (i.e., the data of the index nodes) and the data file (i.e., the data of the data nodes).
[0065] by Figure 1For example, when performing a data query, if we need to query for the key 'c', we start from node n1 (the root node), compare the minimum key of the two child nodes with 'c', and find that 'c' falls within the range of the first child node of n1. Therefore, we find node n2. We continue this process until we reach a data node, and finally find data node n5. Then we can query the position of 'c' and its corresponding key value.
[0066] Regarding page number management, the server can set a maximum page ID and a list of free page numbers. When a Merkle B+ tree-based database creates or updates a node (including index nodes and data nodes), it is equivalent to creating a new node, at which point a page ID needs to be assigned to the new node. First, the server checks the free page number list to see if there are any free page numbers (i.e., page numbers not assigned to nodes). If so, it retrieves them and assigns them to the new node; otherwise, it assigns the maximum page ID to the new node and increments that maximum page ID. Page ID allocation naturally involves page ID reclamation. When node A splits into node B and node C, node A's page ID is reclaimed and added to the free page number list. Additionally, when a node is found to become an empty node, its page ID is also reclaimed and added to the free page number list.
[0067] Currently, data queries or key-value pair additions in Merkle B+ tree-based databases typically involve reading and writing data across a large number of nodes, placing significant data transmission pressure on the server. Therefore, this application provides a distributed database operation method that reduces the data transmission pressure on the server when operating on the database. For more specific technical implementation details of this application's embodiments, please refer to the various examples described below.
[0068] Please see Figure 2 This is a schematic diagram of the structure of a server system provided in an embodiment of this application.
[0069] exist Figure 2 The database consists of a master server and N (N≥1) sub-servers, which can interact with each other. Considering that data nodes in a Merkle B+ tree store large amounts of key-value pairs, while index nodes store only small amounts of index information, this embodiment primarily fragments the data files of the data nodes. That is, the data of the data nodes is stored across the N sub-servers, while the master server only stores the data of the index nodes. This setup distributes most of the data transmission load from the master server to the sub-servers during database operations, reducing the data transmission load on the master server while preventing excessive data transmission load on any single sub-server.
[0070] The aforementioned sub-servers can also be called shard servers. Each shard server has a specified storage capacity, used to divide the range of page numbers for storing data pages. These data pages are used to store the data nodes of the Merkle B+ tree. For example... Figure 3 As shown, each shard server can be configured to store 100 data pages (i.e., storage capacity = 100, which can be set as needed). The master server needs to store various index files (such as the maximum page ID and free page number list of the index files) and related shard server information (such as the IP address, port number, and page number range of the stored data pages). Each shard server needs to store corresponding data files (containing the maximum page ID and free page number list of the data files). Figure 3 In this configuration, the 100 data pages stored on shard server 1 have page numbers ranging from 0 to 99, the 100 data pages stored on shard server 2 have page numbers ranging from 100 to 199, and the 100 data pages stored on shard server 3 have page numbers ranging from 200 to 299. There are no data pages with duplicate page numbers. It should be noted that... Figure 3 This is just one example provided in the embodiments of this application. In actual operation, more (e.g., more than 4) or fewer (e.g., 1) sharding servers can be set up, and the storage capacity of each sharding server can also be different.
[0071] Please see Figure 4 This application illustrates an operation method for a distributed database provided in an embodiment, including:
[0072] 401. The master server retrieves the key-value pairs to be added to the distributed database;
[0073] The embodiments of this application are based on Figure 2 The server system architecture shown implements a distributed database based on a Merkle B+ tree. When a key-value pair needs to be added to this distributed database, the master server first retrieves the key-value pair to be added. These key-value pairs can be one or multiple, meaning batch insertion of key-value pairs is supported.
[0074] 402. The master server determines the first data node in the Merkle B+ tree to which the key-value pair should be inserted based on the first key of the key-value pair;
[0075] After obtaining the key-value pair to be added, the master server determines the data node (represented by the first data node) in the Merkle B+ tree where the key-value pair should be inserted, based on the key value (represented by the first key). Since the master server stores the index node data of the Merkle B+ tree, it can find the first data node where the key-value pair should be inserted based on the first key and the range of each index node.
[0076] Specifically, determining the first data node in the Merkle B+ tree to which the key-value pair should be inserted based on the first key of the key-value pair may include:
[0077] (1) Based on the first key and the minimum key of each index node in the Merkle B+ tree, distribute the key-value pairs sequentially from the root node of the Merkle B+ tree until the key-value pairs are distributed to the leaf index nodes of the Merkle B+ tree.
[0078] (2) Determine the first data node from the data nodes of the Merkle B+ tree connected to the leaf index node based on the first key and the minimum key of the leaf index node.
[0079] In practice, the key-value pair can be distributed sequentially downwards from the root node of the Merkle B+ tree by comparing the first key with the smallest key of each index node, until it reaches the leaf index node (i.e., the last level index node). Then, based on the first key and the smallest key of the leaf index node, the first data node can be found from the data nodes connected to that leaf index node. For example, in Figure 1 In the example, assuming the key-value pairs have been distributed to the leaf index node n2, the first key is b, and the data nodes connected to the leaf index node n2 are n4 and n5, it can be found that b falls within the range of the first child node of the leaf index node n2 (the smallest key is a, i.e., the key value ≥ a). Therefore, it can be determined that the data node n4 connected to the first child node of the leaf index node n2 is the first data node.
[0080] 403. The master server sends the key-value pair and the first page number corresponding to the first data node to the first sub-server among the at least one sub-servers;
[0081] After determining the first data node, the master server can obtain the page number (represented by the first page number) corresponding to that first data node. Each data node's data is stored in a data page, and each data page has a corresponding number (i.e., page number). Here, the data page storing the data file of the first data node is represented by the target data page, so the first page number is the target data page number. Since the master server stores relevant information for each sub-server, including the page number range of the data pages stored by each sub-server, after obtaining the first page number, the master server can determine which sub-server's data page range the first page number falls within, and thus determine which sub-server stores the data file of the first data node. This determined sub-server is represented by the first sub-server. For example, in... Figure 3If the first page number is 150 (within the page number range of 100-199), then the first sub-server can be identified as shard server 2.
[0082] The master server can send the key-value pairs and the first page number to the remote first child server, which then performs key-value pair merging and data node splitting operations. Specifically, the steps by which the master server sends the key-value pairs and the first page number to the first child server may include:
[0083] (1) Generate a gRPC request carrying the key-value pair and the first page number;
[0084] (2) Send the gRPC request to the first sub-server.
[0085] The master server can package the key-value pair and the first page number into a gRPC request, and then send this gRPC request to the first child server. Using gRPC for data exchange between servers has advantages such as simplicity, high data transmission efficiency, and strong compatibility.
[0086] 404. The first sub-server performs key-value pair merging and data node splitting operations on the first data node based on the key-value pair and the first page number to obtain the data node splitting result;
[0087] After receiving the key-value pair and the first page number from the master server, the first sub-server will perform the corresponding key-value pair merging and data node splitting operations on the first data node to obtain the data node splitting result.
[0088] In one implementation of this application, the step of performing key-value pair merging and data node splitting operations on the first data node based on the key-value pair and the first page number to obtain the data node splitting result may include:
[0089] (1) Distribute the key-value pairs to the first data node according to the first page number, and perform a key-value pair merging operation on the first data node;
[0090] (2) If the amount of data in the first data node after the key-value pair merging operation exceeds the set threshold, the first data node is split into at least two new data nodes, so that the data of each new data node can be written into one data page;
[0091] (3) Assign a corresponding page number to each new data node, and write the data of each new data node into the data page corresponding to its respective page number;
[0092] (4) Determine the data node splitting result based on the key value, hash value and corresponding page number of each new data node.
[0093] For step (1) above, the first sub-server can find the data of the first data node based on the first page number, and then distribute the key-value pair to the first data node. Here, a key-value pair merging operation will be performed, that is, merging the currently inserted key-value pair with the original key-value pair of the first data node.
[0094] For step (2) above, if the first sub-server detects that the data volume of the first data node after the key-value pair merging operation exceeds a set threshold (e.g., a 4K data page), it needs to perform a data node splitting operation. Here, according to the set splitting threshold, the first data node will be split into at least two new data nodes, so that the data of each new data node can be written into a data page. Conversely, if the data volume of the first data node after the key-value pair merging operation does not exceed the set threshold, the first data node does not need to undergo a splitting operation.
[0095] For step (3) above, the first sub-server needs to assign a corresponding page number (i.e., the number of the data page storing the data node) to each new data node, and then write the data of each new data node into the data page corresponding to its respective page number.
[0096] Specifically, the first sub-server can record and store the minimum available page number, the range of available page numbers, and a list of free page numbers. The minimum available page number is equal to the maximum page number currently allocated to data nodes by the first sub-server plus one. The range of available page numbers represents the range of page numbers corresponding to the data pages stored on the first sub-server. The list of free page numbers records the free page numbers currently available to allocate to data nodes by the first sub-server. The minimum available page number here is the same concept as the maximum page ID described in the previous section on page number management; it represents a page number that is larger than all allocated page numbers and is not yet allocated, equivalent to the minimum available page number. For example, assuming the currently allocated page numbers to nodes are 1-60, then 61 is a page number larger than all allocated page numbers and not yet allocated; 61 is also the minimum available page number (61, 62, 63…). The range of available page numbers represents the range of page numbers corresponding to the data pages stored on the first sub-server. For example, assuming the first sub-server is… Figure 3 In the case of shard server 2, the available page number range is 100-199. The free page number list records the free page numbers that the first sub-server can currently allocate to data nodes; here, it records page numbers that have been allocated to nodes but reclaimed. Step (3) may include:
[0097] (3.1) Check whether the number of free page numbers recorded in the list of free page numbers is greater than or equal to the number of each new data node;
[0098] (3.2) If the number of free page numbers recorded in the list of free page numbers is greater than or equal to the number of each new data node, then a free page number shall be assigned to each new data node.
[0099] (3.3) If the number of free page numbers recorded in the list of free page numbers is less than the number of each new data node, then each new data node is divided into a first data node set and a second data node set; wherein the number of data nodes contained in the first data node set is equal to the number of free page numbers; a free page number is assigned to each data node contained in the first data node set; for any data node contained in the second data node set, it is detected whether the minimum available page number has exceeded the upper limit of the available page number range; if the minimum available page number has not exceeded the upper limit of the page number range, then the minimum available page number is assigned to any data node and the minimum available page number is incremented.
[0100] The first sub-server checks if the number of free page numbers recorded in the free page number list is greater than or equal to the number of each new data node. If so, it means there are enough free page numbers in the free page number list, and each new data node can be assigned a free page number from the free page number list. If not, it means there are not enough free page numbers in the free page number list, and these new data nodes can be divided into two parts based on the number of free page numbers: a first data node set and a second data node set. The number of data nodes in the first data node set is equal to the number of free page numbers, so each data node in the first data node set can be assigned a free page number. The data nodes in the second data node set cannot be assigned free page numbers. In this case, for any data node in the second data node set, it is first checked whether the minimum available page number stored by the first sub-server exceeds the upper limit of the available page number range. If it does not exceed the upper limit, the minimum available page number can be assigned to the data node, and then the minimum available page number is incremented. For example, suppose the minimum available page number stored on the first sub-server is 198, and the range of available page numbers is 100-199. For the first data node in the second data node set, since the current minimum available page number of 198 does not exceed the upper limit of the available page number range (199), page number 198 can be assigned to this first data node, and then the minimum available page number is incremented to 199. For the second data node in the second data node set, since the current minimum available page number of 199 also does not exceed the upper limit of the available page number range (199), page number 199 can be assigned to this second data node, and then the minimum available page number is incremented to 200. For the third data node in the second data node set, since the current minimum available page number of 200 exceeds the upper limit of the available page number range (199), the minimum available page number cannot be assigned to the third data node. Furthermore, there are no available free page numbers in the free page number list, so the first sub-server has no way to assign page numbers at this point.
[0101] Furthermore, after detecting whether the minimum available page number has exceeded the upper limit of the available page number range, the process may further include:
[0102] If the minimum available page number exceeds the page number limit, the data of the arbitrary data node is sent to a third sub-server (excluding the first sub-server) among the at least one sub-servers, to instruct the third sub-server to allocate a corresponding page number for the arbitrary data node, and to return the allocated page number to the first sub-server.
[0103] If the first sub-server is unable to allocate a page number, it can send the data for the corresponding data node to another sub-server, referred to here as the third sub-server. For example, in... Figure 3If shard server 2 cannot allocate a page number, it can send the data of the corresponding data node to shard server 3. After receiving the data of the corresponding data node, the third sub-server will attempt to allocate a page number for the data node using the same method as the first sub-server. If a page number is successfully allocated, the third sub-server will return the allocated page number result to the first sub-server. If the third sub-server also cannot allocate a page number, it will continue to send the data of the corresponding data node to another sub-server (such as the fourth sub-server), and so on, until a page number is successfully allocated for the data node. The successfully allocated page number will be returned to the first sub-server in sequence through each sub-server.
[0104] For step (4) above, the first sub-server will integrate the key value, hash value and corresponding page number of each new data node to obtain the corresponding data node splitting result.
[0105] 405. The first sub-server returns the data node splitting result to the main server;
[0106] The first sub-server will reply to the upper layer with the data node splitting results, that is, send them to the master server, and then the master server will perform the corresponding index node splitting operation.
[0107] 406. After receiving the data node splitting result, the master server performs the index node splitting operation of the Merkle B+ tree according to the data node splitting result to complete the operation of adding the key-value pair to the distributed database.
[0108] After receiving the data node splitting result (mainly containing the key, page number, and hash value of the split data node) from the first sub-server, the master server can perform corresponding splitting operations on the index node based on this result. Once the index node splitting is complete, the key-value pairs are added to the distributed database.
[0109] like Figure 5 The diagram shown is a schematic representation of the operation of adding key-value pairs to a distributed database according to an embodiment of this application. Figure 5In the process, firstly, a batch of key-value pairs are inserted into the root node of the Merkle B+ tree. Then, the key-value pairs are distributed according to the range of the index nodes until they are distributed to the index nodes at the last level (leaf level). This operation is performed by the master server. Next, the master server sends the key-value pairs and the page numbers of the corresponding data nodes to the remote corresponding sub-server 1. Sub-server 1 performs key-value pair merging and data node splitting operations. If sub-server 1 encounters a situation where it cannot allocate a page number for the new data node during the data node splitting operation, it can send the data of the new data node to sub-server 2. Sub-server 2 completes the page number allocation operation and returns the obtained page number result to sub-server 1. Sub-server 1 returns the data node splitting result to the master server, which then performs the corresponding index node splitting operation, finally completing the addition of the key-value pairs to the distributed database.
[0110] The following example illustrates the process of adding key-value pairs to a database. Figure 6 The figure shows an initial state of a Merkle B+ tree, which includes a root node [a1, b1, c2], an index node [a1], an index node [b1], an index node [c2], a data node [a1, a2], a data node [b1], and a data node [c2].
[0111] Now we need to go to Figure 6 The Merkle B+ tree shown has three key-value pairs added: [a3], [b2], and [c1]. First, as shown... Figure 7 As shown, the key-value pair distribution and merging operations are performed. Figure 7 In this process, starting from the root node [a1, b1, c2], key-value pairs are distributed sequentially to the nodes below. If the node is an index node, the distribution continues downwards; if it is a data node, a key-value pair merging operation is performed. For example, in... Figure 7 On the far right, the inserted [a3] is merged into data node [a1, a2], the inserted [b2] is merged into data node [b1], and the inserted [c1] is merged into data node [c2].
[0112] After completing the key-value pair distribution and merging operations, the next step is to execute as follows: Figure 8 The node splitting operations shown include data node splitting operations and index node splitting operations. Figure 8 In this process, starting from the bottom-level data nodes, the data is split sequentially upwards. If the data size of a data node exceeds a threshold, the data node is split to ensure that the data of each node can be written into a data page. The new nodes obtained after the split need to be assigned corresponding page numbers (see the previous text for the specific page number allocation method). As you can see, Figure 8The data node [a1, a2, a3] is split into two data nodes [a1, a2] and [a3]. This splitting continues upwards, with the index node [a1] also splitting into [a1, a3], until the root node is reached. The root node is thus split from [a1, b1, c2] into [a1, b1, c1], updating the index. In this embodiment, the key-value pair distribution and index node splitting operations are performed by the master server, while the key-value pair merging and data node splitting operations are performed by the sub-servers, thereby distributing the data transmission pressure generated during the key-value pair addition process.
[0113] In one implementation of this application, the operation method may further include:
[0114] (1) When a data query request for the second key is received, the master server determines the second data node in the Merkle B+ tree to be queried based on the second key;
[0115] (2) The master server determines the second sub-server where the data of the second data node is located from the at least one sub-server based on the second page number corresponding to the second data node and the page number range corresponding to the data page stored by each sub-server.
[0116] (3) The master server sends a key-value query request carrying the second key and the second page number to the second sub-server, instructing the second sub-server to find the target key value corresponding to the second key from the data page corresponding to the second page number, and return the target key value to the master server.
[0117] In the server system architecture of this application embodiment, if it is necessary to query data in a distributed database, the master server will receive a data query request. Assuming the key value to be queried is the key value corresponding to the second key, the master server can determine the data node to be queried based on the second key, denoted here as the second data node. The master server can obtain the page number corresponding to the second data node, denoted here as the second page number. Then, based on the second page number and the page number range corresponding to the data pages stored by each sub-server, it searches for the sub-server where the data of the second data node is located from among the connected sub-servers, denoted here as the second sub-server. Next, the master server will send a key-value query request carrying the second key and the second page number to the second sub-server. After receiving the key-value query request, the second sub-server will search for the target key value corresponding to the second key in the data page corresponding to the second page number and return the target key value to the master server. The master server can then output the target key value to complete the data query operation.
[0118] In terms of multi-version control and data rollback in databases, since Merkle B+ trees are equivalent to storing multiple logical trees on disk, when data needs to be rolled back to a certain version, the tree root only needs to be pointed to the root of a stored tree. If multiple logical trees need to be stored, a list of free page numbers, a list of page numbers to be released, and a maximum page ID need to be set. Assuming the database only supports two versions of data rollback, when transaction 4 is completed, it can only roll back to the state of transaction 3 at most. This is equivalent to the database only having two trees: one for transaction 3 and one for transaction 4. Figure 9 The image shown is a schematic diagram illustrating a data rollback operation on a database. Figure 9 In the process, the initial page numbers of the three nodes corresponding to transaction 1 are 1, 2, and 3, respectively. At this time, the maximum page ID is 4, and both the list of free page numbers and the list of page numbers to be released are empty. After transaction 1 completes, transaction 2 is executed. After transaction 2 updates the key-value pair, the nodes with page numbers 2 and 3 become dirty. The node with page number 2 splits into two nodes. Since both the list of free page numbers and the list of page numbers to be released are empty, page numbers can only be assigned to each node by incrementing the maximum page ID. The assigned page numbers are 4, 5, 6, and 7. At this time, the maximum page ID becomes 8, and the reclaimed page numbers 1-3 will not be released immediately (i.e., they enter the list of free page numbers). Instead of storing the data in a separate table, the page numbers are first placed in the list of page numbers to be released. When transaction 3 starts, since only two versions of data rollback are supported, the page numbers to be released for transaction 1 in the list of page numbers to be released need to be released. At this time, page numbers 1, 2, and 3 are placed in the list of free page numbers. After transaction 3 is updated, node 6 becomes dirty (correspondingly, root node 7 also becomes dirty). At this time, page numbers 1 and 2 can be taken from the list of free page numbers for allocation, and node 6 is placed in the list of page numbers to be released. The final result is: the list of free page numbers stores page number 3, and the list of page numbers to be released stores page numbers 6 and 7 corresponding to transaction 2. At this time, if it is necessary to roll back to transaction 2, since the page number of the root node of transaction 2 is already recorded as page number 7, the list of free page numbers of transaction 2, and the list of page numbers to be released of transaction 2 have been recorded, it is only necessary to point the root node to page number 7, replace the current list of free page numbers with the list of free page numbers corresponding to transaction 2, and replace the current list of page numbers to be released with the list of page numbers to be released of transaction 2. In theory, it can support data rollback for an unlimited number of versions, but the list of pages to be released will be longer. This technology is used to achieve multi-version control and data rollback of the database.
[0119] When multi-version control and data rollback are applied to the server system provided in this application embodiment, since the master server and each sub-server store data files or index files and can record their respective maximum page ID, free page number list, and page number list to be released, during data rollback, the master server only needs to point the tree root to the root of a stored tree and send a data rollback request (containing the transaction ID to be rolled back) to each of the sub-servers. After receiving the data rollback request, each sub-server replaces its current free page number list and page number list to be released with the free page number list and page number list corresponding to the transaction ID to be rolled back.
[0120] Furthermore, the server system provided in this application also supports horizontal scaling of sub-servers, that is, adding connected sub-servers on top of existing sub-servers. In actual operation, it is only necessary to configure the relevant information of the sub-server to be added on the main server, such as IP address, port, and storage page number range.
[0121] In this embodiment, a master server and at least one sub-server are configured. Considering that Merkle B+ tree data nodes store large amounts of key-value pairs, while index nodes store only small amounts of index information, the data of the data nodes is distributed among the sub-servers for storage. Each sub-server has a certain number of data pages to store the data of the corresponding data node. When a key-value pair needs to be added to the database, the master server determines the data node to which the key-value pair should be inserted, and then sends the page number and key-value pair corresponding to that data node to the sub-server where the data of that data node resides. Upon receiving the page number and key-value pair, the sub-server performs key-value pair merging and data node splitting operations on that data node, and returns the data node splitting result to the master server. Finally, the master server performs index node splitting operations based on the data node splitting result, thereby completing the operation of adding key-value pairs to the database. This configuration distributes the data transmission pressure of the master server to each sub-server when operating on the database, thereby reducing the data transmission pressure on each server.
[0122] In summary, this embodiment of the application distributes the data transmission pressure of the master server to each sub-server. By distributing the data of the data nodes relatively evenly to each sub-server, it ensures a relatively uniform data read / write load on each sub-server. When the master server's index nodes are updated, they distribute key-value pairs to lower levels. Since the data nodes are distributed across the sub-servers, the data node splitting operations performed by each sub-server are concurrent, resulting in a high concurrency of update operations for the entire database. Furthermore, the server system provided in this embodiment of the application also supports horizontal scaling, meaning that sub-servers can be easily added.
[0123] It should be understood that the sequence number of each step in the above embodiments does not imply the order of execution. The execution order of each process should be determined by its function and internal logic, and should not constitute any limitation on the implementation process of the embodiments of this application.
[0124] The above mainly describes a method for operating a distributed database. The following section will describe a device for operating a distributed database.
[0125] Please see Figure 10 One embodiment of the operating apparatus for a distributed database applied to a master server in this application includes:
[0126] The key-value pair acquisition module 1001 is used to acquire key-value pairs to be added to the distributed database; wherein the distributed database is based on a Merkle B+ tree, the master server is connected to at least one sub-server, each sub-server stores a set number of data pages, and the data pages are used to store the data nodes of the Merkle B+ tree;
[0127] The data node determination module 1002 is used to determine the first data node in the Merkle B+ tree to which the key-value pair needs to be inserted, based on the first key of the key-value pair.
[0128] The key-value pair sending module 1003 is used to send the key-value pair and the first page number corresponding to the first data node to the first sub-server among the at least one sub-server, so as to instruct the first sub-server to perform key-value pair merging and data node splitting operations on the first data node according to the key-value pair and the first page number, to obtain the data node splitting result, and to return the data node splitting result to the master server; wherein, the first page number is the number of the target data page, the target data page stores the data of the first data node, and the first sub-server is the sub-server among the at least one sub-server that stores the target data page;
[0129] The index node splitting module 1004 is used to perform the index node splitting operation of the Merkle B+ tree according to the data node splitting result after receiving the data node splitting result, so as to complete the operation of adding the key-value pair to the distributed database.
[0130] In one implementation of this application, the data node determination module may include:
[0131] The key-value pair distribution unit is used to distribute the key-value pairs sequentially from the root node of the Merkle B+ tree according to the first key and the smallest key of each index node in the Merkle B+ tree, until the key-value pairs are distributed to the leaf index nodes of the Merkle B+ tree.
[0132] A data node determination unit is configured to determine the first data node from the data nodes of the Merkle B+ tree connected to the leaf index node based on the first key and the minimum key of the leaf index node.
[0133] In one implementation of this application, the key-value pair sending module may include:
[0134] The gRPC request generation unit is used to generate a gRPC request carrying the key-value pair and the first page number;
[0135] The gRPC request sending unit is used to send the gRPC request to the first sub-server.
[0136] In one implementation of this application, the operating device for the distributed database may further include:
[0137] The query request receiving module is used to determine the second data node in the Merkle B+ tree to be queried based on the second key when a data query request for the second key is received.
[0138] The sub-server determination module is used to determine, from the at least one sub-server, the second sub-server where the data of the second data node is located, based on the second page number corresponding to the second data node and the page number range corresponding to the data page stored by each sub-server.
[0139] The query request sending module is used to send a key-value query request carrying the second key and the second page number to the second sub-server, so as to instruct the second sub-server to find the target key value corresponding to the second key from the data page corresponding to the second page number, and return the target key value to the main server.
[0140] Please see Figure 11 One embodiment of the operating apparatus for a distributed database applied to a first sub-server in this application includes:
[0141] The key-value pair receiving module 1101 is used to receive a first page number and a key-value pair to be added to the distributed database sent by the master server; wherein, the distributed database is based on a Merkle B+ tree, the master server is connected to at least one sub-server, each sub-server stores a set number of data pages, the data pages are used to store the data of the data nodes of the Merkle B+ tree, the first page number is the number of the target data page, the target data page stores the data of the first data node, the first sub-server is the sub-server among the at least one sub-server that stores the target data page, the first data node is determined by the master server according to the first key of the key-value pair, and the key-value pair is the data node in the Merkle B+ tree to which it is to be inserted;
[0142] The data node splitting module 1102 is used to perform key-value pair merging and data node splitting operations on the first data node according to the key-value pair and the first page number, so as to obtain the data node splitting result.
[0143] The split result return module 1103 is used to return the data node split result to the master server, so as to instruct the master server to perform the index node split operation of the Merkle B+ tree according to the data node split result after receiving the data node split result, so as to complete the operation of adding the key-value pair to the distributed database.
[0144] In one implementation of this application, the data node splitting module may include:
[0145] The key-value pair merging unit is used to distribute the key-value pairs to the first data node according to the first page number, and to perform a key-value pair merging operation on the first data node;
[0146] The data node splitting unit is used to split the first data node into at least two new data nodes if the amount of data in the first data node after the key-value pair merging operation exceeds a set threshold, so that the data of each new data node can be written into a data page.
[0147] The page number allocation unit is used to allocate a corresponding page number to each new data node and write the data of each new data node into the data page corresponding to its respective page number.
[0148] The splitting result determination unit is used to determine the splitting result of the data node based on the key value, hash value and corresponding page number of each new data node.
[0149] Furthermore, the first sub-server records the minimum available page number, the range of available page numbers, and a list of free page numbers; wherein, the minimum available page number is equal to the maximum page number currently allocated to data nodes by the first sub-server plus one, the range of available page numbers represents the range of page numbers corresponding to the data pages stored by the first sub-server, and the list of free page numbers records the free page numbers currently available for allocation to data nodes by the first sub-server; the page number allocation unit may include:
[0150] The idle page number detection subunit is used to detect whether the number of idle page numbers recorded in the idle page number list is greater than or equal to the number of each new data node;
[0151] The first page number allocation subunit is used to allocate a free page number to each new data node if the number of free page numbers recorded in the free page number list is greater than or equal to the number of each new data node.
[0152] The second page number allocation subunit is configured to, if the number of free page numbers recorded in the free page number list is less than the number of each new data node, divide each new data node into a first data node set and a second data node set; wherein the number of data nodes contained in the first data node set is equal to the number of free page numbers; allocate a free page number to each data node contained in the first data node set; for any data node contained in the second data node set, detect whether the minimum available page number has exceeded the upper limit of the available page number range; if the minimum available page number has not exceeded the upper limit of the page number range, allocate the minimum available page number to the arbitrary data node and increment the minimum available page number.
[0153] Furthermore, the page number allocation unit may also include:
[0154] The third page number allocation subunit is used to send the data of any data node to a third sub-server other than the first sub-server among the at least one sub-servers if the minimum available page number has exceeded the page number upper limit, so as to instruct the third sub-server to allocate a corresponding page number for the arbitrary data node and return the page number allocated for the arbitrary data node to the first sub-server.
[0155] This application also provides a computer-readable storage medium storing a computer program that, when executed by a processor, implements the operation method of the distributed database described in any of the above embodiments.
[0156] This application also provides a computer program product that, when run on a server, causes the server to execute the distributed database operation method described in any of the above embodiments.
[0157] Figure 12 This is a schematic diagram of a server provided in one embodiment of this application. For example... Figure 12 As shown, the server 12 in this embodiment includes a processor 120, a memory 121, and a computer program 122 stored in the memory 121 and executable on the processor 120. When the processor 120 executes the computer program 122, it implements the steps in the embodiments of the various distributed database operation methods described above, for example... Figure 4 Steps 401 to 406 are shown. Alternatively, when the processor 120 executes the computer program 122, it implements the functions of each module / unit in the above-described device embodiments, for example... Figure 10 The functions of modules 1001 to 1004 shown, or Figure 11 The functions of modules 1101 to 1103 are shown.
[0158] The computer program 122 can be divided into one or more modules / units, which are stored in the memory 121 and executed by the processor 120 to complete this application. The one or more modules / units can be a series of computer program instruction segments capable of performing specific functions, which describe the execution process of the computer program 122 in the server 12.
[0159] The processor 120 may be a Central Processing Unit (CPU), or other general-purpose processors, digital signal processors (DSPs), application-specific integrated circuits (ASICs), field-programmable gate arrays (FPGAs), or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, etc. A general-purpose processor may be a microprocessor or any conventional processor.
[0160] The memory 121 can be an internal storage unit of the server 12, such as a hard drive or memory of the server 12. The memory 121 can also be an external storage device of the server 12, such as a plug-in hard drive, Smart Media Card (SMC), Secure Digital (SD) card, or Flash Card equipped on the server 12. Furthermore, the memory 121 can include both internal storage units and external storage devices of the server 12. The memory 121 is used to store the computer program and other programs and data required by the server. The memory 121 can also be used to temporarily store data that has been output or will be output.
[0161] Those skilled in the art will clearly understand that, for the sake of convenience and brevity, the above-described division of functional units and modules is merely an example. In practical applications, the above functions can be assigned to different functional units and modules as needed, that is, the internal structure of the device can be divided into different functional units or modules to complete all or part of the functions described above. The functional units and modules in the embodiments can be integrated into one processing unit, or each unit can exist physically separately, or two or more units can be integrated into one unit. The integrated unit can be implemented in hardware or as a software functional unit. Furthermore, the specific names of the functional units and modules are only for easy differentiation and are not intended to limit the scope of protection of this application. The specific working process of the units and modules in the above system can be referred to the corresponding process in the foregoing method embodiments, and will not be repeated here.
[0162] Those skilled in the art will clearly understand that, for the sake of convenience and brevity, the specific working processes of the systems, devices, and units described above can be referred to the corresponding processes in the foregoing method embodiments, and will not be repeated here.
[0163] In the above embodiments, the descriptions of each embodiment have different focuses. For parts that are not described in detail or recorded in a certain embodiment, please refer to the relevant descriptions of other embodiments.
[0164] Those skilled in the art will recognize that the units and algorithm steps of the various examples described in conjunction with the embodiments disclosed herein can be implemented in electronic hardware, or a combination of computer software and electronic hardware. Whether these functions are implemented in hardware or software depends on the specific application and design constraints of the technical solution. Those skilled in the art can use different methods to implement the described functions for each specific application, but such implementation should not be considered beyond the scope of this application.
[0165] In the embodiments provided in this application, it should be understood that the disclosed apparatus and methods can be implemented in other ways. For example, the system embodiments described above are merely illustrative. For instance, the division of modules or units is only a logical functional division, and in actual implementation, there may be other division methods. For example, multiple units or components may be combined or integrated into another system, or some features may be ignored or not executed. Furthermore, the coupling or direct coupling or communication connection shown or discussed may be an indirect coupling or communication connection between devices or units through some interfaces, and may be electrical, mechanical, or other forms.
[0166] The units described as separate components may or may not be physically separate. The components shown as units may or may not be physical units; that is, they may be located in one place or distributed across multiple network units. Some or all of the units can be selected to achieve the purpose of the embodiments of this application, depending on actual needs.
[0167] Furthermore, the functional units in the various embodiments of this application can be integrated into one processing unit, or each unit can exist physically separately, or two or more units can be integrated into one unit. The integrated unit can be implemented in hardware or as a software functional unit.
[0168] If the integrated unit is implemented as a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on this understanding, all or part of the processes in the methods of the above embodiments can also be implemented by a computer program instructing related hardware. The computer program can be stored in a computer-readable storage medium, and when executed by a processor, it can implement the steps of the various method embodiments described above. The computer program includes computer program code, which can be in the form of source code, object code, executable files, or certain intermediate forms. The computer-readable medium can include: any entity or device capable of carrying the computer program code, recording media, USB flash drives, portable hard drives, magnetic disks, optical disks, computer memory, read-only memory (ROM), random access memory (RAM), electrical carrier signals, telecommunication signals, and software distribution media, etc. It should be noted that the content included in the computer-readable medium can be appropriately added or removed according to the requirements of legislation and patent practice in the jurisdiction. For example, in some jurisdictions, according to legislation and patent practice, computer-readable media do not include electrical carrier signals and telecommunication signals.
[0169] The above-described embodiments are only used to illustrate the technical solutions of this application, and are not intended to limit them. Although this application has been described in detail with reference to the foregoing embodiments, those skilled in the art should understand that modifications can still be made to the technical solutions described in the foregoing embodiments, or equivalent substitutions can be made to some of the technical features. Such modifications or substitutions do not cause the essence of the corresponding technical solutions to deviate from the spirit and scope of the technical solutions of the embodiments of this application, and should all be included within the protection scope of this application.
Claims
1. An operating method of a distributed database, applied to a master server, characterized by, The operation method comprises: Obtaining a key-value pair to be added to a distributed database; wherein the distributed database is based on a Merkle B+ tree, the master server is connected with at least one sub-server, each of the sub-servers stores a set number of data pages, and the data pages are used to store data of data nodes of the Merkle B+ tree; According to the first key of the key-value pair, determining a first data node in the Merkle B+ tree required to be inserted by the key-value pair; Sending the key-value pair and a first page number corresponding to the first data node to a first sub-server in the at least one sub-server, to instruct the first sub-server to perform key-value pair merging and data node splitting operations on the first data node according to the key-value pair and the first page number, obtain a data node splitting result, and return the data node splitting result to the master server; wherein the first page number is the number of a target data page, the target data page stores data of the first data node, and the first sub-server is a sub-server in the at least one sub-server that stores the target data page; After receiving the data node splitting result, performing an index node splitting operation of the Merkle B+ tree according to the data node splitting result, to complete the operation of adding the key-value pair to the distributed database.
2. The operating method of claim 1, wherein, The operation method comprises: According to the first key and the minimum key of each index node in the Merkle B+ tree, distributing the key-value pair from the root node of the Merkle B+ tree downwards in turn until the key-value pair is distributed to a leaf index node of the Merkle B+ tree; According to the first key and the minimum key of the leaf index node, determining the first data node from a data node of the Merkle B+ tree connected with the leaf index node. 3.The operating method of claim 1, wherein The operation method comprises: Generating a gRPC request carrying the key-value pair and the first page number; Sending the gRPC request to the first sub-server.
4. The method of operation according to any one of claims 1 to 3, wherein, Further comprising: When receiving a data query request for a second key, determining a second data node in the Merkle B+ tree required to be queried according to the second key; According to the second page number corresponding to the second data node and the page number range corresponding to the data pages stored by each of the sub-servers, determining a second sub-server in which data of the second data node is located from the at least one sub-server; Sending a key-value query request carrying the second key and the second page number to the second sub-server, to instruct the second sub-server to find a target key-value corresponding to the second key from a data page corresponding to the second page number, and return the target key-value to the master server.
5. A method for operating a distributed database, applied to a first sub-server, characterized in that, The operation method comprises: Receiving a first page number and a key-value pair to be added to a distributed database sent by a master server, wherein the distributed database is based on a Merkel B+ tree, the master server is connected with at least one sub-server, each of the sub-servers stores a set number of data pages, the data pages are used to store data of data nodes of the Merkel B+ tree, the first page number is a number of a target data page, the target data page stores data of a first data node, the first sub-server is a sub-server of the at least one sub-servers that stores the target data page, and the first data node is determined by the master server according to a first key of the key-value pair, and the key-value pair needs to be inserted into a data node of the Merkel B+ tree; Performing key-value pair merging and data node splitting operations on the first data node according to the key-value pair and the first page number to obtain a data node splitting result; Returning the data node splitting result to the master server, so as to instruct the master server to perform an index node splitting operation of the Merkel B+ tree according to the data node splitting result after receiving the data node splitting result, so as to complete the operation of adding the key-value pair to the distributed database.
6. The operating method of claim 5, wherein, The performing key-value pair merging and data node splitting operations on the first data node according to the key-value pair and the first page number to obtain a data node splitting result comprises: Distributing the key-value pair to the first data node according to the first page number, and performing key-value pair merging operation on the first data node; If the data amount of the first data node after performing the key-value pair merging operation exceeds a set threshold, splitting the first data node into at least two new data nodes, so that the data of each of the new data nodes can be written into one of the data pages; Allocating a corresponding page number to each of the new data nodes, and writing the data of each of the new data nodes into the data page corresponding to the respective page number; Determining the data node splitting result according to the key-value, hash value and corresponding page number of each of the new data nodes.
7. The operating method of claim 6, wherein, The first sub-server records a minimum available page number, an available page number range and a free page number list, wherein the minimum available page number is equal to the maximum page number currently allocated to data nodes by the first sub-server plus one, the available page number range represents a page number range corresponding to the data pages stored by the first sub-server, and the free page number list records free page numbers currently allocable to data nodes by the first sub-server; The allocating a corresponding page number to each of the new data nodes comprises: Detecting whether the number of free page numbers recorded in the free page number list is greater than or equal to the number of the new data nodes; If the number of free page numbers recorded in the free page number list is greater than or equal to the number of the new data nodes, allocating one of the free page numbers to each of the new data nodes. If the number of free page numbers recorded in the free page number list is less than the number of each new data node, each new data node is divided into a first data node set and a second data node set; wherein the first data node set contains the number of data nodes equal to the number of free page numbers; each data node contained in the first data node set is respectively assigned one of the free page numbers; for any data node contained in the second data node set, it is detected whether the minimum available page number has exceeded the upper limit of the page number of the available page number range, if the minimum available page number has not exceeded the upper limit of the page number, the minimum available page number is assigned to the arbitrary data node, and the minimum available page number is incremented.
8. The operating method of claim 7, wherein, After detecting whether the minimum available page number has exceeded the upper limit of the page number of the available page number range, further comprising: If the minimum available page number has exceeded the upper limit of the page number, the data of the arbitrary data node is sent to a third sub-server other than the first sub-server in the at least one sub-server, to instruct the third sub-server to assign a corresponding page number to the arbitrary data node, and return the page number assigned to the arbitrary data node to the first sub-server.
9. A server comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, characterized in that, The processor executes the computer program to implement the operation method of any one of claims 1 to 4, or implement the operation method of any one of claims 5 to 8.
10. A computer-readable storage medium storing a computer program, the computer program comprising instructions that, when executed by a computer, cause the computer to perform the method of any one of claims 1 to 9. The computer program is executed by the processor to implement the operation method of any one of claims 1 to 4, or implement the operation method of any one of claims 5 to 8.
Citation Information
Patent Citations
Distributed real-time database data hierarchical indexing method
CN103020078A
Data storage method and device, computer equipment and storage medium
CN112559529A