CN112363815A - Redis cluster processing method and device, electronic equipment and computer readable storage medium - Google Patents
Redis cluster processing method and device, electronic equipment and computer readable storage medium Download PDFInfo
- Publication number
- CN112363815A CN112363815A CN202011321574.0A CN202011321574A CN112363815A CN 112363815 A CN112363815 A CN 112363815A CN 202011321574 A CN202011321574 A CN 202011321574A CN 112363815 A CN112363815 A CN 112363815A
- Authority
- CN
- China
- Prior art keywords
- redis
- node
- offline
- cluster
- master
- 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
- 238000003672 processing method Methods 0.000 title claims abstract description 18
- 238000012545 processing Methods 0.000 claims abstract description 41
- 238000000034 method Methods 0.000 claims abstract description 37
- 238000004590 computer program Methods 0.000 claims description 16
- 230000004083 survival effect Effects 0.000 claims description 12
- 238000005516 engineering process Methods 0.000 abstract description 3
- 238000010586 diagram Methods 0.000 description 16
- 230000006870 function Effects 0.000 description 15
- 238000012423 maintenance Methods 0.000 description 8
- 230000007246 mechanism Effects 0.000 description 7
- 239000002699 waste material Substances 0.000 description 6
- 230000008901 benefit Effects 0.000 description 5
- 238000011156 evaluation Methods 0.000 description 5
- 238000004891 communication Methods 0.000 description 4
- 230000003287 optical effect Effects 0.000 description 4
- 230000008569 process Effects 0.000 description 4
- 230000007547 defect Effects 0.000 description 3
- 230000000644 propagated effect Effects 0.000 description 2
- 238000011084 recovery Methods 0.000 description 2
- 230000002159 abnormal effect Effects 0.000 description 1
- 238000013461 design Methods 0.000 description 1
- 230000006872 improvement Effects 0.000 description 1
- 239000004973 liquid crystal related substance Substances 0.000 description 1
- 239000013307 optical fiber Substances 0.000 description 1
- 230000008439 repair process Effects 0.000 description 1
- 239000004065 semiconductor Substances 0.000 description 1
Images
Classifications
-
- G—PHYSICS
- G06—COMPUTING; CALCULATING OR COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F9/00—Arrangements for program control, e.g. control units
- G06F9/06—Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
- G06F9/46—Multiprogramming arrangements
- G06F9/48—Program initiating; Program switching, e.g. by interrupt
- G06F9/4806—Task transfer initiation or dispatching
- G06F9/4843—Task transfer initiation or dispatching by program, e.g. task dispatcher, supervisor, operating system
- G06F9/485—Task life-cycle, e.g. stopping, restarting, resuming execution
- G06F9/4856—Task life-cycle, e.g. stopping, restarting, resuming execution resumption being on a different machine, e.g. task migration, virtual machine migration
-
- G—PHYSICS
- G06—COMPUTING; CALCULATING OR COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F9/00—Arrangements for program control, e.g. control units
- G06F9/06—Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
- G06F9/46—Multiprogramming arrangements
- G06F9/50—Allocation of resources, e.g. of the central processing unit [CPU]
- G06F9/5005—Allocation of resources, e.g. of the central processing unit [CPU] to service a request
- G06F9/5011—Allocation of resources, e.g. of the central processing unit [CPU] to service a request the resources being hardware resources other than CPUs, Servers and Terminals
- G06F9/5022—Mechanisms to release resources
-
- G—PHYSICS
- G06—COMPUTING; CALCULATING OR COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F9/00—Arrangements for program control, e.g. control units
- G06F9/06—Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
- G06F9/46—Multiprogramming arrangements
- G06F9/50—Allocation of resources, e.g. of the central processing unit [CPU]
- G06F9/5005—Allocation of resources, e.g. of the central processing unit [CPU] to service a request
- G06F9/5027—Allocation of resources, e.g. of the central processing unit [CPU] to service a request the resource being a machine, e.g. CPUs, Servers, Terminals
-
- G—PHYSICS
- G06—COMPUTING; CALCULATING OR COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F2209/00—Indexing scheme relating to G06F9/00
- G06F2209/50—Indexing scheme relating to G06F9/50
- G06F2209/5012—Processor sets
Landscapes
- Engineering & Computer Science (AREA)
- Software Systems (AREA)
- Theoretical Computer Science (AREA)
- Physics & Mathematics (AREA)
- General Engineering & Computer Science (AREA)
- General Physics & Mathematics (AREA)
- Hardware Redundancy (AREA)
Abstract
The present application relates to the field of online transaction technologies, and in particular, to a method and an apparatus for Redis cluster processing, an electronic device, and a computer-readable storage medium. In the Redis cluster processing method, a Redis cluster comprises at least 3 Redis master nodes, each Redis master node is deployed on one host, and the method comprises the following steps: determining the current state information of the Redis cluster; if the current state information of the Redis cluster is determined to be that no less than half Redis main nodes in at least 3 Redis main nodes are offline, acquiring a host corresponding to the Redis main nodes which are not offline; configuring a Redis standby node on a host corresponding to the Redis main node which is not offline, wherein the Redis standby node is a replacement node corresponding to the offline Redis main node; and replacing the offline Redis master node by the Redis bypass node to serve as the Redis master node, and determining the current state information of the new Redis cluster. In the application, the Redis side standby nodes are introduced, so that the function of the Redis cluster is recovered to be normal when more than half of hosts corresponding to the Redis main nodes are down.
Description
Technical Field
The present application relates to the field of online transaction technologies, and in particular, to a method and an apparatus for Redis cluster processing, an electronic device, and a computer-readable storage medium.
Background
In the prior art, for a Redis cluster, when a plurality of Redis master nodes are down at the same time, the master node and the slave node cannot be switched, and the defect is difficult to avoid under the existing processing mechanism. In order to avoid the defects, the probability that the downtime of the Redis main nodes exceeds half of the number of the Redis main nodes simultaneously is reduced by increasing the number of the Redis main nodes; however, this method increases the number of devices, resulting in an increase in maintenance cost of the product. In the prior art, when performing Redis cluster management, scheduling is generally performed through a resource pool or a management center, and thus, due to the introduction of other devices or machines, additional resources are occupied, and trigger-type automatic generation and on-demand startup cannot be performed, so that system resources are wasted. In the prior art, a third-party functional module component is usually introduced to perform the processing of the Redis cluster, which results in an increase in maintenance cost. Based on this, when more than half of hosts corresponding to the Redis main nodes are down, how to restore the Redis cluster function to normal becomes a technical problem to be solved urgently at present.
Disclosure of Invention
The application provides a Redis cluster processing method, a Redis cluster processing device, electronic equipment and a computer readable storage medium, so that when more than half of hosts corresponding to Redis main nodes are down, the functions of the Redis cluster are recovered to be normal.
In a first aspect, a method for processing a Redis cluster is provided, where the Redis cluster includes at least 3 Redis master nodes, and each Redis master node is deployed on a host, and includes:
determining the current state information of the Redis cluster;
if the current state information of the Redis cluster is determined to be that no less than half Redis main nodes in at least 3 Redis main nodes are offline, acquiring a host corresponding to the Redis main nodes which are not offline;
configuring a Redis standby node on a host corresponding to the Redis main node which is not offline, wherein the Redis standby node is a replacement node corresponding to the offline Redis main node;
replacing an offline Redis main node by the Redis bypass node to serve as a Redis main node;
current state information of the new Redis cluster is determined.
In one possible implementation manner, before configuring a Redis bypass node on a host corresponding to the unreis master node that is not offline, the method further includes:
acquiring survival conditions of an offline Redis master node and a Redis slave node corresponding to the offline Redis master node;
and determining the Redis master node needing to be configured with the Redis side standby node according to the survival conditions of the offline Redis master node and the Redis slave node corresponding to the offline Redis master node.
In one possible implementation manner, the configuring a Redis bypass node on a host corresponding to the unres master node that is not offline includes:
optionally selecting a host corresponding to the Redis main node which is not offline on the host corresponding to the Redis main node which is not offline;
and configuring the Redis master node of the Redis standby node according to the determined requirement on the host corresponding to the selected non-offline Redis master node.
In a possible implementation manner, before replacing the offline Redis master node with the Redis bypass node as the Redis master node, the method further includes:
deleting the offline Redis main node in the Redis cluster, and releasing a slot position occupied by the offline Redis main node;
adding the Redis bypass node into the Redis cluster;
and allocating the released slot position occupied by the offline Redis main node to the Redis side-standby node.
In one possible implementation manner, if it is determined that the current state information of the new Redis cluster is recovered by the offline Redis master node, the method further includes:
switching the Redis standby node from the Redis master node to a Redis slave node, and switching the offline Redis master node to a Redis master node;
deleting the Redis standby node in the new Redis cluster, and closing the Redis standby node;
it is determined whether the current state of the new Redis cluster is restored to the state before the offline.
In a possible implementation manner, the deleting the Redis bypass node in the new Redis cluster and closing the Redis bypass node includes:
deleting the Redis standby node in the Redis cluster, closing the Redis standby node, and releasing the slot position occupied by the Redis standby node;
adding the offline Redis master node into the new Redis cluster;
and allocating the released slot position occupied by the Redis bypass node to the offline Redis main node.
In a second aspect, a Redis cluster processing apparatus is provided, where a Redis cluster includes at least 3 Redis master nodes, each Redis master node is deployed on a host, and the apparatus includes:
a determining module, configured to determine current state information of the Redis cluster;
an obtaining module, configured to obtain a host corresponding to a Redis master node that is not offline, if the determining module determines that the current state information of the Redis cluster is that no less than half of the Redis master nodes in at least 3 Redis master nodes are offline;
a configuration module, configured to configure a Redis standby node on a host corresponding to the non-offline Redis main node, where the Redis standby node is a replacement node corresponding to the offline Redis main node;
the replacing module is used for replacing the offline Redis main node with the Redis bypass node to serve as the Redis main node;
and the determining module is further used for determining the current state information of the new Redis cluster.
In one possible implementation, the method further includes:
the acquiring module is further configured to acquire the survival conditions of the offline Redis master node and the Redis slave node corresponding to the offline Redis master node;
and the first processing module is used for determining the Redis master node needing to be configured with the Redis side standby node according to the survival conditions of the offline Redis master node and the Redis slave node corresponding to the offline Redis master node.
In a possible implementation manner, the configuration module is configured to optionally select a host corresponding to the unres master node that is not offline on the host corresponding to the unres master node that is not offline; and configuring the Redis master node of the Redis standby node according to the determined requirement on the host corresponding to the selected non-offline Redis master node.
In one possible implementation, the method further includes:
the second processing module is used for deleting the offline Redis main node in the Redis cluster and releasing the slot position occupied by the offline Redis main node; adding the Redis bypass node into the Redis cluster; and allocating the released slot position occupied by the offline Redis main node to the Redis side-standby node.
In a possible implementation manner, if the determining module determines that the current state information of the Redis cluster is recovered by the offline Redis master node, the method further includes:
the third processing module is used for switching the Redis bypass node from the Redis master node to a Redis slave node, and switching the offline Redis master node to the Redis master node; deleting the Redis standby node in the new Redis cluster, and closing the Redis standby node;
and the determining module is used for determining whether the current state of the new Redis cluster is restored to the state before the offline.
In a possible implementation manner, the third processing module is specifically configured to delete the Redis bypass node in a new Redis cluster, close the Redis bypass node, and release a slot occupied by the Redis bypass node; adding the offline Redis master node into a new Redis cluster; and allocating the released slot position occupied by the Redis bypass node to the offline Redis main node.
In a third aspect, an electronic device is provided, including: a processor and a memory;
the memory for storing a computer program;
the processor is used for executing the Redis cluster processing method by calling the computer program.
In a fourth aspect, a computer-readable storage medium is provided for storing a computer program which, when run on a computer, enables the computer to perform the above-mentioned Redis cluster processing method.
By means of the technical scheme, the technical scheme provided by the application at least has the following advantages:
according to the method and the device, when the hosts corresponding to more than half of Redis main nodes are down, the functions of the Redis cluster are recovered to be normal, and waste of system resources is avoided by introducing the Redis side standby nodes which are automatically generated in a triggering mode; and the Redis side standby node is only generated in the host where the Redis cluster is located, other host equipment or machines are not required to be introduced, and the increase of maintenance cost is avoided.
Drawings
Various other advantages and benefits will become apparent to those of ordinary skill in the art upon reading the following detailed description of the preferred embodiments. The drawings are only for purposes of illustrating the preferred embodiments and are not to be construed as limiting the embodiments of the invention. Also, like reference numerals are used to refer to like parts throughout the drawings. In the drawings:
fig. 1 is a schematic flow diagram of a Redis cluster processing method provided in the present application;
fig. 2 is a schematic processing flow diagram of a possible implementation manner of the Redis cluster processing method provided in the present application;
fig. 3 is a schematic structural diagram of a Redis cluster processing apparatus provided in the present application;
fig. 4 is a schematic structural diagram of an electronic device of the Redis cluster processing method provided in the present application.
Detailed Description
The present application provides a method and an apparatus for Redis cluster processing, an electronic device, and a computer-readable storage medium, and the following describes in detail embodiments of the present application with reference to the accompanying drawings.
Reference will now be made in detail to embodiments of the present application, examples of which are illustrated in the accompanying drawings, wherein like or similar reference numerals refer to the same or similar elements or elements having the same or similar function throughout. The embodiments described below with reference to the drawings are exemplary only for the purpose of explaining the present application and are not to be construed as limiting the present application.
As used herein, the singular forms "a", "an", "the" and "the" are intended to include the plural forms as well, unless the context clearly indicates otherwise. It will be further understood that the terms "comprises" and/or "comprising," when used in this specification, specify the presence of stated features, integers, steps, operations, elements, and/or components, but do not preclude the presence or addition of one or more other features, integers, steps, operations, elements, components, and/or groups thereof. It will be understood that when an element is referred to as being "connected" or "coupled" to another element, it can be directly connected or coupled to the other element or intervening elements may also be present. Further, "connected" or "coupled" as used herein may include wirelessly connected or wirelessly coupled. As used herein, the term "and/or" includes all or any element and all combinations of one or more of the associated listed items.
It will be understood by those within the art that, unless otherwise defined, all terms (including technical and scientific terms) used herein have the same meaning as commonly understood by one of ordinary skill in the art to which this application belongs. It will be further understood that terms, such as those defined in commonly used dictionaries, should be interpreted as having a meaning that is consistent with their meaning in the context of the prior art and will not be interpreted in an idealized or overly formal sense unless expressly so defined herein.
To make the objects, technical solutions and advantages of the present application more clear, embodiments of the present application will be described in further detail below with reference to the accompanying drawings. The following several specific embodiments may be combined with each other, and details of the same or similar concepts or processes may not be repeated in some embodiments.
As shown in fig. 1, a schematic flow diagram of a Redis cluster processing method provided in the present application is provided, where a Redis cluster includes at least 3 Redis master nodes, and each Redis master node is deployed on one host, and the method includes the following steps:
step S101, determining the current state information of the Redis cluster;
if the current state information of the Redis cluster is determined to be that no less than half Redis master nodes in at least 3 Redis master nodes are offline, turning to step S102;
step S102, obtaining a host corresponding to a Redis main node which is not offline;
step S103, configuring a Redis side standby node on a host corresponding to a Redis main node which is not offline;
the Redis standby node is a replacement node corresponding to the offline Redis main node;
step S104, replacing the offline Redis main node with the Redis bypass node as the Redis main node;
step S105, determining current state information of the new Redis cluster.
According to the method and the device, when the hosts corresponding to more than half of Redis main nodes are down, the functions of the Redis cluster are recovered to be normal, and waste of system resources is avoided by introducing the Redis side standby nodes which are automatically generated in a triggering mode; and the Redis side standby node is only generated in the host where the Redis cluster is located, other host equipment or machines are not required to be introduced, and the increase of maintenance cost is avoided.
Based on the technical solution provided by the present application, the following explains the technical solution in detail, as shown in fig. 2, a specific processing flow chart of one possible implementation manner of the Redis cluster processing method provided by the present application is provided.
Before the explanation of the technical solution of the present application, the Redis cluster referred to therein is explained appropriately.
Redis is an open source product that stores data structures in memory using a key-value type. Redis is a NoSQL database which is popular in the current Internet, can greatly improve the system performance after being deployed, and is generally used as a database, a cache and a message browser.
Redis itself may provide a highly available solution, mainly including sentinel and trunked modes. For trunked mode, there are several advantages over sentinel mode, including:
1. the cluster mode can be provided with a plurality of main nodes, and the data volume can be dispersed to each main node for processing; the sentinel model can only support one main node, and all data volume is centralized to be processed by the main node.
2. The method is characterized in that a central architecture is not provided, when nodes are in internal communication, the nodes are communicated with each other through a cluster _ bus _ port, all the nodes are kept consistent through a Raft algorithm, and the master node and the slave node can be switched through a node voting mechanism of the nodes; in the sentinel mode, the node state needs to be judged and switched through a sentinel (an additional module), so that the high availability of the sentinel needs to be considered, and the resource consumption of the system can be increased due to the introduction of a plurality of sentinels.
Therefore, the present application mainly makes design improvement for a cluster mode, and in an existing embodiment, a Redis cluster includes five masters and ten slaves (i.e., 5 Redis masters and 10 Redis slaves).
The hosts 1-5 are respectively five hosts, which can be physical machines or virtual machines. The Redis cluster has five groups of nodes, namely, the Redis cluster comprises 5 Redis master nodes and 2 Redis slave nodes corresponding to the Redis master nodes, and each Redis master node is required to be allocated to different hosts in order to guarantee the average use of resources and high availability requirements. Since the Redis cluster uses slots (16384 slots total) for data allocation, all slots are allocated equally on 5 master nodes. Among them, a Redis master node 1, a Redis slave node 4, and a Redis slave node 5 are allocated to the host 1, a Redis master node 2, a Redis slave node 1, and a Redis slave node 5 are allocated to the host 2, a Redis master node 3, a Redis slave node 1, and a Redis slave node 2 are allocated to the host 3, a Redis master node 4, a Redis slave node 3, and a Redis slave node 4 are allocated to the host 4, and a Redis master node 5, a Redis slave node 3, and a Redis slave node 4 are allocated to the host 5. In the embodiment, the higher the number of Redis slave nodes is, the higher the availability degree is, but in consideration of resource consumption, the number of Redis slave nodes following a certain Redis master node generally does not exceed 2. After a certain Redis master node is offline (downtime), voting is carried out through other Redis master nodes through a Raft algorithm, a certain Redis slave node is selected from the Redis slave nodes, and the Redis slave node is promoted to the Redis master node, so that the high availability of the cluster is ensured.
However, although the cluster mode itself provides high availability, the node offline and the master-slave node switching can be judged through the decentralized Redis master node voting mechanism. However, the voting mechanism has a premise that the number of the main nodes which can ensure online survival must exceed more than half of the number of all the main nodes, and the voting mechanism can be effectively carried out. Therefore, once most Redis nodes are down, for example, in the above embodiment, if three hosts are down at the same time, two problems may be caused, so that the cluster state is abnormal:
1. for any group of nodes of the Redis cluster, if the Redis master node and the Redis slave node are offline, the Redis node cannot be recovered;
2. on a living host, the corresponding Redis master node can continue to provide service to the outside, but for other three groups of nodes of the Redis cluster, even if the Redis slave nodes are not down and offline, voting cannot be performed because the number of the Redis master nodes which are not down is less than half of the number of all the Redis master nodes, and therefore master-slave switching of the nodes cannot be performed.
In order to solve the problem of the cluster mode defect, under the condition that most Redis main nodes are down at the same time, the cluster mode can also be kept in a normal state, by introducing a mechanism of a side standby node, the side standby node automatically judges the down condition and the offline condition of the Redis main nodes, generates the side standby node on a survival host in a triggering mode for configuration, starts up the side standby node as required, automatically repairs the Redis cluster, and restores the Redis cluster to the normal state.
For the present application, in one possible implementation, the processing of step S101 described above specifically includes the processing of step S201 to step S202 described below.
Step S201, determining the current state information of the Redis cluster.
In a possible implementation manner, for a plurality of hosts with Redis nodes, the operating conditions of the hosts are obtained in time, whether a downtime condition occurs is determined, and if the hosts are crashed, the corresponding Redis host nodes are in an offline state. When it is determined that not less than half of the Redis master nodes in the at least 3 Redis master nodes are offline, turning to step S202; when it is determined that less than half of the 3 Redis master nodes are offline, the existing voting mechanism processing manner as set forth above is adopted, and will not be explained in detail here.
For the present application, in one possible implementation, the aforementioned processing of step S102 specifically includes the processing of step S202 described below.
Step S202, a host corresponding to the Redis main node which is not offline is obtained.
In a possible implementation manner, when it is determined that not less than half of the Redis master nodes in at least 3 Redis master nodes are offline, the hosts corresponding to the undis master nodes that are not offline, and the survival conditions of the offline Redis master nodes and the Redis slave nodes corresponding to the offline Redis master nodes are obtained, so that the Redis master nodes that need to configure the Redis standby nodes can be determined according to the information. The configured Redis side standby node is a replacement node corresponding to the offline Redis main node, so that the corresponding configuration information is the same as that of the Redis main node.
For the present application, in one possible implementation, the processing of step S103 specifically includes the processing of step S203 to step S204 described below.
Step S203, selecting a host corresponding to the Redis main node which is not offline.
In a possible implementation manner, a Redis master node of a Redis standby node is configured according to the determined requirement, and a host corresponding to an available unres master node that is not offline is determined by combining the obtained host corresponding to the unres master node that is not offline and survival conditions of the offline Redis master node and a Redis slave node corresponding to the offline Redis master node. In a specific embodiment, if there are 5 hosts, the offline Redis master nodes are the Redis master nodes 1, 2, and 3 (i.e., the corresponding hosts 1, 2, and 3 are down), the host 4 and the host 5 are not down hosts, and there is no Redis slave node corresponding to the Redis master node 1 on each host, then one of the slave hosts 4 and the master host 5 may be selected.
And step S204, configuring a Redis bypass node on a host corresponding to the selected non-offline Redis main node.
In a possible implementation manner, after the host corresponding to the unres master node which is not offline is selected, the reds master node which needs to configure the reds standby node configures the reds standby node which needs to configure on the host corresponding to the selected unres master node which is not offline according to the determined requirement.
In a possible implementation manner, when a Redis standby node is configured to a host corresponding to a Redis master node that is not offline, a nodes configuration file and a dump data file corresponding to a local Redis standby node that are stored on the host corresponding to the Redis master node that is not offline need to be deleted.
For the present application, in one possible implementation, the aforementioned processing of step S104 specifically includes the processing of step S205 described below.
And step S205, replacing the offline Redis master node with the Redis bypass node as the Redis master node.
In a possible implementation manner, after a Redis side-by node is configured to a host corresponding to a selected non-offline Redis main node, deleting the offline Redis main node in an original Redis cluster, releasing a slot position occupied by the offline Redis main node, and then adding the Redis side-by node to the Redis cluster to obtain a new Redis cluster; and then the slot position occupied by the released offline Redis main node is allocated to the Redis standby node, and then the Redis standby node is forcibly switched to the Redis main node to replace the offline Redis main node.
For the present application, in one possible implementation, the aforementioned processing of step S105 specifically includes the processing of step S206 described below.
Step S206, determining the current state information of the new Redis cluster.
In a possible implementation manner, after the Redis master node is replaced by the Redis bypass node as a new Redis master node on a host corresponding to the selected non-offline Redis master node, current state information of the new Redis cluster needs to be determined again. If the current state information is determined to be the recovery of the offline Redis master node, go to step S207; if it is determined that the current state information is that the offline Redis master node is not recovered, the process goes to step S203, and a host corresponding to another offline Redis master node is selected to continue processing.
And step S207, replacing the Redis bypass node with the offline Redis main node to serve as the Redis main node.
In a possible implementation manner, after determining that the current state information is the recovery of an offline Redis master node, switching a Redis bypass node from the Redis master node to a Redis slave node, and switching the offline Redis master node to the Redis master node; deleting Redis standby nodes in the new Redis cluster, closing the Redis standby nodes, and releasing slot positions occupied by the Redis standby nodes; adding an offline Redis master node into a new Redis cluster; and allocating the slot positions occupied by the released Redis standby nodes to the offline Redis main nodes, closing the Redis standby nodes, and determining whether the current state of the new Redis cluster is restored to the state before the offline again.
According to the method and the device, when the hosts corresponding to more than half of Redis main nodes are down, the functions of the Redis cluster are recovered to be normal, and waste of system resources is avoided by introducing the Redis side standby nodes which are automatically generated in a triggering mode; and the Redis side standby node is only generated in the host where the Redis cluster is located, other host equipment or machines are not required to be introduced, and the increase of maintenance cost is avoided.
Based on the technical solution of the Redis cluster processing method provided by the present application, the present application correspondingly provides a schematic structural diagram of a Redis cluster processing apparatus, as shown in fig. 3, in a Redis cluster processing apparatus 30 of the present application, a Redis cluster includes at least 3 Redis master nodes, each Redis master node is deployed on a host, and the apparatus may include:
a determining module 31, configured to determine current state information of a Redis cluster;
the obtaining module 32 is configured to obtain a host corresponding to a Redis master node that is not offline if the determining module determines that the current state information of the Redis cluster is that no less than half of the Redis master nodes in at least 3 Redis master nodes are offline;
a configuration module 33, configured to configure a Redis standby node on a host corresponding to a Redis master node that is not offline, where the Redis standby node is a replacement node corresponding to the offline Redis master node;
a replacement module 34, configured to replace an offline Redis master node with a Redis bypass node as a Redis master node;
the determining module 31 is further configured to determine current state information of the new Redis cluster.
In one possible implementation, the method further includes:
the obtaining module 32 is further configured to obtain survival conditions of the offline Redis master node and the Redis slave node corresponding to the offline Redis master node;
the first processing module 35 is configured to determine, according to the survival conditions of the offline Redis master node and the Redis slave node corresponding to the offline Redis master node, a Redis master node that needs to configure a Redis standby node.
In one possible implementation, the configuration module 33 is configured to select a host corresponding to a Redis master node that is not offline on a host corresponding to the Redis master node that is not offline; and configuring the Redis master node of the Redis standby node according to the determined requirement on the host corresponding to the selected non-offline Redis master node.
In one possible implementation, the method further includes:
the second processing module 36 is configured to delete an offline Redis master node in the Redis cluster, and release a slot occupied by the offline Redis master node; adding a Redis side standby node into a Redis cluster; and allocating the slot position occupied by the released offline Redis main node to a Redis side standby node.
In a possible implementation manner, if the determining module 31 determines that the current state information of the Redis cluster is recovered by the offline Redis master node, the method further includes:
a third processing module 37, configured to switch a Redis standby node from a Redis master node to a Redis slave node, and switch an offline Redis master node to a Redis master node; deleting Redis standby nodes in the new Redis cluster, and closing the Redis standby nodes;
and a determining module 31, configured to determine whether the current state of the new Redis cluster is restored to the state before the offline.
In a possible implementation manner, the third processing module 37 is specifically configured to delete a Redis bypass node in a new Redis cluster, close the Redis bypass node, and release a slot occupied by the Redis bypass node; adding an offline Redis master node into a new Redis cluster; and allocating the slot positions occupied by the released Redis standby nodes to offline Redis main nodes.
According to the method and the device, when the hosts corresponding to more than half of Redis main nodes are down, the functions of the Redis cluster are recovered to be normal, and waste of system resources is avoided by introducing the Redis side standby nodes which are automatically generated in a triggering mode; and the Redis side standby node is only generated in the host where the Redis cluster is located, other host equipment or machines are not required to be introduced, and the increase of maintenance cost is avoided.
Referring now to fig. 4, a block diagram of an electronic device (e.g., the terminal device of fig. 1) 400 suitable for implementing embodiments of the present application is shown. The terminal device in the embodiments of the present application may include, but is not limited to, a mobile terminal such as a mobile phone, a notebook computer, a digital broadcast receiver, a PDA (personal digital assistant), a PAD (tablet computer), a PMP (portable multimedia player), a vehicle terminal (e.g., a car navigation terminal), and the like, and a fixed terminal such as a digital TV, a desktop computer, and the like. The electronic device shown in fig. 4 is only an example, and should not bring any limitation to the functions and the scope of use of the embodiments of the present application.
As shown in fig. 4, electronic device 400 may include a processing device (e.g., central processing unit, graphics processor, etc.) 401 that may perform various appropriate actions and processes in accordance with a program stored in a Read Only Memory (ROM)402 or a program loaded from a storage device 408 into a Random Access Memory (RAM) 403. In the RAM 403, various programs and data necessary for the operation of the electronic apparatus 400 are also stored. The processing device 401, the ROM402, and the RAM 403 are connected to each other via a bus 404. An input/output (I/O) interface 405 is also connected to bus 404.
Generally, the following devices may be connected to the I/O interface 405: input devices 406 including, for example, a touch screen, touch pad, keyboard, mouse, camera, microphone, accelerometer, gyroscope, etc.; an output device 407 including, for example, a Liquid Crystal Display (LCD), a speaker, a vibrator, and the like; storage 408 including, for example, tape, hard disk, etc.; and a communication device 409. The communication means 409 may allow the electronic device 400 to communicate wirelessly or by wire with other devices to exchange data. While fig. 4 illustrates an electronic device 400 having various means, it is to be understood that not all illustrated means are required to be implemented or provided. More or fewer devices may alternatively be implemented or provided.
In particular, according to embodiments of the application, the processes described above with reference to the flow diagrams may be implemented as computer software programs. For example, embodiments of the present application include a computer program product comprising a computer program embodied on a computer readable medium, the computer program comprising program code for performing the method illustrated by the flow chart. In such an embodiment, the computer program may be downloaded and installed from a network via the communication device 409, or from the storage device 408, or from the ROM 402. The computer program, when executed by the processing device 401, performs the above-described functions defined in the methods of the embodiments of the present application.
It should be noted that the computer readable medium mentioned above in the present application may be a computer readable signal medium or a computer readable storage medium or any combination of the two. A computer readable storage medium may be, for example, but not limited to, an electronic, magnetic, optical, electromagnetic, infrared, or semiconductor system, apparatus, or device, or any combination of the foregoing. More specific examples of the computer readable storage medium may include, but are not limited to: an electrical connection having one or more wires, a portable computer diskette, a hard disk, a Random Access Memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disc read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the foregoing. In the present application, a computer readable storage medium may be any tangible medium that can contain, or store a program for use by or in connection with an instruction execution system, apparatus, or device. In this application, however, a computer readable signal medium may include a propagated data signal with computer readable program code embodied therein, for example, in baseband or as part of a carrier wave. Such a propagated data signal may take many forms, including, but not limited to, electro-magnetic, optical, or any suitable combination thereof. A computer readable signal medium may also be any computer readable medium that is not a computer readable storage medium and that can communicate, propagate, or transport a program for use by or in connection with an instruction execution system, apparatus, or device. Program code embodied on a computer readable medium may be transmitted using any appropriate medium, including but not limited to: electrical wires, optical cables, RF (radio frequency), etc., or any suitable combination of the foregoing.
The computer readable medium may be embodied in the electronic device; or may exist separately without being assembled into the electronic device.
The computer readable medium carries one or more programs which, when executed by the electronic device, cause the electronic device to: acquiring at least two internet protocol addresses; sending a node evaluation request comprising the at least two internet protocol addresses to node evaluation equipment, wherein the node evaluation equipment selects the internet protocol addresses from the at least two internet protocol addresses and returns the internet protocol addresses; receiving an internet protocol address returned by the node evaluation equipment; wherein the obtained internet protocol address indicates an edge node in the content distribution network.
Alternatively, the computer readable medium carries one or more programs which, when executed by the electronic device, cause the electronic device to: receiving a node evaluation request comprising at least two internet protocol addresses; selecting an internet protocol address from the at least two internet protocol addresses; returning the selected internet protocol address; wherein the received internet protocol address indicates an edge node in the content distribution network.
Computer program code for carrying out operations for aspects of the present application may be written in any combination of one or more programming languages, including an object oriented programming language such as Java, Smalltalk, C + + or the like and conventional procedural programming languages, such as the "C" programming language or similar programming languages. The program code may execute entirely on the user's computer, partly on the user's computer, as a stand-alone software package, partly on the user's computer and partly on a remote computer or entirely on the remote computer or backend server. In the case of a remote computer, the remote computer may be connected to the user's computer through any type of network, including a Local Area Network (LAN) or a Wide Area Network (WAN), or the connection may be made to an external computer (for example, through the Internet using an Internet service provider).
The flowchart and block diagrams in the figures illustrate the architecture, functionality, and operation of possible implementations of systems, methods and computer program products according to various embodiments of the present application. In this regard, each block in the flowchart or block diagrams may represent a module, segment, or portion of code, which comprises one or more executable instructions for implementing the specified logical function(s). It should also be noted that, in some alternative implementations, the functions noted in the block may occur out of the order noted in the figures. For example, two blocks shown in succession may, in fact, be executed substantially concurrently, or the blocks may sometimes be executed in the reverse order, depending upon the functionality involved. It will also be noted that each block of the block diagrams and/or flowchart illustration, and combinations of blocks in the block diagrams and/or flowchart illustration, can be implemented by special purpose hardware-based systems which perform the specified functions or acts, or combinations of special purpose hardware and computer instructions.
The units described in the embodiments of the present application may be implemented by software or hardware. Where the name of a unit does not in some cases constitute a limitation of the unit itself, for example, the first retrieving unit may also be described as a "unit for retrieving at least two internet protocol addresses".
The above description is only a preferred embodiment of the application and is illustrative of the principles of the technology employed. It will be appreciated by those skilled in the art that the scope of the disclosure herein is not limited to the particular combination of features described above, but also encompasses other arrangements formed by any combination of the above features or their equivalents without departing from the spirit of the disclosure. For example, the above features may be replaced with (but not limited to) features having similar functions disclosed in the present application.
The electronic device provided in the present application is applicable to any embodiment of the foregoing Redis cluster processing method, and is not described herein again.
According to the method and the device, when the hosts corresponding to more than half of Redis main nodes are down, the functions of the Redis cluster are recovered to be normal, and waste of system resources is avoided by introducing the Redis side standby nodes which are automatically generated in a triggering mode; and the Redis side standby node is only generated in the host where the Redis cluster is located, other host equipment or machines are not required to be introduced, and the increase of maintenance cost is avoided.
The present application provides a computer-readable storage medium storing a computer program that causes a computer to execute a Redis cluster processing method shown in the above-described embodiments.
The computer-readable storage medium provided in the present application is applicable to any embodiment of the foregoing Redis cluster processing method, and is not described herein again.
According to the method and the device, when the hosts corresponding to more than half of Redis main nodes are down, the functions of the Redis cluster are recovered to be normal, and waste of system resources is avoided by introducing the Redis side standby nodes which are automatically generated in a triggering mode; and the Redis side standby node is only generated in the host where the Redis cluster is located, other host equipment or machines are not required to be introduced, and the increase of maintenance cost is avoided.
It will be understood by those within the art that each block of the block diagrams and/or flowchart illustrations, and combinations of blocks in the block diagrams and/or flowchart illustrations, can be implemented by computer program instructions. Those skilled in the art will appreciate that the computer program instructions may be implemented by a processor of a general purpose computer, special purpose computer, or other programmable data processing apparatus to produce a machine, such that the instructions, which execute via the processor of the computer or other programmable data processing apparatus, implement the aspects specified in the block or blocks of the block diagrams and/or flowchart illustrations disclosed herein.
The modules of the device can be integrated into a whole or can be separately deployed. The modules can be combined into one module, and can also be further split into a plurality of sub-modules.
Those skilled in the art will appreciate that the drawings are merely schematic representations of one preferred embodiment and that the blocks or flow diagrams in the drawings are not necessarily required to practice the present application.
Those skilled in the art will appreciate that the modules in the devices in the embodiments may be distributed in the devices in the embodiments according to the description of the embodiments, and may be correspondingly changed in one or more devices different from the embodiments. The modules of the above embodiments may be combined into one module, or further split into multiple sub-modules.
The above application serial numbers are for descriptive purposes only and do not represent the merits of the embodiments.
The disclosure of the present application is only a few specific embodiments, but the present application is not limited to these, and any variations that can be made by those skilled in the art are intended to fall within the scope of the present application.
Claims (9)
1. A Redis cluster processing method is characterized in that a Redis cluster comprises at least 3 Redis master nodes, each Redis master node is deployed on a host, and the method comprises the following steps:
determining the current state information of the Redis cluster;
if the current state information of the Redis cluster is determined to be that no less than half Redis main nodes in at least 3 Redis main nodes are offline, acquiring a host corresponding to the Redis main nodes which are not offline;
configuring a Redis standby node on a host corresponding to the Redis main node which is not offline, wherein the Redis standby node is a replacement node corresponding to the offline Redis main node;
replacing an offline Redis main node by the Redis bypass node to serve as a Redis main node;
current state information of the new Redis cluster is determined.
2. The method of claim 1, wherein prior to configuring a Redis bypass node on a host corresponding to the Redis master node that is not offline, further comprising:
acquiring survival conditions of an offline Redis master node and a Redis slave node corresponding to the offline Redis master node;
and determining the Redis master node needing to be configured with the Redis side standby node according to the survival conditions of the offline Redis master node and the Redis slave node corresponding to the offline Redis master node.
3. The method of claim 2, wherein configuring a Redis bypass node on a host corresponding to the Redis master node that is not offline comprises:
optionally selecting a host corresponding to the Redis main node which is not offline on the host corresponding to the Redis main node which is not offline;
and configuring the Redis master node of the Redis standby node according to the determined requirement on the host corresponding to the selected non-offline Redis master node.
4. The method of claim 1, wherein prior to replacing the Redis bypass node with the offline Redis master node as a Redis master node, further comprising:
deleting the offline Redis main node in the Redis cluster, and releasing a slot position occupied by the offline Redis main node;
adding the Redis bypass node into the Redis cluster;
and allocating the released slot position occupied by the offline Redis main node to the Redis side-standby node.
5. The method according to any of claims 1-4, wherein if it is determined that the current state information of the new Redis cluster is recovered for the offline Redis master node, the method further comprises:
switching the Redis standby node from the Redis master node to a Redis slave node, and switching the offline Redis master node to a Redis master node;
deleting the Redis standby node in the new Redis cluster, and closing the Redis standby node;
it is determined whether the current state of the new Redis cluster is restored to the state before the offline.
6. The method of claim 5, wherein the deleting the Redis bypass node and shutting down the Redis bypass node in the new Redis cluster comprises:
deleting the Redis standby node in the new Redis cluster, closing the Redis standby node, and releasing the slot position occupied by the Redis standby node;
adding the offline Redis master node into the new Redis cluster;
and allocating the released slot position occupied by the Redis bypass node to the offline Redis main node.
7. A Redis cluster processing device, wherein a Redis cluster includes at least 3 Redis master nodes, each Redis master node is deployed on a host, comprising:
a determining module, configured to determine current state information of the Redis cluster;
an obtaining module, configured to obtain a host corresponding to a Redis master node that is not offline, if the determining module determines that the current state information of the Redis cluster is that no less than half of the Redis master nodes in at least 3 Redis master nodes are offline;
a configuration module, configured to configure a Redis standby node on a host corresponding to the non-offline Redis main node, where the Redis standby node is a replacement node corresponding to the offline Redis main node;
the replacing module is used for replacing the offline Redis main node with the Redis bypass node to serve as the Redis main node;
the determining module is further configured to determine current state information of the new Redis cluster.
8. An electronic device, comprising: a processor and a memory;
the memory for storing a computer program;
the processor is configured to execute the Redis cluster processing method according to any one of the above claims 1 to 6 by calling the computer program.
9. A computer-readable storage medium, characterized in that the computer storage medium is for storing a computer program which, when run on a computer, causes the computer to perform the Redis cluster processing method of any of the above claims 1 to 6.
Priority Applications (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN202011321574.0A CN112363815B (en) | 2020-11-23 | 2020-11-23 | Redis cluster processing method and device, electronic equipment and computer readable storage medium |
Applications Claiming Priority (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN202011321574.0A CN112363815B (en) | 2020-11-23 | 2020-11-23 | Redis cluster processing method and device, electronic equipment and computer readable storage medium |
Publications (2)
Publication Number | Publication Date |
---|---|
CN112363815A true CN112363815A (en) | 2021-02-12 |
CN112363815B CN112363815B (en) | 2024-04-30 |
Family
ID=74534293
Family Applications (1)
Application Number | Title | Priority Date | Filing Date |
---|---|---|---|
CN202011321574.0A Active CN112363815B (en) | 2020-11-23 | 2020-11-23 | Redis cluster processing method and device, electronic equipment and computer readable storage medium |
Country Status (1)
Country | Link |
---|---|
CN (1) | CN112363815B (en) |
Cited By (2)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN113703866A (en) * | 2021-08-25 | 2021-11-26 | 上海哔哩哔哩科技有限公司 | Configuration center information synchronization method and system |
CN114844799A (en) * | 2022-05-27 | 2022-08-02 | 深信服科技股份有限公司 | Cluster management method and device, host equipment and readable storage medium |
Citations (3)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN105337780A (en) * | 2015-12-01 | 2016-02-17 | 迈普通信技术股份有限公司 | Server node configuration method and physical nodes |
US20170220431A1 (en) * | 2016-02-01 | 2017-08-03 | International Business Machines Corporation | Failover of a database in a high-availability cluster |
CN108616566A (en) * | 2018-03-14 | 2018-10-02 | 华为技术有限公司 | Raft distributed systems select main method, relevant device and system |
-
2020
- 2020-11-23 CN CN202011321574.0A patent/CN112363815B/en active Active
Patent Citations (3)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN105337780A (en) * | 2015-12-01 | 2016-02-17 | 迈普通信技术股份有限公司 | Server node configuration method and physical nodes |
US20170220431A1 (en) * | 2016-02-01 | 2017-08-03 | International Business Machines Corporation | Failover of a database in a high-availability cluster |
CN108616566A (en) * | 2018-03-14 | 2018-10-02 | 华为技术有限公司 | Raft distributed systems select main method, relevant device and system |
Cited By (4)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN113703866A (en) * | 2021-08-25 | 2021-11-26 | 上海哔哩哔哩科技有限公司 | Configuration center information synchronization method and system |
CN113703866B (en) * | 2021-08-25 | 2024-04-26 | 上海哔哩哔哩科技有限公司 | Configuration center information synchronization method and system |
CN114844799A (en) * | 2022-05-27 | 2022-08-02 | 深信服科技股份有限公司 | Cluster management method and device, host equipment and readable storage medium |
CN114844799B (en) * | 2022-05-27 | 2024-10-11 | 深信服科技股份有限公司 | Cluster management method and device, host equipment and readable storage medium |
Also Published As
Publication number | Publication date |
---|---|
CN112363815B (en) | 2024-04-30 |
Similar Documents
Publication | Publication Date | Title |
---|---|---|
JP6325001B2 (en) | Method and system using recursive event listeners in nodes of hierarchical data structures | |
CN112291082A (en) | Computer room disaster recovery processing method, terminal and storage medium | |
CN112363815B (en) | Redis cluster processing method and device, electronic equipment and computer readable storage medium | |
CN112035529A (en) | Caching method and device, electronic equipment and computer readable storage medium | |
CN113835992A (en) | Memory leak processing method and device, electronic equipment and computer storage medium | |
CN110554918B (en) | Current limiting method, current limiting device, electronic equipment and computer readable storage medium | |
CN112181724B (en) | Big data disaster recovery method and device and electronic equipment | |
CN114500549A (en) | Method, apparatus, and medium to deploy k8s hosting cluster for users in public cloud | |
CN114070889B (en) | Configuration method, traffic forwarding device, storage medium, and program product | |
CN113127430A (en) | Mirror image information processing method and device, computer readable medium and electronic equipment | |
CN108959285B (en) | Database main key acquisition method and device, storage medium and electronic equipment | |
WO2023273564A1 (en) | Virtual machine memory management method and apparatus, storage medium, and electronic device | |
CN112463514A (en) | Monitoring method and device for distributed cache cluster | |
CN111538717B (en) | Data processing method, device, electronic equipment and computer readable medium | |
CN111083192B (en) | Data consensus method and device and electronic equipment | |
CN113934437A (en) | Method and system for installing application in cloud mobile phone and client cloud mobile phone | |
CN114296961B (en) | Network service rapid switching method and related device | |
CN111552469A (en) | File processing method and device in application program engineering and electronic equipment | |
CN112506713B (en) | Multistage disaster recovery system and method | |
US12013795B1 (en) | System and method for managing ports of data processing systems and attached devices | |
US20240256672A1 (en) | System and method for managing compatibility of modules of data processing systems | |
CN118069740A (en) | Method and system for synchronizing elastomer search data subscription type monitoring | |
CN114201465A (en) | Data integration method, system, computer device and storage medium | |
CN118101434A (en) | Management system active-standby switching method and system based on performance and fault prediction model | |
CN118394761A (en) | Data processing method and device based on object storage cluster and electronic equipment |
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 |