A connection method, device and equipment of a cluster master node and a medium
Patent Information
- Application Number
- CN202311498935.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2023-11-10
- Publication Date
- 2026-09-04
- Estimated Expiration
- 2043-11-10
AI Technical Summary
[0005]本发明的目的是提供一种集群主节点的连接方法、装置、设备及介质,以解决在人工介入的情况下不及时处理或者人工操作错误连接问题,使得当前主节点一直处于断电状态,导致整个操作系统、业务系统无法正常工作,降低数据的存储效率降低的问题
[0057] This invention provides a method for connecting a cluster master node. It creates a connection to the current cross-platform non-relational database (NRD) based on the current NRD connection instance. The method controls the current connection listening instance to determine the validity of the current NRD connection using a timer mechanism. If invalid, it determines that the cluster master node is powered down and re-establishes a new connection to the current NRD to restore the cluster master node's connection. The advantages of this invention are: real-time monitoring via a connection listening instance within a Redis caching system; determining that the cluster master node is powered down and re-establishing a new connection when an invalid connection to the current NRD is detected, thus ensuring the stability of the Redis connection; timely restarting of the Redis server connection without manual intervention, facilitating the subsequent re-election of a new Redis master node; reducing maintenance costs, shortening server downtime, improving storage efficiency, and ensuring the normal operation of the operating system and business systems.
Smart Images

Figure CN117453786B_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of computer technology, and in particular to a method, apparatus, device, and medium for connecting cluster master nodes. Background Technology
[0002] As the demand for high-speed interactive data increases, high-performance open-source in-memory data storage systems such as Redis (Remote DIctionary Server), which allows for reading and writing data across platforms, are becoming increasingly popular and continue to be developed.
[0003] The current cluster uses Redis Sentinel mode, which consists of one master node and multiple slave nodes. Business systems only connect to the master node, which automatically synchronizes data with the slave nodes. If the master node experiences an unexpected power outage or becomes unreachable, a new master node will be automatically elected through Redis Sentinel mode. However, in the event of a master node power outage, the operating system may not have enough time to complete the Transmission Control Protocol (TCP) handshake initiated by the business system. Since the business system will not actively initiate a connection, manual intervention is required to restart the service and then re-elect a new master node. With manual intervention, issues may not be addressed promptly, or incorrect connections may occur, leaving the current master node in a power-off state. This causes the entire operating system and business systems to malfunction, reducing data storage efficiency.
[0004] Therefore, how to connect to Redis in a timely manner without affecting the normal operation of the operating system and business systems, so as to improve data storage efficiency, is a problem that urgently needs to be solved by those skilled in the art. Summary of the Invention
[0005] The purpose of this invention is to provide a method, apparatus, device, and medium for connecting cluster master nodes, in order to solve the problem of connection failure or incorrect manual operation in the event of manual intervention, which causes the current master node to be in a power-off state, resulting in the entire operating system and business system being unable to work properly and reducing data storage efficiency.
[0006] To address the aforementioned technical problems, this invention provides a method for connecting a cluster master node, comprising:
[0007] Obtain the current connection instance and current connection listening instance of the cross-platform non-relational database based on the business system call, wherein the business system is developed based on the runtime environment of an interpreted scripting language;
[0008] Create a connection to the current cross-platform non-relational database based on the current cross-platform non-relational database connection instance;
[0009] The current connection listening instance is controlled to determine whether the current cross-platform non-relational database connection is valid based on a timer mechanism.
[0010] If this is ineffective, the cluster master node is determined to be powered off, and a new connection to the current cross-platform non-relational database is re-established to restore the connection to the cluster master node.
[0011] On the one hand, the process of obtaining a connection instance for the current cross-platform non-relational database includes:
[0012] The code file of the cross-platform non-relational database is obtained based on the runtime environment of the interpreted scripting language;
[0013] Establish a connection between the runtime environment of the interpreted scripting language and the server of the cross-platform non-relational database based on the code file of the cross-platform non-relational database;
[0014] Create a connection client for the cross-platform non-relational database based on the code file of the cross-platform non-relational database;
[0015] The connection client for the cross-platform non-relational database is invoked to create a connection instance for the current cross-platform non-relational database;
[0016] The connection instance of the current cross-platform non-relational database is the connection information of the server of the cross-platform non-relational database, and the connection information includes at least address information, port information and authentication information.
[0017] On the other hand, after obtaining the connection instance of the current cross-platform non-relational database, and before creating a connection to the current cross-platform non-relational database based on the connection instance of the current cross-platform non-relational database, the method further includes:
[0018] The connection instance of the current cross-platform non-relational database is stored in a global static object so that the business system can directly obtain the connection to create the current cross-platform non-relational database.
[0019] On the other hand, the control of the current connection listening instance to determine whether the current cross-platform non-relational database connection is valid based on a timer mechanism includes:
[0020] The timed calling function in the runtime environment of the interpreted scripting language is determined based on the development platform to which the runtime environment of the interpreted scripting language belongs;
[0021] The heartbeat detection command is sent to the server of the cross-platform non-relational database according to the timed call function;
[0022] The corresponding feedback information is determined based on the heartbeat detection command;
[0023] Based on the feedback information, determine whether the current cross-platform non-relational database connection is valid.
[0024] On the other hand, determining that the current cross-platform non-relational database connection is invalid includes:
[0025] Determine whether the feedback information has been obtained within a preset time period;
[0026] If not obtained, the connection to the current cross-platform non-relational database is determined to be invalid;
[0027] If obtained, determine whether the feedback information is empty;
[0028] If the feedback information is empty, then the current cross-platform non-relational database connection is determined to be invalid;
[0029] If the feedback information is not empty, then determine whether the feedback information is a feedback error message;
[0030] If the feedback information is an error message, then the current cross-platform non-relational database connection is determined to be invalid.
[0031] If the feedback information is not a feedback error information, then the feedback time interval corresponding to the feedback information is obtained, wherein the feedback time interval is the time interval between sending the heartbeat detection command and the feedback time;
[0032] If the feedback time interval is greater than the preset time, then the connection to the current cross-platform non-relational database is determined to be invalid.
[0033] On the other hand, when the current cross-platform non-relational database connection becomes invalid, a new connection to the current cross-platform non-relational database is established, including:
[0034] Control the current connection listening instance to trigger a callback function to facilitate logging and execution information;
[0035] Based on the current cross-platform non-relational database connection instance, the cross-platform non-relational database connection client is invoked to recreate the current cross-platform non-relational database connection instance;
[0036] Replace the current cross-platform non-relational database connection instance with the new connection instance.
[0037] Destroy the current connection listening instance, create a new current connection listening instance, and return to the step of creating a connection to the current cross-platform non-relational database based on the current cross-platform non-relational database connection instance to complete the establishment of the new connection to the current cross-platform non-relational database.
[0038] On the other hand, before the control of the current connection listening instance determines whether the current cross-platform non-relational database connection is valid based on a timer mechanism, the following is also included:
[0039] Obtain the status information of the current cross-platform non-relational database connection;
[0040] Determine whether the status information is in a disconnected state;
[0041] If the status information is disconnected, then reconnect to the cross-platform non-relational database server;
[0042] Record the current number of connections to the server that connects to the cross-platform non-relational database;
[0043] Determine whether the current number of connections has reached the preset number;
[0044] If the preset number of attempts is not reached, return to the step of obtaining the status information of the current cross-platform non-relational database connection;
[0045] If the preset number of attempts is reached, and the server of the cross-platform non-relational database has not yet successfully connected or the status information is in the disconnected state, it is determined that the current connection instance of the cross-platform non-relational database is incorrect.
[0046] Return to the step of obtaining the current cross-platform non-relational database connection instance and the current connection listening instance based on the business system call to obtain the new current cross-platform non-relational database connection instance and the new current connection listening instance;
[0047] If the preset number of connections is reached and the connection to the cross-platform non-relational database server is successful, then the process proceeds to the step of controlling the current connection listening instance to determine whether the current connection to the cross-platform non-relational database is valid based on a timer mechanism.
[0048] To address the aforementioned technical problems, the present invention also provides a connection device for a cluster master node, comprising:
[0049] The acquisition module is used to acquire the current connection instance and the current connection listening instance of the cross-platform non-relational database based on the business system call, wherein the business system is developed based on the runtime environment of the interpreted scripting language;
[0050] A creation module is used to create a connection to the current cross-platform non-relational database based on the current cross-platform non-relational database connection instance;
[0051] The determination module is used to control the current connection listening instance to determine whether the current cross-platform non-relational database connection is valid based on a timer mechanism; if invalid, the establishment module is triggered.
[0052] The establishment module is used to determine that the cluster master node has lost power and to re-establish a new connection to the current cross-platform non-relational database in order to restore the connection of the cluster master node.
[0053] To address the aforementioned technical problems, the present invention also provides a connection device for a cluster master node, comprising:
[0054] Memory, used to store computer programs;
[0055] A processor is used to implement the steps of the cluster master node connection method as described above when executing the computer program.
[0056] To address the aforementioned technical problems, the present invention also provides a computer-readable storage medium storing a computer program, which, when executed by a processor, implements the steps of the cluster master node connection method described above.
[0057] This invention provides a method for connecting a cluster master node. It creates a connection to the current cross-platform non-relational database (NRD) based on the current NRD connection instance. The method controls the current connection listening instance to determine the validity of the current NRD connection using a timer mechanism. If invalid, it determines that the cluster master node is powered down and re-establishes a new connection to the current NRD to restore the cluster master node's connection. The advantages of this invention are: real-time monitoring via a connection listening instance within a Redis caching system; determining that the cluster master node is powered down and re-establishing a new connection when an invalid connection to the current NRD is detected, thus ensuring the stability of the Redis connection; timely restarting of the Redis server connection without manual intervention, facilitating the subsequent re-election of a new Redis master node; reducing maintenance costs, shortening server downtime, improving storage efficiency, and ensuring the normal operation of the operating system and business systems.
[0058] Secondly, the process of obtaining the current Redis connection instance uses Node.js to connect to Redis, importing the Redis code file to ensure that Redis connections can quickly detect and recover from connection failures. In this embodiment, the current Redis connection instance is stored in a global static object so that business systems can directly obtain the connection instance for data read and write operations. The process of determining the validity of the current cross-platform NoSQL database connection provides finer-grained information for determining the power outage status of the cluster master node, improving the accuracy of the judgment. The process of re-establishing a new connection to the current cross-platform NoSQL database saves resources, ensures the stability of the Redis connection, and enhances the system's self-healing ability and robustness, realizing the automatic creation, monitoring, and re-establishment of Redis connections. Preprocessing checks before sending Ping commands ensure the stability and reliability of the Redis connection.
[0059] In addition, the present invention also provides a connection device, equipment and medium for cluster master nodes, which have the same beneficial effects as the above-described connection method for cluster master nodes. Attached Figure Description
[0060] To more clearly illustrate the embodiments of the present invention, the accompanying drawings used in the embodiments will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present invention. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.
[0061] Figure 1 A flowchart illustrating a cluster master node connection method provided in an embodiment of the present invention;
[0062] Figure 2 This is a schematic diagram illustrating the connection for power-off recovery of a cluster master node, provided in an embodiment of the present invention.
[0063] Figure 3 This is a structural diagram of a cluster master node connection device provided in an embodiment of the present invention;
[0064] Figure 4 This is a structural diagram of a cluster master node connection device provided in an embodiment of the present invention. Detailed Implementation
[0065] The technical solutions of the embodiments of the present invention will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of the present invention, and not all embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those of ordinary skill in the art without creative effort are within the protection scope of the present invention.
[0066] The core of this invention is to provide a method, apparatus, device, and medium for connecting cluster master nodes, in order to solve the problem of connection failure or incorrect manual operation in the event of manual intervention, which causes the current master node to be in a power-off state, resulting in the entire operating system and business system being unable to work properly and reducing data storage efficiency.
[0067] To enable those skilled in the art to better understand the present invention, the present invention will be further described in detail below with reference to the accompanying drawings and specific embodiments.
[0068] It's important to note that when deploying a Redis cluster using Redis Sentinel mode, if the master node experiences an unexpected power outage or other connection failure, Sentinel mode will automatically elect a new master node. Generally, business systems connect to Redis using the TCP protocol. Before connecting, the Sentinel mode queries the system to identify the master node and then establishes a connection. Normally, if the master node fails but the operating system is functioning correctly, the operating system initiates a TCP four-way handshake with the business system connected to Redis, and the business system re-establishes the connection. However, if the master node experiences an unexpected power outage, the operating system may not have enough time to complete the TCP four-way handshake initiated by the business system. The business system will not proactively re-initiate the connection and requires manual intervention. If manual intervention is not timely, the system will remain in a faulty state. The cluster master node connection method provided in this invention can solve the above-mentioned technical problems.
[0069] The TCP four-way handshake involves sending four segments to disconnect the TCP connection from the server. Redis Sentinel mode, officially recommended by Redis, is a high-availability solution that addresses the shortcomings of master-slave mode. Sentinels monitor the host machine's status; when the host fails, the Sentinel automatically performs failover and promotes one of its monitored slaves to master, thus ensuring high system availability.
[0070] Figure 1 A flowchart illustrating a cluster master node connection method provided in an embodiment of the present invention is shown below. Figure 1 As shown, the method includes:
[0071] S11: Obtain the current cross-platform non-relational database connection instance and the current connection listening instance based on business system calls;
[0072] Among them, the business systems are developed based on the runtime environment of the interpreted scripting language;
[0073] S12: Create a connection to the current cross-platform non-relational database based on the current cross-platform non-relational database connection instance;
[0074] S13: Control the current connection listening instance to determine whether the current cross-platform non-relational database connection is valid based on a timer mechanism; if invalid, proceed to step S14; if valid, return to step S13 to continue monitoring.
[0075] S14: Determine if the cluster master node is powered off, and re-establish a new connection to the current cross-platform non-relational database to restore the connection to the cluster master node.
[0076] Specifically, it retrieves the current cross-platform NoSQL database connection instance (the current Redis connection instance) and the current connection listening instance based on the business system call. The current Redis connection instance is created during system initialization after establishing a connection between the Redis module and the Redis server. Redis is a key-value storage system middleware, often used as a cache for business systems. In this embodiment, the business system is developed based on Node.js (an interpreted scripting language runtime environment), which is a JavaScript runtime environment based on the Chrome V8 engine. It uses an event-driven, non-blocking input / output (I / O) model, allowing JavaScript to run on the server-side development platform.
[0077] After obtaining the current Redis connection instance in step S11, a Redis connection is created based on this instance, i.e., connecting to the Redis server. In other words, a Redis connection is created to connect to the existing one when none exists. In step S13, the current connection listening instance monitors the validity of the current Redis connection. A timer mechanism is used for monitoring to confirm whether the connection is established. If established, listening continues; if not established, the Redis connection needs to be recreated. If the connection is not established, it is determined that the current Redis connection is invalid, indicating that the cluster master node is in a power-off state. After re-establishing the Redis connection, a new master node is selected. This invention only automatically re-establishes the connection when the cluster master node is powered off, without manual intervention.
[0078] The method for creating the connection in step S12 is not limited here; it can be the same as the connection method used during manual intervention, or it can be different, depending on the actual situation. The timer mechanism in step S13 can be a watchdog-based timer mechanism or a software-implemented timer mechanism; there is no limitation here. Regarding the process of determining whether the current Redis connection is valid in step S13, a request can be sent, and the validity can be determined based on the feedback information generated by the request. If the feedback information is an error message or other abnormal information, the current Redis connection is considered invalid; if the feedback information is normal feedback reception, the current Redis connection is considered valid.
[0079] Step S14, re-establishing a new current Redis connection, can either reconnect to the existing connection instance or obtain a new connection instance and create a new current Redis connection. There is no limitation here; it can be set according to the actual situation. Regarding the number of re-establishments and the corresponding time limit, there is no limitation here; it can be set according to the actual situation.
[0080] This invention provides a method for connecting a cluster master node. It creates a connection to the current cross-platform non-relational database (NRD) based on the current cross-platform NRD connection instance. The method controls the current connection listening instance to determine the validity of the current cross-platform NRD connection using a timer mechanism. If invalid, it determines that the cluster master node is powered down and re-establishes a new connection to the current cross-platform NRD to restore the cluster master node's connection. The advantages of this invention are: real-time monitoring is achieved through a connection listening instance within a Redis caching system. When an invalid connection to the current cross-platform NRD is detected, the cluster master node is powered down, and a new connection is re-established to ensure the stability of the Redis connection. It also allows for timely restarting of the Redis server without manual intervention, facilitating the subsequent re-election of a new Redis master node. Furthermore, it reduces maintenance costs, shortens server downtime, improves storage efficiency, and ensures the normal operation of the operating system and business systems.
[0081] Based on the above embodiments, in some embodiments, the process of obtaining the connection instance of the current cross-platform non-relational database in step S11 includes:
[0082] Obtain code files for cross-platform non-relational databases using an interpreted scripting language runtime environment;
[0083] Establish a connection between the runtime environment of the interpreted scripting language and the server of the cross-platform non-relational database based on the code files of the cross-platform non-relational database;
[0084] Create a cross-platform non-relational database connection client based on the code file of the cross-platform non-relational database;
[0085] Invoke the cross-platform non-relational database connection client to create a connection instance for the current cross-platform non-relational database;
[0086] The connection instance of the current cross-platform non-relational database is the connection information of the server of the cross-platform non-relational database. The connection information includes at least address information, port information and authentication information.
[0087] Specifically, the Redis code file (dependency package) is obtained using an interpreted scripting language runtime environment (Node.js). This code file stores the Redis module, and a connection is established between the Node.js runtime environment and the Redis server based on the Redis code file. Based on the Redis code file, communication with the Redis server can be performed within the Node.js environment to conduct various caching operations. A cross-platform NoSQL database connection client (Redis Connection Client) is created based on the Redis code file. The Redis Connection Client is called through Node.js to create the current Redis connection instance. This Redis connection instance is actually the connection information of the Redis server, i.e., configuration information, which includes at least address information, port information, and authentication information.
[0088] The process of obtaining the current Redis connection instance provided in this embodiment of the invention uses Node.js to connect to Redis and imports Redis code files to ensure that Redis connection can quickly detect connection anomalies and recover quickly.
[0089] Based on the above embodiments, in some embodiments, in order for the business system to quickly obtain a connection instance for data read and write operations, after obtaining the connection instance of the current cross-platform non-relational database and before creating a connection to the current cross-platform non-relational database based on the current cross-platform non-relational database connection instance, the following method is further included:
[0090] Store the current cross-platform non-relational database connection instance in a global static object so that business systems can directly obtain the connection to create the current cross-platform non-relational database.
[0091] It is understandable that in this embodiment, the current Redis connection instance is stored in a global static object so that the business system can directly obtain the connection instance and perform data read and write operations. In this way, the business system no longer needs to care about the underlying connection details and can directly use the interface provided by the connection management device for data caching and reading / writing.
[0092] In some embodiments, step S13, controlling the current connection listening instance to determine whether the current cross-platform non-relational database connection is valid based on a timer mechanism, includes:
[0093] Determine the timed calling function in the runtime environment of the interpreted scripting language based on the development platform to which the runtime environment belongs;
[0094] A heartbeat detection command is sent to a cross-platform non-relational database server based on a timed function call;
[0095] Determine the corresponding feedback information based on the heartbeat detection command;
[0096] Determine whether the current cross-platform non-relational database connection is valid based on the feedback information.
[0097] Specifically, this embodiment leverages Node.js features, employing a timer mechanism specifically the `setInterval` function. This function can call functions or calculate expressions at specified intervals, executing a specific timed function call every certain time interval (e.g., 5 seconds). The execution method involves sending a heartbeat command (Ping command) to the Redis server to confirm the connection's validity. The Ping command is a lightweight heartbeat command used to maintain an active connection with the server. The Ping command determines the corresponding feedback information, and based on this feedback, the validity of the current Redis connection is determined.
[0098] In some embodiments, determining that a current connection to a cross-platform non-relational database is invalid includes:
[0099] Determine whether feedback information has been obtained within a preset time period;
[0100] If not found, the current cross-platform non-relational database connection is invalid.
[0101] If obtained, check if the feedback information is empty;
[0102] If the feedback message is empty, it indicates that the current cross-platform non-relational database connection is invalid.
[0103] If the feedback information is not empty, then determine whether the feedback information is an error message;
[0104] If the feedback message is an error message, then the current cross-platform non-relational database connection is invalid.
[0105] If the feedback information is not an error message, then obtain the feedback time interval corresponding to the feedback information, where the feedback time interval is the time interval between sending the heartbeat detection command and the feedback time.
[0106] If the feedback time interval is longer than the preset time, the current cross-platform non-relational database connection is determined to be invalid.
[0107] A preset time is set for obtaining feedback information. Within this preset time, it is determined whether feedback information has been successfully obtained. If not, the current Redis connection is deemed invalid. If obtained, the specific information in the feedback information is checked. If empty, the connection is deemed invalid; otherwise, the feedback information contains specific information. The system then checks whether the feedback information is an error message. If so, the connection is deemed invalid; otherwise, the corresponding feedback time interval is obtained. It should be noted that the feedback time interval in this embodiment is the time interval between the start time of sending the Ping command and the time when the feedback information is generated, which differs from the preset time. In this embodiment, the preset time is the time when the feedback information is obtained. The relationship between the feedback time interval and the preset time can only be determined after the feedback information is obtained within the preset time.
[0108] In this embodiment, the feedback time interval is set to ensure that feedback information is actually obtained from the current Ping command, guaranteeing the timeliness and accuracy of the information. If the feedback time interval is greater than the preset time, the feedback information may have been sent by the previous Ping command, which has not yet been obtained, making it impossible to prove that there was a disconnection when the current Ping command was sent, resulting in a delayed response. Therefore, this embodiment takes this into consideration: only when the feedback time interval is less than the preset time is the feedback information from the current Ping command considered valid; otherwise, if the feedback time interval is greater than the preset time, the current Redis connection is determined to be invalid.
[0109] The process provided in this embodiment for determining the connection validity of a cross-platform non-relational database refines the determination of the power outage status of the cluster master node and improves the accuracy of the judgment.
[0110] In some embodiments, when a current cross-platform non-relational database connection becomes invalid, a new connection to the current cross-platform non-relational database is established, including:
[0111] Control the current connection listening instance to trigger callback functions so as to record logs and execute operation information;
[0112] Based on the current cross-platform non-relational database connection instance, the cross-platform non-relational database connection client is invoked to recreate the current cross-platform non-relational database connection instance;
[0113] Replace the current cross-platform non-relational database connection instance with the new one.
[0114] Destroy the current connection listener instance, create a new current connection listener instance, and return to the step of creating a connection to the current cross-platform non-relational database based on the current cross-platform non-relational database connection instance to complete the establishment of the new current cross-platform non-relational database connection.
[0115] Specifically, after the current Redis connection becomes invalid, a callback function is triggered by the current connection listener instance to handle the connection loss. The callback function logs information, notifies the administrator, or performs other necessary operations to address the connection issue promptly. It then calls the Redis connection client, and based on the saved configuration information, recreates a new Redis connection instance to replace the current one. This ensures resource release and reconstruction, allowing the system to smoothly switch to the new Redis connection instance. Business systems can continue to use the new Redis connection for data reading and writing, and users will hardly notice the connection switch. After recreating the Redis connection, the current connection listener instance is destroyed to avoid redundant resource consumption. A new current connection listener instance is then created to monitor the Redis connection status.
[0116] It should be noted that while creating a new current connection listener instance can be based on an existing one, using the existing instance requires configuring relevant parameters after creating a new Redis connection. During this configuration process, other configuration errors may occur. Therefore, considering the time required for configuration and the possibility of errors, it is preferable to recreate the current connection listener instance and return to the steps of creating a new cross-platform non-relational database connection based on the existing cross-platform non-relational database connection instance to complete the establishment of the new cross-platform non-relational database connection.
[0117] The process of re-establishing a new connection to the current cross-platform non-relational database provided in this embodiment saves resources, ensures the stability of the Redis connection, and enhances the system's self-healing ability and robustness, realizing the automatic creation, monitoring, and re-establishment of Redis connections.
[0118] In some embodiments, before controlling the current connection listening instance to determine whether the current cross-platform non-relational database connection is valid based on a timer mechanism, the method further includes:
[0119] Get the status information of the current cross-platform non-relational database connection;
[0120] Determine if the status information indicates a disconnected state;
[0121] If the status information is disconnected, then reconnect to the cross-platform non-relational database server;
[0122] Record the current number of connections to servers that connect to cross-platform non-relational databases;
[0123] Determine if the current connection count has reached the preset limit;
[0124] If the preset number of attempts is not reached, return to the step of obtaining the status information of the current cross-platform non-relational database connection;
[0125] If the preset number of attempts is reached, and the cross-platform non-relational database server has not yet successfully connected or the status information is disconnected, then the current cross-platform non-relational database connection instance is determined to be faulty.
[0126] Return to the steps of obtaining the current cross-platform non-relational database connection instance and the current connection listening instance based on the business system call to obtain the new current cross-platform non-relational database connection instance and the new current connection listening instance;
[0127] If the preset number of attempts is reached and the connection to the cross-platform non-relational database server is successful, the process proceeds to the step of controlling the current connection listening instance to determine whether the current cross-platform non-relational database connection is valid based on a timer mechanism.
[0128] Specifically, before sending a Ping command for monitoring, it's necessary to ensure the current Redis connection is usable. This involves checking the current Redis connection status. If the status is disconnected, a reconnection to the Redis server is required, and the connection count should be recorded. If the pre-defined number of reconnections is not reached, continue reconnecting to the Redis server. If the pre-defined number of reconnections is reached, and the Redis server still hasn't connected successfully, or if it connects but the status is still disconnected, then the current Redis connection instance is incorrect, possibly due to a configuration error. A new Redis connection instance needs to be obtained for subsequent monitoring.
[0129] If the preset number of attempts is reached and the connection to the Redis server is successfully established, proceed to step S13 for monitoring.
[0130] The preprocessing checks provided in this embodiment before sending the Ping command ensure the stability and reliability of the Redis connection.
[0131] Figure 2 This is a schematic diagram illustrating a power outage recovery process for a cluster master node, as provided in an embodiment of the present invention. Figure 2 As shown, the system includes a connection management unit 1 and a connection listening unit 2. The connection management unit 1 manages Redis connection instances. It creates and returns connections by establishing connections with the cross-platform NoSQL database server 3. When no Redis connection exists, the connection management unit 1 is responsible for creating it. Once a Redis connection is established, the connection management unit 1 distributes the Redis connection instance to ensure its uniqueness. This saves resources and avoids redundant creation and waste. The connection listening unit 2 listens for established Redis connections. By listening, the connection listening unit 2 can confirm whether the connection is established. If the connection listening unit 2 detects that the Redis connection is not established, it will notify the connection management unit 1 to recreate the Redis connection. This ensures the stability and reliability of the Redis connection and avoids business anomalies caused by connection interruptions or other problems.
[0132] By regularly pinging and monitoring connection status, the system can promptly detect connection anomalies and respond quickly when connections are lost. This not only ensures data persistence and consistency but also improves the system's fault tolerance and availability. During implementation, it's crucial to consider thread safety and performance optimization in the design of the connection management and connection listening mechanisms. In Node.js, appropriate synchronous and asynchronous mechanisms can be used to ensure that connection management in a multi-threaded environment does not cause resource contention or conflicts. Furthermore, connection pooling techniques can be employed to improve connection reuse, reduce the overhead of connection creation and destruction, and thus enhance overall system performance.
[0133] Furthermore, the cluster master node connection method of this invention can effectively manage Redis connection instances, ensuring system stability and reliability, and avoiding business anomalies caused by connection interruptions or other problems. In practical applications, this invention can be widely used in various scenarios that require Redis as a cache or message queue. For example, in internet applications, Redis can be used as a cache to accelerate data access speed and improve application performance and response speed. In distributed systems, Redis can be used as a message queue to deliver messages, ensuring reliable message delivery and sequential processing. As a high-performance in-memory database, Redis, through the cooperation of connection management and connection listening devices, ensures effective management and real-time monitoring of Redis connections by the system. Node.js, as a non-blocking asynchronous event-driven framework, can easily handle high-concurrency connection management and data processing, enabling the entire system to maintain efficient and stable operation even when facing a large number of requests. The application of this technology gives the system high availability, high performance, and high maintainability, providing users with a more stable and reliable service experience.
[0134] The foregoing has described in detail various embodiments of the cluster master node connection method. Based on this, the present invention also discloses a cluster master node connection device corresponding to the above methods. Figure 3 This is a structural diagram of a cluster master node connection device provided in an embodiment of the present invention. Figure 3 As shown, the connection device for the cluster master node includes:
[0135] Module 11 is used to obtain the connection instance and the current connection listening instance of the current cross-platform non-relational database based on the business system call. The business system is developed based on the runtime environment of an interpreted scripting language.
[0136] Create module 12 to create a connection to the current cross-platform non-relational database based on the current cross-platform non-relational database connection instance;
[0137] Module 13 is used to control the current connection listening instance to determine whether the current cross-platform non-relational database connection is valid based on a timer mechanism; if invalid, it triggers module 14.
[0138] Establish module 14 to determine if the cluster master node has lost power and re-establish a new connection to the current cross-platform non-relational database to restore the connection to the cluster master node.
[0139] In some embodiments, the process of obtaining the connection instance of the current cross-platform non-relational database in module 11 includes:
[0140] The first acquisition submodule is used to acquire code files for cross-platform non-relational databases based on the runtime environment of an interpreted scripting language;
[0141] The first submodule is used to establish a connection between the runtime environment of the interpreted scripting language and the server of the cross-platform non-relational database based on the code file of the cross-platform non-relational database.
[0142] The first creation submodule is used to create a cross-platform non-relational database connection client based on the code file of the cross-platform non-relational database;
[0143] The second creation submodule is used to call a cross-platform non-relational database connection client to create a connection instance for the current cross-platform non-relational database;
[0144] The connection instance of the current cross-platform non-relational database is the connection information of the server of the cross-platform non-relational database. The connection information includes at least address information, port information and authentication information.
[0145] In some embodiments, after obtaining the connection instance of the current cross-platform non-relational database in module 11 and before creating module 12, the method further includes:
[0146] The first storage submodule is used to store the connection instance of the current cross-platform non-relational database in a global static object so that the business system can directly obtain the connection to create the current cross-platform non-relational database.
[0147] In some embodiments, the determining module 13 includes:
[0148] The first determination submodule is used to determine the timed call function in the runtime environment of the interpreted scripting language based on the development platform to which the runtime environment of the interpreted scripting language belongs;
[0149] The first sending submodule is used to send heartbeat detection commands to a cross-platform non-relational database server according to a timed function call.
[0150] The second determination submodule is used to determine the corresponding feedback information based on the heartbeat detection command;
[0151] The third determination submodule is used to determine whether the current cross-platform non-relational database connection is valid based on the feedback information.
[0152] In some embodiments, determining that a current connection to a cross-platform non-relational database is invalid includes:
[0153] The fourth determination submodule is used to determine whether feedback information has been obtained within a preset time. If no feedback information is obtained, the fifth determination submodule is triggered. If feedback information is obtained, the first judgment submodule is triggered.
[0154] The fifth determination submodule is used to determine if the current cross-platform non-relational database connection is invalid;
[0155] The first judgment submodule is used to determine whether the feedback information is empty; if it is empty, the sixth determination submodule is triggered; if it is not empty, the second judgment submodule is triggered.
[0156] The sixth submodule is used to determine if the current cross-platform non-relational database connection is invalid;
[0157] The second judgment submodule is used to determine whether the feedback information is an error message; if so, the seventh determination submodule is triggered; if not, the second acquisition submodule is triggered.
[0158] The seventh determination submodule is used to determine if the current cross-platform non-relational database connection is invalid;
[0159] The second acquisition submodule is used to acquire the feedback time interval corresponding to the feedback information, wherein the feedback time interval is the time interval between the time of sending the heartbeat detection command and the feedback time.
[0160] The eighth determination submodule is used to determine that the current cross-platform non-relational database connection is invalid if the feedback time interval is greater than a preset time.
[0161] In some embodiments, when the current cross-platform non-relational database connection is invalid, the establishment module 14 includes:
[0162] The first control submodule is used to control the current connection listening instance to trigger callback functions in order to record logs and execute operation information;
[0163] The first calling submodule is used to call the cross-platform non-relational database connection client to recreate the current cross-platform non-relational database connection instance based on the current cross-platform non-relational database connection instance;
[0164] The first replacement submodule is used to replace the current cross-platform non-relational database connection instance with the new current cross-platform non-relational database connection instance;
[0165] The first destruction submodule is used to destroy the current connection listening instance, create a new current connection listening instance, and return to the step of creating a connection to the current cross-platform non-relational database based on the current cross-platform non-relational database connection instance to complete the establishment of a new connection to the current cross-platform non-relational database.
[0166] In some embodiments, prior to determining module 13, the method further includes:
[0167] The third submodule is used to obtain the status information of the current cross-platform non-relational database connection.
[0168] The third judgment submodule is used to determine whether the status information is disconnected; if so, the first connection submodule is triggered.
[0169] The first connection submodule is used to reconnect to a cross-platform non-relational database server;
[0170] The first recording submodule is used to record the current number of connections to servers that connect to cross-platform non-relational databases;
[0171] The fourth judgment submodule is used to determine whether the current connection count has reached the preset number. If the preset number has not been reached, it returns to the third acquisition submodule. If the preset number has been reached and the cross-platform non-relational database server has not been successfully connected or the status information is disconnected, the ninth determination submodule is triggered. If the preset number has been reached and the connection to the cross-platform non-relational database server is successful, the determination module 13 is triggered.
[0172] The ninth submodule is used to determine if there is an error in the current cross-platform non-relational database connection instance;
[0173] Return to module 11 to obtain the new current cross-platform non-relational database connection instance and the new current connection listening instance.
[0174] Since the embodiments of the device part correspond to the embodiments described above, please refer to the embodiments described in the method part for the embodiments of the device part, and will not be repeated here.
[0175] For a description of the cluster master node connection device provided by the present invention, please refer to the above method embodiment. The present invention will not be described again here, but it has the same beneficial effects as the above cluster master node connection method.
[0176] Figure 4 A structural diagram of a cluster master node connection device provided in an embodiment of the present invention is shown below. Figure 4 As shown, the device includes:
[0177] Memory 21 is used to store computer programs;
[0178] Processor 22 is used to implement the steps of the cluster master node connection method when executing computer programs.
[0179] The connection device for the cluster master node provided in this embodiment may include, but is not limited to, a tablet computer, a laptop computer, or a desktop computer.
[0180] The processor 22 may include one or more processing cores, such as a quad-core processor or an octa-core processor. The processor 22 may be implemented using at least one of the following hardware forms: Digital Signal Processor (DSP), Field-Programmable Gate Array (FPGA), or Programmable Logic Array (PLA). The processor 22 may also include a main processor and a coprocessor. The main processor, also known as the Central Processing Unit (CPU), is used to process data in the wake-up state; the coprocessor is a low-power processor used to process data in the standby state. In some embodiments, the processor 22 may integrate a Graphics Processing Unit (GPU), which is responsible for rendering and drawing the content to be displayed on the screen. In some embodiments, the processor 22 may also include an Artificial Intelligence (AI) processor, which handles computational operations related to machine learning.
[0181] The memory 21 may include one or more computer-readable storage media, which may be non-transitory. The memory 21 may also include high-speed random access memory and non-volatile memory, such as one or more disk storage devices or flash memory devices. In this embodiment, the memory 21 is used to store at least the following computer program 211, which, after being loaded and executed by the processor 22, is capable of implementing the relevant steps of the cluster master node connection method disclosed in any of the foregoing embodiments. In addition, the resources stored in the memory 21 may also include an operating system 212 and data 213, etc., and the storage method may be temporary storage or permanent storage. The operating system 212 may include Windows, Unix, Linux, etc. The data 213 may include, but is not limited to, the data involved in the cluster master node connection method, etc.
[0182] In some embodiments, the connection device of the cluster master node may further include a display screen 23, an input / output interface 24, a communication interface 25, a power supply 26, and a communication bus 27.
[0183] Those skilled in the field can understand, Figure 4The structure shown does not constitute a limitation on the connection devices of the cluster master node and may include more or fewer components than shown.
[0184] The processor 22 implements the cluster master node connection method provided in any of the above embodiments by calling the instructions stored in the memory 21.
[0185] For an introduction to the connection device for a cluster master node provided by the present invention, please refer to the above method embodiment. The present invention will not be described in detail here, but it has the same beneficial effects as the above-described connection method for a cluster master node.
[0186] Furthermore, the present invention also provides a computer-readable storage medium storing a computer program, which, when executed by processor 22, implements the steps of the connection method for the cluster master node described above.
[0187] It is understood that if the methods in the above embodiments are implemented as software functional units and sold or used as independent products, they can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of the present invention, in essence, or the part that contributes to the prior art, or all or part of the technical solution, can be embodied in the form of a software product. This computer software product is stored in a storage medium and executes all or part of the steps of the methods described in the various embodiments of the present invention. The aforementioned storage medium includes various media capable of storing program code, such as USB flash drives, portable hard drives, read-only memory (ROM), random access memory (RAM), magnetic disks, or optical disks.
[0188] For an introduction to the computer-readable storage medium provided by the present invention, please refer to the above method embodiments. The present invention will not be described in detail here, but it has the same beneficial effects as the above-described cluster master node connection method.
[0189] The foregoing has provided a detailed description of a cluster master node connection method, apparatus, device, and medium provided by the present invention. The various embodiments in the specification are described in a progressive manner, with each embodiment focusing on its differences from other embodiments. Similar or identical parts between embodiments can be referred to interchangeably. For the apparatus disclosed in the embodiments, since it corresponds to the method disclosed in the embodiments, the description is relatively simple; relevant parts can be referred to in the method section. It should be noted that those skilled in the art can make several improvements and modifications to the present invention without departing from the principles of the invention, and these improvements and modifications also fall within the protection scope of the claims of the present invention.
[0190] It should also be noted that, in this specification, relational terms such as "first" and "second" are used only to distinguish one entity or operation from another, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Furthermore, the terms "comprising," "including," or any other variations thereof are intended to cover non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements includes not only those elements but also other elements not expressly listed, or elements inherent to such a process, method, article, or apparatus. Without further limitations, an element defined by the phrase "comprising one..." does not exclude the presence of other identical elements in the process, method, article, or apparatus that includes said element.
Claims
1. A method for connecting a cluster master node, characterized in that, include: Obtain the current connection instance and current connection listening instance of the cross-platform non-relational database based on the business system call, wherein the business system is developed based on the runtime environment of an interpreted scripting language; Create a connection to the current cross-platform non-relational database based on the current cross-platform non-relational database connection instance; The current connection listening instance is controlled to determine whether the current cross-platform non-relational database connection is valid based on a timer mechanism. If this is ineffective, then the cluster master node is determined to be powered off, and a new connection to the current cross-platform non-relational database is re-established to restore the connection of the cluster master node; Correspondingly, the control of the current connection listening instance to determine whether the current cross-platform non-relational database connection is valid based on a timer mechanism includes: The timed calling function in the runtime environment of the interpreted scripting language is determined based on the development platform to which the runtime environment of the interpreted scripting language belongs; The heartbeat detection command is sent to the server of the cross-platform non-relational database according to the timed call function; The corresponding feedback information is determined based on the heartbeat detection command; Based on the feedback information, determine whether the current cross-platform non-relational database connection is valid; Correspondingly, determining that the current cross-platform non-relational database connection is invalid includes: Determine whether the feedback information has been obtained within a preset time period; If not obtained, the connection to the current cross-platform non-relational database is determined to be invalid; If obtained, determine whether the feedback information is empty; If the feedback information is empty, then the current cross-platform non-relational database connection is determined to be invalid; If the feedback information is not empty, then determine whether the feedback information is a feedback error message; If the feedback information is an error message, then the connection to the current cross-platform non-relational database is determined to be invalid. If the feedback information is not a feedback error information, then the feedback time interval corresponding to the feedback information is obtained, wherein the feedback time interval is the time interval between sending the heartbeat detection command and the feedback time; If the feedback time interval is greater than the preset time, the connection to the current cross-platform non-relational database is determined to be invalid; wherein, feedback information is first obtained within the preset time and then the relationship between the feedback time interval and the preset time is determined.
2. The cluster master node connection method according to claim 1, characterized in that, The process of obtaining a connection instance for the current cross-platform non-relational database includes: The code file of the cross-platform non-relational database is obtained based on the runtime environment of the interpreted scripting language; Establish a connection between the runtime environment of the interpreted scripting language and the server of the cross-platform non-relational database based on the code file of the cross-platform non-relational database; Create a connection client for the cross-platform non-relational database based on the code file of the cross-platform non-relational database; The connection client for the cross-platform non-relational database is invoked to create a connection instance for the current cross-platform non-relational database; The connection instance of the current cross-platform non-relational database is the connection information of the server of the cross-platform non-relational database, and the connection information includes at least address information, port information and authentication information.
3. The cluster master node connection method according to claim 2, characterized in that, After obtaining the connection instance of the current cross-platform non-relational database, and before creating a connection to the current cross-platform non-relational database based on the connection instance of the current cross-platform non-relational database, the method further includes: The connection instance of the current cross-platform non-relational database is stored in a global static object so that the business system can directly obtain the connection to create the current cross-platform non-relational database.
4. The cluster master node connection method according to claim 1, characterized in that, When the current cross-platform non-relational database connection becomes invalid, a new connection to the current cross-platform non-relational database is established, including: Control the current connection listening instance to trigger a callback function to facilitate logging and execution information; Based on the current cross-platform non-relational database connection instance, the cross-platform non-relational database connection client is invoked to recreate the current cross-platform non-relational database connection instance; Replace the current cross-platform non-relational database connection instance with the new connection instance. Destroy the current connection listening instance, create a new current connection listening instance, and return to the step of creating a connection to the current cross-platform non-relational database based on the current cross-platform non-relational database connection instance to complete the establishment of the new connection to the current cross-platform non-relational database.
5. The cluster master node connection method according to claim 2, characterized in that, Before the control of the current connection listening instance to determine whether the current cross-platform non-relational database connection is valid based on a timer mechanism, the method further includes: Obtain the status information of the current cross-platform non-relational database connection; Determine whether the status information is in a disconnected state; If the status information indicates a disconnected state, then reconnect to the cross-platform non-relational database server; Record the current number of connections to the server that connects to the cross-platform non-relational database; Determine whether the current number of connections has reached the preset number; If the preset number of attempts is not reached, return to the step of obtaining the status information of the current cross-platform non-relational database connection; If the preset number of attempts is reached, and the server of the cross-platform non-relational database has not yet successfully connected or the status information is in the disconnected state, it is determined that the current connection instance of the cross-platform non-relational database is incorrect. Return to the step of obtaining the current cross-platform non-relational database connection instance and the current connection listening instance based on the business system call to obtain the new current cross-platform non-relational database connection instance and the new current connection listening instance; If the preset number of connections is reached and the connection to the cross-platform non-relational database server is successful, then the process proceeds to the step of controlling the current connection listening instance to determine whether the current connection to the cross-platform non-relational database is valid based on a timer mechanism.
6. A connection device for a cluster master node, characterized in that, include: The acquisition module is used to acquire the current connection instance and the current connection listening instance of the cross-platform non-relational database based on the business system call, wherein the business system is developed based on the runtime environment of the interpreted scripting language; A creation module is used to create a connection to the current cross-platform non-relational database based on the current cross-platform non-relational database connection instance; The determination module is used to control the current connection listening instance to determine whether the current cross-platform non-relational database connection is valid based on a timer mechanism; if invalid, the establishment module is triggered. The establishment module is used to determine that the cluster master node has lost power and to re-establish a new connection to the current cross-platform non-relational database to restore the connection of the cluster master node; Correspondingly, the control of the current connection listening instance to determine whether the current cross-platform non-relational database connection is valid based on a timer mechanism includes: The timed calling function in the runtime environment of the interpreted scripting language is determined based on the development platform to which the runtime environment of the interpreted scripting language belongs; The heartbeat detection command is sent to the server of the cross-platform non-relational database according to the timed call function; The corresponding feedback information is determined based on the heartbeat detection command; Based on the feedback information, determine whether the current cross-platform non-relational database connection is valid; Correspondingly, determining that the current cross-platform non-relational database connection is invalid includes: Determine whether the feedback information has been obtained within a preset time period; If not obtained, the connection to the current cross-platform non-relational database is determined to be invalid; If obtained, determine whether the feedback information is empty; If the feedback information is empty, then the current cross-platform non-relational database connection is determined to be invalid; If the feedback information is not empty, then determine whether the feedback information is a feedback error message; If the feedback information is an error message, then the connection to the current cross-platform non-relational database is determined to be invalid. If the feedback information is not a feedback error information, then the feedback time interval corresponding to the feedback information is obtained, wherein the feedback time interval is the time interval between sending the heartbeat detection command and the feedback time; If the feedback time interval is greater than the preset time, the connection to the current cross-platform non-relational database is determined to be invalid; wherein, feedback information is first obtained within the preset time and then the relationship between the feedback time interval and the preset time is determined.
7. A connection device for a cluster master node, characterized in that, include: Memory, used to store computer programs; A processor, configured to implement the steps of the cluster master node connection method as described in any one of claims 1 to 5 when executing the computer program.
8. A computer-readable storage medium, characterized in that, The computer-readable storage medium stores a computer program that, when executed by a processor, implements the steps of the cluster master node connection method as described in any one of claims 1 to 5.
Citation Information
Patent Citations
Monitoring system of presto cluster
CN109977161A
Redis cluster node management method and storage medium
CN112100004A