Cluster management method and device, storage medium and electronic equipment
By determining abnormal nodes in the cluster and partitioning adjustments to the partitions to be adjusted, the problem of IO overload and self-healing time of the cluster during burst read and write requests is solved, and the rapid recovery and normal function use of the cluster are achieved.
Patent Information
- Application Number
- CN202510129299.9
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-02-05
- Publication Date
- 2025-06-13
AI Technical Summary
When the cluster bursts with a large number of read and write requests, individual server disk IO is overloaded, resulting in unsynchronized partitions and abnormal nodes, and messages are backlogged, affecting the use of functions. The self-healing process of the prior art takes a long time and cannot effectively improve the cluster recovery speed.
By obtaining the cluster partition indication data of the target cluster, identify the abnormal node, and perform partition adjustments on the adjusted partitions, so that the main replica is not located on the abnormal node, thereby speeding up the speed of the cluster to recover from the abnormal state to a healthy state.
It effectively improves the recovery speed of the cluster, reduces the pressure on abnormal nodes, and ensures the normal flow of messages and the normal use of functions.
Smart Images

Figure CN120144343A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of computer technology, and in particular, to a cluster management method, device, storage medium, and electronic device. Background Art
[0002] When a large number of read and write requests occur suddenly in a cluster, it will cause the disk I / O (Input / Output) of individual servers to be fully utilized (i.e., overloaded). At the same time, unsynchronized partitions will appear in the cluster, and the read traffic of abnormal nodes will decrease, resulting in message backlogs and affecting the use of actual functions. However, related technologies usually wait for the cluster traffic to drop to the normal state and rely on the self-healing of the cluster, resulting in a long time-consuming process, that is, it takes a long time for the cluster to automatically recover to a healthy state. Based on this, there is currently no good solution to how to improve the recovery speed of the cluster. Summary of the Invention
[0003] In view of this, embodiments of the present invention provide a cluster management method, device, storage medium, and electronic device to solve problems such as the long time-consuming process for the cluster to recover from an abnormal state to a healthy state. That is to say, embodiments of the present invention can achieve partition adjustment of a target cluster by adjusting the partitions of each partition to be adjusted in the target cluster, so as to obtain the target cluster after partition adjustment, such that the primary replicas of each partition to be adjusted in the target cluster after partition adjustment are not located on M abnormal nodes. Furthermore, by adjusting the distribution of the primary replicas on the abnormal nodes, the speed at which the cluster recovers from an abnormal state to a healthy state can be accelerated, that is, the recovery speed of the cluster can be effectively improved.
[0004] According to an aspect of an embodiment of the present invention, a cluster management method is provided, and the method includes:
[0005] Obtain cluster partition indication data of a target cluster, where the cluster partition indication data includes partition indication information of each partition in the target cluster;
[0006] Determine M abnormal nodes in the target cluster, and based on the partition indication information of each partition, determine N pending partitions in the target cluster whose primary replicas are located on any one of the M abnormal nodes; where a partition has one primary replica and at least one secondary replica, and both M and N are non-negative integers;
[0007] Determine H partitions to be adjusted from the N pending partitions, where a partition to be adjusted is a synchronized partition, and H is a non-negative integer;
[0008] Perform partition adjustment on each partition to be adjusted among the H partitions to be adjusted, so that the target cluster is updated to the target cluster after partition adjustment, and the primary replicas of each partition to be adjusted in the target cluster after partition adjustment are not located on the M abnormal nodes.
[0009] According to another aspect of the embodiments of the present invention, a cluster management device is provided. The device includes:
[0010] An acquisition unit, configured to acquire cluster partition indication data of a target cluster, where the cluster partition indication data includes partition indication information of each partition in the target cluster;
[0011] A processing unit, configured to determine M abnormal nodes in the target cluster, and based on the partition indication information of each partition, determine N pending partitions in the target cluster where the primary replica is located on any one of the M abnormal nodes; where one partition has one primary replica and at least one secondary replica, and both M and N are non-negative integers;
[0012] The processing unit is further configured to determine H partitions to be adjusted from the N pending partitions, where one partition to be adjusted is a synchronized partition, and H is a non-negative integer;
[0013] The processing unit is further configured to perform partition adjustment on each partition to be adjusted in the H partitions to be adjusted, so that the target cluster is updated to the target cluster after partition adjustment, and the primary replica of each partition to be adjusted in the target cluster after partition adjustment is not located on any of the M abnormal nodes.
[0014] According to another aspect of the embodiments of the present invention, an electronic device is provided. The electronic device includes a processor and a memory storing a program, where the program includes instructions; the instructions, when executed by the processor, cause the processor to execute the method mentioned above.
[0015] According to another aspect of the implementation of the present invention, a non-transitory computer-readable storage medium storing computer instructions is provided, and the computer instructions are used to cause a computer to execute the method mentioned above.
[0016] After obtaining the cluster partition indication data of the target cluster in an embodiment of the present invention, M abnormal nodes in the target cluster can be determined, and based on the partition indication information of each partition, N pending partitions whose primary replicas are located on any one of the M abnormal nodes can be determined from the target cluster; where the cluster partition indication data includes the partition indication information of each partition in the target cluster, a partition has a primary replica and at least one secondary replica, and both M and N are non-negative integers. Further, H partitions to be adjusted can be determined from the N pending partitions, a partition to be adjusted is a synchronized partition, and H is a non-negative integer; and partition adjustment is performed on each partition to be adjusted among the H partitions to be adjusted, so that the target cluster is updated to the target cluster after partition adjustment, and the primary replicas of the respective partitions to be adjusted in the target cluster after partition adjustment are not located on the M abnormal nodes. It can be seen that the embodiment of the present invention can achieve partition adjustment of the target cluster by performing partition adjustment on each partition to be adjusted in the target cluster, so as to obtain the target cluster after partition adjustment, so that the primary replicas of the respective partitions to be adjusted in the target cluster after partition adjustment are not located on the M abnormal nodes, and further, by adjusting the distribution of the primary replicas on the abnormal nodes, the speed of the cluster recovering from the abnormal state to the healthy state can be accelerated, that is, the recovery speed of the cluster can be effectively improved. Description of the Drawings
[0017] In the following description of exemplary embodiments with reference to the drawings, more details, features, and advantages of the present invention are disclosed. In the drawings:
[0018] Figure 1 A flowchart showing a cluster management method according to an exemplary embodiment of the present invention is shown;
[0019] Figure 2 A schematic diagram showing a kind of cluster partition indication data according to an exemplary embodiment of the present invention is shown;
[0020] Figure 3 A schematic diagram showing a kind of Kafka abnormal traffic adjustment tool according to an exemplary embodiment of the present invention is shown;
[0021] Figure 4 A flowchart showing another cluster management method according to an exemplary embodiment of the present invention is shown;
[0022] Figure 5 A flowchart showing still another cluster management method according to an exemplary embodiment of the present invention is shown;
[0023] Figure 6 A schematic diagram showing a kind of primary-secondary replica adjustment data according to an exemplary embodiment of the present invention is shown;
[0024] Figure 7Shows a schematic block diagram of a cluster management device according to an exemplary embodiment of the present invention;
[0025] Figure 8 Shows a structural block diagram of an exemplary electronic device that can be used to implement the embodiments of the present invention. Detailed implementation manners
[0026] Embodiments of the present invention will be described in more detail below with reference to the accompanying drawings. Although some embodiments of the present invention are shown in the drawings, it should be understood that the present invention can be implemented in various forms and should not be construed as limited to the embodiments set forth herein. On the contrary, these embodiments are provided to more thoroughly and completely understand the present invention. It should be understood that the drawings and embodiments of the present invention are only for exemplary purposes and are not used to limit the protection scope of the present invention.
[0027] It should be understood that the various steps recorded in the method embodiments of the present invention can be executed in different orders and / or executed in parallel. In addition, the method embodiments may include additional steps and / or omit the steps shown. The scope of the present invention is not limited in this regard.
[0028] The term "including" and its variants used herein are open-ended, that is, "including but not limited to". The term "based on" is "at least partially based 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. It should be noted that the concepts such as "first" and "second" mentioned in the present invention are only used to distinguish different devices, modules or units, and are not used to limit the order of functions performed by these devices, modules or units or their interdependent relationships.
[0029] It should be noted that the modifications of "one" and "multiple" mentioned in the present invention are illustrative rather than restrictive. Those skilled in the art should understand that unless clearly stated otherwise in the context, it should be understood as "one or more".
[0030] The names of the messages or information exchanged between multiple devices in the embodiments of the present invention are only for illustrative purposes and are not used to limit the scope of these messages or information.
[0031] It should be noted that the execution subject of the cluster management method provided in the embodiments of the present invention may be one or more electronic devices, and the present invention does not limit this; among them, the electronic device may be a terminal (i.e., a client) or a server. When the execution subject includes multiple electronic devices and at least one terminal and at least one server are included in the multiple electronic devices, the cluster management method provided in the embodiments of the present invention can be jointly executed by the terminal and the server. Correspondingly, the terminals mentioned here may include, but are not limited to: smart phones, tablet computers, laptop computers, desktop computers, smart watches, intelligent voice interaction devices, smart home appliances, vehicle-mounted terminals, aircraft, and so on. The server mentioned here may be an independent physical server, or a server cluster or distributed system composed of multiple physical servers, or a cloud server that provides basic cloud computing services such as cloud services, cloud databases, cloud computing, cloud functions, cloud storage, network services, cloud communications, middleware services, domain name services, security services, CDN (Content Delivery Network), and big data and artificial intelligence platforms, and so on.
[0032] Please refer to Figure 1 , the embodiments of the present invention propose a cluster management method, and this cluster management method can be executed by the above-mentioned electronic devices (terminals or servers); or, this cluster management method can be jointly executed by the terminal and the server. For the convenience of description, the subsequent description will take the electronic device executing this cluster management method as an example; as Figure 1 shown, this cluster management method may include the following steps S101-S104:
[0033] S101, obtain the cluster partition indication data of the target cluster, and the cluster partition indication data includes the partition indication information of each partition in the target cluster.
[0034] Optionally, the above target cluster can be any cluster, and the embodiments of the present invention do not limit this. Optionally, the target cluster can be a Kafka cluster (a distributed messaging system characterized by high-level scalability and high throughput). The Kafka cluster can provide an open-source message queue service, which can provide asynchronous large-flow writing and distribution functions for user messages, such as log collection, multiple parties reading the same data simultaneously, etc. Each message published to the Kafka cluster has a category, which is called a Topic. Physically, messages of different Topics are stored separately. Logically, although messages of a Topic are stored on one or more brokers (i.e., nodes, also known as Kafka brokers or Kafka broker servers, and a cluster consists of multiple brokers, and one broker can accommodate multiple topics), users only need to specify the Topic of the message to produce or consume data without caring about where the data is stored. Based on this, the target cluster can include multiple nodes and at least one Topic, etc.
[0035] It should be understood that in order to achieve the scalability of the target cluster, one topic can be distributed to multiple nodes, and one topic can be divided into multiple partitions (i.e., sub-partitions). Each partition is an ordered queue that stores a part of the data of this topic. Each partition has one or more replicas (i.e., replicas). For example, a partition can consist of a leader (i.e., the main replica) and at least one follower (i.e., the secondary replica). Each partition may have multiple replicas, but one of these replicas will be selected as the leader, that is, the "master" among the multiple replicas. When the producer (i.e., the producer) sends data to the target cluster and the consumer (i.e., the consumer) pulls data, they both interact with the leader. The leader and the follower will keep the data synchronized. The secondary replica can ensure the security of the data. If the leader fails, a new leader will be selected from the followers. Therefore, the follower and the leader will not be in the same broker.
[0036] Based on this, the target cluster may include all partitions of each Topic in at least one Topic, that is, each partition in the target cluster may include each partition of each Topic in the target cluster. Optionally, the partition indication information of a partition may include, but is not limited to, at least one of the following: the node identifier of the leader replica of the corresponding partition (such as the node name or node number (i.e., id (Identity document, identity identification number)), etc.), replica indication information (which may also be expressed as Replicas or AR (Assigned Replicas), and can represent all replicas of a partition), in-sync replica indication information (which may also be expressed as Isr (In-Sync Replicas, and can represent the set composed of the follower that can keep in sync with the leader and the leader itself)), the Topic identifier of the Topic to which it belongs (such as the Topic name or Topic number, etc.), and the partition identifier (such as the partition name or partition number, etc.), and so on; the embodiments of the present invention do not limit this. Exemplarily, the cluster partition indication data may be as Figure 2 shown; for example, the Topic identifier of the Topic to which the partition indicated by the partition identifier 0 (subsequently referred to as partition 0 for short) belongs is Topic identifier A, the node identifier of the leader replica of partition 0 is 8 (which can be used to indicate that the leader replica of partition 0 is located on the node indicated by the node identifier 8), and the replica indication information of partition 0 can be used to indicate that the node identifiers of each replica of partition 0 are 8 and 9 respectively, and so on. Among them, a node identifier can be used to indicate a node, a Topic identifier can be used to indicate a Topic, a partition identifier can be used to indicate a partition, and so on.
[0037] Optionally, the replica indication information of a partition may include the node identifier of each replica in all replicas of the corresponding partition, and the node identifier of a replica can be used to indicate the node where the corresponding replica is located; optionally, the replica indication information of a partition may sequentially include the node identifier of the leader replica of the corresponding partition and the node identifier of each of at least one follower replica, that is, it can include the node identifier of each replica of the corresponding partition, so as to be used to indicate the node where each replica of the corresponding partition is located; based on this, the replica indication information of a partition is used to indicate all replicas of the corresponding partition, that is, it can be used to indicate the nodes where all replicas of the corresponding partition are located. Optionally, the in-sync replica indication information of a partition may include the node identifier of each replica (which may include the leader replica itself) in all replicas of the corresponding partition that is in sync with the leader replica of the corresponding partition; based on this, the in-sync replica indication information of a partition can be used to indicate each replica in all replicas of the corresponding partition that is in sync with the leader replica of the corresponding partition, that is, it can be used to indicate the nodes where each replica in all replicas of the corresponding partition that is in sync with the leader replica of the corresponding partition is located.
[0038] In the embodiments of the present invention, the acquisition methods of the cluster partition indication data of the target cluster may include but are not limited to the following several types:
[0039] The first acquisition method: The storage space of the electronic device stores the cluster addresses of each cluster in at least one cluster. In this case, the electronic device may use any one of the at least one cluster as the target cluster to obtain the cluster address of the target cluster. Optionally, the electronic device may obtain the cluster partition indication data of the target cluster at every preset monitoring duration by using the cluster address of the target cluster. Optionally, the preset monitoring duration may be set according to experience or according to actual requirements, and the embodiments of the present invention do not limit this. Based on this, the embodiments of the present invention can realize the automatic monitoring of the target cluster, so as to ensure the healthy state of the target cluster.
[0040] Optionally, the electronic device may call kafka - topics.sh - describe to obtain the cluster partition indication data of the target cluster based on the cluster address of the target cluster. Among them, the cluster partition indication data can be used to indicate the current topic and partition distribution in the target cluster. Among them, kafka - topics.sh - describe may be a command in the Kafka abnormal traffic adjustment tool (that is, it may be a kafka sh script). That is to say, if the electronic device integrates the Kafka abnormal traffic adjustment tool, then the electronic device can obtain the cluster partition indication data of the target cluster through the Kafka abnormal traffic adjustment tool based on the cluster address of the target cluster. That is to say, the kafka - topics.sh - describe command can be called through the Kafka abnormal traffic adjustment tool to obtain the cluster partition indication data of the target cluster based on the cluster address of the target cluster, as Figure 3 shown; Based on this, the electronic device mentioned in the embodiments of the present invention may be any device integrated with (i.e., installed with) the Kafka abnormal traffic adjustment tool.
[0041] The second acquisition method: The target object (i.e., the user) may perform a cluster management input operation. Then, when the electronic device detects the cluster management input operation, it may respond to the cluster management input operation and use the cluster address indicated by the cluster management input operation as the cluster address of the target cluster to obtain the cluster partition indication data of the target cluster, and so on.
[0042] It should be noted that the acquisition of the cluster partition indication data can be before or after determining the M abnormal nodes, and the embodiments of the present invention do not limit this; for example, if the M abnormal nodes are determined based on the cluster partition indication data, the acquisition of the cluster partition indication data needs to be executed before determining the M abnormal nodes, or if the M abnormal nodes are determined by the cluster management input operation, the cluster partition indication data can be acquired after determining the abnormal nodes, that is, the cluster partition indication data can be acquired after detecting the cluster management input operation, and so on.
[0043] S102. Determine M abnormal nodes in the target cluster, and based on the partition indication information of each partition, determine N pending partitions in the target cluster whose primary replicas are located on any one of the M abnormal nodes; where one partition has one primary replica and at least one secondary replica, and both M and N are non-negative integers.
[0044] Optionally, an abnormal node can refer to a node where the disk I / O is full, resulting in an under replicated partition, that is, the node where the primary replica of the under replicated partition is located. Among them, there is a data synchronization relationship between the primary replica and the secondary replicas of the kafka partition. When the data synchronization delay between the secondary replica and the primary replica is high and there is a large amount of unsynchronized data, this partition will become an under replicated partition.
[0045] It should be understood that when the value of M is 0, there are no abnormal nodes in the target cluster, and subsequent operations may not be performed, so as to wait for the next cluster management process of the target cluster.
[0046] S103. Determine H partitions to be adjusted from the N pending partitions, and one partition to be adjusted is a synchronized partition, and H is a non-negative integer.
[0047] Among them, a synchronized partition can refer to a partition where all replicas are synchronized with the corresponding primary replica, that is, the data synchronization delay between any replica and the primary replica of a synchronized partition is low and there is no large amount of unsynchronized data. Optionally, when the amount of unsynchronized data between a replica and the primary replica is less than a preset amount of unsynchronized data, it can be determined that the replica is synchronized with the primary replica; optionally, the preset amount of unsynchronized data can be set according to experience or according to actual requirements, and the embodiments of the present invention do not limit this.
[0048] S104. Perform partition adjustment on each partition to be adjusted among the H partitions to be adjusted, so that the target cluster is updated to the target cluster after partition adjustment, and the primary replicas of each partition to be adjusted in the target cluster after partition adjustment are not located on the M abnormal nodes.
[0049] In the embodiment of the present invention, after all partition adjustments are completed, it means that all adjustments at the entire cluster level are completed, and thus the target cluster after partition adjustment can be obtained. Based on this, in the embodiment of the present invention, through partition adjustment, the primary replica of any partition to be adjusted can be swapped to a normal node (i.e., a non-abnormal node), so that most of the traffic in the abnormal node can be migrated to other normal nodes, effectively reducing the pressure on disk I / O and accelerating the recovery of the abnormal node.
[0050] After obtaining the cluster partition indication data of the target cluster, the embodiment of the present invention can determine M abnormal nodes in the target cluster, and based on the partition indication information of each partition, determine N pending partitions in the target cluster whose primary replicas are located on any one of the M abnormal nodes; where the cluster partition indication data includes the partition indication information of each partition in the target cluster, a partition has a primary replica and at least one secondary replica, and both M and N are non-negative integers. Further, H partitions to be adjusted can be determined from the N pending partitions, and a partition to be adjusted is a synchronized partition, and H is a non-negative integer; and partition adjustment is performed on each partition to be adjusted among the H partitions to be adjusted, so that the target cluster is updated to the target cluster after partition adjustment, and the primary replicas of each partition to be adjusted in the target cluster after partition adjustment are not located on the M abnormal nodes. It can be seen that the embodiment of the present invention can realize the partition adjustment of the target cluster by performing partition adjustment on each partition to be adjusted in the target cluster, so as to obtain the target cluster after partition adjustment, so that the primary replicas of each partition to be adjusted in the target cluster after partition adjustment are not located on the M abnormal nodes, and further, by adjusting the distribution of the primary replicas on the abnormal nodes, the speed of the cluster recovering from the abnormal state to the healthy state can be accelerated, that is, the recovery speed of the cluster can be effectively improved.
[0051] Based on the above description, the embodiment of the present invention also proposes a more specific cluster management method, which can be executed by the above-mentioned electronic device (terminal or server); or, this cluster management method can be jointly executed by the terminal and the server. For the convenience of description, hereinafter, it will be described by taking the electronic device executing this cluster management method as an example; please refer to Figure 4 , this cluster management method may include the following steps S401-S406:
[0052] S401, obtain the cluster partition indication data of the target cluster, where the cluster partition indication data includes the partition indication information of each partition in the target cluster.
[0053] S402, determine M abnormal nodes in the target cluster, and based on the partition indication information of each partition, determine N pending partitions in the target cluster whose primary replicas are located on any one of the M abnormal nodes; where a partition has a primary replica and at least one secondary replica, and both M and N are non-negative integers.
[0054] In one implementation, when determining M abnormal nodes in a target cluster, the electronic device may determine M abnormal nodes from the target cluster based on the partition indication information of each partition. An abnormal node includes the primary replica of at least one unsynchronized partition in the target cluster. That is to say, the electronic device may regard each node in the target cluster that includes the primary replica of any unsynchronized partition as an abnormal node. Among them, an unsynchronized partition refers to a partition where there is a replica (such as any secondary replica) that is not synchronized with the primary replica. That is, an unsynchronized partition may refer to a partition where the replica indication information and the synchronized replica indication information are different. That is to say, when the replica indication information and the synchronized replica indication information of a partition are different, it can be determined that there is a replica in this partition that is not synchronized with the primary replica, so this partition can be regarded as an unsynchronized partition; correspondingly, a synchronized partition may refer to a partition where there is no replica that is not synchronized with the primary replica, that is, it may refer to a partition where the corresponding replicas are all consistent with the primary replica, that is, it may refer to a partition where the replica indication information and the synchronized replica indication information are the same. That is to say, when the replica indication information and the synchronized replica indication information of a partition are the same, it can be determined that each replica in this partition is consistent with the primary replica, so this partition can be regarded as a synchronized partition.
[0055] In an embodiment of the present invention, the target cluster may be a Kafka cluster. A partition indication information may include replica indication information and in-sync replica indication information of a corresponding partition. The replica indication information of a partition may be used to indicate all replicas of the corresponding partition, and the in-sync replica indication information of a partition may be used to indicate each replica that is in sync with the leader replica of the corresponding partition among all replicas of the corresponding partition. Based on this, when determining M abnormal nodes from the target cluster based on the partition indication information of each partition, for any node in the target cluster, the electronic device may, based on the partition indication information of each partition, determine whether there is at least one leader replica of an unsynchronized partition in any node. An unsynchronized partition refers to a partition where the replica indication information and the in-sync replica indication information are different. That is, it may be determined whether there is at least one leader replica of an unsynchronized partition in any node based on the replica indication information and the in-sync replica indication information of each partition. Optionally, the electronic device may first determine whether there is an unsynchronized partition in the target cluster based on the replica indication information and the in-sync replica indication information of each partition. When there is no unsynchronized partition in the target cluster, the value of M may be directly determined to be 0, that is, the M abnormal nodes are empty (at this time, there are no abnormal nodes in the target cluster). When there is an unsynchronized partition in the target cluster, the above determination of whether there is at least one leader replica of an unsynchronized partition in any node may be triggered; or, the electronic device may also directly trigger the above determination of whether there is at least one leader replica of an unsynchronized partition in any node, etc.; the embodiments of the present invention do not limit this. Then correspondingly, if there is at least one leader replica of an unsynchronized partition in any node, any node may be used as an abnormal node, that is, any node may be added to the M abnormal nodes; if there is no at least one leader replica of an unsynchronized partition in any node (that is, there is no leader replica of any unsynchronized partition), any node may not be used as an abnormal node, that is, any node may not be added to the M abnormal nodes, so as to determine M abnormal nodes from the target cluster based on the partition indication information of each partition.
[0056] In another implementation, the electronic device may, when detecting a cluster management input operation performed by the target object, in response to the cluster management input operation, and based on the abnormal node information indicated by the cluster management input operation, determine the M abnormal nodes. In this case, the target object may input the abnormal node information through the cluster management input operation; optionally, the abnormal node information may include, but is not limited to, at least one of the following: the node identifier, node address, etc. of each abnormal node in at least one abnormal node, and the embodiments of the present invention do not limit this; then correspondingly, the electronic device may add each node indicated by the abnormal node information indicated by the cluster management input operation to the M abnormal nodes, so as to determine the M abnormal nodes. Exemplarily, such as Figure 5As shown, the target object can perform a cluster management input operation to pass in the cluster address of the target cluster to be processed and the information of abnormal nodes, so that the electronic device can call the kafka-topics.sh -describe command to obtain all topic and partition replica information (i.e., the cluster partition indication data of the target cluster), and so on.
[0057] In another implementation, the electronic device can also obtain the IO occupancy rate of each node in the target cluster, and can use the nodes with an IO occupancy rate greater than the preset IO occupancy rate threshold as abnormal nodes respectively to determine M abnormal nodes, and so on. Optionally, the preset IO occupancy rate threshold can be set according to experience or according to actual requirements, and the embodiments of the present invention do not limit this.
[0058] Optionally, the partition indication information of a partition may include the node identifier of the leader replica of the corresponding partition, and the node identifier of a replica is used to indicate the node where the corresponding replica is located. Based on this, when determining N pending partitions whose leader replicas are located on any of the M abnormal nodes from the target cluster based on the partition indication information of each partition, the electronic device can traverse each partition in the target cluster and use the currently traversed partition as the current partition; further, based on the partition indication information of the current partition, it can be determined whether there is a node identifier in the node identifiers of the M abnormal nodes that is the same as the node identifier of the leader replica of the current partition; if there is a node identifier in the node identifiers of the M abnormal nodes that is the same as the node identifier of the leader replica of the current partition, it can be determined that the leader replica of the current partition is located on any of the M abnormal nodes (i.e., it can be determined that the leader replica of the current partition is located on the M abnormal nodes), and the current partition is added to the N pending partitions, that is, the current partition can be used as a pending partition; if there is no node identifier in the node identifiers of the M abnormal nodes that is the same as the node identifier of the leader replica of the current partition, it can be determined that the leader replica of the current partition is not located on each of the M abnormal nodes (i.e., it can be determined that the leader replica of the current partition is not located on the M abnormal nodes), so the current partition is not added to the N pending partitions, that is, the current partition is not used as a pending partition; after traversing all partitions in the target cluster, N pending partitions can be obtained.
[0059] S403, determine H partitions to be adjusted from the N pending partitions, and a partition to be adjusted is a synchronized partition, where H is a non-negative integer.
[0060] In the embodiments of the present invention, the electronic device can determine all synchronized partitions from the N pending partitions, and use each determined synchronized partition as a partition to be adjusted respectively.
[0061] Optionally, for any one of the N pending partitions, the electronic device may determine whether the replica indication information of any one of the pending partitions is the same as the synchronized replica indication information; if the replica indication information of any one of the pending partitions is the same as the synchronized replica indication information (in this case, it can be determined that any one of the pending partitions is a synchronized partition), then any one of the pending partitions may be added to the H partitions to be adjusted, that is, any one of the pending partitions may be used as a partition to be adjusted; if the replica indication information of any one of the pending partitions is different from the synchronized replica indication information (in this case, it can be determined that any one of the pending partitions is an unsynchronized partition), then any one of the pending partitions may not be added to the H partitions to be adjusted, that is, any one of the pending partitions may not be used as a partition to be adjusted, so as to determine H partitions to be adjusted from the N pending partitions.
[0062] It can be seen that the electronic device may determine whether there is a node identifier in the node identifiers of the M abnormal nodes that is the same as the node identifier of the primary replica of the current partition. If there is a node identifier in the node identifiers of the M abnormal nodes that is the same as the node identifier of the primary replica of the current partition, then it may be determined whether the replica indication information and the synchronized replica indication information of the current partition are the same; when the replica indication information and the synchronized replica indication information of the current partition are the same, the current partition may be used as a partition to be adjusted, so as to obtain H partitions to be adjusted after traversing each partition in the target cluster, thereby implementing the above determination of H partitions to be adjusted.
[0063] Optionally, when the replica indication information and the synchronized replica indication information of any one of the pending partitions are the same, the electronic device may further determine whether there is a replica among at least one secondary replica of any one of the pending partitions that is on a normal node other than the M abnormal nodes in the target cluster; if there is a replica among at least one secondary replica of any one of the pending partitions that is on a normal node, then trigger the execution of adding any one of the pending partitions to the H partitions to be adjusted; if there is no replica among at least one secondary replica of any one of the pending partitions that is on a normal node, then do not trigger the execution of adding any one of the pending partitions to the H partitions to be adjusted, and so on. Based on this, the embodiments of the present invention can avoid adjusting the primary replica of any partition to a certain secondary replica of any partition located on the M abnormal nodes, thereby avoiding performing invalid operations and further avoiding resource waste.
[0064] Optionally, the electronic device may also mark each partition to be adjusted as to be operated. At this time, a partition to be adjusted may also be referred to as a partition to be operated.
[0065] S404, based on the partition indication information of each partition to be adjusted among the H partitions to be adjusted, respectively determine the replica indication information to be adjusted of each partition to be adjusted.
[0066] Among them, the replica indication information to be adjusted of a partition to be adjusted may include the adjusted node identifier of each replica of the corresponding partition to be adjusted.
[0067] In an embodiment of the present invention, for any one of the H partitions to be adjusted, the electronic device may determine the replica indication information to be adjusted for any one of the partitions to be adjusted based on the replica indication information in the partition indication information of any one of the partitions to be adjusted (that is, based on the replica indication information of any one of the partitions to be adjusted), that is, the adjustment node identifier of each replica of any one of the partitions to be adjusted can be determined; that is to say, the replica indication information of a partition may include the node identifiers of each replica of the corresponding partition. Then, the electronic device may determine the adjustment node identifier of each replica of any one of the partitions to be adjusted based on the node identifiers of each replica of any one of the partitions to be adjusted, so as to determine the replica indication information to be adjusted for any one of the partitions to be adjusted.
[0068] Optionally, the electronic device may determine an adjusted slave replica from at least one slave replica in any one of the partitions to be adjusted, and switch the node identifier of the adjusted slave replica with the node identifier of the master replica of any one of the partitions to be adjusted, so as to obtain the adjustment node identifier of each replica of any one of the partitions to be adjusted. At this time, the adjustment node identifier of the master replica of any one of the partitions to be adjusted may be the node identifier of the adjusted slave replica, and the adjustment node identifier of the adjusted slave replica may be the node identifier of the master replica of any one of the partitions to be adjusted. The adjustment node identifiers of each replica other than the master replica and the adjusted slave replica in all replicas of any one of the partitions to be adjusted are the node identifiers of the corresponding replicas (that is, can remain unchanged). For example, assuming that the node identifiers of each replica of any one of the partitions to be adjusted are 2 (the node identifier of the master replica) and 3 (the node identifier of the slave replica) in sequence, then the adjustment node identifiers of each replica of any one of the partitions to be adjusted may be 3 (the adjustment node identifier of the master replica) and 2 (the adjustment node identifier of the slave replica) in sequence; another example, assuming that the node identifiers of each replica of any one of the partitions to be adjusted are 7 (the node identifier of the master replica), 8 (the node identifier of one slave replica), 9 (the node identifier of another slave replica) in sequence, and the adjusted slave replica is the second replica (that is, the slave replica with the node identifier of 8), then the adjustment node identifiers of each replica of any one of the partitions to be adjusted may be 8, 7, 9, and so on.
[0069] Optionally, the electronic device may use the first slave replica in at least one slave replica of any one of the partitions to be adjusted (that is, the second replica of any one of the partitions to be adjusted) as the adjusted slave replica; or, it may also randomly select an adjusted slave replica from at least one slave replica; or, it may use the first slave replica that is not on M abnormal nodes in at least one slave replica as the adjusted slave replica, and so on; the embodiments of the present invention do not limit this.
[0070] S405, generate master-slave replica adjustment data based on the replica indication information to be adjusted for each partition to be adjusted.
[0071] Optionally, the electronic device may generate master-slave replica adjustment data according to a preset adjustment format based on the replica indication information to be adjusted for each partition to be adjusted. Optionally, the preset adjustment format may be a JSON format (JavaScript Object Notation, a lightweight data interchange format). In this case, the master-slave replica adjustment data may also be referred to as the master-slave replica adjustment JSON. Optionally, the preset adjustment format may be set according to experience or according to actual requirements, which is not limited in the embodiments of the present invention. Optionally, the preset adjustment format may include, but is not limited to, at least one of the following: replica indication information, partition identifier, and topic identifier, etc., which is not limited in the embodiments of the present invention.
[0072] Optionally, the electronic device may generate master-slave replica adjustment data based on the replica indication information to be adjusted for each partition to be adjusted, the partition identifier, and the topic identifier of the topic to which it belongs. Exemplarily, assume that H partitions to be adjusted include the partition indicated by partition identifier 0 (i.e., partition 0) and the partition indicated by partition identifier 1 (i.e., partition 1). The adjustment node identifiers of each replica in the replica indication information to be adjusted for partition 0 are 6 and 7 in sequence, and the adjustment node identifiers of each replica in the replica indication information to be adjusted for partition 1 are 8 and 7 in sequence, so that the master-slave replica adjustment data as shown in Figure 6 can be generated. Among them, Figure 6 the log_dirs in can refer to the files where each replica of a partition is located, which can be any file here.
[0073] Based on this, the embodiments of the present invention may swap the master and slave of the partition to be adjusted according to the partition adjustment method to generate the to-be-switched JSON (i.e., the master-slave replica adjustment data), that is, the order of the node identifiers of the master replica and the node identifiers of the slave replica (such as the slave replica to be adjusted) in the array can be adjusted. The node identifier of the master replica can be adjusted to be behind, and the node identifier of the slave replica can be adjusted to be in front, thereby generating the master-slave replica adjustment data.
[0074] S406. Perform partition adjustment on each partition to be adjusted based on the master-slave replica adjustment data.
[0075] Based on this, the target cluster can be updated to the target cluster after partition adjustment. The master replicas of each partition to be adjusted in the target cluster after partition adjustment are not located on the M abnormal nodes, that is, the master replicas of each partition to be adjusted in the target cluster after partition adjustment are not located on each of the M abnormal nodes. Thus, the master replica of any partition to be adjusted is adjusted to be a replica on other nodes (i.e., normal nodes) other than the M abnormal nodes. In other words, the electronic device can perform partition adjustment on each partition to be adjusted to obtain the target cluster after partition adjustment.
[0076] In an embodiment of the present invention, the electronic device can execute master-slave replica adjustment data so that the master-slave replicas of each partition to be adjusted are adjusted according to the replica indication information to be adjusted of the corresponding partition to be adjusted, so that the master replica of any partition to be adjusted is adjusted to: any replica of the partition to be adjusted on the node indicated by the first adjustment node identifier in the replica indication information to be adjusted of any partition to be adjusted (here it is any slave replica of any partition to be adjusted). Optionally, the electronic device can call the above abnormal adjustment tool (i.e., the Kafka abnormal traffic adjustment tool) to execute the master-slave replica adjustment data; optionally, the electronic device can call the kafka-reassign-partitions.sh --execute command in the tool to execute the master-slave replica adjustment data, thereby starting to execute the adjustment task, that is, the master-slave distribution of the partition to be adjusted can be adjusted. In this case, all topics in the target cluster can be traversed again, and the kafka-reassign-partitions.sh --execute command can be called to execute the master-slave replica adjustment data to adjust the master-slave distribution of the partition. Based on this, any replica of the partition to be adjusted on the node indicated by the first adjustment node identifier in the replica indication information to be adjusted of any partition to be adjusted can be adjusted to the master replica of any partition to be adjusted, that is, at this time, the master replica of any partition to be adjusted can be located on the node indicated by the first adjustment node identifier in the replica indication information to be adjusted of any partition to be adjusted, so that the master replica of any partition to be adjusted can be adjusted to any replica of the partition to be adjusted in the normal node, that is to say, the slave replica of any partition to be adjusted in the normal node can be adjusted to the master replica of any partition to be adjusted.
[0077] Optionally, the electronic device can also call the kafka-reassign-partitions.sh --verify command to determine the adjustment completion indication data, which can be used to indicate whether the master and slave replicas of each partition to be adjusted are adjusted successfully; when the adjustment completion indication data is used to indicate that the master and slave replicas of each partition to be adjusted are adjusted successfully, the following master-slave switch for each partition to be adjusted can be triggered. At this time, the expected master and slave have completed the swap; optionally, the electronic device can call the kafka-reassign-partitions.sh --verify command every preset determination duration to determine the adjustment completion indication data until the adjustment completion indication data is used to indicate that the master and slave replicas of each partition to be adjusted are adjusted successfully. Optionally, in other embodiments, the electronic device can also directly trigger the following master-slave switch for each partition to be adjusted after executing the master-slave replica adjustment data, with a preset waiting completion duration in between, and so on; the present invention does not limit this. Optionally, both the preset determination duration and the preset waiting completion duration can be set according to experience or according to actual requirements, and the embodiments of the present invention do not limit this.
[0078] Furthermore, the electronic device can perform a master-slave switch for each partition to be adjusted to achieve partition adjustment for each partition to be adjusted based on the master-slave replica adjustment data, so that the read and write traffic of any partition to be adjusted is migrated to the normal nodes of the target cluster. Optionally, the electronic device can traverse all topics of the target cluster again and call the kafka-preferred-replica-election.sh command to perform a master-slave switch for each partition to be adjusted, thus completing the master-slave switch operation. In summary, the embodiments of the present invention can provide Kafka sh scripts through the Kafka abnormal traffic adjustment tool. The Kafka sh scripts can provide the ability to access the Kafka cluster and operate on the Kafka cluster, thereby realizing cluster management.
[0079] It should be understood that in Kafka, the master replica is responsible for reading and writing and synchronizes data to the slave replicas. Assuming a one-master-one-slave scenario where the read traffic is equal to the write traffic, the pressure on the master replica can be regarded as 3 parts (writing, reading, synchronization), while the slave replica only has 1 part (synchronization); based on this, the embodiments of the present invention can swap the roles of the master and slave replicas. Then, on the node with full IO (i.e., the abnormal node), the pressure corresponding to the abnormal partition (i.e., the master replica of the unsynchronized partition) will be reduced by 2 / 3; based on this, the embodiments of the present invention can adjust the master replica of the synchronized partition with message backlog in the node with full IO to other nodes (such as other normal nodes), thereby reducing the pressure on the abnormal node and accelerating the speed of the abnormal node's recovery to a healthy state.
[0080] After obtaining the cluster partition indication data of the target cluster, an embodiment of the present invention can determine M abnormal nodes in the target cluster, and based on the partition indication information of each partition, determine N pending partitions in the target cluster whose primary replicas are located on any one of the M abnormal nodes; where the cluster partition indication data includes the partition indication information of each partition in the target cluster, a partition has a primary replica and at least one secondary replica, and both M and N are non-negative integers. Based on this, H pending partitions can be determined from the N pending partitions, and a pending partition is a synchronized partition, and H is a non-negative integer; and based on the partition indication information of each pending partition among the H pending partitions, the pending replica indication information of each pending partition is determined respectively. Further, the primary-secondary replica adjustment data can be generated based on the pending replica indication information of each pending partition; and based on the primary-secondary replica adjustment data, partition adjustment is performed on each pending partition, so that the target cluster is updated to the target cluster after partition adjustment, and the primary replicas of each pending partition in the target cluster after partition adjustment are not located on the M abnormal nodes. It can be seen that the embodiment of the present invention can adjust the distribution of the primary replicas on the abnormal nodes, that is, through the abnormal adjustment tool, the roles of the primary replicas in the abnormal nodes and the secondary replicas in the normal nodes can be exchanged to reduce the pressure on the abnormal nodes and accelerate the speed of the cluster's recovery to health, that is, the speed of the cluster's recovery from the abnormal state to the healthy state can be accelerated; at the same time, the embodiment of the present invention can place no restrictions on business reading and writing, thus effectively ensuring the normal use of the business.
[0081] Based on the description of the related embodiments of the above cluster management method, an embodiment of the present invention also proposes a cluster management device, and this cluster management device can be a computer program (including program code) running in an electronic device; as Figure 7 shown, this cluster management device may include an acquisition unit 701 and a processing unit 702. This cluster management device can execute Figure 1 or Figure 4 shown cluster management method, that is, this cluster management device can run the above units:
[0082] The acquisition unit 701 is used to acquire the cluster partition indication data of the target cluster, and the cluster partition indication data includes the partition indication information of each partition in the target cluster;
[0083] The processing unit 702 is used to determine M abnormal nodes in the target cluster, and based on the partition indication information of each partition, determine N pending partitions in the target cluster whose primary replicas are located on any one of the M abnormal nodes; where a partition has a primary replica and at least one secondary replica, and both M and N are non-negative integers;
[0084] The processing unit 702 is further configured to determine H to-be-adjusted partitions from the N to-be-determined partitions, where one to-be-adjusted partition is a synchronized partition, and H is a non-negative integer;
[0085] The processing unit 702 is further configured to perform partition adjustment on each of the H to-be-adjusted partitions, so that the target cluster is updated to the target cluster after partition adjustment, and the primary replicas of the respective to-be-adjusted partitions in the target cluster after partition adjustment are not located on the M abnormal nodes.
[0086] In one implementation, when determining the M abnormal nodes in the target cluster, the processing unit 702 may specifically be configured to:
[0087] Based on the partition indication information of each partition, determine M abnormal nodes from the target cluster, where one abnormal node includes the primary replicas of at least one unsynchronized partition in the target cluster; and / or,
[0088] When detecting a cluster management input operation performed by a target object, in response to the cluster management input operation, and based on the abnormal node information indicated by the cluster management input operation, determine the M abnormal nodes.
[0089] In another implementation, the target cluster is a Kafka cluster, one partition indication information includes the replica indication information and the in-sync replica indication information of the corresponding partition, the replica indication information of one partition is used to indicate all replicas of the corresponding partition, and the in-sync replica indication information of one partition is used to indicate each replica that is in sync with the primary replica of the corresponding partition among all replicas of the corresponding partition; when the processing unit 702 determines M abnormal nodes from the target cluster based on the partition indication information of each partition, it may specifically be configured to:
[0090] For any node in the target cluster, based on the partition indication information of each partition, determine whether there is at least one primary replica of an unsynchronized partition in the any node, where an unsynchronized partition refers to a partition whose replica indication information and in-sync replica indication information are different;
[0091] If there is the at least one primary replica of an unsynchronized partition in the any node, then use the any node as an abnormal node;
[0092] If there is no such at least one primary replica of an unsynchronized partition in the any node, then do not use the any node as an abnormal node, so as to implement determining M abnormal nodes from the target cluster based on the partition indication information of each partition.
[0093] In another implementation, the partition indication information of a partition includes the node identifier of the primary replica of the corresponding partition, and the node identifier of a replica is used to indicate the node where the corresponding replica is located; when determining, based on the partition indication information of each partition, N pending partitions whose primary replicas are located on any one of the M abnormal nodes from the target cluster, the processing unit 702 may specifically be used for:
[0094] Traverse each partition in the target cluster, and use the currently traversed partition as the current partition;
[0095] Based on the partition indication information of the current partition, determine whether there is a node identifier in the node identifiers of the M abnormal nodes that is the same as the node identifier of the primary replica of the current partition;
[0096] If there is a node identifier in the node identifiers of the M abnormal nodes that is the same as the node identifier of the primary replica of the current partition, determine that the primary replica of the current partition is located on any one of the M abnormal nodes, and add the current partition to the N pending partitions;
[0097] After traversing each partition in the target cluster, obtain the N pending partitions.
[0098] In another implementation, when determining H partitions to be adjusted from the N pending partitions, the processing unit 702 may specifically be used for:
[0099] For any one of the N pending partitions, determine whether the replica indication information and the synchronous replica indication information of the any one of the pending partitions are the same;
[0100] If the replica indication information and the synchronous replica indication information of the any one of the pending partitions are the same, add the any one of the pending partitions to the H partitions to be adjusted;
[0101] If the replica indication information and the synchronous replica indication information of the any one of the pending partitions are different, do not add the any one of the pending partitions to the H partitions to be adjusted, so as to implement determining H partitions to be adjusted from the N pending partitions.
[0102] In another implementation, when performing partition adjustment on each partition to be adjusted among the H partitions to be adjusted, the processing unit 702 may specifically be used for:
[0103] Based on the partition indication information of each partition to be adjusted among the H partitions to be adjusted, respectively determine the replica indication information to be adjusted of each partition to be adjusted;
[0104] Generate master-slave replica adjustment data based on the replica indication information to be adjusted of each partition to be adjusted;
[0105] Partition adjustment is performed on each partition to be adjusted based on the master-slave replica adjusted data.
[0106] In another embodiment, when the processing unit 702 performs partition adjustment on each partition to be adjusted based on the master-slave replica adjusted data, it may specifically be used for:
[0107] Execute the master-slave replica adjusted data so that the master-slave replicas of each partition to be adjusted are adjusted according to the replica indication information to be adjusted of the corresponding partition to be adjusted, so that the master replica of any partition to be adjusted is adjusted to: any replica of the partition to be adjusted on the node indicated by the first adjustment node identifier in the replica indication information to be adjusted of the any partition to be adjusted;
[0108] Perform master-slave switching on each partition to be adjusted to implement partition adjustment on each partition to be adjusted based on the master-slave replica adjusted data, so that the read-write traffic of the any partition to be adjusted is migrated to the normal nodes of the target cluster.
[0109] According to an embodiment of the present invention, Figure 7 Each unit in the cluster management device shown can be separately or all combined into one or several other units to form, or a certain (some) unit can be further split into multiple smaller units in terms of function to form, which can achieve the same operation without affecting the realization of the technical effects of the embodiments of the present invention. The above units are divided based on logical functions. In practical applications, the function of one unit can also be realized by multiple units, or the functions of multiple units are realized by one unit. In other embodiments of the present invention, any cluster management device may also include other units. In practical applications, these functions can also be assisted by other units and can be realized by the cooperation of multiple units.
[0110] According to another embodiment of the present invention, it can be achieved by running a computer program (including program code) capable of executing the respective steps involved in the corresponding methods shown in Figure 1 or Figure 4 on a general-purpose electronic device such as a computer including processing elements and storage elements such as a central processing unit (CPU), a random access storage medium (RAM), and a read-only storage medium (ROM), to construct a cluster management device as shown in Figure 7 and to implement the cluster management method of the embodiments of the present invention. The computer program can be recorded on a computer storage medium, for example, and loaded into the above-mentioned electronic device through the computer storage medium and run therein.
[0111] After obtaining the cluster partition indication data of the target cluster, an embodiment of the present invention can determine M abnormal nodes in the target cluster, and based on the partition indication information of each partition, determine N pending partitions in the target cluster where the primary replica is located on any one of the M abnormal nodes; wherein, the cluster partition indication data includes the partition indication information of each partition in the target cluster, each partition has a primary replica and at least one secondary replica, and both M and N are non-negative integers. Further, H pending partitions can be determined from the N pending partitions, and a pending partition is a synchronized partition, and H is a non-negative integer; and partition adjustment is performed on each of the H pending partitions to update the target cluster to the target cluster after partition adjustment, and the primary replica of each pending partition in the target cluster after partition adjustment is not located on the M abnormal nodes. It can be seen that the embodiment of the present invention can achieve the partition adjustment of the target cluster by performing partition adjustment on each pending partition in the target cluster, so as to obtain the target cluster after partition adjustment, so that the primary replica of each pending partition in the target cluster after partition adjustment is not located on the M abnormal nodes, and further, by adjusting the distribution of the primary replicas on the abnormal nodes, the speed of the cluster recovering from the abnormal state to the healthy state can be accelerated, that is, the recovery speed of the cluster can be effectively improved.
[0112] Based on the descriptions of the above method embodiments and apparatus embodiments, an exemplary embodiment of the present invention further provides an electronic device, including: at least one processor; and a memory communicatively connected to the at least one processor. The memory stores a computer program capable of being executed by the at least one processor, and when the computer program is executed by the at least one processor, it is used to cause the electronic device to execute the method according to the embodiment of the present invention.
[0113] An exemplary embodiment of the present invention further provides a non-transitory computer-readable storage medium storing a computer program, wherein when the computer program is executed by a processor of a computer, it is used to cause the computer to execute the method according to the embodiment of the present invention.
[0114] An exemplary embodiment of the present invention further provides a computer program product, including a computer program, wherein when the computer program is executed by a processor of a computer, it is used to cause the computer to execute the method according to the embodiment of the present invention.
[0115] Reference Figure 8, a structural block diagram of an electronic device 800 that can be used as a server or a client of the present invention will now be described. It is an example of a hardware device that can be applied to various aspects of the present invention. The electronic device is intended to represent various forms of digital electronic computer devices, such as laptop computers, desktop computers, workstations, personal digital assistants, servers, blade servers, mainframe computers, and other suitable computers. The electronic device can also represent various forms of mobile devices, such as personal digital processors, cellular phones, smart phones, wearable devices, and other similar computing devices. The components shown herein, their connections and relationships, and their functions are merely examples and are not intended to limit the implementation of the present invention described herein and / or claimed.
[0116] As Figure 8 shown, the electronic device 800 includes a computing unit 801 that can perform various appropriate actions and processes according to a computer program stored in a read-only memory (ROM) 802 or a computer program loaded from a storage unit 808 into a random access memory (RAM) 803. In the RAM 803, various programs and data required for the operation of the electronic device 800 can also be stored. The computing unit 801, the ROM 802, and the RAM 803 are connected to each other via a bus 804. An input / output (I / O) interface 805 is also connected to the bus 804.
[0117] A plurality of components in the electronic device 800 are connected to the I / O interface 805, including: an input unit 806, an output unit 807, a storage unit 808, and a communication unit 809. The input unit 806 can be any type of device that can input information into the electronic device 800. The input unit 806 can receive input digital or character information and generate key signal inputs related to user settings and / or function controls of the electronic device. The output unit 807 can be any type of device that can present information and can include, but is not limited to, a display, a speaker, a video / audio output terminal, a vibrator, and / or a printer. The storage unit 808 can include, but is not limited to, magnetic disks and optical disks. The communication unit 809 allows the electronic device 800 to exchange information / data with other devices via a computer network such as the Internet and / or various telecommunication networks and can include, but is not limited to, a modem, a network card, an infrared communication device, a wireless communication transceiver, and / or a chipset, such as a Bluetooth™ device, a WiFi device, a WiMax device, a cellular communication device, and / or the like.
[0118] The computing unit 801 can be various general-purpose and / or special-purpose processing components with processing and computing capabilities. Some examples of the computing unit 801 include, but are not limited to, a central processing unit (CPU), a graphics processing unit (GPU), various dedicated artificial intelligence (AI) computing chips, various computing units running machine learning model algorithms, a digital signal processor (DSP), and any suitable processor, controller, microcontroller, etc. The computing unit 801 executes the various methods and processes described above. For example, in some embodiments, the cluster management method can be implemented as a computer software program tangibly embodied in a machine-readable medium, such as the storage unit 808. In some embodiments, part or all of the computer program can be loaded and / or installed onto the electronic device 800 via the ROM 802 and / or the communication unit 809. In some embodiments, the computing unit 801 can be configured to execute the cluster management method in any other suitable way (e.g., by means of firmware).
[0119] The program code for implementing the method of the present invention can be written in any combination of one or more programming languages. These program codes can be provided to a processor or controller of a general-purpose computer, a special-purpose computer, or other programmable data processing devices, such that when the program codes are executed by the processor or controller, the functions / operations specified in the flowcharts and / or block diagrams are implemented. The program code can be executed entirely on the machine, partially on the machine, as an independent software package partially on the machine and partially on a remote machine, or entirely on a remote machine or server.
[0120] In the context of the present invention, a machine-readable medium can be a tangible medium that can contain or store a program for use by or in connection with an instruction execution system, apparatus, or device. A machine-readable medium can be a machine-readable signal medium or a machine-readable storage medium. A machine-readable medium can include, but is not limited to, an electronic, magnetic, optical, electromagnetic, infrared, or semiconductor system, apparatus, or device, or any suitable combination of the foregoing. More specific examples of a machine-readable storage medium would 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 disc read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the foregoing.
[0121] As used in this invention, the terms "machine-readable medium" and "computer-readable medium" refer to any computer program product, apparatus, and / or device (e.g., a magnetic disk, an optical disk, a memory, a programmable logic device (PLD)) used to provide machine instructions and / or data to a programmable processor, including a machine-readable medium that receives machine instructions as a machine-readable signal. The term "machine-readable signal" refers to any signal used to provide machine instructions and / or data to a programmable processor.
[0122] To provide for interaction with a user, the systems and techniques described here can be implemented on a computer having: a display device (e.g., a CRT (cathode ray tube) or LCD (liquid crystal display) monitor) for displaying information to the user; and a keyboard and a pointing device (e.g., a mouse or a trackball) by which the user can provide input to the computer. Other kinds of devices can also be used to provide for interaction with the user; for example, feedback provided to the user can be any form of sensory feedback (e.g., visual feedback, auditory feedback, or tactile feedback); and input from the user can be received in any form (including acoustic, speech, or tactile input).
[0123] The systems and techniques described here can be implemented in a computing system including back-end components (e.g., as a data server), or a computing system including middleware components (e.g., an application server), or a computing system including front-end components (e.g., a user computer having a graphical user interface or a web browser through which the user can interact with an implementation of the systems and techniques described here), or in a computing system including any combination of such back-end components, middleware components, or front-end components. The components of the system can be interconnected by 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), and the Internet.
[0124] A computer system can include clients and servers. Clients and servers are generally remote from each other and typically interact through a communication network. The relationship of client and server arises by virtue of computer programs running on respective computers and having a client-server relationship to each other.
[0125] Also, it should be understood that what is disclosed above are only the preferred embodiments of the present invention, and of course cannot be used to limit the scope of rights of the present invention. Therefore, equivalent changes made in accordance with the claims of the present invention still fall within the scope covered by the present invention.
Claims
1. A cluster management method, characterized in that: include: Acquire cluster partition indication data of the target cluster, wherein the cluster partition indication data includes partition indication information of each partition in the target cluster; Determine M abnormal nodes in the target cluster, and based on the partition indication information of each partition, determine N pending partitions from the target cluster whose master replica is located on any abnormal node among the M abnormal nodes; wherein one partition has one master replica and at least one slave replica, and both M and N are non-negative integers; Determine H partitions to be adjusted from the N partitions to be determined, one partition to be adjusted is a synchronized partition, and H is a non-negative integer; Partition adjustment is performed on each of the H partitions to be adjusted, so that the target cluster is updated to a target cluster after partition adjustment, and the primary copy of each of the partitions to be adjusted in the target cluster after partition adjustment is not located on the M abnormal nodes.
2. The method according to claim 1, characterized in that The determining of the M abnormal nodes in the target cluster includes: Based on the partition indication information of each partition, M abnormal nodes are determined from the target cluster, where one abnormal node includes a primary replica of at least one unsynchronized partition in the target cluster; and / or, When a cluster management input operation performed by the target object is detected, the M abnormal nodes are determined in response to the cluster management input operation and based on abnormal node information indicated by the cluster management input operation.
3. The method according to claim 2, characterized in that The target cluster is a Kafka cluster, and a partition indication information includes replica indication information and synchronous replica indication information of a corresponding partition, wherein the replica indication information of a partition is used to indicate all replicas of the corresponding partition, and the synchronous replica indication information of a partition is used to indicate each replica among all replicas of the corresponding partition that is synchronized with the primary replica of the corresponding partition; The determining M abnormal nodes from the target cluster based on the partition indication information of each partition includes: For any node in the target cluster, based on the partition indication information of each partition, determine whether there is at least one primary replica of an unsynchronized partition in any node, where an unsynchronized partition refers to a partition for which the replica indication information and the synchronized replica indication information are different; If any of the nodes has a primary replica of the at least one unsynchronized partition, treat the any of the nodes as an abnormal node; If the primary replica of the at least one unsynchronized partition does not exist in any of the nodes, then the node is not regarded as an abnormal node, so as to determine M abnormal nodes from the target cluster based on the partition indication information of each partition.
4. The method according to any one of claims 1 to 3, characterized in that: The partition indication information of a partition includes a node identifier of a primary replica of the corresponding partition, and the node identifier of a replica is used to indicate a node where the corresponding replica is located; the determining, based on the partition indication information of each partition, N pending partitions whose primary replicas are located on any abnormal node among the M abnormal nodes from the target cluster includes: Traverse each partition in the target cluster, and use the currently traversed partition as the current partition; Based on the partition indication information of the current partition, determining whether there is a node identifier that is the same as the node identifier of the primary copy of the current partition among the node identifiers of the M abnormal nodes; If there is a node identifier among the node identifiers of the M abnormal nodes that is the same as the node identifier of the primary copy of the current partition, determine that the primary copy of the current partition is located on any abnormal node among the M abnormal nodes, and add the current partition to the N pending partitions; After traversing all partitions in the target cluster, the N pending partitions are obtained.
5. The method according to any one of claims 1 to 3, characterized in that: The determining H partitions to be adjusted from the N partitions to be determined includes: For any pending partition among the N pending partitions, determine whether the replica indication information and the synchronous replica indication information of the any pending partition are the same; If the replica indication information of any pending partition is the same as the synchronous replica indication information, then the any pending partition is added to the H partitions to be adjusted; If the replica indication information and the synchronous replica indication information of any pending partition are different, then any pending partition is not added to the H partitions to be adjusted, so as to achieve the determination of H partitions to be adjusted from the N pending partitions.
6. The method according to any one of claims 1 to 3, characterized in that: The performing partition adjustment on each of the H partitions to be adjusted includes: Based on the partition indication information of each partition to be adjusted among the H partitions to be adjusted, respectively determine the replica indication information to be adjusted of each partition to be adjusted; Generate master-slave replica adjustment data based on the replica indication information to be adjusted of each partition to be adjusted; Based on the master-slave replica adjustment data, partition adjustment is performed on each of the partitions to be adjusted.
7. The method according to claim 6, characterized in that The step of adjusting the partitions to be adjusted based on the master-slave replica adjustment data includes: Execute the master-slave replica adjustment data so that the master-slave replicas of each partition to be adjusted are adjusted according to the replica indication information to be adjusted of the corresponding partition to be adjusted, so that the master replica of any partition to be adjusted is adjusted to: a replica of any partition to be adjusted on the node indicated by the first adjustment node identifier in the replica indication information to be adjusted of any partition to be adjusted; Perform master-slave switching on each partition to be adjusted to achieve the adjustment of data based on the master-slave replicas, and perform partition adjustment on each partition to be adjusted, so that the read and write traffic of any partition to be adjusted is migrated to the normal node of the target cluster.
8. A cluster management device, characterized in that: The device comprises: An acquiring unit, configured to acquire cluster partition indication data of a target cluster, wherein the cluster partition indication data includes partition indication information of each partition in the target cluster; A processing unit, configured to determine M abnormal nodes in the target cluster, and based on the partition indication information of each partition, determine N pending partitions from the target cluster whose master replica is located on any abnormal node among the M abnormal nodes; wherein one partition has one master replica and at least one slave replica, and both M and N are non-negative integers; The processing unit is further used to determine H partitions to be adjusted from the N partitions to be determined, one partition to be adjusted is a synchronized partition, and H is a non-negative integer; The processing unit is further used to perform partition adjustment on each of the H partitions to be adjusted, so that the target cluster is updated to a target cluster after partition adjustment, and the primary copy of each partition to be adjusted in the target cluster after partition adjustment is not located on the M abnormal nodes.
9. An electronic device, characterized in that: include: processor; as well as Memory for storing programs, The program includes instructions, which, when executed by the processor, cause the processor to perform the method according to any one of claims 1 to 7.
10. A non-transitory computer-readable storage medium storing computer instructions, wherein: The computer instructions are used to make a computer execute the method according to any one of claims 1-7.