A method and related apparatus for distributed data storage
By obtaining storage cluster data and finding matching storage node locations in the distributed storage system, directly storing data blocks, the reliability and efficiency problems of the distributed storage system when the metadata server crashes, and achieving higher system reliability Sex and efficiency.
Patent Information
- Application Number
- CN201811554204.4
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2018-12-18
- Publication Date
- 2024-11-26
- Estimated Expiration
- 2038-12-18
AI Technical Summary
The existing distributed storage system has low reliability when the metadata server crashes or goes down, and the metadata server is under pressure and has low efficiency when multiple terminals store data.
By obtaining the storage cluster data, including the location and load of the storage node, dividing the data to be stored into multiple data blocks, and finding the storage node location matching the data blocks in the storage cluster, directly storing the data blocks in the corresponding nodes. Reduce dependence on metadata servers.
It improves the reliability and efficiency of the distributed storage system, avoids system crashes when the metadata server crashes, reduces the working pressure of the metadata server, and improves the efficiency when multiple terminals store data.
Smart Images

Figure CN109388351B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of distributed storage, and in particular to a distributed data storage method and related devices. Background Art
[0002] Traditional network storage systems use centralized storage servers to store all data. Storage servers become the bottleneck of system performance. The reliability and security of the system are reflected through storage servers. In order to meet the needs of large-scale storage applications, more and more storage systems use distributed storage systems. Distributed storage systems use a scalable system structure, use multiple storage servers to share the storage load, and use metadata servers to locate storage information.
[0003] In the current distributed storage system, when a terminal stores data, it first searches the metadata server for the location of the storage node, and then stores the data to be stored in the storage node according to the location of the storage node. In this way, when the metadata server crashes or goes down, the distributed storage system cannot work. The reliability of the distributed storage system is low. Moreover, when multiple terminals store data, multiple terminals need to send a request to the metadata server to search for the location of the storage node. The metadata server is under great workload and the efficiency of the distributed storage system is low. Summary of the invention
[0004] The embodiments of the present invention provide a distributed data storage method and related devices, in order to improve the reliability and efficiency of the distributed storage system.
[0005] A first aspect of the present invention provides a distributed data storage method, comprising:
[0006] Acquire storage cluster data, wherein the storage cluster data includes locations of N storage nodes, processes of the N storage nodes, and loads of the N storage nodes, where N is a positive integer;
[0007] Processing the data to be stored to obtain M data blocks, where M is a positive integer not greater than N;
[0008] Searching the storage cluster data for positions of M storage nodes that match the M data blocks, wherein the M data blocks correspond one-to-one to the positions of the M storage nodes, and the M storage nodes belong to the N storage nodes;
[0009] The M data blocks are stored in the M storage nodes according to positions of the M storage nodes, wherein the M data blocks correspond one-to-one to the M storage nodes.
[0010] Preferably, processing the data to be stored to obtain the M data blocks includes equally dividing the data to be stored into the M data blocks, the size of each data block in the M data blocks is K, and K includes any one of 4MB, 8MB, 16MB, and 32MB.
[0011] Optionally, processing the data to be stored to obtain the M data blocks further includes dividing data in the data to be stored into the M data blocks according to a degree of association, and data in each of the M data blocks are mutually associated.
[0012] A second aspect of the present invention provides a distributed data storage device, comprising:
[0013] An acquisition module, used to acquire storage cluster data, wherein the storage cluster data includes locations of N storage nodes, processes of the N storage nodes, and loads of the N storage nodes, where N is a positive integer;
[0014] A processing module, used for processing the data to be stored to obtain M data blocks, wherein M is a positive integer not greater than N;
[0015] A search module, used to search the storage cluster data for positions of M storage nodes matching the M data blocks, wherein the M data blocks correspond one-to-one to the positions of the M storage nodes, and the M storage nodes belong to the N storage nodes;
[0016] A storage module is used to store the M data blocks in the M storage nodes according to the positions of the M storage nodes, wherein the M data blocks correspond to the M storage nodes one by one.
[0017] A third aspect of the present invention provides an electronic device for distributed data storage, the electronic device comprising a processor, a memory, a communication interface and one or more programs, wherein the one or more programs are stored in the memory and configured to be executed by the processor, and the program includes instructions for executing any of the above-mentioned embodiments.
[0018] A fourth aspect of the present invention provides a computer-readable storage medium, wherein the computer-readable storage medium is used to store a computer program, and the computer program is executed by the processor to implement any of the above-mentioned embodiments.
[0019] It can be seen that when the terminal stores data, it obtains the storage cluster data, processes the data to be stored to obtain M data blocks, and searches for the locations of M storage nodes that match the M data blocks in the data to be stored. The M data blocks correspond to the locations of the M storage nodes one by one, and then the terminal stores each of the M data blocks in each of the M storage nodes according to the locations of the M storage nodes. When the metadata server crashes or goes down, the terminal can obtain the storage cluster data from the cache, thereby finding the locations of the M storage nodes, which improves the reliability of the distributed storage system, and when multiple terminals store data, multiple terminals do not need to query the metadata server for the location of specific storage nodes, which reduces the workload of the metadata server and improves the efficiency of the distributed storage system. BRIEF DESCRIPTION OF THE DRAWINGS
[0020] In order to more clearly illustrate the technical solutions in the embodiments of the present invention, the drawings required for use in the embodiments will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative work.
[0021] Figure 1 A flowchart of a distributed data storage method provided by an embodiment of the present invention;
[0022] Figure 2 A flowchart of another distributed data storage method provided by an embodiment of the present invention;
[0023] Figure 3 A flowchart of another distributed data storage method provided by an embodiment of the present invention;
[0024] Figure 4 A flowchart of another distributed data storage method provided by an embodiment of the present invention;
[0025] Figure 5 Schematic diagram of the correspondence between M data blocks and M storage nodes in an embodiment of the present invention;
[0026] Figure 6 A schematic diagram of capacity expansion provided by an embodiment of the present invention;
[0027] Figure 7 A schematic diagram of capacity reduction provided by an embodiment of the present invention;
[0028] Figure 8 A schematic diagram of a distributed data storage device provided by an embodiment of the present invention;
[0029] Fig. 9The present invention is a schematic diagram of the structure of an electronic device in a hardware operating environment according to an embodiment of the present invention. DETAILED DESCRIPTION
[0030] The embodiments of the present invention provide a distributed data storage method and related devices, in order to improve the reliability and efficiency of the distributed storage system.
[0031] In order to enable those skilled in the art to better understand the scheme of the present invention, the technical scheme in the embodiments of the present invention will be clearly and completely described below in conjunction with the drawings in the embodiments of the present invention. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work should fall within the scope of protection of the present invention.
[0032] The following are detailed descriptions of each.
[0033] The terms "first", "second", "third", "fourth", etc. in the specification and claims of the present invention and the above-mentioned drawings are used to distinguish different objects, rather than to describe a specific order. In addition, the terms "including" and "having" and any variations thereof 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 limited to the listed steps or units, but optionally includes steps or units that are not listed, or optionally includes other steps or units inherent to these processes, methods, products or devices.
[0034] In the embodiment of the present invention, the execution subject is a terminal, and the terminal can be connected to a metadata server or a data server.
[0035] The above-mentioned terminal may be, for example, a mobile phone, a tablet computer, a laptop computer, a PDA, a mobile Internet device, a wearable device or other types of terminals.
[0036] See first Figure 1 , Figure 1 A flowchart of a distributed data storage method provided by an embodiment of the present invention. Figure 1 As shown, a distributed data storage method provided by an embodiment of the present invention may include:
[0037] 101. Obtain storage cluster data, wherein the storage cluster data includes locations of N storage nodes, processes of the N storage nodes, and loads of the N storage nodes, where N is a positive integer.
[0038] The method for obtaining the storage cluster data may be:
[0039] An instruction for obtaining storage cluster data is sent to the metadata server, where the instruction for obtaining storage cluster data is used to instruct the metadata server to send the storage cluster data.
[0040] The storage cluster data sent by the metadata server is received.
[0041] Alternatively, the method for obtaining the storage cluster data may also be:
[0042] The storage cluster data pre-sent by the metadata server and stored in the cache is obtained from the cache.
[0043] Among them, the storage cluster data includes the locations of N storage nodes, the processes of the N storage nodes and the load of the N storage nodes, where N is a positive integer. In a distributed storage system, data is dispersedly stored in multiple storage nodes, and the storage nodes in the system have at least one corresponding backup storage node, so that when a storage node hangs up, the data can be restored through the backup storage node. The process of each storage node includes a working state and a hanging state, and there is a maximum load threshold for the load of each storage node. When the load of a storage node exceeds the maximum load threshold, the storage node will not be able to store other data.
[0044] 102. Process the data to be stored to obtain M data blocks, where M is a positive integer not greater than N.
[0045] Preferably, the method of processing the data to be stored to obtain the M data blocks may be:
[0046] The data to be stored is evenly divided into the M data blocks, the size of each data block in the M data blocks is K, and K includes any one of 4MB, 8MB, 16MB, and 32MB. If the data to be stored can be evenly divided, then the data to be stored is evenly divided into the M data blocks of size K. If the data to be stored cannot be evenly divided, then the remainder of the size of the data to be stored divided by K is calculated, and then the data to be stored is evenly divided into M-1 data blocks of size K, and the size of the Mth data block is the remainder of the size of the data to be stored divided by K.
[0047] Optionally, processing the data to be stored to obtain the M data blocks further includes dividing data in the data to be stored into the M data blocks according to a degree of association, and data in each of the M data blocks are mutually associated.
[0048] 103. Search the storage cluster data for positions of M storage nodes that match the M data blocks, wherein the M data blocks correspond one-to-one to the positions of the M storage nodes, and the M storage nodes belong to the N storage nodes.
[0049] The storage cluster data includes the locations of N storage nodes. To store the M data blocks, the locations of the M storage nodes that match the M data blocks must first be found. Each of the M data blocks has a corresponding storage node, and the storage nodes corresponding to each of the M data blocks belong to the N storage nodes.
[0050] 104. Store the M data blocks in the M storage nodes according to positions of the M storage nodes, wherein the M data blocks correspond to the M storage nodes one-to-one.
[0051] Optionally, after the M data blocks are stored in the M storage nodes, more sophisticated operations may be performed on the data blocks of a fixed size when accessing the data.
[0052] For example, the data to be stored is evenly divided into M data blocks of 4MB in size, and the terminal accesses the first data block among the M data blocks. When the storage node storing the first data block fails, the terminal accesses the backup storage node of the storage node storing the first data block. Since the size of the first data block is 4MB, the terminal only needs to obtain the corresponding 4MB of data from the backup storage node. Similarly, if the data to be stored is evenly divided into M data blocks of 256MB in size, the terminal accesses the first data block among the M data blocks. When the storage node storing the first data block fails, the terminal accesses the backup storage node of the storage node storing the first data block. Since the size of the first data block is 256MB, the terminal needs to obtain the corresponding 256MB of data from the backup storage node. Therefore, dividing the data to be stored into M data blocks of 4MB in size can perform more refined operations on the storage nodes in the system.
[0053] See also Figure 2 , Figure 2 A flowchart of another distributed data storage method provided by another embodiment of the present invention. Figure 2 As shown, another distributed data storage method provided by another embodiment of the present invention may include:
[0054] 201. A terminal receives storage cluster data sent by a metadata server.
[0055] The metadata server is used to manage the metadata of data in the distributed system.
[0056] The terminal sends an instruction for obtaining storage cluster data to the metadata server, where the instruction for obtaining storage cluster data is used to instruct the metadata server to send the storage cluster data to the terminal.
[0057] Among them, the storage cluster data includes the locations of N storage nodes, the processes of the N storage nodes and the load of the N storage nodes, where N is a positive integer. In a distributed storage system, data is dispersedly stored in multiple storage nodes, and the storage nodes in the system have at least one corresponding backup storage node, so that when a storage node hangs up, the data can be restored through the backup storage node. The process of each storage node includes a working state and a hanging state, and there is a maximum load threshold for the load of each storage node. When the load of a storage node exceeds the maximum load threshold, the storage node will not be able to store other data.
[0058] 202. The terminal processes the data to be stored to obtain M data blocks.
[0059] Wherein, M is a positive integer not greater than N.
[0060] Preferably, the method of processing the data to be stored to obtain the M data blocks may be:
[0061] The data to be stored is evenly divided into the M data blocks, the size of each data block in the M data blocks is K, and K includes any one of 4MB, 8MB, 16MB, and 32MB. If the data to be stored can be evenly divided, then the data to be stored is evenly divided into the M data blocks of size K. If the data to be stored cannot be evenly divided, then the remainder of the size of the data to be stored divided by K is calculated, and then the data to be stored is evenly divided into M-1 data blocks of size K, and the size of the Mth data block is the remainder of the size of the data to be stored divided by K.
[0062] Optionally, processing the data to be stored to obtain the M data blocks also includes dividing the data in the data to be stored into the M data blocks according to the degree of association, and the data in each data block of the M data blocks are mutually associated, so as to ensure that the data stored in a storage node are associated, thereby facilitating data search.
[0063] 203. The terminal obtains M key-value information of the M data blocks, wherein the M data blocks correspond to the M key-value information one-to-one.
[0064] Each of the M data blocks has a key value information, and the terminal obtains the key value information of each of the M data blocks, that is, obtains M key value information.
[0065] 204. The terminal processes the M key value information by using a hash algorithm to obtain M hash values corresponding to the M key value information.
[0066] Among them, the terminal processes M key value information through a hash algorithm, which can compress key value information of any length into a hash value of fixed length, and can ensure the uniqueness of the hash value. Hash algorithms include MD4, MD5 and SHA-1, among which MD5 and SHA-1 are the most widely used hash algorithms.
[0067] 205. The terminal searches the storage cluster data for positions of M storage nodes that match the M hash values, wherein the M hash values correspond one-to-one to the positions of the M storage nodes.
[0068] Among them, the storage cluster data includes the locations of N storage nodes, the processes of the N storage nodes and the load of the N storage nodes, N is a positive integer, and the storage cluster data also includes the correspondence between the hash value and the location of the storage node. The correspondence between the hash value and the location of the storage node can be stored in the storage cluster data in the form of a key-value value, and can also be stored in the storage cluster data in the form of a mapping relationship table.
[0069] Optionally, after the terminal finds the locations of the M storage nodes, it can search for the processes of the M storage nodes in the storage cluster data. When there is a storage node whose process is in a suspended state among the M storage nodes, the terminal can search for the location of the backup storage node corresponding to the suspended storage node in the storage cluster data, and then replace the location of the storage node in the suspended state originally found with the location of the backup storage node.
[0070] 206. The terminal sends a storage request message to the data server.
[0071] Among them, the data server is used to access and manage all storage nodes in the distributed system, including backup storage nodes. The above storage request message carries the locations of M storage nodes. After the data server receives the storage request message, it searches for M storage nodes among the N storage nodes in the distributed system according to the locations of the M storage nodes carried by the storage request message.
[0072] 207. The terminal stores the M data blocks in the M storage nodes through the data server.
[0073] Among them, the M data blocks correspond one-to-one to the M storage nodes.
[0074] See also Figure 3 , Figure 3 A flowchart of another distributed data storage method provided by another embodiment of the present invention. Figure 3As shown, another distributed data storage method provided by another embodiment of the present invention may include:
[0075] 301. The terminal obtains from a cache the storage cluster data that is pre-sent by a metadata server and stored in the cache.
[0076] Among them, the storage cluster data includes the locations of N storage nodes, the processes of the N storage nodes and the load of the N storage nodes, where N is a positive integer. In a distributed storage system, data is dispersedly stored in multiple storage nodes, and the storage nodes in the system have at least one corresponding backup storage node, so that when a storage node hangs up, the data can be restored through the backup storage node. The process of each storage node includes a working state and a hanging state, and there is a maximum load threshold for the load of each storage node. When the load of a storage node exceeds the maximum load threshold, the storage node will not be able to store other data.
[0077] The storage cluster data of a cluster is generally stable and does not change frequently. Therefore, the storage cluster data stored in the cache does not change frequently. When the metadata server fails, the terminal can obtain the storage cluster data from the memory instead of from the metadata server. The distributed storage system can still work normally when the metadata server fails.
[0078] 302. The terminal processes the data to be stored to obtain M data blocks.
[0079] Wherein, M is a positive integer not greater than N.
[0080] Preferably, the method of processing the data to be stored to obtain the M data blocks may be:
[0081] The data to be stored is evenly divided into the M data blocks, the size of each data block in the M data blocks is K, and K includes any one of 4MB, 8MB, 16MB, and 32MB. If the data to be stored can be evenly divided, then the data to be stored is evenly divided into the M data blocks of size K. If the data to be stored cannot be evenly divided, then the remainder of the size of the data to be stored divided by K is calculated, and then the data to be stored is evenly divided into M-1 data blocks of size K, and the size of the Mth data block is the remainder of the size of the data to be stored divided by K.
[0082] Optionally, processing the data to be stored to obtain the M data blocks also includes dividing the data in the data to be stored into the M data blocks according to the degree of association, and the data in each data block of the M data blocks are mutually associated, so as to ensure that the data stored in a storage node are associated, thereby facilitating data search.
[0083] 303. The terminal obtains M key-value information of the M data blocks, wherein the M data blocks correspond to the M key-value information one-to-one.
[0084] Each of the M data blocks has a key value information, and the terminal obtains the key value information of each of the M data blocks, that is, obtains M key value information.
[0085] 304. The terminal processes the M key value information by using a hash algorithm to obtain M hash values corresponding to the M key value information.
[0086] Among them, the terminal processes M key value information through a hash algorithm, which can compress key value information of any length into a hash value of fixed length, and can ensure the uniqueness of the hash value. Hash algorithms include MD4, MD5 and SHA-1, among which MD5 and SHA-1 are the most widely used hash algorithms.
[0087] 305. The terminal searches the storage cluster data for positions of M storage nodes that match the M hash values, wherein the M hash values correspond one-to-one to the positions of the M storage nodes.
[0088] Among them, the storage cluster data includes the locations of N storage nodes, the processes of the N storage nodes and the load of the N storage nodes, N is a positive integer, and the storage cluster data also includes the correspondence between the hash value and the location of the storage node. The correspondence between the hash value and the location of the storage node can be stored in the storage cluster data in the form of a key-value value, and can also be stored in the storage cluster data in the form of a mapping relationship table.
[0089] 306. The terminal searches for a process of M storage nodes in the storage cluster data.
[0090] The processes of the M storage nodes include a working state and a hanging state. When a storage node is in the hanging state, the storage node cannot work normally.
[0091] The terminal searches for the process of each storage node among the M storage nodes. When there is a storage node whose process is in a suspended state among the M storage nodes, the terminal searches for the location of the backup storage node corresponding to the suspended storage node in the storage cluster data until the locations of the backup storage nodes of all the storage nodes in the suspended state among the M storage nodes are found.
[0092] 307. The terminal replaces the location of the storage node in the down state with the location of the backup storage node.
[0093] 308. The terminal sends a storage request message to the data server.
[0094] Among them, the data server is used to access and manage all storage nodes in the distributed system, including backup storage nodes. The above storage request message carries the locations of M storage nodes. After the data server receives the storage request message, it searches for M storage nodes among the N storage nodes in the distributed system according to the locations of the M storage nodes carried by the storage request message.
[0095] 309. The terminal stores the M data blocks in the M storage nodes through the data server.
[0096] Among them, the M data blocks correspond one-to-one to the M storage nodes.
[0097] See also Figure 4 , Figure 4 A flowchart of another distributed data storage method provided by another embodiment of the present invention. Figure 4 As shown, another distributed data storage method provided by another embodiment of the present invention may include:
[0098] 401. Obtain storage cluster data, wherein the storage cluster data includes locations of N storage nodes, processes of the N storage nodes, and loads of the N storage nodes, where N is a positive integer.
[0099] The method for obtaining the storage cluster data may be:
[0100] An instruction for obtaining storage cluster data is sent to the metadata server, where the instruction for obtaining storage cluster data is used to instruct the metadata server to send the storage cluster data.
[0101] The storage cluster data sent by the metadata server is received.
[0102] Alternatively, the method for obtaining the storage cluster data may also be:
[0103] The storage cluster data pre-sent by the metadata server and stored in the cache is obtained from the cache.
[0104] Among them, the storage cluster data includes the locations of N storage nodes, the processes of the N storage nodes and the load of the N storage nodes, where N is a positive integer. In a distributed storage system, data is dispersedly stored in multiple storage nodes, and the storage nodes in the system have at least one corresponding backup storage node, so that when a storage node hangs up, the data can be restored through the backup storage node. The process of each storage node includes a working state and a hanging state, and there is a maximum load threshold for the load of each storage node. When the load of a storage node exceeds the maximum load threshold, the storage node will not be able to store other data.
[0105] 402. Process the data to be stored to obtain M data blocks, where M is a positive integer not greater than N.
[0106] Preferably, the method of processing the data to be stored to obtain the M data blocks may be:
[0107] The data to be stored is evenly divided into the M data blocks, the size of each data block in the M data blocks is K, and K includes any one of 4MB, 8MB, 16MB, and 32MB. If the data to be stored can be evenly divided, then the data to be stored is evenly divided into the M data blocks of size K. If the data to be stored cannot be evenly divided, then the remainder of the size of the data to be stored divided by K is calculated, and then the data to be stored is evenly divided into M-1 data blocks of size K, and the size of the Mth data block is the remainder of the size of the data to be stored divided by K.
[0108] Optionally, processing the data to be stored to obtain the M data blocks further includes dividing data in the data to be stored into the M data blocks according to a degree of association, and data in each of the M data blocks are mutually associated.
[0109] 403. Search the storage cluster data for positions of M storage nodes that match the M data blocks, wherein the M data blocks correspond one-to-one to the positions of the M storage nodes, and the M storage nodes belong to the N storage nodes.
[0110] The storage cluster data includes the locations of N storage nodes. To store the M data blocks, the locations of the M storage nodes that match the M data blocks must first be found. Each of the M data blocks has a corresponding storage node, and the storage nodes corresponding to each of the M data blocks belong to the N storage nodes.
[0111] Optionally, after the terminal finds the locations of the M storage nodes, it can search for the processes of the M storage nodes in the storage cluster data. When there is a storage node whose process is in a suspended state among the M storage nodes, the terminal can search for the location of the backup storage node corresponding to the suspended storage node in the storage cluster data, and then replace the location of the storage node in the suspended state originally found with the location of the backup storage node.
[0112] 404. The terminal sends a storage request message to the data server.
[0113] Among them, the data server is used to access and manage all storage nodes in the distributed system, including backup storage nodes. The above storage request message carries the locations of M storage nodes. After the data server receives the storage request message, it searches for M storage nodes among the N storage nodes in the distributed system according to the locations of the M storage nodes carried by the storage request message.
[0114] 405. The terminal stores the M data blocks in the M storage nodes through the data server.
[0115] Among them, the M data blocks correspond one-to-one to the M storage nodes.
[0116] 406. The terminal queries the load of N storage nodes in the storage cluster data.
[0117] When the load of N storage nodes exceeds the maximum load threshold, N storage nodes cannot store data, and the distributed storage system needs to be expanded.
[0118] 407. The terminal sends a capacity expansion instruction to the data server.
[0119] 408. The data server adds X storage nodes and distributes the data in N storage nodes to X storage nodes so that the data in N+X storage nodes are evenly distributed, where X is a positive integer.
[0120] 409. The terminal obtains the locations of the N+X storage nodes, the processes of the N+X storage nodes, and the loads of the N+X storage nodes.
[0121] 410. The terminal sends a first update instruction to the metadata server.
[0122] Among them, the above-mentioned first update instruction carries the positions of N+X storage nodes, the processes of N+X storage nodes and the load of N+X storage nodes. The first update instruction is used to instruct the metadata server to replace the positions of N storage nodes, the processes of N storage nodes and the load of N storage nodes with the positions of N+X storage nodes, the processes of N+X storage nodes and the load of N+X storage nodes.
[0123] 411. The metadata server replaces the positions of the N storage nodes, the processes of the N storage nodes, and the loads of the N storage nodes with the positions of the N+X storage nodes, the processes of the N+X storage nodes, and the loads of the N+X storage nodes.
[0124] Similarly, when the load of N storage nodes is less than the minimum load threshold, the terminal sends a capacity reduction instruction to the data server. After receiving the capacity reduction instruction, the data server reduces Y storage nodes and distributes the data in the N storage nodes to the remaining NY storage nodes so that the data in the NY storage nodes are evenly distributed, where Y is a positive integer less than N.
[0125] The terminal obtains the positions of NY storage nodes, the processes of NY storage nodes and the loads of NY storage nodes, and sends a second update instruction to the metadata server. The second update instruction carries the positions of NY storage nodes, the processes of NY storage nodes and the loads of NY storage nodes. After receiving the second update instruction, the metadata server replaces the positions of N storage nodes, the processes of N storage nodes and the loads of N storage nodes with the positions of NY storage nodes, the processes of NY storage nodes and the loads of NY storage nodes.
[0126] See also Figure 8 , Figure 8 A schematic diagram of a distributed data storage device provided by another embodiment of the present invention. Figure 8 As shown, another embodiment of the present invention provides a distributed data storage device which may include:
[0127] The acquisition module 801 is used to acquire storage cluster data, wherein the storage cluster data includes locations of N storage nodes, processes of the N storage nodes and loads of the N storage nodes, where N is a positive integer.
[0128] The acquisition module is specifically used for:
[0129] Sending a storage cluster data acquisition instruction to the metadata server, wherein the storage cluster data acquisition instruction is used to instruct the metadata server to send the storage cluster data;
[0130] Receiving the storage cluster data sent by the metadata server;
[0131] Alternatively, the storage cluster data pre-sent by the metadata server and stored in the cache is obtained from the cache.
[0132] The processing module 802 is used to process the data to be stored to obtain M data blocks, where M is a positive integer not greater than N.
[0133] The search module 803 is used to search the locations of M storage nodes matching the M data blocks in the storage cluster data, wherein the M data blocks correspond one-to-one to the locations of the M storage nodes, and the M storage nodes belong to the N storage nodes.
[0134] The search module is specifically used for:
[0135] Acquire M key value information of the M data blocks, wherein the M data blocks correspond to the M key value information one by one;
[0136] Processing the M key value information by a hash algorithm to obtain M hash values corresponding to the M key value information one by one;
[0137] The locations of the M storage nodes matching the M hash values are searched in the storage cluster data, wherein the M hash values correspond one-to-one to the locations of the M storage nodes.
[0138] The storage module 804 is configured to store the M data blocks in the M storage nodes according to the positions of the M storage nodes, wherein the M data blocks correspond to the M storage nodes one by one.
[0139] The storage module is specifically used for:
[0140] Sending a storage request message to a data server, the storage request message carrying the locations of the M storage nodes, the storage request message being used to instruct the data server to search for the M storage nodes according to the locations of the M storage nodes;
[0141] The M data blocks are stored in the M storage nodes through the data server.
[0142] The specific embodiments of the distributed data storage device of the present invention are basically the same as the embodiments of the above-mentioned distributed data storage method, and will not be described in detail here.
[0143] See also Fig. 9 , Fig. 9 The present invention is a schematic diagram of the structure of an electronic device in a hardware operating environment according to an embodiment of the present invention.
[0144] The electronic device for distributed data storage in the embodiment of the present invention may be a mobile phone, a tablet computer, a laptop computer, a PDA, a mobile Internet device, a wearable device or other types of terminals.
[0145] Among them, Fig. 9 As shown, the electronic device of the hardware operating environment involved in the embodiment of the present invention may include:
[0146] Processor 901, such as CPU.
[0147] Memory 902, optionally, the memory may be a high-speed RAM memory, or a stable memory, such as a disk memory.
[0148] The communication interface 903 is used to realize the connection and communication between the processor 901 and the memory 902 .
[0149] Optionally, the electronic device for distributed data storage in the embodiment of the present invention may further include a user interface, a network interface, a camera, a sensor, a WiFi module, etc. The user interface may include a display screen, an input unit such as a keyboard, and the optional user interface may further include a standard wired interface and a wireless interface. The network interface may optionally include a standard wired interface and a wireless interface (such as a WiFi interface).
[0150] Those skilled in the art will understand that Fig. 9 The structure of the distributed data storage electronic device shown in the figure does not constitute a limitation of the distributed data storage electronic device, and may include more or less components than shown in the figure, or combine certain components, or arrange the components differently.
[0151] like Fig. 9 As shown, the memory 902 may include an operating system, a network communication module, and a distributed data storage program. The operating system is a program that manages and controls the hardware and software resources of the electronic device for distributed data storage, and supports the operation of the distributed data storage program and other software or programs. The network communication module is used to realize communication between the components inside the memory 902, and communication with other hardware and software in the electronic device for distributed data storage.
[0152] exist Fig. 9 In the electronic device for distributed data storage shown, the processor 901 is used to execute the distributed data storage program stored in the memory 902 to implement the following steps:
[0153] Storage cluster data is obtained, wherein the storage cluster data includes locations of N storage nodes, processes of the N storage nodes, and loads of the N storage nodes, where N is a positive integer.
[0154] The data to be stored is processed to obtain M data blocks, where M is a positive integer not greater than N.
[0155] The locations of M storage nodes matching the M data blocks are searched in the storage cluster data, wherein the M data blocks correspond one-to-one to the locations of the M storage nodes, and the M storage nodes belong to the N storage nodes.
[0156] The M data blocks are stored in the M storage nodes according to positions of the M storage nodes, wherein the M data blocks correspond one-to-one to the M storage nodes.
[0157] Furthermore, in the step of acquiring storage cluster data, the processor 901 is used to execute the distributed data storage program stored in the memory 902 to implement the following steps:
[0158] Sending a storage cluster data acquisition instruction to the metadata server, wherein the storage cluster data acquisition instruction is used to instruct the metadata server to send the storage cluster data;
[0159] Receiving the storage cluster data sent by the metadata server;
[0160] Alternatively, the storage cluster data pre-sent by the metadata server and stored in the cache is obtained from the cache.
[0161] Further, in the step of searching the storage cluster data for the positions of the M storage nodes that match the M data blocks, the processor 901 is used to execute the distributed data storage program stored in the memory 902 to implement the following steps:
[0162] Acquire M key value information of the M data blocks, wherein the M data blocks correspond to the M key value information one by one;
[0163] Processing the M key value information by a hash algorithm to obtain M hash values corresponding to the M key value information one by one;
[0164] The locations of the M storage nodes matching the M hash values are searched in the storage cluster data, wherein the M hash values correspond one-to-one to the locations of the M storage nodes.
[0165] Further, the storage cluster data also includes at least one backup storage node corresponding to the N storage nodes. After the step of searching the storage cluster data for positions of M storage nodes matching the M data blocks, and before the step of storing the M data blocks in the M storage nodes according to the positions of the M storage nodes, the processor 901 is used to execute a distributed data storage program stored in the memory 902 to implement the following steps:
[0166] S1: searching the storage cluster data for a process of an i-th storage node among the M storage nodes, where i is a positive integer with an initial value of 1.
[0167] S2: When the process of the i-th storage node among the M storage nodes is in a down state, execute step S3; when the process of the i-th storage node among the M storage nodes is in a working state, execute step S4.
[0168] S3: searching the storage cluster data for a backup storage node corresponding to the ith storage node among the M storage nodes, and using the position of the backup storage node corresponding to the ith storage node among the M storage nodes as the position of the ith storage node among the M storage nodes.
[0169] S4: Assign the value of i+1 to i.
[0170] S5: When i is not greater than M, execute step S1.
[0171] Further, in the step of storing the M data blocks in the M storage nodes according to the positions of the M storage nodes, the processor 901 is used to execute the distributed data storage program stored in the memory 902 to implement the following steps:
[0172] Sending a storage request message to a data server, the storage request message carrying the locations of the M storage nodes, the storage request message being used to instruct the data server to search for the M storage nodes according to the locations of the M storage nodes;
[0173] The M data blocks are stored in the M storage nodes through the data server.
[0174] Furthermore, the processor 901 is further configured to execute a distributed data storage program stored in the memory 902 to implement the following steps:
[0175] Querying the load of the N storage nodes in the storage cluster data;
[0176] When the loads of the N storage nodes all exceed the maximum load threshold, sending an expansion instruction to the data server, the expansion instruction is used to instruct the data server to add X storage nodes and allocate the data in the N storage nodes to the X storage nodes so that the data in the N+X storage nodes are evenly distributed, where X is a positive integer;
[0177] Obtaining the locations of the N+X storage nodes, the processes of the N+X storage nodes, and the loads of the N+X storage nodes;
[0178] A first update instruction is sent to the metadata server, where the first update instruction carries the positions of the N+X storage nodes, the processes of the N+X storage nodes, and the loads of the N+X storage nodes, and the first update instruction is used to instruct the metadata server to replace the positions of the N storage nodes, the processes of the N storage nodes, and the loads of the N storage nodes with the positions of the N+X storage nodes, the processes of the N+X storage nodes, and the loads of the N+X storage nodes.
[0179] When the loads of the N storage nodes are all less than the minimum load threshold, a capacity reduction instruction is sent to the data server, wherein the capacity reduction instruction is used to instruct the data server to reduce Y storage nodes and allocate the data in the N storage nodes to the remaining NY storage nodes so that the data in the NY storage nodes are evenly distributed, wherein Y is a positive integer less than N;
[0180] Obtaining the locations of the NY storage nodes, the processes of the NY storage nodes, and the loads of the NY storage nodes;
[0181] A second update instruction is sent to the metadata server, wherein the second update instruction carries the positions of the NY storage nodes, the processes of the NY storage nodes and the loads of the NY storage nodes, and the second update instruction is used to instruct the metadata server to replace the positions of the N storage nodes, the processes of the N storage nodes and the loads of the N storage nodes with the positions of the NY storage nodes, the processes of the NY storage nodes and the loads of the NY storage nodes.
[0182] For example, the data to be stored is evenly divided into M data blocks of 4MB in size, and the M data blocks are stored in the storage node. When capacity expansion is required, the terminal accesses a storage node and re-stores a part of the data blocks in the newly added storage node. Since the size of each data block is 4MB, the terminal only needs to obtain 4MB of data from the storage node each time it is re-stored, and the 4MB of data is re-stored in the newly added storage node. Similarly, when capacity reduction is required, 4MB of data can also be operated. If the data to be stored is evenly divided into M data blocks of 256MB in size, the terminal needs to obtain 256MB of data from the storage node, and then needs to operate on 256MB of data each time. Therefore, the data to be stored is evenly divided into M data blocks of 4MB in size, so that more refined operations can be performed on the storage nodes in the system when expanding or reducing capacity.
[0183] It should be noted that, for the aforementioned method embodiments, for the sake of simplicity of description, they are all expressed as a series of action combinations, but those skilled in the art should be aware that the present invention is not limited by the described order of actions, because according to the present invention, certain steps can be performed in other orders or simultaneously. Secondly, those skilled in the art should also be aware that the embodiments described in the specification are all preferred embodiments, and the actions and modules involved are not necessarily required by the present invention. In the above embodiments, the description of each embodiment has its own emphasis. For parts that are not described in detail in a certain embodiment, please refer to the relevant description of other embodiments.
[0184] As described above, the above embodiments are only used to illustrate the technical solutions of the present invention, rather than to limit it. Although the present invention has been described in detail with reference to the aforementioned embodiments, those skilled in the art should understand that the technical solutions recorded in the aforementioned embodiments can still be modified, or some of the technical features therein can be replaced by equivalents. However, these modifications or replacements do not make the essence of the corresponding technical solutions deviate from the scope of the technical solutions of the embodiments of the present invention.
Claims
1. A distributed data storage method, characterized in that: include: Acquire storage cluster data, wherein the storage cluster data includes the locations of N storage nodes, the processes of the N storage nodes, and the loads of the N storage nodes, where N is a positive integer, and the storage cluster data also includes at least one backup storage node corresponding to the N storage nodes, and the process of each storage node includes a working state and a hanging state; Processing the data to be stored to obtain M data blocks, where M is a positive integer not greater than N, includes: evenly dividing the data to be stored into the M data blocks, the size of each data block in the M data blocks is K, K includes any one of 4MB, 8MB, 16MB, and 32MB, and the data of each data block in the M data blocks are related to each other; Searching the storage cluster data for positions of M storage nodes that match the M data blocks, wherein the M data blocks correspond one-to-one to the positions of the M storage nodes, and the M storage nodes belong to the N storage nodes; storing the M data blocks in the M storage nodes according to the positions of the M storage nodes, wherein the M data blocks correspond one-to-one to the M storage nodes; After searching the storage cluster data for the positions of the M storage nodes that match the M data blocks, and before storing the M data blocks in the M storage nodes according to the positions of the M storage nodes, the steps include: S1: searching the storage cluster data for the process of the i-th storage node among the M storage nodes, where i is a positive integer with an initial value of 1; S2: when the process of the i-th storage node among the M storage nodes is in a down state, execute step S3; when the process of the i-th storage node among the M storage nodes is in a working state, execute step S4; S3: searching the storage cluster data for a backup storage node corresponding to the i-th storage node among the M storage nodes, and using the position of the backup storage node corresponding to the i-th storage node among the M storage nodes as the position of the i-th storage node among the M storage nodes; S4: Assign the value of i+1 to i; S5: When i is not greater than M, execute step S1; The method further comprises: Querying the load of the N storage nodes in the storage cluster data; When the loads of the N storage nodes all exceed the maximum load threshold, an expansion instruction is sent to the data server, wherein the expansion instruction is used to instruct the data server to add X storage nodes and allocate the data in the N storage nodes to the X storage nodes so that the data in the N+X storage nodes are evenly distributed, wherein X is a positive integer, and the data server is used to access and manage all storage nodes in the distributed system; Obtaining the locations of the N+X storage nodes, the processes of the N+X storage nodes, and the loads of the N+X storage nodes; Sending a first update instruction to a metadata server, the first update instruction carrying the positions of the N+X storage nodes, the processes of the N+X storage nodes, and the loads of the N+X storage nodes, the first update instruction being used to instruct the metadata server to replace the positions of the N storage nodes, the processes of the N storage nodes, and the loads of the N storage nodes with the positions of the N+X storage nodes, the processes of the N+X storage nodes, and the loads of the N+X storage nodes, the metadata server being used to manage metadata of data in a distributed system; The method further comprises: When the loads of the N storage nodes are all less than the minimum load threshold, a capacity reduction instruction is sent to the data server, wherein the capacity reduction instruction is used to instruct the data server to reduce Y storage nodes and allocate the data in the N storage nodes to the remaining NY storage nodes so that the data in the NY storage nodes are evenly distributed, wherein Y is a positive integer less than N; Obtaining the locations of the NY storage nodes, the processes of the NY storage nodes, and the loads of the NY storage nodes; A second update instruction is sent to the metadata server, wherein the second update instruction carries the positions of the NY storage nodes, the processes of the NY storage nodes and the loads of the NY storage nodes, and the second update instruction is used to instruct the metadata server to replace the positions of the N storage nodes, the processes of the N storage nodes and the loads of the N storage nodes with the positions of the NY storage nodes, the processes of the NY storage nodes and the loads of the NY storage nodes.
2. The method according to claim 1, characterized in that The obtaining of storage cluster data comprises: Sending a storage cluster data acquisition instruction to the metadata server, wherein the storage cluster data acquisition instruction is used to instruct the metadata server to send the storage cluster data; Receiving the storage cluster data sent by the metadata server; Alternatively, the storage cluster data pre-sent by the metadata server and stored in the cache is obtained from the cache.
3. The method according to claim 2, characterized in that The searching the storage cluster data for the locations of the M storage nodes matching the M data blocks comprises: Acquire M key value information of the M data blocks, wherein the M data blocks correspond to the M key value information one by one; Processing the M key value information by a hash algorithm to obtain M hash values corresponding to the M key value information one by one; The locations of the M storage nodes matching the M hash values are searched in the storage cluster data, wherein the M hash values correspond one-to-one to the locations of the M storage nodes.
4. The method according to claim 1, wherein storing the M data blocks in the M storage nodes according to the positions of the M storage nodes comprises: Sending a storage request message to a data server, the storage request message carrying the locations of the M storage nodes, the storage request message being used to instruct the data server to search for the M storage nodes according to the locations of the M storage nodes; The M data blocks are stored in the M storage nodes through the data server.
5. A distributed data storage device, the device being used to execute the method according to any one of claims 1 to 4, characterized in that: The device comprises: An acquisition module, used to acquire storage cluster data, wherein the storage cluster data includes locations of N storage nodes, processes of the N storage nodes, and loads of the N storage nodes, where N is a positive integer; a processing module, used for processing the data to be stored to obtain M data blocks, wherein M is a positive integer not greater than N, and the processing module is further used for evenly dividing the data to be stored into the M data blocks, the size of each data block in the M data blocks is K, and K includes any one of 4MB, 8MB, 16MB, and 32MB; A search module, used to search the storage cluster data for positions of M storage nodes matching the M data blocks, wherein the M data blocks correspond one-to-one to the positions of the M storage nodes, and the M storage nodes belong to the N storage nodes; A storage module is used to store the M data blocks in the M storage nodes according to the positions of the M storage nodes, wherein the M data blocks correspond to the M storage nodes one by one.
6. An electronic device for distributed data storage, characterized in that: The electronic device includes a processor, a memory, a communication interface, and one or more programs, wherein the one or more programs are stored in the memory and configured to be executed by the processor, and the programs include instructions for executing the steps in any one of the methods of claims 1 to 4.
7. A computer-readable storage medium, characterized in that: The computer-readable storage medium is used to store a computer program, and the computer program is executed by a processor to implement the method according to any one of claims 1 to 4.
