The present disclosure relates to the field of computer technologies, and in particular, to a data processing method and apparatus and a storage medium.
With the rapid network development and the increasing data amount, uniform distribution of data in a distributed system is the key to ensuring normal operation of the distributed system. For example, when a machine in the distributed system crashes due to an excessively large amount of data in the machine, all data in the machine cannot be accessed and needs to be migrated to another machine; as a result, the distributed system becomes unstable. Therefore, how to ensure uniform distribution of data in machines in the distributed system is a problem that urgently needs to be resolved.
Embodiments of the present disclosure disclose a data processing method and apparatus and a storage medium, to achieve uniform distribution of data in machines.
A method and an apparatus for data processing are provided. For example, the apparatus includes interface circuitry and processing circuitry. In some embodiments, the interface circuitry connects the apparatus in a distributed system, and the processing circuitry generates first hash values respectively for a first group of virtual nodes to be added into a hash ring that is used to distribute data in the distributed system. The first group of virtual nodes represents a first newly added device, such as a data storage device, and the like in the distributed system. Then, the processing circuitry distributes the data in the distributed system according to the hash ring that includes the first group of virtual nodes with the first hash values. Further, the processing circuitry determines whether the distribution of the data in the distributed system satisfies a uniformity requirement. When the distribution of the data in the distribution system fails to satisfy the uniformity requirement, the processing circuitry identifies a specific virtual node in the first group of virtual nodes that causes the distribution to fail the uniformity requirement. Then, the processing circuitry generates a hash value for a makeup virtual node to replace the specific virtual node in the hash ring, and updates the distribution of the data in the distributed system based on the hash ring with the makeup virtual node.
In an example, the processing circuitry deletes, from the hash ring, the specific virtual node that causes the distribution to fail to satisfy the uniformity requirement, and generates the hash value for the makeup virtual node that is added into the hash ring.
In some embodiments, when the distribution of the data satisfies the uniformity requirement, the processing circuitry determines whether a number of devices in the distributed system reaches a preset number, and adding another device in the distributed system when the number of devices is lower than the preset number. For example, the processing circuitry generates second hash values respectively for a second group of virtual nodes to be added into the hash ring. The second group of virtual nodes represents a second newly added device in the distributed system. The processing circuitry then distributes the data in the distributed system according to the hash ring that includes the first virtual nodes with the first hash values and the second virtual nodes with the second hash values.
In some embodiments, the processing circuitry calculates a difference of data amounts of the distributed data to virtual nodes in the hash ring, and determines that the distribution fails to satisfy the uniformity requirement when the difference exceeds a preset threshold.
In some embodiments, the processing circuitry performs data distribution offline. When the number of devices reaches the preset number, the processing circuitry controls the distributed system to update data storage according to the hash ring. In an example, the processing circuitry determines a piece of data for a storage update to the first newly added device according to a hash value of the piece of data and the first group of virtual nodes in the hash ring. Then, the processing circuitry controls the distributed system via the interface circuitry to store the piece of data to the first newly added device.
Aspects of the disclosure also provide a non-transitory computer-readable medium storing instructions which when executed by a computer cause the computer to perform the method for data processing.
To describe the technical solutions in the embodiments of the present disclosure more clearly, the accompanying drawings for describing the embodiments of the present disclosure are simply described in the following. The accompanying drawings are merely exemplary embodiments, and those skilled in the art can derive other drawings from the accompanying drawings.
The following clearly and completely describes the technical solutions in the embodiments of the present disclosure with reference to the accompanying drawings in the embodiments of the present disclosure. The described embodiments are merely some rather than all of the embodiments of the present disclosure. All other embodiments obtained by those of ordinary skill in the art based on the embodiments of the present disclosure shall fall within the protection scope of the present disclosure.
The embodiments of the present disclosure disclose a data processing method and apparatus and a storage medium, to achieve uniform distribution of data in machines in a distributed system, and improve system stability. For better understanding of the embodiments of the present disclosure, the following first describes an application scenario of the embodiments of the present disclosure.
Referring to
For improvement of system stability, how to ensure uniform distribution of data in each machine in the distributed system is a problem that urgently needs to be resolved. To resolve the problem, the embodiments of the present disclosure disclose a data processing method, to achieve uniform distribution of data in each machine in the distributed system, that is, a difference between data amounts in each machine does not exceed a preset threshold range. The following provides a detailed description.
Referring to
S201. A data processing apparatus generates hash values of a plurality of virtual nodes for a newly added machine in a distributed system.
S202. The data processing apparatus divides existing data in the distributed system based on the hash values of the plurality of virtual nodes.
S203. The data processing apparatus determines whether data distribution in the distributed system after division is uniform. If no, step S204 is performed. If yes, this procedure ends.
S204. The data processing apparatus deletes a virtual node in the plurality of virtual nodes that leads to non-uniform data distribution in the distributed system, and generates a hash value of a makeup virtual node for the newly added machine.
S205. The data processing apparatus divides the existing data in the distributed system based on the hash value of the makeup virtual node. Then step S203 is performed again.
In this embodiment of the present disclosure, the data processing apparatus may be a terminal for data management in the distributed system, or may be a terminal responsible for data balance in the distributed system, which is not limited in this embodiment of the present disclosure.
In this embodiment of the present disclosure, operations may be performed offline, and the distributed system is deployed in an actual system after the existing data in the distributed system is uniformly distributed on virtual nodes, thereby avoiding increasing network load due to continual data migration.
In this embodiment of the present disclosure, the generating hash values of a plurality of virtual nodes for a newly added machine in a distributed system may include: generating the hash values of the plurality of virtual nodes by using a same hash function in a hash algorithm by adding a suffix to an IP address of the newly added machine.
In this embodiment of the present disclosure, that the data processing apparatus divides existing data in the distributed system based on the hash values of the plurality of virtual nodes may include: The data processing apparatus determines a location of each virtual node in the hash ring based on the hash values of the plurality of virtual nodes, and distributes data at each location in a corresponding section to each virtual node based on a preset section that each virtual node can manage. As shown in
In this embodiment of the present disclosure, if data distribution in the distributed system after division is non-uniform, a virtual node that leads to non-uniform data distribution may be deleted, and a hash value of a makeup virtual node is generated for the newly added machine. For example, as shown in
Correspondingly, the existing data in the distributed system is divided based on the hash value of the makeup virtual node, so that the data can be uniformly distributed to virtual nodes. As can be seen, in this implementation, a heuristic algorithm can be used to determine hash values of a plurality of virtual nodes of a newly added machine for uniform data distribution, thereby laying a foundation for improvement of system stability.
Referring to
S206. The data processing apparatus determines whether the number of machines in the distributed system reaches a preset number. If yes, this procedure ends. If no, step S207 is performed.
S207. The data processing apparatus adds a machine to the distributed system, and performs step S201.
In this embodiment of the present disclosure, the newly added machine may be the first machine in the distributed system. If the newly added machine is the first machine and the preset number of machines in the distributed system is greater than 1, after the data processing apparatus generates hash values of a plurality of virtual nodes for the first machine, the data processing apparatus may generate hash values of a plurality of virtual nodes for another newly added machine, to perform operations of step S202 to step S207, thereby maintaining balance of data distribution in the distributed system.
The determining whether data distribution in the distributed system after division is uniform may include: determining whether a difference between data amounts of virtual nodes in the distributed system after division does not exceed a preset threshold; and determining that data distribution in the distributed system after division is uniform if the preset threshold is not exceeded; or determining that data distribution in the distributed system after division is non-uniform if the preset threshold is exceeded. The difference between data amounts is an absolute value. For example, the difference between data amounts in machines is an absolute value of ±5%.
In an optional implementation, step S201 to step S207 may be performed when the data processing apparatus is in an offline state. Therefore, in the data processing method shown in
The data processing apparatus may determine a machine in which to-be-stored data is to be stored by performing the following steps:
11) calculating a hash value of the to-be-stored data;
12) calculating a location of the to-be-stored data in the hash ring based on the hash value, and determining a virtual node responsible for the to-be-stored data;
13) determining a target machine to which the virtual node belongs based on the virtual node; and
14) storing the to-be-stored data in the target machine.
As can be seen, a location, in the hash ring, of a virtual node in the distributed system may be determined by using the data processing method corresponding to step S201 to S207. The data processing method may also be referred to as a ring division algorithm.
In the data processing method shown in
Referring to
a generation unit 601, configured to generate hash values of a plurality of virtual nodes for a newly added machine in a distributed system;
a division unit 602, configured to divide existing data in the distributed system based on the hash values of the plurality of virtual nodes;
a determining unit 603, configured to determine whether data distribution in the distributed system after division is uniform; and
a deletion unit 604, configured to delete, when the determining unit 603 determines that data distribution in the distributed system after division is non-uniform, a virtual node in the plurality of virtual nodes that leads to non-uniform data distribution in the distributed system, and trigger the generation unit 601 to generate a hash value of a makeup virtual node for the newly added machine; and trigger the division unit 602 to divide the existing data in the distributed system based on the hash value of the makeup virtual node.
In this embodiment of the present disclosure, after the division unit 602 divides the existing data in the distributed system based on the hash value of the makeup virtual node, the determining unit 603 determines whether data distribution in the distributed system after division is uniform; and uses, if data distribution is non-uniform, the makeup virtual node as a virtual node that leads to non-uniform data distribution in the distributed system, and triggers the deletion unit 604 to perform the operation of deleting a virtual node that leads to non-uniform data distribution in the distributed system.
In this embodiment of the present disclosure, when data distribution in the distributed system after division is uniform, the determining unit 603 determines whether the number of machines in the distributed system reaches a preset number; and triggers an addition unit to add a machine to the distributed system if the preset number has not been reached, and triggers the generation unit 601 to perform the operation of generating hash values of a plurality of virtual nodes for a newly added machine in a distributed system.
In this embodiment of the present disclosure, when determining whether data distribution in the distributed system after division is uniform, the determining unit 603 is specifically configured to: determine whether a difference between data amounts of virtual nodes in the distributed system after division does not exceed a preset threshold; and determine that data distribution in the distributed system after division is uniform if the preset threshold is not exceeded; or determine that data distribution in the distributed system after division is non-uniform if the preset threshold is exceeded. The difference between data amounts is an absolute value. For example, the difference between data amounts in machines is an absolute value of ±5%.
In this embodiment of the present disclosure, the apparatus shown in
a deployment unit 605, configured to: when the number of machines in the distributed system reaches the preset number, deploy the distributed system to update a machine in which the existing data of the distributed system is stored, and determine locations of the plurality of virtual nodes in a hash ring based on the hash values of the plurality of virtual nodes of the newly added machine in the distributed system, to determine a machine in which to-be-stored data is to be stored.
In this embodiment of the present disclosure, operations may be performed offline, and the distributed system is deployed in an actual system after the existing data in the distributed system is uniformly distributed on virtual nodes, thereby avoiding increasing network load due to continual data migration.
In this embodiment of the present disclosure, that the division unit 602 divides existing data in the distributed system based on the hash values of the plurality of virtual nodes may include: determining a location of each virtual node in the hash ring based on the hash values of the plurality of virtual nodes, and distributing data at each location in a corresponding section to each virtual node based on a preset section that each virtual node can manage. Reference may be made to the related description corresponding to
In this embodiment of the present disclosure, if data distribution in the distributed system after division is non-uniform, the deletion unit 604 may delete a virtual node that leads to non-uniform data distribution, and generate a hash value of a makeup virtual node for the newly added machine. Reference may be made to the related description corresponding to
As can be seen, in this implementation, a heuristic algorithm can be used to determine hash values of a plurality of virtual nodes of a newly added machine for uniform data distribution, thereby improving system stability.
In this embodiment of the present disclosure, the deployment unit 605 deploys the distributed system online to update a machine in which the existing data of the distributed system is stored, and determines locations of the plurality of virtual nodes in a hash ring based on the hash values of the plurality of virtual nodes of the newly added machine in the distributed system, to determine a machine in which to-be-stored data is to be stored.
After the deployment unit 605 deploys the distributed system online to update the machine in which the existing data of the distributed system is stored, the data processing apparatus may further determine a machine in which to-be-stored data is to be stored, which may include the following operations: calculating a hash value of the to-be-stored data; calculating a location of the to-be-stored data in the hash ring based on the hash value, and determining a virtual node responsible for the to-be-stored data; determining a target machine to which the virtual node belongs based on the virtual node; and storing the to-be-stored data in the target machine.
In this embodiment of the present disclosure, a process of distributing data to a virtual node in the distributed system by the data processing apparatus may also be referred to as a ring division algorithm. As can be seen, the data processing apparatus may delete, by using the generation unit 601, the division unit 602, the determining unit 603, and the deletion unit 604, a virtual node that leads to non-uniform data distribution in the distributed system, thereby achieving uniform data distribution.
During actual application, the generation unit 601, the division unit 602, the determining unit 603, the deletion unit 604, and the deployment unit 605 may be implemented by using a central processing unit (CPU), a microprocessor (MPU), a digital signal processor (DSP), or a field-programmable gate array (FPGA).
Referring to
In an embodiment, the processor 701 may be combined with the data processing apparatus shown in
generating hash values of a plurality of virtual nodes for a newly added machine in a distributed system;
dividing existing data in the distributed system based on the hash values of the plurality of virtual nodes;
determining whether data distribution in the distributed system after division is uniform;
deleting, if data distribution is non-uniform, a virtual node in the plurality of virtual nodes that leads to non-uniform data distribution in the distributed system, and generating a hash value of a makeup virtual node for the newly added machine; and
dividing the existing data in the distributed system based on the hash value of the makeup virtual node.
In an embodiment, the processor 701 invokes the program code stored in the memory 703 to perform the following operations after the dividing the existing data in the distributed system based on the hash value of the makeup virtual node:
determining whether data distribution in the distributed system after division is uniform; and
using, if data distribution is non-uniform, the makeup virtual node as a virtual node that leads to non-uniform data distribution in the distributed system, and performing the operation of deleting a virtual node that leads to non-uniform data distribution in the distributed system.
In an embodiment, the processor 701 invokes the program code stored in the memory 703 to perform the following operations when data distribution in the distributed system after division is uniform:
determining whether the number of machines in the distributed system reaches a preset number; and
adding a machine to the distributed system if the preset number has not been reached, and performing the operation of generating hash values of a plurality of virtual nodes for a newly added machine in a distributed system.
In an embodiment, the processor 701 invokes the program code stored in the memory 703 to perform the following operations when determining whether data distribution in the distributed system after division is uniform:
determining whether a difference between data amounts of virtual nodes in the distributed system after division does not exceed a preset threshold; and
determining that data distribution in the distributed system after division is uniform if the preset threshold is not exceeded; or
determining that data distribution in the distributed system after division is non-uniform if the preset threshold is exceeded.
In an embodiment, the processor 701 invokes the program code stored in the memory 703 to perform the following operation when the number of machines in the distributed system reaches the preset number:
deploying the distributed system to update a machine in which the existing data of the distributed system is stored, and determining locations of the plurality of virtual nodes in a hash ring based on the hash values of the plurality of virtual nodes of the newly added machine in the distributed system, to determine a machine in which to-be-stored data is to be stored.
In an embodiment, after deploying the distributed system online to update the machine in which the existing data of the distributed system is stored, the processor 701 may further determine a machine in which to-be-stored data is to be stored, which may include the following operations: calculating a hash value of the to-be-stored data; calculating a location of the to-be-stored data in the hash ring based on the hash value, and determining a virtual node responsible for the to-be-stored data; determining a target machine to which the virtual node belongs based on the virtual node; and storing the to-be-stored data in the target machine.
In this embodiment of the present disclosure, a process of distributing data to a virtual node in the distributed system by the processor 701 may also be referred to as a ring division algorithm.
It is noted herein that the descriptions of the apparatus embodiments are similar to the descriptions of the method embodiments, and have similar beneficial effects as the method embodiments, and therefore no further description is provided. For the technical details not disclosed in the apparatus embodiments of the present disclosure, refer to the descriptions of the method embodiments of the present disclosure for understanding. For brevity, no further description is provided.
An embodiment of the present disclosure further provides a computer-readable storage medium, for example, a memory including a computer program. The computer program may be run by the processor of the data processing apparatus, to complete the steps of the method. Herein, the computer-readable storage medium may be a memory such as a ferromagnetic random access memory (FRAM), a read-only memory (ROM), a programmable read-only memory (PROM), an erasable programmable read-only memory (EPROM), an electrically erasable programmable read-only memory (EEPROM), a flash memory, a magnetic surface memory, an optical disc, or a compact disc read-only memory (CD-ROM); or may be various devices including one or any combination of the foregoing memories.
Further, the computer-readable storage medium stores a computer program, and the computer program is run by a processor to implement the following steps:
generating hash values of a plurality of virtual nodes for a newly added machine in a distributed system;
dividing existing data in the distributed system based on the hash values of the plurality of virtual nodes;
determining whether data distribution in the distributed system after division is uniform;
deleting, if data distribution is non-uniform, a virtual node in the plurality of virtual nodes that leads to non-uniform data distribution in the distributed system, and generating a hash value of a makeup virtual node for the newly added machine; and
dividing the existing data in the distributed system based on the hash value of the makeup virtual node.
In an embodiment, after the dividing the existing data in the distributed system based on the hash value of the makeup virtual node, the method further includes:
determining whether data distribution in the distributed system after division is uniform; and
using, if data distribution is non-uniform, the makeup virtual node as a virtual node that leads to non-uniform data distribution in the distributed system, and performing the step of deleting a virtual node that leads to non-uniform data distribution in the distributed system.
In an embodiment, if data distribution in the distributed system after division is uniform, the method further includes:
determining whether the number of machines in the distributed system reaches a preset number; and
adding a machine to the distributed system if the preset number has not been reached, and performing the step of generating hash values of a plurality of virtual nodes for a newly added machine in a distributed system.
In an embodiment, the determining whether data distribution in the distributed system after division is uniform includes:
determining whether a difference between data amounts of virtual nodes in the distributed system after division does not exceed a preset threshold; and
determining that data distribution in the distributed system after division is uniform if the preset threshold is not exceeded; or
determining that data distribution in the distributed system after division is non-uniform if the preset threshold is exceeded.
In an embodiment, if the number of machines in the distributed system reaches the preset number, the method further includes:
deploying the distributed system to update a machine in which the existing data of the distributed system is stored, and determining locations of the plurality of virtual nodes in a hash ring based on the hash values of the plurality of virtual nodes of the newly added machine in the distributed system, to determine a machine in which to-be-stored data is to be stored.
In the several embodiments provided in this application, it is understood that the disclosed device and method may be implemented in other manners. The described device embodiment is merely exemplary. For example, the unit division is merely logical function division and may be other division in an actual implementation. For example, a plurality of units or components may be combined or integrated into another system, or some features may be ignored or not performed. In addition, the displayed or discussed mutual couplings or direct couplings or communication connections between components may be implemented by using some interfaces. The indirect couplings or communication connections between the devices or units may be implemented in electronic, mechanical, or other forms.
The units described as separate parts may or may not be physically separate, and parts displayed as units may or may not be physical units, may be located at one place, or may be distributed on a plurality of network units. Some or all of the units may be selected depending on actual needs to achieve the objectives of the solutions of the embodiments.
In addition, functional units in the embodiments of the present disclosure may be all integrated into one processing unit, or each of the units may exist alone, or two or more units may be integrated into one unit. The integrated unit may be implemented in a form of hardware, or may be implemented in a form of hardware in addition to a software functional unit.
Those of ordinary skill in the art may understand that all or some of the steps of the method embodiments may be implemented by a program instructing relevant hardware. The program may be stored in a computer-readable storage medium. When the program runs, the steps of the method embodiments are performed. The storage medium may include various media that can store program code, such as a mobile storage device, a ROM, a RAM, a magnetic disk, or an optical disc.
Alternatively, when the integrated unit in the present disclosure is implemented in the form of a software functional module and sold or used as an independent product, the integrated module may be stored in a computer-readable storage medium. Based on such an understanding, the technical solutions in the embodiments of the present disclosure essentially or the part contributing to the existing technologies may be implemented in a form of a software product. The software product is stored in a storage medium, and includes several instructions for instructing a computer device (which may be a personal computer, a server, or a network device) to perform all or some of the steps of the methods described in the embodiments of the present disclosure. The storage medium includes various media that can store program code, such as a mobile storage device, a ROM, a RAM, a magnetic disk, or an optical disc.
It is noted that the various modules, submodules, units, subunits, and components in the present disclosure can be implemented using any suitable technology. For example, a module or a unit can be implemented using processing circuitry. In an example, a module or a unit can be implemented using integrated circuit (IC). In another example, a module or a unit can be implemented as a processor executing software instructions. In another example, interface circuitry is used to implement receiving unit (or module) and/or sending unit (or module).
The descriptions are merely specific implementations of the present disclosure, but are not intended to limit the protection scope of the present disclosure. Any variation or replacement readily figured out by those skilled in the art within the technical scope disclosed in the present disclosure shall fall within the protection scope of the present disclosure. Therefore, the protection scope of the present disclosure shall be subject to the protection scope of the claims.
In the embodiments of the present disclosure, hash values of a plurality of virtual nodes can be generated for a newly added machine in a distributed system. Existing data in the distributed system is divided based on the hash values of the plurality of virtual nodes. It is determined whether data distribution in the distributed system after division is uniform. A virtual node in the plurality of virtual nodes that leads to non-uniform data distribution in the distributed system is deleted if data distribution is non-uniform, and a hash value of a makeup virtual node is generated for the newly added machine. The existing data in the distributed system is then divided based on the hash value of the makeup virtual node. In this way, a foundation is laid for uniform distribution of data in machines and improvement of system stability.
Number | Date | Country | Kind |
---|---|---|---|
201610882278.5 | Oct 2016 | CN | national |
This application is a continuation of International Application No. PCT/CN2017/103239, filed on Sep. 25, 2017, which claims priority to Chinese Patent Application No. 201610882278.5 filed on Oct. 8, 2016. The entire disclosures of the prior applications are incorporated by reference herein in their entirety.
Number | Date | Country | |
---|---|---|---|
Parent | PCT/CN2017/103239 | Sep 2017 | US |
Child | 16220678 | US |