Hash table management methods, devices and systems, and computer storage media
By introducing a primary hash bucket and a backup hash bucket structure into the hash table, and using multiple hash functions to address multiple hash buckets corresponding to a key, the poor storage performance of the hopscotch hash table is solved, achieving load balancing and efficient insertion and query operations.
Patent Information
- Application Number
- CN202011362317.1
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2020-11-28
- Publication Date
- 2025-11-14
- Estimated Expiration
- 2040-11-28
AI Technical Summary
Insertion operations on existing hopscotch hash tables can lead to large movement ranges of key-value pairs, resulting in poor server storage performance.
A primary hash bucket and backup hash bucket structure is adopted. Multiple hash functions are used to address multiple primary hash buckets corresponding to the key, and key-value pairs are stored in one of the primary hash buckets or its backup hash bucket to achieve load balancing.
It improves the storage performance and query efficiency of hash tables, reduces the resource consumption of data transfer between devices, and enhances the execution efficiency of insertion and query operations.
Smart Images

Figure CN114579558B_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of data storage technology, and in particular to a method, apparatus and system for managing hash tables, and a computer storage medium. Background Technology
[0002] A hash table is a data structure that stores data in the form of key-value pairs. Records are accessed by mapping key values to a location in the hash table using a hash function, enabling fast record lookup.
[0003] Currently, servers commonly use hopscotch hashing to store data. A hopscotch hash table consists of multiple consecutive hash buckets. When a server wants to insert a new key-value pair into the hopscotch hash table, it uses a hash function to calculate the hash bucket position corresponding to the key in the key-value pair. Then, it iterates through the L hash buckets immediately following that position to find an empty bucket, where L is a positive integer. If any of these L hash buckets is empty, the new key-value pair is inserted into that empty bucket. If none of these L hash buckets are empty, the search continues until an empty bucket is found. Then, key-value pairs preceding that empty bucket are iteratively moved into that empty bucket until an empty bucket appears among the L hash buckets. Finally, the new key-value pair is inserted into the empty hash bucket among these L hash buckets.
[0004] Because performing an insertion operation in a hopscotch hash table can cause key-value pairs to move, in the worst case, the movement can even involve the entire hash table, leading to poor server storage performance. Summary of the Invention
[0005] This application provides a method, apparatus, system, and computer storage medium for managing hash tables, which can solve the problem of poor storage performance of hash tables in current servers.
[0006] Firstly, a method for managing a hash table is provided. The hash table includes a primary hash bucket and secondary hash buckets. The primary hash buckets are addressable by a hash function, while the secondary hash buckets are not addressable by a hash function. The secondary hash buckets are located between and shared by the two primary hash buckets. The method includes: a first device, in response to receiving a write request for writing a first key-value pair, using at least two hash functions to address at least two primary hash buckets corresponding to the key in the first key-value pair. The first device determines a target empty slot for writing the first key-value pair from the at least two primary hash buckets and the secondary hash buckets of the at least two primary hash buckets. Then, the first device writes the first key-value pair to the target empty slot.
[0007] In this application, when the device needs to perform an insertion operation on the hash table, it only needs to address the main hash bucket corresponding to the key, and then insert the key-value pair into an empty slot in the main hash bucket or its spare hash bucket, without moving the key-value pair, thus improving the storage performance of the device. By using multiple hash functions to address multiple main hash buckets corresponding to the key, and then storing the key-value pair in one of the main hash buckets or one of the spare hash buckets of the main hash bucket, load balancing of the hash table can be achieved.
[0008] Optionally, the implementation process of the first device determining the target empty slot for writing the first key-value pair in at least two first main hash buckets and at least two spare hash buckets of the first main hash buckets includes: the first device first determining the target hash bucket in at least two first main hash buckets and at least two spare hash buckets of the first main hash buckets, the target hash bucket including one or more empty slots; and then the first device determining the unlocked empty slots in the target hash bucket as the target empty slots.
[0009] Optionally, the process of the first device determining the target hash bucket from at least two first primary hash buckets and at least two spare hash buckets of the first primary hash buckets includes: in response to the existence of a hash bucket including an empty slot in at least two first primary hash buckets, the first device determines the target hash bucket from at least two first primary hash buckets. Alternatively, in response to the absence of a hash bucket including an empty slot in at least two first primary hash buckets, the first device determines the target hash bucket from at least two spare hash buckets of the first primary hash buckets.
[0010] Optionally, the implementation process of the first device determining the target hash bucket among at least two first primary hash buckets includes: the first device determining the hash bucket with the most empty slots among at least two first primary hash buckets as the target hash bucket.
[0011] In this application, the first device determines the main hash bucket with the most empty slots among the multiple main hash buckets corresponding to the key as the target hash bucket, and then writes key-value pairs into the empty slots of the target hash bucket, which can achieve load balancing of the hash table and make the storage performance of the hash table better.
[0012] Optionally, the process of the first device determining the target hash bucket from the spare hash buckets of at least two first main hash buckets includes: the first device determining the hash bucket with the most empty slots among the spare hash buckets of at least two first main hash buckets as the target hash bucket.
[0013] In this application, the first device determines the backup hash bucket with the most empty slots among the multiple backup hash buckets of the multiple main hash buckets corresponding to the keyword as the target hash bucket. Subsequently, key-value pairs are written into the empty slots of the target hash bucket, which can achieve load balancing of the hash table and make the storage performance of the hash table better.
[0014] Optionally, the hash table is stored in the second device. The implementation process of the first device addressing at least two first main hash buckets corresponding to the key in the first key-value pair using at least two hash functions in response to receiving a write request for writing the first key-value pair includes: the first device calculating at least two first hash positions corresponding to the key in the first key-value pair using at least two hash functions in response to receiving the write request for writing the first key-value pair. The first device sends at least two first read requests of one-sided remote direct memory access (RDMA) to the second device, each first read request being used to read a main hash bucket and a spare hash bucket of a first hash position. Correspondingly, the implementation process of the first device writing the first key-value pair to the target empty slot includes: the first device sending a one-sided RDMA compare and swap (CAS) request to the second device, the CAS request being used to lock the target empty slot. In response to successful locking of the target empty slot, the first device sends a one-sided RDMA write request to the second device, the write request being used to write the first key-value pair to the target empty slot.
[0015] In this application, when the first device needs to perform an insertion operation on the hash table in the second device, it first calculates the hash position corresponding to the key. Each hash position has a main hash bucket. Then, the main hash bucket and its spare hash bucket corresponding to the key are read locally using one-sided RDMA. The key-value pair is then written locally into an empty slot in the main hash bucket or its spare hash bucket. Finally, it is written back to the second device using one-sided RDMA. This enables the first device to perform an insertion operation on the hash table in the second device using one-sided RDMA. Because the first device selectively reads the main hash bucket and its spare hash bucket corresponding to the key, the amount of data that the first device needs to read locally is small, the transmission resources required between the first and second devices are small, and the execution efficiency of the insertion operation is high.
[0016] Optionally, in response to receiving a read request for reading a second key-value pair, the first device uses at least two hash functions to address at least two second primary hash buckets corresponding to the key in the second key-value pair. The first device queries the second key-value pair in at least two secondary primary hash buckets and in spare hash buckets of at least two secondary primary hash buckets.
[0017] In this application, when the device needs to perform a query operation on the hash table, it only needs to address the main hash bucket corresponding to the key, and then query the key-value pair in the main hash bucket and its backup hash buckets, which has high query efficiency.
[0018] Optionally, the hash table is stored in the second device. The implementation process of the first device addressing at least two second main hash buckets corresponding to the key in the second key-value pair using at least two hash functions in response to receiving a read request for reading the second key-value pair includes: the first device, in response to receiving a read request for reading the second key-value pair, calculating at least two second hash positions corresponding to the key in the second key-value pair using at least two hash functions respectively. The first device sends at least two second read requests via one-way RDMA to the second device, each second read request being used to read the main hash bucket of a second hash position and the spare hash bucket of that main hash bucket.
[0019] In this application, when the first device needs to perform a query operation on the hash table in the second device, it first calculates the hash position corresponding to the key. Each hash position has a main hash bucket. Then, the main hash bucket and its spare hash bucket corresponding to the key are read locally using a one-sided RDMA method. Next, the key-value pair is queried from the main hash bucket and its spare hash bucket corresponding to the key. This enables the first device to perform a query operation on the hash table in the second device using a one-sided RDMA method. Because the first device selectively reads the main hash bucket and its spare hash bucket corresponding to the key, the amount of data that the first device needs to read locally is small, the transmission resources required between the first and second devices are small, the amount of data that the first device needs to query is also small, and the execution efficiency of the query operation is high.
[0020] Optionally, the primary hash buckets and backup hash buckets in the hash table are arranged alternately, or the hash table includes multiple hash bucket groups arranged sequentially, each hash bucket group including two primary hash buckets and a backup hash bucket located between the two primary hash buckets.
[0021] Among them, the spare hash bucket adjacent to the main hash bucket is the spare hash bucket of the main hash bucket.
[0022] Secondly, a method for managing a hash table is provided. The hash table includes a primary hash bucket and secondary hash buckets. The primary hash buckets are addressable by a hash function, while the secondary hash buckets are not addressable by a hash function. The secondary hash buckets are located between and shared by the two primary hash buckets. The method includes: a first device, in response to receiving a read request for reading a first key-value pair, using at least two hash functions to address at least two primary hash buckets corresponding to the key in the first key-value pair. The first device then queries the primary hash buckets and the secondary hash buckets of the primary hash buckets for the first key-value pair.
[0023] Optionally, the hash table is stored in the second device. The implementation process of the first device addressing at least two first main hash buckets corresponding to the key in the first key-value pair using at least two hash functions in response to receiving a read request for reading the first key-value pair includes: the first device, in response to receiving a read request for reading the first key-value pair, calculating at least two first hash positions corresponding to the key in the first key-value pair using at least two hash functions respectively. The first device sends at least two first read requests via one-sided RDMA to the second device, each first read request being used to read the main hash bucket of a first hash position and the spare hash bucket of that main hash bucket.
[0024] Optionally, in response to receiving a write request for writing a second key-value pair, the first device uses at least two hash functions to address at least two second primary hash buckets corresponding to the key in the second key-value pair. The first device determines the target empty slot for writing the second key-value pair from the at least two second primary hash buckets and the spare hash buckets of the at least two second primary hash buckets. The first device then writes the second key-value pair to the target empty slot.
[0025] Optionally, the implementation process of the first device determining the target empty slot for writing the second key-value pair in at least two second main hash buckets and at least two spare hash buckets of the second main hash buckets includes: the first device first determining the target hash bucket in at least two second main hash buckets and at least two spare hash buckets of the second main hash buckets, the target hash bucket including one or more empty slots; and then the first device determining the target empty slot from the unlocked empty slots in the target hash bucket.
[0026] Optionally, the process of the first device determining the target hash bucket from at least two second primary hash buckets and at least two spare hash buckets of the second primary hash buckets includes: in response to the existence of hash buckets including empty slots in at least two second primary hash buckets, the first device determines the target hash bucket from at least two second primary hash buckets. Alternatively, in response to the absence of hash buckets including empty slots in at least two second primary hash buckets, the first device determines the target hash bucket from spare hash buckets of at least two second primary hash buckets.
[0027] Optionally, the implementation process of the first device determining the target hash bucket among at least two second primary hash buckets includes: the first device determining the hash bucket with the most empty slots among at least two second primary hash buckets as the target hash bucket.
[0028] Optionally, the process of the first device determining the target hash bucket from the spare hash buckets of at least two second primary hash buckets includes: the first device determining the hash bucket with the most empty slots among the spare hash buckets of at least two second primary hash buckets as the target hash bucket.
[0029] Optionally, the hash table is stored in the second device. The implementation process of the first device addressing at least two second main hash buckets corresponding to the key in the second key-value pair using at least two hash functions in response to receiving a write request for writing the second key-value pair includes: the first device, in response to receiving the write request for writing the second key-value pair, calculating at least two second hash positions corresponding to the key in the second key-value pair using at least two hash functions respectively. The first device sends at least two second read requests via one-way RDMA to the second device, each second read request being used to read the main hash bucket and the spare hash bucket of the main hash bucket for one second hash position.
[0030] Accordingly, the process of the first device writing the second key-value pair into the target empty slot includes: the first device sending a unilateral RDMA CAS request to the second device, the CAS request being used to lock the target empty slot. In response to the successful locking of the target empty slot, the first device sends a unilateral RDMA write request to the second device, the write request being used to write the second key-value pair into the target empty slot.
[0031] Optionally, the primary hash buckets and backup hash buckets in the hash table are arranged alternately, or the hash table includes multiple hash bucket groups arranged sequentially, each hash bucket group including two primary hash buckets and a backup hash bucket located between the two primary hash buckets.
[0032] Thirdly, a hash table management device is provided. The device includes multiple functional modules that interact to implement the methods described in the first aspect and its various embodiments. The multiple functional modules can be implemented using software, hardware, or a combination of both, and can be arbitrarily combined or divided based on specific implementations.
[0033] Fourthly, a hash table management device is provided. The device includes multiple functional modules that interact to implement the methods described in the second aspect and its various embodiments. These multiple functional modules can be implemented using software, hardware, or a combination of both, and can be arbitrarily combined or divided based on specific implementations.
[0034] Fifthly, a hash table management system is provided, comprising: a first device and a second device, wherein the second device stores a hash table, the hash table including a primary hash bucket and a backup hash bucket, the primary hash bucket being addressable by a hash function, the backup hash bucket being not addressable by a hash function, and the backup hash bucket being located between the two primary hash buckets and shared by the two primary hash buckets.
[0035] A first device, in response to receiving a write request for writing a first key-value pair, calculates at least two first hash positions corresponding to the key in the first key-value pair using at least two hash functions. The first device sends at least two first read requests for one-sided RDMA to a second device, each first read request reading a primary hash bucket and a spare hash bucket of the primary hash bucket for a first hash position. The first device determines the target empty slot for writing the first key-value pair from the read hash buckets. The first device sends an atomic operation CAS request for one-sided RDMA to the second device, the CAS request locking the target empty slot. In response to successful locking of the target empty slot, the first device sends a write request for one-sided RDMA to the second device, the write request writing the first key-value pair into the target empty slot. And / or, the first device, in response to receiving a read request for reading a second key-value pair, calculates at least two second hash positions corresponding to the key in the second key-value pair using at least two hash functions. The first device also sends at least two second read requests for one-sided RDMA to the second device, each second read request reading a primary hash bucket and a spare hash bucket of the primary hash bucket for a second hash position. The first device is also used to query the second key-value pair in the read hash bucket.
[0036] In a sixth aspect, a device is provided, comprising: a processor and a memory;
[0037] The memory is used to store computer programs, the computer programs including program instructions;
[0038] The processor is used to invoke the computer program to implement the methods of the first aspect and its embodiments or to implement the methods of the second aspect and its embodiments.
[0039] In a seventh aspect, a computer storage medium is provided, wherein instructions are stored thereon, which, when executed by a processor, implement the methods described in the first aspect and its embodiments or implement the methods described in the second aspect and its embodiments.
[0040] Eighthly, a chip is provided, the chip including programmable logic circuitry and / or program instructions, which, when the chip is running, implement the methods of the first aspect and its embodiments or implement the methods of the second aspect and its embodiments.
[0041] The beneficial effects of the technical solution provided in this application include at least the following:
[0042] This application proposes a novel hash table structure. The hash table includes a primary hash bucket and adjacent spare hash buckets. When a device needs to perform an insertion operation on the hash table, it only needs to address the primary hash bucket corresponding to the key, and then insert the key-value pair into an empty slot in the primary hash bucket or its spare hash bucket, without moving the key-value pair, thus improving the device's storage performance. By employing multiple hash functions to address multiple primary hash buckets corresponding to the key, and then storing the key-value pair in one of the primary hash buckets or one of its spare hash buckets, load balancing of the hash table can be achieved. When a device needs to perform a query operation on the hash table, it only needs to address the primary hash bucket corresponding to the key, and then query the key-value pair in that primary hash bucket and its spare hash buckets, resulting in high query efficiency. In addition, it also implements insertion and / or query operations of one device into the hash table of another device via one-sided RDMA. This process requires less transmission resources between the two devices and has high operation efficiency. Attached Figure Description
[0043] Figure 1 This is a schematic diagram of the structure of a hash table provided in an embodiment of this application;
[0044] Figure 2 This is a schematic diagram of another hash table structure provided in an embodiment of this application;
[0045] Figure 3 This is a flowchart illustrating a hash table management method provided in an embodiment of this application;
[0046] Figure 4 This is a schematic diagram of the structure of a hash table management system provided in an embodiment of this application;
[0047] Figure 5 This is a schematic diagram of the insertion operation process of a hash table for RDMA provided in an embodiment of this application;
[0048] Figure 6 This is a schematic diagram of a hash table query operation process for RDMA provided in an embodiment of this application;
[0049] Figure 7 This is a schematic diagram of the structure of a hash table management device provided in an embodiment of this application;
[0050] Figure 8 This is a schematic diagram of another hash table management device provided in an embodiment of this application;
[0051] Figure 9 This is a schematic diagram of the structure of another hash table management device provided in the embodiments of this application;
[0052] Figure 10This is a schematic diagram of the structure of another hash table management device provided in an embodiment of this application;
[0053] Figure 11 This is a block diagram of a device provided in an embodiment of this application. Detailed Implementation
[0054] To make the objectives, technical solutions, and advantages of this application clearer, the embodiments of this application will be described in further detail below with reference to the accompanying drawings.
[0055] This application proposes a hash table storage structure. The hash table includes a primary hash bucket and backup hash buckets (collectively referred to as hash buckets). The primary hash bucket is addressable by a hash function, while the backup hash buckets are not. The backup hash buckets are located between the two primary hash buckets and are shared by them. In this application embodiment, a primary hash bucket can use its adjacent backup hash bucket as its own backup hash bucket.
[0056] Optionally, the hash table provided in this application embodiment includes a hash bucket comprising multiple slots. The number of slots in the main hash bucket and the number of slots in the backup hash bucket can be the same or different. Each slot in the hash bucket stores a key-value pair, which includes a key and a value. Each slot in the hash bucket can also be configured with a flag bit as a lock. For example, setting the flag bit of a slot in the hash bucket to 1 indicates that the slot is locked; setting the flag bit of a slot in the hash bucket to 0 indicates that the slot is unlocked. If a slot in the hash bucket is locked, it means that the slot is locked, and the slot cannot be operated by any device other than the device that locked it.
[0057] In one possible implementation, the primary hash bucket and backup hash buckets in the hash table are arranged alternately. Alternatively, Figure 1 This is a schematic diagram of the structure of a hash table provided in an embodiment of this application. For example... Figure 1 As shown, the hash table includes N hash buckets, denoted as hash bucket 1 to hash bucket N, where N is an odd number greater than 1. Among them, the odd-numbered hash buckets are the main hash buckets, that is, hash bucket 1, hash bucket 3, hash bucket 5, ..., hash bucket N are all main hash buckets; the even-numbered hash buckets are the backup hash buckets, that is, hash bucket 2, hash bucket 4, hash bucket 6, ..., hash bucket N-1 are all backup hash buckets.
[0058] In such Figure 1In the hash table shown, hash bucket 1 and hash bucket 3 share hash bucket 2, hash bucket 3 and hash bucket 5 share hash bucket 4, ..., hash bucket N-2 and hash bucket N share hash bucket N-1. That is, hash bucket 1's spare hash bucket includes hash bucket 2, hash bucket 3's spare hash buckets include hash bucket 2 and hash bucket 4, ..., hash bucket N's spare hash bucket includes hash bucket N-1. In other words, all other primary hash buckets besides hash bucket 1 and hash bucket N have two spare hash buckets.
[0059] In another possible implementation, the hash table comprises multiple hash bucket groups arranged sequentially, each hash bucket group including two main hash buckets and a spare hash bucket located between the two main hash buckets. Optionally, Figure 2 This is a schematic diagram of another hash table structure provided in an embodiment of this application. For example... Figure 2 As shown, the hash table includes M hash buckets, denoted as hash bucket 1 to hash bucket M, where M is an integer multiple of 3. Hash bucket 1, hash bucket 2, and hash bucket 3 form a hash bucket group, with hash bucket 1 and hash bucket 3 as the primary hash buckets, and hash bucket 2 as a spare hash bucket shared by hash bucket 1 and hash bucket 3; hash bucket 4, hash bucket 5, and hash bucket 6 form a hash bucket group, with hash bucket 4 and hash bucket 6 as the primary hash buckets, and hash bucket 5 as a spare hash bucket shared by hash bucket 4 and hash bucket 6; ...; hash bucket M-2, hash bucket M-1, and hash bucket M form a hash bucket group, with hash bucket M-2 and hash bucket M as the primary hash buckets, and hash bucket M-1 as a spare hash bucket shared by hash bucket M-2 and hash bucket M.
[0060] In such Figure 2 In the hash buckets shown, the backup hash buckets for hash bucket 1 and hash bucket 3 are both hash bucket 2, the backup hash buckets for hash bucket 4 and hash bucket 6 are both hash bucket 5, ..., and the backup hash buckets for hash bucket M-2 and hash bucket M are both hash bucket M-1. That is, each main hash bucket has one backup hash bucket.
[0061] Based on the hash table proposed in the embodiments of this application, the embodiments of this application also provide a management method for the hash table. In this hash table management method, at least two hash functions are used to address at least two main hash buckets corresponding to a key, that is, at least two hash functions are used to hash a key into at least two main hash buckets respectively. Specifically, one hash function is used to hash a key into one main hash bucket, and different hash functions are used to hash the same key into different hash buckets.
[0062] The hash table management method provided in this application mainly includes the hash table insertion operation process and the query operation process. Optionally, Figure 3This is a flowchart illustrating a hash table management method provided in an embodiment of this application. Steps 301 to 303 illustrate the hash table insertion operation flow; steps 304 to 305 illustrate the hash table query operation flow. Figure 3 As shown, the method includes:
[0063] Step 301: In response to receiving a write request for writing a first key-value pair, the first device uses at least two hash functions to address at least two first main hash buckets corresponding to the key in the first key-value pair.
[0064] The write request includes a first key-value pair, which consists of a key and a value. At least two hash functions are required, each used to address a primary hash bucket corresponding to the key.
[0065] Optionally, the at least two hash functions provided in this application embodiment have different addressing ranges in the hash table. For example, the at least two hash functions may include two hash functions, one of which is used to address the first half of the hash table, and the other is used to address the second half. Alternatively, the at least two hash functions may include three hash functions, one of which is used to address the first 1 / 3 of the hash table, another to address the middle 1 / 3, and the last 1 / 3. This application embodiment does not limit the number or design of the hash functions used for addressing in the hash table.
[0066] This application embodiment illustrates the use of two hash functions to address two main hash buckets corresponding to a key in a hash table. Optionally, the at least two hash functions include a first hash function and a second hash function. After receiving a write request containing a first key-value pair, the first device uses the first hash function to calculate the hash value 1 corresponding to the key in the first key-value pair, and then addresses a first main hash bucket in the hash table based on the hash value 1; and uses the second hash function to calculate the hash value 2 corresponding to the key in the first key-value pair, and then addresses another first main hash bucket in the hash table based on the hash value 2. Here, one hash value corresponds to one hash position in the hash table. Optionally, the first hash function is used to address the first half of the hash table, and the second hash function is used to address the second half of the hash table.
[0067] Step 302: The first device determines the target empty slot for writing the first key-value pair in the at least two first primary hash buckets and the spare hash buckets of the at least two first primary hash buckets.
[0068] Optionally, the spare hash buckets of at least two first primary hash buckets include all spare hash buckets of each of the at least two first primary hash buckets. For example, refer to... Figure 1 or Figure 2 The hash table shown has at least two primary hash buckets corresponding to the keys in the first key-value pairs, including hash bucket 3 and hash bucket 7. In the example... Figure 1 In the hash table shown, the spare hash buckets for the at least two first primary hash buckets include hash bucket 2, hash bucket 4, hash bucket 6, and hash bucket 8. Step 302 is that the first device determines the target empty slot for writing the first key-value pair in hash buckets 2, 3, 4, 6, 7, and 8. Figure 2 In the hash table shown, the backup hash buckets of the at least two first primary hash buckets include hash bucket 2 and hash bucket 8. Step 302 is that the first device determines the target empty slot for writing the first key-value pair in hash bucket 2, hash bucket 3, hash bucket 7 and hash bucket 8.
[0069] In this embodiment of the application, after obtaining at least two primary hash buckets and their backup hash buckets corresponding to a keyword, the first device first queries whether the keyword exists in the at least two primary hash buckets and their backup hash buckets. If it exists, it returns an indication that a duplicate keyword exists; if it does not exist, it then executes step 302. Optionally, the implementation process of step 302 includes the following steps 3021 to 3022:
[0070] In step 3021, the first device determines a target hash bucket from at least two first primary hash buckets and at least two spare hash buckets of the first primary hash buckets, the target hash bucket including one or more empty slots.
[0071] In the first possible scenario, the implementation of step 3021 includes: in response to the existence of hash buckets including empty slots in at least two first primary hash buckets, the first device determines the target hash bucket in the at least two first primary hash buckets.
[0072] Optionally, the first device determines the hash bucket with the most empty slots among the at least two first main hash buckets as the target hash bucket. For example, continuing with the example above, if the number of empty slots in hash bucket 3 is greater than the number of empty slots in hash bucket 7, then the first device determines hash bucket 3 as the target hash bucket; if the number of empty slots in hash bucket 3 is less than the number of empty slots in hash bucket 7, then the first device determines hash bucket 7 as the target hash bucket; if the number of empty slots in hash bucket 3 is equal to the number of empty slots in hash bucket 7, then the first device determines either hash bucket 3 or hash bucket 7 as the target hash bucket.
[0073] In this embodiment, the first device determines the main hash bucket with the most empty slots among the multiple main hash buckets corresponding to the keyword as the target hash bucket. Subsequently, key-value pairs are written into the empty slots of the target hash bucket, which can achieve load balancing of the hash table and make the storage performance of the hash table better.
[0074] Alternatively, in response to the existence of a hash bucket containing an empty slot in at least two first primary hash buckets, the first device may also identify any one of the at least two first primary hash buckets containing an empty slot as the target hash bucket.
[0075] In the second possible scenario, the implementation of step 3021 includes: in response to the absence of a hash bucket including an empty slot in at least two first primary hash buckets, the first device determines the target hash bucket in the spare hash buckets of the at least two first primary hash buckets.
[0076] Optionally, the first device determines the hash bucket with the most empty slots among the spare hash buckets of the at least two first primary hash buckets as the target hash bucket. For example, continuing with the example above, hash bucket 3 and hash bucket 7 both have 0 empty slots, assuming the hash table is as follows: Figure 2 As shown, if the number of empty slots in hash bucket 2 is greater than the number of empty slots in hash bucket 8, the first device determines hash bucket 2 as the target hash bucket; if the number of empty slots in hash bucket 2 is less than the number of empty slots in hash bucket 8, the first device determines hash bucket 8 as the target hash bucket; if the number of empty slots in hash bucket 2 is equal to the number of empty slots in hash bucket 8, the first device determines either hash bucket 2 or hash bucket 8 as the target hash bucket.
[0077] In this embodiment, the first device determines the backup hash bucket with the most empty slots among the multiple backup hash buckets of the multiple main hash buckets corresponding to the keyword as the target hash bucket. Subsequently, key-value pairs are written into the empty slots of the target hash bucket, which can achieve load balancing of the hash table and make the storage performance of the hash table better.
[0078] Alternatively, in response to the absence of any hash bucket including an empty slot in at least two first primary hash buckets, the first device may also determine any hash bucket including an empty slot in any of the spare hash buckets of the at least two first primary hash buckets as the target hash bucket.
[0079] In the third possible case, the implementation process of step 3021 includes: in response to the existence of a hash bucket including an empty slot in at least two first primary hash buckets and the spare hash buckets of the at least two first primary hash buckets, the first device determines any hash bucket including an empty slot in the at least two first primary hash buckets and the spare hash buckets of the at least two first primary hash buckets as the target hash bucket.
[0080] Optionally, if at least two first primary hash buckets do not contain any hash buckets with empty slots, and the spare hash buckets of the at least two first primary hash buckets do not contain any hash buckets with empty slots (i.e., neither the at least two first primary hash buckets nor their spare hash buckets have empty slots), the first device determines that it cannot write the first key-value pair to the hash table. Further, the first device may return an insertion failure message for the write request requesting the writing of the first key-value pair, and / or issue a resizing suggestion for the hash table.
[0081] In step 3022, the first device identifies the unlocked empty slots in the target hash bucket as target empty slots.
[0082] Optionally, after determining the target hash bucket, the first device sequentially searches for empty slots within the target hash bucket. If a found empty slot is locked, the search continues for the next empty slot until an unlocked empty slot is found and designated as the target empty slot. If all empty slots in the target hash bucket are locked, the first device determines that the first key-value pair cannot be written to the hash table. Alternatively, the first device may change the target hash bucket, designating one of the at least two first primary hash buckets and the spare hash buckets of the at least two first primary hash buckets, excluding the target hash bucket, as the new target hash bucket, and then determining the target empty slot within this new target hash bucket.
[0083] Optionally, in step 302, after the first device addresses at least two first main hash buckets and their spare hash buckets corresponding to the key in the first key-value pair, it can also directly search for empty slots in the at least two first main hash buckets and their spare hash buckets to obtain the target empty slot. For example, the first device can search for empty slots sequentially according to the arrangement order of the at least two first main hash buckets and their spare hash buckets in the hash table. This application embodiment does not limit the method of obtaining the target empty slot from the at least two first main hash buckets and their spare hash buckets.
[0084] Step 303: The first device writes the first key-value pair into the target empty slot.
[0085] After identifying the target empty slot, the first device first locks the target empty slot atomically, for example, by setting the marker position of the target empty slot to 1. Then, the first device writes the first key-value pair into the target empty slot. After writing the first key-value pair into the target empty slot, the first device then locks the target empty slot, for example, by setting the marker position of the target empty slot to 0.
[0086] This application proposes a novel hash table structure. The hash table includes a primary hash bucket and adjacent spare hash buckets. When the device needs to perform an insertion operation on the hash table, it only needs to address the primary hash bucket corresponding to the key, and then insert the key-value pair into an empty slot in the primary hash bucket or its spare hash bucket. There is no need to move the key-value pair, thus improving the device's storage performance. By using multiple hash functions to address multiple primary hash buckets corresponding to the key, and then storing the key-value pair in one of the primary hash buckets or one of its spare hash buckets, load balancing of the hash table can be achieved.
[0087] Step 304: In response to receiving a read request for reading a second key-value pair, the first device uses at least two hash functions to address at least two second main hash buckets corresponding to the key in the second key-value pair.
[0088] The read request includes a keyword, which is used to index the second key-value pair requested by the read request. The keyword is the key in the second key-value pair. The implementation of this step can be referred to the relevant explanation of step 301 above, and will not be repeated here in the embodiments of this application.
[0089] Step 305: The first device queries the second key-value pair in the at least two second primary hash buckets and the spare hash buckets of the at least two second primary hash buckets.
[0090] Optionally, the first device first queries the at least two second primary hash buckets for the second key-value pair. If the second key-value pair is not found in the at least two second primary hash buckets, it then queries the spare hash buckets of the at least two second primary hash buckets for the second key-value pair. If the first device fails to find the second key-value pair in either the at least two second primary hash buckets or their spare hash buckets, it determines that the hash table does not store the second key-value pair. Further, the first device may return a query failure or a message indicating that the second key-value pair does not exist for the read request used to request the read of the second key-value pair.
[0091] In this embodiment of the application, when the device needs to perform a query operation on the hash table, it only needs to address the main hash bucket corresponding to the key, and then query the key-value pair in the main hash bucket and its backup hash buckets, which has high query efficiency.
[0092] The order of steps in the hash table management method provided in this application embodiment can be appropriately adjusted, and steps can be added or removed as needed. Steps 301 to 303 (hash table insertion operation) and steps 304 to 305 (hash table query operation) have no sequential relationship or step association. The first device may execute only steps 301 to 303, or only steps 304 to 305, or both. Any variations that can be easily conceived by those skilled in the art within the scope of the technology disclosed in this application should be included within the protection scope of this application.
[0093] In the above embodiments, the hash table is stored in a first device, and the first device performs insertion and / or query operations on the hash table, thus realizing the management of the local hash table by the first device, which can be a server. This application embodiment can also realize the management of a remote hash table by the first device, i.e., the hash table is stored in a second device, and the first device performs insertion and / or query operations on the hash table in the second device. In this application embodiment, the first device uses one-sided RDMA technology to implement insertion and / or query operations on the hash table in the second device. Wherein, the first device uses one-sided RDMA technology, meaning that the insertion and / or query operations on the hash table in the second device by the first device do not require the assistance of the processor in the second device.
[0094] Optionally, Figure 4 This is a schematic diagram of the structure of a hash table management system provided in an embodiment of this application. Figure 4 As shown, the management system includes a first device 101 and a second device 102, wherein the second device 102 stores a hash table. The first device 101 can be a server, and the second device 102 can also be a server. The first device 101 and the second device 102 are connected via an RDMA network, and the first device 101 performs query and / or insert operations on the hash table stored in the second device 102 via the RDMA network.
[0095] In an optional embodiment of this application, the first device 101 is used to perform an insertion operation on the hash table in the second device 102. Specifically, the first device 101, in response to receiving a write request for writing a first key-value pair, calculates at least two first hash positions corresponding to the key in the first key-value pair using at least two hash functions. The first device 101 sends at least two first read requests for one-sided RDMA to the second device 102, each first read request reading a main hash bucket and a spare hash bucket of the main hash bucket for a first hash position. The first device 101 determines the target empty slot for writing the first key-value pair in the read hash buckets. The first device 101 sends a CAS request for one-sided RDMA to the second device 102, the CAS request being used to lock the target empty slot. In response to successful locking of the target empty slot, the first device 101 sends a write request for one-sided RDMA to the second device 102, the write request being used to write the first key-value pair into the target empty slot.
[0096] In this embodiment, when the first device needs to perform an insertion operation on the hash table in the second device, it first calculates the hash position corresponding to the key. Each hash position has a main hash bucket. Then, the main hash bucket and its spare hash bucket corresponding to the key are read locally using one-sided RDMA. The key-value pair is then written locally into an empty slot in the main hash bucket or its spare hash bucket. Finally, it is written back to the second device using one-sided RDMA. This enables the first device to perform an insertion operation on the hash table in the second device using one-sided RDMA. Because the first device selectively reads the main hash bucket and its spare hash bucket corresponding to the key, the amount of data that the first device needs to read locally is small, the transmission resources required between the first and second devices are small, and the execution efficiency of the insertion operation is high.
[0097] Optionally, Figure 5 This is a schematic diagram illustrating the insertion operation flow of a hash table for RDMA provided in an embodiment of this application. Figure 5 As shown, the process includes:
[0098] Step 501: In response to receiving a write request for writing a first key-value pair, the first device uses at least two hash functions to calculate at least two first hash positions corresponding to the key in the first key-value pair.
[0099] The explanation of this step can be found in the relevant content of step 301 above, and will not be repeated here in the embodiments of this application.
[0100] Step 502: The first device sends at least two first read requests for one-sided RDMA to the second device. Each first read request is used to read the main hash bucket of a first hash position and the backup hash bucket of the main hash bucket.
[0101] Optionally, the first device concurrently sends at least two first read requests for one-sided RDMA to the second device. Since the main hash bucket and its spare hash bucket are stored in adjacent locations, a single read request can read both the main hash bucket and its spare hash bucket at once.
[0102] Step 503: The first device determines the target empty slot to write the first key-value pair in the read hash bucket.
[0103] In this embodiment, the main hash bucket read from the first hash position is called the first main hash bucket. The explanation of this step can be found in the relevant content of step 302 above, and will not be repeated here.
[0104] Step 504: The first device sends a CAS request for unilateral RDMA to the second device.
[0105] This CAS request is used to lock the target empty slot.
[0106] Step 505: In response to the successful locking of the target empty slot, the first device sends a one-sided RDMA write request to the second device. The write request is used to write the first key-value pair into the target empty slot.
[0107] The implementation process of step 505 includes: in response to the successful locking of the target empty slot, the first device writes the first key-value pair into the target empty slot locally, and then uses a one-sided RDMA write request to write the slot containing the first key-value pair back to the second device. The write request is also used to lock the slot (i.e., the aforementioned target empty slot) written back to the second device.
[0108] In another optional embodiment of this application, the first device 101 is used to perform a query operation on the hash table in the second device 102. Specifically, the first device 101, in response to receiving a read request for reading a second key-value pair, calculates at least two second hash positions corresponding to the key in the second key-value pair using at least two hash functions. The first device 101 sends at least two second read requests via one-sided RDMA to the second device 102, each second read request reading a main hash bucket and a spare hash bucket of a second hash position. The first device 101 queries the second key-value pair in the read hash buckets.
[0109] In this embodiment, when the first device needs to perform a query operation on the hash table in the second device, it first calculates the hash position corresponding to the key. Each hash position has a main hash bucket. Then, the main hash bucket and its spare hash bucket corresponding to the key are read locally using a one-sided RDMA method. Next, the key-value pair is queried from the main hash bucket and its spare hash bucket corresponding to the key. This enables the first device to perform a query operation on the hash table in the second device using a one-sided RDMA method. Because the first device selectively reads the main hash bucket and its spare hash bucket corresponding to the key, the amount of data that the first device needs to read locally is small, the transmission resources required between the first and second devices are small, and the amount of data that the first device needs to query is also small, resulting in high execution efficiency of the query operation.
[0110] Optionally, Figure 6 This is a schematic diagram illustrating a hash table query operation flow for RDMA provided in an embodiment of this application. For example... Figure 6 As shown, the process includes:
[0111] Step 601: In response to receiving a read request for reading the second key-value pair, the first device uses at least two hash functions to calculate at least two second hash positions corresponding to the key in the second key-value pair.
[0112] The explanation of this step can be found in the relevant content of step 301 above, and will not be repeated here in the embodiments of this application.
[0113] Step 602: The first device sends at least two second read requests for one-sided RDMA to the second device. Each second read request is used to read the main hash bucket of a second hash position and the spare hash bucket of the main hash bucket.
[0114] Optionally, the first device concurrently sends at least two second read requests via one-sided RDMA to the second device. Since the primary hash bucket and its spare hash bucket are stored in adjacent locations, a single read request can read both the primary hash bucket and its spare hash bucket at once.
[0115] In this embodiment of the application, the main hash bucket read from the second hash position is referred to as the second main hash bucket.
[0116] Step 603: The first device queries the second key-value pair in the read hash bucket.
[0117] Optionally, each time the first device reads a primary hash bucket and its backup hash bucket, it queries the second read request for the key. If the key is found, it retrieves the value corresponding to the key and stops processing subsequent received hash buckets. If the slot containing the key is locked, the first device resends a one-sided RDMA read request to read the hash bucket containing that slot again to obtain the second key-value pair.
[0118] In summary, the hash table management method provided in this application proposes a novel hash table structure. The hash table includes a primary hash bucket and adjacent backup hash buckets. When a device needs to perform an insertion operation on the hash table, it only needs to address the primary hash bucket corresponding to the key, and then insert the key-value pair into an empty slot in the primary hash bucket or its backup hash bucket, without needing to move the key-value pair, thus improving the device's storage performance. By using multiple hash functions to address multiple primary hash buckets corresponding to the key, and then storing the key-value pair in one of the primary hash buckets or one of the backup hash buckets of the primary hash bucket, load balancing of the hash table can be achieved. When a device needs to perform a query operation on the hash table, it only needs to address the primary hash bucket corresponding to the key, and then query the key-value pair in that primary hash bucket and its backup hash buckets, resulting in high query efficiency. In addition, it also implements a device to perform insertion and / or query operations on the hash table of another device via unilateral RDMA. In this process, the transmission resources required between the two devices are small, and the operation execution efficiency is high.
[0119] Figure 7This is a schematic diagram of a hash table management device provided in an embodiment of this application. The hash table includes a primary hash bucket and a secondary hash bucket. The primary hash bucket can be addressed by a hash function, while the secondary hash bucket cannot be addressed by a hash function. The secondary hash bucket is located between the two primary hash buckets and is shared by both primary hash buckets. Figure 7 As shown, the device 70 includes:
[0120] The first addressing module 701 is configured to, in response to receiving a write request for writing a first key-value pair, use at least two hash functions to address at least two first main hash buckets corresponding to the keys in the first key-value pair.
[0121] The determination module 702 is used to determine the target empty slot for writing the first key-value pair in at least two first primary hash buckets and at least two spare hash buckets of the first primary hash buckets.
[0122] The write module 703 is used to write the first key-value pair to the target empty slot.
[0123] Optionally, the determining module 702 is configured to: determine a target hash bucket among at least two first primary hash buckets and spare hash buckets of the at least two first primary hash buckets, the target hash bucket including one or more empty slots; and determine the unlocked empty slots in the target hash bucket as target empty slots.
[0124] Optionally, the determining module 702 is configured to: determine a target hash bucket among at least two first primary hash buckets in response to the existence of hash buckets including empty slots among at least two first primary hash buckets; or, determine a target hash bucket among spare hash buckets of at least two first primary hash buckets in response to the absence of hash buckets including empty slots among at least two first primary hash buckets.
[0125] Optionally, the determining module 702 is configured to: in response to the existence of hash buckets including empty slots in at least two first primary hash buckets, determine the hash bucket with the most empty slots among the at least two first primary hash buckets as the target hash bucket.
[0126] Optionally, the determining module 702 is used to: determine the hash bucket with the most empty slots among the spare hash buckets of at least two first primary hash buckets as the target hash bucket.
[0127] Optionally, the device 70 is applied to a first device, and the hash table is stored in a second device. The first addressing module 701 is configured to: in response to receiving a write request for writing a first key-value pair, calculate at least two first hash positions corresponding to the key in the first key-value pair using at least two hash functions; and then send at least two first read requests for one-sided RDMA to the second device, each first read request being used to read the main hash bucket and the backup hash bucket of the main hash bucket for one first hash position. Correspondingly, the write module 703 is configured to: send a CAS request for one-sided RDMA to the second device, the CAS request being used to lock the target empty slot; and in response to successful locking of the target empty slot, send a write request for one-sided RDMA to the second device, the write request being used to write the first key-value pair into the target empty slot.
[0128] Optionally, such as Figure 8 As shown, device 70 also includes:
[0129] The second addressing module 704 is configured to, in response to receiving a read request for reading a second key-value pair, use at least two hash functions to address at least two second main hash buckets corresponding to the key in the second key-value pair. The query module 705 is configured to query the second key-value pair in at least two second main hash buckets and at least two spare hash buckets of the second main hash buckets.
[0130] Optionally, the device 70 is applied to the first device, the hash table is stored in the second device, and the second addressing module 704 is used to: in response to receiving a read request for requesting to read the second key-value pair, calculate at least two second hash positions corresponding to the key in the second key-value pair using at least two hash functions respectively; and send at least two second read requests for one-sided RDMA to the second device, each second read request being used to read the main hash bucket and the backup hash bucket of the main hash bucket for a second hash position.
[0131] Optionally, the primary hash buckets and backup hash buckets in the hash table are arranged alternately, or the hash table includes multiple hash bucket groups arranged sequentially, each hash bucket group including two primary hash buckets and a backup hash bucket located between the two primary hash buckets.
[0132] In summary, in the hash table management device provided in this application embodiment, when the device needs to perform an insertion operation on the hash table, it only needs to address the main hash bucket corresponding to the key through the first addressing module, and then insert the key-value pair into the empty slot of the main hash bucket or its spare hash bucket through the write module, without moving the key-value pair, thus improving the storage performance of the device. By using multiple hash functions to address multiple main hash buckets corresponding to the key, and then storing the key-value pair in one of the main hash buckets or one of the spare hash buckets of the main hash bucket, load balancing of the hash table can be achieved. When the device needs to perform a query operation on the hash table, it only needs to address the main hash bucket corresponding to the key through the second addressing module, and then query the key-value pair in the main hash bucket and its spare hash bucket through the query module, resulting in high query efficiency. In addition, it also realizes that one device can perform insertion and / or query operations on the hash table of another device through a one-sided RDMA method. In this process, the transmission resources required between the two devices are small, and the operation execution efficiency is high.
[0133] Figure 9 This is a schematic diagram of another hash table management device provided in an embodiment of this application. The hash table includes a primary hash bucket and a secondary hash bucket. The primary hash bucket can be addressed by a hash function, while the secondary hash bucket cannot be addressed by a hash function. The secondary hash bucket is located between the two primary hash buckets and is shared by both primary hash buckets. Figure 9 As shown, the device 90 includes:
[0134] The first addressing module 901 is configured to, in response to receiving a read request for reading a first key-value pair, use at least two hash functions to address at least two first main hash buckets corresponding to the keys in the first key-value pair.
[0135] The query module 902 is used to query the first key-value pair in at least two first primary hash buckets and at least two spare hash buckets of the first primary hash buckets.
[0136] Optionally, such as Figure 10 As shown, the device 90 further includes: a second addressing module 903, configured to, in response to receiving a write request for writing a second key-value pair, address at least two second main hash buckets corresponding to the key in the second key-value pair using at least two hash functions; a determining module 904, configured to determine a target empty slot for writing the second key-value pair among the at least two second main hash buckets and spare hash buckets of the at least two second main hash buckets; and a writing module 905, configured to write the second key-value pair to the target empty slot.
[0137] In summary, in the hash table management device provided in this application embodiment, when the device needs to perform an insertion operation on the hash table, it only needs to address the main hash bucket corresponding to the key through the second addressing module, and then insert the key-value pair into the empty slot of the main hash bucket or its spare hash bucket through the write module, without moving the key-value pair, thus improving the storage performance of the device. By using multiple hash functions to address multiple main hash buckets corresponding to the key, and then storing the key-value pair in one of the main hash buckets or one of the spare hash buckets of the main hash bucket, load balancing of the hash table can be achieved. When the device needs to perform a query operation on the hash table, it only needs to address the main hash bucket corresponding to the key through the first addressing module, and then query the key-value pair in the main hash bucket and its spare hash bucket through the query module, resulting in high query efficiency. In addition, it also realizes that one device can perform insertion and / or query operations on the hash table of another device through a one-sided RDMA method. In this process, the transmission resources required between the two devices are small, and the operation execution efficiency is high.
[0138] Regarding the apparatus in the above embodiments, the specific manner in which each module performs its operation has been described in detail in the embodiments related to the method, and will not be elaborated upon here.
[0139] Figure 11 This is a block diagram of a device provided in an embodiment of this application. The device may be a server. Figure 11 As shown, device 110 includes a processor 1101 and a memory 1102.
[0140] Memory 1102 is used to store a computer program, the computer program including program instructions;
[0141] The processor 1101 is used to call the computer program to implement the actions performed by the first device in the above method embodiment.
[0142] Optionally, the device 110 also includes a communication bus 1103 and a communication interface 1104.
[0143] The processor 1101 includes one or more processing cores, and the processor 1101 executes various functional applications and data processing by running computer programs.
[0144] The memory 1102 can be used to store computer programs. Optionally, the memory can store the operating system and application program units required for at least one function. The operating system can be a real-time operating system (RTX), Linux, UNIX, Windows, or OS X.
[0145] There can be multiple communication interfaces 1104, which are used to communicate with other devices. For example, in this embodiment, the communication interface 1104 of the first device can be used to send a unilateral RDMA request to the second device.
[0146] The memory 1102 and the communication interface 1104 are respectively connected to the processor 1101 via the communication bus 1103.
[0147] This application also provides a computer storage medium storing instructions that, when executed by a processor, implement the actions performed by the first device in the above method embodiments. Optionally, the computer storage medium is a non-volatile computer-readable storage medium.
[0148] Those skilled in the art will understand that all or part of the steps of the above embodiments can be implemented by hardware or by a program instructing related hardware. The program can be stored in a computer-readable storage medium, such as a read-only memory, a disk, or an optical disk.
[0149] In the embodiments of this application, the terms "first," "second," and "third" are used for descriptive purposes only and should not be construed as indicating or implying relative importance.
[0150] In this application, the term "and / or" is merely a description of the relationship between related objects, indicating that three relationships can exist. For example, A and / or B can represent: A existing alone, A and B existing simultaneously, or B existing alone. Additionally, the character " / " in this document generally indicates that the preceding and following related objects have an "or" relationship.
[0151] The above description is merely an optional embodiment of this application and is not intended to limit this application. Any modifications, equivalent substitutions, improvements, etc., made within the concept and principles of this application should be included within the protection scope of this application.
Claims
1. A method for managing hash tables, characterized in that, The hash table includes a primary hash bucket and a backup hash bucket, which are arranged alternately. Alternatively, the hash table includes multiple hash bucket groups arranged sequentially, each hash bucket group including two primary hash buckets and a backup hash bucket located between the two primary hash buckets. The primary hash buckets can be addressed by a hash function, while the backup hash buckets cannot be addressed by a hash function. The backup hash bucket adjacent to a primary hash bucket is a backup hash bucket of that primary hash bucket, and the backup hash bucket is shared by the two primary hash buckets. The method includes: In response to receiving a write request for writing a first key-value pair, the first device uses at least two hash functions to address at least two first main hash buckets corresponding to the key in the first key-value pair; In response to the absence of empty slots in any of the at least two first primary hash buckets, the first device determines the hash bucket with the most empty slots among the spare hash buckets of the at least two first primary hash buckets as the target hash bucket. The first device identifies the unlocked empty slots in the target hash bucket as target empty slots; The first device writes the first key-value pair into the target empty slot.
2. The method according to claim 1, characterized in that, In response to receiving a write request for writing the first key-value pair, the first device further includes: In response to the presence of an empty slot in one of the at least two first primary hash buckets, the first device determines the target hash bucket among the at least two first primary hash buckets.
3. The method according to claim 2, characterized in that, The first device determines the target hash bucket from the at least two first primary hash buckets, including: The first device determines the hash bucket with the most empty slots among the at least two first main hash buckets as the target hash bucket.
4. The method according to any one of claims 1 to 3, characterized in that, The hash table is stored in the second device. In response to receiving a write request for writing a first key-value pair, the first device uses at least two hash functions to address at least two first main hash buckets corresponding to the keys in the first key-value pair, including: In response to receiving a write request for writing a first key-value pair, the first device uses the at least two hash functions to calculate at least two first hash positions corresponding to the key in the first key-value pair. The first device sends at least two first read requests for one-sided remote direct memory access (RDMA) to the second device, each first read request being used to read a primary hash bucket and a backup hash bucket of the primary hash bucket at a first hash location; The first device writes the first key-value pair into the target empty slot, including: The first device sends a unilateral RDMA Compare and Exchange (CAS) request to the second device, the CAS request being used to lock the target empty slot; In response to successfully locking the target empty slot, the first device sends a one-sided RDMA write request to the second device, the write request being used to write the first key-value pair into the target empty slot.
5. The method according to any one of claims 1 to 3, characterized in that, The method further includes: In response to receiving a read request for reading a second key-value pair, the first device uses the at least two hash functions to address at least two second main hash buckets corresponding to the key in the second key-value pair; The first device queries the second key-value pair in the at least two second primary hash buckets and the spare hash buckets of the at least two second primary hash buckets.
6. The method according to claim 5, characterized in that, The hash table is stored in a second device. In response to receiving a read request for reading a second key-value pair, the first device uses the at least two hash functions to address at least two second main hash buckets corresponding to the keys in the second key-value pair, including: In response to receiving a read request for reading a second key-value pair, the first device uses the at least two hash functions to calculate at least two second hash positions corresponding to the key in the second key-value pair. The first device sends at least two second read requests for one-sided RDMA to the second device, each second read request being used to read the main hash bucket of a second hash location and the backup hash bucket of the main hash bucket.
7. A method for managing hash tables, characterized in that, The hash table includes a primary hash bucket and a backup hash bucket, which are arranged alternately. Alternatively, the hash table includes multiple hash bucket groups arranged sequentially, each hash bucket group including two primary hash buckets and a backup hash bucket located between the two primary hash buckets. The primary hash buckets can be addressed by a hash function, while the backup hash buckets cannot be addressed by a hash function. The backup hash bucket adjacent to a primary hash bucket is a backup hash bucket of that primary hash bucket, and the backup hash bucket is shared by the two primary hash buckets. The method includes: In response to receiving a read request for reading a first key-value pair, the first device uses at least two hash functions to address at least two first main hash buckets corresponding to the key in the first key-value pair; The first device queries the first key-value pair in the at least two first primary hash buckets and the spare hash buckets of the at least two first primary hash buckets.
8. The method according to claim 7, characterized in that, The method further includes: In response to receiving a write request for writing to the second key-value pair, the first device uses the at least two hash functions to address at least two second main hash buckets corresponding to the key in the second key-value pair; The first device determines the target empty slot for writing the second key-value pair in the at least two second main hash buckets and the spare hash buckets of the at least two second main hash buckets; The first device writes the second key-value pair into the target empty slot.
9. A hash table management device, characterized in that, The hash table includes a primary hash bucket and a secondary hash bucket, which are arranged alternately. Alternatively, the hash table includes multiple hash bucket groups arranged sequentially, each hash bucket group including two primary hash buckets and a secondary hash bucket located between the two primary hash buckets. The primary hash buckets can be addressed by a hash function, while the secondary hash buckets cannot be addressed by a hash function. The secondary hash bucket adjacent to a primary hash bucket is a secondary hash bucket of that primary hash bucket, and the secondary hash bucket is shared by the two primary hash buckets. The device includes: The first addressing module is configured to, in response to receiving a write request for writing a first key-value pair, use at least two hash functions to address at least two first main hash buckets corresponding to the key in the first key-value pair; The determination module is configured to, in response to the absence of any hash bucket including empty slots in the at least two first primary hash buckets, determine the hash bucket with the most empty slots among the spare hash buckets of the at least two first primary hash buckets as the target hash bucket; and determine the unlocked empty slots in the target hash bucket as target empty slots. A write module is used to write the first key-value pair into the target empty slot.
10. The apparatus according to claim 9, characterized in that, The determining module is further configured to: In response to the presence of an empty slot in one of the at least two first primary hash buckets, the target hash bucket is determined among the at least two first primary hash buckets.
11. The apparatus according to claim 10, characterized in that, The determining module is used for: In response to the existence of a hash bucket with empty slots in the at least two first primary hash buckets, the hash bucket with the most empty slots among the at least two first primary hash buckets is determined as the target hash bucket.
12. The apparatus according to any one of claims 9 to 11, characterized in that, The device is applied to a first device, the hash table is stored in a second device, and the first addressing module is used for: In response to receiving a write request for writing a first key-value pair, the at least two hash functions are used to calculate at least two first hash positions corresponding to the key in the first key-value pair. Send at least two first read requests for one-sided remote direct memory access (RDMA) to the second device, each first read request being used to read a primary hash bucket and a backup hash bucket of the primary hash bucket at a first hash location; The write module is used for: Send a unilateral RDMA Compare and Exchange (CAS) request to the second device, the CAS request being used to lock the target empty slot; In response to the successful locking of the target empty slot, a one-sided RDMA write request is sent to the second device, the write request being used to write the first key-value pair into the target empty slot.
13. The apparatus according to any one of claims 9 to 11, characterized in that, The device further includes: The second addressing module is used to, in response to receiving a read request for reading a second key-value pair, address at least two second main hash buckets corresponding to the key in the second key-value pair using the at least two hash functions; The query module is used to query the second key-value pair in the at least two second primary hash buckets and the spare hash buckets of the at least two second primary hash buckets.
14. The apparatus according to claim 13, characterized in that, The device is applied to a first device, the hash table is stored in a second device, and the second addressing module is used for: In response to receiving a read request for reading a second key-value pair, at least two second hash positions corresponding to the key in the second key-value pair are calculated using the at least two hash functions respectively; Send at least two second read requests for one-sided RDMA to the second device, each second read request being used to read the main hash bucket of a second hash location and the spare hash bucket of the main hash bucket.
15. A hash table management device, characterized in that, The hash table includes a primary hash bucket and a secondary hash bucket, which are arranged alternately. Alternatively, the hash table includes multiple hash bucket groups arranged sequentially, each hash bucket group including two primary hash buckets and a secondary hash bucket located between the two primary hash buckets. The primary hash buckets can be addressed by a hash function, while the secondary hash buckets cannot be addressed by a hash function. The secondary hash bucket adjacent to a primary hash bucket is a secondary hash bucket of that primary hash bucket, and the secondary hash bucket is shared by the two primary hash buckets. The device includes: The first addressing module is configured to, in response to receiving a read request for reading a first key-value pair, use at least two hash functions to address at least two first main hash buckets corresponding to the key in the first key-value pair; The query module is used to query the first key-value pair in the at least two first primary hash buckets and the spare hash buckets of the at least two first primary hash buckets.
16. The apparatus according to claim 15, characterized in that, The device further includes: The second addressing module is configured to, in response to receiving a write request for writing a second key-value pair, use the at least two hash functions to address at least two second main hash buckets corresponding to the key in the second key-value pair; A determining module is used to determine the target empty slot for writing the second key-value pair in the at least two second main hash buckets and the spare hash buckets of the at least two second main hash buckets; A write module is used to write the second key-value pair into the target empty slot.
17. A hash table management system, characterized in that, include: A first device and a second device, wherein the second device stores a hash table, the hash table including a main hash bucket and a spare hash bucket, the main hash bucket and the spare hash bucket in the hash table are arranged alternately, or the hash table includes a plurality of hash bucket groups arranged sequentially, each hash bucket group including two main hash buckets and a spare hash bucket located between the two main hash buckets, the main hash buckets can be addressed by a hash function, the spare hash buckets cannot be addressed by a hash function, the spare hash bucket adjacent to the main hash bucket is the spare hash bucket of the main hash bucket, and the spare hash bucket is shared by the two main hash buckets; The first device is configured to, in response to receiving a write request for writing a first key-value pair, use at least two hash functions to calculate at least two first hash positions corresponding to the key in the first key-value pair. The first device is configured to send at least two first read requests for one-sided remote direct memory access (RDMA) to the second device, each first read request being configured to read a primary hash bucket and a spare hash bucket of the primary hash bucket at a first hash location. The first device is used to determine the target empty slot for writing the first key-value pair within the read hash bucket. The first device is used to send a unilateral RDMA Compare and Exchange (CAS) request to the second device, the CAS request being used to lock the target empty slot. The first device is configured to send a one-sided RDMA write request to the second device in response to the successful locking of the target empty slot, the write request being used to write the first key-value pair into the target empty slot; And / or, The first device is configured to, in response to receiving a read request for reading a second key-value pair, use the at least two hash functions to calculate at least two second hash positions corresponding to the key in the second key-value pair. The first device is configured to send at least two second read requests for one-sided RDMA to the second device, each second read request being used to read the main hash bucket and the spare hash bucket of the main hash bucket for a second hash location. The first device is used to query the second key-value pair in the read hash bucket.
18. A device, characterized in that, include: Processor and memory; The memory is used to store computer programs, the computer programs including program instructions; The processor is used to invoke the computer program to implement the hash table management method as described in any one of claims 1 to 8.
19. A computer storage medium, characterized in that, The computer storage medium stores instructions that, when executed by a processor, implement the hash table management method as described in any one of claims 1 to 8.
Citation Information
Patent Citations
Hash table construction method and system for nonvolatile memory
CN107153707A
Persistent hash table access system supporting remote concurrent access
CN111400307A