CN108400999A - A kind of load-balancing method and device of data-base cluster mirror nodes - Google Patents
A kind of load-balancing method and device of data-base cluster mirror nodes Download PDFInfo
- Publication number
- CN108400999A CN108400999A CN201710067354.1A CN201710067354A CN108400999A CN 108400999 A CN108400999 A CN 108400999A CN 201710067354 A CN201710067354 A CN 201710067354A CN 108400999 A CN108400999 A CN 108400999A
- Authority
- CN
- China
- Prior art keywords
- cabinet
- current cabinet
- mirror
- current
- cabinets
- Prior art date
- Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
- Granted
Links
- 238000000034 method Methods 0.000 title claims abstract description 35
- 238000009826 distribution Methods 0.000 claims description 25
- 238000009827 uniform distribution Methods 0.000 claims description 15
- 230000006870 function Effects 0.000 claims description 10
- 238000010586 diagram Methods 0.000 description 12
- 238000003860 storage Methods 0.000 description 9
- 238000004891 communication Methods 0.000 description 5
- 238000004590 computer program Methods 0.000 description 4
- 238000013461 design Methods 0.000 description 4
- 238000012423 maintenance Methods 0.000 description 4
- 238000007405 data analysis Methods 0.000 description 2
- 230000000694 effects Effects 0.000 description 2
- 238000012986 modification Methods 0.000 description 2
- 230000004048 modification Effects 0.000 description 2
- 230000003287 optical effect Effects 0.000 description 2
- 230000008569 process Effects 0.000 description 2
- 238000012545 processing Methods 0.000 description 2
- 238000004458 analytical method Methods 0.000 description 1
- 230000005540 biological transmission Effects 0.000 description 1
- 230000007547 defect Effects 0.000 description 1
- 238000013467 fragmentation Methods 0.000 description 1
- 238000006062 fragmentation reaction Methods 0.000 description 1
- 230000000977 initiatory effect Effects 0.000 description 1
- 238000004519 manufacturing process Methods 0.000 description 1
- 230000007246 mechanism Effects 0.000 description 1
- 230000001360 synchronised effect Effects 0.000 description 1
Classifications
-
- H—ELECTRICITY
- H04—ELECTRIC COMMUNICATION TECHNIQUE
- H04L—TRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
- H04L67/00—Network arrangements or protocols for supporting network services or applications
- H04L67/01—Protocols
- H04L67/10—Protocols in which an application is distributed across nodes in the network
- H04L67/1001—Protocols in which an application is distributed across nodes in the network for accessing one among a plurality of replicated servers
-
- H—ELECTRICITY
- H04—ELECTRIC COMMUNICATION TECHNIQUE
- H04L—TRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
- H04L41/00—Arrangements for maintenance, administration or management of data switching networks, e.g. of packet switching networks
- H04L41/06—Management of faults, events, alarms or notifications
- H04L41/0654—Management of faults, events, alarms or notifications using network fault recovery
- H04L41/0659—Management of faults, events, alarms or notifications using network fault recovery by isolating or reconfiguring faulty entities
-
- H—ELECTRICITY
- H04—ELECTRIC COMMUNICATION TECHNIQUE
- H04L—TRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
- H04L67/00—Network arrangements or protocols for supporting network services or applications
- H04L67/01—Protocols
- H04L67/10—Protocols in which an application is distributed across nodes in the network
- H04L67/104—Peer-to-peer [P2P] networks
- H04L67/1044—Group management mechanisms
-
- H—ELECTRICITY
- H04—ELECTRIC COMMUNICATION TECHNIQUE
- H04L—TRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
- H04L67/00—Network arrangements or protocols for supporting network services or applications
- H04L67/01—Protocols
- H04L67/10—Protocols in which an application is distributed across nodes in the network
- H04L67/1095—Replication or mirroring of data, e.g. scheduling or transport for data synchronisation between network nodes
Landscapes
- Engineering & Computer Science (AREA)
- Computer Networks & Wireless Communication (AREA)
- Signal Processing (AREA)
- Physics & Mathematics (AREA)
- Computing Systems (AREA)
- Mathematical Physics (AREA)
- Theoretical Computer Science (AREA)
- Information Retrieval, Db Structures And Fs Structures Therefor (AREA)
Abstract
Description
技术领域technical field
本发明涉及数据库技术领域,尤其涉及一种数据库集群镜像节点的负载均衡方法及装置。The invention relates to the technical field of databases, in particular to a load balancing method and device for database cluster mirror nodes.
背景技术Background technique
Greenplum是一个关系型数据库集群,它实际上是由数个独立的数据库服务组合成的逻辑数据库。与Oracle RAC的share-disking(共享磁盘)架构不同,Greenplum采用Shared-Nothing(无共享)架构,整个集群由控制节点(Master Host)和多个数据节点(Segment Host)组成(这里可以理解为存放数据的多台机器),其中每一个数据节点上可以运行多个数据库。Greenplum is a relational database cluster, which is actually a logical database composed of several independent database services. Different from the share-disking (shared disk) architecture of Oracle RAC, Greenplum adopts the Shared-Nothing (shared nothing) architecture. The entire cluster consists of a control node (Master Host) and multiple data nodes (Segment Host) (here can be understood as storage Multiple machines for data), where multiple databases can run on each data node.
Greenplum数据库集群绝大部分使用在较为廉价的X86架构的PC服务器上,这样在降低使用成本的过程中不可避免的会带来硬件故障率的提高,为了较好的规避软硬件故障导致的数据库服务的中断,Greenplum还提供数据库层的Mirror(镜像)保护机制,也就是将每一个数据库节点的数据在另外的节点中同步镜像,即在主节点(Primary)正常工作时,集群的管理者将主节点的数据时刻同步到镜像节点(Mirror),当主节点所在的数据节点出现软硬件故障而失去服务能力,镜像节点立即接管主节点的所有服务,故单个节点的故障不影响到整个系统到使用。Most Greenplum database clusters are used on relatively cheap X86 architecture PC servers, which will inevitably lead to an increase in hardware failure rate in the process of reducing usage costs. In order to better avoid database service failures caused by software and hardware failures Greenplum also provides the Mirror (mirror) protection mechanism of the database layer, that is, the data of each database node is mirrored synchronously in another node, that is, when the primary node (Primary) is working normally, the cluster manager will master The data of the node is always synchronized to the mirror node (Mirror). When the data node where the master node is located has a software and hardware failure and loses service capabilities, the mirror node immediately takes over all services of the master node, so the failure of a single node does not affect the use of the entire system.
以拥有一百台服务器集群为例:机柜与服务器摆放的规划如图1所示,由于服务器数量比较多,Greenplum数据库集群(简称GP集群)中的数据库实例的数量也会比较多,以上环境有98个数据节点,其中每一个数据节点有4个主节点实例,即分别有392个主节点实例和镜像节点实例。因此,数据库集群镜像节点的分布也需要充分考虑服务器的物理位置。为了保证数据库集群的高可用性,在一个机柜出问题后,不影响GP的可用性,数据节点Primary实例与对应的Mirror实例也分机柜部署。并且Primary实例与对应的Mirror实例以两个机柜为一组,组成互为镜像关系。Take a cluster of one hundred servers as an example: the layout of cabinets and servers is shown in Figure 1. Due to the large number of servers, the number of database instances in the Greenplum Database cluster (referred to as GP cluster) will also be relatively large. The above environment There are 98 data nodes, and each data node has 4 master node instances, that is, there are 392 master node instances and mirror node instances respectively. Therefore, the distribution of the mirror nodes of the database cluster also needs to fully consider the physical location of the server. In order to ensure the high availability of the database cluster, the availability of the GP will not be affected if a cabinet fails, and the data node Primary instance and the corresponding Mirror instance are also deployed in separate cabinets. In addition, the Primary instance and the corresponding Mirror instance use two cabinets as a group to form a mirror relationship with each other.
每台服务器部署4个Primary实例和4个Mirror实例。Primary实例与Mirror实例分布在不同机柜的服务器上。如机柜1上所有服务器的Primary实例对应的Mirror实例均匀地分布在机柜2的所有服务器上,部署示意图如图2所示。同样,机柜2上所有服务器的Primary实例对应的Mirror实例均匀的分布在机柜1的所有服务器上。机柜1和2的部署示意图如图3所示。Each server deploys 4 Primary instances and 4 Mirror instances. Primary instances and mirror instances are distributed on servers in different cabinets. For example, the mirror instances corresponding to the primary instances of all servers in cabinet 1 are evenly distributed on all servers in cabinet 2, as shown in Figure 2. Similarly, the mirror instances corresponding to the primary instances of all servers in cabinet 2 are evenly distributed on all servers in cabinet 1. The schematic diagram of the deployment of cabinets 1 and 2 is shown in Figure 3.
如图4所示,如果机柜1的某台服务器出现故障宕机,其上的4个Primary实例会由机柜2的四台服务器分别接管。即使机柜1发生整体的故障,其上的所有Primary实例都可以由机柜2的服务器接管。但是当一个机柜整体出现故障后,如机柜交换机故障,镜像机柜将要承受原设计两倍的网络压力,可能出现服务器崩溃。另外,需要人工对所有镜像节点进行人为配置,效率较低。在部署Greenplum集群的过程中,特别是大型集群,由于机器数量较多,并且存放在不同的机架之间,不同机架之间网络环境各异,因此如何更加有效设计镜像节点的分布保证在出现故障时能够让整个集群仍然处于均衡状态,成为DBA(数据库管理者)所面对的难题。As shown in Figure 4, if a server in cabinet 1 fails and goes down, the four primary instances on it will be taken over by the four servers in cabinet 2 respectively. Even if the overall failure of cabinet 1 occurs, all the primary instances on it can be taken over by the server in cabinet 2. However, when a cabinet as a whole fails, such as a cabinet switch failure, the mirrored cabinet will bear twice the network pressure of the original design, and the server may crash. In addition, all mirror nodes need to be manually configured, which is inefficient. In the process of deploying Greenplum clusters, especially large-scale clusters, due to the large number of machines and storage in different racks, the network environment between different racks is different, so how to more effectively design the distribution of mirror nodes to ensure that in Keeping the entire cluster in a balanced state when a failure occurs has become a difficult problem for the DBA (database administrator).
发明内容Contents of the invention
本发明所要解决的技术问题是提供一种数据库集群镜像节点的负载均衡方法,从而解决现有技术当一个机柜整体出现故障后,镜像机柜将要承受原设计两倍的网络压力的缺陷。The technical problem to be solved by the present invention is to provide a load balancing method for database cluster mirror nodes, so as to solve the defect in the prior art that when a whole cabinet fails, the mirror cabinet will bear twice the network pressure of the original design.
为此目的,本发明提出了一种数据库集群镜像节点的负载均衡方法,包括:For this purpose, the present invention proposes a kind of load balancing method of database cluster mirror node, comprising:
获取数据库集群的配置参数;其中,所述配置参数包括机柜数量、每一个机柜的服务器数量以及每一个服务器的主节点实例数量;Obtain configuration parameters of the database cluster; wherein, the configuration parameters include the number of cabinets, the number of servers in each cabinet, and the number of master node instances of each server;
针对所述数据库集群中的每一个机柜执行以下操作:根据所述配置参数,将当前机柜的所有主节点实例对应的镜像节点实例均匀分配到除当前机柜以外的所有其他机柜中,以实现数据库集群镜像节点的负载均衡。Perform the following operations for each cabinet in the database cluster: according to the configuration parameters, evenly distribute the mirror node instances corresponding to all the master node instances of the current cabinet to all other cabinets except the current cabinet, so as to realize the database cluster Load balancing of mirror nodes.
可选的,所述针对数据库集群中的每一个机柜执行以下操作:根据配置参数,将当前机柜的所有主节点实例对应的镜像节点实例均匀分配到除当前机柜以外的所有其他机柜中,包括:Optionally, the following operation is performed for each cabinet in the database cluster: according to configuration parameters, evenly distribute mirror node instances corresponding to all master node instances of the current cabinet to all other cabinets except the current cabinet, including:
针对每一个机柜执行以下操作:根据当前机柜的主节点实例数量以及所述机柜数量,将当前机柜的主节点实例对应的镜像节点实例均匀分配到除当前机柜以外的所有其他机柜中;Perform the following operations for each cabinet: according to the number of master node instances in the current cabinet and the number of cabinets, evenly distribute the mirror node instances corresponding to the master node instance of the current cabinet to all other cabinets except the current cabinet;
针对每一个机柜执行以下操作:根据当前机柜分配的镜像节点实例的数量以及当前机柜的服务器数量,将当前机柜分配的镜像节点实例均匀分配到当前机柜不同的服务器中。Perform the following operations for each cabinet: according to the number of mirror node instances allocated to the current cabinet and the number of servers in the current cabinet, evenly distribute the mirror node instances allocated to the current cabinet to different servers in the current cabinet.
可选的,所述针对每一个机柜执行以下操作:根据当前机柜的主节点实例数量以及所述机柜数量,将当前机柜的主节点实例对应的镜像节点实例均匀分配到除当前机柜以外的所有其他机柜中,包括:Optionally, the following operation is performed for each cabinet: according to the number of master node instances of the current cabinet and the number of cabinets, evenly distribute the mirror node instances corresponding to the master node instance of the current cabinet to all other cabinets except the current cabinet In the cabinet, including:
对所有机柜的主节点实例对应的镜像节点实例进行编号;Number the mirror node instances corresponding to the master node instances of all cabinets;
针对每一个机柜执行以下操作:根据当前机柜的主节点实例对应的镜像节点实例的编号以及所述机柜数量,将当前机柜的所有主节点实例对应的镜像节点实例的编号均匀分配到除当前机柜以外的其他机柜中,最终得到每个机柜分配的镜像节点实例的编号数据。For each cabinet, perform the following operations: according to the number of the mirror node instance corresponding to the master node instance of the current cabinet and the number of the cabinets, evenly distribute the numbers of the mirror node instances corresponding to all the master node instances of the current cabinet to the other cabinets except the current cabinet In other cabinets, the number data of the mirror node instance assigned to each cabinet is finally obtained.
可选的,所述根据当前机柜的主节点实例对应的镜像节点实例的编号以及所述机柜数量,将当前机柜的所有主节点实例对应的镜像节点实例的编号均匀分配到除当前机柜以外的其他机柜中,具体采用以下哈希函数进行均匀分配:Optionally, according to the numbers of the mirror node instances corresponding to the master node instances of the current cabinet and the number of cabinets, the numbers of the mirror node instances corresponding to all the master node instances of the current cabinet are evenly distributed to other cabinets except the current cabinet. In the cabinet, the following hash function is used for uniform distribution:
HashFunc(X)=M%(N-1)HashFunc(X)=M%(N-1)
其中,X为哈希地址,代表编号M所分配到的机柜;M为当前机柜的所有主节点实例对应的镜像节点实例的编号,N为机柜数量。Among them, X is the hash address, which represents the cabinet number M is assigned to; M is the number of the mirror node instance corresponding to all the master node instances of the current cabinet, and N is the number of cabinets.
可选的,所述针对每一个机柜执行以下操作:根据当前机柜分配的镜像节点实例的数量以及当前机柜的服务器数量,将当前机柜分配的镜像节点实例均匀分配到当前机柜不同的服务器中,包括:Optionally, the following operations are performed for each cabinet: according to the number of mirror node instances allocated to the current cabinet and the number of servers in the current cabinet, evenly distribute the mirror node instances allocated to the current cabinet to different servers in the current cabinet, including :
针对每一个机柜执行以下操作:根据当前机柜分配的镜像节点实例的编号数据以及当前机柜的服务器数量,将当前机柜分配的镜像节点实例的编号均匀分配到当前机柜不同的服务器中,最终确定当前机柜的每个服务器分配的镜像节点实例的编号数据。For each cabinet, perform the following operations: according to the number data of the mirror node instance assigned to the current cabinet and the number of servers in the current cabinet, evenly distribute the number of the mirror node instance assigned to the current cabinet to different servers in the current cabinet, and finally determine the current cabinet The number data of the mirror node instance assigned by each server.
可选的,所述根据当前机柜分配的镜像节点实例的编号数据以及当前机柜的服务器数量,将当前机柜分配的镜像节点实例的编号均匀分配到当前机柜不同的服务器中,具体采用以下哈希函数进行均匀分配:Optionally, according to the number data of the mirror node instances allocated to the current cabinet and the number of servers in the current cabinet, the numbers of the mirror node instances allocated to the current cabinet are evenly distributed to different servers in the current cabinet, specifically using the following hash function Make an even distribution:
HashFunc(Y)=K%IHashFunc(Y)=K%I
其中,Y为哈希地址,代表编号K所分配到的服务器;K为当前机柜分配的镜像节点实例的编号,Y为当前机柜的服务器数量。Among them, Y is the hash address, which represents the server number K is allocated to; K is the number of the mirror node instance allocated to the current cabinet, and Y is the number of servers in the current cabinet.
另一方面,本发明实施例还提供了一种数据库集群镜像节点的负载均衡装置,包括:On the other hand, the embodiment of the present invention also provides a load balancing device for database cluster mirror nodes, including:
参数获取模块,用于获取数据库集群的配置参数;其中,所述配置参数包括机柜数量、每个机柜的服务器数量以及每个服务器的主节点实例数量;A parameter acquisition module, configured to acquire configuration parameters of the database cluster; wherein the configuration parameters include the number of cabinets, the number of servers in each cabinet, and the number of master node instances of each server;
均匀分配模块,用于针对数据库集群中的每一个机柜执行以下操作:根据所述配置参数,将当前机柜的所有主节点实例对应的镜像节点实例均匀分配到除当前机柜以外的所有其他机柜中,以实现数据库集群镜像节点的负载均衡。The uniform distribution module is used to perform the following operations for each cabinet in the database cluster: according to the configuration parameters, evenly distribute the mirror node instances corresponding to all the master node instances of the current cabinet to all other cabinets except the current cabinet, To achieve load balancing of database cluster mirror nodes.
可选的,所述均匀分配模块包括:Optionally, the uniform distribution module includes:
机柜分配单元,用于针对每一个机柜执行以下操作:根据当前机柜的主节点实例数量以及所述机柜数量,将当前机柜的主节点实例对应的镜像节点实例均匀分配到除当前机柜以外的所有其他机柜中;The cabinet allocation unit is configured to perform the following operations for each cabinet: according to the number of master node instances of the current cabinet and the number of cabinets, evenly distribute the mirror node instances corresponding to the master node instance of the current cabinet to all other cabinets except the current cabinet in the cabinet;
服务器分配单元,用于针对每一个机柜执行以下操作:根据当前机柜分配的镜像节点实例的数量以及当前机柜的服务器数量,将当前机柜分配的镜像节点实例均匀分配到当前机柜不同的服务器中。The server allocation unit is configured to perform the following operations for each cabinet: according to the number of mirror node instances allocated to the current cabinet and the number of servers in the current cabinet, evenly distribute the mirror node instances allocated to the current cabinet to different servers in the current cabinet.
可选的,所述机柜分配单元包括:Optionally, the cabinet distribution unit includes:
编号子单元,用于对所有机柜的主节点实例对应的镜像节点实例进行编号;The numbering subunit is used to number the mirror node instances corresponding to the master node instances of all cabinets;
机柜编号分配子单元,用于针对每一个机柜执行以下操作:根据当前机柜的主节点实例对应的镜像节点实例的编号以及所述机柜数量,将当前机柜的所有主节点实例对应的镜像节点实例的编号均匀分配到除当前机柜以外的其他机柜中,最终得到每个机柜分配的镜像节点实例的编号数据;The cabinet number allocation subunit is used to perform the following operations for each cabinet: according to the number of the mirror node instance corresponding to the master node instance of the current cabinet and the number of cabinets, assign the mirror node instances corresponding to all master node instances of the current cabinet The number is evenly distributed to other cabinets except the current cabinet, and finally the number data of the mirror node instance assigned to each cabinet is obtained;
可选的,所述服务器分配单元具体用于:Optionally, the server allocation unit is specifically used for:
针对每一个机柜执行以下操作:根据当前机柜分配的镜像节点实例的编号数据以及当前机柜的服务器数量,将当前机柜分配的镜像节点实例的编号均匀分配到当前机柜不同的服务器中,最终确定当前机柜的每个服务器分配的镜像节点实例的编号数据。For each cabinet, perform the following operations: according to the number data of the mirror node instance assigned to the current cabinet and the number of servers in the current cabinet, evenly distribute the number of the mirror node instance assigned to the current cabinet to different servers in the current cabinet, and finally determine the current cabinet The number data of the mirror node instance assigned by each server.
本发明实施例提供的数据库集群镜像节点的负载均衡方法及装置,通过根据数据库集群的配置参数,针对每一个机柜将当前机柜的所有主节点实例对应的镜像节点实例均匀分配到除当前机柜以外的所有其他机柜中,从而将当前机柜的主节点实例对应的镜像节点实例分散在其他不同的机柜中,即使在当前机柜出现故障的情况下,网络压力也可以分散在不同的机柜中,不会单一集中在镜像机柜中,在当前机柜出现故障时,也能够让整个集群处于负载均衡的状态;另外,镜像节点实例的分配不依赖于维护人员的经验,根据配置参数进行镜像节点实例的合理分布,不会出现人为错误等情况,保证了镜像节点实例分布合理化处理,避免了问题发生。The load balancing method and device for database cluster mirror nodes provided by the embodiments of the present invention evenly distribute the mirror node instances corresponding to all the master node instances of the current cabinet to the cabinets other than the current cabinet according to the configuration parameters of the database cluster. In all other cabinets, the mirror node instances corresponding to the primary node instance of the current cabinet are scattered in other different cabinets. Even if the current cabinet fails, the network pressure can be distributed in different cabinets, and will not be single Centralized in the mirror cabinet, when the current cabinet fails, the entire cluster can also be in a load-balanced state; in addition, the allocation of mirror node instances does not depend on the experience of maintenance personnel, and the reasonable distribution of mirror node instances is carried out according to configuration parameters. There will be no human error, etc., which ensures the rationalization of the distribution of mirror node instances and avoids problems.
附图说明Description of drawings
通过参考附图会更加清楚的理解本发明的特征和优点,附图是示意性的而不应理解为对本发明进行任何限制,在附图中:The features and advantages of the present invention will be more clearly understood by referring to the accompanying drawings, which are schematic and should not be construed as limiting the invention in any way. In the accompanying drawings:
图1为现有机柜和服务器摆放的示意图;FIG. 1 is a schematic diagram of placement of existing cabinets and servers;
图2为现有技术机柜1的主节点实例对应的镜像节点实例分布在机柜2中的示意图;FIG. 2 is a schematic diagram showing that the mirror node instances corresponding to the master node instance of the cabinet 1 are distributed in the cabinet 2 in the prior art;
图3为现有技术机柜2的主节点实例对应的镜像节点实例分布在机柜1中的示意图;FIG. 3 is a schematic diagram of the distribution of mirror node instances corresponding to the master node instance of the prior art cabinet 2 in the cabinet 1;
图4为现有技术机柜1的某台服务器发生故障后机柜2接管的原理示意图;FIG. 4 is a schematic diagram of the principle of taking over by the cabinet 2 after a certain server in the cabinet 1 fails in the prior art;
图5为本发明实施例提供的一种数据库集群镜像节点的负载均衡方法的流程示意图;5 is a schematic flow diagram of a load balancing method for a database cluster mirror node provided by an embodiment of the present invention;
图6为本发明实施例提供的一种数据库集群镜像节点的负载均衡装置的架构示意图;FIG. 6 is a schematic structural diagram of a load balancing device for a mirror node of a database cluster provided by an embodiment of the present invention;
图7为本发明另一实施例提供的一种数据库集群镜像节点的负载均衡方法的流程示意图FIG. 7 is a schematic flowchart of a load balancing method for database cluster mirror nodes provided by another embodiment of the present invention
图8为本发明实施例提供的三个机柜的镜像节点实例的编号示意图;FIG. 8 is a schematic numbering diagram of mirroring node instances of three cabinets provided by an embodiment of the present invention;
图9为本发明实施例基于机柜进行镜像节点实例均匀分配后的结果示意图;FIG. 9 is a schematic diagram of the results of uniform distribution of mirror node instances based on cabinets according to an embodiment of the present invention;
图10为本发明实施例基于服务器进行镜像节点实例均匀分配后的结果示意图;FIG. 10 is a schematic diagram of the results of uniform distribution of mirror node instances based on the server according to the embodiment of the present invention;
图11为本发明实施例提供的一种数据库集群镜像节点的负载均衡装置的结构示意图;11 is a schematic structural diagram of a load balancing device for a mirror node of a database cluster provided by an embodiment of the present invention;
图12为本发明实施例提供的电子设备的结构示意图。FIG. 12 is a schematic structural diagram of an electronic device provided by an embodiment of the present invention.
具体实施方式Detailed ways
下面将结合附图对本发明的实施例进行详细描述。Embodiments of the present invention will be described in detail below with reference to the accompanying drawings.
如图5所示,本发明实施例提供了一种数据库集群镜像节点的负载均衡方法,该方法包括以下步骤:As shown in Figure 5, the embodiment of the present invention provides a load balancing method for database cluster mirror nodes, the method includes the following steps:
S1:获取数据库集群的配置参数;其中,所述配置参数包括机柜数量、每个机柜的服务器数量以及每个服务器的主节点实例数量;S1: Obtain configuration parameters of the database cluster; wherein, the configuration parameters include the number of cabinets, the number of servers in each cabinet, and the number of master node instances for each server;
本发明实施例提供的数据库集群镜像节点的负载均衡方法可以以数据库集群镜像节点的负载均衡装置为执行主体。如图6所示,该装置可以分为三层,任务调度层、模型层和分析层。任务调度层主要负责任务的发起,并对输入的配置参数进行判断处理,即判断机柜数量、服务器数量等是否在合理的范围内,如果不合理终止任务进行报错。模型层主要负责将配置参数进行数字化处理,将生产环节中的机器、机柜、实例转化为可以量化处理的数字编号。当数字化处理完成后,数据分析层负责根据配置参数包括的机柜数,将镜像节点实例均匀分配到各机柜。在机柜内部,重新对分配到的镜像节点实例均匀分配到各服务器。The load balancing method of the mirror node of the database cluster provided by the embodiment of the present invention may take the load balancing device of the mirror node of the database cluster as the execution subject. As shown in Figure 6, the device can be divided into three layers, task scheduling layer, model layer and analysis layer. The task scheduling layer is mainly responsible for initiating tasks, and judging and processing the input configuration parameters, that is, judging whether the number of cabinets and servers are within a reasonable range, and if unreasonable, terminate the task and report an error. The model layer is mainly responsible for digitizing configuration parameters, converting machines, cabinets, and instances in the production process into digital numbers that can be quantified. After the digital processing is completed, the data analysis layer is responsible for evenly distributing mirror node instances to each cabinet according to the number of cabinets included in the configuration parameters. Inside the cabinet, re-assign mirror node instances evenly to each server.
S2:针对数据库集群中的每一个机柜执行以下操作:根据所述配置参数,将当前机柜的所有主节点实例对应的镜像节点实例均匀分配到除当前机柜以外的所有其他机柜中,以实现数据库集群镜像节点的负载均衡。S2: Perform the following operations for each cabinet in the database cluster: according to the configuration parameters, evenly distribute the mirror node instances corresponding to all the master node instances of the current cabinet to all other cabinets except the current cabinet, so as to realize the database cluster Load balancing of mirror nodes.
需要说明的是,现有技术中当机柜1整体发生故障时,其上的所有主节点实例都由机柜2(镜像机柜)的服务器接管,因此,机柜2将要承受原设计两倍的网络压力,可能导致机柜2中服务器崩溃。本发明实施例根据数据库管理设计的机柜数量、每个机柜的服务器数量以及每个服务器的主节点实例数量,将当前机柜的所有主节点实例对应的镜像节点实例均匀分配到除当前机柜以外的所有其他机柜中,从而在机柜1整体发生故障时,网络压力不会集中在机柜2中,而是分散到了除机柜1以外的其他所有机柜中。即使机柜1整体发生故障,其他无故障的机柜也不会出现网络压力剧增的现象,保证了在出现故障时整个数据库集群仍然处于负载均衡状态。举例来说,当机柜数量为3个时,由于机柜1的主节点实例对应的镜像节点实例均匀分配到机柜2和机柜3中,如果机柜1发生故障,那么由机柜2和机柜3的服务器进行接管,网络压力不再仅仅集中在机柜2中,从而实现了整个数据库集群镜像节点的负载均衡。It should be noted that in the prior art, when the whole cabinet 1 fails, all the master node instances on it will be taken over by the servers in cabinet 2 (mirror cabinet). Therefore, cabinet 2 will bear twice the network pressure of the original design, May cause the server in rack 2 to crash. In the embodiment of the present invention, according to the number of cabinets designed for database management, the number of servers in each cabinet, and the number of master node instances in each server, the mirror node instances corresponding to all master node instances in the current cabinet are evenly distributed to all cabinets except the current cabinet. In other cabinets, so that when the whole cabinet 1 fails, the network pressure will not be concentrated in the cabinet 2, but distributed to all other cabinets except the cabinet 1. Even if cabinet 1 fails as a whole, other non-faulty cabinets will not experience a sharp increase in network pressure, ensuring that the entire database cluster is still in a load-balanced state when a fault occurs. For example, when the number of cabinets is 3, since the mirror node instances corresponding to the primary node instance of cabinet 1 are evenly distributed to cabinet 2 and cabinet 3, if cabinet 1 fails, the servers in cabinet 2 and cabinet 3 will Taking over, the network pressure is no longer concentrated in the cabinet 2, thus realizing the load balancing of the mirror nodes of the entire database cluster.
本发明实施例提供的数据库集群镜像节点的负载均衡方法,通过根据数据库集群的配置参数,将当前机柜的所有主节点实例对应的镜像节点实例均匀分配到除当前机柜以外的所有其他机柜中,从而将当前机柜的主节点实例对应的镜像节点实例分散在其他不同的机柜中,即使在当前机柜出现故障的情况下,网络压力也可以分散在不同的机柜中,不会单一集中在镜像机柜中,在当前机柜出现故障时,也能够让整个集群处于负载均衡的状态;另外,镜像节点实例的分配不依赖于维护人员的经验,根据配置参数进行镜像节点实例的合理分布,不会出现人为错误等情况,保证了镜像节点实例分布合理化处理,避免了问题发生。The load balancing method of the mirror node of the database cluster provided by the embodiment of the present invention evenly distributes the mirror node instances corresponding to all the master node instances of the current cabinet to all other cabinets except the current cabinet according to the configuration parameters of the database cluster, thereby Distribute the mirror node instances corresponding to the master node instance of the current cabinet in other different cabinets. Even if the current cabinet fails, the network pressure can be distributed in different cabinets, and will not be concentrated in the mirror cabinet. When the current cabinet fails, the entire cluster can also be in a load-balanced state; in addition, the allocation of mirror node instances does not depend on the experience of maintenance personnel, and the reasonable distribution of mirror node instances is carried out according to configuration parameters, without human errors, etc. This ensures the rational distribution of mirror node instances and avoids problems.
在上述实施例的基础上,步骤S2具体包括:On the basis of the foregoing embodiments, step S2 specifically includes:
S201:针对每一个机柜执行以下操作:根据当前机柜的主节点实例数量以及所述机柜数量,将当前机柜的主节点实例对应的镜像节点实例均匀分配到除当前机柜以外的所有其他机柜中;S201: Perform the following operation for each cabinet: according to the number of master node instances of the current cabinet and the number of cabinets, evenly distribute the mirror node instances corresponding to the master node instance of the current cabinet to all other cabinets except the current cabinet;
S202:针对每一个机柜执行以下操作:根据当前机柜分配的镜像节点实例的数量以及当前机柜的服务器数量,将当前机柜分配的镜像节点实例均匀分配到当前机柜不同的服务器中。S202: Perform the following operation for each cabinet: according to the number of mirror node instances allocated to the current cabinet and the number of servers in the current cabinet, evenly distribute the mirror node instances allocated to the current cabinet to different servers in the current cabinet.
具体的,参照图7所示,数据库管理员定义任务,并输入配置参数(机柜数量、服务器数量、以及每台服务器设计的实例数量)。任务调配层进行任务调配,并对输入的配置参数的合理性进行判断。如何不合理就终止任务并进行报错。如果合理,就由模型层将输入的配置参数进行数字化处理,即可以将机柜、服务器和实例转化为可以量化处理的数字编号,并将数字编号导入数据库。之后,数据分析层可以根据生成的数字编号,循环执行分配操作。首先可以基于机柜进行均匀分配,依次针对每一个机柜,将当前机柜对应的镜像节点实例均匀分配到其他的机柜中。根据需要可以生成所有像节点实例在各个机柜的分布列表。之后依次针对每一个机柜,将当前机柜分配的镜像节点实例均匀分配到当前机柜内的不同服务器中,最终完成所有像节点实例的均匀分布,根据需要可以生成所有像节点实例在各个机柜和各个服务器对应的分布列表,即使在某个机柜整体出现故障时,也能够实现负载均衡。Specifically, as shown in FIG. 7 , the database administrator defines tasks and inputs configuration parameters (the number of cabinets, the number of servers, and the number of instances designed for each server). The task allocation layer performs task allocation and judges the rationality of the input configuration parameters. How to terminate the task unreasonably and report an error. If it is reasonable, the model layer will digitize the input configuration parameters, that is, the cabinets, servers, and instances can be converted into digital numbers that can be quantified, and the digital numbers can be imported into the database. Afterwards, the data analysis layer can cycle through the assignment operations based on the generated numbers. First, you can evenly distribute based on the cabinet, and for each cabinet in turn, evenly distribute the mirror node instances corresponding to the current cabinet to other cabinets. A distribution list of all image node instances in each cabinet can be generated as needed. Then, for each cabinet in turn, evenly distribute the mirror node instances assigned by the current cabinet to different servers in the current cabinet, and finally complete the uniform distribution of all image node instances, and generate all image node instances in each cabinet and each server as needed The corresponding distribution list can achieve load balancing even when a certain cabinet fails as a whole.
在上述实施例的基础上,步骤S201具体包括:On the basis of the above embodiments, step S201 specifically includes:
S201-1:对所有机柜的主节点实例对应的镜像节点实例进行编号;S201-1: Number the mirror node instances corresponding to the master node instances of all cabinets;
S201-2:针对每一个机柜执行以下操作:根据当前机柜的主节点实例对应的镜像节点实例的编号以及所述机柜数量,将当前机柜的所有主节点实例对应的镜像节点实例的编号均匀分配到除当前机柜以外的其他机柜中,最终得到每个机柜分配的镜像节点实例的编号数据。S201-2: Perform the following operation for each cabinet: according to the number of the mirror node instance corresponding to the master node instance of the current cabinet and the number of cabinets, evenly distribute the numbers of the mirror node instances corresponding to all the master node instances of the current cabinet to In other cabinets except the current cabinet, the number data of the mirror node instance assigned to each cabinet is finally obtained.
举例来说,假设机柜1有9台服务器,一台服务器有4个主节点实例,其对应的镜像节点实例可以编号为001、002、003、004,机柜1则拥有001、002……036的编号,以此类推。根据生成的数字编号,循环执行分配,将本机柜对应的镜像节点实例均匀分配到不在本机柜的所有其他机柜中。由此,每个机柜都有了均匀分配到本机柜的镜像节点实例的数字编号。对本机柜的编号可以进行重新排序编号处理,生成对应的编号列表。For example, suppose there are 9 servers in cabinet 1, and one server has 4 master node instances, the corresponding mirror node instances can be numbered as 001, 002, 003, 004, and cabinet 1 has 001, 002...036 number, and so on. According to the generated number, the distribution is performed cyclically, and the mirror node instances corresponding to this cabinet are evenly distributed to all other cabinets that are not in this cabinet. As a result, each cabinet has a number that is evenly distributed to the mirror node instances in the cabinet. The numbers of the cabinets can be reordered to generate a corresponding list of numbers.
以三台机柜、每台机柜三台服务器为例,根据获取的配置参数,依次将所有机柜的主节点实例对应的镜像节点实例进行编号,如图8所示,主节点实例编号为001、002、003……036,对应的镜像节点实例编号为001、002、003……036。根据机柜数量,可以将机柜1的所有镜像节点实例的编号分布到机柜2和机柜3上。即将机柜1对应的12个镜像节点实例的编号(001-012)平均分布到机柜2和机柜3上。依次类推,将机柜2对应的镜像节点实例的编号(013-024)平均分布到机柜1和机柜3上,将机柜3对应的镜像节点实例的编号(025-036)平均分布到机柜1和机柜2上。Taking three cabinets and three servers in each cabinet as an example, according to the obtained configuration parameters, number the mirror node instances corresponding to the master node instances of all cabinets in sequence, as shown in Figure 8, the master node instance numbers are 001 and 002 , 003...036, and the corresponding mirror node instance numbers are 001, 002, 003...036. According to the number of cabinets, you can distribute the IDs of all mirror node instances in cabinet 1 to cabinets 2 and 3. That is, the numbers (001-012) of the 12 mirror node instances corresponding to cabinet 1 are evenly distributed to cabinet 2 and cabinet 3. By analogy, evenly distribute the number (013-024) of the mirror node instance corresponding to cabinet 2 to cabinet 1 and cabinet 3, and evenly distribute the number (025-036) of the mirror node instance corresponding to cabinet 3 to cabinet 1 and cabinet 2 on.
可选的,步骤S201-2具体可以采用以下哈希(HASH)函数实现均匀分配:Optionally, in step S201-2, the following hash (HASH) function may be used to achieve uniform distribution:
HashFunc(X)=M%(N-1)HashFunc(X)=M%(N-1)
其中,X为哈希地址,代表编号M所分配到的机柜;M为当前机柜的所有主节点实例对应的镜像节点实例的编号,N为机柜数量。Among them, X is the hash address, which represents the cabinet number M is assigned to; M is the number of the mirror node instance corresponding to all the master node instances of the current cabinet, and N is the number of cabinets.
具体的,采用Hash函数进行均匀分配,主键M是镜像节点实例对应的编号,N为机柜数量,以主键作为分片属性。取关键字被某个不大于哈希表表长N的数除后所得余数为哈希地址。例如:此处机柜数量N=3,M如为001则哈希地址为1,HashFunc(1)=001%(3-1)。以机柜1的三台服务器为例,镜像节点实例编号为(001 002 003 004)(005 006 007 008)(009010 011 012),当机柜1出现宕掉的情况下,机柜2与机柜3分别编号1,0,实例001通过Hash函数得到哈希地址1,这样实例001被分配到编号1(机柜2)上。依次类推,完成机柜1镜像节点实例的均匀分配后,循环执行直到每个机柜的镜像节点实例在其他所有机柜实现均匀分配,结果如图9所示。从图9可知,机柜1的主节点实例对应的镜像节点实例均匀分配到其他机柜(机柜2、机柜3)中,从而当机柜1失去服务能力的情况下,由机柜2和机柜3接管,共同承担网络压力,实现了负载均衡。Specifically, the Hash function is used for uniform distribution. The primary key M is the number corresponding to the mirror node instance, N is the number of cabinets, and the primary key is used as the sharding attribute. Take the remainder obtained after dividing the keyword by a number not greater than the length N of the hash table as the hash address. For example: the number of cabinets here is N=3, if M is 001, the hash address is 1, and HashFunc(1)=001%(3-1). Taking the three servers in cabinet 1 as an example, the mirror node instance numbers are (001 002 003 004) (005 006 007 008) (009010 011 012). When cabinet 1 goes down, cabinet 2 and cabinet 3 are numbered respectively 1, 0, instance 001 obtains the hash address 1 through the Hash function, so instance 001 is assigned to number 1 (cabinet 2). By analogy, after the even distribution of mirror node instances in cabinet 1 is completed, the loop is executed until the mirror node instances of each cabinet are evenly distributed in all other cabinets, and the result is shown in Figure 9. It can be seen from Figure 9 that the mirror node instances corresponding to the master node instance of cabinet 1 are evenly distributed to other cabinets (cabinet 2 and cabinet 3), so that when cabinet 1 loses service capability, cabinet 2 and cabinet 3 take over and jointly Undertake network pressure and achieve load balancing.
其中,当所有机柜的镜像节点实例完成分布后,各机柜所存放的镜像节点实例,可以重新进行排序处理,形成对应编号列表,以机柜1为例,形成如下表1所示的对应排序列表。Among them, after the mirror node instances of all cabinets are distributed, the mirror node instances stored in each cabinet can be sorted again to form a corresponding numbered list. Taking cabinet 1 as an example, a corresponding sorted list is formed as shown in Table 1 below.
表1机柜1分配的镜像节点实例的编号排序Table 1 Numbering of mirror node instances assigned to cabinet 1
在上述实施例的基础上,步骤S202具体可以包括:On the basis of the above embodiments, step S202 may specifically include:
针对每一个机柜执行以下操作:根据当前机柜分配的镜像节点实例的编号数据以及当前机柜的服务器数量,将当前机柜分配的镜像节点实例的编号均匀分配到当前机柜不同的服务器中,最终确定当前机柜的每个服务器分配的镜像节点实例的编号数据。For each cabinet, perform the following operations: according to the number data of the mirror node instance assigned to the current cabinet and the number of servers in the current cabinet, evenly distribute the number of the mirror node instance assigned to the current cabinet to different servers in the current cabinet, and finally determine the current cabinet The number data of the mirror node instance assigned by each server.
需要说明的是,在步骤S201之后,每个机柜都有了均匀分配到本机柜的镜像节点实例的编号,在每台机柜内,由于存在多台服务器,以机柜1为例,可以将本机柜内的镜像节点实例的编号按照上述表1的排序依次分配到本机柜内不同的服务器中。依次类推,直到每一机柜内的镜像节点实例的编号在本机柜内的不同服务器之间完成均匀分配。It should be noted that after step S201, each cabinet has the number of mirror node instances evenly assigned to this cabinet. In each cabinet, since there are multiple servers, taking cabinet 1 as an example, the The numbers of the mirror node instances in the cabinet are assigned to different servers in the cabinet in sequence according to the order in Table 1 above. And so on, until the number of the mirror node instance in each cabinet is evenly distributed among different servers in the cabinet.
可选的,根据当前机柜分配的镜像节点实例的编号数据以及当前机柜的服务器数量,将当前机柜分配的镜像节点实例的编号均匀分配到当前机柜不同的服务器中,具体可以采用以下哈希函数实现均匀分配:Optionally, according to the number data of the mirror node instances allocated to the current cabinet and the number of servers in the current cabinet, the numbers of the mirror node instances allocated to the current cabinet are evenly distributed to different servers in the current cabinet. Specifically, the following hash function can be used to implement Even distribution:
HashFunc(Y)=K%IHashFunc(Y)=K%I
其中,Y为哈希地址,代表编号K所分配到的服务器;K为当前机柜分配的镜像节点实例的编号,Y为当前机柜的服务器数量。Among them, Y is the hash address, which represents the server number K is allocated to; K is the number of the mirror node instance allocated to the current cabinet, and Y is the number of servers in the current cabinet.
具体的,采用Hash函数进行均匀分配,主键K是镜像节点实例对应的编号,I为当前机柜内的服务器数量,以主键作为分片属性。在如图9完成了基于机柜的镜像节点实例分配后,以机柜1为例,将机柜1的三台服务器编号为0、1、2,参照表1的排序,依次对机柜1中分配的编号013、015、017…..035,按照上述哈希函数均匀分配到不同的服务器中。如HashFunc(1)=013%3,即将编号为013的镜像节点实例分配到编号为1的服务器,如HashFunc(2)=017%3,即将编号为017的镜像节点实例分配到编号为2的服务器。以此类推,完成每个机柜内的镜像节点实例在本机柜内的服务器中的均匀分配,结果如图10所示。Specifically, the Hash function is used for uniform distribution, the primary key K is the number corresponding to the mirror node instance, I is the number of servers in the current cabinet, and the primary key is used as the fragmentation attribute. After the cabinet-based image node instance allocation is completed as shown in Figure 9, take cabinet 1 as an example, number the three servers in cabinet 1 as 0, 1, and 2, and refer to the sorting in Table 1, and sequentially assign the numbers in cabinet 1 013, 015, 017.....035 are evenly distributed to different servers according to the above hash function. For example, HashFunc(1)=013%3, the mirror node instance numbered 013 is assigned to the server numbered 1, such as HashFunc(2)=017%3, the mirror node instance numbered 017 is assigned to the server numbered 2 server. By analogy, the mirror node instances in each cabinet are evenly distributed among the servers in the cabinet, and the result is shown in Figure 10.
其中,在完成所有镜像节点实例在各个机柜以及各个服务器的均匀分配后,可以生成新的对应每一个服务器的主节点实例和镜像节点实例,如下表2所示,以机柜1为例,对应3个服务器的主节点实例编号依次为:001、002、003…….012,镜像节点实例编号依次为:013、019、025、031、015、021、027、033、017、023、029、035。Among them, after the uniform distribution of all mirror node instances in each cabinet and each server is completed, a new master node instance and mirror node instance corresponding to each server can be generated, as shown in Table 2 below. Taking cabinet 1 as an example, corresponding to 3 The master node instance numbers of each server are: 001, 002, 003...012, and the mirror node instance numbers are: 013, 019, 025, 031, 015, 021, 027, 033, 017, 023, 029, 035 .
表2机柜1不同服务器分配的镜像节点实例编号列表Table 2 List of mirror node instance numbers assigned to different servers in cabinet 1
根据获取的机柜数N,以及每台机柜所安装的服务器数量I,就能将所有镜像节点实例进行负载均衡的予以配置,将生成的对应配置列表提供给GP数据库,就能按照配置列表进初始化分配,从而到达机柜故障后负载均衡的效果。According to the obtained number of cabinets N and the number of servers I installed in each cabinet, all mirror node instances can be configured for load balancing, and the generated corresponding configuration list can be provided to the GP database, and initialization can be performed according to the configuration list distribution, so as to achieve the effect of load balancing after a cabinet failure.
本发明实施例提供的数据库集群镜像节点的负载均衡方法,在当前机柜出现故障的情况下,网络压力也可以分散在不同的机柜中,不会单一集中在镜像机柜中,在当前机柜出现故障时,也能够让整个集群处于负载均衡的状态;根据不同机柜以及机柜内服务器数量多次Hash运行结果自动化地确定新的镜像节点实例分布列表,不需要人工依靠经验确定镜像节点实例的分配,不依赖于维护人员的经验,根据配置参数进行镜像节点实例的合理分布,不会出现人为错误等情况,保证了镜像节点实例分布合理化处理,避免了问题发生。In the load balancing method of the mirror node of the database cluster provided by the embodiment of the present invention, when the current cabinet fails, the network pressure can also be dispersed in different cabinets, and will not be concentrated in the mirror cabinet alone. When the current cabinet fails , and can also make the entire cluster in a load-balanced state; automatically determine the distribution list of new mirror node instances according to the results of multiple Hash operations in different cabinets and the number of servers in the cabinet, without manually relying on experience to determine the distribution of mirror node instances. Based on the experience of the maintenance personnel, the reasonable distribution of mirror node instances is carried out according to the configuration parameters, and there will be no human error, etc., which ensures the reasonable distribution of mirror node instances and avoids problems.
另一方面,如图11所示,本发明实施例还提供了一种数据库集群镜像节点的负载均衡装置,该装置可以采用上述实施例所述的数据库集群镜像节点的负载均衡方法,包括:依次连接的参数获取模块111和均匀分配模块112;On the other hand, as shown in FIG. 11 , the embodiment of the present invention also provides a load balancing device for a mirror node of a database cluster, which can adopt the load balancing method for a mirror node of a database cluster described in the above embodiment, including: Connected parameter acquisition module 111 and uniform distribution module 112;
其中,参数获取模块111用于获取数据库集群的配置参数;其中,所述配置参数包括机柜数量、每个机柜的服务器数量以及每个服务器的主节点实例数量;Wherein, the parameter obtaining module 111 is used to obtain the configuration parameters of the database cluster; wherein, the configuration parameters include the number of cabinets, the number of servers in each cabinet, and the number of master node instances of each server;
均匀分配模块112用于根据所述配置参数,将当前机柜的所有主节点实例对应的镜像节点实例均匀分配到除当前机柜以外的所有其他机柜中,以实现数据库集群镜像节点的负载均衡。The uniform distribution module 112 is used to evenly distribute the mirror node instances corresponding to all master node instances of the current cabinet to all other cabinets except the current cabinet according to the configuration parameters, so as to realize load balancing of the database cluster mirror nodes.
具体的,参数获取模块111获取数据库集群的配置参数;其中,所述配置参数包括机柜数量、每个机柜的服务器数量以及每个服务器的主节点实例数量;均匀分配模块112针对数据库集群中的每一个机柜执行以下操作:根据所述配置参数,将当前机柜的所有主节点实例对应的镜像节点实例均匀分配到除当前机柜以外的所有其他机柜中,以实现数据库集群镜像节点的负载均衡。Specifically, the parameter acquisition module 111 acquires the configuration parameters of the database cluster; wherein, the configuration parameters include the number of cabinets, the number of servers in each cabinet, and the number of master node instances of each server; A cabinet performs the following operations: according to the configuration parameters, evenly distribute the mirror node instances corresponding to all master node instances of the current cabinet to all other cabinets except the current cabinet, so as to realize load balancing of the database cluster mirror nodes.
本发明实施例提供的数据库集群镜像节点的负载均衡装置,通过根据数据库集群的配置参数,针对每一个机柜将当前机柜的所有主节点实例对应的镜像节点实例均匀分配到除当前机柜以外的所有其他机柜中,从而将当前机柜的主节点实例对应的镜像节点实例分散在其他不同的机柜中,即使在当前机柜出现故障的情况下,网络压力也可以分散在不同的机柜中,不会单一集中在镜像机柜中,在当前机柜出现故障时,也能够让整个集群处于负载均衡的状态;另外,镜像节点实例的分配不依赖于维护人员的经验,根据配置参数进行镜像节点实例的合理分布,不会出现人为错误等情况,保证了镜像节点实例分布合理化处理,避免了问题发生。The load balancing device of the mirror node of the database cluster provided by the embodiment of the present invention evenly distributes the mirror node instances corresponding to all the master node instances of the current cabinet to all other cabinets except the current cabinet according to the configuration parameters of the database cluster. In the cabinet, the mirror node instance corresponding to the master node instance of the current cabinet is scattered in other different cabinets. Even if the current cabinet fails, the network pressure can be distributed in different cabinets, and will not be concentrated in a single In the mirror cabinet, when the current cabinet fails, the entire cluster can also be in a load-balanced state; in addition, the distribution of mirror node instances does not depend on the experience of maintenance personnel, and the reasonable distribution of mirror node instances according to configuration parameters will not In the event of human error, etc., the distribution of mirror node instances is ensured to be rationalized and problems are avoided.
在上述实施例的基础上,所述均匀分配模块112包括:On the basis of the foregoing embodiments, the even distribution module 112 includes:
机柜分配单元,用于针对每一个机柜执行以下操作:根据当前机柜的主节点实例数量以及所述机柜数量,将当前机柜的主节点实例对应的镜像节点实例均匀分配到除当前机柜以外的所有其他机柜中;The cabinet allocation unit is configured to perform the following operations for each cabinet: according to the number of master node instances of the current cabinet and the number of cabinets, evenly distribute the mirror node instances corresponding to the master node instance of the current cabinet to all other cabinets except the current cabinet in the cabinet;
服务器分配单元,用于针对每一个机柜执行以下操作:根据当前机柜分配的镜像节点实例的数量以及当前机柜的服务器数量,将当前机柜分配的镜像节点实例均匀分配到当前机柜不同的服务器中。The server allocation unit is configured to perform the following operations for each cabinet: according to the number of mirror node instances allocated to the current cabinet and the number of servers in the current cabinet, evenly distribute the mirror node instances allocated to the current cabinet to different servers in the current cabinet.
在上述实施例的基础上,所述机柜分配单元包括:On the basis of the above embodiments, the cabinet distribution unit includes:
编号子单元,用于对所有机柜的主节点实例对应的镜像节点实例进行编号;The numbering subunit is used to number the mirror node instances corresponding to the master node instances of all cabinets;
机柜编号分配子单元,用于针对每一个机柜执行以下操作:根据当前机柜的主节点实例对应的镜像节点实例的编号以及所述机柜数量,将当前机柜的所有主节点实例对应的镜像节点实例的编号均匀分配到除当前机柜以外的其他机柜中,最终得到每个机柜分配的镜像节点实例的编号数据;The cabinet number allocation subunit is used to perform the following operations for each cabinet: according to the number of the mirror node instance corresponding to the master node instance of the current cabinet and the number of cabinets, assign the mirror node instances corresponding to all master node instances of the current cabinet The number is evenly distributed to other cabinets except the current cabinet, and finally the number data of the mirror node instance assigned to each cabinet is obtained;
在上述实施例的基础上,所述服务器分配单元具体用于:On the basis of the above embodiments, the server allocation unit is specifically used for:
针对每一个机柜执行以下操作:根据当前机柜分配的镜像节点实例的编号数据以及当前机柜的服务器数量,将当前机柜分配的镜像节点实例的编号均匀分配到当前机柜不同的服务器中,最终确定当前机柜的每个服务器分配的镜像节点实例的编号数据。For each cabinet, perform the following operations: according to the number data of the mirror node instance assigned to the current cabinet and the number of servers in the current cabinet, evenly distribute the number of the mirror node instance assigned to the current cabinet to different servers in the current cabinet, and finally determine the current cabinet The number data of the mirror node instance assigned by each server.
对于与方法对应的数据库集群镜像节点的负载均衡装置实施例而言,由于其与方法实施例基本相似,达到的技术效果也与方法实施例起到的效果相同,所以描述的比较简单,相关之处参见方法实施例的部分说明即可。For the load balancing device embodiment of the mirror node of the database cluster corresponding to the method, since it is basically similar to the method embodiment, the technical effect achieved is also the same as that of the method embodiment, so the description is relatively simple. For details, please refer to the part description of the method embodiment.
再一方面,如图12所示,本发明实施例还提供了一种电子设备,该电子设备可以是上述实施例所述的装置,该电子设备包括至少一个处理器(processor)121、通信接口(Communications Interface)122、至少一个存储器(memory)123和总线124,其中,处理器121,通信接口122,存储器123通过总线124完成相互间的通信。通信接口122可以用于该电子设备与服务器之间的信息传输。处理器121可以调用存储器123中的逻辑指令,以执行上述实施例所述的方法,例如包括:获取数据库集群的配置参数;其中,所述配置参数包括机柜数量、每个机柜的服务器数量以及每个服务器的主节点实例数量;针对数据库集群中的每一个机柜执行以下操作:根据所述配置参数,将当前机柜的所有主节点实例对应的镜像节点实例均匀分配到除当前机柜以外的所有其他机柜中,以实现数据库集群镜像节点的负载均衡。In another aspect, as shown in FIG. 12 , an embodiment of the present invention also provides an electronic device, which may be the device described in the above embodiment, and the electronic device includes at least one processor (processor) 121, a communication interface (Communications Interface) 122, at least one memory (memory) 123 and a bus 124, wherein, the processor 121, the communication interface 122, and the memory 123 complete mutual communication through the bus 124. The communication interface 122 can be used for information transmission between the electronic device and the server. The processor 121 may call the logic instructions in the memory 123 to execute the methods described in the above embodiments, for example, including: acquiring configuration parameters of the database cluster; wherein the configuration parameters include the number of cabinets, the number of servers in each cabinet, and the The number of primary node instances of a server; perform the following operations for each cabinet in the database cluster: according to the configuration parameters, evenly distribute the mirror node instances corresponding to all the primary node instances of the current cabinet to all other cabinets except the current cabinet In order to achieve load balancing of database cluster mirror nodes.
此外,上述的存储器123中的逻辑指令可以通过软件功能单元的形式实现并作为独立的产品销售或使用时,可以存储在一个计算机可读取存储介质中。基于这样的理解,本发明的技术方案本质上或者说对现有技术做出贡献的部分或者该技术方案的部分可以以软件产品的形式体现出来,该计算机软件产品存储在一个存储介质中,包括若干指令用以使得一台计算机设备(可以是个人计算机,服务器,或者网络设备等)执行本发明各个实施例所述方法的全部或部分步骤。而前述的存储介质包括:U盘、移动硬盘、只读存储器(ROM,Read-Only Memory)、随机存取存储器(RAM,Random Access Memory)、磁碟或者光盘等各种可以存储程序代码的介质。In addition, the above logic instructions in the memory 123 may be implemented in the form of software functional units and when sold or used as an independent product, may be stored in a computer-readable storage medium. Based on this understanding, the essence of the technical solution of the present invention or the part that contributes to the prior art or the part of the technical solution can be embodied in the form of a software product, and the computer software product is stored in a storage medium, including Several instructions are used to make a computer device (which may be a personal computer, a server, or a network device, etc.) execute all or part of the steps of the methods described in various embodiments of the present invention. The aforementioned storage medium includes: U disk, mobile hard disk, read-only memory (ROM, Read-Only Memory), random access memory (RAM, Random Access Memory), magnetic disk or optical disk and other media that can store program codes. .
本发明实施例提供了一种计算机程序产品,所述计算机程序产品包括存储在非暂态计算机可读存储介质上的计算机程序,所述计算机程序包括程序指令,当所述程序指令被计算机执行时,计算机能够执行上述各方法实施例所提供的方法,例如包括:获取数据库集群的配置参数;其中,所述配置参数包括机柜数量、每个机柜的服务器数量以及每个服务器的主节点实例数量;针对数据库集群中的每一个机柜执行以下操作:根据所述配置参数,将当前机柜的所有主节点实例对应的镜像节点实例均匀分配到除当前机柜以外的所有其他机柜中,以实现数据库集群镜像节点的负载均衡。An embodiment of the present invention provides a computer program product, the computer program product includes a computer program stored on a non-transitory computer-readable storage medium, the computer program includes program instructions, and when the program instructions are executed by a computer The computer can execute the methods provided by the above method embodiments, for example, including: obtaining configuration parameters of the database cluster; wherein, the configuration parameters include the number of cabinets, the number of servers in each cabinet, and the number of master node instances for each server; Perform the following operations for each cabinet in the database cluster: according to the configuration parameters, evenly distribute the mirror node instances corresponding to all the master node instances of the current cabinet to all other cabinets except the current cabinet, so as to realize the mirror node of the database cluster load balancing.
本发明实施例提供了一种非暂态计算机可读存储介质,所述非暂态计算机可读存储介质存储计算机指令,所述计算机指令使所述计算机执行上述各方法实施例所提供的方法,例如包括:获取数据库集群的配置参数;其中,所述配置参数包括机柜数量、每个机柜的服务器数量以及每个服务器的主节点实例数量;针对数据库集群中的每一个机柜执行以下操作:根据所述配置参数,将当前机柜的所有主节点实例对应的镜像节点实例均匀分配到除当前机柜以外的所有其他机柜中,以实现数据库集群镜像节点的负载均衡。An embodiment of the present invention provides a non-transitory computer-readable storage medium, the non-transitory computer-readable storage medium stores computer instructions, and the computer instructions cause the computer to execute the methods provided in the above method embodiments, For example, it includes: obtaining the configuration parameters of the database cluster; wherein, the configuration parameters include the number of cabinets, the number of servers in each cabinet, and the number of master node instances of each server; perform the following operations for each cabinet in the database cluster: according to the According to the above configuration parameters, the mirror node instances corresponding to all the master node instances of the current cabinet are evenly distributed to all other cabinets except the current cabinet, so as to realize the load balancing of the database cluster mirror nodes.
以上所描述的装置实施例仅仅是示意性的,其中所述作为分离部件说明的单元可以是或者也可以不是物理上分开的,作为单元显示的部件可以是或者也可以不是物理单元,即可以位于一个地方,或者也可以分布到多个网络单元上。可以根据实际的需要选择其中的部分或者全部模块来实现本实施例方案的目的。本领域普通技术人员在不付出创造性的劳动的情况下,即可以理解并实施。The device embodiments described above are only illustrative, and the units described as separate components may or may not be physically separated, and the components shown as units may or may not be physical units, that is, they may be located in One place, or it can be distributed to multiple network elements. Part or all of the modules can be selected according to actual needs to achieve the purpose of the solution of this embodiment. It can be understood and implemented by those skilled in the art without any creative efforts.
通过以上的实施方式的描述,本领域的技术人员可以清楚地了解到各实施方式可借助软件加必需的通用硬件平台的方式来实现,当然也可以通过硬件。基于这样的理解,上述技术方案本质上或者说对现有技术做出贡献的部分可以以软件产品的形式体现出来,该计算机软件产品可以存储在计算机可读存储介质中,如ROM/RAM、磁碟、光盘等,包括若干指令用以使得一台计算机设备(可以是个人计算机,服务器,或者网络设备等)执行各个实施例或者实施例的某些部分所述的方法。Through the above description of the implementations, those skilled in the art can clearly understand that each implementation can be implemented by means of software plus a necessary general hardware platform, and of course also by hardware. Based on this understanding, the essence of the above technical solution or the part that contributes to the prior art can be embodied in the form of software products, and the computer software products can be stored in computer-readable storage media, such as ROM/RAM, magnetic discs, optical discs, etc., including several instructions to make a computer device (which may be a personal computer, server, or network device, etc.) execute the methods described in various embodiments or some parts of the embodiments.
最后应说明的是:以上实施例仅用以说明本发明的技术方案,而非对其限制;尽管参照前述实施例对本发明进行了详细的说明,本领域的普通技术人员应当理解:其依然可以对前述各实施例所记载的技术方案进行修改,或者对其中部分技术特征进行等同替换;而这些修改或者替换,并不使相应技术方案的本质脱离本发明各实施例技术方案的精神和范围。Finally, it should be noted that: the above embodiments are only used to illustrate the technical solutions of the present invention, rather than to limit them; although the present invention has been described in detail with reference to the foregoing embodiments, those of ordinary skill in the art should understand that: it can still be Modifications are made to the technical solutions described in the foregoing embodiments, or equivalent replacements are made to some of the technical features; and these modifications or replacements do not make the essence of the corresponding technical solutions deviate from the spirit and scope of the technical solutions of the various embodiments of the present invention.
Claims (10)
Priority Applications (1)
| Application Number | Priority Date | Filing Date | Title |
|---|---|---|---|
| CN201710067354.1A CN108400999B (en) | 2017-02-06 | 2017-02-06 | A load balancing method and device for database cluster mirror node |
Applications Claiming Priority (1)
| Application Number | Priority Date | Filing Date | Title |
|---|---|---|---|
| CN201710067354.1A CN108400999B (en) | 2017-02-06 | 2017-02-06 | A load balancing method and device for database cluster mirror node |
Publications (2)
| Publication Number | Publication Date |
|---|---|
| CN108400999A true CN108400999A (en) | 2018-08-14 |
| CN108400999B CN108400999B (en) | 2020-10-30 |
Family
ID=63094181
Family Applications (1)
| Application Number | Title | Priority Date | Filing Date |
|---|---|---|---|
| CN201710067354.1A Active CN108400999B (en) | 2017-02-06 | 2017-02-06 | A load balancing method and device for database cluster mirror node |
Country Status (1)
| Country | Link |
|---|---|
| CN (1) | CN108400999B (en) |
Cited By (5)
| Publication number | Priority date | Publication date | Assignee | Title |
|---|---|---|---|---|
| CN111459654A (en) * | 2019-01-22 | 2020-07-28 | 顺丰科技有限公司 | Server cluster deployment method, device, equipment and storage medium |
| CN111858156A (en) * | 2020-06-12 | 2020-10-30 | 北京金山云网络技术有限公司 | Image management method, device and electronic device |
| CN113742173A (en) * | 2021-08-30 | 2021-12-03 | 浙江大华技术股份有限公司 | Multi-device cluster control method, device main control device, and readable storage medium |
| CN114124700A (en) * | 2021-10-26 | 2022-03-01 | 马上消费金融股份有限公司 | Cluster parameter configuration method and device, electronic equipment and readable storage medium |
| CN116112498A (en) * | 2023-02-24 | 2023-05-12 | 郑州云海信息技术有限公司 | A node IO forwarding method, device and medium of a multi-control cluster |
Citations (5)
| Publication number | Priority date | Publication date | Assignee | Title |
|---|---|---|---|---|
| CN101916209A (en) * | 2010-08-06 | 2010-12-15 | 华东交通大学 | A multi-core processor cluster task resource allocation method |
| CN103403666A (en) * | 2012-12-21 | 2013-11-20 | 华为技术有限公司 | Distributed storage control method, device and system |
| US8745264B1 (en) * | 2011-03-31 | 2014-06-03 | Amazon Technologies, Inc. | Random next iteration for data update management |
| US9330151B1 (en) * | 2013-03-08 | 2016-05-03 | Emc Corporation | Database change data capture within a storage array |
| CN106372161A (en) * | 2016-08-31 | 2017-02-01 | 天津南大通用数据技术股份有限公司 | Distributive database data backup piece deployment method and device |
-
2017
- 2017-02-06 CN CN201710067354.1A patent/CN108400999B/en active Active
Patent Citations (5)
| Publication number | Priority date | Publication date | Assignee | Title |
|---|---|---|---|---|
| CN101916209A (en) * | 2010-08-06 | 2010-12-15 | 华东交通大学 | A multi-core processor cluster task resource allocation method |
| US8745264B1 (en) * | 2011-03-31 | 2014-06-03 | Amazon Technologies, Inc. | Random next iteration for data update management |
| CN103403666A (en) * | 2012-12-21 | 2013-11-20 | 华为技术有限公司 | Distributed storage control method, device and system |
| US9330151B1 (en) * | 2013-03-08 | 2016-05-03 | Emc Corporation | Database change data capture within a storage array |
| CN106372161A (en) * | 2016-08-31 | 2017-02-01 | 天津南大通用数据技术股份有限公司 | Distributive database data backup piece deployment method and device |
Cited By (7)
| Publication number | Priority date | Publication date | Assignee | Title |
|---|---|---|---|---|
| CN111459654A (en) * | 2019-01-22 | 2020-07-28 | 顺丰科技有限公司 | Server cluster deployment method, device, equipment and storage medium |
| CN111459654B (en) * | 2019-01-22 | 2024-04-16 | 顺丰科技有限公司 | Server cluster deployment method, device, equipment and storage medium |
| CN111858156A (en) * | 2020-06-12 | 2020-10-30 | 北京金山云网络技术有限公司 | Image management method, device and electronic device |
| CN111858156B (en) * | 2020-06-12 | 2024-11-26 | 北京金山云网络技术有限公司 | Image management method, device and electronic equipment |
| CN113742173A (en) * | 2021-08-30 | 2021-12-03 | 浙江大华技术股份有限公司 | Multi-device cluster control method, device main control device, and readable storage medium |
| CN114124700A (en) * | 2021-10-26 | 2022-03-01 | 马上消费金融股份有限公司 | Cluster parameter configuration method and device, electronic equipment and readable storage medium |
| CN116112498A (en) * | 2023-02-24 | 2023-05-12 | 郑州云海信息技术有限公司 | A node IO forwarding method, device and medium of a multi-control cluster |
Also Published As
| Publication number | Publication date |
|---|---|
| CN108400999B (en) | 2020-10-30 |
Similar Documents
| Publication | Publication Date | Title |
|---|---|---|
| CN108400999B (en) | A load balancing method and device for database cluster mirror node | |
| CN107430603B (en) | System and method for massively parallel processing of databases | |
| CN109739919B (en) | A front-end computer and acquisition system for power system | |
| WO2017080257A1 (en) | Data processing method and system based on key-value pair | |
| WO2015096606A1 (en) | Network device, cluster storage system and distributed lock management method | |
| CN103051691B (en) | Partition allocation method, device and distributed memory system | |
| CN105933137A (en) | Resource management method, device and system | |
| CN106126583A (en) | The collection group strong compatibility processing method of a kind of distributed chart database and system | |
| CN103118130A (en) | Cluster management method and cluster management system for distributed service | |
| CN107590257A (en) | A kind of data base management method and device | |
| US11609928B2 (en) | Systems and methods of determining target database for replication of tenant data | |
| CN110046178A (en) | The method and apparatus of distributed data inquiry | |
| CN103473328A (en) | MYSQL (my structured query language)-based database cloud and construction method for same | |
| CN107682411A (en) | A kind of extensive SDN controllers cluster and network system | |
| Trivedi et al. | System availability assessment using stochastic models | |
| CN108984105B (en) | Method and device for distributing replication tasks in network storage device | |
| CN105843820B (en) | Data migration method and device | |
| CN107800737A (en) | The determination method, apparatus and server cluster of host node in a kind of server cluster | |
| CN107085579A (en) | A method and device for collecting and distributing data | |
| CN103902310A (en) | Scheduling system and method for starting of virtual machines | |
| CN104331508B (en) | A kind of implementation relation type database loads balanced management system and method | |
| CN114791850A (en) | Task processing method and device thereof, and computer-readable storage medium | |
| CN109299191A (en) | A kind of data distribution method, device, server and computer storage medium | |
| CN105450727B (en) | A kind of network communication method and network communication architectures | |
| CN117971983A (en) | Data synchronization method, device, computer equipment and computer readable storage medium |
Legal Events
| Date | Code | Title | Description |
|---|---|---|---|
| PB01 | Publication | ||
| PB01 | Publication | ||
| SE01 | Entry into force of request for substantive examination | ||
| SE01 | Entry into force of request for substantive examination | ||
| GR01 | Patent grant | ||
| GR01 | Patent grant |