Data storage method, device, electronic device and storage medium

By migrating inactive linked lists in the hash table to hard disk storage, the problem of insufficient memory storage space is solved, and only active data is stored in the memory, which improves the effective utilization of memory and avoids resource waste.

CN115391335BActive Publication Date: 2025-09-26NETEASE (HANGZHOU) NETWORK CO LTD
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202210901849.0
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2022-07-28
Publication Date
2025-09-26
Estimated Expiration
2042-07-28

AI Technical Summary

Technical Problem

As the number of player accounts increases, the storage space occupied by the hash table continues to increase, leading to the problem of insufficient memory storage space. At the same time, due to the phenomenon of game players returning, the data in the hash table cannot be deleted at will, resulting in low effective memory occupancy and waste of resources.

Method used

By storing active linked lists in memory and inactive linked lists in hard disk, it is ensured that only currently active data is stored in memory. By using a mixed storage method of memory and hard disk, insufficient memory is avoided and the effective memory usage is improved.

Benefits of technology

Without expanding the memory storage space, complete storage of business data is achieved, the effective memory occupancy rate is improved, and the waste of memory resources is avoided.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN115391335B_ABST
    Figure CN115391335B_ABST
Patent Text Reader

Abstract

The present application provides a data storage method, device, electronic device and storage medium, which relate to the field of computer technology, including: receiving a storage request for data to be stored containing first data and second data, and generating a first memory unit address for the first data in response to the storage request. When the number of memory unit addresses already existing in the hash table is equal to the preset number of addresses, determine the inactive linked list in the linked list corresponding to the hash table that meets the specified conditions. Store the data stored in the inactive linked list in the hard disk, and delete the inactive linked list in the memory. Delete the memory unit address in the hash table that points to the inactive linked list. Store the first memory unit address in the hash table, and store the first data and the second data in the target linked list pointed to by the first memory unit address in the form of a data pair. The embodiment of the present application can not only ensure the storage of complete business data, but also avoid the occurrence of insufficient memory.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the field of computer technology, and in particular to a data storage method, device, electronic device, and storage medium. Background Art

[0002] A hash table is a data structure that allows direct access based on a key value, storing related data in a two-layer structure called an array and a linked list. Specifically, a key value can be mapped to a memory location in the hash table to directly access the record, speeding up lookups.

[0003] In gaming, game data for multiple player accounts can be stored in a hash table. The entire hash table is stored in memory. To store game data for a new player account, a memory cell address is generated based on the new player account's information. A new node is then added to the linked list pointed to by the memory cell address, and the game data for the new player account is stored in the newly added node.

[0004] As the number of player accounts continues to grow, the storage space occupied by the hash table will continue to increase, which will easily lead to insufficient memory storage issues. Due to the frequent phenomenon of player relapse (players returning to the game after six months of absence), the data in the hash table cannot be deleted at will. Therefore, how to solve the storage problem of the hash table without deleting the data has become an urgent problem. Summary of the Invention

[0005] In view of this, the present application provides a data storage method, apparatus, and electronic device, namely, a storage medium. Active linked lists are stored in memory and inactive linked lists are stored on a hard disk based on their update time. In this way, a certain number of linked lists are always stored in memory. This ensures that only currently active data is stored in memory without deleting stored data, while also preventing memory shortages.

[0006] A first aspect of an embodiment of the present application provides a data storage method. When storing data including first historical data and second historical data, a memory unit address generated for the first historical data is stored in a hash table, and the first historical data and the second historical data are stored in a data pair in a linked list pointed to by the memory unit address. The method includes:

[0007] A storage request for data to be stored, which includes first data and second data, is received, and a first memory unit address for the first data is generated in response to the storage request.

[0008] When the number of memory unit addresses already in the hash table is equal to the preset number of addresses, an inactive linked list that meets a specified condition in the linked list corresponding to the hash table is determined, wherein the inactive linked list is a linked list that has not been accessed within a preset time period.

[0009] The data stored in the inactive linked list is stored in the hard disk, and the inactive linked list is deleted in the memory.

[0010] Delete the memory unit address in the hash table that points to the inactive linked list.

[0011] The first memory unit address is stored in a hash table, and the first data and the second data are stored in a data pair in a target linked list pointed to by the first memory unit address.

[0012] In an optional embodiment, the method further comprises:

[0013] When the number of memory unit addresses already existing in the hash table is less than the preset number of addresses, it is determined whether the hash table stores the first memory unit address.

[0014] If the hash table stores the first memory unit address, the first data and the second data are stored in a data pair in the target linked list pointed to by the first memory unit.

[0015] In an optional embodiment, the method further comprises:

[0016] If the first memory unit address is not stored in the hash table, the first memory unit address is stored in the hash table.

[0017] A target linked list pointed to by the first memory unit address is established in the memory, and the first data and the second data are stored in the target linked list in a data pair manner.

[0018] In an optional embodiment, before establishing the target linked list in the memory, the method further includes:

[0019] Check whether the hard disk stores the first data and the second data.

[0020] If the hard disk stores the first data and the second data, the linked list storing the first data and the second data in the hard disk is determined as the target linked list.

[0021] Create a target linked list in memory, including:

[0022] Restore the target linked list from the hard disk to the memory.

[0023] In an optional implementation, determining an inactive linked list in a linked list corresponding to the hash table that meets a specified condition includes:

[0024] Get the last access time of all linked lists corresponding to the hash table respectively.

[0025] Sort all linked lists by priority based on the last access time.

[0026] According to the priority sorting result, the linked list with the earliest last access time is determined to be the inactive linked list.

[0027] In an optional embodiment, the method further comprises:

[0028] After the first data and the second data are stored in the target linked list, the last access time of the target linked list is updated.

[0029] Or after restoring the target linked list from the hard disk to the memory, the last access time of the target linked list is updated.

[0030] In an optional embodiment, the first data includes an account identifier and a server identifier. Generating a first memory unit address for the first data includes:

[0031] Perform a hash operation on the account identifier to obtain an initial hash value.

[0032] A first memory unit address of the first data is obtained according to the initial hash value and the server identifier.

[0033] In an optional embodiment, when the server identifiers corresponding to the multiple data to be stored are the same, the target linked lists pointed to by the multiple first memory unit addresses corresponding to the multiple data to be stored are the same.

[0034] In an optional embodiment, the method further comprises:

[0035] A query request for data to be queried including first data is received, and a first memory unit address for the first data is determined in response to the query request.

[0036] When the first memory unit address does not exist in the hash table, it is queried whether a data pair including the first data is stored in the hard disk.

[0037] When the hard disk stores a target linked list of data pairs containing the first data, the second data included in the data pairs is fed back according to the query request.

[0038] The target linked list is restored to the memory, and the first memory unit address is stored in the hash table.

[0039] In an optional embodiment, the method further comprises:

[0040] When the first memory unit address exists in the hash table, a target linked list pointed to by the first memory unit address is determined in the memory.

[0041] Determine the second data corresponding to the first data according to the data pairs included in the target linked list.

[0042] In response to the query request, second data is sent.

[0043] In an optional implementation, after sending the second data, the method further includes:

[0044] The last access time of the target linked list is updated according to the sending time of the second data.

[0045] A second aspect of an embodiment of the present application provides a data storage device that, when storing data containing first historical data and second historical data, stores memory unit addresses generated for the first historical data in a hash table, and stores the first historical data and the second historical data in a data pair format using a linked list pointed to by the memory unit addresses. The data storage device includes:

[0046] The receiving unit is configured to receive a storage request for data to be stored, which includes first data and second data.

[0047] A generating unit is configured to generate a first memory unit address for the first data in response to a storage request.

[0048] The determining unit is configured to determine, when the number of memory unit addresses already existing in the hash table is equal to a preset number of addresses, an inactive linked list in the linked list corresponding to the hash table that meets a specified condition. The inactive linked list is a linked list that has not been accessed within a preset time period.

[0049] The storage unit is used to store the data stored in the inactive linked list in the hard disk.

[0050] The processing unit is configured to delete the inactive linked list from the memory; and delete the memory unit address pointing to the inactive linked list in the hash table.

[0051] The storage unit is further configured to store the first memory unit address in a hash table, and store the first data and the second data in a data pair in a target linked list pointed to by the first memory unit address.

[0052] In an optional embodiment, the data storage unit further includes a judgment unit.

[0053] The judging unit is configured to judge whether the first memory unit address is stored in the hash table when the number of memory unit addresses already existing in the hash table is less than a preset number of addresses.

[0054] The storage unit is further configured to store the first data and the second data in a data pair in the target linked list pointed to by the first memory unit if the judging unit judges that the hash table stores the first memory unit address.

[0055] In an optional embodiment, the storage unit is further configured to store the first memory unit address in the hash table if the first memory unit address is not stored in the hash table, establish a target linked list pointed to by the first memory unit address in the memory, and store the first data and the second data in the target linked list as data pairs.

[0056] In an optional implementation, the judgment unit is further configured to query whether the hard disk stores the first data and the second data.

[0057] The determining unit is further configured to determine the linked list storing the first data and the second data in the hard disk as the target linked list when the judging unit determines that the first data and the second data are stored in the hard disk.

[0058] The storage unit is specifically used to restore the target linked list from the hard disk to the memory.

[0059] In an optional embodiment, the determining unit is specifically configured to obtain the last access time of each linked list corresponding to the hash table, prioritize all linked lists based on the last access time, and determine, based on the priority sorting result, that the linked list with the earliest last access time is the inactive linked list.

[0060] In an optional embodiment, the processing unit is further configured to update the last access time of the target linked list after the first data and the second data are stored in the target linked list, or to update the last access time of the target linked list after the target linked list is restored from the hard disk to the memory.

[0061] In an optional embodiment, the first data includes an account identifier and a server identifier. The generating unit is specifically configured to perform a hash operation on the account identifier to obtain an initial hash value. Based on the initial hash value and the server identifier, the first memory unit address of the first data is obtained.

[0062] In an optional embodiment, when the server identifiers corresponding to the multiple data to be stored are the same, the target linked lists pointed to by the multiple first memory unit addresses corresponding to the multiple data to be stored are the same.

[0063] In an optional embodiment, the receiving unit is further configured to receive a query request for the data to be queried including the first data, and determine the first memory unit address for the first data in response to the query request.

[0064] The processing unit is further configured to, when the first memory unit address does not exist in the hash table, query whether a data pair including the first data is stored in the hard disk, and, when a target linked list including the data pair including the first data is stored in the hard disk, feedback the second data included in the data pair according to the query request.

[0065] The storage unit is further used to restore the target linked list to the memory and store the first memory unit address in the hash table.

[0066] In an optional embodiment, the determining unit is further configured to, when the first memory unit address exists in the hash table, determine in the memory a target linked list pointed to by the first memory unit address, and determine, based on data pairs included in the target linked list, second data corresponding to the first data.

[0067] The processing unit is further configured to respond to the query request and send the second data.

[0068] In an optional embodiment, the processing unit is further configured to update the last access time of the target linked list according to the sending time of the second data after sending the second data.

[0069] A third aspect of an embodiment of the present application further provides an electronic device, including: a memory and a processor, wherein the memory and the processor are coupled.

[0070] The memory is used to store one or more computer instructions.

[0071] The processor is used to execute one or more computer instructions to implement the data storage method described in the first aspect above.

[0072] The fourth aspect of the embodiments of the present application further provides a computer-readable storage medium on which one or more computer instructions are stored, characterized in that the instructions are executed by a processor to implement the data storage method described in any of the above technical solutions.

[0073] The technical solution provided by the embodiment of the present application can store business data in a mixed manner in memory and hard disk. First, the hash table stored in the memory is used to store memory cell addresses, and each memory cell address is a different linked list in the memory, and the linked list stores business data (first data and second data) in the form of data pairs. When a storage request containing data to be stored is received, the first memory cell address is first generated according to the first data in the data to be stored, and then it is determined whether the hash table has room to store the first memory cell address. If there is no room in the hash table, an inactive linked list that has not been accessed for a long time is searched in the multiple linked lists corresponding to the hash table. The inactive linked list is then stored in the hard disk, and the memory cell address corresponding to the inactive linked list in the hash table is deleted. In this way, a portion of the memory storage space will be released. The first memory cell address is then stored in the hash table, and a target linked list pointed to by the first memory cell address is established in the memory, and finally the data to be stored is stored in the target linked list, thereby achieving the purpose of storing the data to be stored in the memory.

[0074] In the above technical solution, inactive linked lists are moved to the hard disk for storage before creating a new target linked list in memory, thus avoiding the problem of insufficient memory. Using both memory and hard disk to store business data allows for complete storage of business data without expanding memory storage space. Furthermore, this method ensures that the business data stored in memory is frequently accessed or recently updated, while inactive business data is moved to the hard disk for storage. This improves effective memory usage and avoids wasting memory resources. BRIEF DESCRIPTION OF THE DRAWINGS

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

[0076] Figure 1 This is a flow chart of a data storage method provided by an embodiment of the present application;

[0077] Figure 2 A flowchart of a data reading method provided in an embodiment of the present application;

[0078] Figure 3 This is a structural diagram of a data storage device provided in an embodiment of the present application;

[0079] Figure 4 This is a structural diagram of an electronic device provided in an embodiment of the present application. DETAILED DESCRIPTION

[0080] This application provides a data storage method, device, and electronic device, namely, a storage medium. Active linked lists are stored in memory and inactive linked lists are stored on a hard disk based on their update time. This ensures that a certain number of linked lists are always stored in memory. This ensures that only currently active data is stored in memory without deleting stored data, while also preventing memory shortages.

[0081] In order to enable those skilled in the art to better understand the technical solutions of this application, the following clearly and completely describes this application in conjunction with the drawings in the embodiments of this application. However, this application can be implemented in many other ways different from the above description. Therefore, based on the embodiments provided in this application, all other embodiments obtained by those skilled in the art without creative work should fall within the scope of protection of this application.

[0082] It should be noted that the terms "first", "second", "third", etc. in the claims, description and drawings of the present application are used to distinguish similar objects and are not used to describe a specific order or sequence. The data used in this way are interchangeable where appropriate, so that the embodiments of the present application described herein can be implemented in a sequence other than that illustrated or described herein. In addition, the terms "including", "having" and their variations are intended to cover non-exclusive inclusions. For example, a process, method, system, product or device that includes a series of steps or units is not necessarily limited to those steps or units clearly listed, but may include other steps or units that are not clearly listed or inherent to these processes, methods, products or devices.

[0083] A hash table, also known as a hash table, is a data structure that directly accesses data based on a key value. In other words, a hash table accesses data by mapping the key value to a location in a linked list, which speeds up the search. Specifically, when a key is given, the key can be calculated using a hash function, and the result is the storage location in the linked list corresponding to the key. The essence of a hash table is an array, which is used to store the memory unit address corresponding to each stored data. Hash tables generally use a two-layer structure of "array + linked list" for data storage, so that the access efficiency of each data is close to O(1).

[0084] In online gaming scenarios, hash tables can be used to store each player's game data. For example, a player's level data, equipment data, or game record data can all be stored using a hash table. In a hash table, a player's game data can be recorded using key-value pairs (data pairs). The player's account data serves as the key, and the game data associated with that account serves as the value. When querying game data, the hash table can be queried based on the player's account data. The hash table can then be used to determine the storage location of the game data, and the game data can then be directly read from that storage location. Specifically, a hash operation can be performed on the player's account data, and the hash result can be used to determine the memory cell address of the account. The hash table can then be queried to obtain the linked list structure pointed to by the memory cell address. The target memory cell in the linked list structure can then be found based on the memory cell address. The data stored in the target memory cell can then be read to obtain the game data corresponding to the account.

[0085] As the number of player accounts continues to grow, the number of key-value pairs will continue to increase, and the memory storage space corresponding to the entire hash table will also continue to increase. This will inevitably lead to insufficient memory storage space. In the gaming business, due to the frequent phenomenon of player relapse (players returning to the game after six months of absence), the stored data in the hash table cannot be arbitrarily deleted. Storing a large amount of game data of inactive players in memory will also lead to low effective memory utilization and serious waste of memory resources. Therefore, how to improve effective memory utilization and solve the problem of insufficient memory storage space has become an urgent problem.

[0086] To address the above issues, the present application provides a data storage method, device, and electronic device, namely, a storage medium. This method allows for complete storage of business data without expanding memory storage space. By storing active linked lists in memory and inactive linked lists on the hard disk based on update time, it ensures that only currently active data is stored in memory. This improves the effective memory usage and reduces the waste of memory resources. The method, device, terminal, and computer-readable storage medium of the present application are further described in detail below in conjunction with specific embodiments and accompanying drawings.

[0087] The following describes the process of using a hash table to store business data and the process of using a hash table to read business data:

[0088] (1) The process of using hash tables to store business data:

[0089] Figure 1 A flowchart of a data storage method provided in an embodiment of the present application is provided. It should be noted that the steps shown in the flowchart can be executed in a computer system such as a set of computer-executable instructions, and in some cases, the steps shown can be executed in a logical order different from that shown in the flowchart.

[0090] like Figure 1 As shown, the data storage method provided in the embodiment of the present application includes the following steps:

[0091] 101. Receive a storage request for data to be stored.

[0092] When a request is received for new data to be stored, a storage space must be allocated in the memory to ensure that the newly added data is stored in the memory. This is because the memory has a fast read speed, which makes it easier for users to quickly query stored data.

[0093] The data to be stored includes first data and second data, which correspond to each other. For example, if the data to be stored is game data, the first data may be player account data, and the second data may be the game data corresponding to the player account. Specifically, the first data and the second data may be stored in a data pair (key-value pair) format to facilitate user query.

[0094] 102. Determine a first memory unit address according to first data in the data to be stored.

[0095] When storing data in memory, a hash table can be used. First, a memory cell address must be specified for the data to be stored. The data is then stored in the linked list pointed to by the memory cell address. The hash table is used to store the correspondence between memory cell addresses and linked lists. For example, the first data in the data to be stored can be used as a query identifier. The first data is used to obtain the first memory cell address. The data to be stored is then stored in the target storage cell of the target linked list corresponding to the first memory cell address.

[0096] For example, a hash operation can be performed on the first data, and then the first memory unit address can be determined based on the hash operation result. A pointing relationship is then established between the first memory unit address and a storage unit in a linked list. The storage unit can then store the first data and the second data corresponding to the first data in the form of a data pair. In the above example, if the first data is player account data, then a hash operation needs to be performed on the player account data to obtain the first memory unit address corresponding to the player.

[0097] Exemplarily, when determining the first memory unit address, the server identifier corresponding to the player may also be obtained, and the first memory unit address may be obtained by combining the hash calculation result and the server identifier. Specifically, a hash function is used to perform a hash calculation on the player account data to obtain a hash calculation result, which is then combined with the server identifier to obtain the first memory unit address corresponding to the data to be stored. For example, if the hash calculation result for a player account data is 1234, and the corresponding server identifier is 007, then the first memory unit address corresponding to the account identifier is 1234007. A pointing relationship is then established between the first memory unit address and the target linked list, and the game data corresponding to the player account data is stored in the target linked list based on the pointing relationship.

[0098] As will be appreciated, the game data corresponding to multiple player accounts belonging to the same server can be stored in a single linked list, which can speed up data queries. Therefore, based on the account information of the account to be stored, the account ID of the account to be stored and the server ID of the corresponding server are first determined. Therefore, based on the server ID, a linked list can be identified as the target linked list, and the memory unit address corresponding to each player account can be calculated separately. When establishing the pointing relationship between the memory unit addresses, the memory unit addresses of multiple player accounts belonging to the same server are ensured to point to different storage units in the same linked list, ensuring that the game data of these player accounts is stored in the same linked list.

[0099] 103. Determine whether the first memory unit address exists in the hash table. If so, proceed to step 104; otherwise, proceed to step 105.

[0100] After determining the first memory cell address corresponding to the data to be stored, the first step is to determine whether the hash table contains the first memory cell address. If so, the existing pointing relationship can be directly used to update the stored data in the target linked list pointed to by the original first memory cell address. If not, a new target linked list needs to be created in memory, and then a node needs to be added to the target linked list to store the data to be stored.

[0101] 104. Store the data to be stored in the target linked list pointed to by the first memory unit address.

[0102] If the first memory cell address already exists in the hash table, then the data corresponding to the first data has already been stored. In this case, the data corresponding to the first data needs to be updated. That is, the data to be stored is stored in the linked list pointed to by the original first memory cell address, and the data in the corresponding storage cell is updated.

[0103] 105. Determine whether the number of memory unit addresses already existing in the hash table is equal to the preset number of addresses. If so, execute step 106; if not, execute step 110.

[0104] If the first memory unit address does not exist in the hash table, it means that the data to be stored is newly added business data. Then it is necessary to find storage space in the memory for the unit to be stored and store it in the memory. In order to prevent the problem of insufficient memory, a quantity threshold, that is, the preset number of addresses, can be preset in advance based on the storage space capacity of the memory and the storage capacity of the hash table. This preset number of addresses is used to control the number of memory unit addresses stored in the hash table, that is, to control the number of memory unit addresses stored in the hash table not to exceed the preset number of addresses. In this way, the memory occupancy status can be effectively controlled without the need for unlimited expansion of the memory storage space.

[0105] It is understandable that for a fixed-capacity memory space, the more nodes in each linked list in the memory, the smaller the number of preset addresses. This can effectively control the amount of data stored in the memory and ensure that the memory storage space is always sufficient.

[0106] 106. Determine the inactive linked list in the linked list corresponding to the hash table that meets the specified conditions.

[0107] When the number of memory cell addresses stored in the hash table reaches the preset number of addresses, the memory is already full. Storing more data will likely lead to insufficient memory. At this point, all linked lists stored in memory can be analyzed to identify inactive linked lists. These inactive linked lists are then stored in other storage spaces, freeing up the memory space they occupied. This memory space can then be used to store newly added, active data.

[0108] Inactive data is used to characterize the frequency and time of data access. If a piece of data has not been accessed for a long period of time and has not been accessed recently, it is considered inactive data. On the other hand, if a piece of data is frequently accessed and has been accessed frequently recently, it is considered active data. For example, the inactive list among all linked lists can be determined based on the last access time of each linked list. The last access time can be the last time the data was queried or the last time the data was updated, etc., without limitation. It is understood that the closer the last access time is, the more frequently the data stored in the linked list is updated or accessed, and the more active the linked list is, so it should be stored in memory. This allows for faster query and update speeds in linked lists, improving access efficiency. On the other hand, the further back the last access time is, the longer the data has not been accessed or used, and the less active the linked list is, so it is not necessary to store it in memory, which has faster access speeds. Instead, it can be stored on the hard disk and then moved to memory for storage when a query or update request is received.

[0109] For example, the linked lists in memory can be prioritized based on the last access time corresponding to each linked list. The earlier the last access time, the higher the priority. The linked list with the earliest last access time can then be determined as an inactive list.

[0110] 107. Store the data stored in the inactive linked list in the hard disk, and delete the inactive linked list in the memory.

[0111] Understandably, the data stored in the inactive linked list is not frequently accessed or updated. For example, in a gaming scenario, the inactive linked list can store game data for users who haven't logged into the game for a long time. Therefore, the inactive linked list does not need to be stored in memory. Instead, a hard disk file can be created for it and stored on the hard disk. Because hard disks have larger storage space and slower read speeds, using the hard disk to store the data corresponding to the inactive linked list can easily expand the storage capacity while ensuring the data integrity of the hash table. This can also free up memory and reduce the waste of memory storage space.

[0112] 108. Delete the memory unit address pointing to the inactive linked list in the hash table.

[0113] At the same time, once the inactive list is moved to disk, it becomes inaccessible in memory. Therefore, the memory cell addresses in the hash table that point to the inactive list need to be deleted. As you can see, there may be multiple memory cell addresses in the hash table that point to the inactive list. If multiple memory cell addresses point to the inactive list, all of them need to be deleted.

[0114] 109. Store the first memory unit address in a hash table, and store the data to be stored in a target linked list pointed to by the first memory unit address.

[0115] After the data corresponding to the inactive linked list is stored in the hard disk, a portion of the memory space can be released. Then, a target linked list pointed to by the first memory unit address is created in the memory space, and the first data and the second data in the data to be stored in the target linked list are stored in the form of data pairs.

[0116] For example, before creating a new target linked list, it is also necessary to query the storage data in the hard disk. Check whether the hard disk stores the data to be stored. If the storage unit of a linked list in the hard disk stores the data to be stored, it means that the linked list has resumed its active state, and at this time, the linked list can be directly restored to the memory. And it is necessary to re-establish the pointing relationship between the first memory unit address and the linked list. If the data to be stored is not found in the hard disk, it means that the data to be stored is newly added data, then it is necessary to determine the target linked list in the memory, and then establish the pointing relationship between the first memory unit address and the storage unit of the target linked list, and finally store the first data and the second data in the data to be stored in the storage unit of the target linked list in the form of a data pair.

[0117] 110. Directly store the first memory unit address in the hash table, and store the data to be stored in the target linked list pointed to by the first memory unit address.

[0118] If the number of memory cell addresses stored in the hash table is less than the preset number of addresses, it means that some data can still be stored in the memory. To speed up data access and updates, the target linked list pointed to by the first memory cell address can be directly determined in the memory. Finally, a node is added to the target linked list, and the first and second data in the data to be stored are formed as data pairs.

[0119] It is understandable that after the first data and the second data are stored in the target linked list pointed to by the first memory unit address in the memory, the last access time of the target linked list needs to be updated. This is to determine the inactive linked list in the memory when the data is stored next time. It is understandable that once a linked list is queried, accessed, or the data is updated, the last access time of the linked list needs to be updated according to the query time, access time, and update time. Among them, the data update situations include the addition of a new node to the linked list, the modification of the data of any node in the linked list, etc., which are not limited here.

[0120] The technical solution provided by the embodiment of the present application can store business data in a mixed manner in memory and hard disk. First, the hash table stored in the memory is used to store memory cell addresses, and each memory cell address is a different linked list in the memory, and the linked list stores business data (first data and second data) in the form of data pairs. When a storage request containing data to be stored is received, the first memory cell address is first generated according to the first data in the data to be stored, and then it is determined whether the hash table has room to store the first memory cell address. If there is no room in the hash table, an inactive linked list that has not been accessed for a long time is searched in the multiple linked lists corresponding to the hash table. The inactive linked list is then stored in the hard disk, and the memory cell address corresponding to the inactive linked list in the hash table is deleted. In this way, a portion of the memory storage space will be released. The first memory cell address is then stored in the hash table, and a target linked list pointed to by the first memory cell address is established in the memory, and finally the data to be stored is stored in the target linked list, thereby achieving the purpose of storing the data to be stored in the memory.

[0121] In the above technical solution, inactive linked lists are moved to the hard disk for storage before creating a new target linked list in memory, thus avoiding the problem of insufficient memory. Using both memory and hard disk to store business data allows for complete storage of business data without expanding memory storage space. Furthermore, this method ensures that the business data stored in memory is frequently accessed or recently updated, while inactive business data is moved to the hard disk for storage. This improves effective memory usage and avoids wasting memory resources.

[0122] (2) The process of reading business data using the hash table:

[0123] Combine Figure 1 In the embodiment shown, the process of reading business data using a hash table is briefly described below:

[0124] Figure 2 This is a flow chart of a data reading method provided in an embodiment of the present application. Figure 2 As shown, the data reading method includes the following steps:

[0125] 201. Receive a query request for data to be queried.

[0126] When a query request for data to be queried containing first data is received, the hash table is first searched for the first memory unit address corresponding to the first data to see if the data to be queried is stored in the memory. If so, the memory is directly searched to obtain the second data corresponding to the first data. If not, the hard disk is searched for the second data.

[0127] 202. Determine a first memory unit address according to first data in the data to be queried.

[0128] It is understandable that the first data in the query data is related to the storage location. The hash table is used to store the correspondence between memory unit addresses and storage locations. Therefore, it is necessary to first determine the first memory unit address of the query data based on the first data in the query data, and then check whether the storage location corresponding to the first memory unit address exists in the hash table.

[0129] 203. Determine whether the first memory unit address exists in the hash table. If so, execute step 204; otherwise, execute step 207.

[0130] It is understandable that the first memory unit address determined using the first data is the storage space address where the data to be queried should be stored. After determining the first memory unit address, it is necessary to first determine whether the linked list storage unit pointed to by the first memory unit address exists in the memory. If so, the linked list storage unit can be directly accessed in the memory to read the data. If not, it is necessary to query the hard disk again to determine whether the data to be queried is stored there.

[0131] 204. Determine the target linked list pointed to by the first memory unit address in the memory.

[0132] If the first memory unit exists in the hash table, the target linked list corresponding to the first memory unit is determined according to the hash table, and then the target storage unit of the target linked list pointed to by the first memory unit is directly accessed to obtain the second data corresponding to the data to be queried.

[0133] 205. Query the target linked list according to the first memory unit address, obtain the second data corresponding to the data to be queried, and read it.

[0134] It is understandable that the target linked list has multiple storage units, each of which stores different data. After determining the target linked list, it is necessary to find the storage unit in the target linked list pointed to by the first memory unit address. Then, access the storage unit to read the data.

[0135] 206. Respond to the query request and feed back the second data.

[0136] After obtaining the second data, it is necessary to respond to the query request and feedback the retrieved second data. It is understandable that after feedback of the second data, the last access time of the target linked list must also be updated. This last access time is used to indicate the activity level of the target linked list. In other words, it indicates whether the data in the target linked list has been accessed. Thus, when subsequently storing data, the last access time will serve as the basis for determining whether the target linked list is stored in memory or on disk.

[0137] 207. Determine whether the hard disk stores the first data. If so, proceed to step 208. If not, terminate the data query process.

[0138] If the first memory address doesn't exist in the hash table, the memory doesn't store the data being queried. A secondary search is then required on the hard disk. If the first data is stored on the hard disk, the target linked list corresponding to the first data on the hard disk is accessed and queried to obtain the second data corresponding to the first data. If the first data doesn't exist on the hard disk, the data being queried is not stored, and the query fails.

[0139] 208. Determine the second data corresponding to the first data in the hard disk, and determine the target linked list corresponding to the first data.

[0140] If the first data is found on the hard disk, the storage space corresponding to the first data is directly accessed to obtain the second data corresponding to the first data. At the same time, the stored data on the hard disk is also stored in the form of a linked list. Therefore, it is also necessary to determine the target linked list on the hard disk corresponding to the first data. When the first data in the target linked list is queried, it means that the target linked list has resumed its active state. In order to improve the query access speed of the target linked list, it needs to be restored to the memory.

[0141] 209. Respond to the query request and feed back the second data.

[0142] After obtaining the second data from the hard disk, it is also necessary to respond to the query request and feedback the retrieved second data. It is understandable that after feedback of the second data, the last access time of the target linked list also needs to be updated. This last access time is used to indicate the activity level of the target linked list. That is, the data in the target linked list has been accessed. Thus, when the data is subsequently stored, the last access time will serve as the basis for whether the target linked list is stored in the memory or on the hard disk.

[0143] 210. Store the first memory unit address in a hash table.

[0144] After the target linked list on the hard disk is accessed and queried, it means that the target linked list is used again and becomes the active linked list. In order to improve the reading speed of the target linked list, it is necessary to move the target linked list to the memory for storage. For example, it is necessary to first store the first memory address in the hash table, then restore the target linked list to the memory, and then delete the data corresponding to the target linked list from the hard disk.

[0145] It is understandable that when moving the data of the target linked list to the memory, it is also necessary to first determine whether the memory storage space is sufficient. For example, if the number of memory unit addresses in the hash table is less than the preset number of addresses, then the data corresponding to the target linked list can be directly stored in the memory. If the number of memory unit addresses in the hash table is equal to the preset number of addresses, it means that a new linked list cannot be added to the memory. Then it is still necessary to select an inactive linked list based on the last access time of each linked list stored in the memory, store the data corresponding to the inactive linked list in the hard disk, delete the business data corresponding to the inactive linked list in the memory to release memory space, and finally use the released memory space to store the data corresponding to the target linked list.

[0146] 211. Restore the target linked list to the memory, and establish a pointing relationship between the first memory unit address and the target linked list.

[0147] Finally, a pointing relationship between the first memory unit address and the target linked list is established, so as to facilitate querying the target linked list using the first memory unit address.

[0148] In the above embodiment, since the hash table stores data using a hybrid storage method of memory and hard disk, when reading data, the target linked list corresponding to the data to be queried can be first searched in the memory. If the target linked list is found in the memory, the storage unit of the target linked list is directly accessed to complete the data reading process. If the target linked list is not found in the memory, the target linked list corresponding to the data to be queried is searched on the hard disk. If the target linked list is found in the memory, it is necessary to access the node of the target linked list on the hard disk to complete the data reading. The target linked list also needs to be moved to the memory for storage. This ensures that the active linked list is stored in the memory, thereby improving the reading speed of the active linked list.

[0149] Figure 3 A schematic diagram of a data storage device according to an embodiment of the present invention is provided below. Figure 3 The data device provided in this embodiment is described in detail. The embodiments described below are used to explain the technical solution of this application and are not intended to limit actual use.

[0150] When storing storage data including first historical data and second historical data, the memory unit address generated for the first historical data is stored through a hash table, and the first historical data and the second historical data are stored in a data pair through a linked list pointed to by the memory unit address.

[0151] The data storage device comprises:

[0152] The receiving unit 301 is configured to receive a storage request for data to be stored, including first data and second data.

[0153] The generating unit 302 is configured to generate a first memory unit address for the first data in response to a storage request.

[0154] The determining unit 303 is configured to determine an inactive linked list in the linked list corresponding to the hash table that meets a specified condition when the number of existing memory unit addresses in the hash table is equal to the preset number of addresses. The inactive linked list is a linked list that has not been accessed within a preset time period.

[0155] The storage unit 304 is configured to store the data stored in the inactive linked list in a hard disk.

[0156] The processing unit 305 is configured to delete the inactive linked list from the memory; and delete the memory unit address pointing to the inactive linked list in the hash table.

[0157] The storage unit 304 is further configured to store the first memory unit address in a hash table, and store the first data and the second data in a data pair in a target linked list pointed to by the first memory unit address.

[0158] In an optional implementation, the data storage unit further includes a judgment unit 306 .

[0159] The determining unit 306 is configured to determine whether the first memory unit address is stored in the hash table when the number of memory unit addresses already existing in the hash table is less than a preset number of addresses.

[0160] The storage unit 304 is further configured to store the first data and the second data in a data pair in the target linked list pointed to by the first memory unit if the determination unit determines that the hash table stores the first memory unit address.

[0161] In an optional embodiment, the storage unit 304 is further configured to store the first memory unit address in the hash table if the first memory unit address is not stored in the hash table, establish a target linked list pointed to by the first memory unit address in the memory, and store the first data and the second data in the target linked list as data pairs.

[0162] In an optional implementation, the determination unit 306 is further configured to query whether the hard disk stores the first data and the second data.

[0163] The determining unit 303 is further configured to determine the linked list storing the first data and the second data in the hard disk as the target linked list when the determining unit determines that the first data and the second data are stored in the hard disk.

[0164] The storage unit 304 is specifically used to restore the target linked list from the hard disk to the memory.

[0165] In an optional embodiment, the determining unit 303 is specifically configured to obtain the last access time corresponding to each linked list corresponding to the hash table. All linked lists are prioritized according to the last access time. Based on the priority sorting result, the linked list with the earliest last access time is determined as the inactive linked list.

[0166] In an optional embodiment, the processing unit 305 is further configured to update the last access time of the target linked list after the first data and the second data are stored in the target linked list, or to update the last access time of the target linked list after the target linked list is restored from the hard disk to the memory.

[0167] In an optional embodiment, the first data includes an account identifier and a server identifier. The generating unit 302 is specifically configured to perform a hash operation on the account identifier to obtain an initial hash value. Based on the initial hash value and the server identifier, the first memory unit address of the first data is obtained.

[0168] In an optional embodiment, when the server identifiers corresponding to the multiple data to be stored are the same, the target linked lists pointed to by the multiple first memory unit addresses corresponding to the multiple data to be stored are the same.

[0169] In an optional implementation, the receiving unit 301 is further configured to receive a query request for data to be queried including the first data, and determine a first memory unit address for the first data in response to the query request.

[0170] The processing unit 305 is further configured to, when the first memory unit address does not exist in the hash table, query whether a data pair including the first data is stored in the hard disk, and, when a target linked list including the data pair including the first data is stored in the hard disk, feedback the second data included in the data pair according to the query request.

[0171] The storage unit 304 is further configured to restore the target linked list to the memory and store the first memory unit address in the hash table.

[0172] In an optional embodiment, the determining unit 303 is further configured to, when the first memory unit address exists in the hash table, determine in the memory a target linked list pointed to by the first memory unit address, and determine, based on the data pairs included in the target linked list, the second data corresponding to the first data.

[0173] The processing unit 305 is further configured to respond to the query request and send the second data.

[0174] In an optional implementation, the processing unit 305 is further configured to update the last access time of the target linked list according to the sending time of the second data after sending the second data.

[0175] The storage device of the hash table provided in the embodiment of the present application, the storage unit can store business data in a mixed manner in the memory and the hard disk. First, the hash table stored in the memory is used to store the memory unit address, and each memory unit address is a different linked list in the memory, and the linked list stores the business data (first data and second data) in the form of data pairs. When the receiving unit receives a storage request containing data to be stored, the generating unit first generates the first memory unit address according to the first data in the data to be stored, and then the judging unit judges whether the hash table has room to store the first memory unit address. If the judging unit determines that there is no room in the hash table, the determining unit searches for an inactive linked list that has not been accessed for a long time in the multiple linked lists corresponding to the hash table. The storage unit then stores the inactive linked list in the hard disk, and the processing unit deletes the memory unit address corresponding to the inactive linked list in the hash table. In this way, a portion of the memory storage space will be released. The storage unit then stores the first memory unit address in the hash table, and establishes a target linked list pointed to by the first memory unit address in the memory. Finally, the storage unit stores the data to be stored in the target linked list, thereby achieving the purpose of storing the data to be stored in the memory.

[0176] In the above technical solution, inactive linked lists are moved to the hard disk for storage before creating a new target linked list in memory, thus avoiding the problem of insufficient memory. Using both memory and hard disk to store business data allows for complete storage of business data without expanding memory storage space. Furthermore, this method ensures that the business data stored in memory is frequently accessed or recently updated, while inactive business data is moved to the hard disk for storage. This improves effective memory usage and avoids wasting memory resources.

[0177] It should be noted that the information interaction, execution process, etc. between the modules / units in the data storage device are the same as those in this application. Figures 1 to 2 The corresponding method embodiments are based on the same concept. For specific contents, please refer to the description in the method embodiments shown above in this application, which will not be repeated here.

[0178] Next, we will introduce an electronic device provided by an embodiment of the present application. Figure 4 , Figure 4 This is a structural diagram of a storage device provided in an embodiment of the present application. The electronic device 400 can be specifically a virtual reality VR device, a mobile phone, a tablet, a laptop computer, a smart wearable device, a monitoring data processing device or a radar data processing device, etc., which is not limited here. Among them, the storage device 400 can be deployed with Figure 3 The data storage device described in the corresponding embodiment is used to implement Figures 1 to 2Specifically, the electronic device 400 includes: a receiver 801, a transmitter 802, a processor 803 and a memory 804 (wherein the number of the processor 803 in the execution device 800 can be one or more, Figure 4 (taking one processor as an example), the processor 803 may include an application processor 8031 ​​and a communication processor 8032. In some embodiments of the present application, the receiver 801, the transmitter 802, the processor 803 and the memory 804 may be connected via a bus or other means.

[0179] The memory 804 may include a read-only memory and a random access memory, and provides instructions and data to the processor 803. A portion of the memory 804 may also include non-volatile random access memory (NVRAM). The memory 804 stores processor and operation instructions, executable modules, or data structures, or subsets or extended sets thereof. The operation instructions may include various operation instructions for implementing various operations.

[0180] Processor 803 controls the operation of the execution device. In specific applications, the various components of the execution device are coupled together via a bus system. In addition to a data bus, the bus system may also include a power bus, a control bus, and a status signal bus. However, for clarity, all bus systems are referred to as a bus system in the figure.

[0181] The methods disclosed in the above embodiments of the present application can be applied to or implemented by the processor 803. The processor 803 can be an integrated circuit chip with signal processing capabilities. During implementation, each step of the above method can be completed by hardware integrated logic circuits in the processor 803 or by software instructions. The above processor 803 can be a general-purpose processor, a digital signal processor (DSP), a microprocessor, or a microcontroller, and can further include an application-specific integrated circuit (ASIC), a field-programmable gate array (FPGA), or other programmable logic devices, discrete gate or transistor logic devices, or discrete hardware components. The processor 803 can implement or execute the various methods, steps, and logic block diagrams disclosed in the embodiments of the present application. The general-purpose processor can be a microprocessor or any conventional processor. The steps of the methods disclosed in the embodiments of the present application can be directly implemented as being executed by a hardware decoding processor, or can be executed by a combination of hardware and software modules in the decoding processor. The software module can be located in a storage medium well-known in the art, such as random access memory, flash memory, read-only memory, programmable read-only memory, electrically erasable programmable memory, registers, etc. The storage medium is located in memory 804, and processor 803 reads information in memory 804 and, in conjunction with its hardware, completes the steps of the above method.

[0182] Receiver 801 can be used to receive input digital or character information and generate signal input related to executing device-related settings and function control. Transmitter 802 can be used to output digital or character information through the first interface. Transmitter 802 can also be used to send instructions to the disk pack through the first interface to modify data in the disk pack. Transmitter 802 can also include a display device such as a display screen.

[0183] In the embodiment of the present application, the application processor 8031 ​​in the processor 803 is used to execute Figures 1 to 2 The data storage method in the corresponding embodiment. It should be noted that the specific manner in which the application processor 8031 ​​performs each step is the same as that in the present application. Figures 1 to 2 The corresponding method embodiments are based on the same concept, and the technical effects they bring are the same as those in this application. Figures 1 to 2 The corresponding method embodiments are the same. For specific contents, please refer to the description in the method embodiments shown above in this application, which will not be repeated here.

[0184] The seventh embodiment of the present application provides a computer-readable storage medium, which includes computer instructions. When the computer instructions are executed by a processor, they are used to implement the technical solution of any one of the data storage methods or data reading methods in the embodiments of the present application.

[0185] Although the present application is disclosed as above with the preferred embodiments, it is not intended to limit the present application. Any person skilled in the art may make possible changes and modifications without departing from the spirit and scope of the present application. Therefore, the scope of protection of the present application shall be based on the scope defined by the claims of the present application.

Claims

1. A data storage method, characterized in that: When storing storage data including first historical data and second historical data, a memory unit address generated for the first historical data is stored in a hash table, and the first historical data and the second historical data are stored in a data pair manner through a linked list pointed to by the memory unit address. The method includes: receiving a storage request for data to be stored including first data and second data, and generating a first memory unit address for the first data in response to the storage request; When the number of memory unit addresses already existing in the hash table is equal to the preset number of addresses, determining an inactive linked list in the linked list corresponding to the hash table that meets a specified condition; wherein the inactive linked list is a linked list that has not been accessed within a preset time period; Storing the data stored in the inactive linked list in a hard disk, and deleting the inactive linked list in the memory; Deleting the memory unit address pointing to the inactive linked list in the hash table; The first memory unit address is stored in the hash table, and the first data and the second data are stored in a data pair in a target linked list pointed to by the first memory unit address.

2. The method according to claim 1, characterized in that The method further comprises: When the number of memory unit addresses already existing in the hash table is less than the preset number of addresses, determining whether the first memory unit address is stored in the hash table; If the first memory unit address is stored in the hash table, the first data and the second data are stored in the target linked list pointed to by the first memory unit in a data pair.

3. The method according to claim 2, characterized in that The method further comprises: If the first memory unit address is not stored in the hash table, storing the first memory unit address in the hash table; The target linked list pointed to by the first memory unit address is established in the memory; and the first data and the second data are stored in the target linked list in a data pair manner.

4. The method according to claim 3, characterized in that Before establishing the target linked list in the memory, the method further includes: querying whether the hard disk stores the first data and the second data; If the hard disk stores the first data and the second data, determining the linked list storing the first data and the second data in the hard disk as the target linked list; The step of establishing the target linked list in the memory includes: Restoring the target linked list from the hard disk to the memory.

5. The method according to any one of claims 1 to 4, characterized in that Determining an inactive linked list in the linked list corresponding to the hash table that meets a specified condition includes: Obtain the last access time of all linked lists corresponding to the hash table respectively; Prioritize all the linked lists according to the last access time; According to the priority sorting result, the linked list with the earliest last access time is determined as the inactive linked list.

6. The method according to claim 5, characterized in that The method further comprises: After the first data and the second data are stored in the target linked list, updating the last access time of the target linked list; or After the target linked list is restored from the hard disk to the memory, the last access time of the target linked list is updated.

7. The method according to claim 1, characterized in that The first data includes an account identifier and a server identifier; and generating a first memory unit address for the first data includes: Performing a hash operation on the account identifier to obtain an initial hash value; The first memory unit address of the first data is obtained according to the initial hash value and the server identifier.

8. The method according to claim 7, characterized in that When the server identifiers corresponding to the plurality of data to be stored are the same, the target linked lists pointed to by the plurality of first memory unit addresses corresponding to the plurality of data to be stored are the same.

9. The method according to claim 1, characterized in that The method further comprises: receiving a query request for data to be queried including the first data, and determining a first memory unit address for the first data in response to the query request; When the first memory unit address does not exist in the hash table, querying whether the hard disk stores the data pair including the first data; When the hard disk stores a target linked list of the data pair including the first data, feeding back the second data included in the data pair according to the query request; The target linked list is restored to the memory, and the first memory unit address is stored in the hash table.

10. The method according to claim 9, characterized in that The method further comprises: When the first memory unit address exists in the hash table, determining the target linked list pointed to by the first memory unit address in the memory; Determining the second data corresponding to the first data according to the data pairs included in the target linked list; In response to the query request, the second data is sent.

11. The method according to claim 10, characterized in that: After sending the second data, the method further includes: The last access time of the target linked list is updated according to the sending time of the second data.

12. A data storage device, characterized in that: When storing storage data including first historical data and second historical data, a memory unit address generated for the first historical data is stored in a hash table, and the first historical data and the second historical data are stored in a data pair in a linked list pointed to by the memory unit address. The data storage device includes: A receiving unit, configured to receive a storage request for data to be stored, including first data and second data; a generating unit, configured to generate a first memory unit address for the first data in response to the storage request; a determining unit, configured to determine, when the number of memory unit addresses already existing in the hash table is equal to a preset number of addresses, an inactive linked list in the linked list corresponding to the hash table that meets a specified condition; wherein the inactive linked list is a linked list that has not been accessed within a preset time period; a storage unit, configured to store the data stored in the inactive linked list in a hard disk; A processing unit, configured to delete the inactive linked list in the memory; and delete the memory unit address pointing to the inactive linked list in the hash table; The storage unit is further configured to store the first memory unit address in the hash table, and store the first data and the second data in a data pair in the target linked list pointed to by the first memory unit address.

13. An electronic device, characterized in that: include: A memory and a processor, wherein the memory and the processor are coupled; The memory is used to store one or more computer instructions; The processor is configured to execute the one or more computer instructions to implement the data storage method according to any one of claims 1 to 11.

14. A computer-readable storage medium having one or more computer instructions stored thereon, characterized in that: The instruction is executed by a processor to implement the data storage method according to any one of claims 1 to 11.

Citation Information

Patent Citations

  • Data replacement method based on mixed storage, related method, device and system

    CN113297106A

  • Method, device and equipment for managing data based on hash table and storage medium

    CN114328503A