Traffic distribution methods, devices, equipment, and storage media for database clusters
By acquiring and adjusting the traffic weights of the MySQL database cluster nodes, the problem of the new master node being unable to handle read traffic after failover was solved, achieving automatic traffic allocation and load balancing, and ensuring the stability and data consistency of the database cluster.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- SHANGHAI PUDONG DEVELOPMENT BANK
- Filing Date
- 2022-11-28
- Publication Date
- 2026-07-17
Smart Images

Figure CN115757635B_ABST
Abstract
Description
Technical Field
[0001] The embodiments of the present invention relate to the field of database technology, and in particular to a method, apparatus, device and storage medium for traffic allocation of a database cluster. Background Technology
[0002] With the development of database technology, the use of open source databases has become very widespread, and MySQL database occupies a pivotal position among many open source databases.
[0003] For read / write splitting in MySQL databases, it is usually implemented through a database proxy, which is a network middleware located between the business system and the database. However, when a failover occurs, the standby node is promoted to the new master node, but the new master node still retains its initial weight and cannot handle read traffic. It cannot automatically distribute read traffic after failover, and the read-only node bears all the read traffic, causing a surge in load and creating a performance bottleneck. Summary of the Invention
[0004] This invention provides a method, apparatus, device, and storage medium for traffic allocation in a database cluster, so as to automatically adjust the allocation of read and write traffic among the new master node, read-only node, and the original master node after fault recovery when a failover occurs.
[0005] According to one aspect of the present invention, a method for traffic allocation in a database cluster is provided, the database cluster comprising a master node, a backup node, and at least one read-only node; the method includes:
[0006] Obtain the initial traffic weights of the primary node, the backup node, and the at least one read-only node; wherein the initial traffic weight of the backup node is a set value;
[0007] When the primary node fails, the backup node will be switched to become the new primary node;
[0008] The target traffic weight of the new master node is determined based on the initial traffic weight of the master node.
[0009] The database cluster is controlled to read data based on the target traffic weight of the new master node and the initial traffic weight of the at least one read-only node.
[0010] Optionally, the target traffic weight of the new master node is determined based on the initial traffic weight of the master node, including:
[0011] The range of traffic weights is determined based on the initial traffic weights of the master node;
[0012] Select a traffic weight from the range of traffic weights and determine it as the target traffic weight of the new master node.
[0013] Optionally, the traffic weight range is determined based on the initial traffic weight of the master node, including:
[0014] Get the set weight offset;
[0015] The traffic weight range is determined based on the initial traffic weight of the master node and the offset; wherein the traffic weight range is centered on the initial traffic weight of the master node.
[0016] Optionally, the database cluster is controlled to read data based on the target traffic weight of the new master node and the initial traffic weight of the at least one read-only node, including:
[0017] The traffic allocation ratio between the new master node and the at least one read-only node is determined based on the target traffic weight of the new master node and the initial traffic weight of the at least one read-only node.
[0018] The database cluster is controlled to read data according to the stated traffic allocation ratio.
[0019] Optionally, after controlling the database cluster to read data based on the target traffic weight of the new master node and the initial traffic weight of the at least one read-only node, the method further includes:
[0020] If the primary node is repaired, the primary node will be switched to a new backup node, and the traffic weight of the new backup node will be adjusted to a set value.
[0021] According to another aspect of the present invention, a traffic distribution device for a database cluster is provided, the database cluster being configured with a master node, a backup node, and at least one read-only node; the device includes:
[0022] An initial traffic weight acquisition module is used to acquire the initial traffic weights of the primary node, the backup node, and the at least one read-only node; wherein the initial traffic weight of the backup node is a set value;
[0023] The master node switching module is used to switch the backup node to a new master node when the master node fails.
[0024] The target traffic weight determination module is used to determine the target traffic weight of the new master node based on the initial traffic weight of the master node.
[0025] The data reading module is used to control the database cluster to read data based on the target traffic weight of the new master node and the initial traffic weight of the at least one read-only node.
[0026] Optional, the target traffic weight determination module includes:
[0027] A traffic weight range determination unit is used to determine the traffic weight range based on the initial traffic weight of the master node.
[0028] The target traffic weight determination unit is used to select a traffic weight from the range of traffic weights and determine it as the target traffic weight of the new master node.
[0029] Optional, the traffic weight range determination unit is specifically used for:
[0030] Get the set weight offset;
[0031] The traffic weight range is determined based on the initial traffic weight of the master node and the offset; wherein the traffic weight range is centered on the initial traffic weight of the master node.
[0032] According to another aspect of the present invention, an electronic device is provided, the electronic device comprising:
[0033] At least one processor; and
[0034] A memory communicatively connected to the at least one processor; wherein,
[0035] The memory stores a computer program that can be executed by the at least one processor, the computer program being executed by the at least one processor to enable the at least one processor to execute the traffic allocation method for the database cluster according to any embodiment of the present invention.
[0036] According to another aspect of the present invention, a computer-readable storage medium is provided, the computer-readable storage medium storing computer instructions for causing a processor to execute and implement the traffic allocation method for a database cluster according to any embodiment of the present invention.
[0037] This invention obtains the initial traffic weights of the primary node, the backup node, and at least one read-only node; wherein the initial traffic weight of the backup node is a set value; when the primary node fails, the backup node is switched to become the new primary node; the target traffic weight of the new primary node is determined based on the initial traffic weight of the primary node; and the database cluster is controlled to read data based on the target traffic weight of the new primary node and the initial traffic weight of the at least one read-only node. Through the technical solution of this invention, automatic allocation of read and write traffic is achieved among the new primary node, read-only nodes, and the original primary node after failure recovery during failover. Attached Figure Description
[0038] To more clearly illustrate the technical solutions of the embodiments of the present invention, the accompanying drawings used in the embodiments will be briefly introduced below. It should be understood that the following drawings only show some embodiments of the present invention and should not be regarded as a limitation on the scope. For those skilled in the art, other related drawings can be obtained based on these drawings without creative effort.
[0039] Figure 1 This is a flowchart of a traffic allocation method for a database cluster according to Embodiment 1 of the present invention;
[0040] Figure 2 This is an example diagram of the traffic weight allocation before failover provided in Embodiment 1 of the present invention;
[0041] Figure 3 This is an example diagram of traffic weight allocation after failover according to Embodiment 1 of the present invention;
[0042] Figure 4 This is a schematic diagram of the structure of a traffic distribution device for a database cluster according to Embodiment 2 of the present invention;
[0043] Figure 5 This is a schematic diagram of the structure of an electronic device provided according to Embodiment 3 of the present invention. Detailed Implementation
[0044] To enable those skilled in the art to better understand the present invention, the technical solutions of the present invention will be clearly and completely described below with reference to the accompanying drawings of the embodiments of the present invention. Obviously, the described embodiments are only some embodiments of the present invention, and not all embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative effort should fall within the scope of protection of the present invention.
[0045] It should be noted that the terms "first," "second," etc., in the specification, claims, and accompanying drawings of this invention are used to distinguish similar objects and are not necessarily used to describe a specific order or sequence. It should be understood that such data can be interchanged where appropriate so that the embodiments of the invention described herein can be implemented in orders other than those illustrated or described herein. Furthermore, the terms "comprising" and "having," and any variations thereof, are intended to cover a non-exclusive inclusion; for example, a process, method, system, product, or apparatus that comprises a series of steps or units is not necessarily limited to those steps or units explicitly listed, but may include other steps or units not explicitly listed or inherent to such processes, methods, products, or apparatus.
[0046] Example 1
[0047] Figure 1 This is a flowchart of a traffic allocation method for a database cluster according to Embodiment 1 of the present invention. This embodiment is applicable to situations where traffic is allocated to nodes in a database cluster. The method can be executed by a traffic allocation device for the database cluster, which can be implemented in software and / or hardware, optionally through an electronic device, such as a mobile terminal, PC, or server. Specifically, it includes the following steps:
[0048] Step 110: Obtain the initial traffic weights of the primary node, the backup node, and the at least one read-only node.
[0049] The database cluster in this embodiment may include a master node, a standby node, and at least one read-only node. There may be multiple read-only nodes. The initial traffic weight of the standby node can be a set value. The database cluster may include multiple nodes to handle database tasks, such as write and read tasks. For example, the database cluster in this embodiment may be a MySQL cluster. Read / write separation for MySQL databases is typically implemented using a database proxy, which is a network middleware located between the business system and the database.
[0050] In this embodiment, multiple slave nodes in the database cluster can be divided into standby nodes and read-only nodes. The standby nodes are mainly used for disaster recovery of the master node, while the read-only nodes can mainly share the read traffic load. The database cluster in this embodiment can include one master node, one standby node, and at least one read-only node. The initial traffic weight can be pre-configured. In this embodiment, the initial traffic weight can be configured in the database agent to assign initial read traffic weights to each node. In this embodiment, the initial traffic weight of the standby node can be a set value, which can be 0. The initial traffic weight in this embodiment can be configured by technical personnel according to actual needs. For example, assuming the database cluster has an architecture of 1 master node, 1 standby node, and 2 read-only nodes, the initial traffic weight of the master node's read traffic is 50, the initial traffic weight of the standby node's read traffic is 0, and the initial traffic weights of the two read-only nodes are 25 each. That is, the master node bears 50% of the read traffic, the standby node bears 0% of the read traffic, and the two read-only nodes each bear 25% of the read traffic. In this embodiment, the initial traffic weights of the master node, standby node, and at least one read-only node can be obtained.
[0051] For example, Figure 2This is an example diagram illustrating the traffic weight allocation before failover in this embodiment. There can be two read-only nodes; the initial traffic weight of the primary node is 50, the initial traffic weight of the standby node is 0, and the initial weights of the two read-only nodes are 25 each. In this embodiment, the database high-availability component can be orchestrator, and the database proxy component can be proxysql. The orchestrator component manages the MySQL cluster (which may include the primary node, standby node, and read-only nodes), and the proxysql proxy node information is configured in the orchestrator node.
[0052] Step 120: When the primary node fails, the backup node is switched to become the new primary node.
[0053] In this embodiment, when the primary node fails, the backup node can be switched to become the new primary node. If the primary node does not fail, traffic can be read according to the pre-configured initial traffic weight.
[0054] Step 130: Determine the target traffic weight of the new master node based on the initial traffic weight of the master node.
[0055] The target traffic weight can be the traffic weight of the new master node. The target traffic weight can be determined based on the initial traffic weight of the master node. In this embodiment, the target traffic weight of the new master node can be determined based on the initial traffic weight of the master node.
[0056] In this embodiment, optionally, determining the target traffic weight of the new master node based on the initial traffic weight of the master node includes: determining a traffic weight range based on the initial traffic weight of the master node; and selecting a traffic weight from the traffic weight range as the target traffic weight of the new master node.
[0057] The traffic weight range can be less than or equal to the initial traffic weight, or it can be determined based on the initial traffic weight of the master node and the set weight offset. It can also be set according to actual needs. The target traffic weight of the new master node can be determined by selecting a traffic weight from the traffic weight range.
[0058] In this embodiment, the weight range can be determined based on the initial traffic weight of the master node. For example, if the initial traffic weight of the master node is 50, the traffic weight range can be 0-50. The target traffic weight of the new master node can be selected from 0-50, such as 40 or 30, depending on the actual situation.
[0059] In this embodiment, the traffic weight range can be determined based on the initial traffic weight of the master node, and then a traffic weight is selected from the determined traffic weight range to be determined as the target traffic weight of the new master node. This configuration in this embodiment can determine the target traffic weight of the new master node, thereby avoiding the situation where, after a failover, the new master node does not handle read traffic and forwards all read traffic to the read-only node, causing increased load on the read-only node or even rendering it unusable.
[0060] In this embodiment, optionally, determining the traffic weight range based on the initial traffic weight of the master node includes: obtaining a set weight offset; determining the traffic weight range based on the initial traffic weight of the master node and the offset; wherein the traffic weight range is centered on the initial traffic weight of the master node.
[0061] The weight offset can be pre-set; for example, it can be ±10, and can be set according to time requirements. In this embodiment, the traffic weight range can be determined based on the initial traffic weight of the master node and the offset. The traffic weight range can be centered on the initial traffic weight of the master node. It can be understood that in this embodiment, the initial traffic weight can be used as the center, and the range obtained by subtracting or adding the set offset can be used as the traffic weight range. For example, if the initial traffic weight of the master node is 50, and the weight offset can be ±10, then the traffic weight range can be 40-60.
[0062] In this embodiment, a set weight offset can be obtained, and the weight range can be determined based on the initial traffic weight of the master node as the center and the offset. This setting allows for the determination of the traffic weight range, facilitating the selection of a traffic weight from the determined range as the new target traffic weight for the master node, making it more flexible and convenient.
[0063] For example, Figure 3This is an example diagram illustrating the traffic weight allocation after failover in this embodiment. There can be two read-only nodes, and the target traffic weight for the new master node is set to 50. In this embodiment, the hook function after the orchestrator failover reads the original master node weight from the proxysql database and applies it to the new master node, adjusting the read traffic weight of the new master node to 50 and the read traffic weight of the original master node to 0. In this embodiment, when the orchestrator detects a master node failure and initiates a failover, it automatically invokes the pre-set configuration based on its own mechanism to modify the logic of the new master node weight in the proxysql database. The traffic weight adjustments configured after failover are as follows: the target traffic weight of the new master node can be 50; the original master node, after being repaired, acts as a backup node with a traffic weight of 0; and the traffic weights of the two read-only nodes are 25 each.
[0064] In this embodiment, if the original master node is repaired and then rejoins the cluster as a standby node, since the read traffic weight has been modified to 0, it will not bear the read traffic of the standby node after rejoining the cluster. This avoids data inconsistency caused by being away from the cluster for a long time and reduces the impact on business.
[0065] Step 140: Control the database cluster to read data based on the target traffic weight of the new master node and the initial traffic weight of the at least one read-only node.
[0066] In this embodiment, the database cluster can be controlled to read data based on the target traffic weight of the new master node and the initial traffic weight of at least one read-only node.
[0067] In this embodiment, optionally, controlling the database cluster to read data based on the target traffic weight of the new master node and the initial traffic weight of the at least one read-only node includes: determining the traffic allocation ratio between the new master node and the at least one read-only node based on the target traffic weight of the new master node and the initial traffic weight of the at least one read-only node; and controlling the database cluster to read data according to the traffic allocation ratio.
[0068] The traffic allocation ratio between the new master node and at least one read-only node can be determined based on the target traffic weight of the new master node and the initial traffic weight of the at least one read-only node. For example, if there is one read-only node, the target traffic weight of the new master node is 50, and the weight of the read-only node is 50, then the traffic allocation ratio between the new master node and the read-only node is 1:1; if there are two read-only nodes, the target traffic weight of the new master node is 50, and the weights of the two read-only nodes are each 25, then the traffic allocation ratio between the new master node and the two read-only nodes is 2:1:1. In this embodiment, the database cluster can be controlled to read data according to the traffic allocation ratio.
[0069] In this embodiment, the traffic allocation ratio between the new master node and at least one read-only node can be determined based on the target traffic weight of the new master node and the initial traffic weight of at least one read-only node. Then, the database cluster is controlled to read data according to this traffic allocation ratio. This configuration automatically performs data reading based on the automatically allocated read / write traffic ratio between the new master node and the read-only nodes, ensuring data consistency and maintaining the stable operation of the business system.
[0070] In this embodiment, optionally, after controlling the database cluster to read data according to the target traffic weight of the new master node and the initial traffic weight of the at least one read-only node, the method further includes: if the master node is repaired, the master node is switched to a new standby node, and the traffic weight of the new standby node is adjusted to a set value.
[0071] The set value can be preset or set according to actual needs. In this embodiment, the set value can be 0. In this embodiment, if the primary node fails and is repaired, the primary node can be switched to a new standby node, and the traffic weight of the new standby node can be adjusted to the set value. With this setting, after the primary node fails and is repaired, the original primary node is switched to a new standby node for disaster recovery, which is more convenient; it also avoids the situation where read traffic is sent to the original primary node after it recovers and joins the cluster as a standby node.
[0072] This invention obtains the initial traffic weights of the primary node, the backup node, and at least one read-only node; wherein the initial traffic weight of the backup node is a set value; when the primary node fails, the backup node is switched to become the new primary node; the target traffic weight of the new primary node is determined based on the initial traffic weight of the primary node; and the database cluster is controlled to read data based on the target traffic weight of the new primary node and the initial traffic weight of the at least one read-only node. Through the technical solution of this invention, automatic allocation of read and write traffic is achieved among the new primary node, read-only nodes, and the original primary node after failure recovery during failover.
[0073] Example 2
[0074] Figure 4 This is a schematic diagram of a traffic allocation device for a database cluster according to Embodiment 2 of the present invention. This device can execute the traffic allocation method for a database cluster provided in any embodiment of the present invention, and possesses the corresponding functional modules and beneficial effects for executing the method. For example... Figure 4 As shown, the database cluster is configured with one master node, one standby node, and at least one read-only node; the device includes:
[0075] The initial traffic weight acquisition module 410 is used to acquire the initial traffic weights of the primary node, the backup node, and the at least one read-only node; wherein the initial traffic weight of the backup node is a set value.
[0076] The master node switching module 420 is used to switch the backup node to a new master node when the master node fails.
[0077] The target traffic weight determination module 430 is used to determine the target traffic weight of the new master node based on the initial traffic weight of the master node.
[0078] The data reading module 440 is used to control the database cluster to read data based on the target traffic weight of the new master node and the initial traffic weight of the at least one read-only node.
[0079] Optional, the target traffic weight determination module includes:
[0080] A traffic weight range determination unit is used to determine the traffic weight range based on the initial traffic weight of the master node.
[0081] The target traffic weight determination unit is used to select a traffic weight from the range of traffic weights and determine it as the target traffic weight of the new master node.
[0082] Optional, the traffic weight range determination unit is specifically used for:
[0083] Get the set weight offset;
[0084] The traffic weight range is determined based on the initial traffic weight of the master node and the offset; wherein the traffic weight range is centered on the initial traffic weight of the master node.
[0085] Optionally, the data reading module 440 has features for:
[0086] The traffic allocation ratio between the new master node and the at least one read-only node is determined based on the target traffic weight of the new master node and the initial traffic weight of the at least one read-only node.
[0087] The database cluster is controlled to read data according to the stated traffic allocation ratio.
[0088] Optionally, the device further includes:
[0089] The node switching module is used to control the database cluster to read data according to the target traffic weight of the new master node and the initial traffic weight of the at least one read-only node. If the master node is repaired, the module switches the master node to a new standby node and adjusts the traffic weight of the new standby node to a set value.
[0090] The above-described apparatus can execute the methods provided in all the foregoing embodiments of the present invention, and has the corresponding functional modules and beneficial effects for executing the above methods. Technical details not described in detail in this embodiment can be found in the methods provided in all the foregoing embodiments of the present invention.
[0091] Example 3
[0092] Figure 5 This is a schematic diagram of an electronic device according to Embodiment 3 of the present invention. The electronic device 10 is intended to represent various forms of digital computers, such as laptop computers, desktop computers, workstations, personal digital assistants, servers, blade servers, mainframe computers, and other suitable computers. The electronic device may also represent various forms of mobile devices, such as personal digital processors, cellular phones, smartphones, wearable devices (such as helmets, glasses, watches, etc.), and other similar computing devices. The components shown herein, their connections and relationships, and their functions are merely illustrative and are not intended to limit the implementation of the invention described and / or claimed herein.
[0093] like Figure 5As shown, the electronic device 10 includes at least one processor 11 and a memory, such as a read-only memory (ROM) 12 or a random access memory (RAM) 13, communicatively connected to the at least one processor 11. The memory stores computer programs executable by the at least one processor. The processor 11 can perform various appropriate actions and processes based on the computer program stored in the ROM 12 or loaded from storage unit 18 into the RAM 13. The RAM 13 may also store various programs and data required for the operation of the electronic device 10. The processor 11, ROM 12, and RAM 13 are interconnected via a bus 14. An input / output (I / O) interface 15 is also connected to the bus 14.
[0094] Multiple components in electronic device 10 are connected to I / O interface 15, including: input unit 16, such as keyboard, mouse, etc.; output unit 17, such as various types of displays, speakers, etc.; storage unit 18, such as disk, optical disk, etc.; and communication unit 19, such as network card, modem, wireless transceiver, etc. Communication unit 19 allows electronic device 10 to exchange information / data with other devices through computer networks such as the Internet and / or various telecommunications networks.
[0095] Processor 11 can be a variety of general-purpose and / or special-purpose processing components with processing and computing capabilities. Some examples of processor 11 include, but are not limited to, a central processing unit (CPU), a graphics processing unit (GPU), various special-purpose artificial intelligence (AI) computing chips, various processors running machine learning model algorithms, a digital signal processor (DSP), and any suitable processor, controller, microcontroller, etc. Processor 11 performs the various methods and processes described above, such as traffic distribution methods for a database cluster.
[0096] In some embodiments, the traffic allocation method for the database cluster can be implemented as a computer program tangibly contained in a computer-readable storage medium, such as storage unit 18. In some embodiments, part or all of the computer program can be loaded and / or installed on electronic device 10 via ROM 12 and / or communication unit 19. When the computer program is loaded into RAM 13 and executed by processor 11, one or more steps of the traffic allocation method for the database cluster described above can be performed. Alternatively, in other embodiments, processor 11 can be configured to perform the traffic allocation method for the database cluster by any other suitable means (e.g., by means of firmware).
[0097] Various embodiments of the systems and techniques described above herein can be implemented in digital electronic circuit systems, integrated circuit systems, field-programmable gate arrays (FPGAs), application-specific integrated circuits (ASICs), application-specific standard products (ASSPs), systems-on-a-chip (SoCs), payload-programmable logic devices (CPLDs), computer hardware, firmware, software, and / or combinations thereof. These various embodiments may include implementations in one or more computer programs that can be executed and / or interpreted on a programmable system including at least one programmable processor, which may be a dedicated or general-purpose programmable processor, capable of receiving data and instructions from a storage system, at least one input device, and at least one output device, and transmitting data and instructions to the storage system, the at least one input device, and the at least one output device.
[0098] Computer programs used to implement the methods of the present invention may be written in any combination of one or more programming languages. These computer programs may be provided to a processor of a general-purpose computer, a special-purpose computer, or other programmable data processing device, such that when executed by the processor, the computer programs cause the functions / operations specified in the flowcharts and / or block diagrams to be performed. The computer programs may be executed entirely on a machine, partially on a machine, or as a standalone software package, partially on a machine and partially on a remote machine, or entirely on a remote machine or server.
[0099] In the context of this invention, a computer-readable storage medium can be a tangible medium that may contain or store a computer program for use by or in conjunction with an instruction execution system, apparatus, or device. A computer-readable storage medium may include, but is not limited to, electronic, magnetic, optical, electromagnetic, infrared, or semiconductor systems, apparatus, or devices, or any suitable combination thereof. Alternatively, a computer-readable storage medium may be a machine-readable signal medium. More specific examples of machine-readable storage media include electrical connections based on one or more wires, portable computer disks, hard disks, random access memory (RAM), read-only memory (ROM), erasable programmable read-only memory (EPROM or flash memory), optical fibers, portable compact disk read-only memory (CD-ROM), optical storage devices, magnetic storage devices, or any suitable combination thereof.
[0100] To provide interaction with a user, the systems and techniques described herein can be implemented on an electronic device having: a display device (e.g., a CRT (cathode ray tube) or LCD (liquid crystal display) monitor) for displaying information to the user; and a keyboard and pointing device (e.g., a mouse or trackball) through which the user provides input to the electronic device. Other types of devices can also be used to provide interaction with the user; for example, feedback provided to the user can be any form of sensory feedback (e.g., visual feedback, auditory feedback, or tactile feedback); and input from the user can be received in any form (including sound input, voice input, or tactile input).
[0101] The systems and technologies described herein can be implemented in computing systems that include backend components (e.g., as data servers), or computing systems that include middleware components (e.g., application servers), or computing systems that include frontend components (e.g., user computers with graphical user interfaces or web browsers through which users can interact with implementations of the systems and technologies described herein), or any combination of such backend, middleware, or frontend components. The components of the system can be interconnected via digital data communication of any form or medium (e.g., communication networks). Examples of communication networks include local area networks (LANs), wide area networks (WANs), blockchain networks, and the Internet.
[0102] A computing system can include clients and servers. Clients and servers are generally located far apart and typically interact through communication networks. The client-server relationship is created by computer programs running on the respective computers and having a client-server relationship with each other. The server can be a cloud server, also known as a cloud computing server or cloud host, which is a hosting product within the cloud computing service system to address the shortcomings of traditional physical hosts and VPS services, such as high management difficulty and weak business scalability.
[0103] It should be understood that the various forms of processes shown above can be used, with steps reordered, added, or deleted. For example, the steps described in this invention can be executed in parallel, sequentially, or in different orders, as long as the desired result of the technical solution of this invention can be achieved, and this is not limited herein.
[0104] The specific embodiments described above do not constitute a limitation on the scope of protection of this invention. Those skilled in the art should understand that various modifications, combinations, sub-combinations, and substitutions can be made according to design requirements and other factors. Any modifications, equivalent substitutions, and improvements made within the spirit and principles of this invention should be included within the scope of protection of this invention.
Claims
1. A method for traffic allocation in a database cluster, characterized in that, The database cluster includes a master node, a backup node, and at least one read-only node; the method includes: Obtain the initial traffic weights of the primary node, the backup node, and the at least one read-only node; wherein the initial traffic weight of the backup node is a set value; When the primary node fails, the backup node will be switched to become the new primary node; The target traffic weight of the new master node is determined based on the initial traffic weight of the master node. The database cluster is controlled to read data based on the target traffic weight of the new master node and the initial traffic weight of the at least one read-only node; The target traffic weight of the new master node is determined based on the initial traffic weight of the master node, including: The traffic weight range is determined based on the initial traffic weight of the master node; wherein the traffic weight range is a range less than or equal to the initial traffic weight, or a range determined based on the initial traffic weight of the master node and a set weight offset. Select a traffic weight from the range of traffic weights and determine it as the target traffic weight of the new master node; The database cluster is controlled to read data based on the target traffic weight of the new master node and the initial traffic weight of the at least one read-only node, including: The traffic allocation ratio between the new master node and the at least one read-only node is determined based on the target traffic weight of the new master node and the initial traffic weight of the at least one read-only node. The database cluster is controlled to read data according to the stated traffic allocation ratio.
2. The method according to claim 1, characterized in that, The traffic weight range is determined based on the initial traffic weight of the master node, including: Get the set weight offset; The traffic weight range is determined based on the initial traffic weight of the master node and the offset; wherein the traffic weight range is centered on the initial traffic weight of the master node.
3. The method according to claim 1, characterized in that, After controlling the database cluster to read data based on the target traffic weight of the new master node and the initial traffic weight of the at least one read-only node, the process further includes: If the primary node is repaired, the primary node will be switched to a new backup node, and the traffic weight of the new backup node will be adjusted to a set value.
4. A traffic distribution device for a database cluster, characterized in that, The database cluster is configured with one master node, one standby node, and at least one read-only node; the device includes: An initial traffic weight acquisition module is used to acquire the initial traffic weights of the primary node, the backup node, and the at least one read-only node; wherein the initial traffic weight of the backup node is a set value; The master node switching module is used to switch the backup node to a new master node when the master node fails. The target traffic weight determination module is used to determine the target traffic weight of the new master node based on the initial traffic weight of the master node. The data reading module is used to control the database cluster to read data based on the target traffic weight of the new master node and the initial traffic weight of the at least one read-only node. The target traffic weight determination module includes: A traffic weight range determination unit is used to determine a traffic weight range based on the initial traffic weight of the master node; wherein the traffic weight range is a range less than or equal to the initial traffic weight, or a range determined based on the initial traffic weight of the master node and a set weight offset. The target traffic weight determination unit is used to select a traffic weight from the traffic weight range and determine it as the target traffic weight of the new master node. The data reading module is specifically used for: The traffic allocation ratio between the new master node and the at least one read-only node is determined based on the target traffic weight of the new master node and the initial traffic weight of the at least one read-only node. The database cluster is controlled to read data according to the stated traffic allocation ratio.
5. The apparatus according to claim 4, characterized in that, The traffic weight range determination unit is specifically used for: Get the set weight offset; The traffic weight range is determined based on the initial traffic weight of the master node and the offset; wherein the traffic weight range is centered on the initial traffic weight of the master node.
6. An electronic device, characterized in that, The electronic device includes: At least one processor; and A memory communicatively connected to the at least one processor; wherein, The memory stores a computer program that can be executed by the at least one processor, the computer program being executed by the at least one processor to enable the at least one processor to perform the traffic allocation method for the database cluster according to any one of claims 1-3.
7. A computer-readable storage medium, characterized in that, The computer-readable storage medium stores computer instructions that, when executed by a processor, implement the traffic allocation method for the database cluster according to any one of claims 1-3.