WO2021168618A1 - redis集群扩容方法、装置、电子设备以及存储介质 - Google Patents

redis集群扩容方法、装置、电子设备以及存储介质 Download PDF

Info

Publication number
WO2021168618A1
WO2021168618A1 PCT/CN2020/076458 CN2020076458W WO2021168618A1 WO 2021168618 A1 WO2021168618 A1 WO 2021168618A1 CN 2020076458 W CN2020076458 W CN 2020076458W WO 2021168618 A1 WO2021168618 A1 WO 2021168618A1
Authority
WO
WIPO (PCT)
Prior art keywords
redis
instance
cluster
redis instance
machine
Prior art date
Application number
PCT/CN2020/076458
Other languages
English (en)
French (fr)
Inventor
郭子亮
Original Assignee
深圳市欢太科技有限公司
Oppo广东移动通信有限公司
Priority date (The priority date 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 date listed.)
Filing date
Publication date
Application filed by 深圳市欢太科技有限公司, Oppo广东移动通信有限公司 filed Critical 深圳市欢太科技有限公司
Priority to CN202080093350.0A priority Critical patent/CN114945910A/zh
Priority to PCT/CN2020/076458 priority patent/WO2021168618A1/zh
Publication of WO2021168618A1 publication Critical patent/WO2021168618A1/zh

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/20Information retrieval; Database structures therefor; File system structures therefor of structured data, e.g. relational data
    • G06F16/27Replication, distribution or synchronisation of data between databases or within a distributed database system; Distributed database system architectures therefor

Definitions

  • This application relates to the technical field of electronic equipment, and more specifically, to a redis cluster expansion method, device, electronic equipment, and storage medium.
  • Redis is an open source (BSD licensed) in-memory data structure storage used as a database, cache and message broker.
  • the current redis cluster is divided into two camps, one is the proxy + stand-alone redis solution based on codis, and the other is the official redis cluster. Regardless of which solution is adopted, the industry uses the migrate command that comes with redis for migration. , The migration speed is slow, which affects the availability of the business.
  • this application proposes a redis cluster expansion method, device, electronic equipment, and storage medium to solve the above problems.
  • an embodiment of the present application provides a redis cluster expansion method, and the method includes:
  • an embodiment of the present application provides a redis cluster expansion device, and the device includes:
  • the first redis instance deployment module is used to deploy and start the second redis instance on the second machine when the first redis instance in the redis cluster deployed on the first machine is migrated to the second machine.
  • the capacity of the redis instance is not greater than the specified capacity;
  • the first data replication module is used to add the second redis instance as a copy of the first redis instance to the redis cluster, and add the data in the first redis instance The data is copied to the second redis instance;
  • the first redis instance replacement module is used to replace the first redis instance with the second redis instance in the redis cluster.
  • an embodiment of the present application provides an electronic device, including a memory and a processor, the memory is coupled to the processor, the memory stores instructions, and the instructions are executed when the instructions are executed by the processor.
  • the processor executes the above method.
  • an embodiment of the present application provides a computer readable storage medium, and the computer readable storage medium stores program code, and the program code can be invoked by a processor to execute the above method.
  • the redis cluster expansion method, device, electronic equipment, and storage medium provided by the embodiments of the present application are deployed and opened on the second machine when the first redis instance in the redis cluster deployed on the first machine is migrated to the second machine
  • the second redis instance where the capacity of the second redis instance is not greater than the specified capacity, the second redis instance is added to the redis cluster as a copy of the first redis instance, and the data in the first redis instance is copied to the second redis instance , Replace the first redis instance with the second redis instance in the redis cluster, so as to achieve the purpose of rapid expansion of the redis cluster by copying instead of migration, and improve the availability of the business.
  • FIG. 1 shows a schematic flowchart of a redis cluster expansion method provided by an embodiment of the present application
  • Figure 2 shows a schematic diagram of redis cluster expansion provided by an embodiment of the present application
  • FIG. 3 shows another schematic diagram of redis cluster expansion provided by an embodiment of the present application
  • FIG. 4 shows a schematic flowchart of a redis cluster expansion method provided by another embodiment of the present application.
  • FIG. 5 shows a schematic flowchart of a redis cluster expansion method provided by another embodiment of the present application.
  • FIG. 6 shows a schematic flowchart of step S340 of the redis cluster expansion method shown in FIG. 5 of the present application
  • FIG. 7 shows another schematic diagram of redis cluster expansion provided by an embodiment of the present application.
  • FIG. 8 shows another schematic diagram of redis cluster expansion provided by an embodiment of the present application.
  • FIG. 9 shows a schematic flowchart of an embodiment of step S360 of the redis cluster expansion method shown in FIG. 5 of the present application.
  • FIG. 10 shows a schematic flowchart of another embodiment of step S360 of the redis cluster expansion method shown in FIG. 5 of the present application;
  • FIG. 11 shows a schematic flowchart of a redis cluster expansion method provided by another embodiment of the present application.
  • FIG. 12 shows a schematic flowchart of step S430 of the redis cluster expansion method shown in FIG. 11 of the present application;
  • FIG. 13 shows a module block diagram of a redis cluster expansion device provided by an embodiment of the present application
  • FIG. 14 shows a block diagram of an electronic device used to execute the redis cluster expansion method according to the embodiment of the present application
  • FIG. 15 shows a storage unit for storing or carrying program code for implementing the redis cluster expansion method according to the embodiment of the present application.
  • the redis cluster is divided into two camps, one is the proxy + stand-alone redis solution based on codis, and the other is the official redis cluster.
  • the industry uses the migrate command that comes with redis for migration. According to the different cluster schemes, many different optimizations have been made on the basis of migrate.
  • redis cluster in redis 4.0 cluster supports the movement of designated slots in nodes, and also supports automatic redistribution after adding empty nodes according to the existing slot distribution in cluster nodes.
  • Google Cloud redis uses the migrate command to migrate keys in batches.
  • Google Cloud has optimized the migrate and split the migrate command into two stages. 1. Serialize the key requested for migration and send it to the target node, and the target node will return a confirmation after receiving it; 2. After the target node completes the deserialization, it will actively notify the source node, and the source node will delete the local data.
  • the main purpose of this split is to reduce the time that the source node is synchronously blocked by the migrate command, but the redis kernel needs to be modified, and the effect is not obvious.
  • Pre-sharding is the redis cluster expansion solution proposed by the author of redis, antirez, before the official redis cluster solution was perfected.
  • the business must first determine the data to be divided into N parts, each corresponding to a redis instance, when the business storage volume is small, all the redis instances are deployed on a small number of machines.
  • the migration is carried out according to the following steps: 1. Start the standby redis instance in the new virtual machine; 2. Set this instance as a copy of the old instance to be moved; 3. When the initial synchronization is completed and all the slave servers are working, please change The configuration of the client is to use the new instance; 4. Use slave of no one to select the new instance as the master instance; 5. Finally, close all the old instances; 6. Use the new IP/PORT information of each instance to improve the shell script configuration.
  • redis cluster (Alibaba Cloud similar) solution commonly used in the industry relies on the migrate command of redis itself. In order to ensure the atomicity of this command, the entire redis main process will be synchronously blocked during the migration process, which greatly affects the availability. And migrate can only migrate one key at a time, and the migration speed is also very slow.
  • Antirez's previous Pre-sharding solution uses replication instead of migration, which can effectively guarantee the availability and migration speed of redis at the expense of certain consistency, but because it is a fixed number of copies N, N before and after migration is immutable, so how much N is determined? Become a problem.
  • the pre-sharding mentioned earlier is mainly for the master-slave version cluster, and does not explain the current reids cluster solution.
  • the inventor has discovered and proposed the redis cluster expansion method, device, electronic equipment, and storage medium provided by the embodiments of this application after long-term research.
  • the redis cluster is achieved by copying instead of migration.
  • the purpose of rapid expansion is to improve business availability.
  • the specific redis cluster expansion method will be specifically described in the subsequent embodiments.
  • FIG. 1 shows a schematic flowchart of a redis cluster expansion method provided by an embodiment of the present application.
  • the redis cluster expansion method is used to achieve the purpose of rapid expansion of the redis cluster by means of replication instead of migration, and to improve the availability of services.
  • the redis cluster expansion method is applied to the redis cluster expansion device 200 shown in FIG. 13 and the electronic device 100 configured with the redis cluster expansion device 200 (FIG. 14 ).
  • the following will take an electronic device as an example to describe the specific process of this embodiment.
  • the electronic device applied in this embodiment may be a smart phone, a tablet computer, a wearable electronic device, etc., which is not limited here.
  • the redis cluster expansion method may specifically include the following steps:
  • Step S110 When migrating the first redis instance in the redis cluster deployed on the first machine to the second machine, deploy and start the second redis instance on the second machine, and the capacity of the second redis instance is not Greater than the specified capacity.
  • the redis cluster may include multiple redis instances, where the capacities of the multiple redis instances may all be the same, all may be different, or some of the redis instances may be the same.
  • the redis cluster may include a first redis instance and multiple other redis instances, where the capacity of the first redis instance can be the same as the capacity of multiple other redis instances, or it can be the same as the capacity of multiple other redis instances It is different, and it is not limited here.
  • the first redis instance in the redis cluster is deployed on the first machine, and multiple other redis instances in the redis cluster can be deployed on the first machine, or they can be deployed on other machines different from the first machine.
  • the redis cluster includes 5 redis instances, and the 5 redis instances are the first redis instance, the first other redis instance, the second other redis instance, the third other redis instance, and the fourth other redis instance, where, The first redis instance is deployed on the first machine, the first other redis instance, the second other redis instance, the third other redis instance, and the fourth other redis instance can be deployed on the first machine or on other machines.
  • the first other redis instance, the second other redis instance, the third other redis instance, and the fourth other redis instance are deployed on other machines
  • the first other redis instance, the second other redis instance, the third other redis instance, and the first Four other redis instances can all be deployed on the same other machine, part of them can be deployed on the same other machine, or all of them can be deployed on other different machines, which is not limited here.
  • the redis cluster when the redis cluster is expanded, at least one of the multiple redis instances included in the redis cluster may be expanded. That is, when the redis cluster is expanded, the first redis instance in the redis cluster can be expanded, or other redis instances in the redis cluster can be expanded at the same time, which is not limited here.
  • the expansion of the first redis instance in the redis cluster is taken as an example for description. Of course, other redis instances in the redis cluster can also be expanded, which will not be repeated here. Go into details.
  • the first redis instance deployed on the first machine can be migrated to the second machine, where the second machine is different from the first machine.
  • the memory of the second machine may be more sufficient than the memory of the first machine, so as to meet the expansion purpose when the first redis instance is migrated from the first machine to the second machine.
  • the second redis instance when the first redis instance in the redis cluster deployed on the first machine is migrated to the second machine, the second redis instance can be deployed and started on the second machine, where, in order to avoid a single node It is not easy to maintain.
  • the capacity of the second redis instance deployed on the second machine can be limited to not greater than the specified capacity.
  • the memory configuration simply limits the capacity of the second redis instance to not greater than the specified capacity.
  • Step S120 Add the second redis instance to the redis cluster as a copy of the first redis instance, and copy the data in the first redis instance to the second redis instance.
  • the second redis instance can be added to the redis cluster as a copy of the first redis instance, and the data in the first redis instance can be synchronized to the first redis instance.
  • the method of synchronizing the data in the first redis instance to the second redis instance may include replication, copying, etc., so as to quickly synchronize the data in the first redis instance to the second redis instance , which greatly improves the migration speed.
  • redis itself does not support the function of migrating slots, and an additional migration tool needs to be written to perform slot migration. It is easy to cause migration errors due to logic problems.
  • This embodiment uses redis itself to replace the slot migration logic of the external program with the more mature replication function. Reduce the probability of errors. Furthermore, in this embodiment, the data in the first redis instance is synchronized to the second redis instance by means of replication. During the replication process, the use of the service is not affected at all, and the availability of the service can be improved.
  • the data in the first redis instance when the data in the first redis instance is copied to the second redis instance, if the first redis instance includes a slave node, the data in the slave node of the first redis instance can also be copied to the second redis instance.
  • the redis instance there is no limitation here.
  • Figure 2 shows a schematic diagram of redis cluster expansion provided by an embodiment of the present application.
  • machine A can be regarded as the first machine
  • machine B can be regarded as the second machine
  • M can be regarded as As the first redis instance
  • S can be regarded as the second redis instance.
  • the data in the redis instance M in machine A can be copied to the redis instance S, and the redis instance S is compared to the redis instance M
  • the increased capacity of the redis cluster realizes the expansion of the redis cluster.
  • Step S130 Replace the first redis instance with the second redis instance in the redis cluster.
  • the first redis instance can be replaced with the second redis instance in the redis cluster, that is, at this time, the redis cluster It includes the second redis instance and multiple other redis instances, so that by expanding the first redis instance to the second redis, the purpose of redis cluster expansion is achieved.
  • the first redis instance before replacing the first redis instance with the second redis instance in the redis cluster, it can also be checked whether the data in the first redis instance is completely copied to the second redis instance. As a way, you can obtain The capacity occupied by the data in the first redis instance, and monitor the capacity occupied by the data in the second redis instance during the process of copying data from the first redis instance to the second redis instance. At the end of the replication, if you monitor When the capacity occupied by the data in the second redis instance is lower than the capacity occupied by the data in the first redis instance, it can be determined that the data in the first redis instance is not completely copied to the second redis instance, and the first redis instance can be triggered.
  • Figure 3 shows another schematic diagram of redis cluster expansion provided by an embodiment of the present application.
  • machine A can be regarded as the first machine
  • machine B can be regarded as the second machine
  • M can be As the first redis instance
  • S can be regarded as the second redis instance.
  • the redis instance M in machine A can be removed, and the redis instance S in machine B can be replaced with the redis instance M in machine B .
  • the second redis instance when the first redis instance in the redis cluster deployed on the first machine is migrated to the second machine, the second redis instance is deployed and opened on the second machine, wherein, The capacity of the second redis instance is not greater than the specified capacity.
  • the second redis instance is added to the redis cluster as a copy of the first redis instance, and the data in the first redis instance is copied to the second redis instance.
  • One redis instance is replaced with a second redis instance, thereby achieving the purpose of rapid expansion of the redis cluster by copying instead of migration, and improving the availability of the business.
  • FIG. 4 shows a schematic flowchart of a redis cluster expansion method provided by another embodiment of the present application.
  • the following will elaborate on the process shown in Figure 4, and the redis cluster expansion method may specifically include the following steps:
  • Step S210 When migrating the first redis instance in the redis cluster deployed on the first machine to the second machine, deploy and start the second redis instance on the second machine, and the capacity of the second redis instance is not Greater than the specified capacity.
  • Step S220 Add the second redis instance to the redis cluster as a copy of the first redis instance, and copy the data in the first redis instance to the second redis instance.
  • Step S230 Replace the first redis instance with the second redis instance in the redis cluster.
  • step S210 to step S230 please refer to step S110 to step S130, which will not be repeated here.
  • Step S240 When migrating the second redis instance in the redis cluster deployed on the second machine to the third machine, deploy and start a third redis instance on the third machine.
  • the capacity is not greater than the specified capacity.
  • the redis cluster may include a second redis instance and multiple other redis instances.
  • the second redis instance in the redis cluster is deployed on the second machine, and multiple other redis instances in the redis cluster can be deployed on the first machine, can be deployed on the second machine, or can be deployed differently from the first machine.
  • the other machines of the machine and the second machine there is no limitation here.
  • the redis cluster includes 5 redis instances, and the 5 redis instances are the second redis instance, the first other redis instance, the second other redis instance, the third other redis instance, and the fourth other redis instance, where, The second redis instance is deployed on the second machine, the first other redis instance, the second other redis instance, the third other redis instance, and the fourth other redis instance can be deployed on the first machine, deployed on the second machine, or It can be deployed on other machines.
  • the first other redis instance, the second other redis instance, the third other redis instance, and the fourth other redis instance are deployed on other machines
  • the third other redis instances and the fourth other redis instances can all be deployed on the same other machine, part of them can be deployed on the same other machine, or all of them can be deployed on other different machines, which is not limited here.
  • the redis cluster when the redis cluster is expanded, at least one of the multiple redis instances included in the redis cluster may be expanded. That is, when the redis cluster is expanded, the second redis instance in the redis cluster can be expanded, or other redis instances in the redis cluster can be expanded at the same time, which is not limited here.
  • the expansion of the second redis instance in the redis cluster is taken as an example for description. Of course, other redis instances in the redis cluster can also be expanded, which will not be repeated here. Go into details.
  • the second redis instance in the redis cluster when the second redis instance in the redis cluster is expanded, the second redis instance deployed on the second machine can be migrated to the third machine, where the third machine is different from the second machine.
  • the memory of the third machine may be more sufficient than that of the second machine, so as to meet the expansion purpose when the second redis instance is migrated from the second machine to the third machine.
  • the third redis instance when the second redis instance in the redis cluster deployed on the second machine is migrated to the third machine, the third redis instance can be deployed and opened on the third machine, where, in order to avoid a single node It is not easy to maintain.
  • the capacity of the third redis instance deployed on the second machine can be limited to not greater than the specified capacity.
  • the memory configuration simply limits the capacity of the third redis instance to not greater than the specified capacity.
  • Step S250 Add the third redis instance to the redis cluster as a copy of the second redis instance, and copy the data in the second redis instance to the third redis instance.
  • the third redis instance can be added to the redis cluster as a copy of the second redis instance, and the data in the second redis instance can be synchronized to the first redis instance.
  • the method of synchronizing the data in the second redis instance to the third redis instance may include replication, copying, etc., to achieve rapid synchronization of the data in the second redis instance to the third redis instance , which greatly improves the migration speed.
  • Step S260 Replace the second redis instance with the third redis instance in the redis cluster.
  • the second redis instance can be replaced with the third redis instance in the redis cluster, that is, at this time, the redis cluster It includes a third redis instance and multiple other redis instances, so that by expanding the second redis instance to the third redis, the purpose of redis cluster expansion is achieved. Therefore, in this embodiment, the redis cluster can be expanded indefinitely as needed to ensure service availability.
  • the second redis instance before replacing the second redis instance with the third redis instance in the redis cluster, it is also possible to detect whether the data in the second redis instance is completely copied to the third redis instance. As a way, you can obtain The capacity occupied by the data in the second redis instance, and monitor the capacity occupied by the data in the third redis instance during the process of copying data from the second redis instance to the third redis instance. At the end of the replication, if you monitor When the capacity occupied by the data in the third redis instance is lower than the capacity occupied by the data in the second redis instance, it can be determined that the data in the second redis instance is not completely copied to the third redis instance, and the first redis instance can be triggered. 2.
  • the second redis instance when the first redis instance in the redis cluster deployed on the first machine is migrated to the second machine, the second redis instance is deployed and opened on the second machine, where , The capacity of the second redis instance is not greater than the specified capacity, the second redis instance is added to the redis cluster as a copy of the first redis instance, and the data in the first redis instance is copied to the second redis instance, and the redis cluster The first redis instance is replaced with the second redis instance.
  • the third redis instance is deployed and opened on the third machine.
  • the capacity of the redis instance is not greater than the specified capacity
  • the third redis instance is added to the redis cluster as a copy of the second redis instance, and the data in the second redis instance is copied to the third redis instance, and the second in the redis cluster
  • the redis instance is replaced with the third redis instance.
  • this embodiment also deploys redis instances on different machines according to requirements, so as to achieve continuous expansion of the redis cluster and improve service availability.
  • FIG. 5 shows a schematic flowchart of a redis cluster expansion method provided by another embodiment of the present application.
  • the following will elaborate on the process shown in FIG. 5, and the redis cluster expansion method may specifically include the following steps:
  • Step S310 When migrating the first redis instance in the redis cluster deployed on the first machine to the second machine, deploy and start the second redis instance on the second machine, and the capacity of the second redis instance is not Greater than the specified capacity.
  • Step S320 Add the second redis instance to the redis cluster as a copy of the first redis instance, and copy the data in the first redis instance to the second redis instance.
  • Step S330 Replace the first redis instance with the second redis instance in the redis cluster.
  • step S310 to step S330 please refer to step S110 to step S130, which will not be repeated here.
  • Step S340 When migrating the first redis instance in the redis cluster deployed on the first machine to the second machine, deploy and start a fourth redis instance on the second machine, and the capacity of the fourth redis instance is greater than Specify the capacity.
  • the fourth redis instance when migrating the first redis instance in the redis cluster deployed on the first machine to the second machine, the fourth redis instance can be deployed and started on the second machine, where, as needed, you can Set the memory of the fourth redis instance to be temporarily larger than the specified capacity to cope with sudden traffic and ensure business availability.
  • the fourth redis instance when the first redis instance in the redis cluster deployed on the first machine is migrated to the second machine, the fourth redis instance can be deployed and opened on the second machine, and the capacity of the fourth redis instance is greater than The specified capacity is not larger than the target capacity.
  • the designated capacity can include 8G
  • the target capacity can include 16G.
  • the specified capacity can include 8G
  • the capacity of the fourth instance can be set to 16G, so as to be used in the process of copying the data in the first redis instance to the fourth redis instance, if the data in the first redis instance is greater than 8G (For example, 10G), resulting in a situation where the fourth redis instance cannot be stored.
  • FIG. 6 shows a schematic flowchart of step S340 of the redis cluster expansion method shown in FIG. 5 of the present application.
  • the process shown in FIG. 6 will be described in detail below, and the method may specifically include the following steps:
  • Step S341 When migrating the first redis instance in the redis cluster deployed on the first machine to the second machine, obtain the capacity occupied by the data in the first redis instance.
  • the capacity occupied by the data in the first redis instance can be obtained according to the first redis instance
  • the capacity occupied by the data in determines the capacity of the redis instance deployed on the second device.
  • Step S342 When the capacity occupied by the data in the first redis instance is greater than the specified capacity, deploy and start a fourth redis instance on the second machine, and the capacity of the fourth redis instance is greater than that of the first redis The capacity occupied by the data in the instance.
  • a fourth redis instance when it is obtained that the capacity occupied by the data in the first redis instance is greater than the specified capacity, a fourth redis instance can be deployed and opened on the second machine, where the capacity of the fourth redis instance is greater than that of the first redis The capacity occupied by the amount data in the instance. For example, if the specified capacity is 8G, when the capacity occupied by the data in the first redis instance is 10G, you can deploy and open a fourth redis instance with a capacity greater than 10G on the second machine. For example, deploy and open the capacity on the second machine The 16G fourth redis instance to ensure business availability.
  • the second redis instance when it is obtained that the capacity occupied by the data in the first redis instance is not greater than the specified capacity, the second redis instance can be deployed and opened on the second machine, where the capacity of the second redis instance is not greater than the specified capacity capacity.
  • the specified capacity is 8G
  • Step S350 Add the fourth redis instance to the redis cluster as a copy of the first redis instance, and copy the data in the first redis instance to the fourth redis instance.
  • the fourth redis instance after the fourth redis instance is deployed and opened on the second machine, the fourth redis instance can be added to the redis cluster as a copy of the first redis instance, and the data in the first redis instance can be synchronized to the first redis instance.
  • the method of synchronizing the data in the first redis instance to the fourth redis instance may include replication, copying, etc., to achieve rapid synchronization of the data in the first redis instance to the fourth redis instance , which greatly improves the migration speed.
  • Step S360 Perform split processing on the fourth redis instance to obtain multiple fifth redis instances, wherein each fifth redis instance of the multiple fifth redis instances is not larger than a specified capacity.
  • the capacity of the fourth redis instance is greater than the specified capacity, the capacity of the fourth redis instance is larger.
  • the fourth redis instance can be split to split the fourth redis instance into multiple fifth redis instances with smaller capacity, where each fifth redis instance of the multiple fifth redis instances The capacity of the redis instance is not greater than the specified capacity.
  • the upper limit of the memory usage of each fifth redis instance of the multiple fifth redis instances can be configured through max memory to not be greater than the specified capacity.
  • the capacities of multiple fifth redis instances obtained by splitting the fourth redis instance may be equal or unequal.
  • the fourth redis instance can be divided equally according to the data of the fifth redis instance. For example, when the capacity of the fourth redis instance is 16G and the designated capacity is 8G, If you need to split the fourth redis instance into two fifth redis instances, you can equally divide the fourth redis instance into two fifth redis instances with a capacity of 8G; if you need to split the fourth redis into four fifth instances For the redis instance, the fourth redis instance can be equally divided into 4 fifth redis instances with a capacity of 4G.
  • the fourth redis instance can be divided according to the specified capacity. For example, when the capacity of the fourth redis instance is 23G and the specified capacity is 8G, if the fourth redis instance needs to be Split into three fifth redis instances, you can split the fourth redis instance into a fifth redis instance A with a capacity of 8G, a fifth redis instance B with a capacity of 8G, and a fifth redis instance C with a capacity of 7G, here Not limited.
  • performing split processing on the fourth redis instance to obtain multiple fifth redis instances may include: performing split processing on the fourth redis instance through slot migration to obtain multiple fifth redis instances.
  • the split operation is mainly to ensure that the redis cluster can continue to be expanded in the same way in the future, and its execution does not affect the use of the redis cluster. Therefore, the operation can be scheduled in a time period with a small amount of business requests as needed. Avoid affecting the availability of the business.
  • Figure 7 shows another schematic diagram of redis cluster expansion provided by an embodiment of the present application.
  • machine A can be regarded as the first machine
  • machine B can be regarded as the second machine.
  • the capacity of the four redis instances (16G) is greater than the specified capacity (8G)
  • the fourth redis instance can be split through slot migration to obtain two fifth redis instances, as shown in Figure 8.
  • FIG. 9 shows a schematic flowchart of an embodiment of step S360 of the redis cluster expansion method shown in FIG. 5 of the present application.
  • the process shown in FIG. 9 will be described in detail below, and the method may specifically include the following steps:
  • Step S361A Obtain the current service request amount.
  • the current service request amount can be obtained.
  • the current service request volume can be obtained in real time, the current service request volume can be obtained at a preset time interval, the current service request volume can be obtained at a preset time point, or the current service request volume can be obtained according to other preset rules. , It is not limited here.
  • Step S362A When the current service request volume is less than the specified request volume, split the fourth redis instance to obtain the multiple fifth redis instances.
  • a designated request amount may be preset and stored, and the designated request amount is used as a basis for judging the current service request amount. Therefore, in this embodiment, after obtaining the current service request volume, the current service request volume can be compared with the specified request volume to determine whether the current service request volume is less than the specified request volume. When the amount is less than the specified request amount, it indicates that the current business request amount is small, and even if the fourth redis instance is split, the business will not be affected. Therefore, the fourth redis instance can be split to obtain multiple fifth redis instances; When the judgment result indicates that the current service request volume is not less than the specified request volume, it indicates that the current service request volume is large. Splitting the fourth redis instance will affect the service. Therefore, you can continue to obtain the current service request volume until it is obtained. The current business request volume is less than the specified request volume.
  • FIG. 10 shows a schematic flowchart of another embodiment of step S360 of the redis cluster expansion method shown in FIG. 5 of the present application.
  • the process shown in FIG. 10 will be described in detail below, and the method may specifically include the following steps:
  • Step S361B Obtain the current time.
  • the current time can be acquired.
  • the current time may be obtained in real time, the current time may be obtained at a preset time interval, the current time may be obtained at a preset time point, or the current time may be obtained according to other preset rules, which are not limited here.
  • Step S362B When the current time is within a specified time period, perform split processing on the fourth redis instance to obtain the multiple fifth redis instances.
  • a designated request amount may be preset and stored, and the designated request amount is used as a basis for judging the current service request amount. Therefore, in this embodiment, after obtaining the current service request volume, the current service request volume can be compared with the specified request volume to determine whether the current service request volume is less than the specified request volume. When the amount is less than the specified request amount, it indicates that the current business request amount is small. Even if the fourth redis instance is split, the business will not be affected. Therefore, the fourth redis instance can be split to obtain multiple fifth redis instances; When the judgment result indicates that the current service request volume is not less than the specified request volume, it indicates that the current service request volume is large. Splitting the fourth redis instance will affect the service. Therefore, you can continue to obtain the current service request volume until it is obtained. The current business request volume is less than the specified request volume.
  • Step S370 Replace the first redis instance with the multiple fifth redis instances in the redis cluster.
  • the first redis instance can be replaced with multiple fifth redis instances in the redis cluster, that is, at this time, the redis cluster includes multiple fifth redis instances.
  • the redis instance and multiple other redis instances so as to achieve the purpose of redis cluster expansion by expanding the first redis instance to multiple fifth redis.
  • the redis cluster expansion method when the first redis instance in the redis cluster deployed on the first machine is migrated to the second machine, the second redis instance is deployed and opened on the second machine, where , The capacity of the second redis instance is not greater than the specified capacity, the second redis instance is added to the redis cluster as a copy of the first redis instance, and the data in the first redis instance is copied to the second redis instance, and the redis cluster Replace the first redis instance with the second redis instance.
  • FIG. 11 shows a schematic flowchart of a redis cluster expansion method provided by another embodiment of the present application.
  • the following will elaborate on the process shown in FIG. 11, and the redis cluster expansion method may specifically include the following steps:
  • Step S410 When migrating the first redis instance in the redis cluster deployed on the first machine to the second machine, deploy and start the second redis instance on the second machine, and the capacity of the second redis instance is not Greater than the specified capacity.
  • Step S420 Add the second redis instance to the redis cluster as a copy of the first redis instance, and copy the data in the first redis instance to the second redis instance.
  • step S410-step S420 please refer to step S110-step S120, which will not be repeated here.
  • Step S430 Promote the second redis instance to the master node in the redis cluster, and remove the first redis instance from the redis cluster.
  • the way to replace the first redis instance with the second redis instance in the redis cluster can be: promote the second redis instance to the master node in the redis cluster, and remove the first redis from the redis cluster Instance.
  • the second redis instance can be promoted as the master node in the redis cluster through cluster failover.
  • the first redis instance can be removed from the redis cluster through cluster forget.
  • FIG. 12 shows a schematic flowchart of step S430 of the redis cluster expansion method shown in FIG. 11 of the present application.
  • the process shown in FIG. 12 will be described in detail below, and the method may specifically include the following steps:
  • Step S431 Promote the second redis instance to the master node in the redis cluster, and shut down the first redis instance in the redis cluster.
  • the second redis instance when the first redis instance is replaced with the second redis instance in the redis cluster, the second redis instance can be promoted to the master node in the redis cluster, and the first redis instance can be shut down in the redis cluster.
  • Step S432 Remove the closed first redis instance from the redis cluster.
  • the closed first redis instance can be removed from the redis cluster.
  • the slave node of the first redis instance is also removed.
  • redis cluster expansion method when the first redis instance in the redis cluster deployed on the first machine is migrated to the second machine, the second redis instance is deployed and opened on the second machine, where , The capacity of the second redis instance is not greater than the specified capacity, the second redis instance is added to the redis cluster as a copy of the first redis instance, and the data in the first redis instance is copied to the second redis instance, and the redis cluster The second redis instance is promoted to the master node, and the first redis instance is removed from the redis cluster.
  • this embodiment also implements the redis cluster expansion by promoting the second redis instance as the master node and removing the first redis instance, thereby improving the convenience of redis cluster expansion.
  • FIG. 13 shows a block diagram of a redis cluster expansion device 200 provided by an embodiment of the present application.
  • the block diagram shown in FIG. 13 will be described below.
  • the redis cluster expansion device 200 includes: a first redis instance The deployment module 210, the first data replication module 220, and the first redis instance replacement module 230, wherein:
  • the first redis instance deployment module 210 is configured to deploy and start the second redis instance on the second machine when the first redis instance in the redis cluster deployed on the first machine is migrated to the second machine.
  • the capacity of the second redis instance is not greater than the specified capacity.
  • the first data replication module 220 is configured to add the second redis instance as a copy of the first redis instance to the redis cluster, and copy the data in the first redis instance to the second redis instance middle.
  • the first redis instance replacement module 230 is configured to replace the first redis instance with the second redis instance in the redis cluster.
  • redis instance replacement module 230 includes:
  • the redis instance promotion submodule is used to promote the second redis instance to the master node in the redis cluster, and to remove the first redis instance from the redis cluster.
  • the redis instance promotion sub-module includes: a redis instance promotion unit and a redis instance removal unit, wherein:
  • the first redis instance promotion unit is configured to promote the second redis instance to the master node in the redis cluster, and shut down the first redis instance in the redis cluster.
  • the redis instance removal unit is configured to remove the closed first redis instance from the redis cluster.
  • the first redis instance includes a slave node
  • the redis instance promotion submodule includes: a second redis instance promotion unit, wherein:
  • the second redis instance promotion unit is used to promote the second redis instance to the master node in the redis cluster, and remove the first redis instance and the first redis instance from the redis cluster Slave node.
  • redis instance promotion submodule includes: a third redis instance promotion unit, wherein:
  • the third redis instance promotion unit is configured to promote the second redis instance to the master node in the redis cluster through cluster failover.
  • the redis instance promotion module includes: an instance removal unit, wherein:
  • the instance removal unit is configured to remove the first redis instance from the redis cluster through cluster forget.
  • the redis cluster expansion device 200 further includes: a second redis instance deployment module, a second data replication module, and a second redis instance replacement module, wherein:
  • the second redis instance deployment module is used to deploy and start the third redis instance on the third machine when the second redis instance in the redis cluster deployed on the second machine is migrated to the third machine, so The capacity of the third redis instance is not greater than the specified capacity;.
  • the second data replication module is configured to add the third redis instance to the redis cluster as a copy of the second redis instance, and copy the data in the second redis instance to the third redis instance .
  • the second redis instance replacement module is configured to replace the second redis instance with the third redis instance in the redis cluster.
  • the redis cluster expansion device 200 further includes: a third redis instance deployment module, a third data replication module, a redis instance splitting module, and a third redis instance replacement module, wherein:
  • the third redis instance deployment module is used to deploy and start the fourth redis instance on the second machine when the first redis instance in the redis cluster deployed on the first machine is migrated to the second machine. 4.
  • the capacity of the redis instance is greater than the specified capacity.
  • the third redis instance deployment module includes: a capacity acquisition sub-module and a third redis instance deployment sub-module, wherein:
  • the capacity obtaining submodule is used to obtain the capacity occupied by the data in the first redis instance when the first redis instance in the redis cluster deployed on the first machine is migrated to the second machine.
  • the first redis instance deployment sub-module is used to deploy and start a fourth redis instance on the second machine when the capacity occupied by the data in the first redis instance is greater than a specified capacity.
  • the capacity is greater than the capacity occupied by the data in the first redis instance.
  • the third redis instance deployment module includes: a second redis instance deployment sub-module, wherein:
  • the second redis instance deployment submodule is used to deploy and start the fourth redis instance on the second machine when migrating the first redis instance in the redis cluster deployed on the first machine to the second machine,
  • the capacity of the fourth redis instance is greater than the specified capacity and not greater than the target capacity.
  • the third data replication module is configured to add the fourth redis instance as a copy of the first redis instance to the redis cluster, and copy the data in the first redis instance to the fourth redis instance .
  • the redis instance splitting module is used to split the fourth redis instance to obtain multiple fifth redis instances, wherein each fifth redis instance of the multiple fifth redis instances is not larger than a specified capacity.
  • the redis instance splitting module includes: a first redis instance splitting sub-module, wherein:
  • the first redis instance splitting submodule is used to split the fourth redis instance through slot migration to obtain the multiple fifth redis instances.
  • the redis instance splitting module includes: a service request volume acquisition submodule and a second redis instance splitting submodule, wherein:
  • the business request volume acquisition sub-module is used to acquire the current business request volume.
  • the second redis instance splitting submodule is configured to perform split processing on the fourth redis instance when the current service request volume is less than the specified request volume to obtain the multiple fifth redis instances.
  • the redis instance splitting module includes: a current time obtaining submodule and a third redis instance splitting submodule, wherein:
  • the current time acquisition sub-module is used to acquire the current time.
  • the third redis instance splitting submodule is configured to split the fourth redis instance to obtain the multiple fifth redis instances when the current time is within a specified time period.
  • the redis instance splitting module includes: a fourth redis instance splitting submodule, wherein:
  • the fourth redis instance splitting submodule is used to configure the upper limit of the memory occupation of each fifth redis instance of the plurality of fifth redis instances to not be greater than the specified capacity through max memory.
  • the third redis instance replacement module is used to replace the first redis instance with the multiple fifth redis instances in the redis cluster.
  • the coupling between the modules may be electrical, mechanical or other forms of coupling.
  • the functional modules in the various embodiments of the present application may be integrated into one processing module, or each module may exist alone physically, or two or more modules may be integrated into one module.
  • the above-mentioned integrated modules can be implemented in the form of hardware or software functional modules.
  • FIG. 14 shows a structural block diagram of an electronic device 100 provided by an embodiment of the present application.
  • the electronic device 100 may be an electronic device capable of running application programs, such as a smart phone, a tablet computer, or an e-book.
  • the electronic device 100 in this application may include one or more of the following components: a processor 110, a memory 120, and one or more application programs, where one or more application programs may be stored in the memory 120 and configured to be composed of one Or multiple processors 110 execute, and one or more programs are configured to execute the method described in the foregoing method embodiment.
  • the processor 110 may include one or more processing cores.
  • the processor 110 uses various interfaces and lines to connect various parts of the entire electronic device 100, and executes by running or executing instructions, programs, code sets, or instruction sets stored in the memory 120, and calling data stored in the memory 120.
  • Various functions and processing data of the electronic device 100 may adopt at least one of Digital Signal Processing (DSP), Field-Programmable Gate Array (FPGA), and Programmable Logic Array (PLA).
  • DSP Digital Signal Processing
  • FPGA Field-Programmable Gate Array
  • PDA Programmable Logic Array
  • the processor 110 may be integrated with one or a combination of a central processing unit (CPU), a graphics processing unit (GPU), a modem, and the like.
  • the CPU mainly processes the operating system, user interface, and application programs; the GPU is used for rendering and drawing the content to be displayed; the modem is used for processing wireless communication. It can be understood that the above-mentioned modem may not be integrated into the processor 110, but may be implemented by a communication chip alone.
  • the memory 120 may include random access memory (RAM) or read-only memory (Read-Only Memory).
  • the memory 120 may be used to store instructions, programs, codes, code sets or instruction sets.
  • the memory 120 may include a program storage area and a data storage area, where the program storage area may store instructions for implementing the operating system and instructions for implementing at least one function (such as touch function, sound playback function, image playback function, etc.) , Instructions used to implement the following various method embodiments, etc.
  • the storage data area can also store data (such as phone book, audio and video data, chat record data) created by the electronic device 100 during use.
  • FIG. 15 shows a structural block diagram of a computer-readable storage medium provided by an embodiment of the present application.
  • the computer-readable medium 300 stores program code, and the program code can be invoked by a processor to execute the method described in the foregoing method embodiment.
  • the computer-readable storage medium 300 may be an electronic memory such as flash memory, EEPROM (Electrically Erasable Programmable Read Only Memory), EPROM, hard disk, or ROM.
  • the computer-readable storage medium 300 includes a non-transitory computer-readable storage medium.
  • the computer-readable storage medium 300 has storage space for the program code 310 for executing any method steps in the above-mentioned methods. These program codes can be read from or written into one or more computer program products.
  • the program code 310 may be compressed in a suitable form, for example.
  • the redis cluster expansion method, device, electronic equipment, and storage medium provided by the embodiments of the present application are migrated from the first redis instance in the redis cluster deployed on the first machine to the second machine.
  • Two machines deploy and start the second redis instance, where the capacity of the second redis instance is not greater than the specified capacity, the second redis instance is added to the redis cluster as a copy of the first redis instance, and the data in the first redis instance is copied to In the second redis instance, the first redis instance is replaced with the second redis instance in the redis cluster, thereby achieving the purpose of rapid expansion of the redis cluster and improving the availability of the business by means of replication instead of migration.

Landscapes

  • Engineering & Computer Science (AREA)
  • Databases & Information Systems (AREA)
  • Theoretical Computer Science (AREA)
  • Computing Systems (AREA)
  • Data Mining & Analysis (AREA)
  • Physics & Mathematics (AREA)
  • General Engineering & Computer Science (AREA)
  • General Physics & Mathematics (AREA)
  • Information Retrieval, Db Structures And Fs Structures Therefor (AREA)

Abstract

一种redis集群扩容方法、装置、电子设备以及存储介质,涉及电子设备技术领域。所述方法包括:在将部署在第一机器上的redis集群中的第一redis实例向第二机器迁移时,在第二机器部署并开启第二redis实例,所述第二redis实例的容量不大于指定容量(S110),将所述第二redis实例作为第一redis实例的副本加入所述redis集群,并将所述第一redis实例中的数据复制到第二redis实例中(S120),在所述redis集群中将所述第一redis实例替换为所述第二redis实例(S130)。本方法通过复制代替迁移的方式达到redis集群快速扩容的目的,提升业务的可用性。

Description

redis集群扩容方法、装置、电子设备以及存储介质 技术领域
本申请涉及电子设备技术领域,更具体地,涉及一种redis集群扩容方法、装置、电子设备以及存储介质。
背景技术
Redis是一个开放源代码(BSD许可)的内存中数据结构存储,用作数据库,缓存和消息代理。目前的redis集群分为两大阵营,一方是以codis为主的proxy+单机版redis方案,另一方是官方实现的redis cluster,无论是采用哪种方案,业界都采用redis自带的migrate命令进行迁移,迁移速度慢,影响业务的可用性。
发明内容
鉴于上述问题,本申请提出了一种redis集群扩容方法、装置、电子设备以及存储介质,以解决上述问题。
第一方面,本申请实施例提供了一种redis集群扩容方法,所述方法包括:
在将部署在第一机器上的redis集群中的第一redis实例向第二机器迁移时,在所述第二机器部署并开启第二redis实例,所述第二redis实例的容量不大于指定容量;将所述第二redis实例作为所述第一redis实例的副本加入所述redis集群,并将所述第一redis实例中的数据复制到所述第二redis实例中;在所述redis集群中将所述第一redis实例替换为所述第二redis实例。
第二方面,本申请实施例提供了一种redis集群扩容装置,所述装置包括:
第一redis实例部署模块,用于在将部署在第一机器上的redis集群中的第一redis实例向第二机器迁移时,在所述第二机器部署并开启第二redis实例,所述第二redis实例的容量不大于指定容量;第一数据复制模块,用于将所述第二redis实例作为所述第一redis实例的副本加入所述redis集群,并将所述第一redis实例中的数据复制到所述第二redis实例中;第一redis实例替换模块,用于在所述redis集群中将所述第一redis实例替换为所述第二redis实例。
第三方面,本申请实施例提供了一种电子设备,包括存储器和处理器,所述存储器耦接到所述处理器,所述存储器存储指令,当所述指令由所述处理器执行时所述处理器执行上述方法。
第四方面,本申请实施例提供了一种计算机可读取存储介质,所述计算机可读取存储介质中存储有程序代码,所述程序代码可被处理器调用执行上述方法。
本申请实施例提供的redis集群扩容方法、装置、电子设备以及存储介质,在将部署在第一机器上的redis集群中的第一redis实例向第二机器迁移时,在第二机器部署并开启第二redis实例,其中,第二redis实例的容量不大于指定容量,将第二redis实例作为第一redis实例的副本加入redis集群,并将第一redis实例中的数据复制到第二redis 实例中,在redis集群中将第一redis实例替换为第二redis实例,从而通过复制代替迁移的方式达到redis集群快速扩容的目的,提升业务的可用性。
附图说明
为了更清楚地说明本申请实施例中的技术方案,下面将对实施例描述中所需要使用的附图作简单地介绍,显而易见地,下面描述中的附图仅仅是本申请的一些实施例,对于本领域技术人员来讲,在不付出创造性劳动的前提下,还可以根据这些附图获得其它的附图。
图1示出了本申请一个实施例提供的redis集群扩容方法的流程示意图;
图2示出了本申请实施例提供的redis集群扩容的一种示意图;
图3示出了本申请实施例提供的redis集群扩容的又一种示意图;
图4示出了本申请又一个实施例提供的redis集群扩容方法的流程示意图;
图5示出了本申请再一个实施例提供的redis集群扩容方法的流程示意图;
图6示出了本申请的图5所示的redis集群扩容方法的步骤S340的流程示意图;
图7示出了本申请实施例提供的redis集群扩容的再一种示意图;
图8示出了本申请实施例提供的redis集群扩容的另一种示意图;
图9示出了本申请的图5所示的redis集群扩容方法的步骤S360的一个实施例的流程示意图;
图10示出了本申请的图5所示的redis集群扩容方法的步骤S360的又一个实施例的流程示意图;
图11示出了本申请另一个实施例提供的redis集群扩容方法的流程示意图;
图12示出了本申请的图11所示的redis集群扩容方法的步骤S430的流程示意图;
图13示出了本申请实施例提供的redis集群扩容装置的模块框图;
图14示出了本申请实施例用于执行根据本申请实施例的redis集群扩容方法的电子设备的框图;
图15示出了本申请实施例的用于保存或者携带实现根据本申请实施例的redis集群扩容方法的程序代码的存储单元。
具体实施方式
为了使本技术领域的人员更好地理解本申请方案,下面将结合本申请实施例中的附图,对本申请实施例中的技术方案进行清楚、完整地描述。
目前,redis集群分为两大阵营,一方是以codis为主的proxy+单机版redis方案,另一方是官方实现的redis cluster,无论是采用哪种方案,业界都采用redis自带的migrate命令进行迁移,根据集群方案的不同,又在migrate的基础上做了很多不同的优化。
其中,redis cluster在redis 4.0 cluster中支持指定slot在节点中移动,也支持加入空节点后根据集群节点中已存在的slot分布自动进行再分布。
其中,阿里云redis使用migrate命令分批量迁移key,为了减少迁移对redis的同步阻塞时间,阿里云针对migrate做了优化,把migrate命令拆分成两个阶段。1、把请求迁移的key 序列化后发送给目标节点,目标节点接收后返回确认;2、目标节点完成反序列化后主动通知源节点,源节点删除本地数据。这样拆分的主要目的是为了减少源节点被migrate命令同步阻塞的时间,但是需要修改redis内核,而且效果并不明显。
其中,Pre-sharding为在redis官方集群方案还没有完善之前,redis的作者antirez曾经提出来的redis集群扩容方案。业务先要定好数据分成N份,每份对应着一个redis实例,在业务存储量较小的时候,所有的redis实例部署在少数的机器上。迁移是按以下步骤进行:1、在新的虚拟机中启动备用redis实例;2、设置此实例为要移动的旧实例的副本;3、完成初始同步并且所有从属服务器都在工作时,请更改客户端的配置以使用新实例;4、使用slaveof no one选择新实例作为主实例;5、最后关闭所有旧实例;6、使用每个实例的新IP/PORT信息提升shell脚本配置。
发明人在研究中发现,对于目前业界常用的redis cluster(阿里云类似)方案,依赖redis本身的migrate命令。该命令为了保证原子性,在迁移过程中整个redis主进程都会同步阻塞,极大影响可用性。而且migrate每次只能迁移一个key,迁移速度也很慢。antirez以前提出的Pre-sharding方案采用复制替代迁移,在牺牲一定的一致性下可以有效保障redis的可用性和迁移速度,但是因为是固定份数N,迁移前后N不可变,这样N到底定为多少成为了一个难题。如果定的太小,因为单个redis终究会受物理机内存限制,最终总容量过小,无法进一步扩容;如果定的太大,在最初总机器数较小的时候会因为资源抢占导致性能不高,影响服务。而且之前提的pre-sharding主要是针对主从版集群,并没有针对当前的reids cluster方案进行说明。
针对上述技术问题,发明人经过长期的研究发现并提出了本申请实施例提供的redis集群扩容方法、装置、电子设备以及存储介质,针对官方的redis cluster方案,通过复制代替迁移的方式达到redis集群快速扩容的目的,以提升业务的可用性。其中,具体的redis集群扩容方法在后续的实施例中进行具体的说明。
请参阅图1,图1示出了本申请一个实施例提供的redis集群扩容方法的流程示意图。所述redis集群扩容方法用于通过复制代替迁移的方式达到redis集群快速扩容的目的,提升业务的可用性。在具体的实施例中,所述redis集群扩容方法应用于如图13所示的redis集群扩容装置200以及配置有所述redis集群扩容装置200的电子设备100(图14)。下面将以电子设备为例,说明本实施例的具体流程,当然,可以理解的,本实施例所应用的电子设备可以为智能手机、平板电脑、穿戴式电子设备等,在此不做限定。下面将针对图1所示的流程进行详细的阐述,所述redis集群扩容方法具体可以包括以下步骤:
步骤S110:在将部署在第一机器上的redis集群中的第一redis实例向第二机器迁移时,在所述第二机器部署并开启第二redis实例,所述第二redis实例的容量不大于指定容量。
在一些实施方式中,redis集群可以包括多个redis实例,其中,多个redis实例的容量可以全部相同,可以全部不同,也可以部分相同。于本实施例中,redis集群可以包括第一redis实例以及多个其他redis实例,其中,第一redis实例的容量可以与多个其他redis实例的容量相同,也可以与多个其他redis实例的容量不同,在此不做限定。
在一些实施方式中,redis集群中的第一redis实例部署在第一机器上,redis集群中的多个其他redis实例可以部署在第一机器上,也可以部署在不同于第一机器的其他机器上,在此不做限定。例如,假设redis集群中包括5个redis实例,且5个redis实例分别为第一redis实例、第一其他redis实例、第二其他redis实例、第三其他redis实例以及第四其他redis实例,其中,第一redis实例部署在第一机器上,第一其他redis实例、第二其他redis实例、第三其他redis实例以及第四其他redis实例可以部署在第一机器上,也可以部署在其他机器上,当第一其他redis实例、第二其他redis实例、第三其他redis实例以及第四其他redis实例部署在其他机器上时,第一其他redis实例、第二其他redis实例、第三其他redis实例以及第四其他redis实例可以全部部署在其他同一个机器上,可以部分部署在其他同一个机器上,也可以全部部署在其他不同的机器上,在此不做限定。
在一些实施方式中,在对redis集群进行扩容时,可以对redis集群包括的多个redis实例中的至少一个redis实例进行扩容。即,在对redis集群进行扩容时,可以对redis集群中的第一redis实例进行扩容处理,也可以同时对redis集群中的其他redis实例进行扩容处理,在此不做限定。在本实施例中,在对redis集群进行扩容时,以对redis集群中的第一redis实例进行扩容为例进行说明,当然,也可以对redis集群中的其他redis实例进行扩容,在此不再赘述。
在一些实施方式中,在对redis集群中的第一redis实例进行扩容时,可以将部署在第一机器上的第一redis实例向第二机器迁移,其中,第二机器与第一机器不同,且第二机器的内存可以相较于第一机器的内存更加充足,以满足第一redis实例从第一机器迁移到第二机器时的扩容目的。在本实施例中,在将部署在第一机器上的redis集群中的第一redis实例向第二机器迁移时,可以在第二机器部署并开启第二redis实例,其中,为了避免单个节点过大不好维护,可以限制在第二机器部署的第二redis实例的容量的上限值,即可以限制第二redis实例的容量不大于指定容量,在本实施例中,可以简单通过redis的max memory配置简单限制第二redis实例的容量不大于指定容量。
步骤S120:将所述第二redis实例作为所述第一redis实例的副本加入所述redis集群,并将所述第一redis实例中的数据复制到所述第二redis实例中。
在一些实施方式中,在第二机器上部署并开启第二redis实例后,可以将第二redis实例作为第一redis实例的副本加入redis集群中,并将第一redis实例中的数据同步到第二redis实例中,其中,将第一redis实例中的数据同步到的第二redis实例中的方式可以包括复制、拷贝等,以实现将第一redis实例中的数据快速同步到第二redis实例中,极大的提高迁移速度。同时,redis本身不支持迁移slot的功能,需要额外编写迁移工具以执行slot的迁移,很容易因为逻辑问题导致迁移出错,本实施例采用redis本身比较成熟的复制功能代替外部程序的slot迁移逻辑,减少出错概率。再者,本实施例通过复制方式将第一redis实例中的数据同步到第二redis实例中,在复制过程中完全不影响业务的使用,可以提升业务的可用性。
在一些实施方式中,在将第一redis实例中的数据复制到第二redis实例中时,如果第一redis实例包括从节点,也可以将第一redis实例的从节点中的数据复制到第二redis实例中, 在此不做限定。
请参阅图2,图2示出了本申请实施例提供的redis集群扩容的一种示意图,在图2中,机器A可以视作第一机器,机器B可以视作第二机器,M可以视作第一redis实例,S可以视作第二redis实例,如图2所示,可以将机器A中的redis实例M中的数据复制到redis实例S中,且redis实例S相较于redis实例M的容量增大,实现了redis集群的扩容。
步骤S130:在所述redis集群中将所述第一redis实例替换为所述第二redis实例。
在一些实施方式中,在将第一redis实例中的数据复制到第二redis实例中后,可以在redis集群中将第一redis实例替换为第二redis实例,也就是说,此时,redis集群中包括第二redis实例和多个其他redis实例,从而通过将第一redis实例扩容为第二redis的方式,达到redis集群扩容的目的。
在一些实施方式中,在redis集群中将第一redis实例替换为第二redis实例之前,还可以检测第一redis实例中的数据是否完全复制到第二redis实例中,作为一种方式,可以获取第一redis实例中的数据所占的容量,并监测从第一redis实例中复制数据到第二redis实例的过程中,第二redis实例中的数据所占的容量,在复制结束时,若监测到第二redis实例中的数据所占的容量低于第一redis实例中的数据所占的容量时,可以确定第一redis实例中的数据没有完全复制到第二redis实例中,可以触发将第一redis实例中的数据重新复制到第二redis实例中的操作,或者可以触发将第一redis实例中没有复制到第二redis实例中的数据继续复制到第二redis实例中的操作,直到第二redis实例中的数据所占的容量等于第一redis实例中的数据所占的容量时,在redis集群中将第一redis实例替换为第二redis实例。
请参阅图3,图3示出了本申请实施例提供的redis集群扩容的又一种示意图,在图3中,机器A可以视作第一机器,机器B可以视作第二机器,M可以视作第一redis实例,S可以视作第二redis实例,如图3所示,可以将机器A中的redis实例M移除,将机器B中的redis实例S替换机器B中的redis实例M。
本申请一个实施例提供的redis集群扩容方法,在将部署在第一机器上的redis集群中的第一redis实例向第二机器迁移时,在第二机器部署并开启第二redis实例,其中,第二redis实例的容量不大于指定容量,将第二redis实例作为第一redis实例的副本加入redis集群,并将第一redis实例中的数据复制到第二redis实例中,在redis集群中将第一redis实例替换为第二redis实例,从而通过复制代替迁移的方式达到redis集群快速扩容的目的,提升业务的可用性。
请参阅图4,图4示出了本申请又一个实施例提供的redis集群扩容方法的流程示意图。下面将针对图4所示的流程进行详细的阐述,所述redis集群扩容方法具体可以包括以下步骤:
步骤S210:在将部署在第一机器上的redis集群中的第一redis实例向第二机器迁移时,在所述第二机器部署并开启第二redis实例,所述第二redis实例的容量不大于指定容量。
步骤S220:将所述第二redis实例作为所述第一redis实例的副本加入所述redis集群,并将所述第一redis实例中的数据复制到所述第二redis实例中。
步骤S230:在所述redis集群中将所述第一redis实例替换为所述第二redis实例。
其中,步骤S210-步骤S230的具体描述请参阅步骤S110-步骤S130,在此不再赘述。
步骤S240:在将部署在所述第二机器上的redis集群中的第二redis实例向第三机器迁移时,在所述第三机器部署并开启第三redis实例,所述第三redis实例的容量不大于指定容量。
在一些实施方式中,redis集群可以包括第二redis实例和多个其他redis实例。其中,redis集群中的第二redis实例部署在第二机器上,redis集群中的多个其他redis实例可以部署在第一机器上,可以部署在第二机器上,也可以部署在不同于第一机器和第二机器的其他机器上,在此不做限定。例如,假设redis集群中包括5个redis实例,且5个redis实例分别为第二redis实例、第一其他redis实例、第二其他redis实例、第三其他redis实例以及第四其他redis实例,其中,第二redis实例部署在第二机器上,第一其他redis实例、第二其他redis实例、第三其他redis实例以及第四其他redis实例可以部署在第一机器上、部署在第二机器上、也可以部署在其他机器上,当第一其他redis实例、第二其他redis实例、第三其他redis实例以及第四其他redis实例部署在其他机器上时,第一其他redis实例、第二其他redis实例、第三其他redis实例以及第四其他redis实例可以全部部署在其他同一个机器上,可以部分部署在其他同一个机器上,也可以全部部署在其他不同的机器上,在此不做限定。
在一些实施方式中,在对redis集群进行扩容时,可以对redis集群包括的多个redis实例中的至少一个redis实例进行扩容。即,在对redis集群进行扩容时,可以对redis集群中的第二redis实例进行扩容处理,也可以同时对redis集群中的其他redis实例进行扩容处理,在此不做限定。在本实施例中,在对redis集群进行扩容时,以对redis集群中的第二redis实例进行扩容为例进行说明,当然,也可以对redis集群中的其他redis实例进行扩容,在此不再赘述。
在一些实施方式中,在对redis集群中的第二redis实例进行扩容时,可以将部署在第二机器上的第二redis实例向第三机器迁移,其中,第三机器与第二机器不同,且第三机器的内存可以相较于第二机器的内存更加充足,以满足第二redis实例从第二机器迁移到第三机器时的扩容目的。在本实施例中,在将部署在第二机器上的redis集群中的第二redis实例向第三机器迁移时,可以在第三机器部署并开启第三redis实例,其中,为了避免单个节点过大不好维护,可以限制在第二机器部署的第三redis实例的容量的上限值,即可以限制第三redis实例的容量不大于指定容量,在本实施例中,可以简单通过redis的max memory配置简单限制第三redis实例的容量不大于指定容量。
步骤S250:将所述第三redis实例作为所述第二redis实例的副本加入所述redis集群,并将所述第二redis实例中的数据复制到所述第三redis实例中。
在一些实施方式中,在第三机器上部署并开启第三redis实例后,可以将第三redis实例作为第二redis实例的副本加入redis集群中,并将第二redis实例中的数据同步到第三redis实例中,其中,将第二redis实例中的数据同步到的第三redis实例中的方式可以包括复制、拷贝等,以实现将第二redis实例中的数据快速同步到第三redis实例中,极大的提高迁移速度。
步骤S260:在所述redis集群中将所述第二redis实例替换为所述第三redis实例。
在一些实施方式中,在将第二redis实例中的数据复制到第三redis实例中后,可以在redis集群中将第二redis实例替换为第三redis实例,也就是说,此时,redis集群中包括第三redis实例和多个其他redis实例,从而通过将第二redis实例扩容为第三redis的方式,达到redis集群扩容的目的。因此,在本实施例中,redis集群可以根据需要无限次的扩容下去,以保证业务的可用性。
在一些实施方式中,在redis集群中将第二redis实例替换为第三redis实例之前,还可以检测第二redis实例中的数据是否完全复制到第三redis实例中,作为一种方式,可以获取第二redis实例中的数据所占的容量,并监测从第二redis实例中复制数据到第三redis实例的过程中,第三redis实例中的数据所占的容量,在复制结束时,若监测到第三redis实例中的数据所占的容量低于第二redis实例中的数据所占的容量时,可以确定第二redis实例中的数据没有完全复制到第三redis实例中,可以触发将第二redis实例中的数据重新复制到第三redis实例中的操作,或者可以触发将第二redis实例中没有复制到第三redis实例中的数据继续复制到第三redis实例中的操作,直到第三redis实例中的数据所占的容量等于第二redis实例中的数据所占的容量时,在redis集群中将第二redis实例替换为第三redis实例。
本申请又一个实施例提供的redis集群扩容方法,在将部署在第一机器上的redis集群中的第一redis实例向第二机器迁移时,在第二机器部署并开启第二redis实例,其中,第二redis实例的容量不大于指定容量,将第二redis实例作为第一redis实例的副本加入redis集群,并将第一redis实例中的数据复制到第二redis实例中,在redis集群中将第一redis实例替换为第二redis实例,在将部署在第二机器上的redis集群中的第二redis实例向第三机器迁移时,在第三机器部署并开启第三redis实例,其中,第三redis实例的容量不大于指定容量,将第三redis实例作为第二redis实例的副本加入redis集群,并将第二redis实例中的数据复制到第三redis实例中,在redis集群中将第二redis实例替换为第三redis实例。相较于图1所示的redis集群扩容方法,本实施例还根据需求在不同的机器上部署redis实例,以实现redis集群的不断扩容,提升业务的可用性。
请参阅图5,图5示出了本申请再一个实施例提供的redis集群扩容方法的流程示意图。下面将针对图5所示的流程进行详细的阐述,所述redis集群扩容方法具体可以包括以下步骤:
步骤S310:在将部署在第一机器上的redis集群中的第一redis实例向第二机器迁移时,在所述第二机器部署并开启第二redis实例,所述第二redis实例的容量不大于指定容量。
步骤S320:将所述第二redis实例作为所述第一redis实例的副本加入所述redis集群,并将所述第一redis实例中的数据复制到所述第二redis实例中。
步骤S330:在所述redis集群中将所述第一redis实例替换为所述第二redis实例。
其中,步骤S310-步骤S330的具体描述请参阅步骤S110-步骤S130,在此不再赘述。
步骤S340:在将部署在第一机器上的redis集群中的第一redis实例向第二机器迁移时,在所述第二机器部署并开启第四redis实例,所述第四redis实例的容量大于指定容量。
在一些实施方式中,在将部署在第一机器上的redis集群中的第一redis实例向第二机器迁移时,可以在第二机器部署并开启第四redis实例,其中,可以根据需要,可以将第四redis实例的内存设置为临时大于指定容量,以应付突发的流量,保证业务的可用性。在一些实施方式中,在将部署在第一机器上的redis集群中的第一redis实例向第二机器迁移时,可以在第二机器部署并开启第四redis实例,第四redis实例的容量大于指定容量且不大于目标容量。其中,指定容量可以包括8G,目标容量可以包括16G。例如,该指定容量可以包括8G,第四实例的容量可以设置为16G,以应用在将第一redis实例中的数据复制到第四redis实例的过程中,如果第一redis实例中的数据大于8G(例如为10G)时,导致第四redis实例无法存储的情况。
请参阅图6,图6示出了本申请的图5所示的redis集群扩容方法的步骤S340的流程示意图。下面将针对图6所示的流程进行详细的阐述,所述方法具体可以包括以下步骤:
步骤S341:在将部署在所述第一机器上的redis集群中的第一redis实例向所述第二机器迁移时,获取所述第一redis实例中的数据所占的容量。
在一些实施方式中,在将部署在第一机器上的redis集群中的第一redis实例向第二机器迁移时,可以获取第一redis实例中的数据所占的容量,以根据第一redis实例中的数据所占的容量确定在第二器件上部署的redis实例的容量。
步骤S342:当所述第一redis实例中的数据所占的容量大于指定容量时,在所述第二机器部署并开启第四redis实例,所述第四redis实例的容量大于所述第一redis实例中的数据所占的容量。
在一些实施方式中,当获取到第一redis实例中的数据所占的容量大于指定容量时,可以在第二机器部署并开启第四redis实例,其中,第四redis实例的容量大于第一redis实例中的额数据所占的容量。例如,指定容量为8G,当第一redis实例中的数据所占的容量为10G时,可以在第二机器部署并开启容量大于10G的第四redis实例,如在第二机器部署并开启容量为16G的第四redis实例,以保证业务的可用性。
在一些实施方式中,当获取到第一redis实例中的数据所占的容量不大于指定容量时,可以在第二机器部署并开启第二redis实例,其中,第二redis实例的容量不大于指定容量。例如,指定容量为8G,当第一redis实例中的数据所占的额容量为6G时,可以在第二机器部署并开启容量不大于8G的第二redis实例,如在第二机器部署并开启容量为8G的第二redis实例,以避免单个节点过大不好维护。
步骤S350:将所述第四redis实例作为所述第一redis实例的副本加入所述redis集群,并将所述第一redis实例中的数据复制到所述第四redis实例中。
在一些实施方式中,在第二机器上部署并开启第四redis实例后,可以将第四redis实例作为第一redis实例的副本加入redis集群中,并将第一redis实例中的数据同步到第四redis实例中,其中,将第一redis实例中的数据同步到的第四redis实例中的方式可以包括复制、拷贝等,以实现将第一redis实例中的数据快速同步到第四redis实例中,极大的提高迁移速 度。
步骤S360:将所述第四redis实例进行分裂处理,获得多个第五redis实例,其中,所述多个第五redis实例中的每个第五redis实例均不大于指定容量。
在一些实施方式中,由于第四redis实例的容量大于指定容量,因此,第四redis实例的容量较大,为了避免单个节点过大不好维护的问题,在将第一redis实例中的数据复制到第四redis实例之后,可以将第四redis实例进行分裂处理,以将第四redis实例分裂为容量较小的多个第五redis实例,其中,多个第五redis实例中的每个第五redis实例的容量均不大于指定容量。作为一种方式,可以通过max memory配置多个第五redis实例中的每个第五redis实例的内存占用上限不大于指定容量。
在一些实施方式中,对第四redis实例进行分裂获得的多个第五redis实例的容量可以相等,也可以不相等。其中,当多个第五redis实例的容量相等时,可以将第四redis实例按第五redis实例的数据进行容量均分,例如,当第四redis实例的容量为16G,指定容量为8G时,若需要将第四redis实例分裂为2个第五redis实例,则可以将第四redis实例均分为2个容量为8G的第五redis实例;若需要将第四redis均分为4个第五redis实例,则可以将第四redis实例均分为4个容量为4G的第五redis实例。当多个第五redis实例的容量不相等时,可以将第四redis实例按指定容量进行划分,例如,当第四redis实例的容量为23G,指定容量为8G时,若需要将第四redis实例分裂为3个第五redis实例,则可以将第四redis实例分裂为容量为8G的第五redis实例A,容量为8G的第五redis实例B以及容量为7G的第五redis实例C,在此不做限定。
其中,将第四redis实例进行分裂处理,获得多个第五redis实例可以包括:通过slot迁移将第四redis实例进行分裂处理,获得多个第五redis实例。
其中,分裂操作主要是为了保证redis集群后续可以继续使用同样的方式进行扩容,其执行与否并不影响redis集群的使用,因此该操作可以根据需要安排在业务请求量较小的时间段进行,避免影响业务的可用性。
请参阅图7,图7示出了本申请实施例提供的redis集群扩容的再一种示意图,在图7中,机器A可以视作第一机器,机器B可以视作第二机器,在第四redis实例的容量(16G)大于指定容量(8G)时,可以通过slot迁移将第四redis实例进行分裂处理,获得2个第五redis实例,如图8所示。
请参阅图9,图9示出了本申请的图5所示的redis集群扩容方法的步骤S360的一个实施例的流程示意图。下面将针对图9所示的流程进行详细的阐述,所述方法具体可以包括以下步骤:
步骤S361A:获取当前业务请求量。
在本实施例中,可以获取当前业务请求量。在一些实施方式中,可以实时获取当前业务请求量、可以按预设时间间隔获取当前业务请求量、可以按预设时间点获取当前业务请求量、也可以根据其他预设规则获取当前业务请求量,在此不做限定。
步骤S362A:当所述当前业务请求量小于指定请求量时,将所述第四redis实例进行分 裂处理,获得所述多个第五redis实例。
在一些实施方式中,可以预先设置并存储指定请求量,该指定请求量用于作为当前业务请求量的判断依据。因此,在本实施例中,在获取当前业务请求量后,可以将当前业务请求量与指定请求量进行比较,以判断当前业务请求量是否小于指定请求量,其中,当判断结果表征当前业务请求量小于指定请求量时,表征当前业务请求量较小,即使对第四redis实例进行分裂处理也不会影响业务,因此,可以将第四redis实例进行分裂处理,获得多个第五redis实例;当判断结果表征当前业务请求量不小于指定请求量时,表征当前业务请求量较大,对第四redis实例进行分裂处理会影响业务,因此,可以继续对当前业务请求量进行获取,直到获取到当前业务请求量小于指定请求量。
请参阅图10,图10示出了本申请的图5所示的redis集群扩容方法的步骤S360的又一个实施例的流程示意图。下面将针对图10所示的流程进行详细的阐述,所述方法具体可以包括以下步骤:
步骤S361B:获取当前时间。
在本实施例中,可以获取当前时间。在一些实施方式中,可以实时获取当前时间、可以按预设时间间隔获取当前时间、可以按预设时间点获取当前时间、也可以根据其他预设规则获取当前时间,在此不做限定。
步骤S362B:当所述当前时间处于指定时间段时,将所述第四redis实例进行分裂处理,获得所述多个第五redis实例。
在一些实施方式中,可以预先设置并存储指定请求量,该指定请求量用于作为当前业务请求量的判断依据。因此,在本实施例中,在获取当前业务请求量后,可以将当前业务请求量与指定请求量进行比较,以判断当前业务请求量是否小于指定请求量,其中,当判断结果表征当前业务请求量小于指定请求量时,表征当前业务请求量较小,即使对第四redis实例进行分裂处理也不会影响业务,因此,可以将第四redis实例进行分裂处理,获得多个第五redis实例;当判断结果表征当前业务请求量不小于指定请求量时,表征当前业务请求量较大,对第四redis实例进行分裂处理会影响业务,因此,可以继续对当前业务请求量进行获取,直到获取到当前业务请求量小于指定请求量。
步骤S370:在所述redis集群中将所述第一redis实例替换为所述多个第五redis实例。
在一些实施方式中,在获得多个第五redis实例后,可以在redis集群中将第一redis实例替换为多个第五redis实例,也就是说,此时,redis集群中包括多个第五redis实例和多个其他redis实例,从而通过将第一redis实例扩容为多个第五redis的方式,达到redis集群扩容的目的。
本申请再一个实施例提供的redis集群扩容方法,在将部署在第一机器上的redis集群中的第一redis实例向第二机器迁移时,在第二机器部署并开启第二redis实例,其中,第二redis实例的容量不大于指定容量,将第二redis实例作为第一redis实例的副本加入redis集群,并将第一redis实例中的数据复制到第二redis实例中,在redis集群中将第一redis实例替换为第二redis实例,在将部署在第一机器上的redis集群中的第一redis实例 向第二机器迁移时,在第二机器上部署并开启第四redis实例,第四redis实例的容量大于指定容量,将第四redis实例作为第一redis实例的副本加入redis集群,并将第一redis实例中的数据复制到第四redis实例中,将第四redis实例进行分裂处理,获得多个第五实例,多个第五实例中的每个第五实例均不大于指定容量,在redis集群中将第一redis实例替换为多个第五redis实例。相较于图1所示的redis集群扩容方法,本实施例还临时部署大于指定容量的实例以应用突发的流量,提升业务的可用性。
请参阅图11,图11示出了本申请另一个实施例提供的redis集群扩容方法的流程示意图。下面将针对图11所示的流程进行详细的阐述,所述redis集群扩容方法具体可以包括以下步骤:
步骤S410:在将部署在第一机器上的redis集群中的第一redis实例向第二机器迁移时,在所述第二机器部署并开启第二redis实例,所述第二redis实例的容量不大于指定容量。
步骤S420:将所述第二redis实例作为所述第一redis实例的副本加入所述redis集群,并将所述第一redis实例中的数据复制到所述第二redis实例中。
其中,步骤S410-步骤S420的具体描述请参阅步骤S110-步骤S120,在此不再赘述。
步骤S430:在所述redis集群中将所述第二redis实例提升为主节点,并在所述redis集群中移除所述第一redis实例。
在本实施例中,在redis集群中将第一redis实例替换为第二redis实例的方式可以为:在redis集群中将第二redis实例提升为主节点,并在redis集群中移除第一redis实例。在一些实施方式中,可以通过cluster failover在redis集群中将第二redis实例提升为主节点。在一些实施方式中,可以通过cluster forget在redis集群中移除第一redis实例。
请参阅图12,图12示出了本申请的图11所示的redis集群扩容方法的步骤S430的流程示意图。下面将针对图12所示的流程进行详细的阐述,所述方法具体可以包括以下步骤:
步骤S431:在所述redis集群中将所述第二redis实例提升为主节点,并在所述redis集群中关闭所述第一redis实例。
在一些实施方式中,在redis集群中将第一redis实例替换为第二redis实例时,可以在redis集群中将第二redis实例提升为主节点,并在redis集群中关闭第一redis实例。
步骤S432:在所述redis集群中移除关闭后的所述第一redis实例。
在一些实施方式中,在redis集群中关闭第一redis实例后,可以在redis集群中将关闭后的第一redis实例移除。
在一些实施方式中,如果第一redis实例包括从节点,则在redis集群中将第一redis实例移除时,也将第一redis实例的从节点移除。
本申请另一个实施例提供的redis集群扩容方法,在将部署在第一机器上的redis集群中的第一redis实例向第二机器迁移时,在第二机器部署并开启第二redis实例,其中,第二redis实例的容量不大于指定容量,将第二redis实例作为第一redis实例的副本加入redis集群,并将第一redis实例中的数据复制到第二redis实例中,在redis集群中将第二 redis实例提升为主节点,并在redis集群中移除第一redis实例。相较于图1所示的redis集群扩容方法,本实施例还通过提升第二redis实例为主节点并移除第一redis实例的方式实现redis集群的扩容,提升redis集群扩容的便捷性。
请参阅图13,图13示出了本申请实施例提供的redis集群扩容装置200的模块框图,下面将针对图13所示的框图进行阐述,所述redis集群扩容装置200包括:第一redis实例部署模块210、第一数据复制模块220以及第一redis实例替换模块230,其中:
第一redis实例部署模块210,用于在将部署在第一机器上的redis集群中的第一redis实例向第二机器迁移时,在所述第二机器部署并开启第二redis实例,所述第二redis实例的容量不大于指定容量。
第一数据复制模块220,用于将所述第二redis实例作为所述第一redis实例的副本加入所述redis集群,并将所述第一redis实例中的数据复制到所述第二redis实例中。
第一redis实例替换模块230,用于在所述redis集群中将所述第一redis实例替换为所述第二redis实例。
进一步地,所述redis实例替换模块230包括:
redis实例提升子模块,用于在所述redis集群中将所述第二redis实例提升为主节点,并在所述redis集群中移除所述第一redis实例。
进一步地,所述redis实例提升子模块包括:redis实例提升单元和redis实例移除单元,其中:
第一redis实例提升单元,用于在所述redis集群中将所述第二redis实例提升为主节点,并在所述redis集群中关闭所述第一redis实例。
redis实例移除单元,用于在所述redis集群中移除关闭后的所述第一redis实例。
进一步地,所述第一redis实例包括从节点,所述redis实例提升子模块包括:第二redis实例提升单元,其中:
第二redis实例提升单元,用于在所述redis集群中将所述第二redis实例提升为主节点,并在所述redis集群中移除所述第一redis实例和所述第一redis实例的从节点。
进一步地,所述redis实例提升子模块包括:第三redis实例提升单元,其中:
第三redis实例提升单元,用于通过cluster failover在所述redis集群中将所述第二redis实例提升为主节点。
进一步地,所述redis实例提升模块包括:实例移除单元,其中:
实例移除单元,用于通过cluster forget在所述redis集群中移除所述第一redis实例。
进一步地,所述redis集群扩容装置200还包括:第二redis实例部署模块、第二数据复制模块以及第二redis实例替换模块,其中:
第二redis实例部署模块,用于在将部署在所述第二机器上的redis集群中的第二redis实例向第三机器迁移时,在所述第三机器部署并开启第三redis实例,所述第三redis实例的容量不大于指定容量;。
第二数据复制模块,用于将所述第三redis实例作为所述第二redis实例的副本加入所述 redis集群,并将所述第二redis实例中的数据复制到所述第三redis实例中。
第二redis实例替换模块,用于在所述redis集群中将所述第二redis实例替换为所述第三redis实例。
进一步地,所述redis集群扩容装置200还包括:第三redis实例部署模块、第三数据复制模块、redis实例分裂模块以及第三redis实例替换模块,其中:
第三redis实例部署模块,用于在将部署在第一机器上的redis集群中的第一redis实例向第二机器迁移时,在所述第二机器部署并开启第四redis实例,所述第四redis实例的容量大于指定容量。
进一步地,所述第三redis实例部署模块包括:容量获取子模块和第三redis实例部署子模块,其中:
容量获取子模块,用于在将部署在所述第一机器上的redis集群中的第一redis实例向所述第二机器迁移时,获取所述第一redis实例中的数据所占的容量。
第一redis实例部署子模块,用于当所述第一redis实例中的数据所占的容量大于指定容量时,在所述第二机器部署并开启第四redis实例,所述第四redis实例的容量大于所述第一redis实例中的数据所占的容量。
进一步地,所述第三redis实例部署模块包括:第二redis实例部署子模块,其中:
第二redis实例部署子模块,用于在将部署在所述第一机器上的redis集群中的第一redis实例向第二机器迁移时,在所述第二机器部署并开启第四redis实例,所述第四redis实例的容量大于指定容量且不大于目标容量。
第三数据复制模块,用于将所述第四redis实例作为所述第一redis实例的副本加入所述redis集群,并将所述第一redis实例中的数据复制到所述第四redis实例中。
redis实例分裂模块,用于将所述第四redis实例进行分裂处理,获得多个第五redis实例,其中,所述多个第五redis实例中的每个第五redis实例均不大于指定容量。
进一步地,所述redis实例分裂模块包括:第一redis实例分裂子模块,其中:
第一redis实例分裂子模块,用于通过slot迁移对所述第四redis实例进行分裂处理,获得所述多个第五redis实例。
进一步地,所述redis实例分裂模块包括:业务请求量获取子模块和第二redis实例分裂子模块,其中:
业务请求量获取子模块,用于获取当前业务请求量。
第二redis实例分裂子模块,用于当所述当前业务请求量小于指定请求量时,将所述第四redis实例进行分裂处理,获得所述多个第五redis实例。
进一步地,所述redis实例分裂模块包括:当前时间获取子模块和第三redis实例分裂子模块,其中:
当前时间获取子模块,用于获取当前时间。
第三redis实例分裂子模块,用于当所述当前时间处于指定时间段时,将所述第四redis实例进行分裂处理,获得所述多个第五redis实例。
进一步地,所述redis实例分裂模块包括:第四redis实例分裂子模块,其中:
第四redis实例分裂子模块,用于通过max memory配置所述多个第五redis实例中的每个第五redis实例的内存占用上限不大于所述指定容量。
第三redis实例替换模块,用于第三在所述redis集群中将所述第一redis实例替换为所述多个第五redis实例。
所属领域的技术人员可以清楚地了解到,为描述的方便和简洁,上述描述装置和模块的具体工作过程,可以参考前述方法实施例中的对应过程,在此不再赘述。
在本申请所提供的几个实施例中,模块相互之间的耦合可以是电性,机械或其它形式的耦合。
另外,在本申请各个实施例中的各功能模块可以集成在一个处理模块中,也可以是各个模块单独物理存在,也可以两个或两个以上模块集成在一个模块中。上述集成的模块既可以采用硬件的形式实现,也可以采用软件功能模块的形式实现。
请参阅图14,其示出了本申请实施例提供的一种电子设备100的结构框图。该电子设备100可以是智能手机、平板电脑、电子书等能够运行应用程序的电子设备。本申请中的电子设备100可以包括一个或多个如下部件:处理器110、存储器120以及一个或多个应用程序,其中一个或多个应用程序可以被存储在存储器120中并被配置为由一个或多个处理器110执行,一个或多个程序配置用于执行如前述方法实施例所描述的方法。
其中,处理器110可以包括一个或者多个处理核。处理器110利用各种接口和线路连接整个电子设备100内的各个部分,通过运行或执行存储在存储器120内的指令、程序、代码集或指令集,以及调用存储在存储器120内的数据,执行电子设备100的各种功能和处理数据。可选地,处理器110可以采用数字信号处理(Digital Signal Processing,DSP)、现场可编程门阵列(Field-Programmable Gate Array,FPGA)、可编程逻辑阵列(Programmable Logic Array,PLA)中的至少一种硬件形式来实现。处理器110可集成中央处理器(Central Processing Unit,CPU)、图形处理器(Graphics Processing Unit,GPU)和调制解调器等中的一种或几种的组合。其中,CPU主要处理操作系统、用户界面和应用程序等;GPU用于负责待显示内容的渲染和绘制;调制解调器用于处理无线通信。可以理解的是,上述调制解调器也可以不集成到处理器110中,单独通过一块通信芯片进行实现。
存储器120可以包括随机存储器(Random Access Memory,RAM),也可以包括只读存储器(Read-Only Memory)。存储器120可用于存储指令、程序、代码、代码集或指令集。存储器120可包括存储程序区和存储数据区,其中,存储程序区可存储用于实现操作系统的指令、用于实现至少一个功能的指令(比如触控功能、声音播放功能、图像播放功能等)、用于实现下述各个方法实施例的指令等。存储数据区还可以存储电子设备100在使用中所创建的数据(比如电话本、音视频数据、聊天记录数据)等。
请参阅图15,其示出了本申请实施例提供的一种计算机可读存储介质的结构框图。该计算机可读介质300中存储有程序代码,所述程序代码可被处理器调用执行上述方法 实施例中所描述的方法。
计算机可读存储介质300可以是诸如闪存、EEPROM(电可擦除可编程只读存储器)、EPROM、硬盘或者ROM之类的电子存储器。可选地,计算机可读存储介质300包括非易失性计算机可读介质(non-transitory computer-readable storage medium)。计算机可读存储介质300具有执行上述方法中的任何方法步骤的程序代码310的存储空间。这些程序代码可以从一个或者多个计算机程序产品中读出或者写入到这一个或者多个计算机程序产品中。程序代码310可以例如以适当形式进行压缩。
综上所述,本申请实施例提供的redis集群扩容方法、装置、电子设备以及存储介质,在将部署在第一机器上的redis集群中的第一redis实例向第二机器迁移时,在第二机器部署并开启第二redis实例,其中,第二redis实例的容量不大于指定容量,将第二redis实例作为第一redis实例的副本加入redis集群,并将第一redis实例中的数据复制到第二redis实例中,在redis集群中将第一redis实例替换为第二redis实例,从而通过复制代替迁移的方式达到redis集群快速扩容的目的,提升业务的可用性。
最后应说明的是:以上实施例仅用以说明本申请的技术方案,而非对其限制;尽管参照前述实施例对本申请进行了详细的说明,本领域的普通技术人员当理解:其依然可以对前述各实施例所记载的技术方案进行修改,或者对其中部分技术特征进行等同替换;而这些修改或者替换,并不驱使相应技术方案的本质脱离本申请各实施例技术方案的精神和范围。

Claims (20)

  1. 一种redis集群扩容方法,其特征在于,所述方法包括:
    在将部署在第一机器上的redis集群中的第一redis实例向第二机器迁移时,在所述第二机器部署并开启第二redis实例,所述第二redis实例的容量不大于指定容量;
    将所述第二redis实例作为所述第一redis实例的副本加入所述redis集群,并将所述第一redis实例中的数据复制到所述第二redis实例中;
    在所述redis集群中将所述第一redis实例替换为所述第二redis实例。
  2. 根据权利要求1所述的方法,其特征在于,所述在所述redis集群中将所述第一redis实例替换为所述第二redis实例之后,还包括:
    在将部署在所述第二机器上的redis集群中的第二redis实例向第三机器迁移时,在所述第三机器部署并开启第三redis实例,所述第三redis实例的容量不大于指定容量;
    将所述第三redis实例作为所述第二redis实例的副本加入所述redis集群,并将所述第二redis实例中的数据复制到所述第三redis实例中;
    在所述redis集群中将所述第二redis实例替换为所述第三redis实例。
  3. 根据权利要求1或2所述的方法,其特征在于,所述方法还包括:
    在将部署在第一机器上的redis集群中的第一redis实例向第二机器迁移时,在所述第二机器部署并开启第四redis实例,所述第四redis实例的容量大于指定容量;
    将所述第四redis实例作为所述第一redis实例的副本加入所述redis集群,并将所述第一redis实例中的数据复制到所述第四redis实例中;
    将所述第四redis实例进行分裂处理,获得多个第五redis实例,其中,所述多个第五redis实例中的每个第五redis实例均不大于指定容量;
    在所述redis集群中将所述第一redis实例替换为所述多个第五redis实例。
  4. 根据权利要求3所述的方法,其特征在于,所述将所述第四redis实例进行分裂处理,获得多个第五redis实例,包括:
    通过slot迁移对所述第四redis实例进行分裂处理,获得所述多个第五redis实例。
  5. 根据权利要求3或4所述的方法,其特征在于,所述将所述第四redis实例进行分裂处理,获得多个第五redis实例,包括:
    获取当前业务请求量;
    当所述当前业务请求量小于指定请求量时,将所述第四redis实例进行分裂处理,获得所述多个第五redis实例。
  6. 根据权利要求3-5任一项所述的方法,其特征在于,所述将所述第四redis实例进行分裂处理,获得多个第五redis实例,包括:
    获取当前时间;
    当所述当前时间处于指定时间段时,将所述第四redis实例进行分裂处理,获得所述多个第五redis实例。
  7. 根据权利要求3-6任一项所述的方法,其特征在于,所述将所述第四redis实例进行分裂处理,获得多个第五redis实例之后,还包括:
    通过max memory配置所述多个第五redis实例中的每个第五redis实例的内存占用上限不大于所述指定容量。
  8. 根据权利要求3-7任一项所述的方法,其特征在于,所述在将部署在第一机器上的redis集群中的第一redis实例向第二机器迁移时,在所述第二机器部署并开启第四redis实例,包括:
    在将部署在所述第一机器上的redis集群中的第一redis实例向所述第二机器迁移时,获取所述第一redis实例中的数据所占的容量;
    当所述第一redis实例中的数据所占的容量大于指定容量时,在所述第二机器部署并开启第四redis实例,所述第四redis实例的容量大于所述第一redis实例中的数据所占的容量。
  9. 根据权利要求3-8任一项所述的方法,其特征在于,所述在将部署在第一机器上的redis集群中的第一redis实例向第二机器迁移时,在所述第二机器部署并开启第四redis实例,包括:
    在将部署在所述第一机器上的redis集群中的第一redis实例向第二机器迁移时,在所述第二机器部署并开启第四redis实例,所述第四redis实例的容量大于指定容量且不大于目标容量。
  10. 根据权利要求9所述的方法,其特征在于,所述指定容量包括8G,所述目标容量包括16G。
  11. 根据权利要求1-10任一项所述的方法,其特征在于,所述在所述redis集群中将所述第一redis实例替换为所述第二redis实例,包括:
    在所述redis集群中将所述第二redis实例提升为主节点,并在所述redis集群中移除所述第一redis实例。
  12. 根据权利要求11所述的方法,其特征在于,所述在所述redis集群中将所述第二redis实例提升为主节点,并在所述redis集群中移除所述第一redis实例,包括:
    在所述redis集群中将所述第二redis实例提升为主节点,并在所述redis集群中关闭所述第一redis实例;
    在所述redis集群中移除关闭后的所述第一redis实例。
  13. 根据权利要求11或12所述的方法,其特征在于,所述第一redis实例包括从节点,所述在所述redis集群中将所述第二redis实例提升为主节点,并在所述redis集群中移除所述第一redis实例,包括:
    在所述redis集群中将所述第二redis实例提升为主节点,并在所述redis集群中移除所述第一redis实例和所述第一redis实例的从节点。
  14. 根据权利要求11-13任一项所述的方法,其特征在于,所述在所述redis集群中将所述第二redis实例提升为主节点,包括:
    通过cluster failover在所述redis集群中将所述第二redis实例提升为主节点。
  15. 根据权利要求11-14任一项所述的方法,其特征在于,所述在所述redis集群中移除所述第一redis实例,包括:
    通过cluster forget在所述redis集群中移除所述第一redis实例。
  16. 一种redis集群扩容装置,其特征在于,所述装置包括:
    第一redis实例部署模块,用于在将部署在第一机器上的redis集群中的第一redis实例向第二机器迁移时,在所述第二机器部署并开启第二redis实例,所述第二redis实例的容量不大于指定容量;
    第一数据复制模块,用于将所述第二redis实例作为所述第一redis实例的副本加入所述redis集群,并将所述第一redis实例中的数据复制到所述第二redis实例中;
    第一redis实例替换模块,用于在所述redis集群中将所述第一redis实例替换为所述第二redis实例。
  17. 根据权利要求16所述的装置,其特征在于,所述装置还包括:
    第二redis实例部署模块,用于在将部署在所述第二机器上的redis集群中的第二redis实例向第三机器迁移时,在所述第三机器部署并开启第三redis实例,所述第三redis实例的容量不大于指定容量;
    第二数据复制模块,用于将所述第三redis实例作为所述第二redis实例的副本加入所述redis集群,并将所述第二redis实例中的数据复制到所述第三redis实例中;
    第二redis实例替换模块,用于在所述redis集群中将所述第二redis实例替换为所述第三redis实例。
  18. 根据权利要求16或17所述的装置,其特征在于,所述装置还包括:
    第三redis实例部署模块,用于在将部署在第一机器上的redis集群中的第一redis实例向第二机器迁移时,在所述第二机器部署并开启第四redis实例,所述第四redis实例的容量大于指定容量;
    第三数据复制模块,用于将所述第四redis实例作为所述第一redis实例的副本加入所述redis集群,并将所述第一redis实例中的数据复制到所述第四redis实例中;
    redis实例分裂模块,用于将所述第四redis实例进行分裂处理,获得多个第五redis实例,其中,所述多个第五redis实例中的每个第五redis实例均不大于指定容量;
    第三redis实例替换模块,用于第三在所述redis集群中将所述第一redis实例替换为所述多个第五redis实例。
  19. 一种电子设备,其特征在于,包括存储器和处理器,所述存储器耦接到所述处理器,所述存储器存储指令,当所述指令由所述处理器执行时所述处理器执行如权利要求1-15任一项所述的方法。
  20. 一种计算机可读取存储介质,其特征在于,所述计算机可读取存储介质中存储有程序代码,所述程序代码可被处理器调用执行如权利要求1-15任一项所述的方法。
PCT/CN2020/076458 2020-02-24 2020-02-24 redis集群扩容方法、装置、电子设备以及存储介质 WO2021168618A1 (zh)

Priority Applications (2)

Application Number Priority Date Filing Date Title
CN202080093350.0A CN114945910A (zh) 2020-02-24 2020-02-24 redis集群扩容方法、装置、电子设备以及存储介质
PCT/CN2020/076458 WO2021168618A1 (zh) 2020-02-24 2020-02-24 redis集群扩容方法、装置、电子设备以及存储介质

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
PCT/CN2020/076458 WO2021168618A1 (zh) 2020-02-24 2020-02-24 redis集群扩容方法、装置、电子设备以及存储介质

Publications (1)

Publication Number Publication Date
WO2021168618A1 true WO2021168618A1 (zh) 2021-09-02

Family

ID=77490646

Family Applications (1)

Application Number Title Priority Date Filing Date
PCT/CN2020/076458 WO2021168618A1 (zh) 2020-02-24 2020-02-24 redis集群扩容方法、装置、电子设备以及存储介质

Country Status (2)

Country Link
CN (1) CN114945910A (zh)
WO (1) WO2021168618A1 (zh)

Citations (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN105260376A (zh) * 2015-08-17 2016-01-20 北京京东尚科信息技术有限公司 用于集群节点缩扩的方法、设备和系统
CN109656709A (zh) * 2017-10-12 2019-04-19 北京京东尚科信息技术有限公司 一种Codis集群扩容的方法和装置
CN109660576A (zh) * 2017-10-10 2019-04-19 武汉斗鱼网络科技有限公司 用户数据实时迁移方法、存储介质、电子设备及系统
CN110019503A (zh) * 2017-09-01 2019-07-16 北京京东尚科信息技术有限公司 Redis集群的扩容和/或缩容的方法及装置
US20190227727A1 (en) * 2018-01-25 2019-07-25 Vmware, Inc. System and method for speed up data rebuild in a distributed storage system with local deduplication

Patent Citations (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN105260376A (zh) * 2015-08-17 2016-01-20 北京京东尚科信息技术有限公司 用于集群节点缩扩的方法、设备和系统
CN110019503A (zh) * 2017-09-01 2019-07-16 北京京东尚科信息技术有限公司 Redis集群的扩容和/或缩容的方法及装置
CN109660576A (zh) * 2017-10-10 2019-04-19 武汉斗鱼网络科技有限公司 用户数据实时迁移方法、存储介质、电子设备及系统
CN109656709A (zh) * 2017-10-12 2019-04-19 北京京东尚科信息技术有限公司 一种Codis集群扩容的方法和装置
US20190227727A1 (en) * 2018-01-25 2019-07-25 Vmware, Inc. System and method for speed up data rebuild in a distributed storage system with local deduplication

Also Published As

Publication number Publication date
CN114945910A (zh) 2022-08-26

Similar Documents

Publication Publication Date Title
CN108628874B (zh) 迁移数据的方法、装置、电子设备和可读存储介质
US9933956B2 (en) Systems and methods for implementing stretch clusters in a virtualization environment
JP5851055B2 (ja) データ格納方法および装置
WO2018014650A1 (zh) 分布式数据库数据同步方法、相关装置及系统
WO2019001017A1 (zh) 集群间数据迁移方法、系统、服务器及计算机存储介质
JP4693540B2 (ja) データベース再構成装置、およびデータベース再構成プログラム
US11809901B2 (en) Migrating the runtime state of a container between two nodes
JP2002091938A (ja) フェールオーバを処理するシステムおよび方法
WO2018054200A1 (zh) 文件读取方法和装置
CN114466027B (zh) 一种云原生数据库服务提供方法、系统、设备及介质
WO2021184177A1 (zh) 主节点选取方法、装置、电子设备以及存储介质
CN112965951A (zh) 用于数据库中数据重分布的系统和方法
JP2021524104A (ja) マスター・スタンドバイコンテナシステム切替
KR20240046596A (ko) 딥러닝 모델의 훈련 방법, 장치, 시스템, 기기, 매체 및 컴퓨터 프로그램
CN112328365A (zh) 一种虚拟机迁移方法、装置、设备及存储介质
WO2018049879A1 (zh) 数据迁移方法及装置
WO2021168618A1 (zh) redis集群扩容方法、装置、电子设备以及存储介质
CN113448977A (zh) 基于数据库Binlog的分布式缓存更新方法及装置
CN106775846A (zh) 用于物理服务器的在线迁移的方法及装置
CN114925078A (zh) 数据更新方法、系统、电子设备及存储介质
CN111026810B (zh) 数据同步方法、装置及存储介质
CN117632457A (zh) 一种加速器调度方法及相关装置
CN111628895B (zh) 一种配置数据同步方法、装置、设备及可读存储介质
WO2021168697A1 (zh) 数据同步方法、装置、数据存储系统及计算机可读介质
JP6146092B2 (ja) 仮想化システム、仮想サーバ、仮想マシン制御方法、及び仮想マシン制御プログラム

Legal Events

Date Code Title Description
121 Ep: the epo has been informed by wipo that ep was designated in this application

Ref document number: 20922239

Country of ref document: EP

Kind code of ref document: A1

NENP Non-entry into the national phase

Ref country code: DE

32PN Ep: public notification in the ep bulletin as address of the adressee cannot be established

Free format text: NOTING OF LOSS OF RIGHTS PURSUANT TO RULE 112(1) EPC (EPO FORM 1205A DATED 27.01.2023)

122 Ep: pct application non-entry in european phase

Ref document number: 20922239

Country of ref document: EP

Kind code of ref document: A1