Model training method, model synchronization method and related devices
By generating fixed-length string groups to train a learning index model, the problem of existing technologies being unable to support variable-length key retrieval is solved, enabling efficient training and fast searching of variable-length key datasets.
Patent Information
- Application Number
- CN202111575313.6
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-12-21
- Publication Date
- 2026-11-27
- Estimated Expiration
- 2041-12-21
AI Technical Summary
Existing distributed learning index models cannot support dataset retrieval with variable-length keys, resulting in low training efficiency.
By obtaining the target index node set from the B-tree index, generating fixed-length string groups, and training a learned index model based on these strings and key numbers, the number of training samples is reduced to improve efficiency.
It enables fast lookup of variable-length keys, improving training efficiency and lookup speed.
Smart Images

Figure CN116303412B_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of computer technology, and in particular to a model training method, a model synchronization method, and related apparatus. Background Technology
[0002] An index is a structure that sorts the values of one or more columns in a database table, allowing for quick access to specific information within the table. Commonly used indexes in distributed systems include B-tree indexes and learned indexes.
[0003] One current training method for a distributed learning index model is roughly as follows: Obtain keys stored using a B-tree index, where each key has a fixed length. Train the model on the keys of all leaf nodes in the B-tree and the logical address corresponding to each key to obtain the learning index model. After inputting a key into the learning index model, the model can output the logical address corresponding to that key.
[0004] In practical applications, many datasets contain keys of varying lengths. The distributed learning index described above does not support variable-length key indexes, therefore it cannot be used to retrieve datasets containing variable-length keys. Summary of the Invention
[0005] In view of this, this application provides a model training method that can train a learned index model based on keys of different lengths in the target index node. This learned index model can quickly find key-value pairs based on variable-length keys.
[0006] The first aspect provides a model training method, which includes: obtaining a set of target index nodes from a B-tree index; generating a first string group based on the keys of all target index nodes in the target index node set; obtaining the index of each key in the target index node set; using the index of each key in the target index node set as the label of the string in the first string group; and training based on the string group and the label of each string to obtain a target-learnable index model. The target index node set includes the keys of multiple target index nodes, where each target index node is the parent node of a leaf node, and the B-tree index includes keys of different lengths. Each string in the first string group has the same length. There is a one-to-one correspondence between the key index, the key of the target index node, and the string.
[0007] In this way, keys of different lengths can be converted into strings of fixed length. After training a target-learning index model based on the fixed-length strings and key numbers, the target-learning index model can determine the correspondence between strings and key numbers. Since the number of target index nodes in a B-tree index is much smaller than the number of leaf nodes, using the strings obtained by converting the keys of the target index nodes for training can reduce the number of training samples and improve training efficiency.
[0008] In one possible implementation, generating the first string group based on the keys of all target index nodes in the target index node set includes: obtaining a common prefix based on the keys of all target index nodes in the target index node set; removing the common prefix from the keys of each target index node to obtain the remaining strings; extracting an identifier string from the beginning of each remaining string; and generating a string group based on all identifier strings. Any two identifier strings are different. Optionally, the length of each string in the string group is the length of the longest identifier string. Removing the common prefix in this way shortens the string length used for training, saving storage space occupied by training data.
[0009] In another possible implementation, the method further includes: obtaining multiple sets of target index nodes from the B-tree index; selecting a pivot key for a sub-model from each set of target index nodes; generating a second string group based on the pivot keys of the multiple sub-models, where each string in the second string group has the same length; obtaining the sub-model index corresponding to each key in the second set of target index nodes; and training based on the second string group and the sub-model index to obtain a learned index root model. The sub-model index is the label of the string in the second string group. This process is repeated to train the learned index root model based on the string group and the sub-model index. This learned index root model can determine the learned index sub-model based on the key, then determine the node index based on the learned index sub-model, and finally find the leaf node based on the node index. Compared to searching layer by layer in the B-tree index, using two layers of learned index models can reduce the number of layers required to find leaf nodes, thereby improving search efficiency.
[0010] In another possible implementation, the method further includes: receiving operation instructions sent by the terminal via an RDMA interface; updating the leaf nodes of the B-tree index according to the operation instructions; obtaining the hub key of the updated leaf nodes when the number of leaf nodes in the B-tree index changes; processing the input hub key using a learned index root model to obtain the target sub-model index; and retraining the sub-model based on the target index node set corresponding to the target sub-model index. The operation instructions are used to insert or delete key-value pairs in the B-tree index. After updating the leaf nodes of the B-tree index according to the operation instructions, the sub-model corresponding to the updated leaf node and the target index node set corresponding to the sub-model can be determined. The sub-model is then retrained based on this target index node set, and the retrained learned index sub-model can correctly find the node index corresponding to the key.
[0011] In another possible implementation, the method further includes: receiving an RDMA write request from the receiving terminal; modifying the leaf nodes of the B-tree index according to the key carried in the RDMA write request; when the modified leaf nodes include a left leaf node and a right leaf node, generating the key of the target index node based on the keys of the left and right leaf nodes. The key of the target index node lies between the maximum key of the left leaf node and the minimum key of the right leaf node. This allows the intermediate keys of the leaf nodes to be obtained, thus providing a method for generating the target index node. Similarly, upper-level nodes can be generated based on the intermediate keys of the index nodes, until the root node is generated.
[0012] In another possible implementation, generating the key of the target index node based on the keys of the left and right leaf nodes includes: obtaining the common prefix of the largest key of the left leaf node and the smallest key of the right leaf node; obtaining the first target character and the second target character; obtaining the third target character in lexicographical order between the first and second target characters; and constructing the key of the target index node based on the common prefix and the third target character. The first target character is the first character in the largest key of the left leaf node that follows the common prefix, and the second target character is the first character in the smallest key of the right leaf node that follows the common prefix. This method generates the shortest intermediate key for the target index node, minimizing storage space usage. Optionally, the key of the target index node can be constructed based on the common prefix and the second target character.
[0013] The second aspect provides a model synchronization method, which includes: receiving a query command or a scan command; when the terminal stores a learned index root model, inputting the target key from the query command or scan command into the learned index root model; determining a first learned index sub-model based on the sub-model sequence number output by the learned index root model; inputting the target key into the first learned index sub-model; determining a first check field corresponding to the target key and a first address corresponding to the target key based on the node sequence number output by the first learned index sub-model; sending a first RDMA read request including the first address to the server; after the server's network card obtains the data corresponding to the first address according to the first RDMA read request, receiving the data corresponding to the first address sent by the server's network card; comparing the first check field with a second check field included in the data; when the first check field and the second check field are different, sending a second RDMA read request including the second address to the server; after the server obtains the second learned index sub-model from the second address according to the second RDMA read request, receiving the second learned index sub-model sent by the server's network card; and updating the first learned index sub-model to the second learned index sub-model. When a query or scan command is received, the terminal's learned index sub-model and the server's learned index sub-model can be synchronized via RDMA commands to ensure index correctness. Furthermore, synchronizing the learned index sub-model via RDMA commands is faster and more efficient than synchronizing via RPC.
[0014] In one possible implementation, the method further includes: when the terminal does not store the learned root index model, sending a third RDMA read request including a third address to the server, and then receiving the learned root index model sent by the server's network card. The third RDMA read request is used to obtain the learned root index model from the server. This allows for the synchronization of the terminal's learned root index model and the server's learned root index model.
[0015] In another possible implementation, the method further includes: when the terminal does not store the learned index sub-model corresponding to the sub-model sequence number, determining the second address based on the storage address of the learned index root model and the sub-model sequence number; sending a fourth RDMA read request including the second address to the server, and then receiving the second learned index sub-model sent by the server's network card. When the terminal does not store the learned index sub-model corresponding to the sub-model sequence number, the terminal's learned index sub-model and the server's learned index sub-model can be synchronized.
[0016] The third aspect provides a model synchronization method, which includes: receiving an RDMA read request sent by a terminal; obtaining data corresponding to a first address according to the first RDMA read request; sending the data corresponding to the first address to the terminal; receiving a second RDMA read request sent by the terminal; obtaining a second learned index sub-model from a second address according to the second RDMA read request; and sending the second learned index sub-model to the terminal. The first RDMA read request includes the first address and is sent when the terminal stores a learned index root model and a first learned index sub-model. The second RDMA read request includes the second address. By implementing this method, when the learned index sub-model of the terminal is inconsistent with the learned index sub-model of the server, the learned index sub-model of the terminal and the learned index sub-model of the server can be synchronized. Moreover, updating the learned index sub-model via RDMA read requests is faster than updating the learned index model via RPC, thus improving synchronization efficiency.
[0017] In one possible implementation, the method further includes: receiving a third RDMA read request from the terminal; obtaining the learned index root model from a third address based on the third RDMA read request; and sending the learned index root model to the terminal. The third RDMA read request includes the third address and is sent when the terminal does not have the learned index root model stored. This provides a method for synchronizing the learned index root model.
[0018] In another possible implementation, the method further includes: receiving a fourth RDMA read request from the terminal; obtaining a second learned index sub-model based on the sequence number and second address of the first learned index sub-model; and sending the second learned index sub-model to the terminal. The fourth RDMA read request includes the second address, and is sent when the terminal does not store the first learned index sub-model. This provides a method for synchronizing the learned index sub-model when the terminal does not have the first learned index sub-model.
[0019] The fourth aspect provides a model training apparatus, wherein the server has the function of implementing the model training method of the first aspect. This function can be implemented by hardware or by hardware executing corresponding software. The hardware or software includes one or more modules corresponding to the above-described function.
[0020] The fifth aspect provides a terminal that has the function of implementing the model synchronization method in the second aspect. This function can be implemented by hardware or by hardware executing corresponding software. The hardware or software includes one or more modules corresponding to the above-described function.
[0021] A sixth aspect provides a server that has the functionality to implement the model synchronization method of the third aspect. This functionality can be implemented in hardware or by executing corresponding software within hardware. The hardware or software includes one or more modules corresponding to the aforementioned functionality.
[0022] A seventh aspect provides a server comprising a processor and a memory, the memory being used to store a program; the processor executing the program is used to implement the model training method of the first aspect or the model synchronization method of the third aspect.
[0023] The eighth aspect provides a terminal including a processor and a memory for storing a program; the processor executes the program to implement the model synchronization method of the second aspect.
[0024] The ninth aspect provides a computer-readable storage medium storing instructions that, when executed on a computer, cause the computer to perform the methods of the above aspects.
[0025] The tenth aspect provides a computer program product containing instructions that, when run on a computer, causes the computer to perform the methods described above.
[0026] The eleventh aspect provides a chip system including at least one processor coupled to a memory for storing computer programs or instructions, and the processor for executing the computer programs or instructions to implement the methods of the above aspects. Attached Figure Description
[0027] Figure 1 This is a schematic diagram illustrating the execution of an RDMA read operation in a distributed system according to an embodiment of this application; Figure 2 This is a schematic diagram illustrating the execution of an RDMA write operation in a distributed system according to an embodiment of this application; Figure 3 This is a schematic diagram of the learning index model, information table, and key-value pair set in the embodiments of this application; Figure 4 This is a schematic diagram of a B-tree index in an embodiment of this application; Figure 5A This is another schematic diagram of a B-tree index in an embodiment of this application; Figure 5B This is a schematic diagram of the B-tree index and the learned index model in the embodiments of this application; Figure 6 This is a flowchart of a model training method in an embodiment of this application; Figure 7 This is another schematic diagram of a B-tree index in an embodiment of this application; Figure 8 This is a flowchart of a sub-model retraining method in an embodiment of this application; Figure 9 This is a signaling interaction diagram of the model synchronization method in the embodiments of this application; Figure 10 This is a structural diagram of a model training device in an embodiment of this application; Figure 11 This is a structural diagram of a terminal in an embodiment of this application; Figure 12 This is a structural diagram of a server in an embodiment of this application; Figure 13 This is another structural diagram of the server in an embodiment of this application; Figure 14 This is another structural diagram of the terminal in an embodiment of this application. Detailed Implementation
[0028] The model training and model synchronization methods described in this application can be applied to distributed systems. Distributed systems include terminals and servers. Terminals can read and write data stored on the server via a remote direct memory access (RDMA) network.
[0029] Figure 1 This is a schematic diagram illustrating data reading via RDMA read operation in an embodiment of this application. (See also...) Figure 1 Terminal 10 includes a processor 101, a memory 102, and a network interface card 103. The memory 102 stores applications, a learning index model, and information tables. Server 20 includes a processor 201, a memory 202, and a network interface card 203. The memory 202 stores a set of key-value pairs.
[0030] Step S11: After the user enters a query command in the application, the processor 101 obtains the query command from the application.
[0031] Step S12: The processor 101 inputs the key included in the query instruction into the learning index model, and the learning index model can determine the node number corresponding to the key.
[0032] Step S13: After obtaining the node number from the learning index model, the processor 101 searches for the leaf node and the corresponding key-value pair address in the information table based on the node number.
[0033] Step S14: Processor 101 receives key-value pair addresses and generates a remote direct memory access read request including key-value pair addresses.
[0034] Step S15: The processor 101 sends a remote direct memory access read request to the network card 103.
[0035] Step S16: Network card 103 sends a remote direct memory access read request to network card 203.
[0036] Step S17: Network card 203 searches for a key-value pair from the key-value pair set based on the key-value pair address of the remote direct memory access read request.
[0037] Step S18: When the key-value pair set includes the key-value pair corresponding to the key-value pair address, the network card 203 obtains the key-value pair from the key-value pair set of the memory 202.
[0038] Step S19: Network card 203 sends the key-value pair to network card 103.
[0039] In step S20, the network card 103 sends the key-value pair to the application.
[0040] In the above query process, using a learned index model to find the address can improve search efficiency. Furthermore, reading data via RDMA read requests does not require passing through the server's processor 201, saving server computing resources. It should be understood that, in addition to query operations, when terminal 10 performs a scan operation, terminal 10 can also send a remote direct memory access read request to server 20.
[0041] Figure 2 This is a schematic diagram of writing data via RDMA write operation in an embodiment of this application. Figure 2 Terminal structure and Figure 1 The terminal structures are the same. Figure 2 server structure and Figure 1 The server architecture is the same. The server's memory 202 stores a set of key-value pairs and a learned index model.
[0042] Step S21: After the user selects an insert instruction in the application, the processor 101 obtains the insert instruction from the application. The insert instruction includes key-value pairs.
[0043] Step S22: The processor 101 generates a remote direct memory access write request based on the above key-value pair and sends the remote direct memory access write request to the network card 103.
[0044] Step S23: Network card 103 sends the remote direct memory access write request to network card 203.
[0045] Step S24: Network card 203 sends a remote direct memory access write request to processor 201.
[0046] Step S25: The processor 201 writes a new key-value pair to the key-value pair set according to the remote direct memory access write request.
[0047] Step S26: The processor 201 obtains a set of target index nodes, including the new target index node, from the set of key-value pairs, and then retrains the model based on the set of target index nodes.
[0048] Because the key-value pairs in the key-value pair set are stored according to a B-tree index relationship, writing a key-value pair can be understood as inserting a leaf node into the B-tree index. During the key-value pair writing process, the leaf nodes of the B-tree index may split, generating new leaf nodes and new target index nodes. This can cause the original learned indexing model to fail to index the new nodes correctly, requiring retraining of the learned indexing model. The target index node is the parent node of the leaf node. If the leaf nodes of the B-tree index do not split during the key-value pair writing process, the original learned indexing model can still index correctly, and model retraining is not required.
[0049] Step S27: The processor 201 sends the retrained model to the memory 202, updating the original learned index model to the retrained model.
[0050] It should be noted that after step 23, network card 203 can also write key-value pairs to the key-value pair set of memory 202 according to remote direct memory access write requests, without needing to be processed by the server processor 201. This can save the computing resources of server 20 and improve the speed of writing data.
[0051] When terminal 10 performs deletion or update, it can also send an RDMA write request to server 20. The RDMA write request is sent from the terminal's network card 103 to the server's network card 203, and the server's network card 203 writes data to the server's memory 202. The server 20's processor 201 does not participate in the data reading and writing process, so the above data reading and writing speed is very fast.
[0052] After writing data, the learned index model stored on the server needs to be updated based on the newly added set of key-value pairs. Furthermore, the terminal also needs to synchronize the learned index model with the server to ensure the accuracy of key-value pair lookups.
[0053] The terminal or server can store learned index models, each corresponding to an information table and a set of key-value pairs. The learned index model, information table, and key-value pair set are as follows: Figure 3 As shown.
[0054] Given a set of key-value pairs, keys can be obtained for training, and a learned indexing model can be trained based on these keys. Learned indexing models can be divided into single-layer learned indexing models or two-layer learned indexing models.
[0055] The training process of a single-layer learning index model is roughly as follows: When all target index nodes are obtained from the B-tree index, a single-layer learning index model can be trained based on the keys of all target index nodes. This single-layer learning index model can directly determine the node number corresponding to the key based on the input key. After finding the key of the leaf node based on the node number, the address corresponding to the leaf node can be determined from the information table.
[0056] The training process of the two-layer learned index model is roughly as follows: The target index nodes of the B-tree index are divided into multiple sets of target index nodes. A learned index sub-model is trained based on the keys of the target index nodes in each set. A learned index root model is trained based on the pivot key of each set of target index nodes. This learned index model includes a learned index root model and a learned index sub-model, and can be considered as a two-layer learned index model. The pivot key of the target index node set is a key selected according to a preset rule, such as the minimum key, the maximum key, or a key with a preset sequence number. The preset sequence number can be set according to the actual situation, and this application does not limit it.
[0057] The following is a brief introduction to the B-tree index of this application. A B-tree index consists of index nodes and leaf nodes. An index node includes the root node, the target index node, and the nodes between the target index node and the root node. The keys of the index nodes do not belong to the key space.
[0058] A B-tree index's leaf nodes contain one or more keys, each key corresponding to a logical address. This logical address indicates the storage space used to store the value corresponding to the key. Leaf nodes can also store verification information used to validate the keys. A B-tree index's index node contains the address of the next-level node and its key.
[0059] When the number of keys in a leaf node reaches its limit, inserting a new key into that leaf node will split the leaf node and the new key into two new leaf nodes. These split leaf nodes consist of a left leaf node and a right leaf node. The key of the target index node can be generated based on the maximum key of the left leaf node and the minimum key of the right leaf node. The target index node is the underlying index node and also the parent node of the leaf nodes.
[0060] Figure 4 This shows a portion of the nodes in the B-tree index. See also... Figure 4In the B-tree index 41, the node subset 42 includes the target index node 421, leaf nodes 422 and 423. Leaf node 422 includes "abc123" and other keys, where "abc123" is the largest key of leaf node 422, and the other keys are not shown. Leaf node 423 includes "abe123" and other keys, where "abe123" is the smallest key of leaf node 423, and the other keys are not shown. "abd" is chosen as the key of leaf node 421 between "abc123" and "abe123". It should be understood that any string between "abc123" and "abe123" can be chosen as the key of leaf node 421.
[0061] In this application, similar to splitting leaf nodes, index nodes at the next higher level can be generated based on the target index node after splitting, until the root node is generated. When a node in a B-tree index contains multiple keys, the keys are arranged in lexicographical order. The nodes at each level of the B-tree index are also arranged in lexicographical order.
[0062] Figure 5A This shows a portion of the nodes in the B-tree index. See also... Figure 5A In another example, the B-tree index includes root node 510, index node 520, index node 521, target index node 530, and target index node 531. Target index node 530 is the parent node of leaf nodes 540 and 541, and target index node 533 is the parent node of leaf nodes 542 and 543.
[0063] Leaf nodes 540 and 541 are obtained by splitting a leaf node by inserting a key. After splitting to obtain leaf nodes 540 and 541, a key is selected from the keys between the largest key of leaf node 540 and the smallest key of leaf node 541 as the key of the target index node 530. The largest key of leaf node 540 is abc12545, and the smallest key of leaf node 541 is abe13579. Either key from (abc12545, abe13579) can be selected as the key of the target index node 530 in lexicographical order. To reduce storage space, this application can select the shortest key from (abc12545, abe13579) as the key of the target index node 530, such as abd or abe.
[0064] Leaf nodes 542 and 543 are obtained by splitting another leaf node by inserting a key. After obtaining leaf nodes 542 and 543, a key is selected from the keys between the largest key of leaf node 542 and the smallest key of leaf node 543 as the key of the target index node 533. The largest key of leaf node 542 is abgx54521, and the smallest key of leaf node 543 is abgz24680. Following lexicographical order, any key from (abgx54521, abgz24680) can be selected as the key of the target index node 533. To reduce storage space, this application can select the shortest key from (abgx54521, abgz24680) as the key of the target index node 533, for example, abgy. It should be understood that... Figure 5A The nodes are not shown in the text. Figure 5A Nodes at the same level are similar.
[0065] based on Figure 5A The keys and key numbers of the target index nodes can be used to train a learned indexing model, such as... Figure 5B As shown.
[0066] To improve search efficiency, a distributed learning index model has been developed to replace B-tree indexes for data retrieval. This model is trained using the keys and key indices of the leaf nodes of the B-tree index, establishing a correspondence between keys and indices. When a terminal executes a query, it can directly determine the key's location based on the key and the learning index model, and then retrieve the value's address according to the key-address correspondence. Compared to searching a B-tree index level by level, the learning index model can directly calculate the key's location, thus improving search efficiency.
[0067] However, existing distributed learning index models use fixed-length keys, allowing the key's location to be directly determined based on its index and length. When the key lengths in memory are inconsistent, this distributed learning index model cannot correctly locate the key based on its index. Therefore, existing distributed learning index models cannot be applied to key-value databases that include variable-length keys. In distributed systems, the number of leaf nodes can be hundreds of thousands or even millions, resulting in a large amount of training data and low training efficiency.
[0068] In response, this application provides a model training method that can train a learned index model for finding variable-length keys.
[0069] See Figure 6 An embodiment of the model training method of this application includes: Step 601: Obtain the target set of index nodes from the B-tree index.
[0070] In this embodiment, the B-tree index includes keys of different lengths. The target index node set may include all or part of the target index nodes in the B-tree index, and the node indices of multiple target index nodes in the target index node set are consecutive. The target index node is the parent node of the leaf node, and each target index node includes at least one key.
[0071] Step 602: Generate a first string group based on the keys of all target index nodes in the target index node set. Each string in the first string group has the same length.
[0072] In an optional embodiment, generating a first string group based on the keys of all target index nodes in the target index node set includes: obtaining a common prefix based on the keys of all target index nodes in the target index node set; removing the common prefix from the keys of each target index node to obtain a remaining string; extracting an identifier string from the beginning of each remaining string, wherein any two identifier strings are different; and generating a string group based on multiple identifier strings, wherein the length of the strings in the string group is the length of the longest identifier string.
[0073] For example, the keys of four target inodes are abd, abfx, abfmnq, and abgy. The common prefix of these four target inodes is the string "ab". After removing the common prefix from the keys, the remaining strings are d, fx, fmnq, and gy. The identifier strings extracted from the beginning of these remaining strings are d, fx, fm, and g. A fixed-length string is generated based on these identifier strings, resulting in the string group d\0, fx, fm, gy. The string constant \0 occupies one byte.
[0074] It should be noted that when the length of the identifier string is less than the fixed length, the identifier string and the supplementary character can be combined to form a string of fixed length. The supplementary character can be a preset character or a character obtained from the remaining string. The preset character can be, but is not limited to, \0.
[0075] Step 603: Obtain the sequence number of each key in the target inode set.
[0076] When retrieving target inodes sequentially from the target inode set, each target inode can be assigned a unique sequence number. Target inodes can include keys, but not the key sequence number.
[0077] Step 604: Use the index of each key in the target index node set as the label of the string in the first string group.
[0078] In this system, the key number, the key of the target index node, and the string correspond one-to-one.
[0079] For example, the indices of abd, abfx, abfmnq, and abgy are 1, 2, 3, and 4 respectively. The correspondence between the key indices and the keys and strings is shown in Table 1.
[0080] Table 1
[0081] Step 605: Train the target learning index model based on the first string group and the label of each string.
[0082] The target learning index model is used to determine the sequence number of the target index node in the target index node set based on the input key. When the target index node set includes all target index nodes of the B-tree index, the target learning index model obtained by executing steps 602 to 605 is a single-level learning index model. This single-level learning index model can query the target index nodes of the entire B-tree index.
[0083] When the target index node set includes some target index nodes from the B-tree index, the target learned index model obtained by executing steps 602 to 605 is a learned index sub-model. This learned index sub-model can query the target index node set. If the accuracy of indexing based on the learned index sub-model is less than the preset accuracy, a greedy algorithm can be used to obtain more target index nodes from the B-tree index and add them to the target index node set. The learned index sub-model is then retrained based on the new target index node set until the accuracy of the learned index sub-model is greater than or equal to the preset accuracy.
[0084] In this embodiment, for B-tree indexes that include variable-length keys, this application can convert the variable-length keys into fixed-length strings, and then train the index based on the fixed-length strings. In this way, the trained learning index model can perform fast lookups in key-value databases that include variable-length keys.
[0085] Secondly, the order of magnitude of the parent nodes of leaf nodes is about two orders of magnitude lower than that of leaf nodes, therefore the number of target index nodes is much smaller than the number of leaf nodes. Compared to training based on the keys of leaf nodes, training based on strings generated from the keys of target index nodes reduces training data and improves training speed.
[0086] To facilitate understanding, the model training method of this application will be introduced below with another example: See Figure 7 The B-tree index stored on the server is as follows Figure 7As shown. The B-tree index includes a root node 701, a target index node 702, a target index node 703, and leaf nodes 704, 705, 706, 707, 708, and 709. The node number of target index node 702 is 1, and the node number of target index node 703 is 2. The node numbers of leaf nodes 704, 705, 706, 707, 708, and 709 are 1, 2, 3, 4, 5, and 6, respectively.
[0087] Leaf node 704 contains keys a1, b3, c4, and d8. Leaf node 705 contains keys f1, f2, and f6. Leaf node 706 contains keys g5, h4, i9, k2, and k3. Leaf node 707 contains keys i3, i4, m7, m8, n2, and n3. Leaf node 708 contains keys o2, o6, o9, and p1. Leaf node 709 contains keys q2, r4, and w5. For any leaf node, each key corresponds to an address. The location of the address can be set according to the actual situation.
[0088] Generate the key of the target index node based on the keys of the adjacent leaf nodes. Select e as the first key of the target index node 702 from the largest key d8 of leaf node 704 and the smallest key f1 of leaf node 705. Select f7 as the second key of the target index node 702 from the largest key f6 of leaf node 705 and the smallest key g5 of leaf node 706. Select n4 as the first key of the target index node 703 from the largest key i3 of leaf node 707 and the smallest key of leaf node 708. Select p2 as the second key of the target index node 703 from the largest key p1 of leaf node 708 and the smallest key q2 of leaf node 709.
[0089] In one example, the correspondence between the key, string, and key index of the target inode is shown in Table 2:
[0090] Table 2
[0091] The learned index model is obtained by training based on the string group and the corresponding index of the string.
[0092] The learning index root model of this application is described below. In an optional embodiment, the above model training method further includes: obtaining multiple target index node sets from the B-tree index; selecting a hub key of a sub-model from each target index node set; generating a second string group based on the hub keys of multiple sub-models; obtaining the sub-model index corresponding to the hub keys of multiple sub-models; and training based on the second string group and the sub-model index to obtain a learning index root model, wherein the sub-model index corresponding to each key is the label of the string in the second string group.
[0093] In this embodiment, each string in the second string group has the same length. The method for converting the keys into strings can be found in the corresponding description in the embodiment shown in Figure 5. The training algorithm can be, but is not limited to, least squares, support vector machine, or neural network algorithms.
[0094] In one example, the hub keys selected from the four target inode sets are abd, abfx, abfmnq, abgy, abd, abfx, abfmnq, and abgy, corresponding to submodel indices 1, 2, 2, and 3, respectively. The correspondence between the submodel indices, the submodel hub keys, and the strings is shown in Table 3.
[0095] Table 3
[0096] After obtaining the learned index root model through training, the learned index root model can find the learned index sub-model corresponding to the input key. The learned index sub-model can find the target index node index number corresponding to the input key, determine the target index node range based on the target index node index number, and search for the address corresponding to the key in the leaf nodes corresponding to the target index node range.
[0097] In one example, the target index nodes of the B-tree index include abc, abd, abgy, etc. The node number of abc is 300, the node number of abd is 350, and the node number of abgy is 400.
[0098] After inputting abe13579 into the learning index sub-model, the learning index sub-model determines the node index to be 300 based on abe13579, and retrieves abc from the target index node with node index 300. Since abc is less than abe13579, the search is performed from the target index nodes with greater than abc. The node index 300 is increased by a step value. Taking the step value as an example, 100 is used to obtain the node index range [300, 400].
[0099] Retrieve abgy from the target index node with node number 400. Since abe13579 is less than abgy, search for the leaf node of the target index node within the node number range [300, 400] until abe13579 is found.
[0100] The step value can be set according to the actual situation, and this application does not limit it. For example, in the example above, when the step value is 50, abd can be obtained from the target index node with node number 350. Since abd is less than abe13579, abe13579 may not be found in the node number interval [300, 350]. Therefore, it is necessary to expand the node number interval [300, 350] to [300, 400] according to the step value. Since abe13579 is less than abgy, it can be determined that abe13579 can definitely be found in [300, 400].
[0101] The method for finding the leaf node of the target index node based on the target index node in the node sequence range can be, but is not limited to, binary search.
[0102] In distributed scenarios, servers receive a large number of access requests, and much of the data in the server's B-tree index is constantly being updated. This necessitates continuous updates to the learned index model to ensure correct lookups. This application can... Figure 6 The model obtained from the illustrated embodiment or optional embodiment is retrained. The retraining method for the model is described below; please refer to [link / reference]. Figure 8 In an optional embodiment, the above method further includes: Step 801: Receive operation instructions sent by the terminal through the remote direct memory access interface.
[0103] In this embodiment, the operation instructions are used to insert or delete key-value pairs in the B-tree index. The operation instructions are encapsulated based on RDMA read instructions and / or RDMA write instructions.
[0104] Step 802: Update the leaf nodes of the B-tree index according to the operation instructions.
[0105] After updating the B-tree index according to the operation instructions, it is determined whether the number of leaf nodes in the B-tree index has changed. If the number of leaf nodes has changed, it means that the parent node of the changed leaf node has also changed, and the learned index sub-model needs to be retrained. If the number of leaf nodes in the B-tree index remains unchanged, it means that the target index node of the B-tree index remains unchanged, and the learned index sub-model does not need to be retrained.
[0106] Step 803: When the number of leaf nodes in the B-tree index changes, obtain the pivot key of the updated leaf node. The pivot key is also called the critical key.
[0107] Step 804: Input the above pivot key into the learning index root model to obtain the target sub-model number.
[0108] Step 805: Retrain the sub-model based on the set of target index nodes corresponding to the target sub-model number.
[0109] In this embodiment, when the operation instruction is an insertion instruction that includes key-value pairs, the key and key-value pair address can be added to the B-tree index. When the added key causes a leaf node to split, a new target index node is generated. At this time, the set of target index nodes corresponding to the learned index sub-model changes, and the index number of the key in each target index node may also change. Therefore, the learned index sub-model needs to be retrained.
[0110] When the operation instruction is a delete instruction that includes a key, the key in the leaf node is deleted according to the delete instruction. When the deleted key causes the leaf nodes to be merged, the corresponding target index node is deleted. At this time, the set of target index nodes corresponding to the learned index sub-model changes, and the index number of the key in each target index node may also change. Therefore, the learned index sub-model needs to be retrained.
[0111] The pivot key of a leaf node refers to a key obtained from the leaf node according to preset rules, such as the maximum key, minimum key, or a key with a specified index. The modified pivot key of the leaf node is input into the learned index root model. The learned index root model can output a target sub-model index. The set of target index nodes corresponding to the target sub-model index number includes the modified target index nodes. Retraining based on this set of target index nodes yields a new learned index sub-model.
[0112] In distributed systems, B-tree indexes often contain a large number of leaves, such as hundreds of thousands or millions. Retraining based on the entire B-tree index requires significant time and computational resources. This application addresses this by retraining only on the changing set of target index nodes, while omitting retraining on the unchanged set. This reduces the need to read training data. Multiple learned index sub-models can be retrained concurrently, accelerating the retraining process and meeting the speed requirements for model training in high-concurrency insertion scenarios.
[0113] In another optional embodiment, the above method further includes: receiving an RDMA write request sent by a terminal; modifying the leaf nodes of the B-tree index according to the key carried in the RDMA write request; when the modified leaf nodes include a left leaf node and a right leaf node, generating a key for a target index node according to the key of the left leaf node and the key of the right leaf node, wherein the key of the target index node is between the maximum key of the left leaf node and the minimum key of the right leaf node.
[0114] In this embodiment, when the terminal receives an insert instruction, it can send an RDMA write request to the server. After the inserted key causes a leaf node to split, the key of the target index node can be generated based on the key of the split leaf node.
[0115] Optionally, generating the key of the target index node based on the keys of the left and right leaf nodes includes: obtaining the common prefix of the largest key of the left leaf node and the smallest key of the right leaf node, the first target character, and the second target character; obtaining the third target character located between the first and second target characters in lexicographical order; and assembling the key of the target index node based on the common prefix and the third target character. The first target character is the first character in the largest key of the left leaf node after the common prefix, and the second target character is the first character in the smallest key of the right leaf node after the common prefix.
[0116] Such target inodes have the shortest key length, saving storage resources used to store the keys of the target nodes. When converting them to fixed-length strings, they occupy less storage space and the conversion speed can be improved.
[0117] It should be noted that, in some embodiments, the key of the target index node can be formed based on the common prefix and the second target character.
[0118] Both the server and the terminal cache the learned index model. In read-intensive scenarios, the distributed learned index model can improve network throughput, reduce access latency, and save server CPU resources. In write-intensive scenarios, after the server updates data, the distributed learned index model needs to be retrained. At this time, the learned index model on the terminal will be inconsistent with the learned index model on the server.
[0119] When the server updates the learned index model, the learned index model cached on the terminal becomes a dirty model. Using this dirty model for queries may result in access errors. To address this issue, this application proposes a model synchronization method that supports dirty reads. This method can determine whether the terminal's learned index model is consistent with the server's learned index model. If they are inconsistent, it can automatically synchronize the terminal's learned index model with the server's. Only after the terminal obtains the retrained learned index model can it correctly read and write data.
[0120] See Figure 9 One embodiment of the model synchronization method in this application includes: Step 901: The terminal receives the target instruction, which is either a query instruction or a scan instruction.
[0121] Step 902: When the terminal stores a learned index root model, the terminal inputs the target key, including the target instruction, into the learned index root model.
[0122] Step 903: The terminal determines the first learning index sub-model based on the sub-model sequence number output by the learning index root model.
[0123] Step 904: The terminal inputs the target key into the first learning index sub-model.
[0124] Step 905: The terminal determines the first verification field and the first address corresponding to the target key based on the node sequence number output by the target learning index sub-model.
[0125] Each leaf node stores a key, address, and checksum field, and the key, address, and checksum field are in a one-to-one correspondence.
[0126] Specifically, the target index node corresponding to the node number is determined. If the target key is less than the key of the target index node, the target key is searched in the leaf nodes to the left of the target index node. If the target key is greater than the target index node, the target key is searched in the leaf nodes to the right of the target index node. For the left and right leaf nodes, if the node number of the left leaf node is n1, then the node numbers of the leaf nodes to the left of the left leaf node are less than or equal to n1. If the node number of the right leaf node is n2, then the node numbers of the leaf nodes to the right of the right leaf node are greater than or equal to n2. n1 and n2 are positive integers.
[0127] Step 906: The terminal sends a first remote direct memory access read request to the server, including the first address.
[0128] Step 907: The server retrieves the data corresponding to the first address based on the first remote direct memory access read request. The data corresponding to the first address includes a second verification field. Specifically, the server's network card retrieves the data corresponding to the first address based on the first remote direct memory access read request. The data corresponding to the first address is the data corresponding to the target key.
[0129] Step 908: The terminal receives the data corresponding to the first address sent by the network card of the server.
[0130] Both the first and second check fields are used to verify the data corresponding to the first address.
[0131] Step 909: The terminal compares the first verification field with the second verification field.
[0132] When the first verification field is the same as the second verification field, it indicates that the data corresponding to the target key in the terminal is the same as the data corresponding to the target key in the server.
[0133] Step 910: When the first verification field is different from the second verification field, the terminal determines the second address based on the storage address of the learning index root model and the sub-model sequence number output by the second learning index root model.
[0134] When the first and second verification fields differ, it indicates that the data corresponding to the target key in the terminal and the data corresponding to the target key in the server are different. The learned sub-index model used to look up the target key in the server is inconsistent with the learned sub-index model used to look up the target key in the terminal. The terminal needs to synchronize the learned index model from the server.
[0135] Each sub-model has a sub-model number and a storage address. The terminal can determine the storage address of the learned index sub-model based on the storage address of the root model and the sub-model number; the second address is the storage address of the second learned index sub-model. Both the first and second learned index sub-models are learned index sub-models corresponding to the target key. Among the learned index sub-models corresponding to the target key, the second learned index sub-model is the most recent.
[0136] Step 911: The terminal sends a second remote direct memory access read request to the server, including the second address.
[0137] The second RDMA read request is used to obtain the second learned index sub-model.
[0138] Step 912: The server obtains the second learned index sub-model based on the second remote direct memory access read request. Specifically, the server's network card obtains the second learned index sub-model based on the second RDMA read request.
[0139] Step 913: The terminal receives the second learning index sub-model sent by the server's network card.
[0140] Step 914: The terminal updates the first learning index sub-model to the second learning index sub-model.
[0141] After updating the first learned index sub-model to the second learned index sub-model, the terminal inputs the target key, which is included in the query or scan command, into the second learned index sub-model. Based on the node sequence number output by the second learned index sub-model, the terminal determines the target address corresponding to the target key. It then sends an RDMA read request containing the target address to the server and receives the data corresponding to the target address from the server's network card. This process allows the correct data to be found.
[0142] In this embodiment, the learning index model of the terminal and the server can be synchronized according to the RDMA read operation, thereby solving the problem of incorrect indexing caused by the inconsistency between the learning index sub-models of the terminal and the server.
[0143] Secondly, since reading and writing data via RDMA is faster than reading and writing data via a regular network card, using RDMA read operations to synchronize the learning index model between the terminal and the server can reduce model synchronization overhead compared to synchronizing the model by executing remote procedure calls (RPCs) via a regular network card.
[0144] In an optional embodiment, the above model synchronization method further includes: when the terminal does not store the learned index root model, sending a third RDMA read request including a third address to the server; the server obtaining the learned index root model according to the third RDMA read request; and the server sending the learned index root model to the terminal.
[0145] In this embodiment, when the terminal does not store the learned index root model, the terminal can obtain the learned index root model from the server, so that the terminal and the server synchronize the learned index root model.
[0146] In another optional embodiment, the above model synchronization method further includes: when the terminal does not store the learning index sub-model corresponding to the sub-model sequence number, the terminal determines the second address according to the storage address of the learning index root model and the sub-model sequence number; the terminal sends a fourth RDMA read request including the second address to the server; the server obtains the second learning index sub-model from the second address according to the fourth RDMA read request and sends the second learning index sub-model to the terminal.
[0147] In this embodiment, when the terminal does not store the learning index sub-model corresponding to the sub-model sequence number, it indicates that the learning index sub-model stored by the terminal and the server may be inconsistent. The terminal can obtain the second learning index sub-model from the server, so that the terminal and the server can synchronize the learning index root sub-model.
[0148] The model training device of this application is described below. The model training device may be, but is not limited to, a server. See also... Figure 10 In one embodiment, the model training apparatus 1000 of this application includes: The acquisition unit 1001 is used to obtain a set of target index nodes from the B-tree index. The set of target index nodes includes multiple target index nodes, where each target index node is the parent node of a leaf node. The B-tree index includes keys of different lengths. The conversion unit 1002 is used to generate a first string group based on the keys of all target index nodes in the target index node set, wherein each string in the first string group has the same length; Training unit 1003 is used to use the index of each key in the target index node set as the label of the string in the first string group, and the index of the key, the key of the target index node and the string correspond one-to-one; Training unit 1003 is also used to train the target learning index model based on the first string group and the label of each string.
[0149] In this embodiment, the acquisition unit 1001, the conversion unit 1002, and the training unit 1003 can all be implemented by a processor. Figure 10 The model training device shown can achieve Figure 6 The model training method shown in the embodiment or optional embodiments, Figure 10 For the explanation of terms in the illustrated embodiments and the steps performed by each unit, please refer to [link / reference]. Figure 6 The corresponding description in the illustrated embodiment.
[0150] In an optional embodiment, the conversion unit 1002 is specifically configured to obtain a common prefix based on the keys of all target index nodes in the target index node set; remove the common prefix from the key of each target index node to obtain the remaining string; extract an identifier string from the head of each remaining string, wherein any two identifier strings are different; and generate a string group based on all identifier strings, wherein the length of each string in the string group is the length of the longest identifier string.
[0151] In another optional embodiment, the training unit 1003 is further configured to obtain multiple target index node sets from the B-tree index; select a pivot key for a sub-model from each target index node set; generate a second string group based on the pivot keys of the multiple sub-models, wherein each string in the second string group has the same length; obtain the sub-model index corresponding to the pivot key of the sub-model, wherein the sub-model index, the pivot key of the sub-model, and the strings in the second string group correspond one-to-one; and train based on the second string group and the sub-model index to obtain a learned index root model, wherein the sub-model index is the label of the string in the second string group.
[0152] In an optional embodiment, the model training device 1000 further includes: The first receiving unit is used to receive operation instructions sent by the terminal through the RDMA interface. The operation instructions are used to insert or delete key-value pairs. The processing unit is used to update the leaf nodes of the B-tree index according to the RDMA operation instructions; The processing unit is also used to obtain the hub key of the updated leaf node when the number of leaf nodes in the B-tree index changes. The processing unit is also used to input the pivot key into the learned index root model to obtain the target sub-model index; The training unit is also used to retrain the sub-model based on the set of target index nodes corresponding to the target sub-model index.
[0153] In another alternative embodiment, the model training device 1000 further includes: The second receiving unit is also used to receive RDMA write requests sent by the terminal; The modification unit is also used to modify the leaf nodes of the B-tree index according to the key carried in the RDMA write request; when the modified leaf node includes a left leaf node and a right leaf node, the key of the target index node is generated according to the key of the left leaf node and the key of the right leaf node, and the key of the target index node is between the maximum key of the left leaf node and the minimum key of the right leaf node. It should be understood that both the first receiving unit and the second receiving unit can be implemented by the server's network interface.
[0154] In an optional embodiment, the modification unit is specifically configured to: obtain the common prefix of the maximum key of the left leaf node and the minimum key of the right leaf node; obtain a first target character and a second target character, wherein the first target character is the first character in the maximum key of the left leaf node that follows the common prefix, and the second target character is the first character in the minimum key of the right leaf node that follows the common prefix; obtain a third target character located between the first target character and the second target character in lexicographical order; and compose the key of the target index node based on the common prefix and the third target character. Both the processing unit and the modification unit can be implemented by a processor.
[0155] See Figure 11 In one embodiment, terminal 1100 includes: The receiving unit 1101 is used to receive a target instruction, which is a query instruction or a scan instruction; Processing unit 1102 is used to input the target key, including the target instruction, into the learned index root model when the terminal stores the learned index root model; Processing unit 1102 is also used to determine the first learned index sub-model based on the sub-model number output by the learned index root model; Processing unit 1102 is also used to input the target key into the first learned index sub-model; The processing unit 1102 is also used to determine the first verification field corresponding to the target key and the first address corresponding to the target key based on the node sequence number output by the first learning index sub-model; Sending unit 1103 is used to send a first remote direct memory access (RDMA) read request to the server, which includes a first address. The first RDMA read request obtains data corresponding to the first address. The data corresponding to the first address includes a second check field. The receiving unit 1101 is also used to receive data corresponding to the first address sent by the network card of the server; The processing unit 1102 is also used to compare the first verification field with the second verification field; The processing unit 1102 is also used to determine the second address based on the storage address of the root model of the learning index and the sub-model number when the first verification field is different from the second verification field. The second address is the storage address of the second learning index sub-model. The sending unit 1103 is also used to send a second RDMA read request to the server, including a second address, where the second address is the storage address of the second learning index sub-model; The receiving unit 1101 is also used to receive the second learning index sub-model sent by the network card of the server; The processing unit 1102 is also used to update the first learned index sub-model to the second learned index sub-model.
[0156] In an optional embodiment, the sending unit 1103 is further configured to send a third RDMA read request including a third address to the server when the terminal does not store the learned index root model. The third RDMA read request is used to obtain the learned index root model from the server. The receiving unit 1101 is also used to receive the learning index root model sent by the network card of the server.
[0157] In another alternative embodiment, The processing unit 1102 is also used to determine the second address based on the storage address of the root model of the learning index and the sub-model number when the terminal does not store the learning index sub-model corresponding to the sub-model number; The sending unit 1103 is also used to send a fourth RDMA read request, including the second address, to the server; The receiving unit 1101 is also used to receive the second learning index sub-model sent by the network card of the server.
[0158] Figure 11 The terminal shown can achieve Figure 9 The steps performed by the terminal in the illustrated embodiment or optional embodiment are as follows: Figure 11 For the explanation of terms in the illustrated embodiments and the steps performed by each unit, please refer to [link / reference]. Figure 9 The corresponding description in the illustrated embodiment.
[0159] See Figure 12 In one embodiment, the server 1200 of this application includes: The receiving unit 1201 is used to receive a first remote direct memory access (RDMA) read request sent by the terminal. The first RDMA read request includes a first address and is sent when the terminal stores a learned index root model and a first learned index sub-model. Network interface card 1202 is used to obtain data corresponding to a first address according to a first RDMA read request, the data corresponding to the first address including a second check field; and to send the data corresponding to the first address to the terminal. The receiving unit 1201 is also configured to receive a second RDMA read request sent by the terminal, the second RDMA read request including a second address; The network interface card 1202 is also used to obtain the second learned index sub-model from the second address according to the second RDMA read request; and to send the second learned index sub-model to the terminal.
[0160] In one alternative embodiment, The receiving unit 1201 is also used to receive a third RDMA read request sent by the terminal. The third RDMA read request includes a third address and is sent when the terminal does not store the learned index root model. Network interface card 1202 is also used to obtain the learned index root model from the third address according to the third RDMA read request; and to send the learned index root model to the terminal.
[0161] In another alternative embodiment, The receiving unit 1201 is also used to receive a fourth RDMA read request sent by the terminal. The fourth RDMA read request includes a second address and is sent when the terminal does not store the first learned index sub-model. The network interface card 1202 is also used to obtain the second learning index sub-model based on the second address and to send the second learning index sub-model to the terminal.
[0162] Figure 12 The server shown can achieve Figure 9 The steps performed by the server in the illustrated embodiment or optional embodiment are as follows: Figure 12 For the explanation of terms in the illustrated embodiments and the steps performed by each unit, please refer to [link / reference]. Figure 9 The corresponding description in the illustrated embodiment.
[0163] The server described in this application is explained below from a hardware perspective. (See attached document.) Figure 13 One embodiment of the server 1300 in this application includes a processor 1301, a memory 1302, and a network card 1303 connected via a bus 1304.
[0164] It should be understood that the processor 1301 mentioned in this embodiment can 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. The general-purpose processor can be a microprocessor or any conventional processor.
[0165] It should also be understood that the memory 1302 mentioned in the embodiments of this application can be volatile memory or non-volatile memory, or may include both volatile and non-volatile memory. The non-volatile memory can be read-only memory (ROM), programmable read-only memory (PROM), erasable programmable read-only memory (EPROM), electrically erasable programmable read-only memory (EEPROM), or flash memory. The volatile memory can be random access memory (RAM), which is used as an external cache. By way of example, but not limitation, many forms of RAM are available, such as static random access memory (SRAM), dynamic random access memory (DRAM), synchronous dynamic random access memory (SDRAM), double data rate synchronous dynamic random access memory (DDR SDRAM), enhanced synchronous dynamic random access memory (ESDRAM), synchronous linked dynamic random access memory (SLDRAM), and direct rambus RAM (DRRAM).
[0166] The network interface card (NIC) 1303 is used to receive or send data and commands. Commands can be, but are not limited to, RDMA requests and RDMA commands. Data can be, but is not limited to, keys or key-value pairs.
[0167] In one embodiment, memory 1302 is used to store information such as programs, instructions, or data. Processor 1301 executes programs or instructions stored in memory 1302. Figure 6 The model training method in the illustrated embodiment.
[0168] In another embodiment, processor 1301 is used to perform Figure 9 The steps performed by the server in the illustrated embodiment.
[0169] Figure 13 The server shown can achieve Figure 6 The steps performed by the model training device in the illustrated embodiment, or the implementation thereof. Figure 9 The steps performed by the server in the illustrated embodiment are as follows: Figure 13 For the explanation of terms in the illustrated embodiments and the steps performed by each unit, please refer to [link / reference]. Figure 6 The illustrated embodiment or Figure 9The corresponding description in the illustrated embodiment.
[0170] The terminal of this application will be described below from the perspective of hardware devices. (See attached document.) Figure 14 One embodiment of the terminal 1400 in this application includes a processor 1401, a memory 1402, and a network card 1403 connected via a bus 1404.
[0171] It should be understood that the processor 1401 mentioned in this embodiment can be a CPU, or other general-purpose processors, DSPs, ASICs, FPGAs, or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, etc. The general-purpose processor can be a microprocessor or any conventional processor, etc.
[0172] It should also be understood that the memory 1402 mentioned in the embodiments of this application can be volatile memory or non-volatile memory, or may include both volatile and non-volatile memory. The non-volatile memory can be ROM, PROM, EPROM, EEPROM, or flash memory. The volatile memory can be RAM, which is used as an external cache. By way of example, but not limitation, many forms of RAM are available, such as SRAM, DRAM, SDRAM, DDR SDRAM, ESDRAM, SLDRAM, and DRRAM.
[0173] The network interface card 1403 can be used to receive or send data, and to receive or send commands. Commands can be, but are not limited to, RDMA requests and RDMA commands. Data can be, but is not limited to, keys or key-value pairs.
[0174] In another embodiment, network interface card 1403 is used to perform Figure 9 The steps performed by the terminal in the illustrated embodiment. Figure 14 The terminal shown can achieve Figure 9 The steps performed by the terminal in the illustrated embodiment are as follows: Figure 14 For the explanation of terms in the illustrated embodiments and the steps performed by each unit, please refer to [link / reference]. Figure 9 The corresponding description in the illustrated embodiment.
[0175] It should be noted that the information interaction and execution process between the modules / units of the above-mentioned device are based on the same concept as the method embodiments of this application, and the resulting technical effects are the same as those of the method embodiments of this application. For details, please refer to the description in the method embodiments shown above in this application, and will not be repeated here.
[0176] This application provides a computer-readable storage medium storing a computer program that, when run on a computer, causes the computer to perform the methods described in the above embodiments or optional embodiments.
[0177] This application also provides a chip system comprising a processor and a memory coupled to each other. The memory stores computer programs or instructions, and the processing unit executes the computer programs or instructions stored in the memory to cause a routing device to perform the steps performed by the first routing device, the target routing device, or the second routing device in the above embodiments. Optionally, the memory is on-chip memory, such as registers, caches, etc., or it can be off-chip memory within a site, such as ROM or other types of static storage devices capable of storing static information and instructions, such as RAM. The processor mentioned above can be a general-purpose central processing unit, a microprocessor, an ASIC, or one or more integrated circuits for implementing the above communication methods.
[0178] It should also be noted that the device embodiments described above are merely illustrative. The units described as separate components may or may not be physically separate, and 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 modules can be selected to achieve the purpose of this embodiment according to actual needs. Furthermore, in the accompanying drawings of the device embodiments provided in this application, the connection relationships between modules indicate that they have communication connections, which can specifically be implemented as one or more communication buses or signal lines.
[0179] In the above embodiments, implementation can be achieved, in whole or in part, through software, hardware, firmware, or any combination thereof. When implemented in software, it can be implemented, in whole or in part, as a computer program product.
[0180] A computer program product includes one or more computer instructions. When the computer program instructions are loaded and executed on a computer, all or part of the flow or function according to the embodiments of this application is generated. The computer may be a general-purpose computer, a special-purpose computer, a computer network, or other programmable device. The computer instructions may be stored in a computer-readable storage medium or transmitted from one computer-readable storage medium to another. For example, computer instructions may be transmitted from one website, computer, server, or data center to another website, computer, server, or data center via wired (e.g., coaxial cable, fiber optic, digital subscriber line (DSL)) or wireless (e.g., infrared, wireless, microwave, etc.) means. The computer-readable storage medium may be any available medium that a computer can store or a data storage device such as a server or data center that integrates one or more available media. The available media may be magnetic media (e.g., floppy disks, hard disks, magnetic tapes), optical media (e.g., DVDs), or semiconductor media (e.g., solid-state disks (SSDs)).
[0181] The above embodiments are only used to illustrate the technical solutions of this application, and are not intended to limit it. 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 scope of the technical solutions of the embodiments of this application.
Claims
1. A model synchronization method, characterized in that, include: Receive a target instruction, which may be a query instruction or a scan instruction; When the terminal stores a learned index root model, the target key included in the target instruction is input into the learned index root model; The first learned index sub-model is determined based on the sub-model index number output by the learned index root model. The first learned index sub-model is obtained by training based on the first string group and the label of each string in the first string group. The first string group is generated based on the keys of all target index nodes in the target index node set. The label of the string in the first string group is the index of each key in the target index node set. The target index node set includes some target index nodes obtained from the B-tree index. The target index node is the parent node of the leaf node. The B-tree index includes keys of different lengths. The index of the key, the key of the target index node and the string correspond one-to-one. Input the target key into the first learned index sub-model; The first verification field corresponding to the target key and the first address corresponding to the target key are determined based on the node sequence number output by the first learning index sub-model. Send a first remote direct memory access (RDMA) read request to the server, including the first address; The network card of the server receives data corresponding to the first address, which is obtained by the network card according to the first RDMA read request. The data corresponding to the first address includes a second check field. Compare the first verification field with the second verification field; When the first verification field is different from the second verification field, the second address is determined according to the storage address of the root model of the learning index and the sub-model number, and the second address is the storage address of the second learning index sub-model; Send a second RDMA read request, including the second address, to the server; Receive the second learned index sub-model sent by the network card of the server; Update the first learning index sub-model to the second learning index sub-model.
2. The method according to claim 1, characterized in that, The method further includes: When the terminal does not store the learned index root model, it sends a third RDMA read request including a third address to the server. The third RDMA read request is used to obtain the learned index root model from the server. Receive the learned index root model sent by the network card of the server.
3. The method according to claim 1 or 2, characterized in that, The method further includes: When the terminal does not store the learning index sub-model corresponding to the sub-model number, the second address is determined according to the storage address of the learning index root model and the sub-model number; Send a fourth RDMA read request to the server, including the second address; Receive the second learning index sub-model sent by the network card of the server.
4. A model synchronization method, characterized in that, include: The receiving terminal sends a first Remote Direct Memory Access (RDMA) read request, which includes a first address. The first RDMA read request is sent when the terminal stores a learned index root model and a first learned index sub-model. The first learned index sub-model is trained based on a first string group and the label of each string in the first string group. The first string group is generated based on the keys of all target index nodes in the target index node set. The label of each string in the first string group is the index number of each key in the target index node set. The target index node set includes some target index nodes obtained from a B-tree index. The target index node is the parent node of the leaf node. The B-tree index includes keys of different lengths. The index number of the key, the key of the target index node, and the string correspond one-to-one. The data corresponding to the first address is obtained according to the first RDMA read request, and the data corresponding to the first address includes a second verification field. Use the network card to send the data corresponding to the first address to the terminal; Receive a second RDMA read request sent by the terminal, the second RDMA read request including a second address; The second learned index sub-model is obtained from the second address according to the second RDMA read request; The second learned index sub-model is obtained based on the second RDMA read request; The second learning index sub-model is sent to the terminal using the network card.
5. The method according to claim 4, characterized in that, The method further includes: The receiving terminal sends a third RDMA read request, the third RDMA read request including a third address, the third RDMA read request being sent when the terminal does not store a learned index root model; The learned index root model is obtained from the third address according to the third RDMA read request; The learning index root model is sent to the terminal using the network card.
6. The method according to claim 4 or 5, characterized in that, The method further includes: The receiving terminal sends a fourth RDMA read request, the fourth RDMA read request including the second address, and the fourth RDMA read request is sent when the terminal does not store the first learned index sub-model; The second learning index sub-model is obtained based on the sequence number of the first learning index sub-model and the second address; The network card is used to send the second learning index sub-model to the terminal.
7. A terminal, characterized in that, include: The receiving unit is used to receive a target instruction, which is a query instruction or a scan instruction; The processing unit is configured to input the target key, including the target instruction, into the learned index root model when the terminal stores the learned index root model; The processing unit is further configured to determine a first learned index sub-model based on the sub-model index number output by the learned index root model. The first learned index sub-model is obtained by training based on a first string group and the label of each string in the first string group. The first string group is generated based on the keys of all target index nodes in the target index node set. The label of each string in the first string group is the index of each key in the target index node set. The target index node set includes some target index nodes obtained from the B-tree index. The target index node is the parent node of the leaf node. The B-tree index includes keys of different lengths. The index of the key, the key of the target index node, and the string correspond one-to-one. The processing unit is further configured to input the target key into the first learned index sub-model; The processing unit is further configured to determine the first verification field corresponding to the target key and the first address corresponding to the target key based on the node sequence number output by the first learning index sub-model; The sending unit is configured to send a first remote direct memory access (RDMA) read request, including the first address, to the server. The receiving unit is further configured to receive data corresponding to the first address sent by the network card of the server, wherein the data corresponding to the first address is obtained by the network card according to the first RDMA read request, and the data corresponding to the first address includes a second verification field. The processing unit is further configured to compare the first verification field with the second verification field; The processing unit is further configured to determine a second address based on the storage address of the root model of the learning index and the sub-model number when the first verification field is different from the second verification field, wherein the second address is the storage address of the second learning index sub-model; The sending unit is further configured to send a second RDMA read request to the server, including a second address, wherein the second address is the storage address of the second learning index sub-model; The receiving unit is also used to receive the second learning index sub-model sent by the network card of the server; The processing unit is further configured to update the first learned index sub-model to a second learned index sub-model.
8. The terminal according to claim 7, characterized in that, The sending unit is further configured to send a third RDMA read request including a third address to the server when the terminal does not store the learned root index model, the third RDMA read request being used to obtain the learned root index model from the server; The receiving unit is also used to receive the learning index root model sent by the network card of the server.
9. The terminal according to claim 7 or 8, characterized in that, The processing unit is further configured to determine a second address based on the storage address of the root model of the learning index and the sub-model number when the terminal does not store the learning index sub-model corresponding to the sub-model number; The sending unit is further configured to send a fourth RDMA read request, including the second address, to the server; The receiving unit is also used to receive the second learning index sub-model sent by the network card of the server.
10. A server, characterized in that, include: A receiving unit is configured to receive a first Remote Direct Memory Access (RDMA) read request sent by a terminal. The first RDMA read request includes a first address. The first RDMA read request is sent when the terminal stores a learned index root model and a first learned index sub-model. The first learned index sub-model is trained based on a first string group and the label of each string in the first string group. The first string group is generated based on the keys of all target index nodes in the target index node set. The label of each string in the first string group is the index number of each key in the target index node set. The target index node set includes some target index nodes obtained from a B-tree index. The target index node is the parent node of the leaf node. The B-tree index includes keys of different lengths. The index number of the key, the key of the target index node, and the string correspond one-to-one. The network interface card (NIC) is used to obtain data corresponding to the first address according to the first RDMA read request, wherein the data corresponding to the first address includes a second check field; and to send the data corresponding to the first address to the terminal. The receiving unit is further configured to receive a second RDMA read request sent by the terminal, wherein the second RDMA read request includes a second address; The network interface card is further configured to obtain the second learned index sub-model from the second address according to the second RDMA read request; and send the second learned index sub-model to the terminal.
11. The server according to claim 10, characterized in that, The receiving unit is also configured to receive a third RDMA read request sent by the terminal, the third RDMA read request including a third address, and the third RDMA read request being sent when the terminal does not store a learned index root model; The network interface card is also used to obtain the learned index root model from the third address according to the third RDMA read request; and to send the learned index root model to the terminal.
12. The server according to claim 10 or 11, characterized in that, The receiving unit is further configured to receive a fourth RDMA read request sent by the terminal, the fourth RDMA read request including the second address, and the fourth RDMA read request being sent when the terminal does not store the first learned index sub-model; The network interface card is further configured to obtain a second learning index sub-model based on the second address and send the second learning index sub-model to the terminal.
13. A computer storage medium storing instructions, characterized in that, When it is run on a computer, it causes the computer to perform the method of any one of claims 1 to 6.
Citation Information
Patent Citations
Efficient concurrent index data structure based on machine learning
CN111651455A
Communication method, device and system suitable for heterogeneous environment
CN111680791A
