Session state processing method, device, equipment and storage medium

By receiving and processing session tracking information to update session status, the connection is not reusable due to front-end connection locking, and the Session state consistency and connection multiplexing rate are improved.

CN113297305BActive Publication Date: 2025-09-02ALIBABA GROUP HOLDING LTD
View PDF 1 Cites 0 Cited by

Patent Information

Application Number
CN202010688242.X
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2020-07-16
Publication Date
2025-09-02
Estimated Expiration
2040-07-16

AI Technical Summary

Technical Problem

In the prior art, in order to ensure the correctness of the Session state, the front and back end connections are locked, resulting in the back end connection being unable to be multiplexed by other front end connections, reducing the reusability rate of the connection.

Method used

By sending a first connection request to the database, receiving and processing session tracking information, updating the session status information, and matching the target backend connection according to the session status information, avoiding locking the front and backend connections.

Benefits of technology

The Session status consistency of front-end connections is realized, which avoids decoding problems and improves the multiplexing rate of back-end connections.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN113297305B_ABST
    Figure CN113297305B_ABST
Patent Text Reader

Abstract

The embodiments of the present application provide a session state processing method, apparatus, device, and storage medium to address the problem in the prior art of locking the front-end and back-end connections to ensure the correctness of the session state, resulting in the back-end connection being unable to be reused by other front-end connections. The method comprises: sending a first connection request to a database; receiving a processing result fed back by the database, and obtaining session tracking information carried in the processing result; wherein the session tracking information includes at least a first type, a first keyword, and a first value of the first session corresponding to the first connection request; and updating the first session state information of the first session based on the session tracking information to ensure the correctness of the session state of the first session.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the field of computer technology, and in particular to a session state processing method and device, an electronic device, and a storage medium. Background Art

[0002] In the database field, in order to reduce the number of backend connections (backend connections are connections from database proxies to databases), services that use long and short database connections often use a multiplexed connection pool to select backend connections.

[0003] Currently, when a connection request is received from a front-end (client-to-database proxy), multiplexing connection pool implementations typically directly select a back-end connection to execute the request. However, different requests have different session states, and directly reusing a back-end connection can cause decoding issues. For example, if a front-end connection with a session character set set to Latin1 (Latin1 is an alias for the single-byte encoding ISO-8859-1) is reused with a back-end connection using the Universal Character Set / Unicode Transformation Format (UTF-8) character set, the retrieved text data will not be decodable on the client. Therefore, the correctness of the session state must be ensured when selecting a back-end connection.

[0004] In the prior art, to ensure the correctness of session states, frontend and backend connections are typically locked. After receiving a client connection request, the database proxy parses the received Structured Query Language (SQL) to obtain the session state change statement for this request. During this process, the database proxy locks the frontend and backend connections to ensure session state consistency. However, locking the frontend and backend connections prevents the backend connection from being reused by other frontend connections, reducing the backend connection's reusability. Summary of the Invention

[0005] The embodiment of the present application provides a session state processing method to solve the problem in the prior art that, in order to ensure the correctness of the session state, the front-end and back-end connections are locked, resulting in the back-end connection being unable to be reused by other front-end connections.

[0006] Correspondingly, an embodiment of the present application also provides a session state processing device, an electronic device, and a storage medium to ensure the implementation and application of the above method.

[0007] In order to solve the above problems, an embodiment of the present application discloses a session state processing method, which includes:

[0008] Sending a first connection request to the database;

[0009] Receive the processing result fed back by the database, and obtain session tracking information carried in the processing result; wherein the session tracking information at least includes the first type, first keyword and first value of the first session corresponding to the first connection request; and update the first session state information of the first session according to the session tracking information.

[0010] The present application discloses a method for processing a session state, the method comprising:

[0011] receiving a second connection request from the client, and obtaining second session state information of a second session corresponding to the second connection request;

[0012] Match a target backend connection for the second connection request based on the second session state information; wherein, the first session state information of the first session corresponding to the target backend connection includes the second session state information; the first session state information is determined based on session tracking information of the target backend connection fed back by a database.

[0013] The present application discloses a method for processing a session state, the method comprising:

[0014] receiving and processing a first connection request from a database agent;

[0015] Feedback a processing result to the database agent, and carry session tracking information in the processing result; wherein the session tracking information at least includes a first type, a first keyword, and a first value of a first session command corresponding to the first connection request.

[0016] The present application also discloses a session state processing device, which includes:

[0017] A request sending module, configured to send a first connection request to the database;

[0018] a first information acquisition module, configured to receive a processing result fed back by the database and acquire session tracking information carried in the processing result; wherein the session tracking information includes at least a first type, a first keyword, and a first value of the first session corresponding to the first connection request;

[0019] A state updating module is configured to update first session state information of the first session according to the session tracking information.

[0020] The present application also discloses a session state processing device, which includes:

[0021] a third information acquisition module, configured to receive a second connection request from the client, and acquire second session state information of a second session corresponding to the second connection request;

[0022] A backend connection matching module is configured to match a target backend connection for the second connection request based on the second session state information; wherein the first session state information of the first session corresponding to the target backend connection includes the second session state information; and the first session state information is determined based on session tracking information of the target backend connection fed back by a database.

[0023] The present application also discloses a session state processing device, which includes:

[0024] A request receiving module, configured to receive and process a first connection request from a database agent;

[0025] A result feedback module is used to feed back a processing result to the database agent, and carry session tracking information in the processing result; wherein the session tracking information at least includes a first type, a first keyword, and a first value of a first session command corresponding to the first connection request.

[0026] The embodiment of the present application also discloses a data processing system, including: a client, a database agent and a database;

[0027] Wherein, the database agent is used to:

[0028] Sending a first connection request to the database;

[0029] receiving a processing result fed back by the database, and obtaining session tracking information carried in the processing result; wherein the session tracking information includes at least a first type, a first keyword, and a first value of the first session corresponding to the first connection request;

[0030] updating first session state information of the first session according to the session tracking information;

[0031] receiving a second connection request from the client, and obtaining second session state information of a second session corresponding to the second connection request;

[0032] matching a target backend connection for the second connection request based on the second session state information; wherein the first session state information of the first session corresponding to the target backend connection includes the second session state information; and the first session state information is determined based on session tracking information of the target backend connection fed back by a database;

[0033] The database is used to:

[0034] receiving and processing a first connection request from the database agent;

[0035] Feedback the processing result to the database agent, and carry the session tracking information in the processing result.

[0036] An embodiment of the present application further discloses an electronic device, comprising: a processor; and a memory on which executable code is stored. When the executable code is executed, the processor executes one or more methods described in the embodiments of the present application.

[0037] The embodiments of the present application also disclose one or more machine-readable storage media on which executable codes are stored. When the executable codes are executed, the processor executes one or more methods described in the embodiments of the present application.

[0038] Compared with the prior art, the embodiments of the present application have the following advantages:

[0039] In an embodiment of the present application, when the database responds to a first connection request from a database proxy, it carries session tracking information. The database proxy updates the first session state information of the first session based on the session tracking information to ensure the correctness of the session state of the first session. Thus, when the database proxy is servicing a front-end connection, it can match the front-end connection based on the state information of each back-end connection in the connection pool, ensuring consistent session states for the front-end and back-end connections and avoiding decoding issues. Furthermore, during the matching process, since the back-end connection's session state is updated in real time, there is no need to lock the front-end and back-end connections, which can improve the reuse rate of back-end connections. BRIEF DESCRIPTION OF THE DRAWINGS

[0040] Figure 1 This is one of the application diagrams of a session state processing according to an embodiment of the present application;

[0041] Figure 2 This is the second application diagram of a session state processing according to an embodiment of the present application;

[0042] Figure 3 This is a flowchart of another embodiment of a session state processing method of the present application;

[0043] Figure 4 This is a flowchart of another embodiment of a session state processing method of the present application;

[0044] Figure 5 This is a flowchart of another embodiment of a session state processing method of the present application;

[0045] Figure 6 This is a structural block diagram of an embodiment of a session state processing device of the present application;

[0046] Figure 7 This is a structural block diagram of another embodiment of a session state processing device of the present application;

[0047] Figure 8 This is a structural block diagram of another embodiment of a session state processing device of the present application;

[0048] Figure 9 This is a structural block diagram of another embodiment of a session state processing device of the present application;

[0049] Figure 10 is a structural diagram of a data processing system provided in one embodiment of the present application;

[0050] Figure 11 It is a structural diagram of a device provided in one embodiment of the present application. DETAILED DESCRIPTION

[0051] In order to make the above-mentioned purposes, features and advantages of the present application more obvious and easy to understand, the present application is further described in detail below with reference to the accompanying drawings and specific implementation methods.

[0052] The terms "first," "second," and the like in the specification and claims of this application are used to distinguish similar objects, and are not used to describe a particular order or precedence. It should be understood that the terms used in this manner are interchangeable where appropriate, so that the embodiments of the present application can be implemented in orders other than those illustrated or described herein.

[0053] The embodiments of the present application can be applied to data processing fields such as databases, providing data addition, query, update, and deletion operations to clients in these fields. Session state information is maintained based on the session tracking information, ensuring consistency between the session states of front-end and back-end connections, thus avoiding decoding issues. Furthermore, during the matching process, since the back-end connection's session state is updated in real time, locking the front-end and back-end connections is not required, thereby increasing the reuse rate of back-end connections.

[0054] like Figure 1 As shown, Figure 1 A schematic diagram of an application scenario of an embodiment of the present application is shown. Figure 1 In the example, client 1 and client 2 are database clients. When a client needs to connect to a database, it first sends a connection request to the database proxy and establishes a connection. The connection established between the client and the database proxy is a front-end connection. Figure 1 As shown in the figure, front-end connection 1 and front-end connection 2; it can be understood that each client can establish one or more front-end connections with the database proxy. Figure 1In the embodiment of the present application, the database proxy can be interchangeable with the database proxy server, and the database proxy can be a jump server (also known as a bastion server).

[0055] When maintaining a connection between a client and a database, either a persistent connection or a short connection can be used. Specifically, a persistent connection maintains the connection between the client and the server for an extended period of time. When there is no data communication, a persistent connection periodically sends data packets to maintain the connection. Persistent connections are primarily used in scenarios where a small number of clients frequently communicate with the database. Frequent short connections in such scenarios can easily lead to socket errors, and frequently creating socket connections is a waste of resources. However, persistent connections also consume resources on the server side, requiring a dedicated thread (process management can be used in Unix environments) to maintain the connection. Therefore, the choice between persistent and short connections depends on the specific situation.

[0056] When using the database persistent connection service, clients may establish a large number of idle connections with the database. For example, if multiple clients connect directly to the database and establish a large number of connections, the number of concurrent requests received by the database will be far less than the number of connections, as not all connections are active. In this case, maintaining a large number of idle connections is very expensive for the database itself. Therefore, these connections are maintained by the database proxy to reduce the number of connections established with the database.

[0057] For services that use short connections, it improves the utilization efficiency of database connections by multiplexing database long connections; when processing continuous short connection requests, the database proxy can reuse existing long connections to avoid repeated connection establishment and reduce resource consumption for connection establishment.

[0058] For example, when querying data, a client sends a connection request to the database proxy, requesting a front-end connection. After receiving the connection request, the database proxy matches the front-end connection with a back-end connection. During this matching process, a back-end connection with the same session state must be used to match the front-end connection. Therefore, the correct session state of the back-end connection must be ensured.

[0059] Specifically, a session is used by the database to manage client state. The client stores actual data in the database. Each client's data is uniquely keyed by a session ID. The database uses this key to verify the client's identity. Session state includes parameters, variables, and temporary tables for the current connection. Each session's state is independent of the others.

[0060] In step 101, a database agent sends a first connection request to a database.

[0061] The first connection request is used to request a connection with the database, i.e., a backend connection. Once the frontend connection matches the backend connection, the client can perform data processing operations, such as adding, querying, updating, and deleting. For example, when performing user profiling, the client can pre-store a large amount of user parameters, such as physiological parameters and behavioral data, in the database. The database then creates a data table for the client to store the user data. When the client subsequently needs to perform data processing operations, it first sends a frontend connection request to the data proxy, establishing a connection between the client and the database through the database proxy.

[0062] Alternatively, as Figure 1 As shown, when client 1 sends a connection request for front-end connection 1 to the database proxy, it carries the Session state of the front-end connection.

[0063] After receiving the connection request, the database agent generates a first connection request based on the Session status of the front-end connection and sends it to the database, such as generating a message for setting the Session status and carrying the message in the first connection request, so that the Session status of the first connection request remains consistent with the front-end connection.

[0064] The backend connection used by the database proxy to send the first connection request to the database can be a reused backend connection of another persistent connection, or it can establish an existing connection with the database. For example, if the frontend connection used by the client to send the connection request to the database proxy is bound to a backend connection, the first connection request is sent using that backend connection. If not, the database proxy establishes a connection with the database to send the first connection request.

[0065] In step 102, the database agent receives the processing result fed back by the database and obtains the session tracking information carried in the processing result; wherein the session tracking information at least includes the first type, first keyword and first value of the first session corresponding to the first connection request.

[0066] Among them, after receiving the first connection request, the database responds to the first connection request, processes the data processing operation requested by the first connection request, and obtains the data processing result of the processing operation; the data processing result is the processing result for the data processing operation, for example, when the data processing operation is an add or delete operation, the data processing result is whether the add or delete operation is completed; in addition, the processing result may also include a data part, that is, the result data corresponding to the processing operation, for example, if the data processing operation is a query operation, the data processing result is the query data queried.

[0067] In addition to the data processing results, the processing results also include session tracking information (Session Track). Session tracking information is a field in the database message protocol that the server (i.e., the database) sends to the client. It is used to maintain the connection status between the database and the client. Session tracking information may include the type, keyword, and value of the executed session command (SessionCommand).

[0068] Specifically, the type represents the type of session command, such as system variables, user variables, or creating a temporary table. The keyword represents the name of the session command. For example, for a variable, the keyword is the variable name; for creating a temporary table, the keyword is the table name. The value represents the content of the session command. For example, for a variable, the value is the variable value; for creating a temporary table, the value is the temporary table creation statement. Each session command's triple consisting of type, keyword, and value uniquely identifies a session command. From each triple, a database-executable SQL statement can be restored. After sending this SQL statement to the database, the current connection can completely restore the session state represented by this session command.

[0069] Combine Figure 1 After processing the first connection request sent from the database proxy through the backend connection 1, the database processes the data processing operation in the first connection request to obtain a data processing result; and obtains the session tracking information of the first session corresponding to the first connection request, and sends the session tracking information and the data processing result as a processing result to the database proxy.

[0070] In step 103, the database agent updates the first session state information of the first session according to the session tracking information.

[0071] The database proxy updates the first session state information of the first session based on the session tracking information to ensure the correctness of the session state of the first session. Thus, when the database proxy is servicing a front-end connection, it can match the front-end connection based on the state information of each back-end connection in the connection pool, ensuring consistent session states between the front-end and back-end connections and avoiding decoding issues. Furthermore, during the matching process, since the back-end connection session state is updated in real time, there is no need to lock the front-end and back-end connections, thereby improving the reuse rate of back-end connections.

[0072] In addition, in the prior art, database proxies use a whitelist approach to determine the legality of session state changes. A session state whitelist is used to record legal parameters, and for legal parameters, the session state change is assumed to be legal. For parameters outside the whitelist, no session state determination is performed. This results in unexpected anomalies if the front-end connection does not match the session state when selecting the back-end connection. In the embodiments of the present application, the session state of the front-end and back-end connections is recorded through session tracking information. When matching a front-end connection with a back-end connection, the database proxy can match the session state of the front-end connection with the back-end connection to ensure consistency within the session, thereby avoiding the aforementioned problem.

[0073] Existing methods for obtaining session commands by parsing SQL statements have certain limitations. For example, if a user uses a statement like "set a=@b;," which assigns the value of variable b to a, the exact value of a is unknown. To ensure the correctness of the session state, the backend connection and the frontend connection must be locked to avoid unexpected results, but this significantly reduces connection reusability. As the actual executor of SQL statements, the database can determine the exact value. Therefore, the session tracking information returned by the database can be used to obtain the exact value of the session command, eliminating the need to lock the connection and ensuring connection reusability.

[0074] In an optional embodiment, the database agent performs step 103 including:

[0075] Performing data processing on the session tracking information to obtain first processed data, where the data format of the first processed data is a Map data structure;

[0076] The session state information of the first session is updated to the first processing data.

[0077] See also Figure 1After receiving the processing results returned by the database and extracting the session tracking information from the processing results, the database proxy needs to save the session tracking information as the session state information of the first session. Since the session tracking information is a complete string, it occupies a large amount of memory. To improve efficiency, the session tracking information can be converted into the first processing data of a Map data structure. The Map data structure is a simple data structure that can be efficiently added, deleted, modified, and searched. The Map data structure stores data in a key-value format and searches for the value based on the key. The key value is unique and cannot be repeated in the same Map container.

[0078] In this way, the database agent updates the session state information of the first session to the first processed data to reduce the memory usage of the session state information of a large number of sessions; at the same time, the character form of the Map data structure is more concise than the original string. In the process of matching the front-end connection with the back-end connection, by matching the session state information of the Map data structure, the matching efficiency can be improved compared to matching the original string.

[0079] In an optional embodiment, the database agent processes the session tracking information to obtain first processed data, performs hash processing on the first type and the first keyword to obtain a first hash value; and performs hash processing on the first value to obtain a second hash value.

[0080] The first Hash value is a Map keyword of the first processed data, and the second Hash value is a Map value of the first processed data.

[0081] Specifically, the first type represents the type of session command of the first session, such as a system variable, a user variable, or a temporary table creation type; the first keyword represents the name of the session command of the first session, such as for a variable, the first keyword is the variable name; for creating a temporary table, the first keyword is the table name. The first value represents the content of the session command of the first session, such as for a variable, the first value is the variable value; for creating a temporary table, the first value is the table creation statement for the temporary table. During data processing of the session tracking information, the first type and the first keyword are hashed to obtain a first hash value, that is, the first hash value is the hash value of (first type + first keyword); the first value is hashed to obtain a second hash value, that is, the second hash value is the hash value of the first value.

[0082] After obtaining the first hash value and the second hash value respectively, the first hash value is used as the Map keyword (i.e., value), and the second hash value is used as the Map value (i.e., key). In this way, a complete Map data structure is obtained; the session state information is saved in the form of key-value. When matching the session state information later, the value can be found according to the key, that is, the value can be found according to the type + keyword. After obtaining the type, keyword, and value, a session command can be uniquely determined.

[0083] In the process of the database proxy processing the front-end connection, receiving a second connection request from the client, and obtaining second session state information of a second session corresponding to the second connection request;

[0084] A target backend connection is matched for the second connection request according to the second session state information.

[0085] The client of the database proxy is the client of the database, such as Figure 1 As shown in Client 1 and Client 2, when a client needs to connect to the database, such as to add, query, update, or delete data, it first sends a connection request to the database proxy and establishes a connection. The connection established between the client and the database proxy is the front-end connection, as shown in Figure 1 As shown in the figure, the front-end connection 1 and the front-end connection 2 are shown in the figure. The front-end connection can be a long connection or a short connection. The long connection establishes or maintains the back-end connection with the database. The short connection can reuse the back-end connection of the long connection, which can avoid repeated connection establishment and reduce resource consumption for connection establishment.

[0086] When the database proxy receives a second connection request from the client, it parses the second connection request and obtains the second session state information of the second session therein. The second session state information is the session state information of the front-end connection. After obtaining the second session state information, the database proxy matches the back-end connection including the second session state information to ensure that the front-end and back-end connection states are consistent.

[0087] Specifically, the second session state information includes at least a second type, a second keyword, and a second value. The second type represents the type of session command for the second session, such as a system variable, a user variable, or creating a temporary table. The second keyword represents the name of the session command for the second session. For example, for a variable, the second keyword is the variable name; for creating a temporary table, the second keyword is the table name. The second value represents the content of the session command for the second session. For example, for a variable, the second value is the variable value; for creating a temporary table, the second value is the temporary table creation statement. Accordingly, the second session state information can also be converted into a Map data structure, where the Map keyword of the second session state information is the hash value of (second type + second keyword).

[0088] The target session state information of the target session corresponding to the backend connection includes the second session state information, and the session command of the backend connection also needs to include the session command of the frontend connection, and the corresponding values ​​are the same. For example, if the session command state of the second session is "a=1, b=1", then a backend connection with session state information of "a=1, b=2" or "a=1, c=1" cannot match the frontend connection of the second session; however, a backend connection with session state information of "a=1, b=1" or "a=1, b=1, c=1" can match the frontend connection of the second session.

[0089] In an optional embodiment, the database proxy matching a target backend connection for the second connection request according to the second session state information includes:

[0090] Performing data processing on the second session state information to obtain second processed data; wherein the data format of the second processed data is a Map data structure;

[0091] A target backend connection is matched for the second connection request according to the second processing data.

[0092] The database proxy first processes the second session state information to obtain second processed data, the data format of the second processed data being a Map data structure; then matches the target backend connection for the second connection request based on the second processed data; and matches the value and key of the two Map data respectively.

[0093] Specifically, the second processed data includes: a third hash value obtained by performing a third data processing on the second type and the second keyword; and a fourth hash value obtained by performing a fourth data processing on the second value; that is, the third hash value is the hash value of (second type + second keyword), and the fourth hash value is the hash value of the second value.

[0094] In this way, the third hash value is used as the Map key of the second processed data, the fourth hash value is used as the Map value of the second processed data, and the target session state information includes the third hash value and the fourth hash value. Optionally, after calculating the third hash value and the fourth hash value for each second session, the database agent may store the third hash value and the fourth hash value to avoid repeated calculation.

[0095] In an optional embodiment, when the database proxy matches a backend connection for the second session, the second session state information is processed to obtain second processed data in a Map data structure. The second processed data is then matched with the first processed data of the available backend connection. Specifically, the third and fourth hash values ​​are matched with the first and second hash values, respectively, to obtain a matching backend connection, which serves as the backend connection for the second session. Since the session state only changes when a session command is executed, the hash value only needs to be calculated when the session command is updated. During the connection matching process, it is sufficient to compare the converted hash values ​​to see if they are the same, without having to repeatedly calculate the hash value.

[0096] During the matching process, the database proxy also determines whether the second session has been pre-matched with a backend connection. For example, when the client establishes a connection with the database for the first time, if a backend connection is successfully matched, the database proxy can record the matching relationship between the backend connection and the frontend connection.

[0097] Specifically, after obtaining the second session state information of the second session corresponding to the second connection request, if the second session matches a historical backend connection, the database proxy matches the second connection request with the historical backend connection; or

[0098] If the second session does not match a historical backend connection, a target backend connection is matched for the second connection request according to the second session state information.

[0099] See also Figure 1 After receiving the second connection request from the client, the database proxy matches a backend connection based on the second session state information. It first determines whether the second session matches a historical backend connection. For example, if the second session corresponds to frontend connection 1, and frontend connection 1 and backend connection 1 are previously matched, the database proxy directly matches frontend connection 1 with backend connection 1. If the second session does not match a historical backend connection, the database proxy matches a backend connection for the second session from the connection pool. During the matching process, the backend connection with the same session state as the second session is used to ensure the correctness of the backend connection's session state.

[0100] In an optional embodiment, after the database proxy completes the front-end and back-end connection and updates the first session state information of the first session according to the session tracking information, the data processing result in the processing result is sent to the client of the first front-end connection; the data processing result, that is, the processing result for the data processing operation, needs to be fed back to the client, for example, when the data processing operation is an add or delete operation, the data processing result is whether the add or delete operation is completed; in addition, the processing result may also include a data part, that is, the result data corresponding to the processing operation, for example, if the data processing operation is a query operation, the data processing result is the query data queried.

[0101] The first front-end connection is the front-end connection corresponding to the first connection request, and thus a data interaction between the client and the database is completed.

[0102] In an optional embodiment, if the first backend connection corresponding to the first session is not locked and is not in a transaction, the first backend connection is placed in a connection pool; or

[0103] If the first backend connection is locked or the first backend connection is in a transaction, the connection state with the first backend connection is maintained.

[0104] In some cases, to ensure consistent session state, the backend connection and the frontend connection need to be bound. This backend connection cannot be reused by other frontend connections. A backend connection in this state is called a locked connection, meaning it is locked. A locked backend connection is a non-reusable connection. Being in a transaction means that the backend connection is being used by a database transaction. A database transaction refers to a sequence of database operations that accesses the database and may manipulate various data items. A transaction consists of all database operations performed between the start and end of a transaction. Each operation in the database operation sequence is either fully executed or not executed, forming an indivisible unit of work. For databases that support transactions, requests within the same transaction must ensure consistency. Therefore, if the current connection is in a transaction, the current backend connection must be prevented from being reused by other frontend connections until the current transaction ends.

[0105] In an optional embodiment, after the database agent sends the data processing result in the processing result to the client of the first front-end connection, or updates the session status information of the first back-end connection, if the first back-end connection corresponding to the first session is not locked and is not in a transaction, the first back-end connection is placed in a connection pool so that it can be reused by other front-end connections to improve the reuse rate of the back-end connection; or if the first back-end connection is locked or the first back-end connection is in a transaction, the connection state with the first back-end connection is maintained.

[0106] In an embodiment of the present application, the database proxy updates the first session state information of the first session based on the session tracking information to ensure the correctness of the session state of the first session. Thus, when the database proxy is used for a front-end connection, it can match the front-end connection based on the state information of each back-end connection in the connection pool, ensuring consistent session states for the front-end and back-end connections and avoiding decoding issues. Furthermore, during the matching process, since the back-end connection session state is updated in real time, there is no need to lock the front-end and back-end connections, thereby improving the reuse rate of the back-end connections.

[0107] As another aspect of an embodiment of the present application, the database receives and processes a first connection request from a database agent; feeds back a processing result to the database agent, and carries session tracking information in the processing result; wherein the session tracking information includes at least a first type, a first keyword, and a first value of a first session command corresponding to the first connection request.

[0108] The first connection request is used by the database proxy to request a connection with the database, i.e., a backend connection. After the frontend connection matches the backend connection, the client can perform data processing operations through the database proxy. When the client needs to perform data processing operations, it first sends a frontend connection request to the database proxy, which establishes a connection between the client and the database through the database proxy.

[0109] After receiving the first connection request, the database parses the first connection request, processes the data processing operation requested by the first connection request, and obtains a data processing result of the processing operation. The data processing result is the processing result of the data processing operation. For example, if the data processing operation is an add or delete operation, the data processing result is whether the add or delete operation is completed. In addition, the processing result may also include a data portion, namely, the result data corresponding to the processing operation. For example, if the data processing operation is a query operation, the data processing result is the query data retrieved. In addition to the data processing result, the database also includes the session tracking information in the processing result and sends it to the database agent. The database agent updates the first session state information of the first session based on the session tracking information to ensure the correctness of the session state of the first session.

[0110] Session tracking information is a field in the message sent by the server (i.e., database) to the client in the database message protocol, which is used to maintain the connection status between the database and the client; session tracking information may include the type, keyword, and value of the session command that has been executed. The type represents the type of session command, such as system variables, user variables, or the creation of temporary tables. The keyword represents the name of the session command. For example, for variables, the keyword is the variable name; for the creation of temporary tables, the keyword is the table name. The value represents the content of the session command. For example, for variables, the value is the value of the variable; for the creation of temporary tables, the value is the table creation statement of the temporary table. Each triple consisting of the type, keyword, and value of a session command can uniquely identify a session command; and from each of the triples, a database executable SQL statement can be restored; after sending this SQL statement to the database, the current connection can completely restore the session state represented by this session command.

[0111] In the above embodiment, the steps performed by the client, database agent and database are as follows: Figure 2 As shown, see Figure 2 ,In the connection establishment phase, client 1 executes step 1 and requests to establish a ,connection with the data broker.

[0112] In step 2, the database proxy verifies the identity of the client and establishes a connection with the client after the verification passes.

[0113] During the verification process, the client's identity identification number can be used for verification; if the verification fails, feedback is returned to the client to reject the connection.

[0114] In the request sending phase, step 3, client 1 sends a second connection request to the database proxy, requesting access to the database.

[0115] In step 4, the database proxy matches the first backend connection for the second connection request.

[0116] The database agent first determines whether the second session of the second connection request is bound to a historical backend connection: if so, the historical backend connection is matched for the second connection request; otherwise, the backend connection is matched according to the session state information of the second session.

[0117] In step 5, the database agent sends the first connection request to the database.

[0118] After receiving the first connection request, the database parses the first connection request, processes the data processing operation requested by the first connection request, obtains a data processing result of the processing operation, carries the session tracking information in the processing result, and sends it to the database agent.

[0119] In step 6, the database sends the processing results to the database agent.

[0120] The database agent updates the first session state information of the first session according to the session tracking information in the processing result.

[0121] In step 7, the database agent sends the data processing results to client 1, thus completing a data interaction.

[0122] In the connection closing phase, in step 8, client 1 sends a quit message to the database proxy.

[0123] In step 9, the database proxy processes the backend connection. If the first backend connection is not locked and is not in a transaction, the first backend connection is placed in the connection pool; if the first backend connection is locked or the first backend connection is in a transaction, the connection state with the first backend connection is maintained.

[0124] In step 10, the database agent sends a response message to client 1 to close the connection.

[0125] In an embodiment of the present application, when the database responds to a first connection request from a database proxy, it carries session tracking information. The database proxy updates the first session state information of the first session based on the session tracking information to ensure the correctness of the session state of the first session. Thus, when the database proxy is servicing a front-end connection, it can match the front-end connection based on the state information of each back-end connection in the connection pool, ensuring consistent session states for the front-end and back-end connections and avoiding decoding issues. Furthermore, during the matching process, since the back-end connection's session state is updated in real time, there is no need to lock the front-end and back-end connections, thereby improving the reuse rate of back-end connections.

[0126] Based on the above embodiments, the embodiments of the present application also provide a session state processing method, which can control the consistency of the session states of the front-end and back-end connections, avoid decoding problems, and improve the multiplexing rate of the back-end connections.

[0127] Reference Figure 3 , shows a step flow chart of an embodiment of a session state processing method of the present application.

[0128] Optionally, the method is applied to a database agent; Figure 3 As shown, the method includes the following steps:

[0129] Step 301: Send a first connection request to the database.

[0130] The first connection request is used to request a connection with the database, i.e., a backend connection. Once the frontend connection matches the backend connection, the client can perform data processing operations, such as adding, querying, updating, and deleting. For example, when performing user profiling, the client can pre-store a large amount of user parameters, such as physiological parameters and behavioral data, in the database. The database then creates a data table for the client to store the user data. When the client subsequently needs to perform data processing operations, it first sends a frontend connection request to the data proxy, establishing a connection between the client and the database through the database proxy.

[0131] Step 302: Receive the processing result fed back by the database, and obtain session tracking information carried in the processing result; wherein the session tracking information at least includes the first type, first keyword, and first value of the first session corresponding to the first connection request.

[0132] Among them, after receiving the first connection request, the database responds to the first connection request, processes the data processing operation requested by the first connection request, and obtains the data processing result of the processing operation; the data processing result is the processing result for the data processing operation, for example, when the data processing operation is an add or delete operation, the data processing result is whether the add or delete operation is completed; in addition, the processing result may also include a data part, that is, the result data corresponding to the processing operation, for example, if the data processing operation is a query operation, the data processing result is the query data queried.

[0133] In addition to the data processing results, the processing results also include session tracking information (Session Track). Session tracking information is a field in the database message protocol that the server (i.e., the database) sends to the client. It is used to maintain the connection status between the database and the client. Session tracking information may include the type, keyword, and value of the executed session command (SessionCommand).

[0134] Specifically, the type represents the type of session command, such as system variables, user variables, or creating a temporary table. The keyword represents the name of the session command. For example, for a variable, the keyword is the variable name; for creating a temporary table, the keyword is the table name. The value represents the content of the session command. For example, for a variable, the value is the variable value; for creating a temporary table, the value is the temporary table creation statement. Each session command's triple consisting of type, keyword, and value uniquely identifies a session command. From each triple, a database-executable SQL statement can be restored. After sending this SQL statement to the database, the current connection can completely restore the session state represented by this session command.

[0135] Step 303: Update the first session state information of the first session according to the session tracking information.

[0136] The database proxy updates the first session state information of the first session based on the session tracking information to ensure the correctness of the session state of the first session. Thus, when the database proxy is servicing a front-end connection, it can match the front-end connection based on the state information of each back-end connection in the connection pool, ensuring consistent session states between the front-end and back-end connections and avoiding decoding issues. Furthermore, during the matching process, since the back-end connection session state is updated in real time, there is no need to lock the front-end and back-end connections, thereby improving the reuse rate of back-end connections.

[0137] In one example, the step of updating the first session state information of the first session according to the session tracking information includes:

[0138] Performing data processing on the session tracking information to obtain first processed data, where the data format of the first processed data is a Map data structure;

[0139] The session state information of the first session is updated to the first processing data.

[0140] In another example, the step of processing the session tracking information to obtain first processed data includes:

[0141] Performing hash processing on the first type and the first keyword to obtain a first hash value; and performing hash processing on the first value to obtain a second hash value;

[0142] The first Hash value is a Map keyword of the first processed data, and the second Hash value is a Map value of the first processed data.

[0143] In another example, the method further includes:

[0144] receiving a second connection request from the client, and obtaining second session state information of a second session corresponding to the second connection request;

[0145] A target backend connection is matched for the second connection request according to the second session state information.

[0146] In another example, the second session state information includes at least a second type, a second keyword, and a second value;

[0147] The target session state information of the target session corresponding to the backend connection includes the second session state information.

[0148] In another example, the step of matching a target backend connection for the second connection request according to the second session state information includes:

[0149] Performing data processing on the second session state information to obtain second processed data; wherein the data format of the second processed data is a Map data structure;

[0150] A target backend connection is matched for the second connection request according to the second processing data.

[0151] In another example, the second processed data includes: a third Hash value obtained by performing a third data processing on the second type and the second keyword; and a fourth Hash value obtained by performing a fourth data processing on the second value;

[0152] The target session state information includes the third Hash value and the fourth Hash value.

[0153] In another example, after the step of obtaining the second session state information of the second session corresponding to the second connection request, the method includes:

[0154] If the second session matches a historical backend connection, matching the historical backend connection for the second connection request; or

[0155] If the second session does not match a historical backend connection, a target backend connection is matched for the second connection request according to the second session state information.

[0156] In another example, after the step of updating the first session state information of the first session according to the session tracking information, the method further includes:

[0157] The data processing result in the processing result is sent to the client of the first front-end connection; the first front-end connection is the front-end connection corresponding to the first connection request.

[0158] In another example, the method further includes:

[0159] If the first backend connection corresponding to the first session is not locked and is not in a transaction, put the first backend connection into a connection pool; or

[0160] If the first backend connection is locked or the first backend connection is in a transaction, the connection state with the first backend connection is maintained.

[0161] In some optional embodiments of the present application, after the database proxy sends a first connection request to the database, it receives a processing result fed back by the database and obtains session tracking information carried in the processing result; updates the first session state information of the first session based on the session tracking information to ensure the correctness of the session state of the first session; the session tracking information includes at least the first type, first keyword, and first value of the first session corresponding to the first connection request, and each triple consisting of the type, keyword, and value of the session command can uniquely identify a session command; and from each triple, a SQL statement executable by the database can be restored; after sending this SQL statement to the database, the current connection can completely restore the session state represented by this session command, thereby ensuring the real-time nature of the session state update based on the session tracking information. During the process of the database proxy serving the front-end connection, the front-end connection can be matched based on the state information of each back-end connection in the connection pool to achieve consistency in the session state of the front-end and back-end connections and avoid decoding problems. Moreover, during the matching process, since the Session status of the back-end connection is updated in real time, there is no need to lock the front-end and back-end connections, so the back-end connection can be kept in a reusable state, thereby improving the reuse rate of the back-end connection. This solves the problem in the prior art that, in order to ensure the correctness of the Session status, the front-end and back-end connections are locked, resulting in the back-end connection being unable to be reused by other front-end connections.

[0162] When updating the session state information of the first session, the database proxy also converts the session tracking information into first processed data of a Map data structure to reduce the memory usage of the session state information of a large number of sessions. At the same time, the character form of the Map data structure is more concise than the original character string. In the process of the database proxy matching the front-end connection with the back-end connection, the Map data structure corresponding to the session state information of the front-end connection is matched with the Map data structure corresponding to the session state information of the back-end connection. Compared with matching the original character string, the matching efficiency can be improved.

[0163] When matching or releasing a backend connection, the database proxy will identify the status of the backend connection; if the backend connection is not locked and is not in a transaction, the backend connection will be placed in the connection pool to be reused by other front-end connections, thereby improving the reuse rate of the backend connection; conversely, if the backend connection is locked or in a transaction, the connection status with the first backend connection will be maintained until the current transaction ends.

[0164] Based on the above embodiments, the embodiments of the present application also provide a session state processing method, which can control the consistency of the session states of the front-end and back-end connections, avoid decoding problems, and improve the multiplexing rate of the back-end connections.

[0165] Reference Figure 4 , shows a step flow chart of an embodiment of a session state processing method of the present application.

[0166] Optionally, the method is applied to a database agent; Figure 4 As shown, the method includes the following steps:

[0167] Step 401: Receive a second connection request from a client, and obtain second session state information of a second session corresponding to the second connection request.

[0168] The client of the database proxy is the client of the database, such as Figure 1 As shown in Client 1 and Client 2, when a client needs to connect to the database, such as to add, query, update, or delete data, it first sends a connection request to the database proxy and establishes a connection. The connection established between the client and the database proxy is the front-end connection, as shown in Figure 1 As shown in the figure, the front-end connection 1 and the front-end connection 2 are shown in the figure. The front-end connection can be a long connection or a short connection. The long connection establishes or maintains the back-end connection with the database. The short connection can reuse the back-end connection of the long connection, which can avoid repeated connection establishment and reduce resource consumption for connection establishment.

[0169] When the database proxy receives a second connection request from the client, it parses the second connection request and obtains the second session state information of the second session therein. The second session state information is the session state information of the front-end connection. After obtaining the second session state information, the database proxy matches the back-end connection including the second session state information to ensure that the front-end and back-end connection states are consistent.

[0170] Step 402: Match a target backend connection for the second connection request based on the second session state information; wherein the first session state information of the first session corresponding to the target backend connection includes the second session state information; and the first session state information is determined based on session tracking information of the target backend connection fed back by a database.

[0171] Specifically, the second session state information includes at least a second type, a second keyword, and a second value; the second type represents the type of session command of the second session, such as system variables, user variables, or creating a temporary table; the second keyword represents the name of the session command of the second session, such as for variables, the second keyword is the variable name; for creating a temporary table, the second keyword is the table name. The second value represents the content of the session command of the second session, such as for variables, the second value is the value of the variable; for creating a temporary table, the second value is the table creation statement of the temporary table. Correspondingly, the second session state information can also be converted into a Map data structure, and the Map keyword of the second session state information is the hash value of (second type + second keyword),

[0172] The first session state information of the first session corresponding to the backend connection includes the second session state information, and the session command of the backend connection must include the session command of the frontend connection, and the corresponding values ​​must be the same. For example, if the session command state of the second session is "a=1, b=1", then a backend connection with session state information of "a=1, b=2" or "a=1, c=1" cannot match the frontend connection of the second session; however, a backend connection with session state information of "a=1, b=1" or "a=1, b=1, c=1" can match the frontend connection of the second session.

[0173] After receiving the session tracking information returned by the database, the database proxy needs to save the session tracking information as the session state information of the first session. The session tracking information is used to match the session state of the front-end and back-end connection to ensure the consistency of the state within the session, thus avoiding unexpected exceptions.

[0174] In an embodiment of the present application, a second connection request from a client's front-end connection is received, and the second session state information of the second session corresponding to the second connection request is obtained; when matching a front-end connection with a back-end connection, the session state information is determined based on the session tracking information of the back-end connection, and matched with the second session state information of the front-end connection to ensure the correctness of the session state of the first session; based on the state information of each back-end connection in the connection pool, the front-end connection is matched to achieve consistency in the session state of the front-end and back-end connections, thereby avoiding decoding problems. In addition, during the matching process, since the session state of the back-end connection is updated in real time, there is no need to lock the front-end and back-end connections, which can improve the reuse rate of the back-end connection.

[0175] Based on the above embodiments, the embodiments of the present application also provide a session state processing method, which can control the consistency of the session states of the front-end and back-end connections, avoid decoding problems, and improve the multiplexing rate of the back-end connections.

[0176] Reference Figure 5 , shows a step flow chart of an embodiment of a session state processing method of the present application.

[0177] Optionally, the method is applied to a database; Figure 5 As shown, the method includes the following steps:

[0178] Step 501: Receive and process a first connection request from a database agent.

[0179] The first connection request is used by the database proxy to request a connection with the database, i.e., a backend connection. After the frontend connection matches the backend connection, the client can perform data processing operations through the database proxy. When the client needs to perform data processing operations, it first sends a frontend connection request to the database proxy, which establishes a connection between the client and the database through the database proxy.

[0180] After receiving the first connection request, the database parses the first connection request, processes the data processing operation requested by the first connection request, and obtains the data processing result of the processing operation; the data processing result is the processing result for the data processing operation, for example, when the data processing operation is an add or delete operation, the data processing result is whether the add or delete operation is completed; in addition, the processing result may also include a data part, that is, the result data corresponding to the processing operation, for example, if the data processing operation is a query operation, the data processing result is the query data retrieved.

[0181] Step 502: Feedback the processing result to the database agent, and carry session tracking information in the processing result; wherein the session tracking information at least includes the first type, first keyword and first value of the first session command corresponding to the first connection request.

[0182] In addition to the data processing result, the database also carries the session tracking information in the processing result and sends it to the database agent, so that the database agent updates the first session state information of the first session according to the session tracking information to ensure the correctness of the Session state of the first session.

[0183] Session tracking information is a field in the message sent by the server (i.e., database) to the client in the database message protocol, which is used to maintain the connection status between the database and the client; session tracking information may include the type, keyword, and value of the session command that has been executed. The type represents the type of session command, such as system variables, user variables, or the creation of temporary tables. The keyword represents the name of the session command. For example, for variables, the keyword is the variable name; for the creation of temporary tables, the keyword is the table name. The value represents the content of the session command. For example, for variables, the value is the value of the variable; for the creation of temporary tables, the value is the table creation statement of the temporary table. Each triple consisting of the type, keyword, and value of a session command can uniquely identify a session command; and from each of the triples, a database executable SQL statement can be restored; after sending this SQL statement to the database, the current connection can completely restore the session state represented by this session command.

[0184] In an embodiment of the present application, when the database responds to a first connection request from a database proxy, it carries session tracking information, enabling the database proxy to update the first session state information of the first session based on the session tracking information to ensure the correctness of the session state of the first session. Thus, when the database proxy is serving a front-end connection, it can match the front-end connection based on the state information of each back-end connection in the connection pool, achieving consistent session states for the front-end and back-end connections and avoiding decoding issues. Furthermore, during the matching process, since the back-end connection's session state is updated in real time, there is no need to lock the front-end and back-end connections, thereby improving the reuse rate of the back-end connections.

[0185] Based on the above embodiment, this embodiment also provides a session state processing device, referring to Figure 6 , Figure 6 The following is a block diagram showing a session state processing device embodiment of the present application, which may include the following modules:

[0186] The request sending module 601 is configured to send a first connection request to a database.

[0187] The first connection request is used to request a connection with the database, i.e., a backend connection. Once the frontend connection matches the backend connection, the client can perform data processing operations, such as adding, querying, updating, and deleting. For example, when performing user profiling, the client can pre-store a large amount of user parameters, such as physiological parameters and behavioral data, in the database. The database then creates a data table for the client to store the user data. When the client subsequently needs to perform data processing operations, it first sends a frontend connection request to the data proxy, establishing a connection between the client and the database through the database proxy.

[0188] The first information acquisition module 602 is configured to receive the processing result fed back by the database and acquire session tracking information carried in the processing result; wherein the session tracking information includes at least the first type, first keyword, and first value of the first session corresponding to the first connection request.

[0189] Among them, after receiving the first connection request, the database responds to the first connection request, processes the data processing operation requested by the first connection request, and obtains the data processing result of the processing operation; the data processing result is the processing result for the data processing operation, for example, when the data processing operation is an add or delete operation, the data processing result is whether the add or delete operation is completed; in addition, the processing result may also include a data part, that is, the result data corresponding to the processing operation, for example, if the data processing operation is a query operation, the data processing result is the query data queried.

[0190] In addition to the data processing results, the processing results also include session tracking information (Session Track). Session tracking information is a field in the database message protocol that the server (i.e., the database) sends to the client. It is used to maintain the connection status between the database and the client. Session tracking information may include the type, keyword, and value of the executed session command (SessionCommand).

[0191] Specifically, the type represents the type of session command, such as system variables, user variables, or creating a temporary table. The keyword represents the name of the session command. For example, for a variable, the keyword is the variable name; for creating a temporary table, the keyword is the table name. The value represents the content of the session command. For example, for a variable, the value is the variable value; for creating a temporary table, the value is the temporary table creation statement. Each session command's triple consisting of type, keyword, and value uniquely identifies a session command. From each triple, a database-executable SQL statement can be restored. After sending this SQL statement to the database, the current connection can completely restore the session state represented by this session command.

[0192] The state updating module 603 is configured to update the first session state information of the first session according to the session tracking information.

[0193] The database proxy updates the first session state information of the first session based on the session tracking information to ensure the correctness of the session state of the first session. Thus, when the database proxy is servicing a front-end connection, it can match the front-end connection based on the state information of each back-end connection in the connection pool, ensuring consistent session states between the front-end and back-end connections and avoiding decoding issues. Furthermore, during the matching process, since the back-end connection session state is updated in real time, there is no need to lock the front-end and back-end connections, thereby improving the reuse rate of back-end connections.

[0194] Reference Figure 7 , Figure 7 The following is a block diagram showing a session state processing device embodiment of the present application, which may include the following modules:

[0195] The request sending module 601 is configured to send a first connection request to a database.

[0196] The first information acquisition module 602 is configured to receive the processing result fed back by the database and acquire session tracking information carried in the processing result; wherein the session tracking information includes at least the first type, first keyword, and first value of the first session corresponding to the first connection request.

[0197] The state updating module 603 is configured to update the first session state information of the first session according to the session tracking information.

[0198] The database proxy updates the first session state information of the first session based on the session tracking information to ensure the correctness of the session state of the first session. Thus, when the database proxy is servicing a front-end connection, it can match the front-end connection based on the state information of each back-end connection in the connection pool, ensuring consistent session states between the front-end and back-end connections and avoiding decoding issues. Furthermore, during the matching process, since the back-end connection session state is updated in real time, there is no need to lock the front-end and back-end connections, thereby improving the reuse rate of back-end connections.

[0199] In one example, the status update module 603 includes a first processing submodule 6031 and an updating submodule 6032, wherein:

[0200] The first processing submodule 6031 is configured to process the session tracking information to obtain first processed data, wherein the first processed data is in a Map data structure.

[0201] The updating submodule 6032 is configured to update the session state information of the first session to the first processed data.

[0202] In another example, the first processing submodule 6031 includes:

[0203] a first processing unit, configured to perform hash processing on the first type and the first keyword to obtain a first hash value; and perform hash processing on the first value to obtain a second hash value;

[0204] The first Hash value is a Map keyword of the first processed data, and the second Hash value is a Map value of the first processed data.

[0205] In another example, the apparatus further includes:

[0206] A second information acquisition module 604 is configured to receive a second connection request from the client and acquire second session state information of a second session corresponding to the second connection request;

[0207] The matching module 605 is configured to match a target backend connection for the second connection request according to the second session state information.

[0208] In another example, the second session state information includes at least a second type, a second keyword, and a second value;

[0209] The target session state information of the target session corresponding to the backend connection includes the second session state information.

[0210] In another example, the matching module 605 includes:

[0211] The second processing submodule 6051 is configured to process the second session state information to obtain second processed data; the second processed data is in the form of a Map data structure;

[0212] The matching submodule 6052 is configured to match a target backend connection for the second connection request according to the second processed data.

[0213] In another example, the second processed data includes: a third Hash value obtained by performing a third data processing on the second type and the second keyword; and a fourth Hash value obtained by performing a fourth data processing on the second value;

[0214] The target session state information includes the third Hash value and the fourth Hash value.

[0215] In another example, the matching module 605 is configured to:

[0216] If the second session matches a historical backend connection, matching the historical backend connection for the second connection request; or

[0217] If the second session does not match a historical backend connection, a target backend connection is matched for the second connection request according to the second session state information.

[0218] In another example, the apparatus further includes:

[0219] The result feedback module 606 is configured to send the data processing result in the processing result to the client of the first front-end connection; the first front-end connection is the front-end connection corresponding to the first connection request.

[0220] In another example, the apparatus further includes:

[0221] A release module 607 is configured to place the first backend connection corresponding to the first session into a connection pool if the first backend connection is not locked and is not in a transaction; or

[0222] The connection module 608 is configured to maintain a connection state with the first backend connection if the first backend connection is locked or the first backend connection is in a transaction.

[0223] In some optional embodiments of the present application, after the request sending module 601 sends a first connection request to the database, it receives a processing result fed back by the database, and the first information acquisition module 602 obtains session tracking information contained in the processing result. The state update module 603 updates the first session state information of the first session based on the session tracking information to ensure the correctness of the session state of the first session. The session tracking information includes at least the first type, first keyword, and first value of the first session corresponding to the first connection request. Each triple consisting of the type, keyword, and value of the session command can uniquely identify a session command. From each triple, a SQL statement executable by the database can be restored. After sending this SQL statement to the database, the current connection can completely restore the session state represented by this session command. Therefore, based on the session tracking information, the real-time nature of the session state update can be guaranteed. When the database proxy is used for the front-end connection, the front-end connection can be matched based on the state information of each back-end connection in the connection pool to achieve consistency in the session state of the front-end and back-end connections, thereby avoiding decoding problems. Moreover, during the matching process, since the Session status of the back-end connection is updated in real time, there is no need to lock the front-end and back-end connections, so the back-end connection can be kept in a reusable state, thereby improving the reuse rate of the back-end connection. This solves the problem in the prior art that, in order to ensure the correctness of the Session status, the front-end and back-end connections are locked, resulting in the back-end connection being unable to be reused by other front-end connections.

[0224] Based on the above embodiment, this embodiment also provides a session state processing device, referring to Figure 8 , Figure 8 The following is a block diagram showing a session state processing device embodiment of the present application, which may include the following modules:

[0225] The third information acquisition module 801 is configured to receive a second connection request from the client and acquire second session state information of a second session corresponding to the second connection request;

[0226] The backend connection matching module 802 is used to match a target backend connection for the second connection request based on the second session state information; wherein the first session state information of the first session corresponding to the target backend connection includes the second session state information; the first session state information is determined based on the session tracking information of the target backend connection fed back by the database.

[0227] In an embodiment of the present application, the third information acquisition module 801 receives the second connection request of the front-end connection of the client and obtains the second session state information of the second session corresponding to the second connection request; when the back-end connection matching module 802 matches the front-end connection with the back-end connection, it determines the session state information based on the session tracking information of the back-end connection and matches it with the second session state information of the front-end connection to ensure the correctness of the session state of the first session; according to the state information of each back-end connection in the connection pool, the front-end connection is matched to achieve the consistency of the session state of the front-end and back-end connections, thereby avoiding decoding problems. In addition, during the matching process, since the session state of the back-end connection is updated in real time, there is no need to lock the front-end and back-end connections, which can improve the reuse rate of the back-end connection.

[0228] Based on the above embodiment, this embodiment also provides a session state processing device, referring to Figure 9 , Figure 9 The following is a block diagram showing a session state processing device embodiment of the present application, which may include the following modules:

[0229] The request receiving module 901 is configured to receive and process a first connection request from a database agent.

[0230] The first connection request is used by the database proxy to request a connection with the database, i.e., a backend connection. After the frontend connection matches the backend connection, the client can perform data processing operations through the database proxy. When the client needs to perform data processing operations, it first sends a frontend connection request to the database proxy, which establishes a connection between the client and the database through the database proxy.

[0231] After receiving the first connection request, the database parses the first connection request, processes the data processing operation requested by the first connection request, and obtains the data processing result of the processing operation; the data processing result is the processing result for the data processing operation, for example, when the data processing operation is an add or delete operation, the data processing result is whether the add or delete operation is completed; in addition, the processing result may also include a data part, that is, the result data corresponding to the processing operation, for example, if the data processing operation is a query operation, the data processing result is the query data retrieved.

[0232] The result feedback module 902 is used to feed back the processing result to the database agent, and carry session tracking information in the processing result; wherein the session tracking information at least includes the first type, first keyword and first value of the first session command corresponding to the first connection request.

[0233] In addition to the data processing result, the database also carries the session tracking information in the processing result and sends it to the database agent, so that the database agent updates the first session state information of the first session according to the session tracking information to ensure the correctness of the Session state of the first session.

[0234] Session tracking information is a field in the message sent by the server (i.e., database) to the client in the database message protocol, which is used to maintain the connection status between the database and the client; session tracking information may include the type, keyword, and value of the session command that has been executed. The type represents the type of session command, such as system variables, user variables, or the creation of temporary tables. The keyword represents the name of the session command. For example, for variables, the keyword is the variable name; for the creation of temporary tables, the keyword is the table name. The value represents the content of the session command. For example, for variables, the value is the value of the variable; for the creation of temporary tables, the value is the table creation statement of the temporary table. Each triple consisting of the type, keyword, and value of a session command can uniquely identify a session command; and from each of the triples, a database executable SQL statement can be restored; after sending this SQL statement to the database, the current connection can completely restore the session state represented by this session command.

[0235] In an embodiment of the present application, the request receiving module 901 receives and processes the first connection request of the database proxy. The result feedback module 902 carries session tracking information when responding to the first connection request to the database proxy, so that the database proxy updates the first session state information of the first session based on the session tracking information to ensure the correctness of the session state of the first session. In this way, when the database proxy is connecting to the front-end, it can match the front-end connection based on the state information of each back-end connection in the connection pool, achieving consistency in the session state of the front-end and back-end connections and avoiding decoding problems. In addition, during the matching process, since the session state of the back-end connection is updated in real time, there is no need to lock the front-end and back-end connections, which can improve the reuse rate of the back-end connection.

[0236] Based on the above embodiment, this embodiment further provides a data processing system 1000. Figure 10 , Figure 10 1 shows a structural block diagram of an embodiment of a data processing system 1000 of the present application, wherein the data processing system 1000 includes: a client 1001, a database agent 1002, and a database 1003; the number of the client 1001 can be multiple;

[0237] The database agent 1002 is used for:

[0238] Sending a first connection request to the database 1003;

[0239] receiving a processing result fed back by the database 1003 and obtaining session tracking information carried in the processing result; wherein the session tracking information includes at least a first type, a first keyword, and a first value of the first session corresponding to the first connection request;

[0240] updating first session state information of the first session according to the session tracking information;

[0241] receiving a second connection request from the client 1001, and obtaining second session state information of a second session corresponding to the second connection request;

[0242] matching a target backend connection for the second connection request based on the second session state information; wherein the first session state information of the first session corresponding to the target backend connection includes the second session state information; and the first session state information is determined based on the session tracking information of the target backend connection fed back by database 1003;

[0243] The database 1003 is used for:

[0244] Receive and process the first connection request of the database agent 1002;

[0245] Feedback the processing result to the database agent 1002, and carry the session tracking information in the processing result.

[0246] In an embodiment of the present application, database 1003 carries session tracking information when responding to a first connection request from database proxy 1002. Database proxy 1002 updates the first session state information of the first session based on the session tracking information to ensure the correctness of the session state of the first session. Thus, when database proxy 1002 matches a backend connection for client 1001's second connection request, it can match the frontend connection based on the state information of each backend connection in the connection pool, achieving consistent session states for the frontend and backend connections and avoiding decoding issues. Furthermore, during the matching process, since the backend connection's session state is updated in real time, there is no need to lock the frontend and backend connections, which can improve the reuse rate of the backend connections.

[0247] An embodiment of the present application further provides a non-volatile readable storage medium, which stores one or more modules (programs). When the one or more modules are applied to a device, the device can execute instructions (instructions) of each method step in the embodiment of the present application.

[0248] The present application provides one or more machine-readable storage media having instructions stored thereon, which, when executed by one or more processors, cause an electronic device to perform one or more of the methods described in the above embodiments. In the present application, the electronic device includes a terminal device, a server (cluster), and other first-type devices.

[0249] The embodiments of the present application may be implemented as a device configured as desired using any appropriate hardware, firmware, software, or any combination thereof, which may include electronic devices such as terminal devices, servers (clusters), etc. Figure 11 An exemplary apparatus 1100 that can be used to implement various embodiments described in this application is schematically illustrated.

[0250] For one embodiment, Figure 11 An exemplary apparatus 1100 is shown having one or more processors 1102, a control module (chip set) 1104 coupled to at least one of the processor(s) 1102, a memory 1106 coupled to the control module 1104, a non-volatile memory (NVM) / storage device 1108 coupled to the control module 1104, one or more input / output devices 1110 coupled to the control module 1104, and a network interface 1112 coupled to the control module 1104.

[0251] The processor 1102 may include one or more single-core or multi-core processors, and the processor 1102 may include any combination of general-purpose processors or dedicated processors (e.g., graphics processors, application processors, baseband processors, etc.). In some embodiments, the apparatus 1100 can serve as a terminal device, server (cluster), or other device described in the embodiments of the present application.

[0252] In some embodiments, the apparatus 1100 may include one or more computer-readable media (e.g., memory 1106 or NVM / storage 1108) having instructions 1114 and one or more processors 1102 configured in conjunction with the one or more computer-readable media to execute the instructions 1114 to implement a module to perform the actions described in the present disclosure.

[0253] For one embodiment, the control module 1104 may include any suitable interface controller to provide any suitable interface to at least one of the processor(s) 1102 and / or any suitable device or component in communication with the control module 1104 .

[0254] The control module 1104 may include a memory controller module to provide an interface to the memory 1106. The memory controller module may be a hardware module, a software module, and / or a firmware module.

[0255] The memory 1106 can be used, for example, to load and store data and / or instructions 1114 for the device 1100. For one embodiment, the memory 1106 can include any suitable volatile memory, such as a suitable DRAM. In some embodiments, the memory 1106 can include double data rate type 1 four synchronous dynamic random access memory (DDR4 SDRAM).

[0256] For one embodiment, the control module 1104 may include one or more input / output controllers to provide an interface to the NVM / storage device 1108 and the input / output device(s) 1110 .

[0257] For example, NVM / storage 1108 may be used to store data and / or instructions 1114. NVM / storage 1108 may include any suitable non-volatile memory (e.g., flash memory) and / or may include any suitable non-volatile storage device(s) (e.g., one or more hard disk drives (HDDs), one or more compact disk (CD) drives, and / or one or more digital versatile disk (DVD) drives).

[0258] The NVM / storage device 1108 may include storage resources that are physically part of the device on which the apparatus 1100 is installed, or it may be accessible to the device without being part of the device. For example, the NVM / storage device 1108 may be accessible over a network via the input / output device(s) 1110.

[0259] (One or more) input / output devices 1110 may provide an interface for apparatus 1100 to communicate with any other appropriate device. Input / output devices 1110 may include communication components, audio components, sensor components, etc. Network interface 1112 may provide an interface for apparatus 1100 to communicate via one or more networks. Apparatus 1100 may wirelessly communicate with one or more components of a wireless network according to any of one or more wireless network standards and / or protocols, for example, accessing a wireless network based on a communication standard, such as WiFi, 2G, 3G, 4G, 5G, etc., or a combination thereof for wireless communication.

[0260] For one embodiment, at least one of the processor(s) 1102 may be packaged together with the logic of one or more controllers (e.g., a memory controller module) of the control module 1104. For one embodiment, at least one of the processor(s) 1102 may be packaged together with the logic of one or more controllers of the control module 1104 to form a system-in-package (SiP). For one embodiment, at least one of the processor(s) 1102 may be integrated on the same die with the logic of one or more controllers of the control module 1104. For one embodiment, at least one of the processor(s) 1102 may be integrated on the same die with the logic of one or more controllers of the control module 1104 to form a system-on-chip (SoC).

[0261] In various embodiments, the apparatus 1100 may be, but is not limited to, a terminal device such as a server, a desktop computing device, or a mobile computing device (e.g., a laptop computing device, a handheld computing device, a tablet computer, a netbook, etc.). In various embodiments, the apparatus 1100 may have more or fewer components and / or a different architecture. For example, in some embodiments, the apparatus 1100 includes one or more cameras, a keyboard, a liquid crystal display (LCD) screen (including a touchscreen display), a non-volatile memory port, multiple antennas, a graphics chip, an application-specific integrated circuit (ASIC), and a speaker.

[0262] Among them, the main control chip can be used as a processor or control module in the detection device, sensor data, location information, etc. are stored in the memory or NVM / storage device, the sensor group can be used as an input / output device, and the communication interface may include a network interface.

[0263] As for the device embodiment, since it is basically similar to the method embodiment, the description is relatively simple, and the relevant parts can be referred to the partial description of the method embodiment.

[0264] The various embodiments in this specification are described in a progressive manner, and each embodiment focuses on the differences from other embodiments. The same or similar parts between the various embodiments can be referenced to each other.

[0265] The embodiments of the present application are described with reference to the flowcharts and / or block diagrams of the methods, terminal devices (systems), and computer program products according to the embodiments of the present application. It should be understood that each process and / or box in the flowchart and / or block diagram, as well as the combination of the processes and / or boxes in the flowchart and / or block diagram, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, a special-purpose computer, an embedded processor, or other programmable data processing terminal device to produce a machine, so that the instructions executed by the processor of the computer or other programmable data processing terminal device generate instructions for implementing the steps in the process. Figure 1 a process or multiple processes and / or boxes Figure 1 A device that provides the functions specified in a block or multiple blocks.

[0266] These computer program instructions may also be stored in a computer readable memory that can direct a computer or other programmable data processing terminal device to operate in a specific manner, so that the instructions stored in the computer readable memory produce a manufactured product including an instruction device, which implements the process Figure 1 a process or multiple processes and / or boxes Figure 1 The function specified in one or more boxes.

[0267] These computer program instructions can also be loaded onto a computer or other programmable data processing terminal device so that a series of operating steps are executed on the computer or other programmable terminal device to produce a computer-implemented process, thereby providing instructions for executing on the computer or other programmable terminal device to implement the process. Figure 1 a process or multiple processes and / or boxes Figure 1 A step that specifies a function in one or more boxes.

[0268] Although preferred embodiments of the present invention have been described, those skilled in the art may make additional changes and modifications to these embodiments once they become aware of the basic inventive concepts. Therefore, the appended claims are intended to be interpreted as including the preferred embodiments and all changes and modifications that fall within the scope of the embodiments of the present invention.

[0269] Finally, it should be noted that, in this document, relational terms such as first and second, etc., are used only to distinguish one entity or operation from another entity or operation, and do not necessarily require or imply any actual relationship or order between these entities or operations. Moreover, the terms "comprises," "comprising," or any other variations thereof are intended to cover non-exclusive inclusion, such that a process, method, article, or terminal device that includes a series of elements includes not only those elements, but also other elements not explicitly listed, or elements inherent to such process, method, article, or terminal device. In the absence of further limitations, an element defined by the phrase "comprising a ..." does not exclude the presence of additional identical elements in the process, method, article, or terminal device that includes the element.

[0270] The above is a detailed introduction to a session state processing method and device, an electronic device and a storage medium provided by the present application. Specific examples are used in this article to illustrate the principles and implementation methods of the present application. The description of the above embodiments is only used to help understand the method of the present application and its core idea; at the same time, for general technical personnel in this field, based on the ideas of the present application, there will be changes in the specific implementation methods and application scope. In summary, the content of this specification should not be understood as a limitation on the present application.

Claims

1. A session state processing method, applied to a database proxy, comprising: Sending a first connection request to the database; receiving a processing result fed back by the database, and obtaining session tracking information carried in the processing result; wherein the session tracking information includes at least a first type, a first keyword, and a first value of the first session corresponding to the first connection request; and updating and saving first session state information of the first session according to the session tracking information; The method further comprises: receiving a second connection request from the client, and obtaining second session state information of a second session corresponding to the second connection request; wherein the second session state information includes at least a second type, a second keyword, and a second value of the second session corresponding to the second connection request; A target backend connection is matched for the second connection request according to the second session state information, where the first session state information of the first session corresponding to the target backend connection includes the second session state information.

2. The session state processing method according to claim 1, wherein: The step of updating the first session state information of the first session according to the session tracking information includes: Performing data processing on the session tracking information to obtain first processed data, where the data format of the first processed data is a Map data structure; The session state information of the first session is updated to the first processing data.

3. The session state processing method according to claim 2, wherein: The step of processing the session tracking information to obtain first processed data includes: Performing hash processing on the first type and the first keyword to obtain a first hash value; and performing hash processing on the first value to obtain a second hash value; The first Hash value is a Map keyword of the first processed data, and the second Hash value is a Map value of the first processed data.

4. The session state processing method according to claim 1, wherein: The second session state information includes at least a second type, a second keyword, and a second value; The target session state information of the target session corresponding to the backend connection includes the second session state information.

5. The session state processing method according to claim 4, wherein: The step of matching a target backend connection for the second connection request according to the second session state information includes: Performing data processing on the second session state information to obtain second processed data; wherein the data format of the second processed data is a Map data structure; A target backend connection is matched for the second connection request according to the second processing data.

6. The session state processing method according to claim 5, characterized in that: The second processed data includes: a third Hash value obtained by performing a third data processing on the second type and the second keyword; and a fourth Hash value obtained by performing a fourth data processing on the second value; The target session state information includes the third Hash value and the fourth Hash value.

7. The session state processing method according to claim 1, wherein: After the step of obtaining the second session state information of the second session corresponding to the second connection request, the method includes: If the second session matches a historical backend connection, matching the historical backend connection for the second connection request; or If the second session does not match a historical backend connection, a target backend connection is matched for the second connection request according to the second session state information.

8. The session state processing method according to claim 1, wherein: After the step of updating the first session state information of the first session according to the session tracking information, the method further includes: The data processing result in the processing result is sent to the client of the first front-end connection; the first front-end connection is the front-end connection corresponding to the first connection request.

9. The session state processing method according to any one of claims 1 to 8, characterized in that: The method further comprises: If the first backend connection corresponding to the first session is not locked and is not in a transaction, put the first backend connection into a connection pool; or If the first backend connection is locked or the first backend connection is in a transaction, the connection state with the first backend connection is maintained.

10. A session state processing method, applied to a database agent, characterized in that: The method comprises: receiving a second connection request from the client, and obtaining second session state information of a second session corresponding to the second connection request; A target backend connection is matched for the second connection request based on the second session state information; wherein, the first session state information of the first session corresponding to the target backend connection includes the second session state information; the first session state information is determined based on session tracking information of the target backend connection fed back by a database, and the second session state information includes at least a second type, a second keyword, and a second value of the second session corresponding to the second connection request.

11. A session state processing method, applied to a database, characterized in that: The method comprises: receiving and processing a first connection request from a database agent; Feedback the processing result to the database proxy, and carry session tracking information in the processing result; wherein the session tracking information at least includes the first type, first keyword, and first value of the first session command corresponding to the first connection request, so that the database proxy receives the second connection request from the client, obtains the second session state information of the second session corresponding to the second connection request, and matches the target backend connection for the second connection request based on the second session state information, the first session state information of the first session corresponding to the target backend connection includes the second session state information; wherein the second session state information at least includes the second type, second keyword, and second value of the second session corresponding to the second connection request.

12. A session state processing device, applied to a database agent, characterized in that: The device comprises: A request sending module, configured to send a first connection request to the database; a first information acquisition module, configured to receive a processing result fed back by the database and acquire session tracking information carried in the processing result; wherein the session tracking information includes at least a first type, a first keyword, and a first value of the first session corresponding to the first connection request; a state updating module, configured to update and save first session state information of the first session according to the session tracking information; The device is also used to: receive a second connection request from the client, and obtain second session state information of the second session corresponding to the second connection request; the second session state information includes at least a second type, a second keyword, and a second value of the second session corresponding to the second connection request; and match a target backend connection for the second connection request based on the second session state information, where the first session state information of the first session corresponding to the target backend connection includes the second session state information.

13. A session state processing device, applied to a database agent, characterized in that: The device comprises: a third information acquisition module, configured to receive a second connection request from the client, and acquire second session state information of a second session corresponding to the second connection request; the second session state information including at least a second type, a second keyword, and a second value of the second session corresponding to the second connection request; A backend connection matching module is configured to match a target backend connection for the second connection request based on the second session state information; wherein the first session state information of the first session corresponding to the target backend connection includes the second session state information; and the first session state information is determined based on session tracking information of the target backend connection fed back by a database.

14. A session state processing device, applied to a database, characterized in that: The device comprises: A request receiving module, configured to receive and process a first connection request from a database agent; A result feedback module is configured to feed back a processing result to the database proxy, and carry session tracking information in the processing result; wherein the session tracking information includes at least a first type, a first keyword, and a first value of a first session command corresponding to the first connection request, so that the database proxy can receive a second connection request from the client, obtain second session state information of a second session corresponding to the second connection request, and match a target backend connection for the second connection request based on the second session state information, where the first session state information of the first session corresponding to the target backend connection includes the second session state information; wherein the second session state information includes at least a second type, a second keyword, and a second value of the second session corresponding to the second connection request.

15. A data processing system, characterized in that: include: Client, database agent, and database; Wherein, the database agent is used for: Sending a first connection request to the database; receiving a processing result fed back by the database, and obtaining session tracking information carried in the processing result; wherein the session tracking information includes at least a first type, a first keyword, and a first value of the first session corresponding to the first connection request; updating first session state information of the first session according to the session tracking information; receiving a second connection request from the client, and obtaining second session state information of a second session corresponding to the second connection request; wherein the second session state information includes at least a second type, a second keyword, and a second value of the second session corresponding to the second connection request; matching a target backend connection for the second connection request based on the second session state information; wherein the first session state information of the first session corresponding to the target backend connection includes the second session state information; and the first session state information is determined based on session tracking information of the target backend connection fed back by a database; The database is used to: receiving and processing a first connection request from the database agent; Feedback the processing result to the database agent, and carry the session tracking information in the processing result.

16. An electronic device, characterized in that: include: processor; and A memory having executable codes stored thereon, which, when executed, causes the processor to perform the method according to any one of claims 1 to 11.

17. One or more machine-readable storage media having executable codes stored thereon, which, when executed, cause a processor to perform the method according to any one of claims 1 to 11.

Citation Information

Patent Citations

  • A distributed database proxy system based on massive data access requirements

    CN102262680A