Database connection pool conversion method, device, equipment and storage medium

By introducing locked transmission connection pool and threadlocal mechanism into the connection pool of MPP distributed database, the problem that ordinary connection pools cannot perceive the relationship between sessions and connections is solved, and more efficient connection management is achieved and server load is reduced.

CN113051331BActive Publication Date: 2025-06-06深圳市汉云科技有限公司
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202110395315.0
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2021-04-13
Publication Date
2025-06-06
Estimated Expiration
2041-04-13

AI Technical Summary

Technical Problem

In MPP distributed database, ordinary connection pools cannot perceive the relationship between sessions, resulting in frequent acquisition and return connections from the connection pool when executing session transactions, resulting in excessive server resource usage.

Method used

By opening up a new locked transmission connection pool in the data connection pool, the threadlocal mechanism is used to divide the connection pool into a local connection pool and a global connection pool, locking connection requests in the distributed database and avoiding duplicate connection operations.

Benefits of technology

Reduces server load, improves the connection efficiency of the entire transmission process, and simplifies the connection process in the data connection pool in the process of executing session transaction tasks.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN113051331B_ABST
    Figure CN113051331B_ABST
Patent Text Reader

Abstract

The present invention relates to the field of data connection, and discloses a connection pool conversion method, device, equipment and storage medium for a database. The method comprises: receiving a connection request of a first data node in the data node cluster; determining whether the first data node has a session binding setting; if not, connecting the first data node to a second data node corresponding to the connection request based on a preset global connection pool; if yes, connecting the first data node to a second data node corresponding to the connection request according to a preset specific connection algorithm.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of data connection, and in particular to a method, device, equipment and storage medium for converting a connection pool of a database. Background Art

[0002] In an MPP distributed database, it is usually composed of a coordination node and a data node cluster. The coordination node is responsible for client access. Each client creates a session after connecting to the coordination node. The session maintains session information, is responsible for receiving the client's SQL, generating an execution plan, and sending it to the data node for execution. In order to improve performance, the coordination node often uses a connection pool to manage the connection with the data node cluster. In a common connection pool, there is no association between the connection and the session, but for some operations and transactions, it is necessary to ensure that all operations in a session transaction are executed in the same batch of node connections. These management operations cannot be provided by a common connection pool, and the upper layer needs to manage the connection itself. However, in an MPP distributed database, the coordination node needs to communicate with the node cluster very frequently, and usually uses a connection pool to manage the connection with the node to improve performance. Common connection pools usually cannot perceive the relationship between sessions and connections. Some operations and transactions require the logic of ensuring that all operations in the session are executed in the same batch of node connections. Connections cannot be obtained from the connection pool every time they are executed, because different connections may be obtained each time. Normally, it is necessary to save all executed node connection objects in the session context when the transaction is opened. Subsequent operations are performed through these node connections, and these connections can only be returned to the connection pool when the transaction is committed or terminated.

[0003] During the execution of a transaction, there are some operations that are not part of the main process of the transaction, such as data redistribution and logging. These operations usually need to be separated from the main process of the transaction and cannot be executed in the batch of node connections saved in the session. Instead, they need to be executed by obtaining connections from the connection pool. The cumbersome connection management of the upper layer brings a great burden to the system, so the upper layer needs to handle the relationship between the connection and the session and select different execution methods according to different logics. Summary of the invention

[0004] The main purpose of the present invention is to solve the technical problem that the server resources are occupied too much due to complicated connections in the process of executing session transaction tasks in a data connection pool.

[0005] A first aspect of the present invention provides a method for converting a connection pool of a database, comprising the steps of:

[0006] Receiving a connection request from a first data node in the data node cluster;

[0007] Determining whether a session binding setting exists for the first data node;

[0008] If not, connecting the first data node to the second data node corresponding to the connection request based on a preset global connection pool;

[0009] If so, the first data node is connected to the second data node corresponding to the connection request according to a preset specific connection algorithm.

[0010] Optionally, in a first implementation manner of the first aspect of the present invention, determining whether a session binding setting exists for the first data node includes:

[0011] Generate an empty ThreadLocalPool according to the preset transmission protocol and the connection request;

[0012] It is determined whether the connection request of the first data node is set as a session binding setting.

[0013] Optionally, in a second implementation of the first aspect of the present invention, connecting the first data node to the second data node corresponding to the connection request based on a preset global connection pool includes:

[0014] Creating a first link connection between the first data node and a preset global connection pool;

[0015] Creating a second link connection between the second data node corresponding to the connection request and the global connection pool;

[0016] According to the first link connection and the second link connection, the first data node is connected to the second data node corresponding to the connection request, and the ThreadLocalPool is cleared.

[0017] Optionally, in a third implementation manner of the first aspect of the present invention, connecting the first data node to the second data node corresponding to the connection request according to a preset specific connection algorithm includes:

[0018] Establishing a third link connection between the first data node and the ThreadLocalPool;

[0019] Establishing a fourth link connection between the second data node corresponding to the connection request and the ThreadLocalPool;

[0020] According to the third link connection and the fourth link connection, performing transmission test processing between the first data node and the second data node to obtain a connection test result;

[0021] According to the connection test result, the first data node is connected to the second data node corresponding to the connection request.

[0022] Optionally, in a fourth implementation manner of the first aspect of the present invention, connecting the first data node to the second data node corresponding to the connection request according to the connection test result includes:

[0023] Determine whether the connection test result is that the connection is smooth;

[0024] If the connection is smooth, then connecting the third link to the fourth link to establish a connection topology structure between the first data node and the second data node;

[0025] If the connection is not smooth, creating a first link connection between the first data node and a preset global connection pool, and creating a second link connection between the second data node corresponding to the connection request and the global connection pool;

[0026] According to the first link connection and the second link connection, the first data node is connected to the second data node corresponding to the connection request, and the ThreadLocalPool is cleared.

[0027] Optionally, in a fifth implementation of the first aspect of the present invention, after establishing a connection topology structure between the first data node and the second data node through the third link connection and the fourth link connection, the method further includes:

[0028] Receiving a disconnection request for the first data;

[0029] Determine whether the disconnect request is set to be returned to the ThreadLocalPool;

[0030] If yes, delete the third link connection, and save the fourth link connection and the ThreadLocalPool;

[0031] If not, the link deletes the third link connection and the fourth link connection, clears the ThreadLocalPool, and saves the connection topology structure to the global connection pool.

[0032] Optionally, in a sixth implementation manner of the first aspect of the present invention, after receiving a connection request from a first data node in the data node cluster and before determining whether a session binding setting exists for the first data node, the method further includes:

[0033] Determining whether the number of requests of the first data node in a preset time interval exceeds an access threshold;

[0034] If yes, stop executing the connection request;

[0035] If not, the connection request is executed.

[0036] A second aspect of the present invention provides a connection pool conversion device for a database, comprising:

[0037] A receiving module, configured to receive a connection request from a first data node in the data node cluster;

[0038] A determination module, used to determine whether a session binding setting exists for the first data node;

[0039] A first connection module, configured to, if not, connect the first data node to a second data node corresponding to the connection request based on a preset global connection pool;

[0040] The second connection module is configured to connect the first data node to a second data node corresponding to the connection request according to a preset specific connection algorithm.

[0041] A third aspect of the present invention provides a database connection pool conversion device, comprising: a memory and at least one processor, wherein instructions are stored in the memory, and the memory and the at least one processor are interconnected via a line; the at least one processor calls the instructions in the memory so that the database connection pool conversion device executes the above-mentioned database connection pool conversion method.

[0042] A fourth aspect of the present invention provides a computer-readable storage medium, wherein the computer-readable storage medium stores instructions, which, when executed on a computer, enable the computer to execute the above-mentioned database connection pool conversion method.

[0043] In an embodiment of the present invention, a threadlocal mechanism is used to divide the connection pool into a local connection pool and a global connection pool. By opening a new locked transmission connection pool in the data connection pool, the connection request in the distributed database is locked, so that there is no need to repeatedly connect during session tasks, which reduces the load on the server, improves the connection efficiency of the entire transmission process, and simplifies the connection process in the data connection pool during the execution of session transaction tasks. BRIEF DESCRIPTION OF THE DRAWINGS

[0044] Figure 1 A schematic diagram of a first embodiment of a method for converting a database connection pool in an embodiment of the present invention;

[0045] Figure 2 A schematic diagram of a second embodiment of a method for converting a database connection pool in an embodiment of the present invention;

[0046] Figure 3 A schematic diagram of an embodiment of a connection pool conversion device for a database in an embodiment of the present invention;

[0047] Figure 4 It is a schematic diagram of another embodiment of a connection pool conversion device for a database in an embodiment of the present invention;

[0048] Figure 5 The figure is a schematic diagram of an embodiment of a connection pool conversion device for a database in an embodiment of the present invention. DETAILED DESCRIPTION

[0049] The embodiment of the present invention provides a connection pool conversion method, device, equipment and storage medium for a database.

[0050] The terms "first", "second", "third", "fourth", etc. (if any) in the specification and claims of the present invention and the above-mentioned drawings are used to distinguish similar objects, and are not necessarily used to describe a specific order or sequence. It should be understood that the data used in this way can be interchanged where appropriate, so that the embodiments described herein can be implemented in an order other than that illustrated or described herein. In addition, the terms "including" or "having" and any variations thereof are intended to cover non-exclusive inclusions, for example, a process, method, system, product or device that includes a series of steps or units is not necessarily limited to those steps or units that are clearly listed, but may include other steps or units that are not clearly listed or inherent to these processes, methods, products or devices.

[0051] For ease of understanding, the specific process of the embodiment of the present invention is described below. Figure 1 , an embodiment of the connection pool conversion method of the database in the embodiment of the present invention includes:

[0052] 101. Receive a connection request from a first data node in a data node cluster;

[0053] 102. Determine whether a session binding setting exists on the first data node;

[0054] 103. If not, connecting the first data node to the second data node corresponding to the connection request based on a preset global connection pool;

[0055] 104. If yes, then according to a preset specific connection algorithm, connect the first data node to the second data node corresponding to the connection request.

[0056] In this embodiment, the connection pool architecture is generally composed of two pools, namely ThreadLocalPool and global connection pool. Each connection pool implements the connection management function and provides corresponding interfaces to obtain and return connections. The main difference between them is that ThreadLocalPool is implemented in the form of local thread data. Using local thread data, it can be realized in the ConnectionPerThread thread model that a ThreadLocalPool is automatically created each time a session is created, and the corresponding ThreadLocalPool is automatically destroyed when the session exits.

[0057] In the process of obtaining a connection from the connection pool, due to the characteristics of threadlocal, a new empty ThreadLocalPool is automatically generated when a new session is created. When the upper layer uses the connection pool to obtain a connection, it is necessary to distinguish whether to obtain a connection bound to a session or a global connection. If a connection bound to a session is obtained, the connection pool will obtain the connection from the ThreadLocalPool without locking it and return it. If the ThreadLocalPool is just created and no connection is available, it will first be obtained from the global connection pool.

[0058] In the process of returning the connection pool, first determine whether the connection returned is a session-bound connection or a global connection. For the connection returned to the session, return it to the ThreadLocalPool to be reused next time. If the connection returned is a global connection, return it to the global connection pool. There is also a special return method. When the session exits, the ThreadLocalPool will be automatically destroyed. At this time, the connection retained in the ThreadLocalPool will be automatically returned to the global connection pool to be reused next time.

[0059] In an embodiment of the present invention, a new locked transmission connection pool is opened in a data connection pool, so that the connection request in the distributed database is locked, so that there is no need to repeatedly connect during a session task, which reduces the load in the server, improves the connection efficiency of the entire transmission process, and simplifies the connection process in the data connection pool during the execution of the session transaction task process.

[0060] See also Figure 2 , a second embodiment of the connection pool conversion method of a database in an embodiment of the present invention includes:

[0061] 201. Receive a connection request from a first data node in a data node cluster;

[0062] 202. Determine whether the number of requests of the first data node in a preset time interval exceeds an access threshold;

[0063] 203. If yes, stop executing the connection request;

[0064] 204. If not, execute the connection request;

[0065] In the embodiments 202-204, the number of connection requests of the first data node is counted within a certain time range. Since there are many data nodes in the database cluster, an access control is set to control each node from occupying the connection resources of other nodes. For example, the data node is restricted from having more than 50 connection requests within 1 hour.

[0066] 205. Generate an empty ThreadLocalPool according to the preset transmission protocol and connection request;

[0067] 206. Determine whether the connection request of the first data node is set as a session binding setting;

[0068] In embodiments 205-206, after receiving a connection request, an empty local connection pool is immediately created. After the local connection pool is created, it is analyzed whether the connection request of the first data node requires session binding, that is, whether the current request is executing a transaction or other such request that requires binding the connection to a session.

[0069] 207. If not, create a first link connection between the first data node and a preset global connection pool;

[0070] 208. Create a second link connection between the second data node corresponding to the connection request and the global connection pool;

[0071] 209. According to the first link connection and the second link connection, the first data node is connected to the second data node corresponding to the connection request, and the ThreadLocalPool is cleared;

[0072] In embodiments 207-209, a link is established between the first data node and the global connection pool, and the global connection pool establishes a link with the second data node according to the request. The global connection pool serves as an intermediate connection topology point to complete the connection between the first data node and the second data node, and then clears the local connection pool.

[0073] 210. If yes, establish a third link connection between the first data node and the ThreadLocalPool;

[0074] 211. Establish a fourth link connection between the second data node corresponding to the connection request and the ThreadLocalPool;

[0075] 212. Perform transmission test processing on the first data node and the second data node according to the third link connection and the fourth link connection to obtain a connection test result;

[0076] In embodiments 210-212, the first data node is connected to the local connection pool, and then the local connection pool is connected to the second data node, and it is tested whether the first data node and the second data node communicate normally. If the communication is normal, it means that the connection is locked.

[0077] 213. Determine whether the connection test result is that the connection is smooth;

[0078] 214. If the connection is smooth, connect the third link to the fourth link to establish a connection topology structure between the first data node and the second data node;

[0079] In the embodiments 213-214, the detection result needs to be judged, and if the data connection is smooth, the topological connection structure is recorded as a fixed network transmission path between the first data node and the second data node for the next data access.

[0080] 215. Receive a disconnection request for first data;

[0081] 216. Determine whether the disconnection request is set to be returned to ThreadLocalPool;

[0082] 217. If yes, delete the third link connection and save the fourth link connection and ThreadLocalPool;

[0083] 218. If not, delete the third link connection and the fourth link connection, clear the ThreadLocalPool, and save the connection topology structure to the global connection pool;

[0084] In embodiments 215-218, a return instruction is obtained. If it is returned to the local connection pool, the local connection pool will not be cleared. If it is not returned to the local connection pool, the local connection pool needs to be cleared, and then the topology structure of this connection is returned to the global connection pool.

[0085] 219. If the connection is not smooth, create a first link connection between the first data node and a preset global connection pool, and create a second link connection between the second data node corresponding to the connection request and the global connection pool;

[0086] 220. According to the first link connection and the second link connection, the first data node is connected to the second data node corresponding to the connection request, and the ThreadLocalPool is cleared.

[0087] In the embodiments 219-220, if the connection is not smooth, it is considered that the local connection pool cannot be connected, and the local connection pool needs to be deleted, and the first data node and the second data node are connected through the global connection pool. In the process of realizing data connection, a data transmission rate threshold can be set for the connection to be not smooth. If the data transmission rate does not reach the set threshold during the test, it can be considered that it is not smooth.

[0088] In an embodiment of the present invention, a new locked transmission connection pool is opened in a data connection pool, so that the connection request in the distributed database is locked, so that there is no need to repeatedly connect during a session task, which reduces the load in the server, improves the connection efficiency of the entire transmission process, and simplifies the connection process in the data connection pool during the execution of the session transaction task process.

[0089] The above describes the connection pool conversion method of the database in the embodiment of the present invention. The following describes the connection pool conversion device of the database in the embodiment of the present invention. Figure 3 , an embodiment of a connection pool conversion device for a database in an embodiment of the present invention includes:

[0090] A receiving module 301 is used to receive a connection request from a first data node in the data node cluster;

[0091] A determination module 302 is used to determine whether a session binding setting exists on the first data node;

[0092] A first connection module 303, configured to, if not, connect the first data node to a second data node corresponding to the connection request based on a preset global connection pool;

[0093] The second connection module 304 is configured to connect the first data node to the second data node corresponding to the connection request according to a preset specific connection algorithm.

[0094] In an embodiment of the present invention, a new locked transmission connection pool is opened in a data connection pool, so that the connection request in the distributed database is locked, so that there is no need to repeatedly connect during a session task, which reduces the load in the server, improves the connection efficiency of the entire transmission process, and simplifies the connection process in the data connection pool during the execution of the session transaction task process.

[0095] See also Figure 4 Another embodiment of the connection pool conversion device of the database in the embodiment of the present invention includes:

[0096] A receiving module 301 is used to receive a connection request from a first data node in the data node cluster;

[0097] A determination module 302 is used to determine whether a session binding setting exists on the first data node;

[0098] A first connection module 303, configured to, if not, connect the first data node to a second data node corresponding to the connection request based on a preset global connection pool;

[0099] The second connection module 304 is configured to connect the first data node to the second data node corresponding to the connection request according to a preset specific connection algorithm.

[0100] The determining module 302 is specifically used for:

[0101] Generate an empty ThreadLocalPool according to the preset transmission protocol and the connection request;

[0102] It is determined whether the connection request of the first data node is set as a session binding setting.

[0103] The first connection module 303 is specifically used for:

[0104] Creating a first link connection between the first data node and a preset global connection pool;

[0105] Creating a second link connection between the second data node corresponding to the connection request and the global connection pool;

[0106] According to the first link connection and the second link connection, the first data node is connected to the second data node corresponding to the connection request, and the ThreadLocalPool is cleared.

[0107] The second connection module 304 is specifically used for:

[0108] A first link establishing unit 3041 is used to establish a third link connection between the first data node and the ThreadLocalPool;

[0109] A second link establishing unit 3042 is used to establish a fourth link connection between the second data node corresponding to the connection request and the ThreadLocalPool;

[0110] A testing unit 3043 is configured to perform a transmission test process between the first data node and the second data node according to the third link connection and the fourth link connection, and obtain a connection test result;

[0111] The connecting unit 3044 is used to connect the first data node to the second data node corresponding to the connection request according to the connection test result.

[0112] The connection unit 3044 is specifically used for:

[0113] Determine whether the connection test result is that the connection is smooth;

[0114] If the connection is smooth, then connecting the third link to the fourth link to establish a connection topology structure between the first data node and the second data node;

[0115] If the connection is not smooth, creating a first link connection between the first data node and a preset global connection pool, and creating a second link connection between the second data node corresponding to the connection request and the global connection pool;

[0116] According to the first link connection and the second link connection, the first data node is connected to the second data node corresponding to the connection request, and the ThreadLocalPool is cleared.

[0117] The connection pool conversion device of the database specifically includes a return module 305, and the return module 305 is specifically used for:

[0118] Receiving a disconnection request for the first data;

[0119] Determine whether the disconnect request is set to be returned to the ThreadLocalPool;

[0120] If yes, delete the third link connection, and save the fourth link connection and the ThreadLocalPool;

[0121] If not, the link deletes the third link connection and the fourth link connection, clears the ThreadLocalPool, and saves the connection topology structure to the global connection pool.

[0122] The connection pool conversion device of the database further includes a frequency detection module 306, and the frequency detection module 306 is specifically used for:

[0123] Determining whether the number of requests of the first data node in a preset time interval exceeds an access threshold;

[0124] If yes, stop executing the connection request;

[0125] If not, the connection request is executed.

[0126] In an embodiment of the present invention, a new locked transmission connection pool is opened in a data connection pool, so that the connection request in the distributed database is locked, so that there is no need to repeatedly connect during a session task, which reduces the load in the server, improves the connection efficiency of the entire transmission process, and simplifies the connection process in the data connection pool during the execution of the session transaction task process.

[0127] above Figure 3 and Figure 4 The connection pool conversion device of the database in the embodiment of the present invention is described in detail from the perspective of modular functional entities. The connection pool conversion device of the database in the embodiment of the present invention is described in detail from the perspective of hardware processing.

[0128] Figure 5 1 is a schematic diagram of the structure of a connection pool conversion device for a database provided in an embodiment of the present invention. The connection pool conversion device 500 for the database may have relatively large differences due to different configurations or performances, and may include one or more processors (central processing units, CPU) 510 (for example, one or more processors) and a memory 520, and one or more storage media 530 (for example, one or more mass storage devices) storing application programs 533 or data 532. Among them, the memory 520 and the storage medium 530 may be short-term storage or permanent storage. The program stored in the storage medium 530 may include one or more modules (not shown in the figure), and each module may include a series of instruction operations in the connection pool conversion device 500 for the database. Furthermore, the processor 510 may be configured to communicate with the storage medium 530 to execute a series of instruction operations in the storage medium 530 on the connection pool conversion device 500 for the database.

[0129] The database-based connection pool conversion device 500 may also include one or more power supplies 540, one or more wired or wireless network interfaces 550, one or more input and output interfaces 560, and / or one or more operating systems 531, such as Windows Serve, Mac OS X, Unix, Linux, FreeBSD, etc. Those skilled in the art will appreciate that Figure 5 The illustrated database connection pool conversion device structure does not constitute a limitation on the database-based connection pool conversion device, and may include more or fewer components than illustrated, or a combination of certain components, or a different arrangement of components.

[0130] The present invention also provides a computer-readable storage medium, which may be a non-volatile computer-readable storage medium or a volatile computer-readable storage medium. Instructions are stored in the computer-readable storage medium. When the instructions are executed on a computer, the computer executes the steps of the database connection pool conversion method.

[0131] Those skilled in the art can clearly understand that, for the convenience and brevity of description, the specific working process of the above-described system, device, or unit can refer to the corresponding process in the aforementioned method embodiment and will not be repeated here.

[0132] If the integrated unit is implemented in the form of a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of the present invention is essentially 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. The computer software product is stored in a storage medium, including a number of instructions to enable a computer device (which can be a personal computer, a server, or a network device, etc.) to perform all or part of the steps of the method described in each embodiment of the present invention. The aforementioned storage medium includes: U disk, mobile hard disk, read-only memory (ROM), random access memory (RAM), disk or optical disk and other media that can store program codes.

[0133] As described above, the above embodiments are only used to illustrate the technical solutions of the present invention, rather than to limit the same. Although the present invention has been described in detail with reference to the aforementioned embodiments, those skilled in the art should understand that the technical solutions described in the aforementioned embodiments may still be modified, or some of the technical features thereof may be replaced by equivalents. However, these modifications or replacements do not deviate the essence of the corresponding technical solutions from the spirit and scope of the technical solutions of the embodiments of the present invention.

Claims

1. A database connection pool conversion method, the database connection pool conversion method is applied to a data node cluster, It is characterized in that Includes steps: Receiving a connection request from a first data node in the data node cluster; Determining whether a session binding setting exists for the first data node; If not, connecting the first data node to the second data node corresponding to the connection request based on a preset global connection pool; If so, connecting the first data node to the second data node corresponding to the connection request according to a preset specific connection algorithm; Among them, the connection pool of the database consists of a ThreadLocalPool and a global connection pool; ThreadLocalPool and the global connection pool provide interfaces to obtain and return connections respectively; a ThreadLocalPool is automatically created each time a session is created, and the corresponding ThreadLocalPool is automatically destroyed when the session exits; in the process of obtaining a connection, it is determined whether to obtain a session-bound connection or a global connection; if a session-bound connection is obtained, the connection is obtained from the ThreadLocalPool; if no connection is available in the ThreadLocalPool, it is obtained from the global connection pool; in the process of returning a connection, it is determined whether the connection returned is a session-bound connection or a global connection; if a session-bound connection is returned, it is returned to the ThreadLocalPool; if a global connection is returned, it is returned to the global connection pool.

2. The connection pool conversion method of the database according to claim 1, It is characterized in that The determining whether the first data node has a session binding setting includes: Generate an empty ThreadLocalPool according to the preset transmission protocol and the connection request; It is determined whether the connection request of the first data node is set as a session binding setting.

3. The connection pool conversion method of the database according to claim 2, It is characterized in that The connecting the first data node to the second data node corresponding to the connection request based on the preset global connection pool includes: Creating a first link connection between the first data node and a preset global connection pool; Creating a second link connection between the second data node corresponding to the connection request and the global connection pool; According to the first link connection and the second link connection, the first data node is connected to the second data node corresponding to the connection request, and the ThreadLocalPool is cleared.

4. The connection pool conversion method for a database according to any one of claims 2 and 3, It is characterized in that The connecting the first data node to the second data node corresponding to the connection request according to the preset specific connection algorithm comprises: Establishing a third link connection between the first data node and the ThreadLocalPool; Establishing a fourth link connection between the second data node corresponding to the connection request and the ThreadLocalPool; According to the third link connection and the fourth link connection, performing transmission test processing between the first data node and the second data node to obtain a connection test result; According to the connection test result, the first data node is connected to the second data node corresponding to the connection request.

5. The connection pool conversion method for a database according to claim 4, It is characterized in that The connecting the first data node to the second data node corresponding to the connection request according to the connection test result comprises: Determine whether the connection test result is that the connection is smooth; If the connection is smooth, then connecting the third link to the fourth link to establish a connection topology structure between the first data node and the second data node; If the connection is not smooth, creating a first link connection between the first data node and a preset global connection pool, and creating a second link connection between the second data node corresponding to the connection request and the global connection pool; According to the first link connection and the second link connection, the first data node is connected to the second data node corresponding to the connection request, and the ThreadLocalPool is cleared.

6. The connection pool conversion method for a database according to claim 5, It is characterized in that After the connection topology of the first data node and the second data node is established through the third link connection and the fourth link connection, the method further includes: Receiving a disconnection request for the first data; Determine whether the disconnect request is set to be returned to the ThreadLocalPool; If yes, delete the third link connection, and save the fourth link connection and the ThreadLocalPool; If not, the third link connection and the fourth link connection are deleted, the ThreadLocalPool is cleared, and the connection topology is saved in the global connection pool.

7. The connection pool conversion method for a database according to claim 1, It is characterized in that After receiving the connection request of the first data node in the data node cluster and before determining whether the first data node has a session binding setting, the method further includes: Determining whether the number of requests of the first data node in a preset time interval exceeds an access threshold; If yes, stop executing the connection request; If not, the connection request is executed.

8. A database connection pool conversion device, It is characterized in that The connection pool conversion device of the database includes: A receiving module, configured to receive a connection request from a first data node in the data node cluster; A determination module, used to determine whether a session binding setting exists for the first data node; A first connection module, configured to, if not, connect the first data node to a second data node corresponding to the connection request based on a preset global connection pool; a second connection module, configured to connect the first data node to a second data node corresponding to the connection request according to a preset specific connection algorithm; Among them, the connection pool of the database consists of a ThreadLocalPool and a global connection pool; ThreadLocalPool and the global connection pool provide interfaces to obtain and return connections respectively; a ThreadLocalPool is automatically created each time a session is created, and the corresponding ThreadLocalPool is automatically destroyed when the session exits; in the process of obtaining a connection, it is determined whether to obtain a session-bound connection or a global connection; if a session-bound connection is obtained, the connection is obtained from the ThreadLocalPool; if no connection is available in the ThreadLocalPool, it is obtained from the global connection pool; in the process of returning a connection, it is determined whether the connection returned is a session-bound connection or a global connection; if a session-bound connection is returned, it is returned to the ThreadLocalPool; if a global connection is returned, it is returned to the global connection pool.

9. A database connection pool conversion device, It is characterized in that The database connection pool conversion device comprises: a memory and at least one processor, the memory stores instructions, and the memory and the at least one processor are interconnected via a line; The at least one processor calls the instruction in the memory to enable the connection pool conversion device of the database to execute the connection pool conversion method for the database according to any one of claims 1 to 7.

10. A computer-readable storage medium having a computer program stored thereon, It is characterized in that When the computer program is executed by a processor, the connection pool conversion method for a database according to any one of claims 1 to 7 is implemented.

Citation Information

Patent Citations

  • Data access connection session protection method and device

    CN111639116A

  • In-house elegant JDBC connection pooling solution for message broker

    US9098565B1