Connection pool management method and device, electronic equipment, storage medium and program product

By using a hash table in the connection pool to quickly find idle state database connections, the problem of long-term search in the existing technology is solved, and faster client database connections are achieved.

CN120448442APending Publication Date: 2025-08-08CETC JINCANG (BEIJING) TECH CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202510526950.6
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-04-24
Publication Date
2025-08-08

AI Technical Summary

Technical Problem

In the prior art, the connection pool takes a long time to find the idle state database connection, resulting in a longer time for the client to connect to the database.

Method used

Use a hash table (such as SwissTable) to store database connection information, quickly find database connections with connection status in idle state through keys in the hash table, and obtain the corresponding connection handle.

Benefits of technology

Improves the speed of finding idle state database connections in the connection pool and reduces the duration of the client connecting to the database.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN120448442A_ABST
    Figure CN120448442A_ABST
Patent Text Reader

Abstract

The invention provides a connection pool management method and device, electronic equipment, a storage medium and a program product. The method comprises the steps that in response to a request of a client for connecting a database, according to at least one piece of database connection information stored in a first hash table of a connection pool, a connection handle connected with a first database with the connection state being an idle state is determined, the database connection information comprises a first key-value pair, and the first key-value pair comprises a second key-value pair; keys in the first key value pair are used for representing a connection state of database connection, and values in the first key value pair are used for representing a connection handle of the database connection; and sending a connection handle connected with the first database to the client. According to the method, the time for the client to connect the database is shortened.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the field of database technology, and in particular to a connection pool management method, device, electronic device, storage medium, and program product. Background Art

[0002] Database connection pooling is a technology that pre-creates database connections, groups them into a pool, and dynamically allocates database connections from the pool to clients. When a client needs to access the database, it requests an idle database connection from the pool. Once the client has finished using the connection, the connection is returned to the pool. Using a connection pool to connect to the database avoids the performance overhead associated with frequently creating and destroying database connections.

[0003] In related technologies, the connection pool uses a queue to store multiple connection information. When a client sends a database connection request to the connection pool, the connection pool needs to search and allocate an idle database connection in the queue. The client connects to the database based on the allocated database connection. When the number of database connections stored in the queue is large, it takes a long time to find an idle database connection in the connection pool, resulting in a longer time for the client to connect to the database. Summary of the Invention

[0004] The present application provides a connection pool management method, device, electronic device, storage medium and program product to solve the problem of long client connection time to the database in the prior art.

[0005] In a first aspect, the present application provides a connection pool management method, comprising:

[0006] In response to a request from a client to connect to a database, determining a connection handle of a first database connection whose connection state is idle based on at least one database connection information stored in a first hash table of a connection pool, wherein the database connection information includes a first key-value pair, the key in the first key-value pair is used to represent the connection state of the database connection, and the value in the first key-value pair is used to represent the connection handle of the database connection;

[0007] Send the connection handle of the first database connection to the client.

[0008] Optionally, the database connection information further includes first metadata corresponding to the first key-value pair, where the first metadata is used to represent a slot status of a slot storing the database connection information;

[0009] The step of determining the connection handle of the first database connection whose connection state is idle according to at least one database connection information stored in the first hash table of the connection pool includes:

[0010] Determine at least one slot corresponding to a key representing an idle connection state in the first hash table, and use a first slot of the at least one slot as a target slot;

[0011] If the slot state represented by the first metadata in the target slot is a storage state, the connection handle in the target slot is determined as the connection handle of the first database connection. If the slot state represented by the first metadata in the target slot is empty or a deletion state, this step is repeated with the slot next to the target slot as a new target slot until the connection handle of the first database connection is obtained.

[0012] Optionally, it also includes:

[0013] The key corresponding to the connection handle of the first database connection is updated to a key indicating that the connection state is active.

[0014] Optionally, it also includes:

[0015] In response to the client's operation of releasing the first database connection, the key corresponding to the connection handle of the first database connection is updated to a key indicating that the connection state is an idle state.

[0016] Optionally, the connection pool includes a second hash table corresponding to at least one database connection whose slot state in the first hash table is a storage state, the second hash table includes at least one parameter information of the database connection, the parameter information includes a second key-value pair and second metadata corresponding to the second key-value pair, the key in the second key-value pair is used to represent an identifier of a parameter of the database connection, the value in the second key-value pair is used to represent a parameter value of the parameter, and the second metadata is used to represent the slot state of the slot storing the parameter information;

[0017] The method further comprises:

[0018] In response to a request to set a first parameter for the first database connection, determining whether the second hash table includes a key representing the first parameter;

[0019] If the second hash table does not include a key representing the first parameter, first parameter information corresponding to the first parameter is stored in the second hash table, and second metadata in the first parameter information is used to indicate that the slot state of the slot storing the first parameter information is a newly added parameter storage state;

[0020] When the second hash table includes the key representing the first parameter, the value and second metadata corresponding to the key representing the first parameter are updated in the second hash table, and the second metadata in the first parameter information is used to represent that the slot state of the slot storing the first parameter information is a non-new parameter storage state.

[0021] Optionally, it also includes:

[0022] In response to the client releasing the first database connection, for the first parameter, if the slot state of the slot storing the first parameter information is a new parameter storage state, deleting the first parameter information from the second hash table;

[0023] When the slot state of the slot storing the first parameter information is a non-newly added parameter storage state, the first parameter information is restored to a value before responding to the setting request for the first parameter of the first database connection.

[0024] In a second aspect, the present application provides a connection pool management device, comprising:

[0025] a determining module, configured to, in response to a request from a client to connect to a database, determine a connection handle of a first database connection whose connection state is idle based on at least one database connection information stored in a first hash table of a connection pool, wherein the database connection information includes a first key-value pair, the key in the first key-value pair being used to represent the connection state of the database connection, and the value in the first key-value pair being used to represent the connection handle of the database connection;

[0026] A sending module is used to send the connection handle of the first database connection to the client.

[0027] Optionally, the database connection information further includes first metadata corresponding to the first key-value pair, where the first metadata is used to represent a slot status of a slot storing the database connection information;

[0028] The step of determining the connection handle of the first database connection whose connection state is idle according to at least one database connection information stored in the first hash table of the connection pool includes:

[0029] Determine at least one slot corresponding to a key representing an idle connection state in the first hash table, and use a first slot of the at least one slot as a target slot;

[0030] If the slot state represented by the first metadata in the target slot is a storage state, the connection handle in the target slot is determined as the connection handle of the first database connection. If the slot state represented by the first metadata in the target slot is empty or a deletion state, this step is repeated with the slot next to the target slot as a new target slot until the connection handle of the first database connection is obtained.

[0031] Optionally, it also includes:

[0032] The key corresponding to the connection handle of the first database connection is updated to a key indicating that the connection state is active.

[0033] Optionally, it also includes:

[0034] In response to the client's operation of releasing the first database connection, the key corresponding to the connection handle of the first database connection is updated to a key indicating that the connection state is an idle state.

[0035] Optionally, the connection pool includes a second hash table corresponding to at least one database connection whose slot state in the first hash table is a storage state, the second hash table includes at least one parameter information of the database connection, the parameter information includes a second key-value pair and second metadata corresponding to the second key-value pair, the key in the second key-value pair is used to represent an identifier of a parameter of the database connection, the value in the second key-value pair is used to represent a parameter value of the parameter, and the second metadata is used to represent the slot state of the slot storing the parameter information;

[0036] The method further comprises:

[0037] In response to a request to set a first parameter for the first database connection, determining whether the second hash table includes a key representing the first parameter;

[0038] If the second hash table does not include a key representing the first parameter, first parameter information corresponding to the first parameter is stored in the second hash table, and second metadata in the first parameter information is used to indicate that the slot state of the slot storing the first parameter information is a newly added parameter storage state;

[0039] When the second hash table includes the key representing the first parameter, the value and second metadata corresponding to the key representing the first parameter are updated in the second hash table, and the second metadata in the first parameter information is used to represent that the slot state of the slot storing the first parameter information is a non-new parameter storage state.

[0040] Optionally, it also includes:

[0041] In response to the client releasing the first database connection, for the first parameter, if the slot state of the slot storing the first parameter information is a new parameter storage state, deleting the first parameter information from the second hash table;

[0042] When the slot state of the slot storing the first parameter information is a non-newly added parameter storage state, the first parameter information is restored to a value before responding to the setting request for the first parameter of the first database connection.

[0043] In a third aspect, the present application provides an electronic device, comprising: a processor, and a memory communicatively connected to the processor;

[0044] The memory stores computer-executable instructions;

[0045] The processor executes the computer-executable instructions stored in the memory to implement the method described in the first aspect and various possible designs of the first aspect.

[0046] In a fourth aspect, an embodiment of the present application provides a computer-readable storage medium, in which computer-executable instructions are stored. When a processor executes the computer-executable instructions, the method described in the first aspect and various possible designs of the first aspect is implemented.

[0047] In a fifth aspect, an embodiment of the present application provides a computer program product, including a computer program. When the computer program is executed by a processor, it implements the method described in the first aspect and various possible designs of the first aspect.

[0048] The connection pool management method, apparatus, electronic device, storage medium, and program product provided herein enable a connection pool to, in response to a client's request to connect to a database, determine a connection handle for a first database connection with an idle state based on at least one database connection information stored in a first hash table of the connection pool, and send the connection handle of the first database connection to the client. Because the connection pool can quickly search for database connections with an idle state in the hash table using a key in the hash table and obtain the corresponding connection handle, the speed of searching for idle database connections in the connection pool is improved, thereby reducing the time it takes for the client to connect to the database. BRIEF DESCRIPTION OF THE DRAWINGS

[0049] The accompanying drawings, which are incorporated in and constitute a part of this specification, illustrate embodiments consistent with the present application and, together with the description, serve to explain the principles of the present application.

[0050] Figure 1 This is a schematic diagram of a scenario where a database is connected based on a connection pool;

[0051] Figure 2 A flow chart of a connection pool management method provided in an embodiment of the present application;

[0052] Figure 3 A schematic diagram of the connection status of a database connection provided in an embodiment of the present application;

[0053] Figure 4 A schematic diagram of a method for managing database connection parameters in a connection pool provided in an embodiment of the present application Figure 1 ;

[0054] Figure 5 A schematic diagram of a method for managing database connection parameters in a connection pool provided in an embodiment of the present application Figure 2 ;

[0055] Figure 6 A schematic diagram of the structure of a connection pool management device provided in an embodiment of the present application;

[0056] Figure 7 A schematic diagram of the structure of an electronic device provided in an embodiment of the present application.

[0057] The above drawings illustrate specific embodiments of the present application, which will be described in more detail below. These drawings and the textual description are not intended to limit the scope of the present application in any way, but rather to illustrate the concepts of the present application to those skilled in the art by reference to specific embodiments. DETAILED DESCRIPTION

[0058] Exemplary embodiments will be described in detail herein, with examples illustrated in the accompanying drawings. In the following description, when referring to the drawings, identical numerals in different figures represent identical or similar elements, unless otherwise indicated. The embodiments described in the following exemplary embodiments are not intended to represent all embodiments consistent with the present application. Rather, they are merely examples of apparatus and methods consistent with certain aspects of the present application, as detailed in the appended claims.

[0059] Figure 1 The following is a schematic diagram of a scenario where a database is connected based on a connection pool. Figure 1 As shown, multiple database connections are pre-established in the connection pool. Each database connection can be used to communicate with the database. The client can send a request to connect to the database to the connection pool. The connection pool searches for an idle database connection in multiple databases and assigns the database connection to the client. Figure 1As shown, client A sends a request to connect to the database to the connection pool. The connection pool includes N database connections, among which database connection 1 has been assigned to client B. Therefore, database connection 1 is active and the other N-1 database connections are idle. The connection pool can assign any idle database connection to client A.

[0060] In related technologies, connection pools use queues to store multiple connection information. In this approach, the connection pool maintains a queue that stores database connections and their corresponding connection states. When a client sends a database connection request to the connection pool, the connection pool needs to traverse the database connections in the queue to identify an idle database connection, assign that database connection to the client, and the client connects to the database based on the assigned database connection. If the queue holds a large number of database connections, searching for an idle database connection in the connection pool takes a long time, resulting in a longer time for the client to connect to the database.

[0061] In view of this, the present application proposes a connection pool management method. The connection pool stores database connection information via a hash table. The key in the connection information is used to represent the connection state of the database connection, and the value is used to represent the connection handle of the database connection. In this method, the connection handle of the database connection with an idle state is determined based on the database connection information stored in the hash table of the connection pool, and the connection handle of the database connection is sent to the client. Because the connection pool can quickly search for database connections with an idle state in the hash table using the key in the hash table and obtain the corresponding connection handle, the speed of searching for idle database connections in the connection pool is improved, thereby reducing the time it takes for the client to connect to the database.

[0062] It should be understood that the database access method of the embodiments of the present application can be used in any scenario involving connecting to a database. The execution entity of the embodiments of the present application can be any device for connecting to a database. This device is not limited to a specific implementation and can be implemented by software and / or hardware. Specifically, the device can be, for example, a connection pool or a server running a connection pool. The following description uses the connection pool as an example execution entity.

[0063] The following specific embodiments describe in detail the technical solution of the present application and how the technical solution of the present application solves the above-mentioned technical problems. The following specific embodiments can be combined with each other, and the same or similar concepts or processes may not be repeated in some embodiments. The embodiments of the present application will be described below in conjunction with the accompanying drawings.

[0064] Figure 2 A flow chart of a connection pool management method provided in an embodiment of the present application. Figure 2As shown in , the connection pool management method may include the following steps:

[0065] S201 : In response to a request from a client to connect to a database, determine a connection handle of a first database connection whose connection state is idle according to at least one database connection information stored in a first hash table of a connection pool.

[0066] The first hash table is a data structure with a high search speed. For example, the first hash table may be a SwissTable. SwissTable is a high-performance hash table that can provide faster search, insertion, and deletion operations while maintaining low memory overhead.

[0067] The database connection information is information related to a database connection created in the connection pool. The database connection information includes a first key-value pair, wherein the key in the first key-value pair is used to represent the connection state of the database connection, and the value in the first key-value pair is used to represent the connection handle of the database connection.

[0068] For example, the connection status of a database connection may include active, idle, invalid, and disconnected states. The active state indicates that the database connection is assigned to a client for use, the idle state indicates that the database connection is not assigned, the invalid state indicates that the database connection can no longer be used normally due to timeout, network anomaly, or server restart, and the disconnected state indicates that the database connection has been explicitly closed by the database server or network layer and can no longer be restored.

[0069] Taking the first hash table as SwissTable as an example, SwissTable stores at least one database connection information, where the key in the database connection information represents the connection status of the database connection, and the value represents the connection handle of the database connection. For example, if the key in the database connection information represents an active state, then this indicates that the database connection corresponding to the database connection information has been allocated to a client for use. Based on the SwissTable, the storage location of the database connection information for the first database connection with an idle state can be determined in the SwissTable based on the key representing the idle state, and the value in the database connection information corresponding to the first database connection, i.e., the connection handle of the first database connection, can be obtained.

[0070] S202: Send a connection handle of the first database connection to the client.

[0071] The database connection information of the first database connection stores the connection handle of the first database connection. For example, if the first hash table is SwissTable, SwissTable stores the database connection information of the first database connection, and the value in the database connection information of the first database connection is the connection handle of the first database connection. After the first database connection is determined based on the key, the value in the database connection information of the first database connection can be read and sent to the client, i.e., the connection handle of the first database connection.

[0072] In the connection pool management method of the present application, a connection pool can, in response to a client's request to connect to a database, determine a connection handle for a first database connection with an idle state based on at least one database connection information stored in a first hash table of the connection pool, and send the connection handle of the first database connection to the client. Because the connection pool can quickly search for database connections with an idle state in the hash table using a key in the hash table and obtain the corresponding connection handle, the speed of searching for idle database connections in the connection pool is improved, thereby reducing the time it takes for the client to connect to the database.

[0073] The following uses SwissTable as an example to illustrate the connection pool management method proposed in this application.

[0074] Optionally, the database connection information further includes first metadata corresponding to the first key-value pair, where the first metadata is used to represent a slot status of a slot storing the database connection information.

[0075] In this manner, a connection handle of a first database connection whose connection state is idle is determined based on at least one database connection information stored in a first hash table of a connection pool. At least one slot corresponding to a key representing the connection state as idle in the first hash table can be determined, and a first slot of the at least one slot is used as a target slot. When the slot state represented by the first metadata in the target slot is a storage state, the connection handle in the target slot is determined as the connection handle of the first database connection. When the slot state represented by the first metadata in the target slot is empty or a deleted state, this step is repeated with the next slot of the target slot as a new target slot until a connection handle of the first database connection is obtained.

[0076] For example, the SwissTable of the connection pool stores at least one database connection information. The database connection information in the SwissTable of the connection pool is, for example:

[0077] SwissTable{

[0078] void key[MAX_ITEMS];

[0079] void value[MAX_ITEMS];

[0080] uint8_t metedata[MAX_ITEMS];

[0081] uint64_t hashcode[MAX_ITEMS];

[0082] }

[0083] The key represents the database connection status, the value represents the database connection handle, the metedata represents the slot status of the slot storing the database connection information, and the hash code identifies the index of the element in the table. The first 57 bits of the hash value obtained by hashing the value are used as H1, and the last 7 bits of the hash value are used as H2. The hash code is H1, and metedata can be 0b1000 0000 to indicate that the slot is empty, 0b11111110 to indicate that the slot is deleted, and a combination of 0 and H2 to indicate that the slot is storing data.

[0084] Taking the first database connection as an example, after the connection pool creates the first database connection, it stores the database connection information for the first database connection in the connection pool's SwissTable. Specifically, based on the connection status of the first database connection, the value representing the connection status of the first database connection is used as the key, the connection handle of the first database connection is used as the value, the value is hashed to obtain a 64-bit value, the first 57 bits of the 64-bit value are used as the hashcode, and the 8-bit value consisting of 0 and the last 7 bits of the 64-bit value is used as metedata. The connection status of the first database connection is represented as the storage status. For example, if the last 7 bits of the 64-bit value obtained by hashing the value are 1010100, metedata is 0b0101 0100.

[0085] Based on the SwissTable of the connection pool in the above example, in response to a client's request to connect to a database, the connection handle of the first database connection in the idle state is determined based on at least one database connection information stored in the first hash table of the connection pool. For example, if 0001 represents a database connection in the idle state, the slot corresponding to the database connection with the key 0001 can be searched based on 0001, and the first slot is selected as the target slot.

[0086] If the slot state represented by the metedata of the target slot is the storage state, the value in the target slot is determined as the connection handle of the first database connection. The metedata in the target slot is 0b1000 0000, indicating that the slot state is empty, or 0b1111 1110, indicating that the slot state is deleted. Repeat this step with the next slot after the target slot as the new target slot until the connection handle of the first database connection is obtained.

[0087] The connection pool management method of the present application improves the speed of finding database connections in the idle state in the connection pool, thereby reducing the time it takes for the client to connect to the database, because the connection pool can quickly search for database connections in the idle state in the hash table through the keys in the hash table and obtain the corresponding connection handle.

[0088] Optionally, after sending the connection handle of the first database connection to the client, the connection pool may update the key corresponding to the connection handle of the first database connection to a key indicating that the connection state is active.

[0089] Illustratively, after the connection pool sends the connection handle of the first database connection to the client, the first database connection is allocated to the client for use, and the key of the first database connection can be updated from key 0001 representing an idle state to key 0010 representing an active state.

[0090] Optionally, in response to the client's operation of releasing the first database connection, the connection pool may update the key corresponding to the connection handle of the first database connection to a key indicating that the connection state is an idle state.

[0091] When a client needs to disconnect from the database, it can release the first database connection. The first database connection is then returned to the connection pool, which can then allocate it to another client. Therefore, in response to the client releasing the first database connection, the connection pool can update the key corresponding to the connection handle of the first database connection to a key indicating that the connection is in an idle state. For example, the key of the first database connection is updated from key 0010 indicating an active state to key 0001 indicating an idle state.

[0092] Optionally, the connection pool may trigger a reconnection mechanism based on a key representing a connection state of an invalid state or a disconnected state. Figure 3 A schematic diagram of the connection status of a database connection provided in an embodiment of the present application. Figure 3As shown, the connection status of the database connection can include: idle state, active state, invalid state and closed state. Taking the first hash table as the SwissTable of the connection pool as an example, the key corresponding to the SwissTable of the connection pool can be 0001 representing the idle state, 0010 representing the active state, 0011 representing the invalid state, and 1111 representing the closed state.

[0093] For example, the connection pool can periodically identify database connections in the SwissTable of the connection pool that are in an invalid or disconnected state based on the key indicating the connection state is invalid and the key indicating the connection state is closed, and trigger a reconnection mechanism. For example, the connection pool can attempt to connect to the database based on the value of the database connection, or it can recreate a new database connection.

[0094] Optionally, when the connection pool recreates a new database connection, it is necessary to delete the database connection information of the database connection with an invalid or disconnected connection state from the SwissTable of the connection pool, and store the database connection information of the newly created database connection in the SwissTable of the connection pool.

[0095] Optionally, when attempting to connect to the database according to the value of the database connection, if the database is reconnected, the key of the database connection in the SwissTable of the connection pool is updated to a key indicating that the connection state is idle.

[0096] In the connection pool management method of an embodiment of the present application, a connection pool can, in response to a client's request to connect to a database, determine a connection handle for a first database connection with an idle state based on at least one database connection information stored in a first hash table of the connection pool, and send the connection handle of the first database connection to the client. Because the connection pool can quickly search for database connections with an idle state in the hash table using a key in the hash table and obtain the corresponding connection handle, the speed of searching for idle database connections in the connection pool is improved, thereby reducing the time it takes for the client to connect to the database.

[0097] The above is an explanation of the first hash table included in the connection pool. Optionally, the connection pool may also include a second hash table corresponding to at least one database connection whose slot state is a storage state in the first hash table. The second hash table includes at least one parameter information of the database connection. The parameter information includes a second key-value pair and second metadata corresponding to the second key-value pair. The key in the second key-value pair is used to represent the identifier of the parameter of the database connection, and the value in the second key-value pair is used to represent the parameter value of the parameter. The second metadata is used to represent the slot state of the slot storing the parameter information.

[0098] Figure 4 A schematic diagram of a method for managing database connection parameters in a connection pool provided in an embodiment of the present application Figure 1 .like Figure 4 As shown, the following steps may be included:

[0099] S401: In response to a request to set a first parameter for a first database connection, determine whether a second hash table includes a key representing the first parameter.

[0100] If yes, execute S402;

[0101] If not, execute S403.

[0102] Taking the second hash table, SwissTable, which stores parameter information for database connections, as an example, key is used to represent the parameter name of the database connection parameter, value is used to represent the parameter value of the parameter, metedata is used to represent the slot status of the slot storing the parameter information, and hashcode is used to identify the index of the element in the table itself. The first 57 bits of the hash value obtained by hashing value are used as H1, the last 7 bits of the hash value are used as H2, the hashcode is H1, and metedata can be 0b1000 0000 to indicate that the slot status is empty, 0b1111 1110 to indicate that the slot status is deleted, and the combination of 0 and H2 to indicate that the slot is in storage status.

[0103] Exemplarily, in response to a setting request for a first parameter of a first database connection, the slot where the first parameter should be stored is determined in the SwissTable of the first database connection based on the hash value of the first parameter. If the slot stores data, it is determined that the second hash table includes a key representing the first parameter.

[0104] S402: Store first parameter information corresponding to the first parameter in a second hash table.

[0105] When the second hash table does not include the key representing the first parameter, the first parameter information corresponding to the first parameter is stored in the second hash table, and the second metadata in the first parameter information is used to represent that the slot state of the slot storing the first parameter information is a new parameter storage state.

[0106] Taking the storage of the first parameter information in the SwissTable of the first database connection as an example, specifically, the parameter name of the first parameter is used as the key, the value of the first parameter is used as the value, the value is hashed to obtain a 64-bit value, the first 57 bits of the 64-bit value are used as the hashcode, and the result of the AND operation of the last 7 bits of the 64-bit value and 0x80 is used as metedata, which represents the slot state of the slot storing the first parameter information as the newly added parameter storage state, that is, the first parameter is a newly added parameter in the first database connection.

[0107] For example, if the last 7 bits of the 64-bit value obtained by hashing value are 0010100, the result of the AND operation of 0010100 and 0x80 is 0b1001 0100, and the second metadata in the parameter information of the first parameter is 0b1001 0100. In this method, the highest bit of the second metadata of the newly added parameter in the SwissTable of the first database connection is 1.

[0108] S403: Update the value corresponding to the key representing the first parameter and the second metadata in the second hash table.

[0109] When the second hash table includes a key representing the first parameter, the value and second metadata corresponding to the key representing the first parameter are updated in the second hash table, and the second metadata in the first parameter information is used to represent that the slot state of the slot storing the first parameter information is a non-new parameter storage state.

[0110] Taking the parameter information of the first parameter stored in the SwissTable of the connection pool as an example, specifically, key is the parameter name of the first parameter, value is the value of the first parameter, hashcode is the first 57 bits of the 64-bit value obtained by hashing value, metedata is 0 and the 8-bit value of the last 7 bits of the 64-bit value obtained by hashing value, indicating that the slot status of the slot storing the first parameter information is a non-newly added parameter storage state, that is, the first parameter is not a new parameter in the first database connection.

[0111] The value and second metadata corresponding to the key representing the first parameter are updated in the second hash table. For example, the value can be updated with the new value of the first parameter. For example, if the last 7 bits of the 64-bit value obtained by hashing the updated value are 0010100, the second metadata in the parameter information of the first parameter is updated to 0b0001 0100. In this way, the highest bit of the second metadata of the non-newly added parameter in the SwissTable connected to the first database is 0.

[0112] Optionally, it is possible to determine whether the value corresponding to the key representing the first parameter stored in the second hash table is the same as the value to be updated based on the hashcode corresponding to the key representing the first parameter stored in the second hash table. If the value corresponding to the key representing the first parameter stored in the second hash table is the same as the value to be updated, there is no need to update the value corresponding to the key representing the first parameter and the second metadata in the second hash table.

[0113] In the connection pool management method of an embodiment of the present application, the connection pool includes a second hash table corresponding to each database connection, the second hash table includes at least one parameter information of the database connection, the parameter information includes a second key-value pair and second metadata corresponding to the second key-value pair, the key in the second key-value pair is used to represent the identifier of the parameter of the database connection, the value in the second key-value pair is used to represent the parameter value of the parameter, and the second metadata is used to represent the slot status of the slot storing the parameter information. The second metadata can represent that the slot status of the slot storing the parameter information is a non-newly added parameter storage state, or the slot status of the slot storing the parameter information is a non-newly added parameter storage state. Based on the second metadata, it is possible to distinguish whether the parameter is a newly added parameter for the database connection, so that when the client releases the database connection, different processing can be performed for the newly added parameter or the non-newly added parameter, thereby managing the parameters of the database connection.

[0114] Optionally, in response to the client's operation of releasing the first database connection, for the first parameter, when the slot state of the slot storing the first parameter information is a new parameter storage state, the first parameter information is deleted from the second hash table; when the slot state of the slot storing the first parameter information is a non-new parameter storage state, the first parameter information is restored to the value before responding to the setting request for the first parameter of the first database connection.

[0115] Figure 5 A schematic diagram of a method for managing database connection parameters in a connection pool provided in an embodiment of the present application Figure 2 .like Figure 5 As shown, in response to the client releasing the first database connection, the following steps may be included for the first parameter:

[0116] S501: Determine whether the slot status of the slot storing the first parameter information is a newly added parameter storage state.

[0117] If yes, execute S502;

[0118] If not, execute S503.

[0119] S502: Delete the first parameter information from the second hash table.

[0120] When the slot state of the slot storing the first parameter information is a newly added parameter storage state, the first parameter information is deleted from the second hash table.

[0121] Optionally, the connection pool can, based on preset rules, delete or retain the first parameter information from the second hash table when the slot state of the slot storing the first parameter information is a newly added parameter storage state. For example, if the connection pool determines that the first parameter is globally effective, that is, when the first database connection is subsequently assigned to any client, the first parameter is still effective for the client's database connection. If the first parameter is determined to be globally effective, the connection pool retains the first parameter information in the second hash table for the first database connection. If the first parameter is determined to be non-globally effective, the first parameter information is deleted from the second hash table.

[0122] S503: Restore the first parameter information to a value before responding to the setting request for the first parameter of the first database connection.

[0123] Optionally, when the connection pool updates the value corresponding to the key representing the first parameter and the second metadata in the second hash table, the connection pool stores the value corresponding to the key of the first parameter in the connection pool. In this manner, the connection pool responds to the client's operation of releasing the first database connection, and when the slot state of the slot storing the first parameter information is a non-new parameter storage state, the connection pool restores the first parameter information to the value before responding to the setting request for the first parameter of the first database connection.

[0124] Optionally, if the slot state of the slot storing the first parameter information is a non-new parameter storage state, the first parameter information is retained or restored to the value before the response to the setting request for the first parameter of the first database connection. For example, the connection pool determines that the first parameter is globally effective, that is, when the first database connection is subsequently assigned to any client, the first parameter is still effective for the client connection database. If the first parameter is determined to be globally effective, the connection pool retains the first parameter information in the second hash table of the first database connection and does not change the first parameter information. If the first parameter is determined to be non-globally effective, the first parameter information is retained or restored to the value before the response to the setting request for the first parameter of the first database connection.

[0125] The connection pool management method of the embodiment of the present application includes a second hash table corresponding to each database connection in the connection pool, the second hash table includes at least one parameter information of the database connection, the parameter information includes a second key-value pair and second metadata corresponding to the second key-value pair, the key in the second key-value pair is used to represent the identifier of the parameter of the database connection, the value in the second key-value pair is used to represent the parameter value of the parameter, and the second metadata is used to represent the slot status of the slot storing the parameter information. Among them, the second metadata can represent that the slot status of the slot storing the parameter information is a non-newly added parameter storage state, or the slot status of the slot storing the parameter information is a non-newly added parameter storage state. According to the second metadata, it can be distinguished whether the parameter is a new parameter for the database connection. When the client releases the database connection, the new parameter can be deleted or the non-newly added parameter can be restored to better manage the parameters of the database connection and ensure the accuracy of the parameters of the database connection when the database connection is subsequently allocated to any client.

[0126] The above is a description of the method embodiment of the present application. The following is a description of the device provided in the embodiment of the present application.

[0127] Figure 6 This is a schematic diagram of the structure of a connection pool management device provided in an embodiment of the present application. Figure 6 As shown, the database access device 600 may include, for example, a determination module 601 and a sending module 602. Optionally, it may also include an update module and a parameter setting module.

[0128] Determining module 601 is configured to, in response to a request from a client to connect to a database, determine a connection handle of a first database connection whose connection state is idle based on at least one database connection information stored in a first hash table of a connection pool, wherein the database connection information includes a first key-value pair, the key in the first key-value pair being used to represent the connection state of the database connection, and the value in the first key-value pair being used to represent the connection handle of the database connection;

[0129] The sending module 602 is configured to send the connection handle of the first database connection to the client.

[0130] In one possible implementation, the database connection information also includes first metadata corresponding to the first key-value pair, where the first metadata is used to represent the slot status of the slot storing the database connection information; the determination module 601 is specifically used to determine at least one slot corresponding to a key in the first hash table representing a connection status of an idle state, and use the first slot of the at least one slot as the target slot; when the slot status represented by the first metadata in the target slot is a storage state, determine the connection handle in the target slot as the connection handle of the first database connection; when the slot status represented by the first metadata in the target slot is empty or deleted, repeat this step with the slot next to the target slot as the new target slot until the connection handle of the first database connection is obtained.

[0131] In a possible implementation, the update module is specifically configured to update the key corresponding to the connection handle of the first database connection to a key indicating that the connection state is active.

[0132] In a possible implementation, the update module is further configured to, in response to the client releasing the first database connection, update the key corresponding to the connection handle of the first database connection to a key indicating that the connection state is an idle state.

[0133] In one possible implementation, the connection pool includes a second hash table corresponding to each of at least one database connections whose slot status in the first hash table is a storage state, the second hash table including at least one parameter information of the database connection, the parameter information including a second key-value pair and second metadata corresponding to the second key-value pair, the key in the second key-value pair being used to represent an identifier of a parameter of the database connection, the value in the second key-value pair being used to represent a parameter value of the parameter, and the second metadata being used to represent a slot status of the slot storing the parameter information; accordingly, the parameter setting module is further configured to, in response to a setting request for a first parameter of the first database connection, determine whether the second hash table includes a key representing the first parameter; if the second hash table does not include a key representing the first parameter, store the first parameter information corresponding to the first parameter in the second hash table, the second metadata in the first parameter information being used to represent that the slot status of the slot storing the first parameter information is a newly added parameter storage state; if the second hash table includes a key representing the first parameter, update the value and second metadata corresponding to the key representing the first parameter in the second hash table, the second metadata in the first parameter information being used to represent that the slot status of the slot storing the first parameter information is a non-newly added parameter storage state.

[0134] Correspondingly, the parameter setting module is also used to, in response to the client's operation of releasing the first database connection, for the first parameter, when the slot state of the slot storing the first parameter information is a new parameter storage state, delete the first parameter information from the second hash table; and when the slot state of the slot storing the first parameter information is a non-new parameter storage state, restore the first parameter information to the value before responding to the setting request for the first parameter of the first database connection.

[0135] The device provided in the embodiment of the present application can execute the above method embodiment, and its implementation principle and technical effects are similar, which will not be repeated here.

[0136] It should be understood that the above-described device embodiments are merely illustrative, and the device of the present application may also be implemented in other ways. For example, the division of units / modules in the above-described embodiments is merely a logical functional division, and actual implementations may employ other division methods. For example, multiple units, modules, or components may be combined or integrated into another system, or some features may be omitted or not implemented.

[0137] Figure 7 This is a schematic diagram of the structure of an electronic device provided in an embodiment of the present application. Figure 7 As shown, the electronic device may include: at least one processor 701 and a memory 702.

[0138] The memory 702 is used to store programs. Specifically, the programs may include program codes, and the program codes include computer operation instructions.

[0139] The memory 702 may include a high-speed RAM memory, and may also include a non-volatile memory.

[0140] The processor 701 is configured to execute computer-executable instructions stored in the memory 702 to implement the method of the aforementioned method embodiment. The processor 701 may be a central processing unit (CPU), an application-specific integrated circuit (ASIC), or one or more integrated circuits configured to implement the embodiments of the present application.

[0141] Optionally, the electronic device may further include a communication interface 703. In specific implementation, if the communication interface 703, the memory 702 and the processor 701 are implemented independently, the communication interface 703, the memory 702 and the processor 701 may be interconnected via a bus and communicate with each other.

[0142] Optionally, in a specific implementation, if the communication interface 703, the memory 702 and the processor 701 are integrated on a chip, the communication interface 703, the memory 702 and the processor 701 can complete communication through an internal interface.

[0143] The present application also provides a computer-readable storage medium, which may include: a USB flash drive, a mobile hard disk, a read-only memory (ROM), a random access memory (RAM), and other media that can store program codes. Specifically, the computer-readable storage medium stores program instructions, which are used to implement the actions of the above-mentioned method implementation method.

[0144] The present application also provides a computer program product, which includes a computer program, and when the computer program is executed by a processor, the actions of the above method implementation are implemented.

[0145] In addition, unless otherwise specified, the functional units / modules in the various embodiments of the present application may be integrated into a single unit / module, each unit / module may exist physically separately, or two or more units / modules may be integrated together. The aforementioned integrated units / modules may be implemented in the form of hardware or software program modules.

[0146] If an integrated unit / module is implemented in hardware, the hardware may be digital circuits, analog circuits, or other similar devices. The physical implementation of the hardware structure includes, but is not limited to, transistors. Unless otherwise specified, a processor may be any suitable hardware processor, such as a CPU, GPU, FPGA, DSP, or ASIC. Unless otherwise specified, a storage unit may be any suitable storage medium, such as resistive random access memory (RRAM), dynamic random access memory (DRAM), static random access memory (SRAM), enhanced dynamic random access memory (EDRAM), high-bandwidth memory (HBM), or hybrid memory cube (HMC).

[0147] If the integrated unit / module is implemented in the form of a software program module and sold or used as an independent product, it can be stored in a computer-readable memory. Based on this understanding, the technical solution of the present application, 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 memory and includes a number of instructions for enabling a computer device (which can be a personal computer, server, or network device, etc.) to execute all or part of the steps of the various embodiments of the present application. The aforementioned memory includes various media that can store program code, such as USB flash drives, read-only memories (ROMs), random access memories (RAMs), and mobile hard drives.

[0148] In the above embodiments, the description of each embodiment has its own emphasis. For parts not described in detail in a particular embodiment, please refer to the relevant description of other embodiments. The technical features of the above embodiments can be combined in any way. To keep the description concise, 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 specification.

[0149] Those skilled in the art will appreciate that all or part of the steps in the above-described method embodiments can be implemented by hardware associated with program instructions. The aforementioned program can be stored in a computer-readable storage medium. When executed, the program performs the steps of the above-described method embodiments. The aforementioned storage medium includes various media capable of storing program code, such as ROM and RAM.

Claims

1. A connection pool management method, characterized in that: include: In response to a request from a client to connect to a database, determining a connection handle of a first database connection whose connection state is idle based on at least one database connection information stored in a first hash table of a connection pool, wherein the database connection information includes a first key-value pair, the key in the first key-value pair is used to represent the connection state of the database connection, and the value in the first key-value pair is used to represent the connection handle of the database connection; Send the connection handle of the first database connection to the client.

2. The method according to claim 1, characterized in that The database connection information further includes first metadata corresponding to the first key-value pair, where the first metadata is used to represent a slot status of a slot storing the database connection information; The step of determining the connection handle of the first database connection whose connection state is idle according to at least one database connection information stored in the first hash table of the connection pool includes: Determine at least one slot corresponding to a key representing an idle connection state in the first hash table, and use a first slot of the at least one slot as a target slot; If the slot state represented by the first metadata in the target slot is a storage state, the connection handle in the target slot is determined as the connection handle of the first database connection. If the slot state represented by the first metadata in the target slot is empty or a deletion state, this step is repeated with the slot next to the target slot as a new target slot until the connection handle of the first database connection is obtained.

3. The method according to claim 2, characterized in that Also includes: The key corresponding to the connection handle of the first database connection is updated to a key indicating that the connection state is active.

4. The method according to claim 2, characterized in that Also includes: In response to the client's operation of releasing the first database connection, the key corresponding to the connection handle of the first database connection is updated to a key indicating that the connection state is an idle state.

5. The method according to any one of claims 1 to 4, characterized in that The connection pool includes a second hash table corresponding to at least one database connection whose slot state in the first hash table is a storage state, the second hash table includes at least one parameter information of the database connection, the parameter information includes a second key-value pair and second metadata corresponding to the second key-value pair, the key in the second key-value pair is used to represent an identifier of a parameter of the database connection, the value in the second key-value pair is used to represent a parameter value of the parameter, and the second metadata is used to represent a slot state of a slot storing the parameter information; The method further comprises: In response to a request to set a first parameter for the first database connection, determining whether the second hash table includes a key representing the first parameter; If the second hash table does not include a key representing the first parameter, first parameter information corresponding to the first parameter is stored in the second hash table, and second metadata in the first parameter information is used to indicate that the slot state of the slot storing the first parameter information is a newly added parameter storage state; When the second hash table includes the key representing the first parameter, the value and second metadata corresponding to the key representing the first parameter are updated in the second hash table, and the second metadata in the first parameter information is used to represent that the slot state of the slot storing the first parameter information is a non-new parameter storage state.

6. The method according to claim 5, characterized in that Also includes: In response to the client releasing the first database connection, for the first parameter, if the slot state of the slot storing the first parameter information is a new parameter storage state, deleting the first parameter information from the second hash table; When the slot state of the slot storing the first parameter information is a non-newly added parameter storage state, the first parameter information is restored to a value before responding to the setting request for the first parameter of the first database connection.

7. A connection pool management device, characterized in that: include: a determining module, configured to, in response to a request from a client to connect to a database, determine a connection handle of a first database connection whose connection state is idle based on at least one database connection information stored in a first hash table of a connection pool, wherein the database connection information includes a first key-value pair, the key in the first key-value pair being used to represent the connection state of the database connection, and the value in the first key-value pair being used to represent the connection handle of the database connection; A sending module is used to send the connection handle of the first database connection to the client.

8. An electronic device, characterized in that: include: a processor, and a memory communicatively connected to the processor; The memory stores computer-executable instructions; The processor executes the computer-executable instructions stored in the memory to implement the method according to any one of claims 1 to 6.

9. A computer-readable storage medium, characterized in that The computer-readable storage medium stores computer-executable instructions, which are used to implement the method according to any one of claims 1 to 6 when executed by a processor.

10. A computer program product, characterized in that The invention comprises a computer program, which implements the method according to any one of claims 1 to 6 when being executed by a processor.