Data storage method and related device
By introducing consistent hashing and random selection algorithms into the Memcached cluster, the flexibility problem of traditional Memcached clusters during scaling up and down is solved, enabling flexible allocation and load balancing of storage nodes, and improving the scaling up and down effect and the continuity of data reading.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- CHINA MOBILE (SUZHOU) SOFTWARE TECH CO LTD
- Filing Date
- 2025-12-31
- Publication Date
- 2026-04-21
AI Technical Summary
Traditional Memcached clusters using consistent hashing algorithms for data storage have low flexibility when scaling up or down, affecting the actual scaling effect. Furthermore, they cannot be flexibly adjusted when real nodes come online or go offline, leading to data read failures or unbalanced loads.
By employing a consistent hashing algorithm combined with a random selection algorithm, data identifiers are mapped to groups through a central node, and storage nodes are determined based on the random selection algorithm. This enables flexible allocation and load balancing of storage nodes, reduces data migration, and ensures business continuity.
It improves the system's scalability and scaling flexibility and practical effect, reduces network and server load, ensures the continuity and uniformity of data reading, and avoids the negative impact of data migration.
Smart Images

Figure CN121900696A_ABST
Abstract
Description
Technical Field
[0001] The application generally relates to the field of computers, and in particular to a data storage method and related apparatus. Background Technology
[0002] In the OpenStack architecture (a cloud computing management platform), Memcached (a distributed memory caching system) is a commonly used distributed caching service to improve performance and reduce database load. It is often used to store frequently accessed information such as temporary data, metadata, and session state. Essentially, it is a key-value database where the key is a string and the value can be in various formats, including strings, numbers, and binary objects. It achieves efficient caching through multi-node distributed memory storage.
[0003] Traditional Memcached's distributed implementation is based on a client-side consistent hashing algorithm, with no awareness between server-side nodes. This algorithm can operate on a hash ring, where virtual and physical nodes are relatively evenly distributed. Keys are first mapped to virtual nodes, and then stored by matching the nearest physical node clockwise. (See also...) Figure 1 , Figure 1 This is a logical diagram of a hash ring based on a consistent hashing algorithm provided in an embodiment of this application. Figure 1 The hash ring shown contains three real nodes: real node 1, real node 2, and real node 3, and three virtual nodes: virtual node 1 through virtual node 9. For example, key1 is first mapped to virtual node 9, and then mapped clockwise to the nearest real node 1, with the value corresponding to key1 stored in real node 1; key2 is first mapped to virtual node 8, and then mapped clockwise to the nearest real node 1, with the value corresponding to key2 stored in real node 1; key3 is first mapped to virtual node 5, and then mapped clockwise to the nearest real node 2, with the value corresponding to key3 stored in real node 2.
[0004] In traditional Memcached clusters, which use consistent hashing to store data, once the hash ring is set on the client, data storage can only be done by virtual nodes searching for the corresponding physical nodes in a clockwise direction on a fixed hash ring. If you want to make horizontal modifications to the system capacity (such as adding or deleting physical nodes), the modified physical node can only affect the physical nodes upstream or downstream in a clockwise direction, which is not very flexible and affects the actual scaling effect. Summary of the Invention
[0005] This application addresses some of the shortcomings mentioned in the background art by providing a data storage method and related apparatus, which can improve the flexibility of system expansion or contraction and enhance the actual expansion and contraction effect.
[0006] The first aspect of this application provides a data storage method. This method can be applied to a data storage system, which includes a central node and at least two storage nodes. A first storage node is one of the storage nodes, and each storage node is used to store a corresponding data identifier and data. In this method, the central node can obtain first data and, based on the first data identifier, determine a first group identifier using a consistent hashing algorithm, where the first data identifier is an identifier for the first data. Then, based on a random selection algorithm, it determines the first storage node corresponding to the first group identifier from at least two storage nodes. The central node then sends the first data identifier and the first data to the first storage node.
[0007] In this process, the central node first maps the identifier of the data to be cached to the group, and then selects the storage node from the data storage system to store the data in the group based on a random selection algorithm. The mapping relationship between the group and the storage node is more random and flexible. If the system capacity is modified, when adding or deleting storage nodes, the capacity of multiple storage nodes in the system before the modification can be distributed more randomly and flexibly, improving the actual expansion flexibility and effectiveness.
[0008] In conjunction with the first aspect, in the first possible implementation, the central node can update the first mapping relationship based on the first group identifier and the first node identifier. The first node identifier is the identifier of the first storage node. The first mapping relationship includes the correspondence between multiple groups of group identifiers and node identifiers. The correspondence between the second group identifier and the second node identifier is one of these groups. The second group identifier is determined based on the second data identifier. The second node identifier is the identifier of the second storage node. The second storage node is any storage node in the data storage system. The second data identifier and the second data are any set of data identifiers and data stored in the second storage node.
[0009] In conjunction with the first possible implementation of the first aspect, in the second possible implementation, the central node receives a first data read request carrying a first data identifier. Then, based on the first data identifier, the central node determines a first group identifier using a consistent hashing algorithm. Next, it queries the first mapping relationship to obtain the first node identifier corresponding to the first group identifier. Based on the first node identifier, it retrieves the first data from the first storage node and finally responds to the first data read request, returning the first data. Through these steps, the central node can achieve fast reading of cached data.
[0010] In a third possible implementation, combining the first aspect or the first possible implementation of the first aspect, the storage nodes in the data storage system include three or more, with the first storage node being the storage node that goes offline within a preset time. The central node can also obtain all data identifiers and data corresponding to the storage in the first storage node. The third data identifier and third data are any set of data identifiers and data corresponding to the storage in the first storage node. Based on the third data identifier, the central node determines the third group identifier using a consistent hashing algorithm, and then, based on a random selection algorithm, determines the third storage node corresponding to the third group identifier from other storage nodes in the data storage system besides the first storage node. Finally, the central node sends the third data identifier and third data to the third storage node. This approach ensures business continuity when a storage node goes offline, distributes the caching tasks of the offline node more evenly among other storage nodes, eliminates the need for cross-migrating of data, minimizes the amount of data to be migrated, and reduces network and server load.
[0011] In conjunction with the first possible implementation of the first aspect, in the fourth possible implementation, the central node can obtain the correspondence between the fourth group identifier and the fourth node identifier from the first mapping relationship. This correspondence is any pair of group identifiers and node identifiers in the first mapping relationship. The central node can also determine the sixth storage node corresponding to the fourth group identifier from the data storage system after the addition of the fifth storage node based on a random selection algorithm. If the sixth storage node and the fifth storage node are the same storage node, the central node obtains the fifth data identifier and fifth data from the fourth storage node. The fourth storage node is the storage node indicated by the fourth node identifier in the data storage system, and the fifth data identifier and fifth data are any pair of data identifiers and data stored in the fourth storage node. The central node can also determine the fifth group identifier corresponding to the fifth data identifier based on a consistent hashing algorithm. If the fifth group identifier matches the fourth group identifier, the central node sends the fifth data identifier and fifth data to the fifth storage node. When storage nodes are brought online, business continuity can be guaranteed. The online node can share the caching tasks among multiple storage nodes, ensuring a balanced workload across all storage nodes. Data does not need to be cross-migrated, the amount of data to be migrated is minimized, and the load on the network and servers is reduced.
[0012] In conjunction with the third possible implementation of the first aspect, in the fifth possible implementation, the central node can specifically obtain all valid data identifiers stored in the first storage node, then send all valid data identifiers to the first storage node, and finally the central node receives the data corresponding to each data identifier among all valid data identifiers returned by the first storage node.
[0013] A second aspect of this application provides a data processing apparatus applied to a data storage system. The data storage system includes a central node and at least two storage nodes, with a first storage node being one of the storage nodes. The storage nodes are used to store corresponding data identifiers and data. The data processing apparatus is contained within the central node and includes an interaction module and a calculation module.
[0014] The interaction module is used to obtain the initial data.
[0015] The calculation module is used to determine a first group identifier based on a consistent hashing algorithm, where the first data identifier is the identifier of the first data. The calculation module is also used to determine the first storage node corresponding to the first group identifier from at least two storage nodes based on a random selection algorithm.
[0016] The interaction module is also used to send the first data identifier and the first data to the first storage node.
[0017] In conjunction with the second aspect, in the first possible implementation, the computing module is further configured to update the first mapping relationship based on the first group identifier and the first node identifier. The first node identifier is the identifier of the first storage node. The first mapping relationship includes the correspondence between multiple groups of group identifiers and node identifiers. The correspondence between the second group identifier and the second node identifier is one of these groups. The second group identifier is determined based on the second data identifier. The second node identifier is the identifier of the second storage node. The second storage node is any storage node in the data storage system. The second data identifier and the second data are any set of data identifiers and data stored in the second storage node.
[0018] In conjunction with the first possible implementation of the second aspect, in the second possible implementation, the interaction module is also used to receive a first data read request, the first data read request carrying a first data identifier.
[0019] The calculation module is also used to determine the first group identifier based on the first data identifier using a consistent hashing algorithm, and to query the first mapping relationship to obtain the first node identifier corresponding to the first group identifier.
[0020] The interaction module is also used to obtain first data from the first storage node based on the first node identifier, and to respond to the first data read request and return the first data.
[0021] In conjunction with the second aspect or the first possible implementation of the second aspect, in the third possible implementation, the storage nodes in the data storage system include three or more, and the first storage node is the storage node in the data storage system that goes offline within a preset time.
[0022] The interaction module is also used to obtain all data identifiers and data of the corresponding storage in the first storage node, and the third data identifier and the third data are any set of data identifiers and data of the corresponding storage in the first storage node.
[0023] The calculation module is also used to determine the third group identifier based on the third data identifier using a consistent hashing algorithm, and to determine the third storage node corresponding to the third group identifier from other storage nodes in the data storage system other than the first storage node using a random selection algorithm.
[0024] The interaction module is also used to send the third data identifier and the third data to the third storage node.
[0025] In conjunction with the first possible implementation of the second aspect, in the fourth possible implementation, the calculation module is further configured to obtain the correspondence between the fourth group identifier and the fourth node identifier from the first mapping relationship, and to determine the sixth storage node corresponding to the fourth group identifier from the data storage system after the addition of the fifth storage node based on a random selection algorithm. The correspondence between the fourth group identifier and the fourth node identifier is the correspondence between any group identifier and node identifier in the first mapping relationship.
[0026] When the sixth storage node and the fifth storage node are the same storage node, the interaction module is also used to obtain the fifth data identifier and the fifth data from the fourth storage node. The fourth storage node is the storage node indicated by the fourth node identifier in the data storage system, and the fifth data identifier and the fifth data are any set of data identifiers and data stored in the fourth storage node.
[0027] The calculation module is also used to determine the fifth group identifier corresponding to the fifth data identifier based on the consistent hashing algorithm.
[0028] If the fifth group identifier is the same as the fourth group identifier, the interaction module is also used to send the fifth data identifier and the fifth data to the fifth storage node.
[0029] A third aspect of this application provides a computer-readable storage medium storing program code that, when executed on a computer, causes the computer to perform the methods described in the first aspect and any possible implementation thereof.
[0030] The fourth aspect of this application provides a computer program product comprising: computer program code, which, when run on a computer, causes the computer to perform the methods described in the first aspect and any possible implementation thereof. Attached Figure Description
[0031] Figure 1 This is a schematic diagram of a hash ring based on a consistent hashing algorithm provided in an embodiment of this application; Figure 2 This is a schematic diagram comparing the hash rings before and after a Memcached real node goes online, provided in an embodiment of this application. Figure 3 This is a schematic diagram comparing the hash rings before and after a Memcached real node goes offline, provided in an embodiment of this application. Figure 4 This is a schematic diagram of the architecture of a data storage system provided in an embodiment of this application; Figure 5 This is a flowchart illustrating a data storage method provided in an embodiment of this application; Figure 6 This is a schematic diagram of a data migration process in a scenario where a storage node goes offline, provided in an embodiment of this application. Figure 7 This is a schematic diagram of the structure of a doubly linked list in Memcached provided in an embodiment of this application; Figure 8 This is a schematic diagram illustrating the change in the correspondence in the first mapping relationship under a storage node offline scenario provided in an embodiment of this application; Figure 9 This is a schematic diagram of a data migration process in a storage node going online scenario provided by an embodiment of this application; Figure 10 This is a schematic diagram illustrating the change of the corresponding relationship in the first mapping relationship under a storage node going online scenario provided in an embodiment of this application; Figure 11 This is a schematic diagram of the structure of a data processing device provided in this application. Figure 12 This is a schematic diagram of another data processing device provided in an embodiment of this application. Detailed Implementation
[0032] The present application / disclosure will now be described in further detail with reference to the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are merely illustrative of the present application / disclosure and are not intended to limit the scope of the present application / disclosure. Furthermore, it should be noted that, for ease of description, only the parts relevant to the present application / disclosure are shown in the accompanying drawings, not the entire structure.
[0033] This application provides a data storage method based on a consistent hashing algorithm and a random selection algorithm. Before introducing the method provided in this application, these two algorithms will be introduced first.
[0034] First, let's introduce the consistent hashing algorithm. The consistent hashing algorithm is an algorithm used in the field of distributed caching to implement data sharding and load balancing. The hash ring is its core carrier, and the two together constitute the underlying logic of data and node mapping in distributed storage systems (such as Memcached clusters).
[0035] A hash ring is a virtual ring-shaped hash space whose hash value range is typically mapped to a fixed interval (e.g., 0~2³²-1), forming a closed ring structure. This ring space is configured with two types of core nodes: first, physical nodes, which are the physical or virtual server nodes that actually provide storage services in the distributed caching cluster. Each physical node corresponds to one or more hash value points on the hash ring through hash operations; second, virtual nodes. To optimize the uniformity of the mapping of physical nodes, several virtual nodes are allocated to each physical node. These virtual nodes are also mapped to different points on the hash ring, forming a one-to-one correspondence with the physical nodes.
[0036] For the key-type data to be stored, its hash value is first calculated using a unified hash function. This hash value is then mapped to the corresponding point on the hash ring. Starting from that point, the hash ring is traversed clockwise. If the first matched node is a real node, that real node is the target storage node for the key-type data. If the first matched node is a virtual node, the real node corresponding to that virtual node is the target storage node for the key-type data. The unified hash function mentioned above can be one of the following hash functions: MD5 (Message-Digest Algorithm 5), SHA-1 (Secure Hash Algorithm 1), CRC32 (Cyclic Redundancy Check 32), MurmurHash2 (MurmurHash Algorithm 2), MurmurHash3 (MurmurHash Algorithm 3), Jenkins Hash (Jenkins Hash Algorithm), etc.
[0037] From the above introduction to the consistent hashing algorithm, it's clear that traditional Memcached systems typically require mapping key-type data to virtual nodes and then searching clockwise along the hash ring for the nearest physical node to be used as the data storage node. This lack of flexibility impacts the actual scaling performance in expansion and contraction scenarios. Furthermore, since traditional Memcached systems are based on consistent hashing, adding new physical nodes to the system for expansion affects the existing mapping between virtual and physical nodes. Because physical nodes are unaware of each other and cannot migrate data, some virtual nodes will be mapped to the added physical node when reading data. This makes it difficult to accurately locate the corresponding physical storage node when reading data that originally corresponded to these virtual nodes, thus impacting business operations. Additionally, the added physical node can only share the caching tasks of its clockwise adjacent physical nodes on the hash ring; the caching tasks of other physical nodes remain heavy.
[0038] by Figure 2 For example, Figure 2 This is a schematic diagram comparing the hash rings of a Memcached real node before and after it goes online, provided in an embodiment of this application. Figure 2 As shown in the diagram, before real node 4 came online, the hash ring contained three real nodes: real node 1, real node 2, and real node 3. Virtual nodes 1, 2, and 3 were mapped to real node 3; virtual nodes 4, 5, 6, and 7 were mapped to real node 2; and virtual nodes 8 and 9 were mapped to real node 1. After real node 4 came online, its position on the hash ring was between virtual nodes 8 and 9. Therefore, virtual node 8 changed from being mapped to real node 1 to being mapped to real node 4. Since there is no data transfer between real nodes 1 and 4, some data corresponding to virtual node 8 will be cached in real node 1 and not in real node 4. When a client accesses this data, according to the consistent hashing algorithm, it will try to retrieve it from real node 4, which is currently mapped to virtual node 8, resulting in a data hit failure. Furthermore, when real node 4 comes online, it can only share some of the caching pressure with real node 1. The positions of other real nodes and virtual nodes on the hash ring remain unchanged. Therefore, the caching tasks of real nodes 2 and 3 are not shared, and the caching tasks may still be heavy.
[0039] When a physical node goes offline in the system, since the physical nodes are unaware of each other and cannot migrate data, the data originally cached by that physical node will become unreadable, thus affecting the business. In addition, after a physical node goes offline, the physical nodes adjacent to it in the clockwise direction will take over the caching tasks that were originally handled by the offline physical node, which will increase the caching tasks of the adjacent physical nodes in the clockwise direction, resulting in load imbalance and affecting overall performance.
[0040] by Figure 3 For example, Figure 3 This is a schematic diagram comparing the hash rings before and after a Memcached real node goes offline, provided in an embodiment of this application. Figure 3 As shown in the diagram, before real node 1 goes offline, the hash ring contains three real nodes: real node 1, real node 2, and real node 3. Virtual nodes 1, 2, and 3 are mapped to real node 3; virtual nodes 4, 5, 6, and 7 are mapped to real node 2; and virtual nodes 8 and 9 are mapped to real node 1. After real node 1 goes offline, virtual nodes 8 and 9, which were originally mapped to real node 1, are now mapped to real node 3. Since there is no data transfer between real node 1 and real node 3, some data corresponding to virtual nodes 8 or 9 will be lost when real node 1 goes offline and will not exist in real node 3. When a client accesses this data, according to the consistent hashing algorithm, it will try to retrieve it from the real node 3 that virtual nodes 8 or 9 are currently mapped to, resulting in a data hit failure. Furthermore, when real node 1 goes offline, the caching tasks that should have been handled by real node 1 will be transferred to real node 3 through the change of the mapping of virtual node 8 and virtual node 9. The caching tasks of real node 3 will increase dramatically, resulting in an unbalanced load.
[0041] The data storage method provided in this application can effectively solve the technical problems of low flexibility and real node online and offline scenarios. The method will be described in detail later.
[0042] The following section introduces random selection algorithms. Random selection algorithms can achieve a relatively uniform mapping and allocation of data to be stored to storage nodes by combining hash operations with randomness rules. Examples include basic random algorithms, 2-random selection algorithms, the straw algorithm (a distributed decision-making algorithm based on weighted voting), and the straw2 algorithm (an optimized version of the straw algorithm). This application does not impose specific restrictions on the specific implementation algorithms.
[0043] The `straw2` algorithm is a weighted random selection algorithm based on a "lottery" model. This algorithm takes the unique identifier of the data to be stored (such as the key or group identifier) and the weights of each candidate node (the weights of candidate nodes are related to their performance and storage capacity) as input. Based on the unique identifier of the data to be stored and the weights of each candidate node, a lottery score is calculated for each candidate node. After traversing all candidate nodes and calculating their scores, the node with the highest score is selected as the target node, achieving targeted data mapping. For example, in calculating the lottery score of each candidate node, a hash function can be used to determine a random value corresponding to the unique identifier of the data to be stored in the range of 0 to 65535. Normalization and logarithmic operations are performed on this random value, and the result is divided by the node weight to obtain the final score.
[0044] The Straw2 algorithm features weighted adaptation, stable mapping, and computational independence. First, it achieves load balancing across storage nodes through weight factors, with nodes having higher weights being more likely to be selected. This adapts well to mixed deployments of nodes with varying performance and capacity in distributed data storage systems. Second, when a storage node is deleted from the distributed storage system, only the data stored on that node before deletion will trigger remapping due to the node's invalidation. The algorithm's score calculation logic needs to be re-executed to match a new storage node from the remaining nodes. All other data not mapped to the deleted node retains its node relationships completely, without any migration. When a new storage node is added, only the data whose score determines the new node is the optimal node (data previously mapped to other storage nodes) will be migrated to the new node during the first execution of the Straw2 algorithm after addition. All other data remains unaffected by the existing node mappings and requires no remapping or migration. Furthermore, the calculation of scores for the same data across different storage nodes relies solely on the weight of the storage node itself and the input hash factor, without being related to other storage nodes. This avoids the impact of changes in the scale of the data storage system on the scores of individual storage nodes, ensuring system scalability and computational efficiency.
[0045] The following describes the data storage method provided in the embodiments of this application. This method can be applied to a data storage system, which can be a distributed data storage system, including a central node and storage nodes. The central node is used to execute the method provided in the embodiments of this application, and the storage nodes are used to store corresponding data identifiers and data. This data storage system can be a system that caches data in memory. The data is mostly temporary, frequently accessed copies, such as system session states, business metadata, and hot query results, and does not guarantee data persistence (some support weak persistence). Examples include a Memcached cluster system (where each storage node can be a Memcached instance) or a Redis cluster system (where each storage node can be a Redis instance). There can be one or multiple central nodes, one of which is the primary central node, and the others are backup central nodes. There are at least two storage nodes. The central node can interact directly with the storage nodes, sending data identifiers and / or data to the storage nodes, and also retrieving data identifiers and / or data stored in the storage nodes. The storage nodes are unaware of and do not communicate with each other. Furthermore, the data storage system can also include client nodes, which can be used to provide cached data to the data center system and to read cached data from the data storage system.
[0046] See also Figure 4 , Figure 4 This is a schematic diagram of the architecture of a data storage system provided in an embodiment of this application. Figure 4 The data storage system 40 shown exemplarily includes a central node 401 and four storage nodes: storage nodes 402, 403, 404, and 405. The central node 401 is connected to each of the storage nodes. The central node 401 can be used to execute the methods provided in the embodiments of this application. The four storage nodes 402, 403, 404, and 405 are used to store data identifiers and data respectively. Further, the system 40 may also include a client node 406, which is connected to the central node 401. When the client node 406 has data that needs to be cached, it transmits it to the central node 401. The central node 401 caches the data in the data storage system 40 based on the methods provided in the embodiments of this application. The client node 406 can also obtain cached data in the data storage system 40 through the central node 401. It is worth noting that the nodes mentioned above can be implemented through instances, processes, etc. For example, a Memcached instance can be a storage node, and the connection between nodes can be achieved through data interaction between instances and processes based on code, functions, etc.
[0047] The following describes the specific implementation of the data storage method provided in the embodiments of this application. Please refer to [link / reference]. Figure 5 , Figure 5 This is a flowchart illustrating a data storage method provided in an embodiment of this application. The method can be executed by the central node in the data storage system and may include steps S501-S504.
[0048] S501, the central node obtains the first data.
[0049] The first data can be data transmitted from the client to the central node in the data storage system. It can be frequently accessed, potentially lost data that the client needs to access. Each piece of data has its own unique identifier, which is the first data identifier. For example, the first data could be a user's nickname, avatar, or membership level on an e-commerce platform, while the first data identifier could be the user's account. Similarly, in a retail system, the first data could be the product's name, unit price, or image, while the first data identifier could be the product's code. Furthermore, the first data identifier and the first data can typically exist in key-value pairs. The client can organize the data it needs to cache and its identifier into key-value pairs and send them to the central node, where the data identifier is the key and the data is the value.
[0050] S502, the central node determines the first group identifier based on the first data identifier and the consistent hashing algorithm.
[0051] Based on the above introduction to consistent hashing algorithms and hash rings, a hash ring forms a closed loop through a certain range of hash values. Different points on the hash ring correspond to different hash values. Similar to setting virtual nodes on the hash ring, several group nodes can be pre-set on the hash ring. Each group node corresponds to a fixed point, and different group nodes correspond to different group identifiers. Data identifiers mapped to different group nodes belong to different groups (such as PG, Placement Group) and also correspond to different group identifiers. Based on the above settings, a unified hash function can be used to determine the hash value corresponding to the first data identifier. Then, this hash value is mapped to the corresponding point on the hash ring. Based on the point of this hash value on the hash ring, the first group to which the first data identifier belongs is determined, corresponding to the first group identifier. The first group identifier is the group identifier of the first group, used to indicate that the first data belongs to the first group. For example, the above group can be multiple different PGs, the first group is one of the PGs, and the first group identifier can be the PG_ID of that PG.
[0052] S503, the central node determines the first storage node corresponding to the first group identifier from at least two storage nodes based on a random selection algorithm.
[0053] Here, the central node can take the first group identifier and the weight of the storage node as input, and determine the lottery score of the storage node through a random selection algorithm. After traversing all the storage nodes in the data storage system, the storage node with the highest lottery score is determined as the first storage node corresponding to the first group identifier, which is the storage node planned to be used to store the first data and the first data identifier.
[0054] Furthermore, the central node can also store the correspondence between the first group identifier and the first node identifier of the first storage node. For example, the central node can store the above correspondence through a first mapping relationship. In this way, if other data identifiers also belong to the first group later, the first mapping relationship can be directly queried to find that the data identifier also corresponds to the first storage node, thus improving data processing efficiency. It is understandable that although this query method is not directly calculated in this step, the result is still obtained based on the correspondence obtained by the random selection algorithm, so it does not contradict the description in step S503.
[0055] S504, the central node sends the first data identifier and the first data to the first storage node.
[0056] The central node can send the first data identifier and the first data to the first storage node in the form of key-value pairs, and the first storage node caches the key-value pairs of the first data identifier and the first data.
[0057] In this embodiment, the central node determines a first group identifier based on a first data identifier using a consistent hashing algorithm, and then determines a first storage node corresponding to the first group identifier from the data storage system based on a random selection algorithm. Finally, the central node sends the first data identifier and the first data to the first storage node for corresponding storage. In this process, the central node first maps the identifier of the data to be cached to a group, and then selects a storage node from the data storage system to store the data in that group based on a random selection algorithm. The mapping relationship from group to storage node is more random and flexible. If the system capacity is modified, adding or deleting storage nodes can more randomly and flexibly distribute the capacity across multiple storage nodes in the system before the modification, improving the actual expansion flexibility and effectiveness.
[0058] The data storage process described in steps S501-S504 above can optionally be further included after step S503: S505, the central node updates the first mapping relationship based on the first group identifier and the first node identifier.
[0059] The first node identifier is the identifier of the first storage node. The first mapping relationship includes the correspondence between multiple groups of identifiers and node identifiers. The correspondence between the second group identifier and the second node identifier is one of these groups. The second group identifier is determined based on the second data identifier. The second node identifier is the identifier of the second storage node. The second storage node is any storage node in the data storage system. The second data identifier and the second data are any set of data identifiers and data stored in the second storage node.
[0060] In other words, each time the central node calculates the node identifier corresponding to a new group identifier, it can record it in the first mapping relationship. The first mapping relationship contains the correspondence between the group identifier determined by the data identifier of each piece of data cached in the data storage system and its node identifier. This first mapping relationship can also be used when the data identifier of other data also belongs to the first group. The central node can directly query the first mapping relationship to find that the data identifier also corresponds to the first storage node, thereby improving data processing efficiency.
[0061] In the specific implementation, the first mapping relationship can be recorded in the ETCD (Distributed Key-Value Store) of the central node, stored in the form of key-value pairs RouteTable / {PG_ID} / {ip:port}, where PG_ID is the PG number (representing the group identifier), and ip:port is the IP (Internet Protocol) address and port information of the Memcached instance. When the client node starts, it reads this first mapping relationship.
[0062] Memcached instances can notify the central node of their service status through a heartbeat mechanism. ETCD can record key-value pairs with the prefix MCS / to describe the service status of Memcached instances in the data storage system. The central node uses ETCD's watch mechanism (data change monitoring mechanism) to monitor keys with the prefix MCS / . When a change occurs, the data storage system may have undergone horizontal scaling up / down, requiring data migration, which will be described in detail below.
[0063] Optionally, if there are backup storage nodes in the data storage system, the first mapping relationship may also include the correspondence between the group identifier and the node identifier related to the backup storage nodes, further ensuring the high availability of the system.
[0064] Furthermore, the method may also include steps S506-S510 for reading the first data: S506, the central node receives the first data read request.
[0065] The first data read request can be sent by the client node, and the first data read request carries the first data identifier.
[0066] S507, the central node determines the first group identifier based on the first data identifier and the consistent hashing algorithm.
[0067] Here, similar to the implementation described in step S502, the hash value is determined by the same hash algorithm in step S502, and then the corresponding group node is determined on the hash ring, and the corresponding first group identifier is obtained.
[0068] S508, the central node queries the first mapping relationship and obtains the first node identifier corresponding to the first group identifier.
[0069] S509, the central node obtains the first data from the first storage node according to the first node identifier.
[0070] S510, the central node responds to the first data read request and returns the first data.
[0071] By following the steps described above, the central node can quickly read cached data.
[0072] The data storage and retrieval process in this method has been described above. The following sections will discuss how to ensure business continuity and the uniformity of caching tasks across storage nodes when the data storage system is horizontally scaling down or up. First, we will combine... Figure 6 In the case of reduced volume: When a data storage system is scaled down, there are usually three or more storage nodes in the system. The first storage node is one of these nodes and is scheduled to go offline within a preset time. (See [reference]). Figure 6 , Figure 6 This is a schematic diagram illustrating a data migration process in a storage node offline scenario provided by an embodiment of this application, such as... Figure 6 As shown, the process may include steps S601-S604.
[0073] S601, the central node obtains all data identifiers and data stored in the corresponding storage in the first storage node.
[0074] The central node can obtain all valid data identifiers stored in the first storage node, then send all valid data identifiers to the first storage node, and receive the data corresponding to each data identifier in all valid data identifiers returned by the first storage node.
[0075] In practical implementation, if this method is applied to a Memcached cluster system, Memcached version 1.5 can implement an improved LRU (Least Recently Used) algorithm, which includes the lru_crawler thread, also known as the LRU crawler. This thread is an asynchronous background process that scans all items in the LRU list, reclaiming expired items or performing other processing. Based on this characteristic of the LRU crawler, it can be improved to meet the requirement of obtaining all keys. In Memcached, a single data unit is called an item. Each item contains information such as the data's key, value, and expiration time. Each item is stored in a different slab (memory allocation block) according to its size. The items in each slab are organized using a doubly linked list to form an LRU linked list.
[0076] See also Figure 7 , Figure 7 This is a schematic diagram of a doubly linked list structure in Memcached provided in an embodiment of this application, as shown below. Figure 7 As shown, items are stored in slab 1, slab 2, slab 3, ..., slab n (the items in each slab are of similar size). Items in each slab are organized using a doubly linked list. For example, in slab 1, items 1-n each have a P (Previous) pointer and an N (Next) pointer, ensuring that they can be linked together to form a doubly linked list. The most recently accessed item is placed at the head of the list, and the least recently accessed item is placed at the tail. When a new item is added or an old item is accessed, the corresponding item is moved to the head; when the cache is full, the least recently accessed item is removed from the tail. Crawler (also known as LRU crawler) can start from the tail of the linked list and scan items one by one. During the scan, expired or deleted items are cleared, and the keys of valid items are recorded. After scanning one slab, the linked list is moved on to the next slab, without missing any items.
[0077] Specifically, during Memcached instance initialization, an `lru_crawler` thread is created and blocked on a condition variable. `n` crawler pointers are generated, each pointing to the tail of a slab. When the central node issues `lru_crawler` related instructions, the `lru_crawler` thread is awakened via the condition variable. It then traverses all items in the LRU list and runs the `crawler_dump_eval` and `crawler_dump_finalize` callback functions for each item. During `crawler_dump_eval`, for a given item, it first checks the item's expiration time and deletion flag. If it has expired or been marked for deletion, it skips the item; if it hasn't expired and hasn't been marked for deletion, it retrieves the item's key (containing the data identifier) and writes it to the buffer. `crawler_dump_finalize` is executed after all items have been traversed. It writes an end marker to the end of the buffer and sends the contents of the buffer to the central node, thus obtaining all data identifiers.
[0078] After obtaining all the keys of the first storage node, the corresponding value (containing the data) can be obtained by iterating through each key and executing the get command, thus obtaining all the data identifiers and data.
[0079] S602, the central node determines the third group identifier based on the third data identifier and the consistent hashing algorithm.
[0080] Among them, the third data identifier and the third data are any set of data identifiers and data stored in the first storage node.
[0081] S603, the central node determines the third storage node corresponding to the third group identifier from the other storage nodes in the data storage system, excluding the first storage node, based on a random selection algorithm.
[0082] The methods for determining the third group identifier in step S602 and the methods for determining the third storage node in step S603 can be found in the respective references. Figure 5 The descriptions of steps S502 and S503 in the corresponding embodiments will not be repeated here.
[0083] S604, the central node sends the third data identifier and the third data to the third storage node.
[0084] In step S601, the central node obtains all data identifiers and data stored in the first storage node. Then, for any set of data identifiers and data, it uses them as third data identifiers and third data respectively to execute steps S602-S604. After traversing all data identifiers and data, the data migration of the first storage node is completed. It is understandable that when different data identifiers and data are used as third data identifiers and third data to execute process S602-S603, the resulting third storage nodes may be different storage nodes in the data storage system. For data identifiers and data obtained from the same third storage node, the central node in step S604 can send them in batches to the third storage node.
[0085] Furthermore, the central node can update the first mapping relationship based on the correspondence between the third group identifier and the third node identifier. The third node identifier is the identifier of the third storage node, and the updated first mapping relationship can be used subsequently for data caching or data retrieval from the third storage node.
[0086] Can be combined Figure 8 For example, Figure 8 This is a schematic diagram illustrating the change in the correspondence in the first mapping relationship under a storage node offline scenario provided in an embodiment of this application. For example... Figure 8 The data storage system shown contains three storage nodes: memcached1, memcached2, and memcached3, and six groups: PG1, PG2, PG3, PG4, PG5, and PG6. Before memcached3 went offline, the first mapping relationship indicated that PG1 and PG2 corresponded to memcached1, PG3 and PG6 corresponded to memcached3, and PG4 and PG5 corresponded to memcached2. After memcached3 went offline, according to the updated first mapping relationship in steps S601-S603, PG1, PG2, and PG3 corresponded to memcached1, and PG4, PG5, and PG6 corresponded to memcached2. The central node migrated the data whose data identifiers corresponded to PG3 and the corresponding data identifiers from the data stored in memcached3 to memcached1, and migrated the data whose data identifiers corresponded to PG6 and the corresponding data identifiers from the data stored in memcached3 to memcached2.
[0087] Before the first storage node goes offline, the above process can evenly transfer the cached data from that node to other storage nodes in the data storage system. Even if the first storage node goes offline, cache misses can be avoided, ensuring business continuity. Simultaneously, the caching tasks of the offline node can be evenly distributed among other storage nodes, improving overall system performance. Furthermore, if the random selection algorithm in this method uses the straw2 algorithm, based on its stable mapping characteristic mentioned earlier, it can ensure that data does not need cross-migrating in the scenario of storage node offline, minimizing the amount of data to be migrated and reducing network and server load.
[0088] The following is combined with Figure 9 For details on the expansion, please refer to [link / reference]. Figure 9 , Figure 9 This is a schematic diagram illustrating a data migration process in a storage node going online scenario, as provided in an embodiment of this application. Figure 9 As shown, the process may include steps S901-S905.
[0089] S901, the central node obtains the correspondence between the fourth group identifier and the fourth node identifier from the first mapping relationship.
[0090] The correspondence between the fourth group identifier and the fourth node identifier is the correspondence between any group identifier and node identifier in the first mapping relationship. The first mapping relationship contains multiple correspondences between group identifiers and node identifiers. For any group identifier and node identifier, the central node uses it as the fourth group identifier and the fourth node identifier, and traverses all group identifiers and node identifiers to execute steps S902-S905.
[0091] S902, the central node determines the sixth storage node corresponding to the fourth group identifier from the data storage system after the addition of the fifth storage node based on a random selection algorithm.
[0092] The first mapping relationship includes the correspondence between group identifiers and node identifiers before the addition of the fifth storage node. This correspondence was determined before the addition of the fifth storage node. When selecting storage nodes based on the random selection algorithm, the fifth storage node was not considered as a candidate. After the addition of the fifth storage node, in step S903, the central node can treat the fifth storage node as a candidate and perform random selection. For specific implementation details, please refer to [link to relevant documentation]. Figure 5The implementation of step S503 in the corresponding embodiment is described below and will not be repeated. Furthermore, if the random selection algorithm in this method uses the straw2 algorithm, based on the stable mapping characteristic of this algorithm described above, it is easy to see that the sixth storage node determined in step S902 is either the same storage node as the fifth storage node or the same storage node as the fourth storage node; there is no other third case. Here, the fourth storage node is the storage node indicated by the fourth node identifier in the data storage system. If the sixth storage node and the fourth storage node are the same storage node, it means that the data identifier and its data corresponding to the fourth group identifier are both in the original storage node and do not need to be migrated. If the sixth storage node and the fifth storage node are the same storage node, it means that the data identifier and its data corresponding to the fourth group identifier need to be migrated to the fifth storage node, and the central node needs to execute step S903.
[0093] S903, when the sixth storage node and the fifth storage node are the same storage node, the central node obtains the fifth data identifier and the fifth data from the fourth storage node.
[0094] The fourth storage node is the storage node indicated by the fourth node identifier in the data storage system, and the fifth data identifier and the fifth data are any set of data identifiers and data stored in the corresponding fourth storage node.
[0095] S904, the central node determines the fifth group identifier corresponding to the fifth data identifier based on the fifth data identifier and the consistent hashing algorithm.
[0096] If the sixth and fifth storage nodes are the same storage node, it indicates that data in the fourth storage node needs to be migrated to the fifth storage node. The central node filters out the data to be migrated from the fourth storage node through steps S903 and S904. For the data identifiers stored in the fourth storage node, the central node can first obtain all valid data identifiers and then send them to the fourth storage node. The fourth storage node can return the data corresponding to each valid data identifier to the central node. After obtaining all the corresponding data identifiers and data stored in the fourth storage node, the central node uses any set of data identifiers and data as the fifth data identifier and fifth data, and executes step S904 to iterate through all data identifiers and data.
[0097] In S904, if the fifth group identifier determined by the central node is different from the fourth group identifier, it means that the fifth data identifier and the fifth data do not need to be migrated. If the fifth group identifier determined by the central node is the same as the fourth group identifier, it means that the fifth data identifier belongs to the group that needs to be migrated (the group corresponding to the fifth group identifier), and data migration needs to be performed. Then, step S905 is executed.
[0098] S905, if the fifth group identifier is consistent with the fourth group identifier, the central node sends the fifth data identifier and the fifth data to the fifth storage node.
[0099] Understandably, the central node can send data identifiers and data that are to be migrated to the fifth storage node in batches.
[0100] Furthermore, the central node can update the first mapping relationship based on the correspondence between the fifth group identifier and the fifth node identifier. The fifth node identifier is the identifier of the fifth storage node, and the updated first mapping relationship can be used subsequently for data caching or data retrieval from the fifth storage node.
[0101] Can be combined Figure 10 For example, Figure 10 This is a schematic diagram illustrating the change in the correspondence in the first mapping relationship under a storage node online scenario provided in an embodiment of this application. For example... Figure 10 The data storage system shown contains three storage nodes: memcached1, memcached2, and memcached3, and six groups: PG1, PG2, PG3, PG4, PG5, and PG6. Before memcached3 went offline, the first mapping relationship indicated that PG1 and PG2 corresponded to memcached1, PG3 and PG6 corresponded to memcached3, and PG4 and PG5 corresponded to memcached2. After memcached4 came online, according to the updated first mapping relationship in steps S901-S904, PG1 and PG2 corresponded to memcached1, PG4 corresponded to memcached2, PG3 corresponded to memcached3, and PG5 and PG6 corresponded to memcached4. The central node migrated data from memcached2 whose data identifiers corresponded to PG5 to memcached4, and migrated data from memcached3 whose data identifiers corresponded to PG6 to memcached4.
[0102] After the fifth storage node comes online, the above process allows for the migration of some cached data from other storage nodes to the fifth storage node using a random selection algorithm. This avoids cache misses and ensures business continuity. Simultaneously, the fifth storage node can distribute caching tasks across multiple storage nodes, ensuring balanced workloads and improving overall system performance. Furthermore, if the random selection algorithm in this method uses the straw2 algorithm, based on its stable mapping characteristic mentioned earlier, it ensures that data does not require cross-migrating during storage node deployment, minimizing the amount of data to be migrated and reducing network and server load.
[0103] In practical applications, configuration files can be stored in the ETCD of the central node. When a memcached node comes online or offline, the relevant configuration files can be automatically retrieved, and related configuration information, such as memory limits and connection limits, can be read, enabling automated deployment of storage nodes. When the central node is scaling up or down, it can also periodically write task information to the ETCD, including the amount of data being migrated, migration rate, migration progress, and information such as the total capacity, used capacity, and available capacity of the data storage system. All of this information can be displayed, facilitating operations personnel's monitoring of the scaling status.
[0104] The following describes the related apparatus provided in the embodiments of this application. This application also provides a data processing apparatus applied in a data storage system. The data storage system includes a central node and at least two storage nodes, with the first storage node being one of the storage nodes. Each storage node is used to store data identifiers and data. The data processing apparatus is contained within the central node. (See also...) Figure 11 , Figure 11 This is a schematic diagram of the structure of a data processing device provided in this application, as shown below. Figure 11 As shown, the data processing device 110 includes: Interaction module 1101 is used to obtain the first data.
[0105] The calculation module 1102 is used to determine a first group identifier based on a consistent hashing algorithm according to a first data identifier. The first group identifier is a group identifier of a first group, used to indicate that the first data belongs to the first group.
[0106] The first data identifier is the identifier of the first data.
[0107] The calculation module 1102 is also used to determine the first storage node corresponding to the first group identifier from at least two storage nodes based on a random selection algorithm.
[0108] The interaction module 1101 is also used to send the first data identifier and the first data to the first storage node.
[0109] In one optional implementation, the calculation module 1102 is further configured to update the first mapping relationship based on the first group identifier and the first node identifier.
[0110] The first node identifier is the identifier of the first storage node. The first mapping relationship includes the correspondence between multiple groups of identifiers and node identifiers. The correspondence between the second group identifier and the second node identifier is one of these groups. The second group identifier is determined based on the second data identifier. The second node identifier is the identifier of the second storage node. The second storage node is any storage node in the data storage system. The second data identifier and the second data are any set of data identifiers and data stored in the second storage node.
[0111] The interaction module 1101 is also used to receive the first data read request.
[0112] The first data read request carries the first data identifier.
[0113] The calculation module 1102 is also used to determine the first group identifier based on the first data identifier using a consistent hashing algorithm, and to query the first mapping relationship to obtain the first node identifier corresponding to the first group identifier.
[0114] The interaction module 1101 is also used to obtain first data from the first storage node according to the first node identifier, and to respond to the first data read request and return the first data.
[0115] In one optional implementation, the storage nodes in the data storage system include three or more, and the first storage node is the storage node in the data storage system that goes offline within a preset time.
[0116] The interaction module 1101 is also used to obtain all data identifiers and data stored in the corresponding storage in the first storage node, and the third data identifier and the third data are any set of data identifiers and data stored in the corresponding storage in the first storage node.
[0117] The calculation module 1102 is also used to determine the third group identifier based on the third data identifier using a consistent hashing algorithm, and to determine the third storage node corresponding to the third group identifier from other storage nodes in the data storage system other than the first storage node using a random selection algorithm.
[0118] The interaction module 1101 is also used to send the third data identifier and the third data to the third storage node.
[0119] In another optional implementation, the calculation module 1102 is further configured to obtain the correspondence between the fourth group identifier and the fourth node identifier from the first mapping relationship, and to determine the sixth storage node corresponding to the fourth group identifier from the data storage system after the addition of the fifth storage node based on a random selection algorithm. The correspondence between the fourth group identifier and the fourth node identifier is any correspondence between a group identifier and a node identifier in the first mapping relationship.
[0120] When the sixth storage node and the fifth storage node are the same storage node, the interaction module 1101 is also used to obtain the fifth data identifier and the fifth data from the fourth storage node. The fourth storage node is the storage node indicated by the fourth node identifier in the data storage system, and the fifth data identifier and the fifth data are any set of data identifiers and data stored in the corresponding fourth storage node.
[0121] The calculation module 1102 is also used to determine the fifth group identifier corresponding to the fifth data identifier based on the consistent hashing algorithm.
[0122] If the fifth group identifier is the same as the fourth group identifier, the interaction module 1101 is also used to send the fifth data identifier and the fifth data to the fifth storage node.
[0123] It is understood that the data processing device 110 in the embodiments of this application can achieve... Figure 5 , Figure 6 or Figure 9 The steps performed by the central node in the corresponding embodiment. Regarding... Figure 11 For details on the specific implementation methods and corresponding beneficial effects of the functional components included in the data processing device 110, please refer to the foregoing. Figure 5 , Figure 6 or Figure 9 A detailed description of the embodiments.
[0124] See Figure 12 , Figure 12 This is a schematic diagram of another data processing device provided in the embodiments of this application, such as... Figure 12 As shown, the data processing device 120 includes a processor 1201, a memory 1202, and a communication interface 1203. The processor 1201 is connected to the memory 1202 and the communication interface 1203, for example, the processor 1201 can be connected to the memory 1202 and the communication interface 1203 via a bus.
[0125] Processor 1201 is configured to support data processing device execution Figure 5 , Figure 6 or Figure 9The corresponding function in the corresponding method. The processor 1201 can be a Central Processing Unit (CPU), a Network Processor (NP), a hardware chip, or any combination thereof. The aforementioned hardware chip can be an Application-Specific Integrated Circuit (ASIC), a Programmable Logic Device (PLD), or a combination thereof. The aforementioned PLD can be a Complex Programmable Logic Device (CPLD), a Field-Programmable Gate Array (FPGA), a Generic Array Logic (GAL), or any combination thereof.
[0126] The memory 1202 is used to store program code, etc. The memory 1202 includes internal memory, which may include at least one of the following: volatile memory (e.g., dynamic random access memory (DRAM), static RAM (SRAM), synchronous dynamic RAM (SDRAM), etc.) and non-volatile memory (e.g., one-time programmable read-only memory (OTPROM), programmable ROM (PROM), erasable programmable ROM (EPROM), electrically erasable programmable ROM (EEPROM). The memory 1202 may also include external memory, which may include at least one of the following: hard disk drive (HDD) or solid-state drive (SSD), flash drive, such as high-density flash (CF), secure digital (SD), micro SD, mini SD, extreme digital (xD), memory stick, etc.
[0127] Communication interface 1203 is used to receive or send data.
[0128] Processor 1201 can call the program code to perform the following operations: Get the first data; Based on the first data identifier, a first group identifier is determined using a consistent hashing algorithm. The first data identifier is the identifier of the first data; the first group identifier is the group identifier of the first group, used to indicate that the first data belongs to the first group. Based on a random selection algorithm, the first storage node corresponding to the first group identifier is determined from at least two storage nodes; Send the first data identifier and the first data to the first storage node.
[0129] It should be noted that the implementation of each operation can also be referred to accordingly. Figure 5 , Figure 6 or Figure 9 The corresponding description of the method embodiment shown; the processor 1201 can also be used to perform other operations in the above method embodiment.
[0130] This application also provides a computer program product that, when run by a computer, can perform the above-described... Figure 5 , Figure 6 or Figure 9 The method shown in the embodiment is designed for the central node.
[0131] This invention also provides a computer storage medium storing a computer program, the computer program including program instructions, which, when executed by a computer, cause the computer to perform the method described in the foregoing embodiments. The computer may be part of the data processing apparatus mentioned above.
[0132] Those skilled in the art will understand that all or part of the processes in the above embodiments can be implemented by a computer program instructing related hardware. The program can be stored in a computer-readable storage medium, and when executed, it can include the processes of the embodiments of the above methods. The storage medium can be a magnetic disk, optical disk, read-only memory (ROM), or random access memory (RAM), etc.
[0133] The above-disclosed embodiments are merely preferred embodiments of this application and should not be construed as limiting the scope of this application. Therefore, any equivalent variations made in accordance with the claims of this application shall still fall within the scope of this application.
Claims
1. A data storage method, wherein the method is applied in a data storage system, characterized in that, The data storage system includes a central node and at least two storage nodes, wherein the first storage node is one of the storage nodes, and the storage node is used to store data identifiers and data; the method includes: The central node acquires the first data; The central node determines a first group identifier based on a consistent hashing algorithm according to a first data identifier, where the first data identifier is the identifier of the first data; the first group identifier is the group identifier of the first group, used to indicate that the first data belongs to the first group; The central node determines the first storage node corresponding to the first group identifier from the at least two storage nodes based on a random selection algorithm; The central node sends the first data identifier and the first data to the first storage node.
2. The method according to claim 1, characterized in that, The method further includes: The central node updates the first mapping relationship based on the first group identifier and the first node identifier; the first node identifier is the identifier of the first storage node; the first mapping relationship includes the correspondence between multiple groups of group identifiers and node identifiers, and the correspondence between the second group identifier and the second node identifier is one of them; the second group identifier is determined based on the second data identifier; the second node identifier is the identifier of the second storage node; the second storage node is any storage node in the data storage system; the second data identifier and the second data are any set of data identifiers and data stored in the second storage node.
3. The method according to claim 1 or 2, characterized in that, The data storage system includes three or more storage nodes; the first storage node is a storage node in the data storage system that goes offline within a preset time; the method further includes: The central node obtains all data identifiers and data stored in the corresponding storage node in the first storage node; the third data identifier and the third data are any set of data identifiers and data stored in the corresponding storage node in the first storage node; The central node determines the third group identifier based on the third data identifier and a consistent hashing algorithm. The central node determines the third storage node corresponding to the third group identifier from other storage nodes in the data storage system, excluding the first storage node, based on a random selection algorithm. The central node sends the third data identifier and the third data to the third storage node.
4. The method according to claim 2, characterized in that, The method further includes: The central node obtains the correspondence between the fourth group identifier and the fourth node identifier from the first mapping relationship; the correspondence between the fourth group identifier and the fourth node identifier is the correspondence between any group identifier and node identifier in the first mapping relationship; The central node determines the sixth storage node corresponding to the fourth group identifier from the data storage system after the addition of the fifth storage node based on a random selection algorithm. When the sixth storage node and the fifth storage node are the same storage node, the central node obtains the fifth data identifier and the fifth data from the fourth storage node; the fourth storage node is the storage node indicated by the fourth node identifier in the data storage system, and the fifth data identifier and the fifth data are any set of data identifiers and data stored in the fourth storage node. The central node determines the fifth group identifier corresponding to the fifth data identifier based on the fifth data identifier using a consistent hashing algorithm; If the fifth group identifier matches the fourth group identifier, the central node sends the fifth data identifier and the fifth data to the fifth storage node.
5. The method according to claim 3, characterized in that, The central node obtains all data identifiers and data stored in the first storage node, including: The central node obtains all valid data identifiers stored in the first storage node from the first storage node; The central node sends all valid data identifiers to the first storage node; The central node receives the data corresponding to each data identifier from all the valid data identifiers returned by the first storage node.
6. A data processing apparatus, wherein the apparatus is applied in a data storage system, characterized in that, The data storage system includes a central node and at least two storage nodes, with the first storage node being one of the storage nodes. The storage node is used to store data identifiers and data. The data processing device is included in the central node; The data processing device includes: The interaction module is used to obtain the initial data. The calculation module is used to determine a first group identifier based on a consistent hashing algorithm according to a first data identifier, wherein the first data identifier is the identifier of the first data; and the first group identifier is the group identifier of the first group, used to indicate that the first data belongs to the first group. The calculation module is further configured to determine the first storage node corresponding to the first group identifier from the at least two storage nodes based on a random selection algorithm; The interaction module is also used to send the first data identifier and the first data to the first storage node.
7. The apparatus according to claim 6, characterized in that, The calculation module is further configured to update the first mapping relationship based on the first group identifier and the first node identifier; the first node identifier is the identifier of the first storage node; the first mapping relationship includes multiple sets of correspondences between group identifiers and node identifiers, and the correspondence between the second group identifier and the second node identifier is one of these sets; The second group identifier is determined based on the second data identifier; the second node identifier is the identifier of the second storage node; The second storage node is any storage node in the data storage system; The second data identifier and the second data are any set of data identifiers and data stored in the second storage node.
8. The apparatus according to claim 6 or 7, characterized in that, The data storage system includes three or more storage nodes; the first storage node is the storage node in the data storage system that goes offline within a preset time. The interaction module is further configured to obtain all data identifiers and data stored in the first storage node; the third data identifier and the third data are any set of data identifiers and data stored in the first storage node. The calculation module is further configured to determine a third group identifier based on the third data identifier using a consistent hashing algorithm, and to determine the third storage node corresponding to the third group identifier from other storage nodes in the data storage system other than the first storage node using a random selection algorithm. The interaction module is also used to send the third data identifier and the third data to the third storage node.
9. The apparatus according to claim 7, characterized in that, The calculation module is further configured to obtain the correspondence between the fourth group identifier and the fourth node identifier from the first mapping relationship, and to determine the sixth storage node corresponding to the fourth group identifier from the data storage system after the addition of the fifth storage node based on a random selection algorithm; the correspondence between the fourth group identifier and the fourth node identifier is the correspondence between any group identifier and node identifier in the first mapping relationship; When the sixth storage node and the fifth storage node are the same storage node, the interaction module is further configured to obtain a fifth data identifier and fifth data from the fourth storage node; the fourth storage node is the storage node indicated by the fourth node identifier in the data storage system, and the fifth data identifier and the fifth data are any set of data identifiers and data stored in the fourth storage node. The calculation module is further configured to determine the fifth group identifier corresponding to the fifth data identifier based on the consistent hashing algorithm; If the fifth group identifier is the same as the fourth group identifier, the interaction module is also used to send the fifth data identifier and the fifth data to the fifth storage node.
10. A computer-readable storage medium, characterized in that, The computer-readable storage medium stores a computer program that is executed by a processor to implement the method of any one of claims 1 to 5.