Database processing method, device and equipment, storage medium and program product
By setting the virtual slot of the source node to the migration status and returning the target node information, the problem that the database cluster cannot access the migrated data during the expansion process is solved, and access to the migrated data and cluster availability are achieved.
Patent Information
- Application Number
- CN202411155709.9
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-08-21
- Publication Date
- 2024-12-17
AI Technical Summary
In the read-write separation scenario, the database cluster cannot effectively access the migrated data during the expansion process, resulting in data access errors and cluster availability.
By responding to the data migration instruction, the use status of the virtual slot where the data to be migrated is set in the source node to be migrated as being migrated, and the information of the target node is returned to obtain the migration of the virtual slot when the data is not queried from the node. Enter the target node to achieve access to migrated data.
In the read-write separation scenario, access to the migrated data is achieved, ensuring the correctness of data access and cluster availability during the expansion process.
Smart Images

Figure CN119149516A_ABST
Abstract
Description
Technical Field
[0001] The present disclosure relates to the field of database technology, and in particular to a database processing method, device, electronic device, readable storage medium, and computer program product. Background Art
[0002] In high-concurrency scenarios, the proper use of database cache can significantly improve application performance and response speed, while reducing the load on the database server. For most applications, data consistency requirements are not very high, and there is usually a large difference in the pressure of read requests and write requests. Read operations usually account for the majority of requests, while write operations are less common. By distributing read and write requests to different nodes that store data copies, load balancing can be achieved, thereby improving the system's read and write performance and capacity.
[0003] The above information disclosed in this Background section is only for enhancement of understanding of the background of the present disclosure and therefore it may contain information that does not constitute the prior art that is already known to one of ordinary skill in the art. Summary of the invention
[0004] The purpose of the present disclosure is to provide a database processing method, device, electronic device, readable storage medium and computer program product.
[0005] Other features and advantages of the present disclosure will become apparent from the following detailed description, or may be learned in part by the practice of the present disclosure.
[0006] According to one aspect of the present disclosure, a database processing method is provided, comprising: in response to executing a data migration instruction, setting the usage status of a virtual slot where the data to be migrated is located in a first node to being migrated, wherein the data migration instruction comprises an instruction to migrate the data to be migrated stored in a source node to a target node, the first node is a slave node in a database cluster, and the source node and the target node are both master nodes of the first node in the database cluster.
[0007] According to an embodiment of the present disclosure, the first node includes all slave nodes on the shard corresponding to the virtual slot where the data to be migrated is located.
[0008] According to an embodiment of the present disclosure, the method further includes: in response to executing an instruction to expand the capacity of the database cluster, adding the target node to the database cluster.
[0009] According to an embodiment of the present disclosure, the method further includes: setting the migration target of multiple shards in the database cluster as the target node, the multiple shards including the shards corresponding to the virtual slots where the data to be migrated is located.
[0010] According to another aspect of the present disclosure, a database processing method is provided, which is applied to a database cluster, and the method includes: in response to receiving a first data query request, querying data corresponding to a first keyword in a first node, the first node being a slave node in the database cluster, and the data query request including the first keyword; in response to not finding the data corresponding to the first keyword in the first node, obtaining a usage status of a virtual slot to which the first keyword belongs in the first node; in response to determining that the usage status of the virtual slot to which the first keyword belongs in the first node is being migrated out, returning indication information, the indication information including information of a target node, and the status of the virtual slot to which the first keyword belongs in the target node is being migrated in.
[0011] According to one embodiment of the present disclosure, the method also includes: in response to executing a data migration instruction, setting the usage status of the virtual slot where the data to be migrated is located in the first node to being migrated, wherein the data migration instruction includes an instruction to migrate the virtual slot of the data to be migrated stored in the source node and the data stored thereon to the target node, the data to be migrated includes data corresponding to the first keyword, and the source node and the target node are both master nodes of the first node in the database cluster.
[0012] According to one embodiment of the present disclosure, the method also includes: in response to executing a data migration instruction, setting the usage status of the virtual slot where the data to be migrated is located in multiple nodes on the corresponding shard to be migrated as being migrated, wherein the data migration instruction includes an instruction to migrate the data to be migrated stored in the source node to the target node, the data to be migrated includes data corresponding to the first keyword, the multiple nodes include the source node and the first node, and the source node and the target node are both master nodes of the first node in the database cluster.
[0013] According to an embodiment of the present disclosure, the method further includes: in response to executing an instruction to expand the capacity of the database cluster, adding the target node to the database cluster.
[0014] According to an embodiment of the present disclosure, the method further includes: setting the migration target of multiple shards in the database cluster as the target node, the multiple shards including the shards corresponding to the virtual slots where the data to be migrated is located.
[0015] According to another aspect of the present disclosure, there is provided a database processing method, which is applied to a database cluster, and the method includes: in response to determining that a master node in the database cluster has failed, obtaining data center identification information of the master node; obtaining data center identification information of multiple slave nodes of the master node; and based on the data center identification information of the master node and its multiple slave nodes, selecting a slave node in the same data center as that of the master node from the multiple slave nodes of the master node as a new master node in the database cluster.
[0016] According to one embodiment of the present disclosure, the method also includes: in response to a request to add a node to the database cluster, obtaining data center identification information of the node, and associating the data center identification information to the node, wherein the node is the master node and at least one of its multiple slave nodes.
[0017] According to an embodiment of the present disclosure, based on the data center identification information of the master node and its multiple slave nodes, a slave node in the same data center as that of the master node is selected from the multiple slave nodes of the master node as a new master node in the database cluster, including: based on the data center identification information of the master node and its multiple slave nodes, determining multiple candidate nodes from the multiple slave nodes of the master node, the multiple candidate nodes are all in the same data center as that of the master node; obtaining priority information of the multiple candidate nodes; and based on the priority information of the multiple candidate nodes, determining a candidate node with the highest priority from the multiple candidate nodes as the new master node in the database cluster.
[0018] According to one embodiment of the present disclosure, the method also includes: in response to executing a master node switching instruction, obtaining target data center identification information, and setting multiple slave nodes deployed in the data center corresponding to the target data center identification information as the new master node in the database cluster, wherein the data center corresponding to the target data center identification information is different from the data center corresponding to the data center identification information of the master node.
[0019] According to another aspect of the present disclosure, there is provided a database processing method, which is applied to a client, and the client is used to access the database cluster such as any of the above-mentioned database processing methods, and the database cluster includes an application node. The method includes: in response to executing a second data query instruction, obtaining a second keyword to be queried from the second data query instruction; obtaining information about the virtual slot to which the second keyword belongs; obtaining information about the shard corresponding to the virtual slot to which the second keyword belongs based on the information about the virtual slot to which the second keyword belongs; obtaining data center identification information of multiple nodes on the shard corresponding to the virtual slot to which the second keyword belongs based on the information about the shard corresponding to the virtual slot to which the second keyword belongs; obtaining data center identification information of the application node; and querying for data corresponding to the second keyword in at least one node in the multiple nodes that is in the same data center as that where the application node is located based on the data center identification information of the application node and the data center identification information of the multiple nodes.
[0020] According to an embodiment of the present disclosure, based on the data center identification information of the application node and the data center identification information of the multiple nodes, the data corresponding to the second keyword is queried in at least one node in the multiple nodes that is in the same data center as the application node, including: comparing the data center identification information of the application node with the data center identification information of the multiple nodes respectively, determining that at least one node whose data center identification information is the same as the data center identification information of the multiple nodes is the node to be queried; and querying the data corresponding to the second keyword in the node to be queried.
[0021] According to an embodiment of the present disclosure, the data center identification information of the application node is compared with the data center identification information of the multiple nodes, and at least one node whose data center identification information is the same as the data center identification information of the multiple nodes is determined as a node to be queried, including: comparing the data center identification information of the application node with the data center identification information of the multiple nodes, and determining that multiple nodes whose data center identification information is the same as the data center identification information of the multiple nodes are candidate nodes to be queried; and selecting at least one slave node from the multiple candidate nodes to be queried as the node to be queried.
[0022] According to another aspect of the present disclosure, a database processing device is provided, including: a setting module, for setting the usage status of a virtual slot where the data to be migrated is located in a first node to being migrated in response to executing a data migration instruction, wherein the data migration instruction includes an instruction to migrate the data to be migrated stored in a source node to a target node, the first node is a slave node in a database cluster, and the source node and the target node are both master nodes of the first node in the database cluster.
[0023] According to another aspect of the present disclosure, there is provided a database processing device, which is applied to a database cluster, and the device includes: a reading module, which is used to query data corresponding to a first keyword in a first node in response to receiving a first data query request, the first node being a slave node in the database cluster, and the data query request including the first keyword; an acquisition module, which is used to obtain a usage status of a virtual slot to which the first keyword belongs in the first node in response to not finding the data corresponding to the first keyword in the first node; and a return module, which is used to return indication information in response to determining that the usage status of the virtual slot to which the first keyword belongs in the first node is being migrated out, the indication information including information of a target node, and the status of the virtual slot to which the first keyword belongs in the target node is being migrated in.
[0024] According to another aspect of the present disclosure, there is provided a database processing device, which is applied to a database cluster, and the device includes: an acquisition module, which is used to obtain data center identification information of the master node in response to determining that the master node in the database cluster has a fault; the acquisition module is also used to obtain data center identification information of multiple slave nodes of the master node; and an election module is used to select a slave node in the same data center as that of the master node from the multiple slave nodes of the master node as a new master node in the database cluster based on the data center identification information of the master node and its multiple slave nodes.
[0025] According to another aspect of the present disclosure, there is provided a database processing device, which is applied to a client, and the client is used to access the database cluster in the above-mentioned database processing method, and the database cluster includes an application node. The device includes: an acquisition module, which is used to obtain a second keyword to be queried from the second data query instruction in response to executing a second data query instruction; obtain information about the virtual slot to which the second keyword belongs; obtain information about the shard corresponding to the virtual slot to which the second keyword belongs according to the information about the virtual slot to which the second keyword belongs; obtain data center identification information of multiple nodes on the shard corresponding to the virtual slot to which the second keyword belongs according to the information about the shard corresponding to the virtual slot to which the second keyword belongs; obtain data center identification information of the application node; a query module, which is used to query data corresponding to the second keyword in at least one node in the multiple nodes that is in the same data center as the application node according to the data center identification information of the application node and the data center identification information of the multiple nodes.
[0026] According to another aspect of the present disclosure, an electronic device is provided, comprising: a memory, a processor, and executable instructions stored in the memory and executable in the processor, wherein the processor implements any of the above methods when executing the executable instructions.
[0027] According to another aspect of the present disclosure, a computer-readable storage medium is provided, on which computer-executable instructions are stored, and when the executable instructions are executed by a processor, any of the above methods is implemented.
[0028] The embodiments of the present disclosure provide a computer program product or a computer program, which includes computer instructions stored in a computer-readable storage medium. A processor of a computer device reads the computer instructions from the computer-readable storage medium, and the processor executes the computer instructions, so that the computer device executes the methods provided in the above-mentioned various optional implementations.
[0029] It is to be understood that the foregoing general description and the following detailed description are exemplary only and are not restrictive of the present disclosure. BRIEF DESCRIPTION OF THE DRAWINGS
[0030] The above and other objects, features and advantages of the present disclosure will become more apparent by describing in detail example embodiments thereof with reference to the attached drawings.
[0031] Figure 1 The following is a schematic diagram showing the processing flow of a Redis cluster expansion process.
[0032] Figure 2 A flowchart of a database processing method in an embodiment of the present disclosure is shown.
[0033] Figure 3 The figure is a flowchart of another database processing method according to an exemplary embodiment.
[0034] Figure 4 according to Figure 2 and Figure 3 An example of a database processing method in a capacity expansion scenario is shown.
[0035] Figure 5 is based on Figure 4 A schematic diagram of the capacity expansion process of the database processing method provided by the embodiment of the present disclosure is shown.
[0036] Figure 6 The following is an example diagram showing a database cluster and application node multi-computer room deployment.
[0037] Figure 7 The flowchart of another database processing method is shown according to an exemplary embodiment.
[0038] Figure 8 Shows Figure 7 FIG. 5 is a schematic diagram of the processing process of step S708 in one embodiment.
[0039] Fig. 9 is based on Figure 7 A flow chart of a master node switching method is shown.
[0040] Fig.10 is based on Figure 7 A flowchart of another database processing method is shown.
[0041] Fig.11 Shows Fig.10 FIG. 1 is a schematic diagram of the processing process of step S1012 in one embodiment.
[0042] Fig.12 Shows Fig.11 FIG. 1 is a schematic diagram of the processing process of step S1102 in one embodiment.
[0043] Fig.13 A block diagram of a database processing device in an embodiment of the present disclosure is shown.
[0044] Fig.14 A block diagram of another database processing device in an embodiment of the present disclosure is shown.
[0045] Fig.15 A block diagram of another database processing device in an embodiment of the present disclosure is shown.
[0046] Fig.16 A block diagram of yet another database processing device in an embodiment of the present disclosure is shown.
[0047] Fig.17 A schematic structural diagram of an electronic device in an embodiment of the present disclosure is shown. DETAILED DESCRIPTION
[0048] Example embodiments will now be described more fully with reference to the accompanying drawings. However, example embodiments can be implemented in a variety of forms and should not be construed as limited to the examples set forth herein; rather, these embodiments are provided so that the disclosure will be more comprehensive and complete and will fully convey the concepts of the example embodiments to those skilled in the art. The accompanying drawings are only schematic illustrations of the disclosure and are not necessarily drawn to scale. The same reference numerals in the figures represent the same or similar parts, and thus their repeated description will be omitted.
[0049] In addition, the described features, structures or characteristics may be combined in one or more embodiments in any suitable manner. In the following description, many specific details are provided to provide a full understanding of the embodiments of the present disclosure. However, those skilled in the art will appreciate that the technical solutions of the present disclosure may be practiced while omitting one or more of the specific details, or other methods, devices, steps, etc. may be adopted. In other cases, well-known structures, methods, devices, implementations or operations are not shown or described in detail to avoid obscuring various aspects of the present disclosure.
[0050] In addition, the terms "first", "second", etc. are used for descriptive purposes only and should not be understood as indicating or implying relative importance or implicitly indicating the number of the indicated technical features. Therefore, the features defined as "first" or "second" may explicitly or implicitly include one or more of the features. In the description of the present disclosure, the meaning of "plurality" is at least two, such as two, three, etc., unless otherwise clearly and specifically defined. The symbol " / " generally indicates that the objects associated with each other are in an "or" relationship.
[0051] In this disclosure, unless otherwise clearly specified and limited, terms such as "connection" should be understood in a broad sense, for example, it can be an electrical connection or can communicate with each other; it can be directly connected or indirectly connected through an intermediate medium. For ordinary technicians in this field, the specific meanings of the above terms in this disclosure can be understood according to specific circumstances.
[0052] Some terms involved in the present disclosure are explained below.
[0053] Multiple replicas: refers to the process of replicating data in a distributed system to improve data fault tolerance and availability. Each replica is a copy of the original data and is stored on different nodes. When a node fails, the same data can be obtained from other nodes. In the case of multiple replicas, data consistency and synchronization are important considerations. Common multi-replica consistency models include strong consistency and eventual consistency. Strong consistency requires that the data between replicas remain completely consistent, while eventual consistency allows data inconsistency between replicas for a certain period of time, but will eventually reach a consistent state through a certain mechanism.
[0054] Read-write separation: refers to a technical means of assigning read operations and write operations to different nodes for processing in data management systems such as database cache. Usually, read operations far outnumber write operations. By distributing read requests to multiple read nodes, the system's read performance and concurrent processing capabilities can be improved. In a read-write separation architecture, there is usually a master node and multiple slave nodes and multiple copies. The master node is responsible for processing write operations, while the slave node is responsible for processing read operations. The application sends read and write requests to different nodes to balance the system load and improve performance.
[0055] Redis Cluster: The official Redis (Remote Dictionary Server) cluster uses a decentralized architecture and can share data between multiple Redis nodes. Redis cluster uses sharding technology on the server side. Each shard is responsible for a part of the data and has multiple copies. It also introduces virtual slots, that is, a three-level mapping relationship of shard->slot->data. The redis cluster mode has 16384 slots, and all data is mapped to the slots. Each Redis node manages a part of the slots. At the same time, each instance node coordinates and communicates to jointly provide consistent services to the outside world. The nodes in the cluster exchange each other's status and detect the information of newly added nodes through the gossip protocol. Redis cluster supports dynamic node addition, dynamic slot migration, and automatic failover.
[0056] TP90: The performance index is a measure of system performance, which means that during the operation of the system, 90% of the operation response time is lower than or equal to the threshold set by the index. This index is usually used to evaluate the stability and efficiency of the system. A lower TP90 value means better system performance.
[0057] The database involved in the embodiments of the present disclosure is described by taking Redis as an example, but is not limited to this.
[0058] In related technologies, there are mainly the following ways to implement Redis read-write separation:
[0059] Method 1: Proxy layer implementation
[0060] By building a proxy layer, such as Twemproxy, Codis, etc., read requests are evenly distributed to multiple Redis replicas, and write requests are uniformly forwarded to the master node by the proxy layer. The proxy layer is responsible for routing and load balancing read and write requests. The application directly connects to the proxy layer, which is transparent to the application.
[0061] Method 2: Client implementation
[0062] By configuring the sharding strategy on the client, data is sharded by key, and different shards are connected to different Redis instances to achieve read-write separation. The application needs to be responsible for the management of data sharding and request routing, and certain logical processing is required for the application.
[0063] Method 3: Redis Sentinel Implementation
[0064] Sentinel in Redis cluster mode can achieve master-slave replication and high availability. By configuring multiple Redis replicas, one is the master node and the others are slave nodes. Applications connect to the master node for write operations and connect to the slave node for read operations. When the master node fails, Sentinel automatically upgrades a slave node to the new master node to achieve failover and high availability.
[0065] When using a database, you may encounter a situation where you need to add nodes to improve overall performance and capacity due to an increase in the amount of data stored, an increase in the number of concurrent clients, or an increase in business processing capability requirements. This process is usually called capacity expansion. Conversely, the process of reducing nodes is called capacity reduction. Data migration is performed during both capacity expansion and capacity reduction, that is, data on one node is migrated to another node, such as the migration slot when migrating Redis data. In the disclosed embodiment, the scenario of data migration is described as capacity expansion, but it is not limited to this.
[0066] In the related technology, when the Redis cluster is expanded, the virtual slot position of the source node (master node) is migrated out (migrating or exporting, etc.) and the virtual slot position of the target node (master node) is migrated in (importing) until the data migration is completed, and the virtual slot position is updated to the target node management to complete the expansion operation. Figure 1 The following is a schematic diagram showing the processing flow of a Redis cluster expansion process. Figure 1 As shown, before the expansion, nodes 101, 102, and 103 are deployed in the cluster. The slots on the shard of node 101 include slot 1, slot 2, and slot 3. The slots on the shard of node 102 include slot 4, slot 5, and slot 6. The slots on the shard of node 101 include slot 7, slot 8, and slot 9. The expansion goal is to add node 104 to the cluster and migrate slot 2 of node 101, slot 6 of node 102, and slot 9 of node 103 to node 104 respectively. Figure 1 The figure shows the process of slot 9 being migrated from node 103 to node 104, where keys K1 to K5 have been automatically migrated and keys K6 to K8 are to be migrated. Figure 1Steps S110 to S120 in FIG. 1 illustrate the information interaction process of querying the data (value V1) corresponding to the keyword (key) K1 stored in slot 9 in this state.
[0067] Step S110 , requesting the client 130 to query the data corresponding to K1 .
[0068] In step S112, the client 130 calculates the hash value of K1 and obtains the slot 9 where K1 is located. Because the expansion has not been completed and the cluster topology has not changed, the source node will be queried first.
[0069] Step S114 , the client 130 sends a request to the node 103 to which slot 9 belongs, requesting to query the data corresponding to K1 .
[0070] In step S116 , if the node 103 fails to find the data corresponding to K1 and slot 9 in the node 103 is in the state of being migrated out, the node 103 returns the asking command and the target node, ie, the address of the node 104 , to the client 130 .
[0071] Step S118 , the client 130 requests the node 104 to query the data corresponding to K1 .
[0072] In step S120 , the node 104 searches for data V1 corresponding to K1 and returns V1 to the client 130 .
[0073] If the data being queried is not on the node 104 (eg K11), the node 104 cannot be found, and the data does not exist.
[0074] Figure 1 The scenario shown does not adopt the read-write separation method, that is, nodes 101 to 104 are all nodes that can know the migration status (for example, they are all master nodes). As mentioned above, in the read-write separation scenario, the Redis cluster slave node will not record the data migration status. Therefore, during the expansion process, due to the current Redis defects, the cluster slave node cannot obtain the master node exporting and / or importing status. Therefore, the client will only access the source node. If the source node has no data, it is considered that the data does not exist, but in fact, the data may have been migrated to the target node, causing an error.
[0075] As mentioned above, the read-write separation method adopted by the related technical database is that the master node in the cluster (also called the master database, master library, etc.) executes the write request, and then synchronizes the written data to the slave node (also called the slave database, slave library, etc.), and the slave node executes the read request. In this deployment method, when data is migrated between master nodes, the cluster slave nodes cannot identify the data being migrated, resulting in the inability to access the data being migrated. How to access the data being migrated in the read-write separation scenario has become an urgent problem to be solved.
[0076] Therefore, the present disclosure provides a database processing method, which sets the usage status of the virtual slot where the data to be migrated is located in the first node to be migrated as being migrated out in response to executing a data migration instruction. Therefore, when the slave node in the database cluster fails to query the data corresponding to the first keyword in the first data query request, the usage status of the virtual slot to which the first keyword belongs in the slave node is obtained, and when it is determined that the usage status of the virtual slot to which the first keyword belongs in the slave node is being migrated out, information indicating the migration target node of the data corresponding to the first keyword is returned, so as to realize access to the data being migrated in a read-write separation scenario.
[0077] Figure 2 FIG. 1 is a flowchart of a database processing method according to an exemplary embodiment. Figure 2 The method shown can be applied to a database cluster, for example.
[0078] refer to Figure 2 , the method 20 provided in the embodiment of the present disclosure may include the following steps.
[0079] In step S202, in response to executing a data migration instruction, the usage status of the virtual slot where the data to be migrated is located in the first node is set to being migrated, wherein the data migration instruction includes an instruction to migrate the data to be migrated stored in the source node to the target node, the first node is a slave node in the database cluster, and the source node and the target node are both master nodes of the first node in the database cluster.
[0080] In some embodiments, data migration can be performed in a capacity expansion scenario. In response to executing an instruction to expand the database cluster, a target node can be added to the database cluster so that the data to be migrated can be migrated to the target node. Data can be migrated during off-peak hours, and the migration speed can be controlled during data migration.
[0081] In some embodiments, the database cluster may include several master nodes, each of which may have several slave nodes. When the master node is performing data migration, the corresponding slave nodes may maintain data consistency with the master node. One or more nodes (including the first node) for processing read requests may be designated, and when executing the data migration instruction, the use status of the slot to be migrated of the designated node is set to being migrated (or called being migrated).
[0082] In some embodiments, the first node may include all slave nodes on the shard corresponding to the virtual slot where the data to be migrated is located.
[0083] In some embodiments, the migration target of multiple shards in the database cluster can be set as a target node, and in response to the data migration instruction, the state of the target node is set to be migrated. The multiple shards may include shards corresponding to the virtual slots where the data to be migrated is located. For example, referring to Figure 1 , the migration targets of the shards of nodes 101, 102, and 103 are all node 104.
[0084] According to the database processing method provided by the embodiment of the present disclosure, in response to executing a data migration instruction, the use status of the virtual slot where the data to be migrated is located in the first node is set to being migrated out, so that when the slave node in the database cluster fails to query the data, the use status of the virtual slot where the data is located in the slave node can be obtained and the data can be queried in the corresponding node accordingly, thereby realizing access to the data being migrated in a read-write separation scenario.
[0085] Figure 3 FIG. 1 is a flowchart of another database processing method according to an exemplary embodiment. Figure 3 The method shown can be applied to a database cluster, for example. Figure 3 and Figure 2 The connection is that Figure 2 The data to be migrated in the Figure 3 The data corresponding to the first keyword in the query.
[0086] refer to Figure 3 , the method 30 provided in the embodiment of the present disclosure may include the following steps.
[0087] In step S302, in response to receiving a first data query request, data corresponding to a first keyword is queried in a first node, the first node is a slave node in a database cluster, and the data query request includes the first keyword.
[0088] In some embodiments, in a read-write separation scenario, a data query request is sent to a slave node.
[0089] In some embodiments, a data query request may be sent through a client, which may run on an application node in a database cluster. The application node interacts with a master node and / or a slave node through a network, which may include various connection types, such as wired, wireless communication links, or optical fiber cables, etc.
[0090] In step S304, in response to not finding data corresponding to the first keyword in the first node, the usage status of the virtual slot to which the first keyword belongs in the first node is obtained.
[0091] In the embodiment of the present disclosure, a situation is described in which the first keyword has been migrated to the target node, and the virtual slot to which the first keyword belongs has not yet been migrated.
[0092] In step S306, in response to determining that the virtual slot to which the first keyword belongs is in use status in the first node as being migrated out, indication information is returned, the indication information including information of the target node, and the status of the virtual slot to which the first keyword belongs in the target node is being migrated in.
[0093] According to the database processing method provided by the embodiment of the present disclosure, when a slave node in a database cluster fails to query the data corresponding to the first keyword in the first data query request, the usage status of the virtual slot to which the first keyword belongs in the slave node is obtained, and when it is determined that the usage status of the virtual slot to which the first keyword belongs in the slave node is being migrated, information indicating the migration target node of the data corresponding to the first keyword is returned, thereby accessing the data being migrated in a read-write separation scenario.
[0094] Figure 4 according to Figure 2 and Figure 3 This shows an example of a database processing method in a capacity expansion scenario. Figure 4 , the method 40 provided in the embodiment of the present disclosure may include the following steps.
[0095] In step S402, in response to executing an instruction to expand the capacity of the database cluster, the target node is added to the database cluster.
[0096] In some embodiments, the expansion is due to a capacity bottleneck, and data needs to be migrated to the newly added cluster node to ensure that the current shard is at a reasonable level and has a certain degree of safety redundancy. The target node can be selected to ensure sufficient capacity.
[0097] In step S404, in response to executing the data migration instruction, the usage status of the virtual slot where the data to be migrated is located in all nodes on the corresponding shard is set to being migrated.
[0098] In some embodiments, the data migration instruction includes an instruction to migrate the data to be migrated stored in the source node to the target node. The data to be migrated may include data corresponding to the first keyword. All nodes on the shard corresponding to the virtual slot where the data to be migrated is located may include the source node, the first node, and other master nodes and slave nodes. The source node and the target node are both master nodes of the first node in the database cluster.
[0099] In step S406, the migration target of multiple shards in the database cluster is set as a target node.
[0100] In some embodiments, the migration targets of multiple shards in a database cluster can be set to the same node. Figure 1, the migration targets of the shards of node 101, node 102, and node 104 are all node 104.
[0101] In step S408, in response to receiving the first data query request, data corresponding to the first keyword is searched in the first node.
[0102] In step S410, in response to not finding data corresponding to the first keyword in the first node, the usage status of the virtual slot to which the first keyword belongs in the first node is obtained.
[0103] In step S412, in response to determining that the use status of the virtual slot to which the first keyword belongs in the first node is being migrated out, indication information is returned.
[0104] According to the database processing method provided by the embodiment of the present disclosure, the Redis expansion process is transformed. When the expansion starts, all nodes on the same shard are set to the exporting state, and the migration target node points to the same target node. In this way, when reading the slave node, if the data cannot be queried and the virtual slot state is in the exporting state, the slave node will return the asking command and point to the recorded target node. The client can obtain the data by accessing the target node again, thereby solving the problem that the client cannot obtain the slave node data during expansion in the read-write separation mode, ensuring the correctness of accessing data, and thus ensuring the availability of the cluster during the migration process. .
[0105] Figure 5 is based on Figure 4 FIG. 1 is a schematic diagram showing a capacity expansion process of a database processing method provided by an embodiment of the present disclosure. Figure 5 As shown, the master node (migration source node) 503 and its slave nodes 5032, 5034 and 5036 are deployed in the cluster before expansion. At the beginning of expansion, the master node (migration target node) 504 is added to the cluster, and the slot 9 on the shard of the source node 503 is ready to be migrated to the target node 504. In the expansion, the slot 9 on the source node 503, the slave nodes 5032, 5034 and 5036 are all set to the state of being migrated out, and the slot 9 on the target node 504 is set to the state of being migrated in. Figure 4 4. FIG. 4 shows the process of slot 9 being migrated from source node 503 to target node 504. Keys K1 to K3 have been automatically migrated, and K4 and K5 are to be migrated. Figure 4 Steps S510 to S518 in the figure illustrate the information interaction process of querying the data (value V2) corresponding to the key K2 stored in slot 9 in this state.
[0106] Step S510, request the client 5002 to query the data corresponding to K2.
[0107] In step S512, the client 5002 calculates the hash value of K2, obtains the slot 9 where K2 is located, and sends a read request to the slave node 5036 of the source node (master node) 503 to which slot 9 belongs, requesting to query the data corresponding to K2.
[0108] Step S514, when the data corresponding to K2 is queried from the node 5036, it is found that slot 9 is in the state of being migrated out, and the asking command and the address of the target node 504 are returned to the client 5002.
[0109] Step S516, the client 5002 requests the target node 504 to query the data corresponding to K2.
[0110] Step S518 , the target node 504 queries the data V2 corresponding to K2 and returns V2 to the client 5002 .
[0111] Read-write separation greatly improves the read-write performance of the system. In actual deployment, some core applications are generally deployed in multiple computer rooms (also called data centers (DC)) based on high availability considerations. Figure 6 The following is an example of a database cluster and application node multi-computer room deployment diagram. Figure 6 As shown in the figure, the data distribution of cluster shard N is stored on the nodes of computer room 1, computer room 2 and computer room 3, including master node 1 and slave node 1 deployed in computer room 1, slave node 2 deployed in computer room 2, and slave node 3 deployed in computer room 3. Application node 1, application node 2 and application node 3 are deployed in computer room 1, computer room 2 and computer room 3 respectively. This deployment method brings the following problems:
[0112] Cluster stability decreases: When a Redis cluster is deployed in multiple computer rooms, in a complex network environment, due to network latency and other reasons, the master-slave switchover will be more frequent, resulting in a large amount of master-slave data replication, which has a greater impact on the network. At the same time, the alarms generated by the continuous master-slave switchover also bring greater operation and maintenance pressure.
[0113] Cross-data center access: Due to the cross-data center deployment of Redis nodes and application nodes, a large amount of cross-data center data access occurs. In cross-city situations, it can even reach tens of milliseconds, which is unacceptable for some business scenarios.
[0114] Figure 7 FIG. 1 is a flowchart of another database processing method according to an exemplary embodiment. Figure 7 The method shown can be applied to a database cluster deployed in multiple computer rooms, for example, to solve the problem caused by frequent master-slave switching. Figure 7 and Figure 2 , Figure 3It can be applied to the same or different database clusters, and the present disclosure is not limited thereto.
[0115] refer to Figure 7 , the method 70 provided in the embodiment of the present disclosure may include the following steps.
[0116] In step S702, in response to a request to add a node to a database cluster, data center identification information of the node is obtained, and the data center identification information is associated with the node, which is a master node and at least one of its multiple slave nodes.
[0117] In some embodiments, the DC_ID (computer room ID) parameter can be extended in the Redis node. When building a Redis cluster, different DC_IDs are injected into the Redis nodes deployed in different computer rooms. Figure 5 Taking the cluster shard N shown as an example, DC_ID=1 can be injected into the master node 1, the slave node 1, and the application node 1, DC_ID=2 can be injected into the slave node 2 and the application node 2, and DC_ID=3 can be injected into the slave node 3 and the application node 3.
[0118] In step S704, in response to determining that a master node in the database cluster fails, data center identification information of the master node is obtained.
[0119] In step S706, data center identification information of multiple slave nodes of the master node is obtained.
[0120] In step S708, according to the data center identification information of the master node and its multiple slave nodes, a slave node in the same data center as the master node is selected from the multiple slave nodes of the master node as a new master node in the database cluster.
[0121] In some embodiments, the election algorithm under Redis cluster failure can be improved. In the case of master node failure and downtime, the cluster autonomously elects only slave nodes in the same computer room to take over the master node, and will not select slave nodes in different computer rooms to take over the master node. Figure 7 The following is an exemplary diagram of the process of an improved election algorithm.
[0122] According to the method provided by the embodiment of the present disclosure, in the event of a master node failure or downtime, the cluster autonomously elects only a slave node in the same computer room to take over the master node, and does not select a slave node in a different computer room to take over the master node. This ensures high availability of the cluster and prevents the situation where multiple computer rooms are constantly switching between masters and slaves in a weak network.
[0123] Figure 8 Shows Figure 7 The processing process of step S708 in one embodiment is shown in FIG. Figure 8As shown, in the embodiment of the present disclosure, the above step S708 may further include the following steps.
[0124] Step S802, according to the data center identification information of the master node and its multiple slave nodes, multiple candidate nodes are determined from the multiple slave nodes of the master node, and the multiple candidate nodes are all in the same data center as that of the master node.
[0125] Step S804: Obtain priority information of multiple candidate nodes.
[0126] In some embodiments, the priority may be an election priority set according to actual needs, for example, a larger complex offset has a higher priority, or a larger running ID has a higher priority, and so on.
[0127] Step S806: Determine a candidate node with the highest priority from among the multiple candidate nodes as a new master node in the database cluster according to the priority information of the multiple candidate nodes.
[0128] According to the method provided by the embodiment of the present disclosure, by extending the computer room ID parameter in the Redis node and improving the election algorithm under cluster failure, in the event of a master node failure or downtime, the cluster autonomously elects only a slave node in the same computer room to take over the master node, thereby effectively solving the technical problem of continuous master-slave switching in multiple computer rooms under weak network conditions.
[0129] Fig. 9 is based on Figure 7 A flowchart of a master node switching method is shown in FIG. In the case of extreme failures such as power outage in the main computer room, the following method can be used: Figure 7 The method shown is to manually switch the available machine room.
[0130] refer to Fig. 9 , the method 90 provided in the embodiment of the present disclosure may include the following steps.
[0131] In step S902, a master node switching instruction is received.
[0132] In step S904, in response to executing the master node switching instruction, target data center identification information is obtained.
[0133] In step S906, multiple slave nodes deployed in the data center corresponding to the target data center identification information are set as new master nodes in the database cluster, wherein the data center corresponding to the target data center identification information is different from the data center corresponding to the data center identification information of the master node.
[0134] According to the method provided in the embodiment of the present disclosure, the cluster supports manual switching across computer rooms. In extreme fault conditions such as power outage in the main computer room, a one-key switching command can be sent to the node through the control surface to promote all slave nodes in the specified computer room to master nodes. This operation can be completed within minutes and can meet the requirements of computer room-level faults.
[0135] In some embodiments, when building a Redis cluster, different DC_IDs are injected into Redis nodes deployed in different computer rooms, and an external query node computer room ID interface can also be provided to facilitate the client software development kit (SDK) to obtain cluster topology and computer room information when interacting with the cluster.
[0136] Fig.10 is based on Figure 7 FIG. 1 is a flowchart of another database processing method. Figure 7 The method shown can be applied to a client, for example, which can be used to access Figure 7 The database cluster including the application node in the database processing method shown solves the above-mentioned problem caused by cross-computer room access. The user can operate on the client to communicate with the application node to read / write data in the master node and / or slave node connected to the application node.
[0137] refer to Fig.10 , the method 100 provided in the embodiment of the present disclosure may include the following steps.
[0138] In step S1002, in response to executing the second data query instruction, a second keyword to be queried is obtained from the second data query instruction.
[0139] In step S1004, information about the virtual slot to which the second keyword belongs is obtained.
[0140] In step S1006, information of the slice corresponding to the virtual slot to which the second keyword belongs is obtained according to the information of the virtual slot to which the second keyword belongs.
[0141] In step S1008, according to the information of the shard corresponding to the virtual slot to which the second keyword belongs, the data center identification information of multiple nodes on the shard corresponding to the virtual slot to which the second keyword belongs is obtained.
[0142] In step S1010, data center identification information of the application node is obtained.
[0143] In step S1012, based on the data center identification information of the application node and the data center identification information of the multiple nodes, data corresponding to the second keyword is searched in at least one node in the multiple nodes that is in the same data center as the application node.
[0144] The above-mentioned Redis cluster transformation and expansion process optimization provide basic support for the client SDK to support same-data-center reading. When accessing the Redis cluster, the business needs to introduce the corresponding client SDK and configure the corresponding same-data-center reading and writing strategy. After that, when batches are launched through the company's internal online system, the online system will inject the corresponding data center ID according to the data center where the application node is located. There is a corresponding interface inside the SDK to obtain the injected data center ID.
[0145] According to the method provided by the embodiment of the present disclosure, during the subsequent startup and operation of the application, the client will dynamically obtain the real-time topology from the Redis cluster. Since the modified Redis node is configured with a computer room ID, the topology information contains the computer room information of each Redis node. When the client accesses Redis data, the virtual slot is calculated through the keyword, and the relevant shard is obtained. Then, the computer room information of all nodes in the shard is obtained, and compared with the computer room where the current application node is located. When the corresponding computer room is found, the data in the same computer room can be accessed. In the case of cluster abnormalities, the bottom-up strategy can be adopted to access the main node. Through the above transformation, in the case of multi-computer room deployment, the same computer room read strategy is adopted, the business delay is significantly reduced, and the concurrency capacity is greatly improved.
[0146] Fig.11 Shows Fig.10 Schematic diagram of the processing process of step S1012 in one embodiment. Fig.11 As shown, in the embodiment of the present disclosure, the above step S1012 may further include the following steps.
[0147] Step S1102 : Compare the data center identification information of the application node with the data center identification information of multiple nodes respectively, and determine at least one node whose data center identification information is the same as the data center identification information of the multiple nodes as the node to be queried.
[0148] Step S1104: search for data corresponding to the second keyword in the node to be queried.
[0149] Fig.12 Shows Fig.11 Schematic diagram of the processing process of step S1102 in one embodiment. Fig.12 As shown, in the embodiment of the present disclosure, the above step S1102 may further include the following steps.
[0150] Step S1202 : Compare the data center identification information of the application node with the data center identification information of the multiple nodes respectively, and determine that the multiple nodes whose data center identification information is the same as the data center identification information of the multiple nodes are candidate nodes to be queried.
[0151] Step S1204: Select at least one slave node from multiple candidate nodes to be queried as the node to be queried.
[0152] Table 1 below shows a configuration example of a client SDK.
[0153] Table 1
[0154] Configuration details clientVersion:3.3.3 redisTimeOut:120 socketTimeout:500 --readWriteConfig-- readWritePolicy:DC_SLAVE_FIRST maxRedirection:3 clientDcid:2
[0155] Among them, the service adopts cross-city multi-computer room deployment. The computer room ID of the application node running on the client with version 3.3.3 is 2. "DC_SLAVE_FIRST" indicates that the service adopts the same computer room slave priority strategy, that is, the same computer room gives priority to reading slave nodes, and then reads the master node when the slave node fails. When the cross-city network delay is about 30ms, the method provided by the embodiment of the present disclosure is adopted to introduce the client SDK and transform the Redis cluster to implement the same computer room reading strategy. By injecting the computer room ID information, when the application accesses the Redis cluster, the node in the same computer room is given priority to process the read operation, which can achieve TP90 within 1ms, with good performance, thereby avoiding the performance degradation caused by cross-computer room access and improving the performance of the system.
[0156] Through the method provided by the embodiment of the present disclosure, by optimizing the high-availability switching mode of the cluster, optimizing the expansion process and providing the same-computer-room access strategy, in the case of Redis cluster and application multi-computer-room deployment, the same-computer-room closed-loop reading of the application and the data node can be achieved, ensuring that most of the application's read operations are completed within 1 millisecond. At the same time, while ensuring performance, the problems of frequent master-slave switching of the cluster in a weak network and unavailability of read operations during expansion are solved, ensuring that the system has good performance and stability.
[0157] Fig.13 FIG. 1 is a block diagram of a database processing device according to an exemplary embodiment. Fig.13 The device shown can be applied to a database cluster, for example.
[0158] refer to Fig.13 , the apparatus 130 provided in the embodiment of the present disclosure may include a setting module 1302. The setting module 1302 may be used to set the use state of the virtual slot where the data to be migrated is located in the first node to be migrated in response to executing a data migration instruction, wherein the data migration instruction includes an instruction to migrate the data to be migrated stored in the source node to the target node, the first node is a slave node in the database cluster, and the source node and the target node are both master nodes of the first node in the database cluster.
[0159] The first node may include all slave nodes on the shard corresponding to the virtual slot where the data to be migrated is located.
[0160] Fig.14 FIG. 1 is a block diagram of another database processing device according to an exemplary embodiment. Fig.14 The device shown can be applied to a database cluster, for example.
[0161] refer to Fig.14 The device 140 provided in the embodiment of the present disclosure may include a reading module 1402 , an acquisition module 1404 and a return module 1406 .
[0162] The reading module 1402 may be configured to query data corresponding to a first keyword in a first node in response to receiving a first data query request, where the first node is a slave node in a database cluster, and the data query request includes the first keyword.
[0163] The acquisition module 1404 may be configured to acquire the usage status of the virtual slot to which the first keyword belongs in the first node in response to not finding data corresponding to the first keyword in the first node.
[0164] The return module 1406 can be used to return indication information in response to determining that the usage status of the virtual slot to which the first keyword belongs in the first node is being migrated out, the indication information including information of the target node, and the status of the virtual slot to which the first keyword belongs in the target node is being migrated in.
[0165] Fig.15 FIG. 1 is a block diagram of another database processing device according to an exemplary embodiment. Fig.15 The device shown can be applied to a database cluster, for example.
[0166] refer to Fig.15 The device 150 provided in the embodiment of the present disclosure may include an adding module 15012, a setting module 15014, an obtaining module 15016, a reading module 1502, an acquisition module 1504, a selection module 1505 and a return module 1506.
[0167] The adding module 15012 may be configured to add a target node to the database cluster in response to executing an instruction to expand the capacity of the database cluster.
[0168] The setting module 15014 can be used to set the usage status of the virtual slot where the data to be migrated is located in the first node to being migrated in response to executing a data migration instruction, wherein the data migration instruction includes an instruction to migrate the data to be migrated stored in the source node to the target node, the data to be migrated includes data corresponding to the first keyword, and the source node and the target node are both master nodes of the first node in the database cluster.
[0169] The setting module 15014 can also be used to respond to the execution of a data migration instruction, and set the usage status of the virtual slot where the data to be migrated is located in multiple nodes on the corresponding shard to be migrated as being migrated, wherein the data migration instruction includes an instruction to migrate the data to be migrated stored in the source node to the target node, the data to be migrated includes data corresponding to the first keyword, the multiple nodes include the source node and the first node, and the source node and the target node are both master nodes of the first node in the database cluster.
[0170] The setting module 15014 can also be used to set the migration target of multiple shards in the database cluster as a target node, and the multiple shards include the shards corresponding to the virtual slots where the data to be migrated is located.
[0171] The setting module 15014 can also be used to respond to executing a master node switching instruction, obtain target data center identification information, and set multiple slave nodes deployed in the data center corresponding to the target data center identification information as new master nodes in the database cluster, wherein the data center corresponding to the target data center identification information is different from the data center corresponding to the data center identification information of the master node.
[0172] The acquisition module 15016 may be used to obtain data center identification information of a node in response to a request to add a node to a database cluster, wherein the node is a master node and at least one of its multiple slave nodes.
[0173] The reading module 1502 may be configured to query data corresponding to a first keyword in a first node in response to receiving a first data query request, where the first node is a slave node in a database cluster, and the data query request includes the first keyword.
[0174] The acquisition module 1504 may be configured to acquire the usage status of the virtual slot to which the first keyword belongs in the first node in response to not finding data corresponding to the first keyword in the first node.
[0175] The acquisition module 1504 may also be configured to acquire data center identification information of the master node in response to determining that the master node in the database cluster has failed.
[0176] The acquisition module 1504 may also be used to acquire data center identification information of multiple slave nodes of the master node.
[0177] The election module 1505 can be used to select a slave node in the same data center as the master node from among the multiple slave nodes of the master node as a new master node in the database cluster according to the data center identification information of the master node and its multiple slave nodes.
[0178] The election module 1505 can also be used to determine multiple candidate nodes from the multiple slave nodes of the master node based on the data center identification information of the master node and its multiple slave nodes, and the multiple candidate nodes are all in the same data center as the master node; obtain priority information of the multiple candidate nodes; and determine the candidate node with the highest priority from the multiple candidate nodes as the new master node in the database cluster based on the priority information of the multiple candidate nodes.
[0179] The return module 1506 can be used to return indication information in response to determining that the usage status of the virtual slot to which the first keyword belongs in the first node is being migrated out, the indication information including information of the target node, and the status of the virtual slot to which the first keyword belongs in the target node is being migrated in.
[0180] Fig.16 FIG. 1 is a block diagram of another database processing device according to an exemplary embodiment. Fig.16 The device shown can be applied to a client, for example, where the client is used to Figure 6 The database processing method shown includes a database cluster including application nodes.
[0181] refer to Fig.16 The device 160 provided in the embodiment of the present disclosure may include an acquisition module 1602 and a query module 1604.
[0182] The acquisition module 1602 can be used to obtain the second keyword to be queried from the second data query instruction in response to executing the second data query instruction; obtain the information of the virtual slot to which the second keyword belongs; obtain the information of the shard corresponding to the virtual slot to which the second keyword belongs based on the information of the virtual slot to which the second keyword belongs; obtain the data center identification information of multiple nodes on the shard corresponding to the virtual slot to which the second keyword belongs based on the information of the shard corresponding to the virtual slot to which the second keyword belongs; and obtain the data center identification information of the application node.
[0183] The query module 1604 may be used to query data corresponding to the second keyword in at least one node in the same data center as the application node among the multiple nodes according to the data center identification information of the application node and the data center identification information of the multiple nodes.
[0184] In some embodiments, the query module 1604 can also be used to compare the data center identification information of the application node with the data center identification information of multiple nodes, respectively, to determine at least one node whose data center identification information is the same as the data center identification information of multiple nodes as the node to be queried; and to query the data corresponding to the second keyword in the node to be queried.
[0185] In some embodiments, the query module 1604 can also be used to compare the data center identification information of the application node with the data center identification information of multiple nodes, respectively, to determine that multiple nodes whose data center identification information is the same as the data center identification information of multiple nodes are candidate nodes to be queried; and to select at least one slave node from the multiple candidate nodes to be queried as the node to be queried.
[0186] The specific implementation of each module in the device provided by the embodiment of the present disclosure can refer to the content of the above method, which will not be repeated here.
[0187] Fig.17 The following is a schematic diagram showing the structure of an electronic device in an embodiment of the present disclosure. It should be noted that: Fig.17 The device shown is only an example of a computer system, which should not bring any limitation to the functions and scope of use of the embodiments of the present disclosure.
[0188] like Fig.17 As shown, the device 1700 includes a central processing unit (CPU) 1701, which can perform various appropriate actions and processes according to a program stored in a read-only memory (ROM) 1702 or a program loaded from a storage portion 1708 into a random access memory (RAM) 1703. In the RAM 1703, various programs and data required for the operation of the device 1700 are also stored. The CPU 1701, the ROM 1702, and the RAM 1703 are connected to each other via a bus 1704. An input / output (I / O) interface 1705 is also connected to the bus 1704.
[0189] The following components are connected to the I / O interface 1705: an input section 1706 including a keyboard, a mouse, etc.; an output section 1707 including a cathode ray tube (CRT), a liquid crystal display (LCD), etc., and a speaker, etc.; a storage section 1708 including a hard disk, etc.; and a communication section 1709 including a network interface card such as a LAN card, a modem, etc. The communication section 1709 performs communication processing via a network such as the Internet. A drive 1710 is also connected to the I / O interface 1705 as needed. A removable medium 1711, such as a magnetic disk, an optical disk, a magneto-optical disk, a semiconductor memory, etc., is installed on the drive 1710 as needed, so that a computer program read therefrom is installed into the storage section 1708 as needed.
[0190] 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 computer-readable medium, and the computer program contains 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 part 1709, and / or installed from a removable medium 1711. When the computer program is executed by a central processing unit (CPU) 1701, the above-mentioned functions defined in the system of the present disclosure are executed.
[0191] It should be noted that the computer-readable medium shown in the present disclosure 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 can 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 electromagnetic signals, optical signals, or any suitable combination of the above. Computer-readable signal media may also be any computer-readable medium other than computer-readable storage media, 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 appropriate medium, including but not limited to: wireless, wire, optical cable, RF, etc., or any suitable combination of the above.
[0192] The flow charts and block diagrams in the accompanying drawings illustrate the possible architecture, functions and operations of the systems, methods and computer program products according to various embodiments of the present disclosure. In this regard, each box in the flow chart or block diagram can represent a module, a program segment, or a part of a code, and the above-mentioned module, program segment, or a part of a code contains one or more executable instructions for realizing the specified logical function. It should also be noted that in some alternative implementations, the functions marked in the box can also occur in a different order from the order marked in the accompanying drawings. For example, two 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 box in the block diagram or flow chart, and the combination of the boxes in the block diagram 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.
[0193] The modules involved in the embodiments described in the present disclosure may be implemented by software or hardware. The modules described may also be set in a processor, for example, it may be described as: a processor includes a setting module. The names of these modules do not constitute a limitation on the modules themselves in some cases, for example, the setting module may also be described as "a module for setting the usage status of the virtual slots of the database node".
[0194] As another aspect, the present disclosure further provides a computer-readable medium, which may be included in the device described in the above embodiment; or may exist independently without being assembled into the device. The above computer-readable medium carries one or more programs, and when the above one or more programs are executed by a device, the device includes:
[0195] In response to executing a data migration instruction, the usage status of the virtual slot where the data to be migrated is located in the first node is set to being migrated, wherein the data migration instruction includes an instruction to migrate the data to be migrated stored in the source node to the target node, the first node is a slave node in the database cluster, and the source node and the target node are both master nodes of the first node in the database cluster.
[0196] The embodiments of the present disclosure provide a computer program product or a computer program, which includes computer instructions stored in a computer-readable storage medium. A processor of a computer device reads the computer instructions from the computer-readable storage medium, and the processor executes the computer instructions, so that the computer device executes the methods provided in the above-mentioned various optional implementations.
[0197] The exemplary embodiments of the present disclosure are specifically shown and described above. It should be understood that the present disclosure is not limited to the detailed structures, configurations or implementations described herein; on the contrary, the present disclosure is intended to cover various modifications and equivalent configurations included in the spirit and scope of the appended claims.
Claims
1. A database processing method, characterized in that: include: In response to executing the data migration instruction, the usage status of the virtual slot where the data to be migrated is located in the first node is set as migrated, wherein the data migration instruction includes an instruction to migrate the data to be migrated stored in the source node to a target node, the first node is a slave node in the database cluster, and the source node and the target node are both the master nodes of the first node in the database cluster.
2. The method according to claim 1, characterized in that The first node includes all slave nodes on the shard corresponding to the virtual slot where the data to be migrated is located.
3. The method according to claim 1 or 2, characterized in that: Also includes: In response to executing an instruction to expand the capacity of the database cluster, the target node is added to the database cluster.
4. The method according to claim 3, characterized in that Also includes: The migration target of multiple shards in the database cluster is set as the target node, and the multiple shards include the shard corresponding to the virtual slot where the data to be migrated is located.
5. A database processing method, characterized in that: Applied to a database cluster, the method includes: In response to receiving a first data query request, querying data corresponding to a first keyword in a first node, the first node being a slave node in the database cluster, the data query request including the first keyword; In response to not finding data corresponding to the first keyword in the first node, obtaining a usage status of a virtual slot to which the first keyword belongs in the first node; In response to determining that the virtual slot to which the first keyword belongs is in use status of being migrated out in the first node, indication information is returned, the indication information including information of a target node, and the status of the virtual slot to which the first keyword belongs in the target node is being migrated in.
6. The method according to claim 5, characterized in that Also includes: In response to executing the data migration instruction, the use state of the virtual slot where the data to be migrated is located in the first node is set as migrated, wherein the data migration instruction includes instructions to migrate the data to be migrated stored in the source node to the target node, the data to be migrated includes data corresponding to the first keyword, and the source node and the target node are both the primary nodes of the first node in the database cluster.
7. The method according to claim 5, characterized in that Also includes: In response to executing the data migration instruction, the usage status of the virtual slot where the data to be migrated is located in a plurality of nodes on the corresponding shard is set as migration, wherein the data migration instruction includes instructions to migrate the data to be migrated stored in the source node to the target node, the data to be migrated includes data corresponding to the first keyword, the multiple nodes include the source node and the first node, and the source node and the target node are both master nodes of the first node in the database cluster.
8. The method according to claim 6 or 7, characterized in that: Also includes: In response to executing an instruction to expand the capacity of the database cluster, the target node is added to the database cluster.
9. The method according to claim 8, characterized in that Also includes: The migration target of multiple shards in the database cluster is set as the target node, and the multiple shards include the shard corresponding to the virtual slot where the data to be migrated is located.
10. A database processing method, characterized in that: Applied to a client, the client is used to access the database cluster in the database processing method according to any one of claims 1 to 9, the database cluster includes an application node, and the method includes: In response to executing a second data query instruction, obtaining a second keyword to be queried from the second data query instruction; Obtaining information about the virtual slot to which the second keyword belongs; Acquire information of a shard corresponding to the virtual slot to which the second keyword belongs according to information of the virtual slot to which the second keyword belongs; According to the information of the shard corresponding to the virtual slot to which the second keyword belongs, acquiring data center identification information of multiple nodes on the shard corresponding to the virtual slot to which the second keyword belongs; Obtaining data center identification information of the application node; According to the data center identification information of the application node and the data center identification information of the multiple nodes, at least one node in the multiple nodes that is in the same data center as where the application node is located is queried for data corresponding to the second keyword.
11. The method according to claim 10, characterized in that According to the data center identification information of the application node and the data center identification information of the multiple nodes, querying at least one node in the multiple nodes that is in the same data center as where the application node is located for data corresponding to the second keyword includes: Compare the data center identification information of the application node with the data center identification information of the multiple nodes respectively, and determine at least one node whose data center identification information is the same as the data center identification information of the multiple nodes as the node to be queried; The node to be queried is searched for data corresponding to the second keyword.
12. The method according to claim 11, characterized in that Comparing the data center identification information of the application node with the data center identification information of the multiple nodes respectively, and determining at least one node whose data center identification information is the same as the data center identification information of the multiple nodes as the node to be queried, includes: Compare the data center identification information of the application node with the data center identification information of the multiple nodes respectively, and determine multiple nodes whose data center identification information is the same as the data center identification information of the multiple nodes as candidate nodes to be queried; At least one slave node is selected from a plurality of candidate nodes to be queried as the node to be queried.
13. A database processing method, characterized in that: The database cluster used in the database processing method according to any one of claims 1 to 9, the method comprising: In response to determining that a master node in the database cluster fails, obtaining data center identification information of the master node; Obtaining data center identification information of multiple slave nodes of the master node; According to the data center identification information of the master node and its multiple slave nodes, a slave node in the same data center as that of the master node is selected from the multiple slave nodes of the master node as a new master node in the database cluster.
14. The method according to claim 13, characterized in that Also includes: In response to a request to add a node to the database cluster, data center identification information of the node is obtained and the data center identification information is associated with the node, wherein the node is the master node and at least one of its multiple slave nodes.
15. The method according to claim 13 or 14, characterized in that According to the data center identification information of the master node and its multiple slave nodes, selecting a slave node in the same data center as that of the master node from the multiple slave nodes of the master node as a new master node in the database cluster, including: Determine multiple candidate nodes from the multiple slave nodes of the master node according to the data center identification information of the master node and the multiple slave nodes thereof, wherein the multiple candidate nodes are all in the same data center as that of the master node; Obtaining priority information of the multiple candidate nodes; According to the priority information of the multiple candidate nodes, a candidate node with the highest priority is determined from the multiple candidate nodes as a new master node in the database cluster.
16. The method according to claim 13 or 14, characterized in that Also includes: In response to executing a master node switching instruction, target data center identification information is obtained, and multiple slave nodes deployed in the data center corresponding to the target data center identification information are set as new master nodes in the database cluster, wherein the data center corresponding to the target data center identification information is different from the data center corresponding to the data center identification information of the master node.
17. A database processing device, characterized in that: include: The setting module is configured to set the usage state of the virtual slot where the data to be migrated in the first node in response to executing the data migration instruction, wherein the data migration instruction includes an instruction to migrate the data to be migrated in the source node to a target node, the first node is a slave node in the database cluster, and the source node and the target node are both the master nodes of the first node in the database cluster.
18. A database processing device, characterized in that: Applied to a database cluster, the device comprises: a reading module, configured to query data corresponding to a first keyword in a first node in response to receiving a first data query request, wherein the first node is a slave node in the database cluster, and the data query request includes the first keyword; an acquisition module, configured to acquire, in response to not finding data corresponding to the first keyword in the first node, a usage status of a virtual slot to which the first keyword belongs in the first node; The return module is used to return indication information in response to determining that the usage status of the virtual slot to which the first keyword belongs in the first node is being migrated out, wherein the indication information includes information of a target node, and the status of the virtual slot to which the first keyword belongs in the target node is being migrated in.
19. A database processing device, characterized in that: Applied to a client, the client is used to access the database cluster in the database processing method according to any one of claims 1 to 9, the database cluster includes an application node, and the device includes: The acquisition module is configured to obtain the second keyword to be queried in response to executing the second data query instruction; to obtain information of the virtual slot to which the second keyword belongs; to obtain information of the shard corresponding to the virtual slot to which the second keyword belongs according to the information of the virtual slot to which the second keyword belongs; to obtain data center identification information of multiple nodes on the shard corresponding to the virtual slot to which the second keyword belongs according to the information of the shard corresponding to the virtual slot to which the second keyword belongs; to obtain data center identification information of the application node; A query module is used to query data corresponding to the second keyword in at least one node in the multiple nodes that is in the same data center as the application node based on the data center identification information of the application node and the data center identification information of the multiple nodes.
20. A database processing device, characterized in that: The database cluster used in the database processing method according to any one of claims 1 to 9, the device comprising: An acquisition module, configured to acquire data center identification information of the master node in response to determining that the master node in the database cluster fails; The acquisition module is further used to acquire data center identification information of multiple slave nodes of the master node; The election module is used to select a slave node in the same data center as the master node from among the multiple slave nodes of the master node as a new master node in the database cluster according to the data center identification information of the master node and its multiple slave nodes.
21. An electronic device, comprising: A memory, a processor, and executable instructions stored in the memory and executable in the processor, characterized in that when the processor executes the executable instructions, the method as described in any one of claims 1-4 or claims 5-9 or claims 10-12 or claims 13-16 is implemented.
22. A computer-readable storage medium having computer-executable instructions stored thereon, characterized in that: When the executable instructions are executed by a processor, the method according to any one of claims 1 to 4, claims 5 to 9, claims 10 to 12, or claims 13 to 16 is implemented.
23. A computer program product comprising a computer program / instructions, characterized in that When the computer program / instructions are executed by a processor, the method according to any one of claims 1-4, claims 5-9, claims 10-12, or claims 13-16 is implemented.
Citation Information
Patent Citations
Data migration method and data migration apparatus
CN105468473A
Data query method and system
CN108416039A
Storage cluster capacity expansion method and device, computer equipment and storage medium
CN117435129A
Data migration method and device, electronic equipment and storage medium
CN118051501A
Method and device for data migration in database cluster and storage medium
WO2018099397A1
