Database connection reconstruction method, device, equipment, readable storage medium and program product

By directly interacting with the database cluster management platform to obtain node metadata, comparing and rebuilding connections in the connection pool, the problem of reduced application response speed caused by database connection failure was solved, and the effect of quickly restoring application services was achieved.

CN122633649APending Publication Date: 2026-08-25TENPAY PAYMENT TECHNOLOGY CO LTD SHENZHEN BRANCH
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202510210753.3
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-02-24
Publication Date
2026-08-25

AI Technical Summary

Technical Problem

When a database connection fails, it slows down the application's response time. Current technology requires restarting the service to restore a valid connection, which affects the efficiency of business recovery.

Method used

By sending node metadata query requests to the database cluster management platform, the network addresses of the primary and standby nodes are obtained and compared, and the connections in the connection pool are rebuilt, thus enabling the rapid reconstruction of failed connections.

Benefits of technology

During routine maintenance or unexpected failures of the database cluster, the system can quickly restore the relevant business operations of the application, improving business availability and response speed.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN122633649A_ABST
    Figure CN122633649A_ABST
Patent Text Reader

Abstract

The application relates to a database connection reconstruction method, device, equipment, readable storage medium and program product. The method comprises the following steps: sending a node metadata query request to a management platform of a database cluster; receiving node metadata of a current database cluster returned by the management platform, wherein the node metadata comprises network addresses of master library nodes and backup library nodes in the database cluster; obtaining network addresses corresponding to created connections in a current connection pool, wherein the created connections comprise master library connections and backup library connections; performing consistency comparison on the network addresses of the master library nodes in the node metadata and the network addresses corresponding to the master library connections, and performing consistency comparison on the network addresses of the backup library nodes in the node metadata and the network addresses corresponding to the backup library connections; and in the case that the comparison results are inconsistent, reconstructing the connections in the connection pool according to the network addresses of the master library nodes and the network addresses of the backup library nodes in the node metadata, so that the connections can be quickly reconstructed.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This application relates to the field of computer technology, and in particular to a method, apparatus, computer device, computer-readable storage medium, and computer program product for reconstructing a database connection. Background Technology

[0002] Creating a database connection is a time-consuming operation and can easily pose security risks to the database. Therefore, creating multiple database connections centrally during program initialization and managing them in a centralized manner to form a connection pool for program use can ensure faster database read and write speeds and enhance security and reliability.

[0003] During routine database maintenance or unexpected failures, connections in the connection pool may become invalid. For example, when processes on the standby node are undergoing maintenance, the data on the standby node may be significantly behind that of the primary node. The current connection will read outdated data from the application's perspective, which is not as expected, making the connection invalid. Similarly, after a primary / standby node switch, the application can still access the old primary node through the old connection, but due to the switch, write operations will fail, and read operations will read outdated data, making the current connection invalid.

[0004] When these connections fail, the application cannot obtain a new connection, causing the failure to be resolved in a long time. It can only obtain a new connection after restarting, which obviously affects the response speed of the application. Summary of the Invention

[0005] Therefore, it is necessary to provide a method, apparatus, computer device, computer-readable storage medium, and computer program product for rebuilding database connections to address the aforementioned technical problems. This method can quickly rebuild valid connections and facilitate the restoration of application usage in the shortest possible time.

[0006] Firstly, this application provides a method for rebuilding a database connection, including:

[0007] Send node metadata query requests to the database cluster management platform;

[0008] The system receives the node metadata of the current database cluster returned by the management platform in response to the node metadata query request. The node metadata includes the network address of the primary database node and the network address of the backup database node in the database cluster. The primary database node is used to provide data read and write services, and the backup database node is used to back up the data of the primary database node.

[0009] Obtain the network addresses corresponding to the connections already created in the current connection pool, including primary database connections and backup database connections;

[0010] The network address of the primary database node in the node metadata is compared with the network address corresponding to the primary database connection. The network address of the backup database node in the node metadata is also compared with the network address corresponding to the backup database connection. If the comparison results are inconsistent, the connection in the connection pool is reconstructed based on the network addresses of the primary database node and the backup database node in the node metadata.

[0011] Secondly, this application also provides a database connection reconstruction apparatus, comprising:

[0012] The node metadata acquisition module is used to send a node metadata query request to the database cluster management platform; and to receive the node metadata of the current database cluster returned by the management platform in response to the node metadata query request. The node metadata includes the network address of the primary database node and the network address of the backup database node in the database cluster. The primary database node is used to provide data read and write services, and the backup database node is used to back up the data of the primary database node.

[0013] The connection acquisition module is used to acquire the network addresses corresponding to the connections already created in the current connection pool, including primary database connections and backup database connections;

[0014] The comparison module is used to compare the network address of the primary database node in the node metadata with the network address corresponding to the primary database connection, and to compare the network address of the backup database node in the node metadata with the network address corresponding to the backup database connection.

[0015] The reconstruction module is used to reconstruct the connections in the connection pool based on the network addresses of the primary and backup nodes in the node metadata when the comparison results are inconsistent.

[0016] In some embodiments, the database connection rebuilding apparatus further includes:

[0017] The receiving module is used to receive connection acquisition requests. The connection acquisition requests are submitted by the data access interface object after receiving a database operation request initiated by the application. The database operation request carries a query statement.

[0018] The connection return module is used to respond to the connection acquisition request by returning an idle connection to the data access interface object, so that the data access interface object can pass the query statement to the database cluster through the acquired connection and receive the execution result returned by the database cluster after executing the query statement.

[0019] In some embodiments, the connection return module is further configured to, in response to the connection acquisition request, query the status attributes of each connection in the current connection pool, the status attributes including idle status, occupied status, and abandoned status; if there is an idle connection in the current connection pool, return the idle target connection to the data access interface object, and update the status attribute of the target connection to occupied status.

[0020] In some embodiments, the database connection rebuilding apparatus further includes:

[0021] The connection creation module is used to update the status attribute of the target connection to idle state when it receives a connection playback notification about the target connection sent by the data access interface object.

[0022] In some embodiments, the connection return module is further configured to send a waiting connection release notification to the data access interface object when there are no idle connections in the current connection pool and the total number of connections in the connection pool reaches a set upper limit.

[0023] In some embodiments, the database connection rebuilding apparatus further includes:

[0024] The connection creation module is used to create new connections according to the configuration parameters of the connection pool when the total number of connections in the current connection pool has not reached the set upper limit. The created connections are added to the idle connection queue, which is used to store idle connections.

[0025] In some embodiments, the comparison module is further configured to modify the status attribute of the connections already created in the current connection pool to an abandoned state;

[0026] The reconstruction module is also used to call the connection creation function to create a new primary database connection based on the network address of the primary database node in the node metadata, and to call the connection creation function to create a new standby database connection based on the network address of the standby database node in the node metadata, and to add the newly created primary database connection and standby database connection to the connection pool.

[0027] In some embodiments, the node metadata acquisition module is further configured to send a node metadata query request to the database cluster management platform at set intervals to obtain the node metadata of the current database cluster, and receive the node metadata of the current database cluster returned by the management platform in response to the node metadata query request, wherein the node metadata of the current database cluster is updated after the database cluster performs a primary / backup node switch.

[0028] Thirdly, this application also provides a computer device, including a memory and a processor, wherein the memory stores a computer program, and the processor executes the computer program to perform the following steps:

[0029] Send node metadata query requests to the database cluster management platform;

[0030] The system receives the node metadata of the current database cluster returned by the management platform in response to the node metadata query request. The node metadata includes the network address of the primary database node and the network address of the backup database node in the database cluster. The primary database node is used to provide data read and write services, and the backup database node is used to back up the data of the primary database node.

[0031] Obtain the network addresses corresponding to the connections already created in the current connection pool, including primary database connections and backup database connections;

[0032] The network address of the primary database node in the node metadata is compared with the network address corresponding to the primary database connection. The network address of the backup database node in the node metadata is also compared with the network address corresponding to the backup database connection.

[0033] If the comparison results are inconsistent, the connections in the connection pool are reconstructed based on the network addresses of the primary and backup nodes in the node metadata.

[0034] Fourthly, this application also provides a computer-readable storage medium having a computer program stored thereon, which, when executed by a processor, performs the following steps:

[0035] Send node metadata query requests to the database cluster management platform;

[0036] The system receives the node metadata of the current database cluster returned by the management platform in response to the node metadata query request. The node metadata includes the network address of the primary database node and the network address of the backup database node in the database cluster. The primary database node is used to provide data read and write services, and the backup database node is used to back up the data of the primary database node.

[0037] Obtain the network addresses corresponding to the connections already created in the current connection pool, including primary database connections and backup database connections;

[0038] The network address of the primary database node in the node metadata is compared with the network address corresponding to the primary database connection. The network address of the backup database node in the node metadata is also compared with the network address corresponding to the backup database connection.

[0039] If the comparison results are inconsistent, the connections in the connection pool are reconstructed based on the network addresses of the primary and backup nodes in the node metadata.

[0040] Fifthly, this application also provides a computer program product, including a computer program that, when executed by a processor, performs the following steps:

[0041] Send node metadata query requests to the database cluster management platform;

[0042] The system receives the node metadata of the current database cluster returned by the management platform in response to the node metadata query request. The node metadata includes the network address of the primary database node and the network address of the backup database node in the database cluster. The primary database node is used to provide data read and write services, and the backup database node is used to back up the data of the primary database node.

[0043] Obtain the network addresses corresponding to the connections already created in the current connection pool, including primary database connections and backup database connections;

[0044] The network address of the primary database node in the node metadata is compared with the network address corresponding to the primary database connection. The network address of the backup database node in the node metadata is also compared with the network address corresponding to the backup database connection.

[0045] If the comparison results are inconsistent, the connections in the connection pool are reconstructed based on the network addresses of the primary and backup nodes in the node metadata.

[0046] The aforementioned database connection reconstruction method, apparatus, computer equipment, computer-readable storage medium, and computer program product send a node metadata query request to the database cluster management platform, and receive the node metadata of the current database cluster returned by the management platform in response to the node metadata query request. The node metadata includes the network addresses of the primary database node and the standby database node in the database cluster. The primary database node is used to provide data read and write services, and the standby database node is used to back up data from the primary database node. The method also obtains the network addresses corresponding to the connections already created in the current connection pool, including primary database connections and standby database connections. The method compares the consistency of the network addresses of the primary database node and the corresponding network addresses of the primary database connections in the node metadata, and compares the consistency of the network addresses of the standby database nodes and the corresponding network addresses of the standby database connections in the node metadata. If the comparison results are inconsistent, the method reconstructs the connections in the connection pool based on the network addresses of the primary database node and the standby database node in the node metadata.

[0047] By directly interacting with the database cluster management platform to obtain the node metadata of the database cluster, and comparing the obtained node metadata with the network address corresponding to the connection in the connection pool, it is possible to proactively discover failed connections and rebuild valid connections. The rapid rebuilding of failed connections enables the database to quickly restore the relevant business on the application during routine maintenance or unexpected failures. Attached Figure Description

[0048] To more clearly illustrate the technical solutions in the embodiments of this application or related technologies, the drawings used in the description of the embodiments of this application or related technologies will be briefly introduced below. Obviously, the drawings described below are only some embodiments of this application. For those skilled in the art, other related drawings can be obtained based on these drawings without creative effort.

[0049] Figure 1 This is an application environment diagram of a database connection reconstruction method in one embodiment;

[0050] Figure 2 A schematic diagram of the framework for providing business connections to the database for related technologies;

[0051] Figure 3 This is a flowchart illustrating a database connection reconstruction method in one embodiment;

[0052] Figure 4 This is a schematic diagram of the framework for connecting services to the database in one embodiment;

[0053] Figure 5 This is a flowchart illustrating the database connection reconstruction method in a detailed embodiment;

[0054] Figure 6 This is a detailed framework diagram illustrating the connection between a service and a database in one embodiment.

[0055] Figure 7 This is a schematic diagram of the workflow of the periodic check process in one embodiment;

[0056] Figure 8 This is a structural block diagram of a database connection reconstruction device in one embodiment;

[0057] Figure 9 This is an internal structural diagram of a computer device in one embodiment;

[0058] Figure 10 This is a diagram of the internal structure of a computer device in another embodiment. Detailed Implementation

[0059] To make the objectives, technical solutions, and advantages of this application clearer, the following detailed description is provided in conjunction with the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are merely illustrative and not intended to limit the scope of this application.

[0060] The following explanations are provided regarding some concepts involved in the embodiments of this application:

[0061] A database cluster consists of at least two or more database servers that form a virtual single logical database image, providing transparent data services to applications (clients).

[0062] Node metadata describes the information of each node in a database cluster, including the node's role type and corresponding network address. Role types include primary and standby nodes. The primary node provides data read and write services, while the standby node performs data backups for the primary node. Primary and standby nodes have different data permissions; the primary node provides read and / or write services, while the standby node typically only provides read services.

[0063] A database connection pool is a container for storing database connections. It manages and reuses connection resources, conserves resources, avoids frequent connection creation and destruction, improves user database access efficiency, and reduces waiting time. A connection pool is formed when a program starts by establishing a sufficient number of database connections and grouping them into a pool. The program dynamically requests, uses, and releases connections from the pool. Connections in the pool have different state attributes: idle, occupied, and discarded.

[0064] A Data Access Object (DAO) is a design pattern used to separate data access logic from business logic in an application. It provides an abstract interface for accessing the database, freeing the business logic layer from directly handling the details of underlying data storage, thereby improving code maintainability and scalability.

[0065] The database connection reconstruction method provided in this application embodiment can be applied to, for example... Figure 1 In the application environment shown, terminal 102 communicates with the management platform 104 of database cluster 106 via a network, and management platform 104 communicates with database cluster 106 via a network.

[0066] In some embodiments, the database connection reconstruction method provided in this application can be executed by terminal 102. In some embodiments, the database connection reconstruction apparatus provided in this application can be configured in terminal 102. In some embodiments, a connection management tool (also known as a connection management SDK, where SDK is an abbreviation for Software Development Kit) runs on terminal 102, and the connection management SDK implements the database connection reconstruction method provided in this application at runtime. In some embodiments, the database connection reconstruction apparatus provided in this application may include the connection management tool.

[0067] It is understood that in some embodiments, when the server has a need to connect to the database cluster, the database connection reconstruction method provided in this application embodiment can also be executed by the server, and the database connection reconstruction device provided in this application embodiment can be configured in the server.

[0068] In some embodiments, the connection management tool running on terminal 102 queries the node metadata of the database cluster 106 from the management platform 104 of the database cluster 106. The node metadata includes the network addresses of the primary database node and the standby database node in the database cluster 106. The primary database node is used to provide data read and write services, and the standby database node is used to back up the data of the primary database node. The connection management tool running on terminal 102 obtains the network addresses corresponding to the connections already created in the current connection pool. The created connections include primary database connections and standby database connections. The connection management tool running on terminal 102 performs a consistency comparison between the network address of the primary database node in the node metadata and the network address corresponding to the primary database connection, and performs a consistency comparison between the network address of the standby database node in the node metadata and the network address corresponding to the standby database connection. If the comparison results are inconsistent, the connection in the connection pool is reconstructed based on the network addresses of the primary database node and the standby database node in the node metadata.

[0069] In some embodiments, after an application running on terminal 102 submits a database operation request carrying a query statement, the Data Access Object (DAO) calls a connection management tool to obtain a database connection based on the submitted database operation request. Specifically, a connection acquisition request can be sent to the connection management tool. In response to the connection acquisition request, the connection management tool acquires an idle connection and returns the idle connection to the Data Access Object, so that the Data Access Object can pass the query statement to the database cluster 106 through the acquired connection and receive the execution result returned by the database cluster 106 after executing the query statement.

[0070] In some embodiments, the connection management tool running on terminal 102 can proactively obtain node metadata about database cluster 106 from the database cluster management platform 104. For example, the connection management tool running on terminal 102 can periodically and proactively query the database cluster 106 management platform 104 for node metadata about database cluster 106, and the database cluster 106 management platform 104 returns the latest node metadata to the connection management tool running on terminal 102. For example, after a planned primary / standby node switchover in database cluster 106, the management platform 104 will obtain the current node metadata of database cluster 106, i.e., the latest node role information: which nodes(s) are primary database nodes and which nodes are standby database nodes. At the same time, the management platform 104 will obtain the network addresses of the primary database node and the standby database node in the current database cluster 106. Here, a planned primary / standby node switchover refers to proactively switching a standby database node to a primary database node and switching the original primary database node to a standby database node at a foreseeable and planned time.

[0071] In some embodiments, terminal 102 may be, but is not limited to, various personal computers, laptops, smartphones, tablets, IoT devices, and portable wearable devices. IoT devices may include smart speakers, smart TVs, smart air conditioners, smart in-vehicle devices, projection devices, etc. Portable wearable devices may include smartwatches, smart bracelets, head-mounted displays, etc. Head-mounted displays may include virtual reality (VR) devices, augmented reality (AR) devices, smart glasses, etc. Management platform 104 may be a standalone physical server, a server cluster or distributed system composed of multiple physical servers, or a cloud server providing cloud computing services.

[0072] In some embodiments, the database cluster 106 may periodically report node metadata to the management platform 104. The database cluster 106 may be a MySQL cluster, and the management platform 104 of the database cluster 106 may be a MySQL high-availability management platform.

[0073] Figure 2 A schematic diagram illustrating the framework for connecting business applications to a database using related technologies. (Refer to...) Figure 2 The architecture diagram includes a pre-packaged Data Access Interface Object (DAO), a configuration center, a database cluster management platform, and the database cluster itself.

[0074] Reference Figure 2The front-end business obtains a connection through the DAO, executes database query statements based on the obtained connection, obtains the execution results, and returns the execution results to the process that initiated the database operation request for further processing.

[0075] Reference Figure 2 The DAO is used to create and manage connections, obtain node metadata of the database cluster from the configuration center, create new connections based on the node metadata of the database cluster, and return idle connections to the front-end business in response to connection acquisition requests initiated by the front-end business (referring to applications that can implement certain business functions).

[0076] Reference Figure 2 The configuration center is used to receive node metadata proactively reported by the management platform when node metadata changes. The configuration center is also used to periodically query node metadata from the management platform, store node metadata obtained or queried from the management platform, and provide node metadata query functionality to external programs through a general interface.

[0077] Reference Figure 2 The database cluster management platform is used to acquire and store the node metadata of the database cluster. The management platform is also used to manage information such as the role and liveness status of each node in the database cluster, and to report this information to the configuration center.

[0078] exist Figure 2In the architecture shown, when the master node in the database cluster fails, a master-slave switch is required. Node S1 is switched to become the master node, and nodes S2 and the original master node M become the new slave nodes. Node permissions are updated; the original master nodes M and S2 only have read permissions, while node S1 has read and write permissions. At this time, the management platform reports the new node metadata to the configuration center, and the configuration center updates and stores the new node metadata. However, since connection management and creation are implemented through the DAO, if the DAO fails to detect when the node metadata stored in the configuration center has changed, and does not actively query and retrieve the new node metadata from the configuration center, the primary database connection in the connection pool currently maintained by the DAO is still established on the original primary database node M, created based on the network address of the original primary database node M. Since the original primary database node M is still "alive," subsequent database write and update requests will be passed to the original primary database node M for execution. The original primary database node M no longer has write permissions, resulting in an error; clearly, the connection is now invalid. To restore the response to database operation requests, the only solution is to restart the service or use other methods to force the DAO to query the new node metadata from the configuration center, create a new connection based on the new metadata, and then pass the database operation requests to the database cluster through the new connection. Obviously, creating a new connection at this point is very time-consuming, leading to low recovery efficiency for related business processes in the application, reduced business availability, and difficulty in meeting scenarios with high availability requirements.

[0079] exist Figure 2 In the architecture shown, when the standby node in the database cluster is under maintenance or has been taken offline and no longer belongs to the database cluster, the data in the standby node may be far behind that of the primary node. Even if the connection corresponding to the standby node is still available, the data read from the standby node may be old data, which is not as expected and will reduce business availability.

[0080] The database connection reconstruction method provided in this application embodiment interacts directly with the database cluster management platform to obtain the node metadata of the database cluster. By comparing the obtained node metadata with the network address corresponding to the connection in the connection pool, it can proactively discover failed connections and rebuild valid connections. The rapid reconstruction of failed connections enables the database to quickly restore relevant business on the application during routine maintenance or unexpected failures.

[0081] In one exemplary embodiment, such as Figure 3 As shown, a method for rebuilding a database connection is provided, which can be applied to... Figure 1The following steps are used as an example of computer equipment (e.g., terminal 102), including steps 302 to 310. Wherein:

[0082] Step 302: Send a node metadata query request to the database cluster management platform.

[0083] Step 304: Receive the node metadata of the current database cluster returned by the management platform in response to the node metadata query request. The node metadata includes the network address of the primary database node and the network address of the standby database node in the database cluster. The primary database node is used to provide data read and write services, and the standby database node is used to back up the data of the primary database node.

[0084] A database cluster comprises at least two or more database servers, which together form a virtual, single logical database image, providing transparent data services to applications (clients). Node metadata describes each node in the database cluster, including its role type and corresponding network address. Role types include primary and standby nodes. The primary node provides data read and write services, while the standby node performs data backups for the primary node. Primary and standby nodes have different data permissions; the primary node provides read and / or write services, while the standby node typically only provides read services. For example, the node metadata for a database cluster might be:

[0085] {

[0086] Database cluster name: test01

[0087] Port number: 3306

[0088] Master node: 192.168.xxx.1

[0089] Backup nodes: 192.168.xxx.2, 192.168.xxx.3, 192.168.xxx.4

[0090] ...

[0091] }

[0092] In some embodiments, a connection management tool running on a computer device can implement the connection reconstruction method provided in this application embodiment. Specifically, the connection management tool can periodically send node metadata query requests to the database cluster management platform, directly querying the current node metadata of the database cluster from the database cluster management platform. For example, it can query the current node metadata of the database cluster directly from the database cluster management platform every 5 seconds to perform a check and reconstruction of a failed connection. After the check is completed, it waits another 5 seconds before performing the next wake-up check.

[0093] In this embodiment, a new general connection management tool is added to manage the connection pool, eliminating the intermediate configuration center. The connection management tool can directly obtain the node metadata of the database cluster from the management platform and create connections, enabling rapid reconstruction of failed database connections.

[0094] Step 306: Obtain the network address corresponding to the connection already created in the current connection pool. The created connection includes the primary database connection and the backup database connection.

[0095] A database connection pool is a container for storing database connections. It manages and reuses connection resources, conserves resources, avoids frequent connection creation and destruction, improves user database access efficiency, and reduces waiting time. A connection pool is formed when a program starts by establishing a sufficient number of database connections and grouping them into a pool. The program dynamically requests, uses, and releases connections from the pool. Connections in the pool have different state attributes: idle, occupied, and discarded.

[0096] During initialization, a computer device can create a connection pool based on the database type, connection pool configuration parameters, and database file path. Each database node's host number and port number (corresponding to a network address) can represent a connection. Depending on the database node's role, the connections already created in the current connection pool can be categorized as primary database connections and secondary database connections. Therefore, when a failed connection check is needed, the computer device can obtain the network addresses corresponding to the connections already created in the current connection pool, including both primary and secondary database connections.

[0097] In some embodiments, the connection pool is managed by a connection management tool running on a computer device. Therefore, when the computer device needs to check and rebuild failed connections, it can directly obtain the network addresses corresponding to the connections created in the current connection pool, namely the primary database connection and the backup database connection.

[0098] Step 308: Perform a consistency comparison between the network address of the primary database node in the node metadata and the network address corresponding to the primary database connection, and perform a consistency comparison between the network address of the standby database node in the node metadata and the network address corresponding to the standby database connection.

[0099] Specifically, after obtaining the network address of the master node and the network address corresponding to the master connection in the connection pool from the current node metadata, a consistency comparison is performed between the network address of the current master node and the network address corresponding to the master connection in the connection pool.

[0100] Step 310: If the comparison results are inconsistent, rebuild the connection in the connection pool based on the network addresses of the primary database node and the standby database node in the node's metadata.

[0101] If the comparison results are inconsistent, it indicates that the primary database connection in the connection pool is invalid and needs to be rebuilt. Similarly, after obtaining the network address of the standby database node and the corresponding network address of the standby database connection in the connection pool from the current node metadata, the computer device can perform a consistency comparison between the network address of the standby database node in the node metadata and the network address corresponding to the standby database connection. If the comparison results are inconsistent, it indicates that the standby database connection in the connection pool is invalid and also needs to be rebuilt.

[0102] The aforementioned database connection reconstruction method directly obtains the node metadata of the database cluster from the management platform and directly manages the connection pool. This enables rapid detection and reconstruction of failed database connections. Specifically, by interacting directly with the database cluster management platform, the latest node metadata of the database cluster can be obtained after the database cluster completes a primary / standby node swap or performs process maintenance on some nodes. By comparing the obtained node metadata with the network addresses corresponding to the connections in the connection pool, failed connections can be proactively detected and valid connections rebuilt in a timely manner. This rapid reconstruction of failed connections allows the database to quickly restore relevant business operations on the application during routine maintenance or unexpected failures.

[0103] In one exemplary embodiment, such as Figure 4 The diagram illustrates a framework for connecting a business application to a database. (Refer to...) Figure 4 The architecture diagram includes a pre-packaged Data Interface Access Object (DAO), a database cluster management platform, and the database cluster itself. The DAO obtains node metadata from the database cluster management platform directly through a connection management tool (hereinafter referred to as the Connection Management SDK) and manages the connection pool. (Refer to...) Figure 4 The front-end business logic obtains connections through the DAO and executes database queries based on these connections. The DAO calls the connection management SDK to obtain connections. The connection management SDK is used for connection creation and management, creating connection pools based on configuration parameters and the latest node metadata. It also periodically sends node metadata query requests to the database cluster management platform to retrieve node metadata. Furthermore, a background thread checks if the periodically retrieved node metadata matches the network address corresponding to the current connection in the connection pool, enabling connection checks and reconstruction. The database cluster management platform manages information such as the roles and liveness status of each node in the database cluster, which the connection management SDK can then query. Figure 2 Compared to the previous framework diagram, a new connection management SDK has been added to manage the connection pool, and the intermediate configuration center has been removed. The connection management SDK directly obtains the node metadata of the database cluster from the management platform, thereby achieving efficient management of the connection pool.

[0104] In some embodiments, the method further includes: receiving a connection acquisition request, the connection acquisition request being submitted by a data access interface object after receiving a database operation request initiated by an application, the database operation request carrying a query statement; responding to the connection acquisition request, returning an idle connection to the data access interface object, so that the data access interface object can pass the query statement to the database cluster through the acquired connection, and receive the execution result returned by the database cluster after executing the query statement.

[0105] A Data Access Object (DAO) is a design pattern used to separate data access logic from business logic in an application. It provides an abstract interface for accessing a database, freeing the business logic layer from directly handling the details of underlying data storage, thus improving code maintainability and scalability. For example, in an application that needs to read and write information from a database, the DAO pattern can create a Data Access Object that encapsulates all database interaction operations (such as querying, inserting, and updating data). The application's business logic only needs to call the methods of this Data Access Object without needing to worry about the specific database type (relational or non-relational), connection method, or the details of writing SQL statements (Structured Query Language). In this embodiment, a connection management SDK is integrated into the Data Access Object. The SDK obtains a connection to the database cluster and executes SQL statements through this connection.

[0106] In an exemplary embodiment, after receiving a database operation request initiated by an application, the data access interface object on the computer device requests a database connection from the connection management SDK, that is, submits a connection acquisition request to the connection management tool. In response to the connection acquisition request, the connection management SDK queries the status attributes of each connection in the connection pool and returns an idle connection to the data access interface object, so that the data access interface object can pass the query statement to the database cluster through the acquired connection and receive the execution result returned by the database cluster after executing the query statement.

[0107] In an exemplary embodiment, the connection management SDK responds to the connection acquisition request by retrieving an idle connection from the idle connection queue of the connection pool and returning the idle connection to the data access interface object.

[0108] In an exemplary embodiment, after receiving a database operation request initiated by an application, the data access interface object on the computer device determines the data operation type based on the query statement carried in the database operation request. Data operation types include read operations and write operations. Based on the data operation type, it requests a connection corresponding to that data operation type from the connection management SDK. In response to the connection acquisition request, the connection management SDK returns an idle connection corresponding to that data operation type to the data access interface object. For example, when the data operation type is a read operation, a backup database connection or a primary database connection can be requested from the connection management SDK; when the data operation type is a write operation, a primary database connection can be requested from the connection management SDK.

[0109] In this embodiment, when actively discovering failed connections and reconstructing valid connections, once a database operation request initiated by the application is received, a valid connection in an idle state can be obtained from the connection pool and returned to the data access interface object. This enables timely response to database operation requests and ensures the smooth operation of related services on the application.

[0110] In some embodiments, the connection that returns an idle state to the data access interface object in response to the connection acquisition request includes: querying the status attributes of each connection in the current connection pool in response to the connection acquisition request, the status attributes including idle state, occupied state, and abandoned state; if there is an idle connection in the current connection pool, returning an idle target connection to the data access interface object and updating the status attribute of the target connection to occupied state.

[0111] In this embodiment, by accurately maintaining the state attributes of each connection in the connection pool, it is ensured that a valid connection in an idle state can be obtained from the connection pool, and database operation requests can be responded to in a timely manner, thus ensuring the smooth operation of related services on the application.

[0112] In some embodiments, the method further includes: upon receiving a connection playback notification about the target connection sent by the data access interface object, updating the status attribute of the target connection to an idle state.

[0113] In this embodiment, after a connection is used, it is not closed, but is returned to the connection pool for future use. The reasonable allocation and release of connections can improve connection reuse, reduce the overhead of establishing new connections, and also speed up access.

[0114] In some embodiments, the method further includes: sending a waiting connection release notification to the data access interface object when there are no idle connections in the current connection pool and the total number of connections in the connection pool reaches a set upper limit.

[0115] In some embodiments, the method further includes: if the total number of connections in the current connection pool has not reached a set upper limit, creating a new connection according to the configuration parameters of the connection pool, and adding the created connection to an idle connection queue, which is used to store idle connections.

[0116] Specifically, the total number of connections in the connection pool can be scanned in real time. Once it is found that the total number of connections in the connection pool is less than the upper limit set in the configuration parameters of the connection pool, a new connection is created and added to the idle connection queue. This can ensure the stability of the connections in the connection pool. Subsequently, a valid connection can be returned to the data access interface object in a timely manner, saving connection creation time.

[0117] In some embodiments, if the comparison results are inconsistent, the status attribute of the connection already created in the current connection pool is modified to obsolete. In an exemplary embodiment, after modifying the status attribute of the connection already created in the current connection pool to obsolete, it is also necessary to check whether the status attribute of the connection already created in the current connection pool is idle. If it is idle, it can be directly recycled, modified to obsolete, and removed from the connection pool. If it is not idle, it is necessary to wait for the connection to complete its current task before recycling it.

[0118] In some embodiments, rebuilding the connection in the connection pool based on the network addresses of the primary and backup nodes in the node metadata includes: modifying the status attribute of the connection already created in the current connection pool to an abandoned state; calling a connection creation function to create a new primary connection based on the network address of the primary node in the node metadata; calling a connection creation function to create a new backup connection based on the network address of the backup node in the node metadata; and adding the newly created primary and backup connections to the connection pool.

[0119] Specifically, if the comparison results are inconsistent, the connection in the current connection pool can be considered an invalid connection and recycled. After that, the computer device needs to add a new valid connection to the connection pool. Based on the network address of the primary database node in the node's metadata, the connection creation function is called to create a new primary database connection. Based on the network address of the standby database node in the node's metadata, the connection creation function is called to create a new standby database connection. The newly created primary database connection and standby database connection are then added to the connection pool.

[0120] In some embodiments, querying the node metadata of the current database cluster from the database cluster management platform includes: querying the node metadata of the current database cluster from the database cluster management platform at set intervals, wherein the node metadata of the current database cluster is updated after the database cluster performs a primary / standby node switchover.

[0121] In this embodiment, in order to ensure that when the node role of the dataset cluster changes or a node fails, the failed connection in the connection pool can be detected in time and the connection can be rebuilt in time, so as to ensure that the database can quickly restore business during routine maintenance or unexpected failures.

[0122] In a detailed embodiment, such as Figure 5 The diagram shows a flowchart of a method for rebuilding a database connection. This method can be executed by a computer device, see reference [link to relevant documentation]. Figure 5 It includes the following steps:

[0123] Step 502: At set intervals, send a node metadata query request to the database cluster management platform and receive the current node metadata of the database cluster returned by the management platform in response to the node metadata query request.

[0124] The node metadata includes the network addresses of the primary and standby nodes in the database cluster. The primary node provides data read and write services, while the standby node performs data backups on the primary node.

[0125] Specifically, computer devices can periodically query the node metadata of the database cluster directly from the database cluster management platform. For example, they can query the node metadata of the database cluster directly from the database cluster management platform every 5 seconds to check and rebuild failed connections. After the check is completed, they wait another 5 seconds before performing the next wake-up check.

[0126] Step 504: Obtain the network addresses corresponding to the connections already created in the current connection pool. These created connections include primary database connections and standby database connections.

[0127] Specifically, when it is necessary to check and rebuild failed connections, computer devices can directly obtain the network addresses corresponding to the connections created in the current connection pool, namely the primary database connection and the standby database connection, through the connection management tool.

[0128] Step 506: Perform a consistency comparison between the network address of the primary database node in the node metadata and the network address corresponding to the primary database connection, and perform a consistency comparison between the network address of the standby database node in the node metadata and the network address corresponding to the standby database connection.

[0129] Specifically, after obtaining the network address of the primary database node and the corresponding network address of the primary database connection in the connection pool from the current node metadata, a consistency comparison is performed between the network address of the current primary database node and the corresponding network address of the primary database connection in the connection pool. If the comparison result is inconsistent, it indicates that the primary database connection in the connection pool is a failed connection and needs to be rebuilt. Similarly, after obtaining the network address of the standby database node and the corresponding network address of the standby database connection in the connection pool from the current node metadata, the computer device can perform a consistency comparison between the network address of the standby database node in the node metadata and the corresponding network address of the standby database connection. If the comparison result is inconsistent, it indicates that the standby database connection in the connection pool is a failed connection and also needs to be rebuilt.

[0130] Step 508: If the comparison results are inconsistent, modify the status attribute of the connection already created in the current connection pool to the obsolete state.

[0131] Specifically, if the comparison results are inconsistent, the computer device will modify the status attribute of the connection already created in the current connection pool to the obsolete state.

[0132] Step 510: Based on the network address of the primary database node in the node's metadata, call the connection creation function to create a new primary database connection; based on the network address of the standby database node in the node's metadata, call the connection creation function to create a new standby database connection; and add the newly created primary database connection and standby database connection to the connection pool.

[0133] Specifically, if the comparison results are inconsistent, the connections in the current connection pool can be considered invalid connections and recycled. After that, the computer device needs to add new valid connections to the connection pool. Based on the network address of the primary database node in the node's metadata, the connection creation function is called to create a new primary database connection. Based on the network address of the standby database node in the node's metadata, the connection creation function is called to create a new standby database connection. The newly created primary database connection and standby database connection are then added to the connection pool.

[0134] Step 512: If the total number of connections in the current connection pool has not reached the set upper limit, create a new connection according to the configuration parameters of the connection pool and add the created connection to the idle connection queue, which is used to store idle connections.

[0135] Specifically, the computer device can scan the total number of connections in the connection pool in real time. Once it finds that the total number of connections in the connection pool is less than the upper limit set in the configuration parameters of the connection pool, a new connection is created and added to the idle connection queue. This can ensure the stability of the connections in the connection pool. Subsequently, a valid connection can be returned to the data access interface object in a timely manner, saving connection creation time.

[0136] Step 514: Receive a connection acquisition request. This connection acquisition request is submitted by the data access interface object after receiving a database operation request initiated by the application. The database operation request carries a query statement.

[0137] Specifically, after receiving a database operation request initiated by the application, the data access interface object on the computer device requests a database connection from the connection management SDK, that is, submits a connection acquisition request to the connection management SDK.

[0138] Step 516: In response to the connection acquisition request, query the status attributes of each connection in the current connection pool. The status attributes include idle status, occupied status, and abandoned status.

[0139] Specifically, in response to the connection acquisition request, the connection management SDK queries the status attributes of each connection in the connection pool, returns an idle connection to the data access interface object, so that the data access interface object can pass the query statement to the database cluster through the acquired connection, and receive the execution result returned by the database cluster after executing the query statement.

[0140] Step 518: If there is an idle connection in the current connection pool, return the idle target connection to the data access interface object and update the status attribute of the target connection to occupied status.

[0141] Step 520: If there are no idle connections in the current connection pool and the total number of connections in the connection pool has reached the set upper limit, send a waiting connection release notification to the data access interface object.

[0142] Step 522: Based on the data access interface object, the query statement is passed to the database cluster through the obtained connection, and the execution result returned by the database cluster after executing the query statement is received.

[0143] In one exemplary embodiment, such as Figure 6 The diagram illustrates a framework for connecting a business application to a database. Within this framework, a database operation request processing flow can be implemented. In this flow, the database connection reconstruction method provided in this embodiment can be used to manage the connection pool. The database operation request processing flow includes:

[0144] 1. When a front-end user clicks a button or submits a form on the application interface, the application's back-end constructs the corresponding SQL query statement or other database query statement based on the relevant business logic and initiates a database operation request.

[0145] 2. The application's backend submits the above SQL query statement or other database query statement to the data access interface object, which then interacts with the database and returns the execution result to the application's backend.

[0146] 3. The data access interface object calls the embedded connection management SDK and requests an idle target connection from the connection pool through the connection acquisition function.

[0147] 4. The connection management SDK obtains an idle target connection from the connection pool. If no idle connection is available, a new connection needs to be created, and the SDK will eventually return an idle target connection or throw an exception.

[0148] 5. When creating a connection, if the number of connections has not reached the limit, a connection to the database is created. After successful creation, the database connection is returned. If the limit is reached or there is another exception in the connection, an exception is thrown to the data access interface object.

[0149] 6. After the data access interface object obtains an idle target connection, it passes the SQL query statement or other database query statement to the database cluster through the target connection, receives the execution result returned by the database cluster after executing the query statement, and returns the execution result to the application's backend. If the execution fails, it also returns a formatted error message to the application's backend for further processing, such as retrying based on the error message or directly returning a request failure message to the application's frontend.

[0150] Reference Figure 6 An embedded periodic check process is used in the connection management SDK. At set intervals, it checks the network address corresponding to each connection in the connection pool against the node metadata of the database cluster to see if they match. If they don't match, the current connection in the connection pool is invalid and needs to be destroyed and rebuilt. If they match, it waits for the next wake-up call to perform the comparison again.

[0151] In one exemplary embodiment, such as Figure 7 The diagram shown illustrates the workflow of the periodic check process in some embodiments. (Refer to...) Figure 7 It includes the following steps:

[0152] 1. The process starts after the data access interface object is initialized. It performs a check operation at set intervals using a loop function. After the check is completed, it continues to sleep for the set time and waits for the next wake-up to perform the check again.

[0153] 2. This process obtains the node metadata of the database cluster to which the current data source belongs, as well as the network address to which each connection in the connection pool is connected, including the network address corresponding to the primary database connection and the network address corresponding to the standby database connection.

[0154] 3. This process compares the network address of the primary database node in the node's metadata with the network address corresponding to the primary database connection, and then compares the network address of the standby database node in the node's metadata with the network address corresponding to the standby database connection. If they match, no action is required; otherwise, the connections in the connection pool need to be destroyed and rebuilt. This process will modify the status attribute of the connections already created in the current connection pool to the obsolete state.

[0155] 4. This process will reclaim abandoned connections. For non-idle connections that have been marked as abandoned, reclamation will be initiated after the connection has completed its current task. For idle connections that have been marked as abandoned, they can be reclaimed directly.

[0156] 5. Since the failed connections were destroyed as described above, the process adds new connections to the connection pool. This means that after calling the function to destroy a connection, it continues to call the connection creation function to replenish the connection pool. It also scans the connection pool size, and if it finds that the number of connections in the pool is less than the minimum (or maximum) number configured for the connection pool, it will automatically create new connections.

[0157] Using the database connection reconstruction method described above, when a database node is switched or unexpectedly crashes and the high availability management platform completes the switchover, all failed connections can be reconstructed in a short time, thereby greatly reducing the switching time and quickly restoring business access.

[0158] In some embodiments, a connection reconstruction system is also provided. The system includes a terminal, a database cluster, and a management platform for the database cluster, wherein an application runs on the terminal, and the application's backend encapsulates a data access interface object and connection management tools.

[0159] Among them, the data access interface object is used to call the connection management tool to obtain an idle connection, pass the query statement to the database cluster through the obtained connection, and receive the execution result returned by the database cluster after executing the query statement;

[0160] Among them, the connection management tool is used to query the node metadata of the current database cluster from the database cluster management platform. The node metadata includes the network address of the primary database node and the network address of the standby database node in the database cluster.

[0161] The connection management tool is also used to obtain the network addresses corresponding to the connections already created in the current connection pool. The created connections include primary database connections and standby database connections.

[0162] The connection management tool is also used to compare the network address of the primary database node in the node metadata with the network address corresponding to the primary database connection, and to compare the network address of the standby database node in the node metadata with the network address corresponding to the standby database connection. If the comparison results are inconsistent, the connection in the connection pool is rebuilt based on the network address of the primary database node and the network address of the standby database node in the node metadata.

[0163] The database cluster management platform is used to obtain the latest node metadata from the database cluster, while the connection management tool is also used to actively obtain the latest node metadata from the management platform.

[0164] In some embodiments, the connection management tool is also used to modify the status attribute of the connection already created in the current connection pool to the obsolete state in the case of inconsistency; to call the connection creation function to create a new primary database connection based on the network address of the primary database node in the node metadata, and to call the connection creation function to create a new standby database connection based on the network address of the standby database node in the node metadata, and to supplement the connection pool with the newly created primary database connection and standby database connection.

[0165] It should be understood that although the steps in the flowcharts of the above embodiments are shown sequentially according to the arrows, these steps are not necessarily executed in the order indicated by the arrows. Unless explicitly stated herein, there is no strict order restriction on the execution of these steps, and they can be executed in other orders. Moreover, at least some steps in the flowcharts of the above embodiments may include multiple steps or multiple stages. These steps or stages are not necessarily completed at the same time, but can be executed at different times. The execution order of these steps or stages is not necessarily sequential, but can be performed alternately or in turn with other steps or at least some of the steps or stages of other steps.

[0166] Based on the same inventive concept, this application also provides a database connection reconstruction apparatus for implementing the database connection reconstruction method described above. The solution provided by this apparatus is similar to the implementation described in the above method; therefore, the specific limitations in one or more database connection reconstruction apparatus embodiments provided below can be found in the limitations of the database connection reconstruction method described above, and will not be repeated here.

[0167] In one exemplary embodiment, such as Figure 8 As shown, a database connection reconstruction device 800 is provided, including: a node metadata acquisition module 802, a connection acquisition module 804, a comparison module 806, and a reconstruction module 808, wherein:

[0168] The node metadata acquisition module 802 is used to send a node metadata query request to the management platform of the database cluster and receive the node metadata of the current database cluster returned by the management platform in response to the node metadata query request. The node metadata includes the network address of the primary database node and the network address of the standby database node in the database cluster. The primary database node is used to provide data read and write services, and the standby database node is used to back up the data of the primary database node.

[0169] The connection acquisition module 804 is used to acquire the network addresses corresponding to the connections already created in the current connection pool. These created connections include primary database connections and standby database connections.

[0170] The comparison module 806 is used to compare the network address of the primary database node in the node metadata with the network address corresponding to the primary database connection, and to compare the network address of the standby database node in the node metadata with the network address corresponding to the standby database connection.

[0171] Reconstruction module 808 is used to reconstruct the connections in the connection pool based on the network addresses of the primary and backup nodes in the node's metadata when the comparison results are inconsistent.

[0172] In some embodiments, the database connection rebuilding apparatus 800 further includes:

[0173] The receiving module is used to receive connection acquisition requests. These requests are submitted by the data access interface object after receiving a database operation request initiated by the application. The database operation request carries a query statement.

[0174] The connection return module is used to respond to the connection acquisition request by returning an idle connection to the data access interface object, so that the data access interface object can pass the query statement to the database cluster through the acquired connection and receive the execution result returned by the database cluster after executing the query statement.

[0175] In some embodiments, the connection return module is further configured to, in response to the connection acquisition request, query the status attributes of each connection in the current connection pool, the status attributes including idle status, occupied status and abandoned status; if there is an idle connection in the current connection pool, return the idle target connection to the data access interface object, and update the status attribute of the target connection to occupied status.

[0176] In some embodiments, the database connection rebuilding apparatus 800 further includes:

[0177] The connection creation module is used to update the status attribute of the target connection to idle state when a connection playback notification about the target connection is received from the data access interface object.

[0178] In some embodiments, the connection return module is further configured to send a waiting connection release notification to the data access interface object when there are no idle connections in the current connection pool and the total number of connections in the connection pool reaches a set upper limit.

[0179] In some embodiments, the database connection rebuilding apparatus 800 further includes:

[0180] The connection creation module is used to create new connections based on the configuration parameters of the connection pool when the total number of connections in the current connection pool has not reached the set upper limit. The created connections are then added to the idle connection queue, which is used to store idle connections.

[0181] In some embodiments, the comparison module 806 is further configured to modify the status attribute of the connection already created in the current connection pool to an abandoned state;

[0182] The reconstruction module 808 is also used to call the connection creation function to create a new primary database connection based on the network address of the primary database node in the node metadata, and to call the connection creation function to create a new standby database connection based on the network address of the standby database node in the node metadata, and to add the newly created primary database connection and standby database connection to the connection pool.

[0183] In some embodiments, the node metadata acquisition module 802 is further configured to query the current node metadata of the database cluster from the database cluster management platform at set intervals, wherein the current node metadata of the database cluster is updated after the database cluster performs a primary / backup node switch.

[0184] The aforementioned database connection reconstruction device 800 sends a node metadata query request to the database cluster management platform and receives the current database cluster node metadata returned by the management platform in response to the query request. The node metadata includes the network addresses of the primary and standby nodes in the database cluster. The primary node provides data read / write services, and the standby node performs data backup for the primary node. It then obtains the network addresses corresponding to the connections already created in the current connection pool, including primary and standby connections. The device performs a consistency comparison between the network addresses of the primary and standby nodes in the node metadata and their corresponding network addresses. If the comparison results are inconsistent, the device reconstructs the connections in the connection pool based on the network addresses of the primary and standby nodes in the node metadata. By directly interacting with the database cluster management platform to obtain the database cluster node metadata and comparing it with the network addresses corresponding to the connections in the connection pool, it can proactively discover failed connections and rebuild valid connections. This rapid reconstruction of failed connections enables the database to quickly restore relevant business operations on the application during routine maintenance or unexpected failures.

[0185] Each module in the aforementioned database connection reconstruction device 800 can be implemented entirely or partially through software, hardware, or a combination thereof. These modules can be embedded in or independent of the processor in a computer device, or stored in the memory of a computer device as software, so that the processor can call and execute the operations corresponding to each module.

[0186] In one exemplary embodiment, a computer device is provided, which may be a server, and its internal structure diagram may be as follows: Figure 9 As shown, this computer device includes a processor, memory, input / output (I / O) interfaces, and a communication interface. The processor, memory, and I / O interfaces are connected via a system bus, and the communication interface is also connected to the system bus via the I / O interfaces. The processor provides computational and control capabilities. The memory includes non-volatile storage media and internal memory. The non-volatile storage media stores the operating system and computer programs. The internal memory provides the environment for the operation of the operating system and computer programs stored in the non-volatile storage media. The I / O interfaces are used for exchanging information between the processor and external devices. The communication interface is used for communicating with external terminals via a network connection. When the computer program is executed by the processor, it implements a database connection reconstruction method.

[0187] In one exemplary embodiment, a computer device is provided, which may be a terminal, and its internal structure diagram may be as follows: Figure 10 As shown, the computer device includes a processor, memory, input / output interfaces, a communication interface, a display unit, and an input device. The processor, memory, and input / output interfaces are connected via a system bus, and the communication interface, display unit, and input device are also connected to the system bus via the input / output interfaces. The processor provides computational and control capabilities. The memory includes non-volatile storage media and internal memory. The non-volatile storage media stores the operating system and computer programs. The internal memory provides an environment for the operation of the operating system and computer programs stored in the non-volatile storage media. The input / output interfaces are used for exchanging information between the processor and external devices. The communication interface is used for wired or wireless communication with external terminals; wireless communication can be achieved through Wi-Fi, mobile cellular networks, Near Field Communication (NFC), or other technologies. When executed by the processor, the computer program implements a method for rebuilding database connections.

[0188] Those skilled in the art will understand that Figure 10 The structure shown is merely a block diagram of a portion of the structure related to the present application and does not constitute a limitation on the computer device to which the present application is applied. Specific computer devices may include more or fewer components than those shown in the figure, or combine certain components, or have different component arrangements.

[0189] In one exemplary embodiment, a computer device is provided, including a memory and a processor, wherein the memory stores a computer program, and the processor executes the computer program to implement the steps of a method for rebuilding a database connection.

[0190] In one embodiment, a computer-readable storage medium is provided having a computer program stored thereon, which, when executed by a processor, implements the steps of a method for rebuilding a database connection.

[0191] In one embodiment, a computer program product is provided, including a computer program that, when executed by a processor, implements the steps of a method for rebuilding a database connection.

[0192] It should be noted that the user information (including but not limited to user device information, user personal information, etc.) and data (including but not limited to data used for analysis, data stored, data displayed, etc.) involved in this application are all information and data authorized by the user or fully authorized by all parties, and the collection, use and processing of the relevant data must comply with relevant regulations.

[0193] Those skilled in the art will understand that all or part of the processes in the methods of the above embodiments can be implemented by a computer program instructing related hardware. The computer program can be stored in a non-volatile computer-readable storage medium, and when executed, it can include the processes of the embodiments of the above methods. Any references to memory, databases, or other media used in the embodiments provided in this application can include at least one of non-volatile memory and volatile memory. Non-volatile memory can include read-only memory (ROM), magnetic tape, floppy disk, flash memory, optical memory, high-density embedded non-volatile memory, resistive random access memory (ReRAM), magnetic random access memory (MRAM), ferroelectric random access memory (FRAM), phase change memory (PCM), graphene memory, etc. Volatile memory can include random access memory (RAM) or external cache memory, etc. By way of illustration and not limitation, RAM can take many forms, such as Static Random Access Memory (SRAM) or Dynamic Random Access Memory (DRAM). The databases involved in the embodiments provided in this application may include at least one type of relational database and non-relational database. Non-relational databases may include, but are not limited to, blockchain-based distributed databases. The processors involved in the embodiments provided in this application may be general-purpose processors, central processing units, graphics processing units, digital signal processors, programmable logic devices, quantum computing-based data processing logic devices, artificial intelligence (AI) processors, etc., and are not limited to these.

[0194] The technical features of the above embodiments can be combined in any way. For the sake of brevity, not all possible combinations of the technical features in the above embodiments are described. However, as long as there is no contradiction in the combination of these technical features, they should be considered to be within the scope of this application.

[0195] The embodiments described above are merely illustrative of several implementation methods of this application, and while the descriptions are specific and detailed, they should not be construed as limiting the scope of this patent application. It should be noted that those skilled in the art can make various modifications and improvements without departing from the concept of this application, and these all fall within the protection scope of this application. Therefore, the protection scope of this application should be determined by the appended claims.

Claims

1. A method for rebuilding a database connection, characterized in that, The method includes: Send node metadata query requests to the database cluster management platform; The system receives the node metadata of the current database cluster returned by the management platform in response to the node metadata query request. The node metadata includes the network address of the primary database node and the network address of the backup database node in the database cluster. The primary database node is used to provide data read and write services, and the backup database node is used to back up the data of the primary database node. Obtain the network addresses corresponding to the connections already created in the current connection pool, including primary database connections and backup database connections; The network address of the primary database node in the node metadata is compared with the network address corresponding to the primary database connection. The network address of the backup database node in the node metadata is also compared with the network address corresponding to the backup database connection. If the comparison results are inconsistent, the connections in the connection pool are reconstructed based on the network addresses of the primary and backup nodes in the node metadata.

2. The method according to claim 1, characterized in that, The method further includes: Receive a connection acquisition request, which is submitted by the data access interface object after receiving a database operation request initiated by the application. The database operation request carries a query statement. In response to the connection acquisition request, an idle connection is returned to the data access interface object, so that the data access interface object can pass the query statement to the database cluster through the acquired connection and receive the execution result returned by the database cluster after executing the query statement.

3. The method according to claim 2, characterized in that, The connection that returns an idle state to the data access interface object in response to the connection acquisition request includes: In response to the connection acquisition request, query the status attributes of each connection in the current connection pool, including idle status, occupied status, and abandoned status; If there is an idle connection in the current connection pool, return the idle target connection to the data access interface object and update the status attribute of the target connection to occupied status.

4. The method according to claim 3, characterized in that, The method further includes: Upon receiving a connection playback notification regarding the target connection from the data access interface object, the status attribute of the target connection is updated to idle.

5. The method according to claim 2, characterized in that, The method further includes: If there are no idle connections in the current connection pool and the total number of connections in the connection pool reaches a set upper limit, a notification to wait for connection release is sent to the data access interface object.

6. The method according to claim 1, characterized in that, The method further includes: If the total number of connections in the current connection pool has not reached the set upper limit, a new connection is created according to the configuration parameters of the connection pool, and the created connection is added to the idle connection queue, which is used to store idle connections.

7. The method according to any one of claims 1 to 6, characterized in that, The step of reconstructing the connections in the connection pool based on the network addresses of the primary and backup nodes in the node metadata includes: Modify the status attribute of the connections already created in the current connection pool to the obsolete state; Based on the network address of the master database node in the node metadata, call the connection creation function to create a new master database connection; Based on the network address of the backup database node in the node metadata, call the connection creation function to create a new backup database connection; The newly created primary and standby database connections are added to the connection pool.

8. The method according to claim 1, characterized in that, The process of sending node metadata query requests to the database cluster management platform includes: At set intervals, node metadata query requests are sent to the database cluster management platform. The step of receiving the node metadata of the current database cluster returned by the management platform in response to the node metadata query request includes: The system receives the node metadata of the current database cluster returned by the management platform in response to the node metadata query request, wherein the node metadata of the current database cluster is updated after the database cluster performs a primary / standby node switch.

9. A database connection reconstruction apparatus, characterized in that, The device includes: The node metadata acquisition module is used to send a node metadata query request to the database cluster management platform and receive the node metadata of the current database cluster returned by the management platform in response to the node metadata query request. The node metadata includes the network address of the primary database node and the network address of the backup database node in the database cluster. The primary database node is used to provide data read and write services, and the backup database node is used to back up the data of the primary database node. The connection acquisition module is used to acquire the network addresses corresponding to the connections already created in the current connection pool, including primary database connections and backup database connections; The comparison module is used to compare the network address of the primary database node in the node metadata with the network address corresponding to the primary database connection, and to compare the network address of the backup database node in the node metadata with the network address corresponding to the backup database connection. The reconstruction module is used to reconstruct the connections in the connection pool based on the network addresses of the primary and backup nodes in the node metadata when the comparison results are inconsistent.

10. A computer device comprising a memory and a processor, wherein the memory stores a computer program, characterized in that, When the processor executes the computer program, it implements the steps of the method according to any one of claims 1 to 8.

11. A computer-readable storage medium having a computer program stored thereon, characterized in that, When the computer program is executed by a processor, it implements the steps of the method according to any one of claims 1 to 8.

12. A computer program product, comprising a computer program, characterized in that, When the computer program is executed by a processor, it implements the steps of the method according to any one of claims 1 to 8.