A cluster expansion and contraction method, device, medium and equipment based on terminal agent
Through the cluster expansion and contraction method based on the terminal agent, the problem of data imbalance and uneven load during the expansion and contraction process of the Redis cluster is solved, the cluster status change is transparent to the application, the operation complexity and cost are reduced, and the efficiency is improved Performance and flexibility.
Patent Information
- Application Number
- CN202410819844.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-06-24
- Publication Date
- 2024-09-10
- Estimated Expiration
- 2044-06-24
AI Technical Summary
During the expansion and contraction process of the existing Redis cluster, there are problems such as data imbalance, uneven load, frequent data validity verification, network congestion, and client topology reconstruction, which make the operation complex and time-consuming, affecting application performance.
Using a terminal agent-based cluster expansion and contraction method, the data slot configuration information is changed through the configuration center. The Redis terminal agent and the application-side terminal agent work together to implement data slot migration and routing management. Instruction filters are used for data migration, reducing the impact on Redis. The occupation of the main thread improves operational flexibility and transparency.
It makes cluster status changes transparent to applications, reduces Redis main thread blocking time, reduces data structure design and modification costs and code intrusiveness, and improves the flexibility of business data operations and the efficiency of expansion and contraction.
Smart Images

Figure CN118377435B
Abstract
Description
Technical Field
[0001] The present invention relates to the field of computer technology, and in particular to a cluster expansion and contraction method, device, medium and equipment based on terminal agent. Background Art
[0002] In the process of daily microservice application development, various distributed middleware are often introduced. In theory, the middleware cluster can be expanded or reduced within a certain scale. However, this expansion and reduction is only at the operation and maintenance level. In fact, it is often a heavy operation for running applications and generally requires application restart. Taking Redis as an example, the Redis community version cluster provides a solution based on data slot distribution. All data is calculated by hashing the key name to obtain a data slot number, and data slots with different numbers are assigned to different nodes. When nodes increase or decrease, data slot migration is gradually completed through background tasks.
[0003] However, the data slot migration in the prior art has the following technical problems:
[0004] 1. The data distribution algorithm of the cluster is fixed, which is prone to data imbalance, with some nodes being overloaded while other nodes being idle;
[0005] 2. Data distribution has nothing to do with business. Nodes with clustering enabled will verify data legitimacy (whether the data slot to which the node belongs is the node itself), and operations may be forwarded over the network multiple times. In addition, data that do not belong to the same slot but to the same node cannot be associated with each other.
[0006] 3. In cluster mode, coordination between cluster nodes and data rebalancing require the use of the Redis main thread, which causes longer blocking time in addition to data operations;
[0007] 4. Each data migration may cause the client to reconstruct the topology of the cluster nodes, which is a heavy operation that requires locking, time-consuming, and the application needs to wait for a response.
[0008] Therefore, there is an urgent need for a cluster expansion and contraction method based on terminal agents, which can make the cluster expansion and contraction and high availability mechanism transparent to the application system by customizing the Redis cluster management mechanism. Summary of the invention
[0009] In view of this, an object of the embodiments of the present invention is to provide a cluster expansion and contraction method, apparatus, medium and device based on terminal proxy to solve the above-mentioned problems.
[0010] To achieve the above objectives, in a first aspect, an embodiment of the present invention provides a cluster expansion and contraction method based on a terminal agent, the method comprising:
[0011] Changing the data slot configuration information through the configuration center, and sending the changed data slot configuration information to the application-side terminal proxy cluster and the Redis terminal proxy cluster;
[0012] After receiving the data slot configuration information, the Redis terminal proxy cluster parses the data slot configuration information to obtain the data slot allocation information of the current node; traverses the Redis data key name of the current node, obtains the data slot number corresponding to each Redis data key name, and executes the data slot migration instruction according to the data slot number and the data slot allocation information; and updates the execution result of the data slot migration instruction to the configuration center;
[0013] After the application-side terminal proxy cluster receives the data slot configuration information through the connection pool, it performs hash calculation on the Redis data key name in the Redis operation instruction, obtains the data slot number corresponding to the Redis data key name, obtains the Redis node corresponding to the Redis data key name according to the data slot number and the data slot configuration information, and reconstructs a single shard connection pool according to the Redis node through the connection pool. The single shard connection pool is used for the Java application client to establish a single connection with the master-slave shard of the Redis node through the single shard connection pool, and adds an instruction filter in the channel of the single connection. Through the instruction filter, data migration is performed on the data slot belonging to the migration according to the routing rule of first checking the old node and then checking the new node.
[0014] In some possible implementations, the instruction filter includes a compound instruction filter, a subscription filter, and an array filter;
[0015] The adding of the instruction filter in the channel of the single connection, and performing data migration on the data slots belonging to the migration according to the routing rule of first checking the old node and then checking the new node through the instruction filter, specifically includes:
[0016] When the client sends a Redis operation instruction through a Java application, the Redis operation instruction is parsed and the regular expression of the Redis data key name is matched through the compound instruction filter, and whether the Redis data key name is locked is determined according to the locked Redis key name list in the local memory. If the Redis data key name is locked and is still not unlocked after waiting for a preset unlocking time, the returned response information is the failure information of the corresponding instruction; when the sent Redis operation instruction involves multiple Redis data key names, if the multiple Redis data key names are located in different nodes, the compound instruction filter sends a broadcast notification of locking the Redis data key name to the application-side terminal proxy cluster, and when the application-side terminal proxy cluster receives the subscription lock broadcast notification through the subscription filter, the locked Redis data key name is stored in the locked Redis key name list in the local memory;
[0017] The client rewrites the Lua script according to the locked Redis key name list through the Java application, sends the multiple Redis data key names to the corresponding Redis nodes respectively through the compound instruction filter, and adds array header information to the return result of each Lua script;
[0018] When the array filter receives the array header information and the number of the array header information reaches the count value, a broadcast unlock notification is sent to the application-side terminal proxy cluster;
[0019] When the application-side terminal proxy cluster receives the unlocked subscription information, the unlocked Redis data key name is removed from the locked Redis key name list.
[0020] In some possible implementations, the method further includes:
[0021] Within the preset reading time, the composite instruction filter is used to implement the read operation of the same key in the local cache in a whitelist manner. When creating a single shard connection pool, the composite instruction filter is used to send a subscription change notification to the Redis node, and the subscription filter is used to match the changed Redis data key name with the Redis data key name in the whitelist, and the matching Redis data key name is removed from the whitelist.
[0022] In some possible implementations, changing the data slot distribution configuration information by the configuration center and sending the changed data slot change configuration information to the application-side terminal proxy cluster and the Redis terminal proxy cluster specifically includes:
[0023] When a new Redis master-slave-shard is added to the Redis group in the configuration center and a data slot is allocated, the source node and the target node are marked on the data slot, and a data slot migration instruction is sent to the Redis terminal proxy where the Redis node on the shard where the data slot change occurs is driven by the data change event inside the configuration center;
[0024] The configuration center updates the data slot configuration information according to the execution result of the data slot migration instruction, and sends the updated data slot configuration information to the application-side terminal proxy cluster.
[0025] In some possible implementations, the method further includes: the Redis terminal agent accesses the Redis node in a Unix domain socket manner, and receives the Redis enhancement instruction pushed by the configuration center in a whitelist filtering manner.
[0026] In some possible implementations, after receiving the data slot configuration information, the Redis terminal proxy cluster parses the data slot configuration information to obtain the data slot allocation information of the current node; traverses the Redis data key name of the current node to obtain the data slot number corresponding to each Redis data key name, and executes the data slot migration instruction according to the data slot number and the data slot allocation information; and updates the execution result of the data slot migration instruction to the configuration center, specifically including:
[0027] After receiving the data slot configuration information, the Redis terminal agent parses the data slot configuration information to obtain the data slot number interval allocated to the node;
[0028] Perform hash calculation on the Redis data key name of the node and then take the modulus to obtain the data slot number of each Redis data key name;
[0029] Determine whether the data slot number is within the data slot number interval of the current node; if the data slot number is not within the data slot number interval of the current node, mark the data slot and add it to the migration plan task list;
[0030] Looping and taking a Redis data key name from the migration plan task list, and executing a data slot migration instruction;
[0031] When the Redis data key name migration is completed, a message is sent to the configuration center to update the data slot and only mark the target node, and the migration plan task is closed.
[0032] In some possible implementations, the connection pool is deployed inside the application or is deployed independently of the application as an application-side terminal proxy;
[0033] The connection pool includes a multi-group connection pool, a group connection pool and a single-slice connection pool; the data slot configuration information is obtained from the configuration center in real time through the group connection pool, and the single-slice connection pool is distributed with different ports.
[0034] In a second aspect, an embodiment of the present invention provides a cluster expansion and contraction device based on a terminal agent, the device comprising:
[0035] A data slot configuration unit, used to change the data slot configuration information through the configuration center, and send the data slot configuration information to the application-side terminal proxy cluster and the Redis terminal proxy cluster;
[0036] The Redis terminal proxy cluster is used to parse the data slot configuration information to obtain the data slot allocation information of the current node after receiving the data slot configuration information; traverse the Redis data key name of the current node to obtain the data slot number corresponding to each Redis data key name, and execute the data slot migration instruction according to the data slot number and the data slot allocation information; and update the execution result of the data slot migration instruction to the configuration center;
[0037] The application-side terminal proxy cluster is used to perform hash calculation on the Redis data key name in the Redis operation instruction after receiving the data slot configuration information through the connection pool, obtain the data slot number corresponding to the Redis data key name, obtain the Redis node corresponding to the Redis data key name according to the data slot number and the data slot configuration information, and reconstruct a single shard connection pool according to the Redis node through the connection pool. The single shard connection pool is used for the Java application client to establish a single connection with the master-slave-shard of the Redis node through the single shard connection pool, and add an instruction filter in the channel of the single connection. Through the instruction filter, data migration is performed on the data slot belonging to the migration according to the routing rule of first checking the old node and then checking the new node.
[0038] In a third aspect, an embodiment of the present invention provides an electronic device, including:
[0039] one or more processors;
[0040] A storage device is used to store one or more programs. When the one or more programs are executed by the one or more processors, the one or more processors implement a cluster expansion and contraction method based on a terminal agent as described in any one of the first aspects.
[0041] In a fourth aspect, an embodiment of the present invention provides a computer-readable medium having a computer program stored thereon, which, when executed by a processor, implements a cluster expansion and contraction method based on a terminal agent as described in any one of the first aspects.
[0042] The above technical solution has the following beneficial effects:
[0043] In the embodiment of the present invention, since the routing is performed through the configuration center scheduling and the connection pool, the application can be regarded as accessing a single Redis node, that is, the change of the cluster state is transparent to the application;
[0044] In the embodiment of the present invention, the Redis node does not run in cluster mode, and all cluster validity checks are ineffective, thereby bringing greater flexibility to business data operations;
[0045] In the embodiment of the present invention, scheduling is performed through the configuration center and the terminal agent, Redis only executes data read and write commands, the scheduling calculation does not occupy the Redis main thread time, and the blocking time is the shortest.
[0046] In the embodiment of the present invention, the cost of designing and modifying the stock data structure is reduced by externalizing the terminal agent, and the code intrusiveness is reduced. BRIEF DESCRIPTION OF THE DRAWINGS
[0047] In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. It is obvious that the drawings described below are only some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative work.
[0048] Figure 1 It is a flow chart of a cluster expansion and contraction method based on terminal agent according to an embodiment of the present invention;
[0049] Figure 2 It is a deployment diagram of a cluster scaling method based on terminal proxy according to an embodiment of the present invention;
[0050] Figure 3 It is a structural schematic diagram of a connection pool deployment according to an embodiment of the present invention;
[0051] Figure 4 is a data migration flow chart of an embodiment of the present invention;
[0052] Figure 5 It is a functional block diagram of a cluster expansion and contraction method based on terminal agent according to an embodiment of the present invention;
[0053] Figure 6 It is a functional block diagram of an electronic device according to an embodiment of the present invention. DETAILED DESCRIPTION
[0054] Embodiments of the present disclosure will be described in more detail below with reference to the accompanying drawings. Although certain embodiments of the present disclosure are shown in the accompanying drawings, it should be understood that the present disclosure can be implemented in various forms and should not be construed as being limited to the embodiments described herein, which are instead provided for a more thorough and complete understanding of the present disclosure. It should be understood that the drawings and embodiments of the present disclosure are only for exemplary purposes and are not intended to limit the scope of protection of the present disclosure.
[0055] It should be understood that the various steps described in the method embodiments of the present disclosure may be performed in different orders and / or in parallel. In addition, the method embodiments may include additional steps and / or omit the steps shown. The scope of the present disclosure is not limited in this respect.
[0056] The term "including" and its variations used herein are open inclusions, i.e., "including but not limited to". The term "based on" means "based at least in part on". The term "one embodiment" means "at least one embodiment"; the term "another embodiment" means "at least one additional embodiment"; the term "some embodiments" means "at least some embodiments". The relevant definitions of other terms will be given in the following description.
[0057] It should be noted that the concepts such as "first" and "second" mentioned in the present disclosure are only used to distinguish different devices, modules or units, and are not used to limit the order or interdependence of the functions performed by these devices, modules or units.
[0058] It should be noted that the modifications of "one" and "plurality" mentioned in the present disclosure are illustrative rather than restrictive, and those skilled in the art should understand that unless otherwise clearly indicated in the context, it should be understood as "one or more".
[0059] The names of the messages or information exchanged between multiple devices in the embodiments of the present disclosure are only used for illustrative purposes and are not used to limit the scope of these messages or information.
[0060] Glossary:
[0061] Redis nodes: including Redis master nodes and slave nodes: the core of Redis's high availability mechanism. External applications generally only access Redis master nodes for read and write operations. Redis slave nodes are read-only. The two synchronize data through protocols. It is generally believed that the data of the two are consistent in a macro sense. Therefore, when the Redis master node is unavailable, the Redis slave node can be changed to the Redis master node to replace the work of the Redis master node. A Redis master node can have multiple Redis slave nodes.
[0062] Redis failover: When the Redis master node is unavailable, a certain mechanism is used to promote one of the slave nodes to the new master node, and the other slave nodes become slave nodes of the new master node. All clients are notified to restore services by accessing the new master node.
[0063] Redis Lua: Redis's built-in scripting language can be combined with certain business logic. Lua scripts are exclusive and can ensure atomicity, that is, the script content is either all successful or all failed, and the scripts can only be executed sequentially (only one script can be executed at the same time).
[0064] Unix Domain Socket: Unix Domain Socket, in Unix and Linux systems, is a method of inter-process communication through sock files. Since it does not go through the network, there is no delay and the data security is high.
[0065] MIGRATE: Migration command. In Redis, the MIGRATE command is used to migrate keys from one Redis instance to another. This migration command is mainly used in the Redis cluster management and data migration process to migrate the specified key and its data to the target instance by specifying the source instance, target instance, key name, and other parameters.
[0066] Figure 1 is a flow chart of a cluster expansion and contraction method based on terminal agent according to an embodiment of the present invention. Figure 2 is a deployment diagram of a cluster scaling method based on terminal proxy according to an embodiment of the present invention, such as Figure 2 As shown, in this embodiment, the client obtains the configuration information of the configuration center through the Redis connection pool inside the Java application or the Redis connection pool that is independent of the Java application and acts as an application-side terminal agent, and migrates the data in the Redis node according to the configuration information; in this embodiment, a terminal agent is added to the server where the Redis node is deployed to perform the data migration work scheduled in the background. The specific process is as follows Figure 1 As shown, the data migration method includes the following steps:
[0067] Step S11, changing the data slot configuration information through the configuration center, and sending the changed data slot configuration information to the application-side terminal proxy cluster and the Redis terminal proxy cluster.
[0068] In this embodiment, data slot attributes and algorithm attributes are added to the Redis grouping in the configuration center, and the hash algorithm of the data slot is customized through the Groovy (Groovy is a dynamic scripting language based on the Java virtual machine) script for the management of the Redis terminal proxy cluster and the connection pool routing. That is, new shard configuration information is added to the configuration center, including the address, port, and data slot range of the master node, etc., but in actual applications, it can be configured through the corresponding visual interface. In the embodiment of the present invention, since the routing is performed through the configuration center scheduling and connection pool, the application can be regarded as accessing a single Redis node, that is, the change of cluster status is transparent to the application;
[0069] Step S12, after receiving the data slot configuration information, the Redis terminal proxy cluster parses the data slot configuration information to obtain the data slot allocation information of this node; traverses the Redis data key name of this node, obtains the data slot number corresponding to each Redis data key name, and executes the data slot migration instruction according to the data slot number and the data slot allocation information; and updates the execution result of the data slot migration instruction to the configuration center.
[0070] In this embodiment, a Redis terminal agent is deployed on each Redis node server, and multiple Redis terminal agents constitute a Redis terminal agent cluster. Each Redis terminal agent obtains configuration information of data change events from the configuration center and parses the configuration information. The configuration information contains the data slot number interval of each master node. The Redis terminal agent parses the obtained configuration information and obtains the data slot number of the Redis node corresponding to the Redis terminal agent. The data slot number is an interval value.
[0071] At the same time, the Redis terminal agent traverses the key name of the data of the Redis node, calculates the data slot number corresponding to each key name through the hash sharding algorithm, and judges whether the data key name corresponding to the data slot number belongs to the Redis node according to the data slot number and the data slot number interval corresponding to the current Redis node. If it does not belong to the current Redis node, that is, the data slot number corresponding to the data key name is not in the data slot number interval of the current node, then execute the data slot migration instruction, that is, the Redis MIGRATE instruction, and update the result of the data slot migration to the configuration center.
[0072] Specifically, when the Redis terminal agent determines that a data slot needs to be migrated, it first stores the data slot to be migrated in the cache queue, starts the migration plan task, and then executes the migration instruction to start Redis key traversal (scan). When the traversal is completed (the cursor returned by the scan instruction is 0), it sends a message to the configuration center to update the data slot and only mark the new node (target node), and closes the migration plan task; Redis's MIGRATE instruction migrates the data slot in the cache queue from a certain Key in one Redis to another Redis. Its parameters include the key name of the source node, the address, port, and password of the target node, the maximum execution time of the migration instruction (the maximum migration time of the entire process of the moved key), and the strategy if there is a key-value pair with the same name on the target node (if there is already a key with the same name, there are three strategies, direct replacement, or renaming, or direct error reporting. This embodiment uses direct replacement).
[0073] In the embodiment of the present invention, the Redis node does not run in cluster mode, and all cluster validity checks are ineffective, which brings greater flexibility to business data operations; in the embodiment of the present invention, scheduling is performed through the configuration center and the terminal agent, the Redis node only executes data read and write commands, the scheduling calculation does not occupy the Redis main thread time, and the blocking time is the shortest.
[0074] Step S13, after the application-side terminal proxy cluster receives the data slot configuration information through the connection pool, it performs hash calculation on the Redis data key name in the Redis operation instruction, obtains the data slot number corresponding to the Redis data key name, obtains the Redis node corresponding to the Redis data key name according to the data slot number and the data slot configuration information, and reconstructs the single shard connection pool according to the Redis node through the connection pool. The single shard connection pool is used for the Java application client to establish a single connection with the master-slave-shard of the Redis node through the single shard connection pool, and adds an instruction filter in the channel of the single connection. Through the instruction filter, data migration is performed on the data slot belonging to the migration according to the routing rule of first checking the old node and then checking the new node.
[0075] In this embodiment, after the Redis operation instruction is decoded according to the protocol, it is an array, and its first element is the instruction. Generally, the second element of the array is the key name (special instructions are specially processed by enumeration to ensure that the key name is obtained. For example, the DEL instruction can be followed by multiple key names. It must first be converted into a Lua script call and then split by the Lua parser). The key is hashed to obtain the data slot number corresponding to each key. The configuration center is configured with configuration information for data slot allocation. The source node and the target node are marked in the configuration information. The source node refers to the data slot to be migrated from the current master node, and the target node refers to the data slot to be migrated into the current master node. According to the data slot number where the key is located, it can be determined whether the data slot needs to be migrated. For example, if the data slot number in the configuration information is the source node, then it is the data slot to be migrated from the current master node. If the data slot number is the target node, then it is the data slot to be migrated into the current master node. Then, the corresponding single shard connection pool is constructed for the Redis node to be migrated in or out through the connection pool, and the Java client accesses the Redis node through the single shard connection pool to access the master-slave shard.
[0076] In addition, this embodiment further adds an instruction filter in the channel of a single connection, and uses the instruction filter to perform data migration on the data slots belonging to the migration according to the routing rule of first checking the old node and then checking the new node.
[0077] The Redis node of the embodiment of the present invention does not actually run in cluster mode, and all cluster legitimacy checks are ineffective, which brings greater flexibility to business data operations; because the routing is performed through the configuration center scheduling and connection pool, the application can be regarded as accessing a single Redis node, that is, the change of cluster status is transparent to the application; the Redis terminal agent is scheduled by the configuration center, and the Redis node only executes data read and write commands, and the scheduling calculation does not occupy the Redis main thread time, and the blocking time is the shortest. This embodiment reduces the cost of designing and modifying the existing data structure and reduces the code intrusiveness by externalizing the terminal agent.
[0078] In some embodiments, the instruction filter in step S13 includes a compound instruction filter, a subscription filter and an array filter; when the client sends a Redis operation instruction through a Java application, the Redis operation instruction is parsed and the regular expression of the Redis data key name is matched through the compound instruction filter, and whether the Redis data key name is locked is determined according to the locked Redis key name list in the local memory. If the Redis data key name is locked and is still not unlocked after waiting for a preset unlocking time, the returned response information is the failure information of the corresponding instruction; when the sent Redis operation instruction involves multiple Redis data key names, if the multiple Redis data key names are located in different nodes, the instruction request filter sends a broadcast notification of locking the Redis data key name to the application-side terminal proxy cluster, and when the application-side terminal proxy cluster receives the subscription locking broadcast notification through the subscription filter, the locked Redis data key name is stored in the locked Redis key name list in the local memory;
[0079] The client rewrites the Lua script according to the locked Redis key name list through the Java application, sends multiple Redis data key names to the corresponding Redis nodes through the compound instruction filter, and adds array header information to the return result of each Lua script; when the array filter receives the array header information and the number of array header information reaches the count value, it sends a broadcast unlock notification to the application-side terminal proxy cluster; when the application-side terminal proxy cluster receives the unlocked subscription information, it removes the unlocked Redis data key name from the locked Redis key name list. When the instruction filter parses the request as a Lua script, it needs to send a publish instruction to operate data located on different Redis nodes, and the instruction filter mechanism is locked through the Redis terminal proxy.
[0080] Specifically, the locked key is obtained through the subscription filter, the key name is cached locally, and a match check is performed before the instruction is forwarded. If the key to be operated is locked, it is necessary to wait for the lock. When the instruction is to be sent, the compound instruction filter performs regular expression matching of the instruction and the key name, and checks the list of locked key names in the local memory. If the key is locked and is still not unlocked after waiting for 200 milliseconds for 5 times, for example, the response information returned is the failure information of the corresponding instruction. In this embodiment, the subscription filter maintains the lock list by subscribing to LUA_LOCK_* and LUA_UNLOCK_*.
[0081] In addition, when the sent instruction involves multiple Redis data key names, if the multiple Redis data key names are located in different nodes, a broadcast notification of locking the Redis data key name is sent to the application side terminal proxy cluster through the Lua script. When the application side terminal proxy cluster receives the subscription lock broadcast notification through the subscription filter, the locked Redis data key name is stored in the locked Redis key name list in the local memory. In this embodiment, because each application side terminal proxy uses the same cluster connection pool and is configured with the same node, it will take effect as long as any of its master-slave shards has a broadcast message captured by the subscription filter. Because the group connection pool is configured with the same node, there will definitely be a lock notification to all Redis nodes. By broadcasting, the Redis node is notified that the key has been locked, and no instruction access to this key is allowed. Each Redis node is connected to each Redis master-slave-shard through a single connection pool. Sending a broadcast message in any Redis is actually equivalent to all Redis terminal proxies receiving the request, that is, the Redis terminal proxy cluster will receive the request.
[0082] The client rewrites the Lua script according to the locked Redis key name list through the Java application, sends multiple Redis data key names to the corresponding Redis nodes respectively, and adds array header information to the return result of each Lua script; when the array filter receives the array header information, it sends a broadcast unlock notification to the application-side terminal proxy cluster; when the application-side terminal proxy cluster receives the unlocked subscription information, it removes the unlocked Redis data key name from the locked Redis key name list. In this embodiment, by rewriting the Lua script, the information return array can be returned, and the array filter means that when the response information is decoded into an array, the first element of the array is locked or locked (Locking), then the count of the completed locking process is performed according to the rules.
[0083] In this embodiment, by adding filters, atomic operations on related data in different data slots can be implemented. For example, the compound instruction filter can not only parse the Lua script, but also perform lock checks. In addition, the compound instruction filter also handles the operation of checking the old node first and then the new node in the migration. What it sends to the old node is actually a Lua script with an array return value, that is, this is a special compound instruction that only locks two nodes. The subscription filter can filter specific data locking notifications. The locking instruction has a fixed prefix. The subscription instruction psubscribe LUA_LOCK_* is sent from the client. For example, when it is necessary to lock a key named abc, the instruction publish LUA_LOCK_abc XXX is sent. XXX is the node flag for verification in the unlock instruction. After receiving the lock notification, the subscription filter parses the key to be locked as abc and records it locally. When it can be unlocked, the publish LUA_UNLOCK_abc XXX instruction is sent; the array filter filters the locked key list with specific header information. Specific header information means adding at least 5 elements to the front of the array, namely Locking, script count (depends on the data in Redis for global unification), number of distribution nodes, number of lock keys, and lock key list.
[0084] In this embodiment, since a single Redis instruction generally does not operate multiple key-value pairs, Lua scripts can operate multiple key-value pairs due to their atomicity. If these keys are distributed on different nodes, it is generally difficult to ensure atomicity, so this embodiment uses an instruction filter to filter the key names in the Lua script to implement a mechanism for executing Lua scripts on multiple nodes by locking. This embodiment sets a filter on a single connected channel to make the enhanced Redis cluster management transparent to the application, supplemented by a visual interface, which reduces the learning cost of application developers and operation and maintenance personnel. This embodiment uses Netty to customize the connection of Redis, and solves the problem of sticky and broken packets of TCP (Transmission Control Protocol) through a custom codec. On this basis, Netty uses a chain processor, and only a new processor is hung on the chain for instruction filtering.
[0085] In the embodiment of the present invention, by externalizing the Redis terminal agent and the application-side terminal agent, the cost of designing and modifying the existing data structure is reduced, and the code intrusiveness is reduced.
[0086] In some embodiments, the method may also include: when creating a single shard connection pool, sending a subscription change notification to the Redis node through a compound instruction filter, and matching the changed Redis data key name with the Redis data key name in the whitelist through the subscription filter, and removing the matched Redis data key name from the whitelist. Specifically, when each single shard connection pool is created, the compound instruction filter sends "psubscribe __keyspace@0__:*" to subscribe to Redis; when receiving a "PMESSAGE __keyspace@0__:" type notification, the subscription filter matches the changed key name with the key name in the read cache whitelist, and removes the key name from the whitelist if a match is found, to ensure that the cached data is up to date;
[0087] In some embodiments, the method of changing the data slot distribution configuration information through the configuration center and sending the changed data slot change configuration information to the application-side terminal proxy cluster and the Redis terminal proxy cluster specifically includes: when a new Redis master-slave-shard is added to the Redis group in the configuration center and a data slot is allocated, the source node and the target node are marked on the data slot, and a data slot migration instruction is sent to the Redis terminal proxy where the Redis node on the shard where the data slot change occurs is located, driven by the data change event inside the configuration center; the configuration center updates the data slot configuration information according to the execution result of the data slot migration instruction, and sends the updated data slot configuration information to the application-side terminal proxy cluster.
[0088] In this embodiment, new shard configuration information is added to the configuration center, including the address, port, and data slot range of the master node. In actual operation, the configuration can be performed through the corresponding visual interface. In addition, this embodiment uses the modified Nacos as the configuration center. When the configuration information of Nacos changes, it triggers a broadcast operation inside Java. In this embodiment, a listener for the event is added during the modification. When a data change event is monitored, a Redis enhancement instruction is sent to the Redis terminal agent where the Redis node on the shard where the data slot change occurs is located.
[0089] In some embodiments, the method further includes: the Redis terminal agent accesses the Redis node in the form of a Unix domain socket, and receives the Redis enhancement instructions pushed by the configuration center in the form of whitelist filtering.
[0090] In this embodiment, the terminal agent deployed on the Redis node server accesses Redis in Unix domain socket mode, and only allows the configuration center to push specific enhancement instructions externally through whitelist filtering. That is, through the configuration center address preset in the configuration file, only custom Redis enhancement instructions sent from these addresses are allowed. On the one hand, the network delay of the traversal operation is minimized, and on the other hand, security can be enhanced at the same time.
[0091] In some embodiments, in step S12, after receiving the data slot configuration information, the Redis terminal proxy cluster parses the data slot configuration to obtain the data slot number interval of the node; traverses the Redis data key name of the node, obtains the data slot number corresponding to each data key name, and executes the data slot migration instruction according to the data slot configuration information and each Redis data key name; and updates the execution result of the data slot migration instruction to the configuration center, specifically including: after receiving the data slot configuration information, the Redis terminal proxy parses the data slot configuration information to obtain the data slot number interval allocated to the node, performs a hash calculation on the Redis data key name of the node and then takes the modulus, obtains the data slot number of each Redis data key name, determines whether the data slot number is within the data slot number interval of the node, if the data slot number is not within the data slot number interval of the node, marks the data slot and adds it to the migration plan task list; loops to take out a Redis data key name from the migration plan task list and executes the data slot migration instruction; when the Redis data key name migration is completed, sends a message to the configuration center to update the data slot and only mark the target node, and closes the migration plan task.
[0092] Specifically, after receiving the Redis enhanced instruction from the configuration center, the Redis terminal agent starts the data slot migration plan task, traverses the Redis data key name for the Redis enhanced instruction, performs hash calculation on each scanned Redis data key name, obtains the data slot number corresponding to the Redis data key name, and determines whether the data slot where the Redis data key name is located is on the current node. If the data slot where the Redis data key name is located is not on the current node, determine whether the data slot number belongs to the current Redis node according to the numbering interval. If the data slot number is not in the numbering interval, mark the data slot and add it to the migration plan task list (here the data slot to be transferred is marked and placed in a cache queue); take out a Redis data key name from the migration plan task list through a loop, and execute the Redis MIGRATE instruction; when the Redis data key name traversal is completed, send an update data slot to the configuration center to only mark the target node, and close the migration plan task.
[0093] Figure 3 is a schematic diagram of a connection pool deployment structure of an embodiment of the present invention, such as Figure 3 As shown, the connection pool includes deployment inside the application or deployment as an application-side terminal proxy independently of the application; the connection pool includes multi-group connection pool, group connection pool and single shard connection pool; the configuration information is obtained from the configuration center in real time through the group connection pool, and distributed using multi-group connection pools with different ports. Each Redis master-slave shard is connected through a single shard connection pool.
[0094] The Redis connection pool for Java applications in the embodiment of the present invention is implemented by creating a multi-level Redis connection pool. Java applications are horizontally expanded and compatible with unified management of connecting different deployment modes in the same application. The unified interface is defined using Java's IRedisPool interface (IRedisPool is a class name, indicating a pool class), and a three-layer implementation class is used to implement the creation of a Redis connection pool for Java applications.
[0095] 1. Single Shard Connection Pool (SingleRedisPool)
[0096] A single shard connection pool is a connection pool for a single Redis master node. When an application operates a cluster, the final operation is only on the master node. The slave node is an automatic mechanism within the cluster to complete the synchronization of the master node data.
[0097] The connection pool is the management of connection objects. A single Redis connection is the smallest unit. A single connection pool has a Socket connection set on one side and at least one client connection object set on the other side, such as a Jedis / Lettuce / Redisson connection object, or a custom connection object. In short, it is a connection created by the application to the Redis node. A single connection object must be a Socket connection, and additional attribute variables can be added to it for management. In the three general clients mentioned here, these attribute variables are all encapsulated differently.
[0098] 2. Group Connection Pool (GroupRedisPool)
[0099] The group connection pool is a management tool for a single group of multiple master-slave shards with the same type of functions. It is responsible for the scheduling of different Redis nodes (such as failover and dynamic expansion and contraction). The master of the "master-slave shard" refers to the master node, and the slave refers to the slave node.
[0100] Single shard connection pool: corresponds to a "master-slave shard" in the cluster, but only operates the master node. When the master node fails and fails over, the Redis slave node that can replace the current Redis master node as the new Redis master node will be determined in the master-slave shard, and all connection object properties in the connection pool will be updated and switched to the new Redis master node.
[0101] In order to deal with sudden master node failures, it is necessary to subscribe to the configuration change event of the single connection pool in the configuration center. After the configuration manager listens to the configuration change event of the single connection pool, the group connection pool is based on the configuration information of the configuration change event. The type of grouping and the master node information of the single connection pool creates a single shard connection pool object for the new Redis master node. After the single shard connection pool is created, session (pairing of request information and response information in a single command execution) management is performed. Among them, the configuration center stores the configuration file information of Redis, which changes dynamically according to the health check; the application holds the top-level multi-group connection pool and the bottom-level single shard connection pool to the node connection; the two are associated and bonded through the middle-layer group connection pool.
[0102] The types of connection pool grouping (i.e., the types of master-slave shards) are divided into three types according to the Redis cluster type: single node (SINGLE), sentinel (SENTINEL), cluster (CLUSTER), and other customized types. The objects contained in the grouped connection pool are all single connection pools, which aggregate multiple single connection pools into managers for all shards of the entire Redis cluster. Based on its failover mechanism, the content of the configuration change information stored in the configuration center is executed, so that only the corresponding master node configuration information is changed.
[0103] The configuration manager listens to the configuration change events of the group configuration information in the configuration center, re-acquires the new configuration change events, filters the changed master-slave shard information, and performs a series of operations such as reconstructing the corresponding single shard connection pool, rebuilding the session, and destroying the old single shard connection pool according to the changed master-slave shard information. Since only the master-slave shard with changed configuration is updated, the process takes a very short time compared to reconstructing the entire topology and all connection pools, so that the Java program is basically unaware of the failover when calling. Among them, the shard information mainly includes the address and port number of the master node, the node information corresponding to the data slot, and the algorithm for data sharding. In addition, the group connection pool also supports dynamic routing rule configuration. Through sessions and routing rules, the business relevance of stored data is ensured, so that when multiple shards in the group are horizontally expanded, the related data is guaranteed to fall in the same shard. In this way, the characteristics of Redis are retained while maximizing horizontal expansion.
[0104] 3. MultiGroupRedisPool
[0105] The multi-group connection pool is used to distinguish different functions and manage multiple groups based on logical isolation. The objects contained in the multi-group connection pool are group connection pools, which are used to provide a single Java application with a top-level abstraction for connecting to different Redis clusters. The multi-group connection pool is the interface for applications to call the connection pool. It is used to manage all group connection pools in a unified manner. According to the information in the configuration file, the group configuration information of each group connection pool is pulled from the configuration center to create the corresponding group connection pool. The interface defines three methods for external programs to call: get connection, return connection, and destroy connection pool. Due to the object-oriented characteristics, the program calling this interface does not need to care about which layer the connection pool call is at.
[0106] In this embodiment, Redis can be accessed through the connection pool directly integrated by the application or the connection pool of the application-side terminal agent, and the migration management scheduling is performed through the configuration center, and the connection pool obtains the group connection pool configuration from the configuration center. Through the connection pool in this embodiment, the routing direction during the migration process can be controlled to achieve high availability and reconstruction of the single shard connection pool (SingleRedisPool) in the group connection pool (GroupRedisPool).
[0107] In some embodiments, during the migration of the migration data slot, the packet connection pool performs routing according to the rule of checking the source node first and then writing to the target node.
[0108] Specifically, if a piece of data does not exist in the new node (target node), it has two possibilities. One is that it does not exist in the old node (source node) and has not been migrated. This is an uncertain state, and it is not appropriate to read or write at this time. Therefore, in this embodiment, the group connection pool performs routing according to the rule of checking the source node first and then writing the target node.
[0109] Figure 4 is a data migration flow chart of an embodiment of the present invention, such as Figure 4As shown, in this embodiment, when a new Redis master-slave-shard is added to the Redis group in the configuration center and a data slot is allocated, the data slot is marked as the source node and the target node, and driven by the data change event inside the configuration center, a data migration instruction is sent to the Redis terminal agent deployed on the Redis node server on the shard where the data slot change occurs; the client obtains the configuration information of the configuration center through the Redis connection pool inside the Java application or the Redis connection pool that is independent of the Java application and is an application-side terminal agent, and migrates the data in the Redis node according to the configuration information; this embodiment adds a terminal agent (agent) on the server where the Redis node is deployed, and performs the data migration work scheduled in the background through the terminal agent (agent). The specific data migration process is as follows:
[0110] S1, obtain configuration information: The Redis terminal agent obtains the configuration information of the data change event from the configuration center, parses the configuration information, and obtains the number interval of the data slot corresponding to the current Redis node;
[0111] S2, execute the sharding algorithm: the Redis terminal agent traverses the Redis data key name, and performs hash calculation on the Redis data key name according to the custom sharding algorithm, and then takes the modulus to obtain the data slot number corresponding to each Redis data key name;
[0112] S3, determine whether the data slot number belongs to the current Redis node: determine whether the data slot number belongs to the current Redis node according to the number interval. If the data slot number is not in the number interval, that is, it does not belong to the current Redis node, write the data slot into the cache queue. In this embodiment, when the cursor number is 0, a round of traversal (scan) is completed. Because each traversal will have a delay, this embodiment puts the key corresponding to the data slot to be migrated into the cache queue;
[0113] S4, execute data migration: The Redis terminal agent uses the migration (MIGRATE) command to perform migration work and migrate the keys corresponding to the data slots in the cache queue.
[0114] Since the Redis terminal proxy of this embodiment directly traverses locally, the migration efficiency can be improved.
[0115] S5, obtaining configuration information: the application-side terminal agent obtains configuration information from the configuration center through the group connection pool;
[0116] S6: Execute the sharding algorithm: perform hash calculation on the Redis data key name in the Redis operation instruction according to the custom sharding algorithm, obtain the data slot number corresponding to each Redis data key name, obtain the Redis node where the Redis data key name is located according to the configuration information, reconstruct a single sharding connection pool according to the Redis node where it is located, and perform enhanced processing on the Redis instruction on the single connection channel;
[0117] S7, execute the data slot rule: the group connection pool routes according to the rule of checking the source node first and then writing the target node; when the current Redis master node in the master-slave shard accessed by the Java client fails, after determining the Redis slave node that can replace the current Redis master node as the new Redis master node in the master-slave shard, migrate the data slot from the failed master node to the slave node that can serve as the new master node according to the data slot rule to complete the data migration.
[0118] In addition, in this embodiment, after the data migration is completed, the Redis terminal agent sends an update data slot message to the configuration center. The message only updates the new node (ie, the target node) in the data slot, thereby completing the data slot migration.
[0119] In the embodiment of the present invention, both expansion and reduction involve data slot migration, the only difference being whether new master-slave shards are added. Reduction is to migrate all the data slots on a group of master-slave shards, and then delete the master-slave shards from the cluster configuration, while expansion is to add master-slave shards and reallocate the data slots of the entire Redis node. Since the embodiment of the present invention only updates the master-slave shards whose configuration has changed, the process takes a very short time compared to rebuilding the entire topology and all connection pools, so that the Java program is basically unaware of the failover when calling it.
[0120] The embodiment of the present invention refers to the concept of data slots in the community version, and then puts time-consuming operations (whether it is time-consuming operations of Redis nodes or client SDKs (Software Development Kits)) on external terminal agents. At this time, since Redis is not running in cluster mode, there is no need to perform data legitimacy checks. There are terminal agents on both the Redis side and the application side, but the terminal agents on both sides are not on the same call access link. The Redis side mainly solves traversal enhancement and health checks, docking scheduling management, and the client will not access it, while the application-side agent is responsible for the routing of multiple shards and data slots. Because in an original state, if you start to migrate the data slot, there is an intermediate process because it is a key-by-key migration, and after all the data is migrated, the new data slot state must be updated. This embodiment supports data slot migration on the terminal agent, and due to the existence of the terminal agent, this process is imperceptible to the application. In addition, the embodiment of the present invention is based on custom connections, filters, and locking and unlocking operations, so the present application can support complete Lua features, making the data migration process transparent to the application.
[0121] Figure 5 is a functional block diagram of a cluster expansion and contraction device based on a terminal agent according to an embodiment of the present invention. Figure 5 As shown, the device 100 includes:
[0122] The data slot configuration unit 110 is used to change the data slot configuration information through the configuration center, and send the changed data slot configuration information to the application-side terminal proxy cluster and the Redis terminal proxy cluster;
[0123] The Redis terminal proxy cluster 120 is used for the Redis terminal proxy cluster to parse the data slot configuration information to obtain the data slot allocation information of the current node after receiving the data slot configuration information; traverse the Redis data key name of the current node, obtain the data slot number corresponding to each Redis data key name, and execute the data slot migration instruction according to the data slot number and the data slot allocation information; and update the execution result of the data slot migration instruction to the configuration center;
[0124] The application-side terminal proxy cluster 130 is used for the application-side terminal proxy cluster to perform hash calculation on the Redis data key name in the Redis operation instruction after receiving the data slot configuration information through the connection pool, obtain the data slot number corresponding to the Redis data key name, obtain the Redis node corresponding to the Redis data key name according to the data slot number and the data slot configuration information, and reconstruct the single-shard connection pool according to the Redis node through the connection pool. The single-shard connection pool is used for the Java application client to establish a single connection with the master-slave-shard of the Redis node through the single-shard connection pool, and add an instruction filter in the channel of the single connection. Through the instruction filter, data migration is performed on the data slot belonging to the migration according to the routing rule of first checking the old node and then checking the new node.
[0125] The Redis node of the embodiment of the present invention does not actually run in cluster mode, and all cluster legitimacy checks are ineffective, which brings greater flexibility to business data operations; because the routing is performed through the configuration center scheduling and connection pool, the application can be regarded as accessing a single Redis node, that is, the change of cluster status is transparent to the application; the Redis terminal agent is scheduled by the configuration center, and Redis only executes data read and write commands. The scheduling calculation does not occupy the Redis main thread time, and the blocking time is the shortest. This embodiment reduces the cost of designing and modifying the existing data structure and reduces the code intrusiveness by externalizing the terminal agent.
[0126] For details, please refer to Figures 1 to 4 The method embodiment shown.
[0127] Reference below Figure 6 , which shows an electronic device suitable for implementing the embodiments of the present disclosure. The terminal device in the embodiments of the present disclosure may include, but is not limited to, mobile terminals such as mobile phones, notebook computers, digital broadcast receivers, PDAs (personal digital assistants), PADs (tablet computers), PMPs (portable multimedia players), vehicle-mounted terminals (such as vehicle-mounted navigation terminals), etc., and fixed terminals such as digital TVs, desktop computers, etc. Figure 6 The electronic device shown is only an example and should not bring any limitation to the functions and scope of use of the embodiments of the present disclosure.
[0128] like Figure 6As shown, the electronic device may include a processing device (e.g., a central processing unit, a graphics processing unit, etc.) 601, which can perform various appropriate actions and processes according to a program stored in a read-only memory (ROM) 602 or a program loaded from a storage device 607 into a random access memory (RAM) 603. In RAM 603, various programs and data required for the operation of the electronic device are also stored. The processing device 601, ROM 602, and RAM 603 are connected to each other via a bus 604. An input / output (I / O) interface 605 is also connected to the bus 604.
[0129] Typically, the following devices may be connected to the I / O interface 605: input devices 609 including, for example, a touch screen, a touch pad, a keyboard, a mouse, a camera, a microphone, an accelerometer, a gyroscope, etc.; output devices 608 including, for example, a liquid crystal display (LCD), a speaker, a vibrator, etc.; storage devices 607 including, for example, a magnetic tape, a hard disk, etc.; and communication devices 606. The communication devices 606 may allow the electronic device to communicate with other devices wirelessly or by wire to exchange data. Although Figure 6 An electronic device having various devices is shown, but it should be understood that it is not required to implement or possess all the devices shown. More or fewer devices may be implemented or possessed instead.
[0130] In particular, according to an embodiment of the present disclosure, the process described above with reference to the flowchart can be implemented as a computer software program. For example, an embodiment of the present disclosure includes a computer program product, which includes a computer program carried on a non-transitory computer-readable medium, and the computer program includes a program code for executing the method shown in the flowchart. In such an embodiment, the computer program can be downloaded and installed from a network through a communication device 606, or installed from a storage device 607, or installed from a ROM 602. When the computer program is executed by the processing device 601, the above-mentioned functions defined in the method of the embodiment of the present disclosure are executed.
[0131] It should be noted that the computer-readable medium disclosed above may be a computer-readable signal medium or a computer-readable storage medium or any combination of the above two. The computer-readable storage medium may be, for example, but not limited to, an electrical, magnetic, optical, electromagnetic, infrared, or semiconductor system, device or device, or any combination of the above. More specific examples of computer-readable storage media may include, but are not limited to: an electrical connection with one or more wires, a portable computer disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the above. In the present disclosure, a computer-readable storage medium may be any tangible medium containing or storing a program that may be used by or in combination with an instruction execution system, device or device. In the present disclosure, a computer-readable signal medium may include a data signal propagated in a baseband or as part of a carrier wave, in which a computer-readable program code is carried. This propagated data signal may take a variety of forms, including but not limited to an electromagnetic signal, an optical signal, or any suitable combination of the above. The computer readable signal medium may also be any computer readable medium other than a computer readable storage medium, which may send, propagate or transmit a program for use by or in conjunction with an instruction execution system, apparatus or device. The program code contained on the computer readable medium may be transmitted using any suitable medium, including but not limited to: wires, optical cables, RF (radio frequency), etc., or any suitable combination of the above.
[0132] In some embodiments, the client and the server may communicate using any currently known or future developed network protocol such as HTTP (HyperText Transfer Protocol), and may be interconnected with any form or medium of digital data communication (e.g., a communication network). Examples of communication networks include a local area network ("LAN"), a wide area network ("WAN"), an internet (e.g., the Internet), and a peer-to-peer network (e.g., an adhoc network), as well as any currently known or future developed network.
[0133] The computer-readable medium may be included in the electronic device, or may exist independently without being installed in the electronic device.
[0134] The computer-readable medium carries one or more programs. When the one or more programs are executed by the electronic device, the electronic device performs the following steps:
[0135] Change the data slot configuration information through the configuration center, and send the changed data slot configuration information to the application-side terminal proxy cluster and the Redis terminal proxy cluster;
[0136] After receiving the data slot configuration information, the Redis terminal proxy cluster parses the data slot configuration information to obtain the data slot allocation information of the current node; traverses the Redis data key name of the current node, obtains the data slot number corresponding to each Redis data key name, and executes the data slot migration instruction according to the data slot number and the data slot allocation information; and updates the execution result of the data slot migration instruction to the configuration center;
[0137] After the application-side terminal proxy cluster receives the data slot configuration information through the connection pool, it performs hash calculation on the Redis data key name in the Redis operation instruction, obtains the data slot number corresponding to the Redis data key name, obtains the Redis node corresponding to the Redis data key name according to the data slot number and the data slot configuration information, and reconstructs the single-shard connection pool according to the Redis node through the connection pool. The single-shard connection pool is used for the Java application client to establish a single connection with the master-slave-shard of the Redis node through the single-shard connection pool, and adds an instruction filter in the channel of the single connection. Through the instruction filter, data migration is performed on the data slot belonging to the migration according to the routing rule of checking the old node first and then the new node.
[0138] Computer program code for performing the operations of the present disclosure may be written in one or more programming languages or a combination thereof, including, but not limited to, object-oriented programming languages such as Java, Smalltalk (an object-oriented programming language), C++, and conventional procedural programming languages such as "C" or similar programming languages. The program code may be executed entirely on the user's computer, partially on the user's computer, as a separate software package, partially on the user's computer and partially on a remote computer, or entirely on a remote computer or server. In cases involving a remote computer, the remote computer may be connected to the user's computer through any type of network, including a local area network (LAN) or a wide area network (WAN), or may be connected to an external computer (e.g., via the Internet using an Internet service provider).
[0139] The flow chart and block diagram in the accompanying drawings illustrate the possible architecture, function and operation of the system, method and computer program product according to various embodiments of the present disclosure. In this regard, each square box in the flow chart or block diagram can represent a module, a program segment or a part of a code, and the module, the program segment or a part of the code contains one or more executable instructions for realizing the specified logical function. It should also be noted that in some implementations as replacements, the functions marked in the square box can also occur in a sequence different from that marked in the accompanying drawings. For example, two square boxes represented in succession can actually be executed substantially in parallel, and they can sometimes be executed in the opposite order, depending on the functions involved. It should also be noted that each square box in the block diagram and / or flow chart, and the combination of the square boxes in the block diagram and / or flow chart can be implemented with a dedicated hardware-based system that performs a specified function or operation, or can be implemented with a combination of dedicated hardware and computer instructions.
[0140] The units involved in the embodiments described in the present disclosure may be implemented by software or hardware, wherein the name of a unit does not, in some cases, limit the unit itself.
[0141] The functions described above herein may be performed at least in part by one or more hardware logic components. For example, without limitation, exemplary types of hardware logic components that may be used include: field programmable gate arrays (FPGAs), application specific integrated circuits (ASICs), application specific standard products (ASSPs), systems on chips (SOCs), complex programmable logic devices (CPLDs), and the like.
[0142] In the context of the present disclosure, a machine-readable medium may be a tangible medium that may contain or store a program for use by or in conjunction with an instruction execution system, device, or apparatus. A machine-readable medium may be a machine-readable signal medium or a machine-readable storage medium. A machine-readable medium may include, but is not limited to, an electronic, magnetic, optical, electromagnetic, infrared, or semiconductor system, device, or device, or any suitable combination of the foregoing. More specific examples of machine-readable storage media may include an electrical connection based on one or more wires, a portable computer disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the foregoing.
[0143] The above description is only a preferred embodiment of the present disclosure and an explanation of the technical principles used. Those skilled in the art should understand that the scope of disclosure involved in the present disclosure is not limited to the technical solutions formed by a specific combination of the above technical features, but should also cover other technical solutions formed by any combination of the above technical features or their equivalent features without departing from the above disclosed concept. For example, the above features are replaced with the technical features with similar functions disclosed in the present disclosure (but not limited to) by each other to form a technical solution.
[0144] In addition, although each operation is described in a specific order, this should not be understood as requiring these operations to be performed in the specific order shown or in a sequential order. Under certain circumstances, multitasking and parallel processing may be advantageous. Similarly, although some specific implementation details are included in the above discussion, these should not be interpreted as limiting the scope of the present disclosure. Some features described in the context of a separate embodiment can also be implemented in a single embodiment in combination. On the contrary, the various features described in the context of a single embodiment can also be implemented in multiple embodiments individually or in any suitable sub-combination mode.
[0145] Although the subject matter has been described in language specific to structural features and / or methodological logical actions, it should be understood that the subject matter defined in the appended claims is not necessarily limited to the specific features or actions described above. On the contrary, the specific features and actions described above are merely example forms of implementing the claims.
Claims
1. A cluster expansion and contraction method based on terminal agent, It is characterized in that The method comprises: Changing the data slot configuration information through the configuration center, and sending the changed data slot configuration information to the application-side terminal proxy cluster and the Redis terminal proxy cluster; After receiving the data slot configuration information, the Redis terminal proxy cluster parses the data slot configuration information to obtain the data slot allocation information of the current node; traverses the Redis data key name of the current node, obtains the data slot number corresponding to each Redis data key name, and executes the data slot migration instruction according to the data slot number and the data slot allocation information; and updates the execution result of the data slot migration instruction to the configuration center; After receiving the data slot configuration information through the connection pool, the application-side terminal proxy cluster performs hash calculation on the Redis data key name in the Redis operation instruction, obtains the data slot number corresponding to the Redis data key name, obtains the Redis node corresponding to the Redis data key name according to the data slot number and the data slot configuration information, and reconstructs a single shard connection pool according to the Redis node through the connection pool. The single shard connection pool is used for the Java application client to establish a single connection with the master-slave-shard of the Redis node through the single shard connection pool, and adds an instruction filter in the channel of the single connection. Through the instruction filter, data migration is performed on the data slot belonging to the migration according to the routing rule of first checking the old node and then checking the new node; wherein, the instruction filter includes a compound instruction filter, a subscription filter and an array filter; The adding of the instruction filter in the channel of the single connection, and performing data migration on the data slots belonging to the migration according to the routing rule of first checking the old node and then checking the new node through the instruction filter, specifically includes: When the client sends a Redis operation instruction through a Java application, the Redis operation instruction is parsed and the regular expression of the Redis data key name is matched through the compound instruction filter, and whether the Redis data key name is locked is determined according to the locked Redis key name list in the local memory. If the Redis data key name is locked and is still not unlocked after waiting for a preset unlocking time, the returned response information is the failure information of the corresponding instruction; when the sent Redis operation instruction involves multiple Redis data key names, if the multiple Redis data key names are located in different nodes, the compound instruction filter sends a broadcast notification of locking the Redis data key name to the application-side terminal proxy cluster, and when the application-side terminal proxy cluster receives the subscription lock broadcast notification through the subscription filter, the locked Redis data key name is stored in the locked Redis key name list in the local memory; The client rewrites the Lua script according to the locked Redis key name list through the Java application, sends the multiple Redis data key names to the corresponding Redis nodes respectively through the compound instruction filter, and adds array header information to the return result of each Lua script; When the array filter receives the array header information and the number of the array header information reaches the count value, a broadcast unlock notification is sent to the application-side terminal proxy cluster; When the application-side terminal proxy cluster receives the unlocked subscription information, the unlocked Redis data key name is removed from the locked Redis key name list.
2. The method according to claim 1, It is characterized in that The method further comprises: Within the preset reading time, the composite instruction filter is used to implement the read operation of the same key in the local cache in a whitelist manner. When creating a single shard connection pool, the composite instruction filter is used to send a subscription change notification to the Redis node, and the subscription filter is used to match the changed Redis data key name with the Redis data key name in the whitelist, and the matching Redis data key name is removed from the whitelist.
3. The method according to claim 1, It is characterized in that The method of changing the data slot distribution configuration information through the configuration center and sending the changed data slot change configuration information to the application side terminal proxy cluster and the Redis terminal proxy cluster specifically includes: When a new Redis master-slave-shard is added to the Redis group in the configuration center and a data slot is allocated, the source node and the target node are marked on the data slot, and a data slot migration instruction is sent to the Redis terminal proxy where the Redis node on the shard where the data slot change occurs is driven by the data change event inside the configuration center; The configuration center updates the data slot configuration information according to the execution result of the data slot migration instruction, and sends the updated data slot configuration information to the application-side terminal proxy cluster.
4. The method according to claim 3, It is characterized in that The method also includes: the Redis terminal agent accesses the Redis node in a Unix domain socket manner, and receives the Redis enhancement instruction pushed by the configuration center in a whitelist filtering manner.
5. The method according to claim 3, It is characterized in that After receiving the data slot configuration information, the Redis terminal proxy cluster parses the data slot configuration information to obtain the data slot allocation information of the current node; traverses the Redis data key name of the current node to obtain the data slot number corresponding to each Redis data key name, and executes the data slot migration instruction according to the data slot number and the data slot allocation information; And updating the execution result of the data slot migration instruction to the configuration center, specifically including: After receiving the data slot configuration information, the Redis terminal agent parses the data slot configuration information to obtain the data slot number interval allocated to the node; Perform hash calculation on the Redis data key name of the node and then take the modulus to obtain the data slot number of each Redis data key name; Determine whether the data slot number is within the data slot number interval of the current node; if the data slot number is not within the data slot number interval of the current node, mark the data slot and add it to the migration plan task list; Looping and taking a Redis data key name from the migration plan task list, and executing a data slot migration instruction; When the Redis data key name migration is completed, a message is sent to the configuration center to update the data slot and only mark the target node, and the migration plan task is closed.
6. The method according to claim 1, It is characterized in that The connection pool is deployed inside the application or independently deployed as an application-side terminal proxy; The connection pool includes a multi-group connection pool, a group connection pool and a single-slice connection pool; the data slot configuration information is obtained from the configuration center in real time through the group connection pool, and the single-slice connection pool is distributed with different ports.
7. A cluster expansion and contraction device based on terminal agent, It is characterized in that The device comprises: A data slot configuration unit, used to change the data slot configuration information through the configuration center, and send the changed data slot configuration information to the application-side terminal proxy cluster and the Redis terminal proxy cluster; The Redis terminal proxy cluster is used to parse the data slot configuration information to obtain the data slot allocation information of the current node after the Redis terminal proxy cluster receives the data slot configuration information; traverse the Redis data key name of the current node, obtain the data slot number corresponding to each Redis data key name, and execute the data slot migration instruction according to the data slot number and the data slot allocation information; and update the execution result of the data slot migration instruction to the configuration center; The application-side terminal proxy cluster is used to perform hash calculation on the Redis data key name in the Redis operation instruction after receiving the data slot configuration information through the connection pool, obtain the data slot number corresponding to the Redis data key name, obtain the Redis node corresponding to the Redis data key name according to the data slot number and the data slot configuration information, reconstruct a single shard connection pool according to the Redis node through the connection pool, the single shard connection pool is used for the Java application client to establish a single connection with the master-slave-shard of the Redis node through the single shard connection pool, and add an instruction filter in the channel of the single connection, and perform data migration on the data slot belonging to the migration according to the routing rule of first checking the old node and then checking the new node through the instruction filter; Wherein, the instruction filter includes a compound instruction filter, a subscription filter and an array filter; The application-side terminal proxy cluster is specifically used for: When the client sends a Redis operation instruction through a Java application, the compound instruction filter parses the Redis operation instruction and matches the regular expression of the Redis data key name, and determines whether the Redis data key name is locked according to the locked Redis key name list in the local memory. If the Redis data key name is locked and is still not unlocked after waiting for a preset unlocking time, the returned response information is the failure information of the corresponding instruction; when the sent Redis operation instruction involves multiple Redis data key names, if the multiple Redis data key names are located in different nodes, the compound instruction filter sends a broadcast notification of the locked Redis data key name to the application-side terminal proxy cluster, and the application-side terminal proxy cluster When the group receives a broadcast notification of subscription locking through a subscription filter, the locked Redis data key name is stored in a locked Redis key name list in the local memory; the client rewrites the Lua script according to the locked Redis key name list through a Java application, sends multiple Redis data key names to corresponding Redis nodes respectively through the compound instruction filter, and adds array header information to the return result of each Lua script; when the array filter receives the array header information and the number of the array header information reaches the count value, a broadcast unlocking notification is sent to the application-side terminal proxy cluster; when the application-side terminal proxy cluster receives the unlocked subscription information, the unlocked Redis data key name is removed from the locked Redis key name list.
8. An electronic device, It is characterized in that include: one or more processors; A storage device for storing one or more programs. When the one or more programs are executed by the one or more processors, the one or more processors implement a cluster expansion and contraction method based on a terminal agent as described in any one of claims 1-6.
9. A computer readable medium having a computer program stored thereon, It is characterized in that When the computer program is executed by a processor, a cluster expansion and contraction method based on terminal agent is implemented as described in any one of claims 1 to 6.
