Data storage method, device, computer equipment, storage medium and program product
By implementing a data storage method on the management node of the distributed database system, in response to the storage request of the target data, the target availability zone is determined from multiple availability zones, the candidate data node grouping is determined based on the remaining space rate of each data node group in the target availability zone, and the target data node grouping is determined from the candidate data node grouping, and finally multiple copies of the target data are stored in the target data node grouping, which solves the problem of long-term determination of data nodes in the distributed database system, and improves storage efficiency and high availability of the system.
Patent Information
- Application Number
- CN202411814952.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-12-11
- Publication Date
- 2025-04-04
- Estimated Expiration
- 2044-12-11
AI Technical Summary
The determination time of data nodes in distributed database systems is long, resulting in low overall storage efficiency.
By implementing a data storage method on the management node of the distributed database system, in response to the storage request of the target data, the target availability zone is determined from multiple availability zones, the candidate data node packet is determined based on the remaining space rate of each data node packet in the target availability zone, and the target data node packet is determined from the candidate data node packet, and finally multiple copies of the target data are stored in the target data node packet.
It shortens the determination time of data nodes, improves the storage efficiency of distributed database systems, and improves the system's high availability and disaster recovery capabilities through cross-AZ deployment and data balance strategies.
Smart Images

Figure CN119293044B_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the technical field of data storage, and in particular to a data storage method, apparatus, computer equipment, storage medium and program product. Background Art
[0002] A distributed database system consists of a management node and multiple data nodes. The management node is responsible for the overall management and monitoring of the system, while the data node is responsible for actual data storage and retrieval. The two work together to ensure the stable operation of the system.
[0003] In the related art, when storing data in a distributed database system, in order to prevent accidental loss of data and resulting in inaccessibility, the management node usually copies the data into multiple copies, each of which is called a replica, and writes them to different data nodes respectively to achieve redundant backup of the data.
[0004] However, the related art has the problem that it takes a long time to determine the data nodes, resulting in low overall storage efficiency of the distributed database system. Summary of the invention
[0005] Based on this, it is necessary to provide a data storage method, device, computer equipment, storage medium and program product to address the above technical problems, shorten the determination time of data nodes, and improve the storage efficiency of distributed database systems.
[0006] In a first aspect, the present application provides a data storage method, which is applied to a management node of a distributed database system, and the method includes:
[0007] In response to a storage request for target data, a target availability zone is determined from multiple availability zones of a distributed database system; each availability zone includes multiple data node groups;
[0008] Determine candidate data node groups for target data based on the remaining space rate of each data node group in the target availability zone;
[0009] A target data node group is determined from each candidate data node group, and multiple copies of the target data are stored in the target data node group.
[0010] In one embodiment, determining the candidate data node grouping of the target data according to the remaining space rate of each data node grouping in the target available zone includes:
[0011] Sort the data nodes in groups according to the remaining space rate from large to small;
[0012] From the sorted data node grouping sequence, a plurality of candidate data node groups matching a preset grouping quantity are determined in sequence.
[0013] In one embodiment, multiple data nodes in the target data node group are distributed in different computer rooms; storing multiple copies of the target data in the target data node group includes:
[0014] Determine the number of nodes to be allocated to each computer room based on the number of copies of the target data and the number of computer rooms corresponding to the target data node groupings;
[0015] When the number of available data nodes in each computer room is greater than the number of nodes allocated in each computer room, the data nodes in each computer room that match the number of nodes allocated are determined as target data nodes;
[0016] Multiple copies of the target data are stored in the target data nodes of each computer room.
[0017] In one embodiment, determining the number of nodes to be allocated to each computer room according to the number of copies of the target data and the number of computer rooms corresponding to the target data node groupings includes:
[0018] According to the uniformly distributed storage method, the quotient is calculated based on the number of copies of the target data and the number of computer rooms corresponding to the target data node grouping;
[0019] If there is no remainder in the result of the quotient, the result of the quotient is determined as the number of nodes allocated to each computer room;
[0020] If there is a remainder in the result of the quotient, the integer value in the result is determined as the initial node allocation quantity of each computer room, and the initial node allocation quantity in the computer room matching the remainder is adjusted to obtain the node allocation quantity of each computer room.
[0021] In one embodiment, multiple copies of the target data are stored in target data nodes in each computer room, including:
[0022] For any computer room, sort the data nodes according to the remaining available space of each data node in the computer room to obtain a data node sequence;
[0023] Determine candidate data nodes that match a preset number of nodes from the sorted data node sequence;
[0024] Randomly determine the target data node that matches the node allocation quantity from each candidate data node;
[0025] Store the replicas that match the number of nodes assigned to each target data node in the computer room.
[0026] In one embodiment, the method further comprises:
[0027] If the number of available data nodes in any computer room is less than the number of nodes allocated in the computer room, the target data node group is removed from each candidate data node group, and a new target data node group is re-determined from the removed candidate data node groups.
[0028] In a second aspect, the present application further provides a data storage device, the device comprising:
[0029] A request response module, configured to respond to a storage request for target data and determine a target availability zone from multiple availability zones of a distributed database system; each availability zone includes multiple data node groups;
[0030] A grouping evaluation module is used to determine candidate data node groups for target data based on the remaining space rate of each data node group in the target availability zone;
[0031] The data storage module is used to determine the target data node group from each candidate data node group and store multiple copies of the target data in the target data node group.
[0032] In a third aspect, the present application further provides a computer device, including a memory and a processor, wherein the memory stores a computer program, and when the processor executes the computer program, the steps of the method in any one of the embodiments of the first aspect are implemented.
[0033] In a fourth aspect, the present application further provides a computer-readable storage medium having a computer program stored thereon, which, when executed by a processor, implements the steps of the method in any one of the embodiments of the first aspect above.
[0034] In a fifth aspect, the present application further provides a computer program product, comprising a computer program, which, when executed by a processor, implements the steps of the method in any one of the embodiments of the first aspect above.
[0035] In the above data storage method, device, computer equipment, storage medium and program product, the management node of the distributed database system determines the target available zone from multiple available zones of the distributed database system in response to the storage request of the target data; determines the candidate data node group of the target data according to the remaining space rate of each data node group in the target available zone; determines the target data node group from each candidate data node group, and stores multiple copies of the target data in the target data node group. In this method, in the target data storage scenario, in response to the storage request of the target data, the target available zone is first determined from multiple available zones, then the candidate data node group is determined from the target available zone, then the target data node group is determined from the candidate data node group, and finally the data node storing the copy of the target data is determined from the target data node group. In this way, a layer-by-layer routing method is adopted to gradually narrow the determination range of the data node storing the copy of the target data, so as to shorten the determination time of the data node, quickly store multiple copies of the target data, and thus improve the data storage efficiency of the distributed database system. Moreover, when determining the target availability zone, the target availability zone closest to the area where the storage request is triggered can be selected according to the principle of proximity to reduce network latency; when determining the target data node grouping, the candidate data node grouping is determined according to the remaining space rate of each data node grouping in the target availability zone to ensure the rationality of each candidate data node grouping. Furthermore, the method of selecting the target data node grouping from each candidate data node can not only ensure the rationality of the target data node grouping, but also improve the flexibility and diversity of the target data node grouping to a certain extent, and avoid data hot spots of data nodes. In addition, the distributed database system includes multiple availability zones, and the data transmission processes between the availability zones are isolated from each other to avoid failures in a single availability zone, such as hardware failures, network problems, etc., which may cause the entire distributed database system to be unavailable, thereby improving the high availability of the distributed database system. BRIEF DESCRIPTION OF THE DRAWINGS
[0036] In order to more clearly illustrate the technical solutions in the embodiments of the present application or related technologies, the drawings required for use in the embodiments of the present application or related technical descriptions will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present application. For ordinary technicians in this field, other related drawings can be obtained based on these drawings without paying creative work.
[0037] Figure 1 An application environment diagram of a data storage method in one embodiment;
[0038] Figure 2 A first flow chart of a data storage method in one embodiment;
[0039] Figure 3A schematic diagram of grouping data nodes in an available zone in one embodiment;
[0040] Figure 4 A schematic diagram of a flow chart of a data node grouping and sorting step in one embodiment;
[0041] Figure 5 A schematic diagram of the deployment of an available zone computer room in one embodiment;
[0042] Figure 6 A second flow chart of a data storage method in one embodiment;
[0043] Figure 7 A schematic diagram of a flow chart of a step of determining the number of nodes allocated to a computer room in one embodiment;
[0044] Figure 8 A third flow chart of a data storage method in one embodiment;
[0045] Fig. 9 A fourth flow chart of a data storage method in one embodiment;
[0046] Fig.10 is a structural block diagram of a data storage device in one embodiment;
[0047] Fig.11 FIG. 4 is a diagram showing the internal structure of a computer device in one embodiment. DETAILED DESCRIPTION
[0048] In order to make the purpose, technical solution and advantages of the present application more clearly understood, the present application is further described in detail below in conjunction with the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are only used to explain the present application and are not used to limit the present application.
[0049] The technical background of this application is first described below.
[0050] Distributed database systems store data on multiple different data nodes. Unlike centralized databases, the data nodes of distributed databases are distributed on different servers. The networks between the servers are interconnected and logically form a unified whole. In addition, distributed database systems include multiple clients so that users can access the global data of the distributed database system from any location.
[0051] For the cluster architecture of distributed database systems, physical resources (such as data, servers, and applications) are usually distributed in different regions, and each region is called an availability zone. Existing technical solutions usually deploy all data nodes of the distributed database system in the same region, that is, one distributed database system corresponds to one availability zone (AZ). This deployment method has at least the following problems:
[0052] (1) High-risk concentration. All data nodes are deployed in the same AZ. If a failure occurs in the AZ (such as power outage, network failure, etc.), the entire distributed database system will be unavailable.
[0053] (2) Load imbalance. All traffic is concentrated in one AZ, which may cause the load of the AZ to be too high, but it cannot be balanced to other availability zones.
[0054] (3) Limited scalability. As the business grows, when nodes need to be expanded horizontally, due to the limited resources of a single AZ, it may not be able to provide sufficient computing, storage, and network resources, limiting the horizontal expansion capabilities of the database system.
[0055] Furthermore, when using the above cluster architecture for data storage, in order to prevent accidental data loss and inaccessibility, the data will be copied into multiple copies when writing data. Each copy of the data is called a replica and is written to different data nodes respectively to improve data redundancy and achieve data backup and disaster recovery.
[0056] The data routing algorithm is a strategy that determines how data copies are distributed on multiple data nodes. An effective data routing algorithm can improve the scalability and fault tolerance of the system. However, for the data routing algorithm of distributed database systems, the existing technical solutions are mostly applied to small-scale database systems and do not take into account data balance and hot spot issues. For example, when adopting the remaining space priority strategy, when selecting data nodes, unavailable data nodes are first eliminated, and then all available nodes are traversed to obtain the remaining space of the nodes, and the node with the largest remaining space is found in the cluster as the target node.
[0057] In actual application scenarios, the data routing strategy in related technologies needs to traverse all data nodes in the cluster when selecting the target data node. In scenarios with large data scale, the number of data nodes can reach hundreds. It takes too long and is inefficient to traverse all nodes and obtain their remaining space, which is not suitable for large distributed database systems. In addition, selecting the node with the largest remaining space may cause hot spot problems. For example, in scenarios with frequent data writing, the routing algorithm repeatedly selects the same target data node with the largest remaining space, which will cause the node to be overloaded and cause node failure.
[0058] Based on this, the embodiment of the present application provides a distributed database system architecture, which improves the reliability, availability and scalability of the distributed database system by deploying different data nodes in multiple AZs. Furthermore, in a large distributed database system deployed across AZs, a data storage method of a data routing strategy is proposed to improve data storage efficiency and ensure data balance and load balance among data nodes.
[0059] Before describing the technical solution of the embodiment of the present application, the application scenario of the embodiment of the present application is described first.
[0060] The data storage method provided in the embodiment of the present application can be applied to Figure 1 In the application environment shown, Figure 1 The distributed database system includes a management node and multiple data nodes. The management node is connected to each data node, and the multiple data nodes are divided into different availability zones according to the region. Figure 1 Taking a distributed database system including Q availability zones as an example, there is no data transmission between different availability zones. This communication method can effectively avoid failures in a single availability zone, such as hardware failures, network problems, etc., which may cause the entire distributed database system to be unavailable, thereby improving the high availability of the distributed database system.
[0061] In actual applications, multiple data nodes are deployed in each availability zone, and all copies of a data block are distributed on the data nodes of the same AZ. The number of data nodes in each availability zone can be planned according to the frequency of user requests in different regions. For example, the number of nodes deployed in the availability zone with a high user request frequency can be increased. The data node can be a server for storing data.
[0062] The technical solution of the present application and how the technical solution of the present application solves the above-mentioned technical problems are described in detail below with specific embodiments. The following specific embodiments can be combined with each other, and the same or similar concepts or processes may not be repeated in some embodiments. The embodiments of the present application will be described below in conjunction with the accompanying drawings.
[0063] In an exemplary embodiment, Figure 2 As shown, a data storage method is provided, which is applied to a management node of a distributed database system, and the method includes:
[0064] S201, in response to a storage request for target data, determining a target availability zone from multiple availability zones of a distributed database system; each availability zone includes multiple data node groups.
[0065] A distributed database system includes multiple clients, which can be distributed in different regions for users to access. In practical applications, a distributed database system is a unified whole in logic, and users can access all data in the distributed database system from any client.
[0066] The distributed database system includes a management node and multiple data nodes. The management node is used to respond to access requests triggered on any client corresponding to the distributed database system, and based on the access request, search or store the corresponding data from each data node, and return the data processing results to the client.
[0067] It should be noted that in the embodiment of the present application, multiple data nodes of the distributed database system are divided into different availability zones according to the geographical scope, and each availability zone can be regarded as a region. In addition, within each availability zone, multiple data nodes of the availability zone are equally divided into multiple data node groups. For example, each availability zone in the distributed database system includes M×N data nodes, see Figure 3 , Figure 3 This is an architecture diagram of a distributed database system. The data nodes are divided into M groups in an equal manner, and each data node group includes N data nodes.
[0068] In the embodiment of the present application, the storage request is triggered when any client corresponding to the distributed database system uploads the target data. In response to the storage request for the target data, the management node determines the requested physical location corresponding to the storage request based on the IP location, geolocation service and other triggering information, and then determines the available area closest to the requested physical location as the target available area based on the distance between the physical location of each available area and the requested physical location, so as to reduce network delay and improve access speed.
[0069] S202: Determine candidate data node groups for target data according to the remaining space ratio of each data node group in the target available zone.
[0070] For each data node group in the target availability zone, obtain the remaining available space and initial capacity of each data node in the data node group, calculate the sum of the remaining available space of each data node as the total remaining space of the data node group, calculate the sum of the initial capacity of each data node as the total capacity of the data node group, and use the ratio between the total remaining space and the total capacity as the remaining space rate of the data node group.
[0071] For each data node group in the target availability zone, the remaining space rate is expressed as follows:
[0072]
[0073] in, The remaining space ratio of the data node group. The sum of the remaining available space of all data nodes in the data node group. It is the sum of the total capacity of all data nodes in the data node group.
[0074] When determining the remaining space rate of each data node group in the target availability zone, multiple data node groups whose remaining space rates are within a preset range can be determined as candidate data node groups, or multiple data node groups whose remaining space rates are greater than a preset space rate threshold can be determined as candidate data node groups, to ensure that each candidate data node group can store multiple copies of the target data.
[0075] In order to prevent the need to traverse all data nodes under all data node groups each time data routing is performed, in an embodiment of the present application, each data node group and the remaining space rate of each data node group are dynamically maintained. When a data node group writes data, deletes data, or all data nodes go down, the remaining space rate of the group to which the data node belongs is recalculated.
[0076] S203, determining a target data node group from each candidate data node group, and storing multiple copies of the target data in the target data node group.
[0077] It should be noted that in the embodiment of the present application, multiple copies of the target data are stored in the same data node group. Then, when multiple candidate data node groups are determined, a candidate data node group can be randomly determined from the multiple candidate data groups as the target data node group to avoid the same data node group repeatedly storing different target data, thereby avoiding the hot spot problem of data nodes in the data node group.
[0078] Further, after determining the target data node group, multiple copies of the target data are randomly stored in different data nodes of the target data node group in a manner that one data node stores one copy.
[0079] Optionally, based on the remaining available space of each data node in the target data node group, multiple candidate data node sets supporting storage of replicas are determined, and multiple target data nodes matching the number of replicas are determined from the candidate data node sets, and each replica is stored in each target data node.
[0080] In an embodiment of the present application, the management node of the distributed database system determines the target available zone from multiple available zones of the distributed database system in response to a storage request for target data; determines the candidate data node grouping of the target data according to the remaining space rate of each data node grouping in the target available zone; determines the target data node grouping from each candidate data node grouping, and stores multiple copies of the target data in the target data node grouping. In this method, in the target data storage scenario, in response to a storage request for target data, the target available zone is first determined from multiple available zones, then the candidate data node grouping is determined from the target available zone, then the target data node grouping is determined from the candidate data node grouping, and finally the data node storing the copy of the target data is determined from the target data node grouping. In this way, a layer-by-layer routing method is adopted to gradually narrow the determination range of the data nodes storing the copy of the target data, so as to shorten the determination time of the data node, quickly store multiple copies of the target data, and thus improve the data storage efficiency of the distributed database system. Moreover, when determining the target availability zone, the target availability zone closest to the area where the storage request is triggered can be selected according to the principle of proximity to reduce network latency; when determining the target data node grouping, the candidate data node grouping is determined according to the remaining space rate of each data node grouping in the target availability zone to ensure the rationality of each candidate data node grouping. Furthermore, the method of selecting the target data node grouping from each candidate data node can not only ensure the rationality of the target data node grouping, but also improve the flexibility and diversity of the target data node grouping to a certain extent, and avoid data hot spots of data nodes. In addition, the distributed database system includes multiple availability zones, and the data transmission processes between the availability zones are isolated from each other to avoid failures in a single availability zone, such as hardware failures, network problems, etc., which may cause the entire distributed database system to be unavailable, thereby improving the high availability of the distributed database system.
[0081] Below, an achievable method for grouping candidate data nodes is described through an embodiment. Figure 4 As shown, according to the remaining space rate of each data node group in the target availability zone, the candidate data node group of the target data is determined, including:
[0082] S401, sorting the data node groups in descending order of remaining space rate.
[0083] According to the order of remaining space rate from large to small, the data node groups are sorted to obtain the data node group sequence. In the data node group sequence, the lower the remaining space rate, the less remaining space the data node group has, and the more likely it is that the copies of the target data stored in the data node group will be concentrated in one or a small number of data nodes, resulting in uneven data storage, or even inability to store all copies; the higher the remaining space rate, the larger the remaining space of the data node group, and the easier it is to achieve storage balance when storing the copies of the target data in the data node group.
[0084] S402: From the sorted data node grouping sequence, determine in sequence a plurality of candidate data node groups that match a preset grouping quantity.
[0085] The preset number of groups is an integer not less than 1, and the preset number of groups may be set based on an empirical value or may be a parameter carried in the storage request.
[0086] After obtaining the sorted data node grouping sequence, multiple candidate data node groups that match the preset grouping quantity are determined in order from high to low.
[0087] Considering that the distributed database system is a large-scale system, in the embodiment of the present application, each candidate data node group includes a sufficient number of data nodes and storage space. In other words, each candidate data node supports storing multiple copies of the target data.
[0088] In an embodiment of the present application, each data node group is sorted in descending order of remaining space rate, and then a plurality of candidate data node groups that match a preset number of groups are determined in sequence from the sorted data node group sequence, thereby further narrowing the determination range of subsequent target data node groups, thereby ensuring the rationality of the determined target data node groups and improving the flexibility of the target data node group determination method.
[0089] The target data node group includes multiple data nodes, and the number of data nodes is much larger than the number of copies of the target data. In this case, it is necessary to screen out a part of the target data nodes from the multiple data nodes in the target data node group again to store multiple copies of the target data.
[0090] In an exemplary embodiment, Figure 5 As shown, multiple data nodes in the target data node group are distributed in different computer rooms; Figure 5 The figure below is a diagram showing the distribution of data centers in a single availability zone.
[0091] In the context that multiple data nodes in the target data node group are distributed in different computer rooms, such as Figure 6As shown, storing multiple copies of target data in a target data node group includes the following steps:
[0092] S601, determining the number of nodes to be allocated to each computer room according to the number of copies of the target data and the number of computer rooms corresponding to the target data node groups.
[0093] According to the number of computer rooms, the number of copies of the target data is divided into multiple copies to obtain the same number of sub-copies as the number of computer rooms, and the number of each sub-copy is used as the number of nodes allocated to a computer room.
[0094] S602: When the number of available data nodes in each computer room is greater than the number of allocated nodes in each computer room, determine the data nodes in each computer room that match the number of allocated nodes as target data nodes.
[0095] Before determining the target number of data nodes in each computer room, it is necessary to first eliminate the unavailable nodes in each computer room and determine the number of available data nodes in each computer room.
[0096] For any computer room, remove downtime nodes, nodes with excessive load, and nodes with insufficient remaining available space from the computer room to obtain the number of available data nodes in the computer room. Insufficient remaining available space means that the actual remaining available space of the node minus the capacity of the data replica planned to be written to this node is less than the reserved minimum space.
[0097] Next, the number of available data nodes in each computer room is compared with the number of nodes allocated in each computer room. If the number of available data nodes in each computer room is greater than the number of nodes allocated in each computer room, it means that each computer room includes a sufficient number of data node storage copies. In this case, the data nodes in each computer room that match the number of nodes allocated are determined as target data nodes.
[0098] In an exemplary embodiment, if the number of available data nodes in any computer room is less than the number of nodes allocated in the computer room, the target data node group is removed from each candidate data node group, and a new target data node group is re-determined from the removed candidate data node groups.
[0099] If the number of available data nodes in any computer room is less than the number of nodes allocated to the computer room, it means that the currently available data nodes in the computer room do not support storing the storage copies of the data nodes pre-allocated for it, and the target data grouping cannot store all the data copies of the target data. In this case, it is necessary to redefine the new target data node grouping, and in order to prevent the new target data node grouping from being consistent with the initially determined target data grouping, the initially determined target data node grouping will be removed from each candidate data node grouping, and a new target data node grouping will be re-determined from the removed candidate data node grouping to ensure the validity of the new target data node.
[0100] In an embodiment of the present application, when the number of available data nodes in any computer room is less than the number of nodes allocated in the computer room, the target data node group is removed from each candidate data node group, and a new target data node group is re-determined from the removed candidate data node group to avoid repeated determination of the same target data node in the candidate data node group, thereby ensuring the validity of the new target data node. In addition, when determining the new target data node, the number of candidate data node groups is reduced, which can improve the efficiency of determining the new target data node to a certain extent.
[0101] S603, storing multiple copies of the target data in the target data nodes of each computer room respectively.
[0102] According to the storage method of one copy corresponding to one data node, multiple copies of the target data are stored in the target data nodes of each computer room respectively.
[0103] In the embodiment of the present application, considering the poor disaster tolerance of a single computer room, if an unexpected situation such as a power outage in the computer room causes all servers in the entire fault domain to crash, the fault domain will not be able to read and write data, affecting the service quality. Multiple computer rooms are equipped for an available area, and multiple data nodes in the target data node group are distributed in different computer rooms to improve the disaster tolerance of the system. At the same time, according to the number of copies of the target data and the number of computer rooms corresponding to the target data node group, the number of nodes allocated to each computer room is determined. When the number of available data nodes in each computer room is greater than the number of nodes allocated in each computer room, the data nodes in each computer room that match the number of nodes allocated are determined as target data nodes, and multiple copies of the target data are evenly stored in the target data nodes of each computer room. In this way, when a computer room fails, only some copies stored in the data nodes of the failed computer room fail, without affecting the reading of copy data from the target data nodes in other non-faulty computer rooms, so as to improve the high availability of the distributed database system.
[0104] In an exemplary embodiment, a possible implementation method of the aforementioned embodiment S601 "determining the number of nodes to be allocated to each computer room according to the number of copies of the target data and the number of computer rooms corresponding to the target data node groups" is described as follows: Figure 7 As shown, including:
[0105] S701, in accordance with a uniformly distributed storage method, find the quotient of the number of copies of the target data and the number of computer rooms corresponding to the target data node grouping.
[0106] In order to ensure that each copy is evenly distributed among multiple computer rooms, according to the storage method in which each computer room evenly stores multiple copies of the target data, the ratio between the number of copies of the target data and the number of computer rooms corresponding to the target data node grouping is calculated to obtain the quotient. The quotient operation in this embodiment is a rounding-down calculation.
[0107] S702: If there is no remainder in the result of the quotient, the result of the quotient is determined as the number of nodes allocated to each computer room.
[0108] S703, if there is a remainder in the result of the quotient, the integer value in the result is determined as the initial node allocation number of each computer room, and the initial node allocation number in the computer room matching the remainder is adjusted to obtain the node allocation number of each computer room.
[0109] For example, if the number of replicas is r and the number of computer rooms is k, calculate the result of (r / k). If r / k is divisible, that is, the result of the quotient (r / k) is a positive integer, then the number of nodes allocated to each computer room is determined to be (r / k).
[0110] For scenarios that cannot be divided evenly, r / k is rounded down, and the remainder is recorded as (r%k). The integer result is determined as the initial node allocation number of each computer room, and (r%k) computer rooms are randomly selected from the k computer rooms as the storage location of the remaining copies. The initial node allocation number of the randomly selected (r%k) computer rooms is added by 1 to obtain the adjusted node allocation number of the (r%k) computer rooms. In the embodiment of the present application, the node allocation number of the i-th computer room is recorded as num(i), where i=1, 2, ..., k.
[0111] Exemplarily, multiple data nodes of the target data node group are distributed in 5 computer rooms. If the number of copies is 10, the number of nodes allocated to each computer room is determined to be 2 (10 / 5); if the number of copies is 11, the number of nodes allocated to four computer rooms is determined to be 2 (10 / 5), and the number of nodes allocated to one computer room is determined to be 3 (10 / 5+1).
[0112] In an embodiment of the present application, in accordance with a uniformly distributed storage method, the quotient is calculated based on the number of copies of the target data and the number of computer rooms corresponding to the target data node grouping. When there is no remainder in the result of the quotient, the result of the quotient is directly determined as the number of node allocations in each computer room; when there is a remainder in the result of the quotient, the integer value in the result is determined as the initial node allocation number in each computer room, and the initial node allocation number in the computer room that matches the remainder is adjusted to distribute the data copies as evenly as possible in different computer rooms, to ensure the balance of data nodes, and to avoid service unavailability due to failure of a single computer room.
[0113] In an exemplary embodiment, a possible implementation method of the aforementioned embodiment S603 "storing multiple copies of the target data in the target data nodes of each computer room respectively" is described as follows: Figure 8 As shown, including:
[0114] S801, for any computer room, sort the data nodes according to the remaining available space of the data nodes in the computer room to obtain a data node sequence.
[0115] For any computer room, the data nodes in the computer room are sorted in descending order of the remaining available space of each data node in the computer room to obtain the data node sequence of the computer room.
[0116] S802: Determine candidate data nodes that match a preset number of nodes from the sorted data node sequence.
[0117] The preset number of nodes is an integer not less than the number of nodes allocated to a single computer room. After obtaining the sorted data node grouping sequence, multiple candidate data nodes matching the preset number of nodes are determined in order from high to low.
[0118] S803: Randomly determine a target data node that matches the node allocation quantity from each candidate data node.
[0119] Further, after determining the target data node group, multiple copies of the target data are randomly stored in different data nodes of the target data node group in a manner that one data node stores one copy.
[0120] S804, storing the replicas matching the number of nodes allocated to each target data node in the computer room.
[0121] In the manner of storing one replica in one data node, the replicas matching the number of nodes allocated are stored in each target data node in the computer room.
[0122] In an embodiment of the present application, for any computer room, each data node is sorted according to the remaining available space of each data node in the computer room to obtain a data node sequence, which provides a quantitative basis for determining the target data node. Then, from the sorted data node sequence, candidate data nodes that match the preset number of nodes are determined to narrow the determination range of the target data nodes; then, target data nodes that match the node allocation number are randomly determined from each candidate data node to ensure load balancing between the target data nodes and avoid hot spot problems.
[0123] In an exemplary embodiment, a data storage method is provided, such as Fig. 9 As shown, the following steps are included:
[0124] S901, in response to a storage request for target data, determining a target availability zone from multiple availability zones in a distributed database storage system according to a proximity principle.
[0125] S902: Determine a plurality of candidate data node groups that match a preset number of groups according to the remaining space ratio of each data node group in the target available zone.
[0126] In order to prevent the need to traverse all data nodes under all data node groups each time data routing is performed, in an embodiment of the present application, each data node group and the remaining space rate of each data node group are dynamically maintained. When a data node group writes data, deletes data, or all data nodes go down, the remaining space rate of the group to which the data node belongs is recalculated.
[0127] Based on the remaining space rate of each data node group, obtain the topM candidate data node groups with the highest remaining space rate. Among them, topM can be configured by the user, and the minimum value is 1, which means that the candidate data node group with the highest remaining space rate is selected to ensure data balance between different data node groups, and avoid the situation where a certain data node group may be frequently selected as a write target in scenarios with large data write volume and high concurrency, causing hot spot problems. The maximum value of topM is the total number of data node groups in the target availability zone, which means that the data balance problem between data node groups is not considered, and random selection is made among all data node groups.
[0128] S903: Randomly determine a target data node group from each candidate data node group.
[0129] A candidate data node group is randomly selected from each candidate data node group as the target data node group as the write location of the copy of the target data.
[0130] S904, remove unavailable nodes in the target data node group, and determine available data nodes in multiple computer rooms corresponding to the target data node group.
[0131] S905, determining the number of nodes to be allocated to each computer room according to the number of copies of the target data and the number of computer rooms corresponding to the target data node groupings.
[0132] S906: Determine whether the number of available data nodes in each computer room is greater than or equal to the number of nodes allocated in the corresponding computer room.
[0133] S907: If not, remove the target data node group from the candidate data node group and return to step S903.
[0134] S908: If yes, then determine a preset number of candidate data nodes from each computer room according to the remaining available space of the data nodes in each computer room.
[0135] For each computer room, sort the data nodes in the computer room in descending order of the remaining available space of the data nodes, and select the topN data nodes as candidate data nodes. The size of topN is configurable, and the minimum value is the number of nodes allocated to the computer room. The size of topN is configurable. If topN is the number of nodes allocated to the computer room, it means that several data nodes with the largest remaining available space are selected from this computer room, which can ensure data balance between nodes, but hot spots cannot be avoided in high-concurrency scenarios; the maximum value of topN is the number of all available data nodes in the computer room, which means that data balance between nodes is not considered, and random selection is made among all available data nodes.
[0136] S909: Randomly determine a data node with the same number of node allocations from the candidate data nodes in each computer room as a target data node.
[0137] S910, storing multiple copies of the target data in each target data node in each computer room respectively.
[0138] In the embodiment of the present application, a cross-AZ deployment method of a distributed database system is adopted, and data nodes are deployed in multiple AZs. Fault isolation between AZs can avoid the situation where the entire database system is unavailable due to a single AZ failure. At the same time, data nodes are deployed in various places to support users to obtain data access services from the nearest AZ and improve access speed. In addition, the data nodes in a single availability zone are further subdivided into multiple data node groups, thereby avoiding the data routing algorithm from traversing all data nodes in the entire AZ and improving the efficiency of determining data nodes. In addition, each AZ is equipped with multiple computer rooms, and multiple copies of the data are distributed in different computer rooms to avoid service unavailability due to a single computer room failure. In summary, the data storage solution implemented using the above-mentioned deployment method can, on the one hand, select the fault domain closest to the user based on the user location to reduce network latency and improve access speed. On the other hand, when selecting a target data node group within an AZ and selecting a target data node within a target data node group, compared to the prior art method of selecting the one with the largest remaining space or randomly selecting within the entire cluster, the data storage solution of the present application uses an adjustable parameter (preset number of groups / preset number of nodes) to first determine the candidate data node group / candidate data node, and then randomly select the target data node group / target data node from the candidate data node group / candidate data node, thereby achieving a compromise between data balance and load balance to a certain extent.
[0139] It should be understood that, although the various steps in the flowcharts involved in the above-mentioned embodiments are displayed in sequence according to the indication of the arrows, these steps are not necessarily executed in sequence according to the order indicated by the arrows. Unless there is a clear explanation in this article, the execution of these steps does not have a strict order restriction, and these steps can be executed in other orders. Moreover, at least a part of the steps in the flowcharts involved in the above-mentioned embodiments can include multiple steps or multiple stages, and these steps or stages are not necessarily executed at the same time, but can be executed at different times, and the execution order of these steps or stages is not necessarily to be carried out in sequence, but can be executed in turn or alternately with other steps or at least a part of the steps or stages in other steps.
[0140] Based on the same inventive concept, the embodiment of the present application also provides a data storage device for implementing the data storage method involved above. The implementation solution provided by the device to solve the problem is similar to the implementation solution recorded in the above method, so the specific limitations in one or more data storage device embodiments provided below can refer to the limitations on the data storage method above, and will not be repeated here.
[0141] In an exemplary embodiment, Fig.10 As shown, a data storage device is provided, including: a request response module 1001, a group evaluation module 1002 and a data storage module 1003, wherein:
[0142] The request response module 1001 is used to respond to a storage request for target data and determine a target availability zone from multiple availability zones of a distributed database system; each availability zone includes multiple data node groups;
[0143] A grouping evaluation module 1002 is used to determine candidate data node groups for target data according to the remaining space rate of each data node group in the target available zone;
[0144] The data storage module 1003 is used to determine the target data node group from each candidate data node group, and store multiple copies of the target data in the target data node group.
[0145] In an exemplary embodiment, the grouping evaluation module 1002 includes: a node grouping sorting unit and a node grouping determination unit, wherein:
[0146] A node grouping sorting unit is used to sort the data node groups in descending order of remaining space rate;
[0147] The node group determination unit is used to sequentially determine a plurality of candidate data node groups that match a preset grouping quantity from the sorted data node grouping sequence.
[0148] In an exemplary embodiment, multiple data nodes in the target data node group are distributed in different computer rooms; the data storage module 1003 includes: a node quantity determination unit, a target node determination unit and a data copy storage unit, wherein:
[0149] A node quantity determination unit, used to determine the number of nodes to be allocated to each computer room according to the number of copies of the target data and the number of computer rooms corresponding to the target data node grouping;
[0150] A target node determination unit, configured to determine, when the number of available data nodes in each computer room is greater than the number of allocated nodes in each computer room, data nodes in each computer room that match the number of allocated nodes as target data nodes;
[0151] The data copy storage unit is used to store multiple copies of the target data in the target data nodes of each computer room respectively.
[0152] In an exemplary embodiment, the node quantity determination unit includes: an allocation node operation subunit, a first allocation subunit and a second allocation subunit, wherein:
[0153] The node allocation operation subunit is used to calculate the quotient according to the number of copies of the target data and the number of computer rooms corresponding to the target data node grouping according to the uniformly distributed storage method;
[0154] A first allocation subunit is used to determine the result of the quotient as the number of nodes allocated to each computer room if there is no remainder in the result of the quotient;
[0155] The second allocation subunit is used to determine the integer value in the result as the initial node allocation quantity of each computer room if there is a remainder in the quotient, and adjust the initial node allocation quantity in the computer room matching the remainder to obtain the node allocation quantity of each computer room.
[0156] In an exemplary embodiment, the data replica storage unit includes: a node sorting subunit, a candidate node determination subunit, a target node determination subunit and a target node storage subunit, wherein:
[0157] The data node sorting subunit is used to sort the data nodes in any computer room according to the remaining available space of each data node in the computer room to obtain a data node sequence;
[0158] A candidate node determination subunit, used to determine candidate data nodes matching a preset number of nodes from the sorted data node sequence;
[0159] A target node determination subunit is used to randomly determine a target data node that matches the node allocation quantity from each candidate data node;
[0160] The target node storage subunit is used to store the replicas matching the node allocation quantity in each target data node of the computer room.
[0161] In one of the embodiments, the target node determination unit is further used to remove the target data node group from each candidate data node group if the number of available data nodes in any computer room is less than the number of nodes allocated in the computer room, and to re-determine a new target data node group from the removed candidate data node group.
[0162] Each module in the above data storage device can be implemented in whole or in part by software, hardware, or a combination thereof. Each module can be embedded in or independent of a processor in a computer device in the form of hardware, or can be stored in a memory in a computer device in the form of software, so that the processor can call and execute operations corresponding to each module.
[0163] In an exemplary embodiment, a computer device is provided. The computer device may be a server, and its internal structure diagram may be as shown in FIG. Fig.11 As shown. The computer device includes a processor, a memory, an input / output interface (Input / Output, referred to as I / O) and a communication interface. The processor, the memory and the input / output interface are connected through a system bus, and the communication interface is connected to the system bus through the input / output interface. The processor of the computer device is used to provide computing and control capabilities. The memory of the computer device includes a non-volatile storage medium and an internal memory. The non-volatile storage medium stores an operating system, a computer program and a database. The internal memory provides an environment for the operation of the operating system and the computer program in the non-volatile storage medium. The database of the computer device is used to store data for data routing and data storage. The input / output interface of the computer device is used to exchange information between the processor and an external device. The communication interface of the computer device is used to communicate with an external terminal through a network connection. When the computer program is executed by the processor, a data storage method is implemented.
[0164] Those skilled in the art will understand that Fig.11 The structure shown in the figure is only a block diagram of a part of the structure related to the solution of the present application, and does not constitute a limitation on the computer device to which the solution of the present application is applied. The specific computer device may include more or fewer components than those shown in the figure, or combine certain components, or have a different arrangement of components.
[0165] In an exemplary embodiment, a computer device is provided, including a memory and a processor, wherein a computer program is stored in the memory, and the processor implements the steps in the above-mentioned method embodiments when executing the computer program.
[0166] In an exemplary embodiment, a computer-readable storage medium is provided, on which a computer program is stored. When the computer program is executed by a processor, the steps in the above-mentioned method embodiments are implemented.
[0167] In an exemplary embodiment, a computer program product is provided, including a computer program, and when the computer program is executed by a processor, the steps in the above method embodiments are implemented.
[0168] It should be noted that the user information (including but not limited to user device information, user personal information, etc.) and data (including but not limited to data used for analysis, stored data, displayed data, etc.) involved in this application are all information and data authorized by the user or fully authorized by all parties, and the collection, use and processing of relevant data must comply with relevant regulations.
[0169] A person of ordinary skill in the art can understand that all or part of the processes in the above-mentioned embodiment method can be completed by instructing the relevant hardware through a computer program, and the computer program can be stored in a non-volatile computer-readable storage medium. When the computer program is executed, it can include the processes of the embodiments of the above-mentioned methods. Among them, any reference to the memory, database or other medium used in the embodiments provided in the present application can include at least one of non-volatile memory and volatile memory. Non-volatile memory can include read-only memory (ROM), magnetic tape, floppy disk, flash memory, optical memory, high-density embedded non-volatile memory, resistive random access memory (ReRAM), magnetic random access memory (MRAM), ferroelectric random access memory (FRAM), phase change memory (PCM), graphene memory, etc. Volatile memory can include random access memory (RAM) or external cache memory, etc. As an illustration and not limitation, RAM can be in various forms, such as static random access memory (SRAM) or dynamic random access memory (DRAM). The database involved in each embodiment provided in this application may include at least one of a relational database and a non-relational database. Non-relational databases may include distributed databases based on blockchains, etc., but are not limited to this. The processor involved in each embodiment provided in this application may be a general-purpose processor, a central processing unit, a graphics processor, a digital signal processor, a programmable logic device, a data processing logic device based on quantum computing, an artificial intelligence (AI) processor, etc., but are not limited to this.
[0170] The technical features of the above embodiments may be combined arbitrarily. To make the description concise, not all possible combinations of the technical features in the above embodiments are described. However, as long as there is no contradiction in the combination of these technical features, they should be considered to be within the scope of this application.
[0171] The above-described embodiments only express several implementation methods of the present application, and the descriptions thereof are relatively specific and detailed, but they cannot be understood as limiting the scope of the present application. It should be pointed out that, for a person of ordinary skill in the art, several variations and improvements can be made without departing from the concept of the present application, and these all belong to the protection scope of the present application. Therefore, the protection scope of the present application shall be subject to the attached claims.
Claims
1. A data storage method, characterized in that: Applied to a management node of a distributed database system, the method comprises: In response to a storage request for target data, an available zone closest to a request physical location corresponding to the storage request is determined as a target available zone from multiple available zones of the distributed database system; each of the available zones includes multiple data node groups; each of the available zones is equipped with multiple computer rooms; there is no data transmission between different available zones; the number of data nodes in each available zone is obtained according to the frequency planning of user requests in different regions; According to the remaining space rate of each data node group in the target available zone, multiple data node groups greater than a preset space threshold are determined as candidate data node groups for the target data; the remaining space rate of the data node group is the ratio between the total remaining space of the data node group and the total capacity of the data node group; the total remaining space of the data node group is the sum of the remaining available space of each data node in the data node group; the total capacity of the data node group is the sum of the initial capacity of each data node in the data node group; A target data node group is determined from each of the candidate data node groups, and multiple copies of the target data are stored in different data nodes of the target data node group; the multiple data nodes in the target data node group are distributed in different computer rooms.
2. The method according to claim 1, characterized in that The step of determining, according to the remaining space rate of each data node group in the target available zone, a plurality of data node groups having a space rate greater than a preset space threshold as candidate data node groups for the target data includes: Sorting the data node groups in descending order of remaining space rate; From the sorted data node grouping sequence, a plurality of candidate data node groups matching a preset grouping quantity are determined in sequence from a plurality of data node groups greater than a preset space threshold.
3. The method according to claim 1 or 2, characterized in that: The storing the multiple copies of the target data to the target data node group includes: Determine the number of nodes to be allocated to each computer room according to the number of copies of the target data and the number of computer rooms corresponding to the target data node grouping; In the case where the number of available data nodes in each of the computer rooms is greater than the number of nodes allocated in each of the computer rooms, determining the data nodes in each of the computer rooms that match the number of nodes allocated as target data nodes; Multiple copies of the target data are stored in target data nodes of each computer room respectively.
4. The method according to claim 3, characterized in that The determining the number of nodes to be allocated to each computer room according to the number of copies of the target data and the number of computer rooms corresponding to the target data node groupings includes: According to a uniformly distributed storage method, the quotient is calculated based on the number of copies of the target data and the number of computer rooms corresponding to the target data node grouping; If there is no remainder in the result of the quotient, the result of the quotient is determined as the number of nodes allocated to each of the computer rooms; If there is a remainder in the result of the quotient, the integer value in the result is determined as the initial node allocation number of each computer room, and the initial node allocation number in the computer room matching the remainder is adjusted to obtain the node allocation number of each computer room.
5. The method according to claim 3, characterized in that: The storing of the multiple copies of the target data in the target data nodes of each computer room respectively includes: For any computer room, sort the data nodes according to the remaining available space of each data node in the computer room to obtain a data node sequence; Determine candidate data nodes that match a preset number of nodes from the sorted data node sequence; Randomly determine a target data node that matches the node allocation quantity from each of the candidate data nodes; The replicas matching the node allocation quantity are stored in each target data node of the computer room.
6. The method according to claim 3, characterized in that The method further comprises: If the number of available data nodes in any computer room is less than the number of nodes allocated in the computer room, the target data node group is removed from each of the candidate data node groups, and a new target data node group is re-determined from the removed candidate data node groups.
7. A data storage device, characterized in that: The device comprises: A request response module is used to respond to a storage request for target data, and determine, from multiple available zones of a distributed database system, an available zone closest to a request physical location corresponding to the storage request as a target available zone; each of the available zones includes multiple data node groups; each of the available zones is equipped with multiple computer rooms; there is no data transmission between different available zones; the number of data nodes in each of the available zones is obtained according to the frequency planning of user requests in different regions; A grouping evaluation module is used to determine multiple data node groups greater than a preset space threshold as candidate data node groups for the target data according to the remaining space rate of each data node group in the target available zone; the remaining space rate of the data node group is the ratio between the total remaining space of the data node group and the total capacity of the data node group; the total remaining space of the data node group is the sum of the remaining available space of each data node in the data node group; the total capacity of the data node group is the sum of the initial capacity of each data node in the data node group; The data storage module is used to determine the target data node group from each of the candidate data node groups, and store multiple copies of the target data in different data nodes of the target data node group; the multiple data nodes in the target data node group are distributed in different computer rooms.
8. A computer device comprising a memory and a processor, wherein the memory stores a computer program, wherein: When the processor executes the computer program, the steps of the method according to any one of claims 1 to 6 are implemented.
9. A computer-readable storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, the steps of the method according to any one of claims 1 to 6 are implemented.
10. A computer program product, comprising a computer program, characterized in that When the computer program is executed by a processor, the steps of the method according to any one of claims 1 to 6 are implemented.
Citation Information
Patent Citations
Data storage method and device
CN107657027A
Data writing method, device and system and storage medium
CN116225344A
Distributed database system load balancing method and device
CN116991580A
Data processing method and device, computer equipment and computer readable storage medium
CN117008818A