Method and apparatus for acquiring cluster topology relationship
By obtaining the address and configuration information of the nodes to be probed in the cluster, determining the node type, finding the head node, and probing level by level, the problem of automatically obtaining the cluster topology relationship is solved, and the stability of cluster operation is improved.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-02-21
- Publication Date
- 2026-04-10
AI Technical Summary
Existing technologies cannot automatically obtain cluster topology relationships, leading to unstable cluster operation.
By obtaining the address information of the nodes to be probed in the cluster, connecting the nodes, determining the node type, finding the head node, and probing the nodes level by level based on the head node, the cluster topology is generated.
It enables automatic acquisition of cluster topology relationships, improving the reliability of cluster operation.
Smart Images

Figure CN116668302B_ABST
Abstract
Description
TECHNICAL FIELD
[0001] The present application relates to the technical field of databases, and in particular to a method and device for obtaining a cluster topology relationship, an electronic device, and a storage medium. BACKGROUND
[0002] At present, the topology relationship of a cluster can change, for example, if a master node in the cluster is abnormal, the master node is usually replaced by a standby node, which can cause the topology relationship of the cluster to change. The topology relationship of the cluster has an important influence on the normal operation of the cluster. In the related art, the topology relationship of the entire cluster cannot be automatically obtained, which is not conducive to the normal operation of the cluster. SUMMARY
[0003] The present application aims to at least partly solve one of the above technical problems.
[0004] To this end, one object of the present application is to provide a method for obtaining a cluster topology relationship, which can automatically detect a head node of a cluster based on any node in the cluster, and detect nodes step by step downward from the head node to obtain the topology relationship of the cluster, so as to automatically obtain the topology relationship of the cluster and improve the reliability of the cluster operation.
[0005] A second object of the present application is to provide a device for obtaining a cluster topology relationship.
[0006] A third object of the present application is to provide an electronic device.
[0007] A fourth object of the present application is to provide a computer-readable storage medium.
[0008] The first aspect of the present application provides a method for obtaining a cluster topology relationship, comprising: obtaining address information of a to-be-detected node in a cluster, and connecting with the to-be-detected node based on the address information, wherein the to-be-detected node is any node in the cluster; obtaining node configuration information of the to-be-detected node, and determining a node type of the to-be-detected node according to the node configuration information; determining a head node of the cluster according to the node type of the to-be-detected node; detecting nodes step by step downward from the head node, and generating a topology relationship of the cluster according to a detection result.
[0009] The second aspect embodiment of the present application provides a device for obtaining a cluster topology relationship, comprising: a connection module, configured to obtain address information of a to-be-detected node in a cluster, and connect with the to-be-detected node based on the address information, wherein the to-be-detected node is any node in the cluster; a first determination module, configured to obtain node configuration information of the to-be-detected node, and determine a node type of the to-be-detected node according to the node configuration information; a second determination module, configured to determine a head node of the cluster according to the node type of the to-be-detected node; and a detection module, configured to detect nodes step by step downwards according to the head node, and generate a topology relationship of the cluster according to a detection result.
[0010] The third aspect embodiment of the present application provides an electronic device, comprising a memory, a processor, and a computer program stored in the memory and capable of running on the processor, wherein the processor implements the method for obtaining a cluster topology relationship according to the first aspect embodiment of the present application when executing the program.
[0011] The fourth aspect embodiment of the present application provides a computer readable storage medium, which stores a computer program, wherein the program is executed by a processor to implement the method for obtaining a cluster topology relationship according to the first aspect embodiment of the present application.
[0012] The technical solution provided by the embodiments of the present application can have the following beneficial effects:
[0013] The address information of a to-be-detected node in a cluster is obtained, and the to-be-detected node is connected based on the address information, the to-be-detected node is any node in the cluster, the node configuration information of the to-be-detected node is obtained, the node type of the to-be-detected node is determined according to the node configuration information, the head node of the cluster is determined according to the node type of the to-be-detected node, the nodes are detected step by step downwards according to the head node, and the topology relationship of the cluster is generated according to a detection result. Thus, the head node of the cluster can be automatically detected based on any node in the cluster, and the nodes are detected step by step downwards according to the head node, so as to obtain the topology relationship of the cluster, thereby the automatic obtaining of the cluster topology relationship is realized, and the reliability of the cluster operation is improved.
[0014] Additional aspects and advantages of the present application will be made apparent by the following description and the accompanying drawings. BRIEF DESCRIPTION OF DRAWINGS
[0015] The above and / or additional aspects and advantages of the present application will become apparent and be readily understood from the following description, taken in conjunction with the accompanying drawings, in which:
[0016] Figure 1 A flowchart of a method for obtaining a cluster topology relationship according to an embodiment of the present application;
[0017] Figure 2 A flowchart of a process of determining whether a to-be-detected node is configured with a slave node in a method of acquiring a cluster topology relationship according to an embodiment of the present application;
[0018] Figure 3 A flowchart of a process of acquiring a cluster topology relationship by a head node detecting nodes step by step downwards in a method of acquiring a cluster topology relationship according to an embodiment of the present application;
[0019] Figure 4 A structural diagram of an apparatus for acquiring a cluster topology relationship according to an embodiment of the present application; and
[0020] Figure 5 A structural diagram of an electronic device according to an embodiment of the present application. DETAILED DESCRIPTION
[0021] Embodiments of the present application are described in detail below with reference to the accompanying drawings, in which the same or similar notations used throughout the drawings and the specific description denote the same or similar elements or elements having the same or similar functions. The embodiments described below with reference to the accompanying drawings are exemplary and are intended to explain the present application, and cannot be understood as limiting the present application.
[0022] The method, apparatus, electronic device and storage medium for acquiring a cluster topology relationship according to an embodiment of the present application are described below in conjunction with the accompanying drawings.
[0023] Figure 1 A flowchart of a method of acquiring a cluster topology relationship according to an embodiment of the present application.
[0024] As shown in Figure 1 the method for acquiring a cluster topology relationship according to an embodiment of the present application includes the following steps:
[0025] S101, acquiring address information of a to-be-detected node in a cluster, and connecting with the to-be-detected node based on the address information, wherein the to-be-detected node is any node in the cluster.
[0026] In an embodiment of the present application, the cluster can include at least one node, and the to-be-detected node is any node in the cluster. It can be understood that each to-be-detected node can correspond to a group of address information, and different to-be-detected nodes can correspond to different address information. The address information of the to-be-detected node in the cluster can be acquired, and the to-be-detected node is connected based on the address information.
[0027] It should be noted that the type of address information is not limited in the embodiments of the present application. Optionally, the address information can include an IP address and a PORT port. Further, connecting with the to-be-detected node based on the address information can include connecting with instances corresponding to the IP address and the PORT port in the address information.
[0028] In S102, node configuration information of the to-be-detected node is acquired, and the node type of the to-be-detected node is determined according to the node configuration information.
[0029] In the embodiments of the present application, each to-be-detected node can correspond to a set of node configuration information. It can be understood that the node configuration information can include master node configuration information and / or slave node configuration information. The node configuration information of the to-be-detected node can be acquired, and the node type of the to-be-detected node is determined according to the node configuration information.
[0030] Optionally, determining the node type of the to-be-detected node according to the node configuration information can include judging whether the to-be-detected node is configured with a master node according to the node configuration information, judging whether the to-be-detected node is configured with a slave node according to the node configuration information, and determining the node type of the to-be-detected node according to the above judgment results, which can include the following four possible implementation manners.
[0031] Manner 1: in response to that the to-be-detected node is not configured with a master node and is configured with a slave node, determining the node type of the to-be-detected node as a Top node.
[0032] It can be understood that the Top node is not configured with a master node and is configured with a slave node. In the embodiments of the present application, in response to that the to-be-detected node is not configured with a master node and is configured with a slave node, the node type of the to-be-detected node can be determined as a Top node.
[0033] Manner 2: in response to that the to-be-detected node is configured with a master node and is not configured with a slave node, determining the node type of the to-be-detected node as a Bottom node.
[0034] It can be understood that the Bottom node is configured with a master node and is not configured with a slave node. In the embodiments of the present application, in response to that the to-be-detected node is configured with a master node and is not configured with a slave node, the node type of the to-be-detected node can be determined as a Bottom node.
[0035] Manner 3: in response to that the to-be-detected node is configured with a master node and is configured with a slave node, determining the node type of the to-be-detected node as a Middle node.
[0036] It can be understood that the Middle node is configured with a master node and is configured with a slave node. In the embodiments of the present application, in response to that the to-be-detected node is configured with a master node and is configured with a slave node, the node type of the to-be-detected node can be determined as a Middle node.
[0037] Manner 4: in response to that the to-be-detected node is not configured with a master node and a slave node, determining the node type of the to-be-detected node as a single point.
[0038] It can be understood that the single point is not configured with the master node and the slave node. In the embodiment of the application, in response to the to-be-detected node not being configured with the master node and the slave node, the node type of the to-be-detected node is determined as the single point.
[0039] In S103, the head node of the cluster is determined according to the node type of the to-be-detected node.
[0040] In the embodiment of the application, the head node of the cluster can be determined according to the node type of the to-be-detected node, which can include the following possible implementation manners:
[0041] Manner 1: in response to the node type of the to-be-detected node being the head node, the to-be-detected node is determined as the head node of the cluster.
[0042] Manner 2: in response to the node type of the to-be-detected node being the tail node, nodes are detected step by step upwards from the tail node until a node of the head node type is detected.
[0043] In an implementation manner, the nodes can be detected step by step upwards from the tail node, which can include taking the tail node as a target node, in the detection of the next level upwards according to the target node, address information of the master node of the target node is acquired according to the node configuration information of the target node, the address information of the master node of the target node is traversed, each address information traversed is connected to the corresponding next level node, and the connected node is taken as a new target node for the next level detection, and if the next level detection cannot be performed according to one target node, the corresponding target node is taken as the head node.
[0044] For example, the tail node is taken as a target node, address information of the first level master node of the tail node is acquired according to the node configuration information of the tail node, the first level master node is connected according to the traversed address information, and the connected first level master node is taken as a new target node for the next level detection, for example, address information of the second level master node of the first level master node is acquired, the second level master node is connected according to the traversed address information, and the connected second level master node is taken as a new target node for the next level detection, and if the next level detection cannot be performed according to the second level master node, the corresponding second level master node is taken as the head node.
[0045] In an implementation manner, in the case where the target node is not configured with the master node, the next level detection cannot be performed according to the target node at this time.
[0046] Manner 3: in response to the node type of the to-be-detected node being the intermediate node, nodes are detected step by step upwards from the intermediate node until a node of the head node type is detected.
[0047] It should be noted that the related content of the step-by-step detection of the nodes upwards from the intermediate node can be referred to the above-mentioned embodiment, which will not be described here again.
[0048] In response to the node type of the to-be-detected node being a single point, any remaining node in the cluster is taken as a new to-be-detected node, and the step of acquiring address information of the to-be-detected node in the cluster and the subsequent steps are executed.
[0049] In S104, the head node is detected according to the head node, and the topology relationship of the cluster is generated according to the detection result.
[0050] At present, the topology relationship of the cluster may change, for example, if a master node in the cluster is abnormal, the master node is usually replaced by a standby node, which causes the topology relationship of the cluster to change. The topology relationship of the cluster has an important influence on the normal operation of the cluster. In the related art, the topology relationship of the entire cluster cannot be automatically acquired, which is not conducive to the normal operation of the cluster.
[0051] In the embodiment of the application, the address information of the to-be-detected node in the cluster is acquired, the to-be-detected node is connected based on the address information, the node type of the to-be-detected node is determined according to the node configuration information of the to-be-detected node, the head node of the cluster is automatically detected, the nodes are detected according to the head node, and the topology relationship of the cluster is acquired, so that the automatic acquisition of the topology relationship of the cluster is realized.
[0052] In summary, according to the method for acquiring the topology relationship of the cluster, the address information of the to-be-detected node in the cluster is acquired, the to-be-detected node is connected based on the address information, the node configuration information of the to-be-detected node is acquired, the node type of the to-be-detected node is determined according to the node configuration information, the head node of the cluster is determined according to the node type of the to-be-detected node, the nodes are detected according to the head node, and the topology relationship of the cluster is generated according to the detection result. Thus, the head node of the cluster can be automatically detected based on any node in the cluster, the nodes are detected according to the head node, and the topology relationship of the cluster is acquired, so that the automatic acquisition of the topology relationship of the cluster is realized, and the reliability of the cluster operation is improved.
[0053] On the basis of any of the above embodiments, after determining that the node type of the to-be-detected node is an intermediate node, the method further comprises, for each intermediate node, judging whether the master node and the slave node of the intermediate node are consistent.
[0054] In response to the master node and the slave node being inconsistent, it is indicated that the cluster is not a mutual replication (double master) topology relationship, and it can be determined that the cluster is a cluster for which the topology relationship can be directly generated. In one implementation, in response to the master node and the slave node being inconsistent, the nodes are detected according to the intermediate node, and the node type of the node is detected until the node type of the node is a head node.
[0055] Or, in response to the master node and the slave node being consistent, indicating that the cluster is in a mutual replication (dual master) topology relationship, the detection is stopped, and the cluster is determined as a cluster that cannot directly generate a topology relationship.
[0056] On the basis of any of the above embodiments, the node configuration information can include slave node configuration information. The slave node configuration information includes an IP address and a PORT port.
[0057] Further, as shown in the above embodiments, determining whether the to-be-detected node is configured with a slave node according to the node configuration information can include: Figure 2
[0058] S201, obtaining an IP address and a PORT port in the slave node configuration information.
[0059] In the embodiments of the present application, after being connected with the to-be-detected node, the node configuration information of the to-be-detected node can be obtained, and the node configuration information includes slave node configuration information. Further, the IP address and the PORT port in the slave node configuration information can be obtained. It can be understood that the number of IP addresses and PORT ports can be one or more.
[0060] Optionally, the IP address and the PORT port in the slave node configuration information can be obtained by inputting a preset command. For example, the IP address in the slave node configuration information can be obtained by inputting "show process list", and the PORT port in the slave node configuration information can be obtained by inputting "show slave hosts".
[0061] S202, generating a candidate slave node list according to the IP address and the PORT port, wherein the candidate slave node list includes a mapping relationship between the IP address and the PORT port.
[0062] It can be understood that a mapping relationship between any IP address and any PORT port can be generated according to any IP address and any PORT port, and a candidate slave node list can be constructed according to all generated mapping relationships.
[0063] S203, determining whether there is a usable mapping relationship between the IP address and the PORT port in the candidate slave node list.
[0064] It can be understood that the mapping relationship between the IP address and the PORT port can not be usable. For example, the IP address is not usable, and / or the PORT port is not usable, and / or the IP address and the PORT port do not match, and / or the like, so that the mapping relationship between the IP address and the PORT port is not usable.
[0065] In the embodiments of the present application, it can be determined whether there is a mapping relationship between a usable IP address and a PORT port in the candidate slave node list, for example, whether the IP address is usable, and / or whether the PORT port is usable, and / or whether the IP address and the PORT port are matched.
[0066] In response to the mapping relationship between the usable IP address and the PORT port existing in the candidate slave node list, it is determined that the to-be-probed node is configured with a slave node, or in response to the mapping relationship between the usable IP address and the PORT port not existing in the candidate slave node list, it is determined that the to-be-probed node is not configured with a slave node.
[0067] In the embodiments of the present application, in response to the mapping relationship between the usable IP address and the PORT port existing in the candidate slave node list, it is indicated that there is a usable candidate slave node in the candidate slave node list, and then it can be determined that the to-be-probed node is configured with a slave node. Further, the candidate slave node corresponding to the mapping relationship between the usable IP address and the PORT port can be determined as the slave node configured for the to-be-probed node.
[0068] Or, in response to the mapping relationship between the usable IP address and the PORT port not existing in the candidate slave node list, it is indicated that there is no usable candidate slave node in the candidate slave node list, and then it can be determined that the to-be-probed node is not configured with a slave node.
[0069] Therefore, the method can generate a candidate slave node list according to the IP address and the PORT port in the slave node configuration information, the candidate slave node list includes a mapping relationship between an IP address and a PORT port, determine whether there is a mapping relationship between a usable IP address and a PORT port in the candidate slave node list, and determine whether the to-be-probed node is configured with a slave node according to whether there is a mapping relationship between a usable IP address and a PORT port in the candidate slave node list.
[0070] On the basis of any of the above embodiments, the node configuration information can include master node configuration information. The master node configuration information includes an IP address and a PORT port. It should be noted that the related content of determining whether the to-be-probed node is configured with a master node according to the node configuration information can refer to the related content of determining whether the to-be-probed node is configured with a slave node according to the node configuration information in the above embodiments, which will not be described here.
[0071] On the basis of any of the above embodiments, as shown in FIG. 10, the step of generating the topology relationship of the cluster according to the head node to probe the nodes step by step and according to the probing result in step S103 can include: Figure 3
[0072] S301, taking the head node as a target node, and according to the node configuration information of the target node, address information of a slave node of the target node is obtained when a next-level detection is performed according to the target node.
[0073] S302, address information of the slave node of the target node is traversed, a next-level node is connected according to each address information traversed, and the connected node is taken as a new target node for a next-level detection, if a next-level detection cannot be performed according to a target node, the target node is taken as an end of a link in a topology relationship, and a link containing the end and the head node is generated.
[0074] For example, the head node is taken as a target node, address information of a first-level slave node of the head node is obtained according to the node configuration information of the head node, a first-level slave node is connected according to the address information traversed, and the connected first-level slave node is taken as a new target node for a next-level detection, for example, address information of a second-level slave node of the first-level slave node is obtained, a second-level slave node is connected according to the address information traversed, and the connected second-level slave node is taken as a new target node for a next-level detection, if a next-level detection cannot be performed according to the second-level slave node, the second-level slave node is taken as an end of a link in a topology relationship, and a link containing the end and the head node is generated, and the link contains the head node, the first-level slave node, and the second-level slave node. In an implementation, if a target node is not configured with a slave node, a next-level detection cannot be performed according to the target node at this time.
[0075] S303, the generated links are integrated as a topology relationship of a cluster.
[0076] For example, the generated links can be spliced to generate a topology relationship of a cluster.
[0077] For example, there can be repeated links between different links, repeated links and difference links between the generated links can be obtained, each difference link and one repeated link are retained, the retained links are spliced to generate a topology relationship of a cluster.
[0078] For example, there can be repeated links between different links, repeated links between the generated links can be obtained, only one repeated link is retained for the repeated links, and the redundant repeated links are deleted, and the remaining links are spliced to generate a topology relationship of a cluster.
[0079] Therefore, in the method, a next-level detection can be performed according to a target node, a node is detected level by level from the head node, and the generated links are integrated as a topology relationship of a cluster.
[0080] To implement the above embodiments, this application also proposes an apparatus for obtaining cluster topology relationships.
[0081] Figure 4 This is a schematic diagram of an apparatus for obtaining cluster topology relationships according to an embodiment of this application.
[0082] like Figure 4 As shown, the apparatus 100 for obtaining cluster topology relationships in this application embodiment includes: a connection module 110, a first determination module 120, a second determination module 130, and a detection module 140.
[0083] The connection module 110 is used to obtain the address information of the node to be probed in the cluster, and connect to the node to be probed based on the address information, wherein the node to be probed is any node in the cluster;
[0084] The first determining module 120 is used to obtain the node configuration information of the node to be detected and determine the node type of the node to be detected based on the node configuration information.
[0085] The second determining module 130 is used to determine the head node of the cluster based on the node type of the node to be detected;
[0086] The detection module 140 is used to detect nodes level by level down from the head node and generate the topology of the cluster based on the detection results.
[0087] In one embodiment of this application, the first determining module 120 is specifically used to: determine whether the node to be detected is configured with a master node based on the node configuration information; determine whether the node to be detected is configured with a slave node based on the node configuration information; and determine that the node type of the node to be detected is a head node if the node to be detected is not configured with a master node but is configured with a slave node.
[0088] In one embodiment of this application, the first determining module 120 is further configured to: determine the node type of the node to be detected as a tail node in response to the fact that the node to be detected is configured with a master node and not with a slave node; the second determining module 130 is further configured to: detect nodes upwards level by level according to the tail node until a node of type head node is detected.
[0089] In one embodiment of this application, the first determining module 120 is further configured to: determine the node type of the node to be detected as an intermediate node in response to the node to be detected being configured with a master node and a slave node; the second determining module 130 is further configured to: detect nodes upwards level by level according to the intermediate node until a node of type head node is detected.
[0090] In an embodiment of the present application, the detecting module 140 is further configured to: for each intermediate node, determine whether the master node and the slave node of the intermediate node are consistent; and in response to the master node and the slave node being consistent, stop the detection and determine that the cluster is a cluster that cannot directly generate a topology relationship.
[0091] In an embodiment of the present application, the node configuration information comprises slave node configuration information, and the first determining module 120 is further configured to: acquire an IP address and a PORT port in the slave node configuration information; generate a candidate slave node list according to the IP address and the PORT port, wherein the candidate slave node list comprises a mapping relationship between the IP address and the PORT port; determine whether there is a usable mapping relationship between the IP address and the PORT port in the candidate slave node list; in response to there being a usable mapping relationship between the IP address and the PORT port in the candidate slave node list, determine that the node to be detected is configured with a slave node; or in response to there being no usable mapping relationship between the IP address and the PORT port in the candidate slave node list, determine that the node to be detected is not configured with a slave node.
[0092] In an embodiment of the present application, the detecting module 140 is further configured to: when performing the next-level detection according to a target node, acquire address information of a slave node of the target node according to node configuration information of the target node; traverse the address information of the slave node of the target node, connect to a corresponding next-level node according to each address information obtained through the traversal, and take the connected node as a new target node to perform the next-level detection; if the next-level detection cannot be performed according to one target node, take the corresponding target node as an end of a link in the topology relationship, and correspondingly generate a link comprising the end and the head node; and the generating the topology relationship of the cluster according to the detection result comprises: integrating the generated links into the topology relationship of the cluster.
[0093] It should be noted that details not disclosed in the apparatus for acquiring a topology relationship of a cluster in the embodiments of the present application can refer to details disclosed in the method for acquiring a topology relationship of a cluster in the above embodiments of the present application, which will not be described herein.
[0094] In summary, the device for acquiring the cluster topology relationship in the embodiment of the present application acquires the address information of the to-be-probed node in the cluster, connects with the to-be-probed node based on the address information, acquires the node configuration information of the to-be-probed node, determines the node type of the to-be-probed node according to the node configuration information, determines the head node of the cluster according to the node type of the to-be-probed node, probes the nodes step by step from the head node, and generates the topology relationship of the cluster according to the probing result. Thus, the head node of the cluster can be automatically probed based on any node in the cluster, and the nodes are probed step by step from the head node, so as to acquire the topology relationship of the cluster, thereby realizing the automatic acquisition of the cluster topology relationship and improving the reliability of the cluster operation.
[0095] In order to realize the above-mentioned embodiments, as shown in Figure 5 The embodiment of the present application provides an electronic device 200, which comprises a memory 210, a processor 220 and a computer program stored in the memory 210 and capable of running on the processor 220. When the processor 220 executes the program, the above-mentioned method for acquiring the cluster topology relationship is realized.
[0096] The electronic device of the embodiment of the present application acquires the address information of the to-be-probed node in the cluster by the processor executing the computer program stored in the memory, connects with the to-be-probed node based on the address information, acquires the node configuration information of the to-be-probed node, determines the node type of the to-be-probed node according to the node configuration information, determines the head node of the cluster according to the node type of the to-be-probed node, probes the nodes step by step from the head node, and generates the topology relationship of the cluster according to the probing result. Thus, the head node of the cluster can be automatically probed based on any node in the cluster, and the nodes are probed step by step from the head node, so as to acquire the topology relationship of the cluster, thereby realizing the automatic acquisition of the cluster topology relationship and improving the reliability of the cluster operation.
[0097] In order to realize the above-mentioned embodiments, the embodiment of the present application provides a computer readable storage medium, which stores a computer program. When the program is executed by a processor, the above-mentioned method for acquiring the cluster topology relationship is realized.
[0098] The computer readable storage medium of the embodiment of the application, by storing the computer program and being executed by the processor, obtains address information of a to-be-probed node in the cluster, and connects with the to-be-probed node based on the address information, the to-be-probed node being any node in the cluster, obtains node configuration information of the to-be-probed node, determines a node type of the to-be-probed node according to the node configuration information, determines a head node of the cluster according to the node type of the to-be-probed node, probes nodes step by step from the head node downwards, and generates a topology relationship of the cluster according to the probing result. Thus, the head node of the cluster can be automatically probed based on any node in the cluster, and nodes are probed step by step from the head node downwards to obtain the topology relationship of the cluster, so that automatic acquisition of the topology relationship of the cluster is realized, and the reliability of cluster operation is improved.
[0099] In the description of the present application, it should be understood that the orientation or positional relationship indicated by the terms "center", "longitudinal", "lateral", "length", "width", "thickness", "upper", "lower", "front", "back", "left", "right", "vertical", "horizontal", "top", "bottom", "inner", "outer", "clockwise", "counterclockwise", "axial", "radial", "circumferential" and the like are based on the orientation or positional relationship shown in the drawings, and are only for the convenience of describing the present application and simplifying the description, and do not indicate or imply that the device or element referred to must have a particular orientation, be constructed and operated in a particular orientation, and therefore cannot be understood as a limitation of the present application.
[0100] In addition, the terms "first", "second" are only for descriptive purposes and cannot be understood as indicating or implying relative importance or implicitly indicating the number of the technical features indicated. Therefore, the features defined with "first", "second" can explicitly or implicitly include one or more of the features. In the description of the present application, the meaning of "multiple" is two or more, unless otherwise explicitly specified and limited.
[0101] In the present application, unless otherwise explicitly specified and limited, the terms "mounting", "connecting", "connecting", "fixing" and the like should be understood in a broad sense, for example, it can be fixed connection, or detachable connection, or integral; it can be mechanical connection, or electrical connection; it can be directly connected, or indirectly connected through an intermediate medium; it can be the internal communication of two elements or the interaction relationship between two elements. For those skilled in the art, the specific meaning of the above terms in the present application can be understood according to the specific circumstances.
[0102] In the present application, unless specifically defined and limited otherwise, the first feature "on" or "under" the second feature can be that the first and second features are in direct contact, or the first and second features are in indirect contact through an intermediate medium. Moreover, the first feature "over", "above" and "on top of" the second feature can be that the first feature is directly above or obliquely above the second feature, or only indicates that the first feature is higher than the second feature in horizontal height. The first feature "under", "below" and "underneath" the second feature can be that the first feature is directly below or obliquely below the second feature, or only indicates that the first feature is lower than the second feature in horizontal height.
[0103] In the description of the present application, the description of the terms "one embodiment", "some embodiments", "an example", "a specific example", or "some examples" etc. means that the specific features, structures, materials or characteristics described in connection with the embodiment or example are included in at least one embodiment or example of the present application. In the present application, the illustrative description of the above terms does not necessarily refer to the same embodiment or example. Moreover, the specific features, structures, materials or characteristics described can be combined in any appropriate manner in any one or more embodiments or examples. In addition, the person skilled in the art can combine and combine the different embodiments or examples described in the present application and the features of the different embodiments or examples without contradiction.
[0104] Although the embodiments of the present application have been shown and described above, it can be understood that the above embodiments are exemplary and cannot be construed as limiting the present application, and the person skilled in the art can make changes, modifications, replacements and variations to the above embodiments within the scope of the present application.
Claims
1. A method for obtaining a cluster topology relationship, characterized in that, The method comprises: obtaining address information of a to-be-detected node in a cluster, and connecting with the to-be-detected node based on the address information, wherein the to-be-detected node is any node in the cluster; obtaining node configuration information of the to-be-detected node, and determining a node type of the to-be-detected node according to the node configuration information; determining a head node of the cluster according to the node type of the to-be-detected node; determining a topology relationship of the cluster according to a detection result of a node detected step by step from the head node; the determining of the node type of the to-be-detected node according to the node configuration information comprises: determining whether the to-be-detected node is configured with a master node according to the node configuration information; determining whether the to-be-detected node is configured with a slave node according to the node configuration information; in response to the to-be-detected node being configured with the master node and the slave node, determining that the node type of the to-be-detected node is an intermediate node; the determining of the head node of the cluster according to the node type of the to-be-detected node comprises: for each intermediate node, determining whether the master node and the slave node of the intermediate node are consistent; in response to the master node and the slave node being consistent, determining that the cluster is in a mutual replication topology relationship, and then stopping the detection and determining that the cluster is a cluster that cannot directly generate a topology relationship; in response to the master node and the slave node being inconsistent, determining that the cluster is not in the mutual replication topology relationship, and then detecting a node step by step upwards from the intermediate node until a node of a head node type is detected.
2. The method for acquiring cluster topology relationship according to claim 1, characterized in that, in response to the to-be-detected node not being configured with the master node and being configured with the slave node, determining that the node type of the to-be-detected node is the head node.
3. The method of claim 2, wherein, The method further comprises: in response to the to-be-detected node being configured with the master node and not being configured with the slave node, determining that the node type of the to-be-detected node is a tail node; the determining of the head node of the cluster according to the node type of the to-be-detected node comprises: detecting a node step by step upwards from the tail node until a node of a head node type is detected.
4. The method of claim 2, wherein, The node configuration information comprises slave node configuration information, and the determining of whether the to-be-detected node is configured with the slave node according to the node configuration information comprises: obtaining an IP address and a PORT port in the slave node configuration information; generating a candidate slave node list according to the IP address and the PORT port, wherein the candidate slave node list comprises a mapping relationship between the IP address and the PORT port; determining whether there is a mapping relationship between a usable IP address and a PORT port in the candidate slave node list; in response to there being a mapping relationship between a usable IP address and a PORT port in the candidate slave node list, determining that the to-be-detected node is configured with the slave node; or in response to there not being a mapping relationship between a usable IP address and a PORT port in the candidate slave node list, determining that the to-be-detected node is not configured with the slave node.
5. The method for acquiring cluster topology relationship according to any one of claims 1-4, characterized in that, The step-by-step detection of the node comprises: when detecting a next-level node according to a target node, obtaining address information of a slave node of the target node according to node configuration information of the target node; traverse address information of slave nodes of the target node, connect to a corresponding next level node according to each address information traversed, and take the connected node as a new target node for next level detection; if next level detection cannot be performed according to a target node, take the corresponding target node as an end of a link in the topological relationship, and correspondingly generate a link containing the end and the head node; the generating the topological relationship of the cluster according to the detection result comprises: integrating each link generated into the topological relationship of the cluster.
6. An apparatus for acquiring a cluster topology relationship, the apparatus comprising: comprise: a connecting module configured to acquire address information of a to-be-detected node in a cluster, and connect to the to-be-detected node based on the address information, wherein the to-be-detected node is any node in the cluster; a first determining module configured to acquire node configuration information of the to-be-detected node, and determine a node type of the to-be-detected node according to the node configuration information; a second determining module configured to determine a head node of the cluster according to the node type of the to-be-detected node; a detecting module configured to detect nodes level by level downwards according to the head node, and generate a topological relationship of the cluster according to a detection result; the first determining module is specifically configured to: determine whether the to-be-detected node is configured with a master node according to the node configuration information; determine whether the to-be-detected node is configured with a slave node according to the node configuration information; in response to the to-be-detected node being configured with a master node and a slave node, determine that the node type of the to-be-detected node is an intermediate node; the second determining module is specifically configured to: for each intermediate node, determine whether the master node and the slave node of the intermediate node are consistent; in response to the master node and the slave node being consistent, determine that the cluster is a mutual replication topological relationship, and then stop detection, and determine that the cluster is a cluster for which a topological relationship cannot be directly generated; in response to the master node and the slave node being inconsistent, determine that the cluster is not a mutual replication topological relationship, and then detect nodes level by level upwards according to the intermediate node, until a node type of a node detected is a head node.
7. An electronic device, comprising: comprise: a memory, a processor, and a computer program stored in the memory and executable on the processor, and when the processor executes the program, the method for acquiring a topological relationship of a cluster in any one of claims 1-5 is implemented.
8. A computer readable storage medium having stored thereon a computer program, characterized in that, The program is executed by the processor to implement the method for acquiring a topological relationship of a cluster in any one of claims 1-5.
Citation Information
Patent Citations
Network topology discovery method based on MAC information
CN104579979A
Ethernet switch topology generating and drawing method based on Tarjan algorithm
CN113300880A