Initialization Method, Device, Equipment and Medium of Relational Database Routing Middleware
By establishing a connection with the MySQL cluster node and determining the master node information, the problem of MySQL Router restart failed is solved, and the automatic initialization and successful restart of the relational database cluster is realized.
Patent Information
- Application Number
- CN202210014465.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-01-05
- Publication Date
- 2025-07-22
- Estimated Expiration
- 2042-01-05
AI Technical Summary
After the MySQL cluster is turned off, the host where MySQL Router is located or the pod on the cloud fails to restart, causing the application to be unable to connect to the database through MySQL Router.
By establishing a connection with each node in the relational database cluster, the node to be detected is determined for successful connection, and the master node is determined based on the node's role information, the information of the master node is written into a temporary file, and the routing middleware is initialized.
It realizes automatic determination of the main node of the relational database cluster and automatic initialization of the routing middleware, ensuring that the host or cloud pods are successfully restarted, and solving the problem that the application cannot connect to the database after the restart failed.
Smart Images

Figure CN114385734B_ABST
Abstract
Description
Technical Field
[0001] Embodiments of the present invention relate to the technical field of distribution networks, and in particular, to an initialization method, device, equipment, and medium for a relational database routing middleware. Background Art
[0002] When an application uses the MySQL Router middleware provided by MySQL to access a MySQL cluster, it is necessary to configure MySQL Router with information such as the domain name and port of the primary node in the MySQL cluster. When the application connects to the MySQL Router to implement database access, if the MySQL cluster undergoes a master switch, it has no impact on the application, and the MySQL Router realizes automatic routing to the primary database.
[0003] However, if the host where the MySQL Router is located or the pod on the cloud is restarted, since the configuration information of the MySQL Router is still the relevant information of the original primary node before the master switch, the initialization of the MySQL Router will fail, and further, the restart of the host where the MySQL Router is located or the pod on the cloud will fail, and the application cannot connect to the database through the MySQL Router. Summary of the Invention
[0004] Embodiments of the present invention provide an initialization method, device, equipment, and medium for a relational database routing middleware, so as to solve the technical problem that the host or the pod on the cloud where the routing middleware is located fails to restart after the master switch of the relational database cluster, and further solve the technical problem that the application cannot connect to the relational database through the routing middleware.
[0005] In a first aspect, an embodiment of the present invention provides an initialization method for a relational database routing middleware, and the method includes:
[0006] Establish connections with each node in the relational database cluster, and determine the nodes to be detected for which the connection establishment is successful;
[0007] Determine the primary node based on the role information corresponding to each of the nodes to be detected, and write the node information corresponding to the primary node into a temporary file;
[0008] Perform initialization processing on the routing middleware of the relational database cluster based on the temporary file.
[0009] Optionally, the determining the primary node based on the role information corresponding to each of the nodes to be detected, and writing the node information corresponding to the primary node into a temporary file includes:
[0010] For each of the nodes to be detected, determine whether the node to be detected is the master node based on the role information corresponding to the node to be detected;
[0011] If so, write the node information of the node to be detected into a temporary file.
[0012] Optionally, the determining whether the node to be detected is the master node based on the role information corresponding to the node to be detected includes:
[0013] For each of the nodes to be detected, obtain the system library related table corresponding to the node to be detected;
[0014] Obtain the role information corresponding to the node to be detected based on the system library related table, and determine whether the node to be detected is the master node based on the role information.
[0015] Optionally, the method further includes:
[0016] Obtain the configuration file corresponding to the relational database cluster, where the configuration file includes the node information of all nodes in the relational database cluster;
[0017] Obtain the node information corresponding to the master node based on the configuration file.
[0018] Optionally, the method further includes:
[0019] Obtain the node information of each node in the relational database cluster;
[0020] Generate the configuration file corresponding to the relational database cluster based on the node information of each node.
[0021] Optionally, writing the node information corresponding to the master node into a temporary file includes:
[0022] Determine the domain name information, password information, port information, and user information of the master node based on the node information corresponding to the master node;
[0023] Write the domain name information, the password information, the port information, and the user information into a temporary file.
[0024] Optionally, the method further includes:
[0025] When it is detected that the server or container group where the routing middleware of the relational database cluster is located is restarted, perform an operation of establishing a connection with each node in the relational database cluster.
[0026] In a second aspect, an embodiment of the present invention further provides an initialization device for a relational database routing middleware, where the device includes:
[0027] A connection establishment module, configured to establish connections with each node in the relational database cluster and determine the nodes to be detected for which the connection establishment is successful;
[0028] A node detection module, configured to determine a primary node based on the role information corresponding to each of the nodes to be detected, and write the node information corresponding to the primary node into a temporary file;
[0029] A processing module, configured to perform initialization processing on the routing middleware of the relational database cluster based on the temporary file.
[0030] In a third aspect, an embodiment of the present invention further provides an electronic device, where the electronic device includes:
[0031] One or more processors;
[0032] A storage device, configured to store one or more programs,
[0033] When the one or more programs are executed by the one or more processors, the one or more processors implement the initialization method of the relational database routing middleware provided in any embodiment of the present invention.
[0034] In a fourth aspect, an embodiment of the present invention further provides a computer-readable storage medium, on which a computer program is stored, and when the program is executed by a processor, it implements the initialization method of the relational database routing middleware provided in any embodiment of the present invention.
[0035] The embodiments in the above invention have the following advantages or beneficial effects:
[0036] By establishing connections with each node in the relational database cluster respectively, determining the nodes to be detected for which the connection establishment is successful, then determining the primary node according to the role information corresponding to each node to be detected, writing the node information corresponding to the primary node into a temporary file, and performing initialization processing on the routing middleware of the relational database cluster according to the temporary file, it realizes the automatic determination of the primary node of the relational database cluster and the automatic initialization of the routing middleware according to the determined primary node, ensures that the host where the routing middleware is located or the pod on the cloud can be successfully restarted, solves the technical problem that the host where the routing middleware is located or the pod on the cloud fails to restart after the relational database cluster switches the primary node, and further solves the technical problem that the application cannot connect to the relational database through the routing middleware after the restart fails. Description of the Drawings
[0037] To more clearly illustrate the technical solutions of the exemplary embodiments of the present invention, the following briefly introduces the drawings required for describing the embodiments. Obviously, the introduced drawings are only the drawings of a part of the embodiments to be described by the present invention, rather than all the drawings. For those of ordinary skill in the art, without creative efforts, other drawings can also be obtained according to these drawings.
[0038] Figure 1 It is a schematic flowchart of a method for initializing a relational database routing middleware provided in the first embodiment of the present invention;
[0039] Figure 2A It is a schematic flowchart of a method for initializing a relational database routing middleware provided in the second embodiment of the present invention;
[0040] Figure 2B It is a schematic flowchart of a method for determining a primary node provided in the second embodiment of the present invention;
[0041] Figure 3 It is a schematic structural diagram of an initialization device for a relational database routing middleware provided in the third embodiment of the present invention;
[0042] Figure 4 It is a schematic structural diagram of an electronic device provided in the fourth embodiment of the present invention. Detailed implementation manners
[0043] The following further elaborates on the present invention in conjunction with the drawings and embodiments. It can be understood that the specific embodiments described herein are only used to explain the present invention, rather than limiting the present invention. Additionally, it should be noted that for the sake of description, only the parts related to the present invention rather than all the structures are shown in the drawings.
[0044] Embodiment 1
[0045] Figure 1 It is a schematic flowchart of a method for initializing a relational database routing middleware provided in the first embodiment of the present invention. This embodiment is applicable to the situation of automatically initializing the routing middleware in a relational database cluster, especially applicable to the situation of detecting the nodes in the relational database cluster to determine the primary node and initializing the routing middleware according to the node information of the primary node. This method can be executed by an initialization device for a relational database routing middleware, and this device can be implemented by hardware and / or software. The method specifically includes the following steps:
[0046] S110. Establish connections with each node in the relational database cluster, and determine the nodes to be detected with successful connection establishment.
[0047] Among them, the relational database cluster can be a MySQL cluster (MySQL InnoDB Cluster); the relational database cluster is composed of multiple nodes. Specifically, each node in the relational database cluster can include a primary node and at least one secondary node. The routing middleware of the relational database cluster can be MySQL Router middleware. Specifically, the MySQL Router middleware is a lightweight middleware of the MySQL cluster. It is located between the application and each node of the MySQL cluster. The MySQL Router middleware is the entry point for the application to connect. The application communicates by connecting the MySQL Router middleware and each node of the underlying MySQL cluster. It is transparent to the application. The application only needs to connect to the MySQL Router middleware to interact with the underlying databases (i.e., each node) in the relational database cluster.
[0048] In this embodiment, the server or container group where the routing middleware of the relational database cluster (i.e., the MySQL Router middleware) is located can establish connections with each node in the relational database cluster when the routing middleware needs to be initialized to determine the primary node. Among them, the server where the routing middleware is located can be a host; the container group can be a cloud pod. Specifically, the cloud pod can be the basic unit of the Kubernetes system, the smallest component that can be created or deployed by users in the resource object model, and also the resource object for running containerized applications on the Kubernetes system.
[0049] That is, optionally, the method further includes: when it is detected that the server or container group where the routing middleware of the relational database cluster is restarted, perform the operation of establishing connections with each node in the relational database cluster. In this way, it can be ensured that the server or container group where the routing middleware is located can automatically determine the primary node every time it is restarted, and then the server or container group can complete the initialization of the routing middleware.
[0050] Of course, in this embodiment, considering that if the relational database cluster does not perform a master switch, the information required for the initialization of the routing middleware remains unchanged and there is no need to re-obtain the node information of the primary node. Therefore, the server or container group where the routing middleware is located can also perform the operation of establishing connections with each node in the relational database cluster when it is restarted and the relational database cluster has performed a master switch. That is, when the relational database cluster has not performed a master switch, if the server or container group where the routing middleware is located is restarted, the node information of the primary node used in the previous initialization can be continued to be used for the initialization of the routing middleware this time.
[0051] In this embodiment, specifically, before initializing the routing middleware, connections are established with each node in the relational database cluster. If the connection with a node is successfully established, the node is determined as a node to be detected, so as to further determine whether the node to be detected is the master node.
[0052] S120. Determine the master node based on the role information corresponding to each of the nodes to be detected, and write the node information corresponding to the master node into a temporary file.
[0053] Among them, the role information may be information describing whether the node to be detected is the master node or the slave node. Exemplarily, the role information may be the node function identifier of the node to be detected. For example, the role information being Primary indicates that the node to be detected is the master node, and the role information being Secondary indicates that the node to be detected is the slave node; or, the role information being Master indicates that the node to be detected is the master node, and the role information being Slave indicates that the node to be detected is the slave node.
[0054] In this embodiment, the role information corresponding to all the nodes to be detected can be obtained, and the master node is determined among all the nodes to be detected according to all the role information. Further, after determining the master node of the relational database cluster, the node information of the master node is written into a temporary file, so as to initialize the routing middleware based on the node information of the master node in the temporary file.
[0055] Among them, the temporary file may be a file for storing the information required for initializing the routing middleware. Optionally, each time the node information corresponding to the master node is written into the temporary file, the original cache information in the temporary file can be deleted, and the node information to be written this time can be cached into the temporary file.
[0056] In this embodiment, the node information corresponding to the master node may be the node information required for routing initialization, such as the domain name information, password information, port information, and user information of the master node. Of course, the node information of the master node may also include other description information of the master node, such as the node identifier, container information, image address, etc.
[0057] In a specific implementation manner, writing the node information corresponding to the master node into the temporary file includes: determining the domain name information, password information, port information, and user information of the master node based on the node information corresponding to the master node; writing the domain name information, the password information, the port information, and the user information into the temporary file.
[0058] Among them, the domain name information can be the IP or HOST of the master node, the password information can be the PASSWORD of the master node, the port information can be the PORT of the master node, and the user information can be the USER of the master node. That is, in this embodiment, the domain name information, password information, port information, and user information required for initializing the routing middleware can be extracted from the node information corresponding to the master node, and then the domain name information, password information, port information, and user information are written into a temporary file. Through this optional implementation, it can be ensured that the information written into the temporary file is the information required for initializing the routing middleware, reducing the memory occupied by the temporary file, and further reducing the information that needs to be written into the temporary file, thereby improving the initialization speed of the routing middleware.
[0059] In this embodiment, the node information of the master node can be obtained from the configuration file. That is, optionally, the method further includes: obtaining the configuration file corresponding to the relational database cluster, where the configuration file includes the node information of all nodes in the relational database cluster; obtaining the node information corresponding to the master node based on the configuration file. Exemplarily, after determining the master node, the node information of the master node can be queried in the configuration file according to the node identifier of the master node.
[0060] Specifically, in this embodiment, before initializing the routing middleware, the node information of all nodes in the relational database cluster can be obtained, and a configuration file can be generated based on the node information of all nodes. Then, after determining the master node, the node information corresponding to the master node can be extracted from the configuration file. That is, the method may further include: obtaining the node information of each node in the relational database cluster; generating the configuration file corresponding to the relational database cluster based on each piece of node information.
[0061] S130. Initialize the routing middleware of the relational database cluster based on the temporary file.
[0062] Specifically, after writing the node information of the master node into the temporary file, the routing middleware can be configured according to the node information in the temporary file to perform the initialization process of the routing middleware. Exemplarily, the server or container group where the routing middleware is located can use the node information in the temporary file to execute the MySQL Router program initialization command to complete the MySQL Router initialization.
[0063] In an alternative embodiment, initializing the routing middleware of the relational database cluster based on the temporary file may be as follows: The server or container group where the routing middleware is located pulls the image file, and starts the container corresponding to the routing middleware according to the pulled image file. Further, the container uses the node information in the temporary file to execute the MySQL Router program initialization command to complete the MySQL Router initialization.
[0064] The technical solution of this embodiment establishes connections with each node in the relational database cluster respectively, determines the nodes to be detected with successful connection establishment, and then determines the primary node according to the role information corresponding to each node to be detected, writes the node information corresponding to the primary node into the temporary file, and initializes the routing middleware of the relational database cluster according to the temporary file, realizing the automatic determination of the primary node of the relational database cluster and the automatic initialization of the routing middleware according to the determined primary node, ensuring that the host or cloud pod where the routing middleware is located can be successfully restarted, solving the technical problem that the host or cloud pod where the routing middleware is located fails to restart after the primary node of the relational database cluster is switched, and further solving the technical problem that the application cannot connect to the relational database through the routing middleware after the restart fails.
[0065] In this embodiment, by establishing connections with each node in the relational database cluster, the automatic detection of the nodes in the MySQL cluster is realized. Moreover, by determining the primary node according to the role information of the nodes to be detected with successful connection establishment, the automatic detection of the primary node is realized; by writing the node information of the primary node into the temporary file to initialize the routing middleware based on the temporary file, it is realized that 2. Using the temporarily saved MySQL primary node information, the MySQL Router initialization is automatically completed, realizing that the MySQL Router can be automatically restarted in the case of the primary node switch of the MySQL cluster without manual intervention.
[0066] Embodiment 2
[0067] Figure 2A FIG. is a schematic flowchart of a method for initializing a relational database routing middleware provided in Embodiment 2 of the present invention. On the basis of the above embodiments, optionally, determining the primary node according to the role information corresponding to each node to be detected and writing the node information corresponding to the primary node into the temporary file includes: for each node to be detected, determining whether the node to be detected is the primary node based on the role information corresponding to the node to be detected; if so, writing the node information of the node to be detected into the temporary file. The explanations of the same or corresponding terms in the above embodiments are not repeated here. Refer to Figure 2A , the method for initializing the relational database routing middleware provided in this embodiment includes the following steps:
[0068] S210. Establish connections with each node in the relational database cluster, and determine the nodes to be detected for which the connection establishment is successful.
[0069] S220. For each of the nodes to be detected, based on the role information corresponding to the node to be detected, determine whether the node to be detected is the master node. If so, write the node information of the node to be detected into a temporary file.
[0070] Specifically, in this embodiment, if it is determined, based on the role information corresponding to the currently detected node, that the currently detected node is the master node, then write the node information of the currently detected node into a temporary file. If it is determined, based on the role information corresponding to the currently detected node, that the currently detected node is not the master node, then continue to determine whether the next node to be detected is the master node based on the role information corresponding to the next node to be detected until a master node is determined.
[0071] Exemplarily, the determining whether the node to be detected is the master node based on the role information corresponding to the node to be detected includes: for each of the nodes to be detected, obtain the system library related table corresponding to the node to be detected; based on the system library related table, obtain the role information corresponding to the node to be detected, and based on the role information, determine whether the node to be detected is the master node.
[0072] Among them, the system library related table can be performance_schema; performance_schema includes the role information of each node. Specifically, the role information corresponding to the node to be detected can be extracted according to the system library related table, and then it can be determined whether the node to be detected is the master node according to the role information.
[0073] In this embodiment, the operation of determining whether the node to be detected is the master node can be repeatedly executed in a loop until the master node is determined. As Figure 2B shown, a schematic flow diagram of determining the master node is shown. Refer to Figure 2B , this embodiment can also determine the master node of the relational database cluster through the following steps: Step 1. Try to connect to the MySQL instance (i.e., the node in the relational database cluster); Step 2. Determine whether the connection is successful. If so, execute Step 4; if not, execute Step 3; Step 3. Record the log and ignore this instance; Step 4. Query the system library related table of this instance; Step 5. Determine whether it is the master node. If not, execute Step 6; if so, execute Step 7; Step 6. Record the log, disconnect the connection, and return to execute Step 1; Step 7. Write the node information of this instance into a temporary file.
[0074] It should be noted that in this embodiment, connections can be established with all nodes simultaneously, or a connection can be established with only one node each time. If the connection is successful, the node is determined as the node to be detected. Then, based on the role information of the node, it is judged whether the node is the master node. If not, a connection is continued with the next node. Of course, in this embodiment, the role information of all nodes to be detected can also be obtained at one time, and then the master node is determined among all nodes to be detected based on all the role information.
[0075] S230. Initialize the routing middleware of the relational database cluster based on the temporary file.
[0076] The technical solution of this embodiment establishes connections with each node in the relational database cluster, determines the nodes to be detected with successful connection establishment, and then for each node to be detected, based on the role information corresponding to the node to be detected, it is judged whether the node to be detected is the master node. If so, the node information of the node to be detected is written into the temporary file, and the routing middleware is initialized according to the temporary file, realizing the traversal and confirmation of whether each node to be detected is the master node. When the master node is determined, the judgment of the role information of the remaining nodes to be detected can be stopped, and there is no need to determine the master node based on the role information corresponding to all nodes to be detected, improving the initialization efficiency of the routing middleware.
[0077] Embodiment III
[0078] Figure 3 FIG. 13 is a schematic structural diagram of an initialization device for a relational database routing middleware provided in Embodiment III of the present invention. This embodiment is applicable to the situation of automatically initializing the routing middleware in a relational database cluster, especially applicable to the situation of detecting nodes in a relational database cluster to determine the master node and initializing the routing middleware according to the node information of the master node. The device specifically includes: a connection establishment module 310, a node detection module 320, and a processing module 330.
[0079] The connection establishment module 310 is used to establish connections with each node in the relational database cluster and determine the nodes to be detected with successful connection establishment;
[0080] The node detection module 320 is used to determine the master node based on the role information corresponding to each of the nodes to be detected and write the node information corresponding to the master node into the temporary file;
[0081] The processing module 330 is used to initialize the routing middleware of the relational database cluster based on the temporary file.
[0082] Optionally, the node detection module 320 is specifically used for:
[0083] For each of the nodes to be detected, determine whether the node to be detected is the master node based on the role information corresponding to the node to be detected; if so, write the node information of the node to be detected to a temporary file.
[0084] Optionally, the node detection module 320 includes a table acquisition unit and a judgment unit. The table acquisition unit is configured to, for each of the nodes to be detected, acquire the system library-related table corresponding to the node to be detected. The judgment unit is configured to obtain the role information corresponding to the node to be detected based on the system library-related table, and determine whether the node to be detected is the master node based on the role information.
[0085] Optionally, the device further includes a node information acquisition module, which is configured to acquire the configuration file corresponding to the relational database cluster. The configuration file includes the node information of all nodes in the relational database cluster. The node information corresponding to the master node is acquired based on the configuration file.
[0086] Optionally, the device further includes a configuration file generation module, which is configured to acquire the node information of each node in the relational database cluster, and generate the configuration file corresponding to the relational database cluster based on the node information.
[0087] Optionally, the node detection module 320 includes an information writing unit, which is configured to determine the domain name information, password information, port information, and user information of the master node based on the node information corresponding to the master node, and write the domain name information, the password information, the port information, and the user information to a temporary file.
[0088] Optionally, the connection establishment module 310 is specifically configured to:
[0089] When it is detected that the server or container group where the routing middleware of the relational database cluster is located is restarted, perform an operation of establishing a connection with each node in the relational database cluster.
[0090] In this embodiment, the connection establishment module is used to establish connections with each node in the relational database cluster respectively, and determine the nodes to be detected with successful connection establishment. Then, through the node detection module, the master node is determined according to the role information corresponding to each node to be detected, and the node information corresponding to the master node is written into a temporary file. Through the processing module, the routing middleware of the relational database cluster is initialized according to the temporary file, realizing the automatic determination of the master node of the relational database cluster and the automatic initialization of the routing middleware according to the determined master node, ensuring that the host where the routing middleware is located or the pod on the cloud can be successfully restarted, solving the technical problem that the host where the routing middleware is located or the pod on the cloud fails to restart after the master switch of the relational database cluster, and further solving the technical problem that the application cannot connect to the relational database through the routing middleware after the restart failure.
[0091] The initialization device of the relational database routing middleware provided by the embodiment of the present invention can execute the initialization method of the relational database routing middleware provided by any embodiment of the present invention, and has the corresponding functional modules and beneficial effects for executing the method.
[0092] It should be noted that the various units and modules included in the above system are only divided according to functional logic, but are not limited to the above division, as long as the corresponding functions can be realized; in addition, the specific names of the functional units are only for the convenience of mutual distinction and do not limit the protection scope of the embodiments of the present invention.
[0093] Embodiment Four
[0094] Figure 4 It is a schematic structural diagram of an electronic device provided by Embodiment Four of the present invention. Figure 4 It shows a block diagram of an exemplary electronic device 12 suitable for implementing the embodiments of the present invention. Figure 4 The shown electronic device 12 is only an example and should not bring any limitation to the functions and usage scope of the embodiments of the present invention. The device 12 is typically an electronic device that undertakes the initialization function of the routing middleware of the relational database cluster.
[0095] As Figure 4 shown, the electronic device 12 is presented in the form of a general-purpose computing device. The components of the electronic device 12 may include but are not limited to: one or more processors or processing units 16, a memory 28, and a bus 18 connecting different components (including the memory 28 and the processing unit 16).
[0096] Bus 18 represents one or more of several types of bus architectures, including a memory bus or memory controller, a peripheral bus, an Accelerated Graphics Port, a processor, or a local bus using any of the various bus architectures. By way of example, these architectures include, but are not limited to, Industry Standard Architecture (ISA) bus, Micro Channel Architecture (MCA) bus, Enhanced ISA bus, Video Electronics Standards Association (VESA) local bus, and Peripheral Component Interconnect (PCI) bus.
[0097] Electronic device 12 typically includes a variety of computer-readable media. These media can be any available media that can be accessed by electronic device 12, including volatile and non-volatile media, removable and non-removable media.
[0098] Memory 28 can include computer device-readable media in the form of volatile memory, such as Random Access Memory (RAM) 30 and / or cache memory 32. Electronic device 12 can further include other removable / non-removable, volatile / non-volatile computer storage media. By way of example only, storage device 34 can be used for reading and writing on non-removable, non-volatile magnetic media ( Figure 4 not shown, typically referred to as a "hard disk drive"). Although Figure 4 not shown in the figure, a disk drive for reading and writing on a removable non-volatile disk (such as a "floppy disk") and an optical disk drive for reading and writing on a removable non-volatile optical disk (such as a Compact Disc-Read Only Memory (CD-ROM), Digital Video Disc-Read Only Memory (DVD-ROM), or other optical media) can be provided. In these cases, each drive can be connected to bus 18 through one or more data media interfaces. Memory 28 can include at least one program product 40 having a set of program modules 42 configured to perform the functions of the embodiments of the present invention. The program product 40, which can be stored in, for example, memory 28, such program modules 42 include, but are not limited to, one or more application programs, other program modules, and program data, and the implementation of a network environment may be included in each or some combination of these examples. Program modules 42 generally execute the functions and / or methods in the embodiments described in the present invention.
[0099] The electronic device 12 can also communicate with one or more external devices 14 (such as keyboards, mice, cameras, etc. and displays), and can also communicate with one or more devices that enable a user to interact with the electronic device 12, and / or communicate with any device that enables the electronic device 12 to communicate with one or more other computing devices (such as network cards, modems, etc.). Such communication can be carried out through the input / output (I / O) interface 22. Moreover, the electronic device 12 can also communicate with one or more networks (such as a Local Area Network (LAN), a Wide Area Network (WAN), and / or a public network, such as the Internet) through the network adapter 20. As shown in the figure, the network adapter 20 communicates with other modules of the electronic device 12 through the bus 18. It should be understood that although not shown in the figure, other hardware and / or software modules can be used in combination with the electronic device 12, including but not limited to: microcode, device drivers, redundant processing units, external disk drive arrays, Redundant Arrays of Independent Disks (RAID) devices, tape drives, and data backup storage devices, etc.
[0100] The processor 16 executes various functional applications and data processing by running the programs stored in the memory 28. For example, it implements the initialization method of the relational database routing middleware provided in the above embodiments of the present invention, including:
[0101] Establish connections with each node in the relational database cluster, and determine the nodes to be detected for which the connection establishment is successful;
[0102] Determine the master node based on the role information corresponding to each of the nodes to be detected, and write the node information corresponding to the master node into a temporary file;
[0103] Initialize the routing middleware of the relational database cluster based on the temporary file.
[0104] Of course, those skilled in the art can understand that the processor can also implement the technical solutions of the initialization method of the relational database routing middleware provided in any embodiment of the present invention.
[0105] Embodiment Five
[0106] Embodiment Five of the present invention also provides a computer-readable storage medium, on which a computer program is stored. When the program is executed by a processor, it implements the steps of the initialization method of the relational database routing middleware provided in any embodiment of the present invention. The method includes:
[0107] Establish connections with each node in the relational database cluster, and determine the nodes to be detected for which the connection establishment is successful;
[0108] Determine the master node based on the role information corresponding to each of the nodes to be detected, and write the node information corresponding to the master node into a temporary file;
[0109] Perform initialization processing on the routing middleware of the relational database cluster based on the temporary file.
[0110] The computer storage medium of the embodiments of the present invention can adopt any combination of one or more computer-readable media. The computer-readable medium can be a computer-readable signal medium or a computer-readable storage medium. The computer-readable storage medium can be, for example, but not limited to, an electrical, magnetic, optical, electromagnetic, infrared, or semiconductor system, apparatus, or device, or any combination of the above. More specific examples (a non-exhaustive list) of the computer-readable storage medium include: an electrical connection having one or more wires, a portable computer disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the above. In this document, the computer-readable storage medium can be any tangible medium that contains or stores a program, and this program can be used by or in combination with an instruction execution system, apparatus, or device.
[0111] The computer-readable signal medium can include a data signal propagated in a baseband or as part of a carrier wave, which carries the computer-readable program code. Such a propagated data signal can take various forms, including but not limited to electromagnetic signals, optical signals, or any suitable combination of the above. The computer-readable signal medium can also be any computer-readable medium other than the computer-readable storage medium, and this computer-readable medium can send, propagate, or transmit a program for use by or in combination with an instruction execution system, apparatus, or device.
[0112] The program code contained on the computer-readable medium can be transmitted by any appropriate medium, including but not limited to wireless, wire, optical cable, RF, etc., or any suitable combination of the above.
[0113] Computer program code for performing the operations of the embodiments of the present invention may be written in one or more programming languages or combinations thereof. The programming languages include object-oriented programming languages such as Java, Smalltalk, C++, and also include conventional procedural programming languages such as the "C" language or similar programming languages. The program code may be executed entirely on the user's computer, partially on the user's computer, executed as a stand-alone software package, partially on the user's computer and partially on a remote computer, or entirely on a remote computer or server. In the case of a remote computer, the remote computer may be connected to the user's computer through any type of network including a local area network (LAN) or a wide area network (WAN), or may be connected to an external computer (e.g., through the Internet using an Internet service provider).
[0114] Note that the above is only the preferred embodiment of the present invention and the technical principles applied. Those skilled in the art will understand that the present invention is not limited to the specific embodiments described herein. Various obvious changes, re-adjustments, and substitutions can be made by those skilled in the art without departing from the protection scope of the present invention. Therefore, although the present invention has been described in more detail through the above embodiments, the present invention is not limited to the above embodiments. Without departing from the concept of the present invention, more other equivalent embodiments may be included, and the scope of the present invention is determined by the scope of the appended claims.
Claims
1. An initialization method for a relational database routing middleware, characterized in that The method includes: When detecting a restart of the server or container group where the routing middleware of the relational database cluster is located, establish connections with each node in the relational database cluster, and determine the nodes to be detected for which the connections are successfully established; Determine the master node based on the role information corresponding to each of the nodes to be detected, and write the node information corresponding to the master node into a temporary file; Perform initialization processing on the routing middleware of the relational database cluster based on the temporary file; The determining the master node based on the role information corresponding to each of the nodes to be detected and writing the node information corresponding to the master node into a temporary file includes: For each of the nodes to be detected, determine whether the node to be detected is the master node based on the role information corresponding to the node to be detected; If so, write the node information of the node to be detected into the temporary file; The performing initialization processing on the routing middleware of the relational database cluster based on the temporary file includes: pulling an image file from the server or container group where the routing middleware is located, and starting a container corresponding to the routing middleware according to the image file, and the container uses the node information in the temporary file to perform initialization processing on the routing middleware.
2. The method according to claim 1, characterized in that, The determining whether the node to be detected is the master node based on the role information corresponding to the node to be detected includes: For each of the nodes to be detected, obtain the system library related tables corresponding to the node to be detected; Obtain the role information corresponding to the node to be detected based on the system library related tables, and determine whether the node to be detected is the master node based on the role information.
3. The method according to claim 1, characterized in that, The method further includes: Obtain the configuration file corresponding to the relational database cluster, where the configuration file includes the node information of all nodes in the relational database cluster; Obtain the node information corresponding to the master node based on the configuration file.
4. The method according to claim 3, characterized in that, The method further includes: Obtain the node information of each node in the relational database cluster; Generate the configuration file corresponding to the relational database cluster based on each of the node information.
5. The method according to claim 1, characterized in that The writing the node information corresponding to the master node into the temporary file includes: Determine the domain name information, password information, port information, and user information of the master node based on the node information corresponding to the master node; Write the domain name information, the password information, the port information, and the user information into the temporary file.
6. An initialization device for a relational database routing middleware, characterized in that The apparatus includes: A connection establishment module, configured to establish connections with each node in the relational database cluster, and determine the nodes to be detected for which the connections are successfully established; A node detection module, configured to determine the master node based on the role information corresponding to each of the nodes to be detected, and write the node information corresponding to the master node into a temporary file; A processing module, configured to perform initialization processing on the routing middleware of the relational database cluster based on the temporary file; The connection establishment module is specifically configured to: when detecting a restart of the server or container group where the routing middleware of the relational database cluster is located, perform an operation of establishing connections with each node in the relational database cluster; The node detection module is specifically configured to: for each of the nodes to be detected, determine whether the node to be detected is a master node based on the role information corresponding to the node to be detected; If so, write the node information of the node to be detected into a temporary file; The processing module is specifically configured to pull an image file from the server or container group where the routing middleware is located, and start a container corresponding to the routing middleware according to the image file. The container uses the node information in the temporary file to perform initialization processing on the routing middleware.
7. An electronic device, characterized in that, The electronic device includes: One or more processors; A storage device for storing one or more programs, When the one or more programs are executed by the one or more processors, the one or more processors implement the initialization method of the relational database routing middleware as described in any one of claims 1-5.
8. A computer-readable storage medium having a computer program stored thereon, characterized in that, When the program is executed by the processor, it implements the initialization method of the relational database routing middleware as described in any one of claims 1-5.