Disclosure of Invention
In view of this, an object of the embodiments of the present invention is to provide a method and a device for testing a Redis component, which can verify the high availability of a Redis component cluster of an Insight platform, improve testing efficiency, save human resources, and provide guarantee and basis for a Redis high availability cluster function test of the cluster.
In view of the above object, an aspect of an embodiment of the present invention provides a method for testing a Redis component, including the steps of:
creating a Redis cluster;
deleting the process of a first main node in the Redis cluster;
detecting the state of a first slave node corresponding to the first master node;
responding to the change of the first slave node into a new first master node, and starting the process of the original first master node;
and in response to the original first master node becoming a new first slave node, judging that the availability of the Redis component is stable.
According to one embodiment of the invention, creating a Redis cluster comprises: a three-master three-slave Redis cluster is created in a cloud sea Insight platform.
According to one embodiment of the present invention, the deleting the process of the first master node in the Redis cluster comprises: and acquiring the process of the Redis server of the first main node, and killing the process through a kill-9 command.
According to one embodiment of the present invention, detecting a state of a first slave node corresponding to a first master node comprises: the set k1 HelloWorld cluster command is used to verify that the Redis cluster function is normal.
According to an embodiment of the present invention, the process of starting the original primary master node includes: and after finding the corresponding conf configuration file under the installation path of the original first main node, starting the original first main node.
In another aspect of the embodiments of the present invention, there is also provided a device for testing a Redis component, where the device includes:
at least one processor; and
a memory storing program code executable by the processor, the program code when executed by the processor performing the steps of:
creating a Redis cluster;
deleting the process of a first main node in the Redis cluster;
detecting the state of a first slave node corresponding to the first master node;
responding to the change of the first slave node into a new first master node, and starting the process of the original first master node;
and in response to the original first master node becoming a new first slave node, judging that the availability of the Redis component is stable.
According to one embodiment of the invention, creating a Redis cluster comprises: a three-master three-slave Redis cluster is created in a cloud sea Insight platform.
According to one embodiment of the present invention, the deleting the process of the first master node in the Redis cluster comprises: and acquiring the process of the Redis server of the first main node, and killing the process through a kill-9 command.
According to one embodiment of the present invention, detecting a state of a first slave node corresponding to a first master node comprises: the set k1 HelloWorld cluster command is used to verify that the Redis cluster function is normal.
According to an embodiment of the present invention, the process of starting the original primary master node includes: and after finding the corresponding conf configuration file under the installation path of the original first main node, starting the original first main node.
The invention has the following beneficial technical effects: the Redis component testing method provided by the embodiment of the invention comprises the steps of establishing a Redis cluster; deleting the process of a first main node in the Redis cluster; detecting the state of a first slave node corresponding to the first master node; responding to the change of the first slave node into a new first master node, and starting the process of the original first master node; the technical scheme of judging the stable availability of the Redis component in response to the fact that the original first master node is changed into a new first slave node can verify the high availability of the Insight platform Redis component cluster, so that the test efficiency is improved, the human resources are saved, guarantee and basis are provided for the Redis high availability cluster function test of the cluster, and the product competitiveness is improved.
Detailed Description
In order to make the objects, technical solutions and advantages of the present invention more apparent, the following embodiments of the present invention are described in further detail with reference to the accompanying drawings.
In view of the above objects, a first aspect of embodiments of the present invention proposes an embodiment of a method of Redis component testing. Fig. 1 shows a schematic flow diagram of the method.
As shown in fig. 1, the method may include the steps of:
s1, testing a Redis component;
s2, deleting the process of the first master node in the Redis cluster;
s3, detecting the state of a first slave node corresponding to the first master node;
s4, responding to the change of the first slave node into a new first master node, starting the process of the original first master node;
s5, in response to the original first master node becoming the new first slave node, determining that the Redis component availability is stable.
The method can realize automatic testing in a script mode, the script uses Shell script as a development language to realize automatic testing of Redis master-slave node switching, the method mainly adopts operation commands such as simulation process faults and Redis service starting to verify the high availability of the Redis, meanwhile, the Redis operation commands carried by Hadoop are selected to verify that the Redis function is not affected after master-slave switching of a cluster, and logs in the testing process are reserved and execution records can be retroactively analyzed.
Through the technical scheme, the high availability of the Insight platform Redis component cluster can be verified, the testing efficiency is improved, the human resources are saved, the guarantee and the basis are provided for the Redis high availability cluster function test of the cluster, and the product competitiveness is improved.
In a preferred embodiment of the present invention, creating a Redis cluster comprises: a three-master three-slave Redis cluster is created in a cloud sea Insight platform. Two Redis servers are installed in an interface of a cloud sea Insight platform, after the installation is successful, a CreateRediscuster button is clicked on an operation interface, and a Redis cluster with three masters and three slaves can be automatically generated by the system.
In a preferred embodiment of the present invention, the deleting the process of the first master node in the Redis cluster includes: and acquiring the process of the Redis server of the first main node, and killing the process through a kill-9 command. The process of Redis-server of the first host node (assuming the port number of the first host node is 7001) is first acquired and killed by the kill-9 command. Therefore, the situation that the main node fails to work is simulated, and whether the first slave node corresponding to the first main node can be automatically changed into a new first main node or not is checked. The following is one example of this process:
# procedure for forced killing of Master node 1
ps-ef|grep 7001|grep-v grep|awk'{print$2}'|xargs kill-9
# see if the slave node 1 status is already master
echo“cluster nodes”|Redis-cli–h$host–p$port–c
Wherein: the $ host and $ port may be any node that is not the first master node.
In a preferred embodiment of the present invention, detecting the state of the first slave node corresponding to the first master node comprises: the set k1 HelloWorld cluster command is used to verify that the Redis cluster function is normal. After the first master node is hung up due to a fault, whether the cluster function is normal or not is verified by executing a Redis cluster command, such as set k1 HelloWorld. If the first master node fails and can not work normally, the first slave node automatically becomes a new first master node and can work normally, the high availability of the cluster is stable, and the process is to verify that the slave node can be automatically switched to the corresponding master node. The following is one example of this process:
# run Cluster execution Command
echo“set k1 HelloWorld”|Redis-cli–h$host–p$port–c
Wherein: the $ host and $ port may be any node that is not the first master node.
In a preferred embodiment of the present invention, the process of starting the original primary master node includes: and after finding the corresponding conf configuration file under the installation path of the original first main node, starting the original first main node. Finding the conf configuration file of the corresponding node, such as Redis _7001.conf, under the installation path of the original first main node, and then starting the original first main node. And after the original first main node is restarted, a cluster detection command carried by Redis is executed, and a cluster nodes command is operated to check the state of each node of the cluster. The process is to verify whether the restarted original first master node can become a corresponding new first slave node instead of knocking the new first master node down, and if the restarted original first master node can become a corresponding first slave node, the high availability of the cluster is stable. The following is one example of this process:
# into Redis installation configuration File Path
cd/usr/hdp/3.0.1.0-111/Redis/Redis_7001/conf
# boot failure Master node
Redis-server./Redis_7001.conf
# View Cluster nodes Master-slave status
echo“cluster nodes”|Redis-cli–h$host–p$port–c
Through the technical scheme, the high availability of the Insight platform Redis component cluster can be verified, the testing efficiency is improved, the human resources are saved, the guarantee and the basis are provided for the Redis high availability cluster function test of the cluster, and the product competitiveness is improved.
It should be noted that, as will be understood by those skilled in the art, all or part of the processes in the methods of the above embodiments may be implemented by instructing relevant hardware through a computer program, and the above programs may be stored in a computer-readable storage medium, and when executed, the programs may include the processes of the embodiments of the methods as described above. The storage medium may be a magnetic disk, an optical disk, a Read-Only Memory (ROM), a Random Access Memory (RAM), or the like. The embodiments of the computer program may achieve the same or similar effects as any of the above-described method embodiments.
Furthermore, the method disclosed according to an embodiment of the present invention may also be implemented as a computer program executed by a CPU, and the computer program may be stored in a computer-readable storage medium. The computer program, when executed by the CPU, performs the above-described functions defined in the method disclosed in the embodiments of the present invention.
In view of the above object, a second aspect of the embodiments of the present invention provides an apparatus for testing a Redis component, the apparatus comprising:
at least one processor; and
a memory storing program code executable by the processor, the program code when executed by the processor performing the steps of:
creating a Redis cluster;
deleting the process of a first main node in the Redis cluster;
detecting the state of a first slave node corresponding to the first master node;
responding to the change of the first slave node into a new first master node, and starting the process of the original first master node;
and in response to the original first master node becoming a new first slave node, judging that the availability of the Redis component is stable.
In a preferred embodiment of the present invention, creating a Redis cluster comprises: a three-master three-slave Redis cluster is created in a cloud sea Insight platform. Two Redis servers are installed in an interface of a cloud sea Insight platform, after the installation is successful, a CreateRediscuster button is clicked on an operation interface, and a Redis cluster with three masters and three slaves can be automatically generated by the system.
In a preferred embodiment of the present invention, the deleting the process of the first master node in the Redis cluster includes: and acquiring the process of the Redis server of the first main node, and killing the process through a kill-9 command. The process of Redis-server of the first host node (assuming the port number of the first host node is 7001) is first acquired and killed by the kill-9 command. Therefore, the situation that the main node fails to work is simulated, and whether the first slave node corresponding to the first main node can be automatically changed into a new first main node or not is checked.
In a preferred embodiment of the present invention, detecting the state of the first slave node corresponding to the first master node comprises: the set k1 HelloWorld cluster command is used to verify that the Redis cluster function is normal. After the first master node is hung up due to a fault, whether the cluster function is normal or not is verified by executing a Redis cluster command, such as set k1 HelloWorld. If the first master node fails and can not work normally, the first slave node automatically becomes a new first master node and can work normally, the high availability of the cluster is stable, and the process is to verify that the slave node can be automatically switched to the corresponding master node.
In a preferred embodiment of the present invention, the process of starting the original primary master node includes: and after finding the corresponding conf configuration file under the installation path of the original first main node, starting the first main node. Finding the conf configuration file of the corresponding node, such as Redis _7001.conf, under the installation path of the original first main node, and then starting the original first main node. And after the original first main node is restarted, a cluster detection command carried by Redis is executed, and a cluster nodes command is operated to check the state of each node of the cluster. The process is to verify whether the restarted original first master node can become the corresponding first slave node instead of knocking off a new first master node, and if the restarted original first master node can become the corresponding first slave node, the high availability of the cluster is stable.
It should be particularly noted that the embodiment of the system described above employs the embodiment of the method described above to specifically describe the working process of each module, and those skilled in the art can easily think that the modules are applied to other embodiments of the method described above.
Further, the above-described method steps and system elements or modules may also be implemented using a controller and a computer-readable storage medium for storing a computer program for causing the controller to implement the functions of the above-described steps or elements or modules.
Those of skill would further appreciate that the various illustrative logical blocks, modules, circuits, and algorithm steps described in connection with the disclosure herein may be implemented as electronic hardware, computer software, or combinations of both. To clearly illustrate this interchangeability of hardware and software, various illustrative components, blocks, modules, circuits, and steps have been described above generally in terms of their functionality. Whether such functionality is implemented as software or hardware depends upon the particular application and design constraints imposed on the overall system. Skilled artisans may implement the described functionality in varying ways for each particular application, but such implementation decisions should not be interpreted as causing a departure from the scope of the disclosed embodiments of the present invention.
The embodiments described above, particularly any "preferred" embodiments, are possible examples of implementations and are presented merely to clearly understand the principles of the invention. Many variations and modifications may be made to the above-described embodiments without departing from the spirit and principles of the technology described herein. All such modifications are intended to be included within the scope of this disclosure and protected by the following claims.