Database access method, device, electronic device and storage medium

Establishing HTTP and TCP connections between clients and databases by proxy services solves the problem of database access restrictions caused by TCP connection, and realizes HTTP -based database access and transactional requests, which improves the speed of connection.

CN119155346BActive Publication Date: 2025-01-24PINGCAP XINGCHEN (BEIJING) TECH CO LTD
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202411639960.2
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2024-11-15
Publication Date
2025-01-24
Estimated Expiration
2044-11-15

AI Technical Summary

Technical Problem

In some scenarios, the TCP connection cannot be established, resulting in the inability to access the database.

Method used

Through agency services, use HTTP to connect to client communication, and establish a TCP connection to database communication when necessary, and execute database operation statements.

Benefits of technology

It implements access to the database based on HTTP, solves the problem of database access restrictions caused by the inability to establish a TCP connection, and supports transactional database requests, improving the speed of connecting to the database.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119155346B_ABST
    Figure CN119155346B_ABST
Patent Text Reader

Abstract

The embodiments of the present application provide a database access method, device, electronic device and storage medium, which relate to the field of databases, for example, can be used in the field of distributed databases. The method is executed by a proxy service, and the proxy service and the database are deployed in the same backbone network, including: receiving a first operation request for the database sent by a client via HTTP, if the first operation request does not include session information, creating a TCP connection between the proxy service and the database, and executing the database operation statement in the first operation request through the TCP connection; if the first operation request includes session information, determining the created TCP connection based on the session information, and executing the database operation statement in the first operation request through the created TCP connection. Generate a return result based on the session information and the execution result, and send the return result to the client. The embodiments of the present application implement access to the database via HTTP, with low access latency and support for transactional requests.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the field of database technology, and in particular to a database access method, device, electronic device and computer-readable storage medium. Background Art

[0002] Accessing a database usually relies on a Transmission Control Protocol (TCP) connection because TCP connections provide a reliable, connection-oriented communication mechanism that ensures the stability and order of data transmission between the client and the server.

[0003] In the traditional server-client model, the client directly establishes a connection with the database server through the TCP protocol, executes SQL operations, and then receives the results. However, in modern computing environments, especially in mobile devices, browsers, or edge computing scenarios, the database cannot be accessed directly through a TCP connection, so there is a problem of database access restrictions in these scenarios. Summary of the invention

[0004] The embodiments of the present application provide a database access method, device, electronic device, computer storage medium and computer program product, which can solve the problem of being unable to access the database due to failure to establish a TCP connection in some scenarios. The technical solution is as follows:

[0005] According to a first aspect of an embodiment of the present application, a database access method is provided, which is executed by a proxy service, and the proxy service and the database are deployed on the same backbone network. The method includes:

[0006] receiving a first operation request for the database sent by a client, wherein the first operation request is a request based on the Hypertext Transfer Protocol (HTTP), and the first operation request includes a database operation statement, wherein the communication connection between the client and the proxy service is an HTTP connection;

[0007] In the case where the first condition is not met, a first session is created between the client and the proxy service, and a first Transmission Control Protocol TCP connection is established between the proxy service and the database, and a correspondence between a session identifier of the first session and a connection identifier of the first TCP connection is stored in a first mapping relationship; the first TCP connection is used as a target TCP connection; and first session information of the first session is sent to the client; wherein the session information of any session includes the session identifier of any session; the first mapping relationship includes a correspondence between a session identifier of at least one created session and a connection identifier of a corresponding TCP connection; the failure to meet the first condition includes that the first operation request does not include session information;

[0008] If the first operation request includes session information, use the session information as second session information, determine a connection identifier corresponding to the session identifier in the second session information based on the stored first mapping relationship, and use a second TCP connection corresponding to the connection identifier as the target TCP connection;

[0009] Communicate with the database through the target TCP connection, execute the database operation statement through the database, obtain the execution result, and send the execution result to the client.

[0010] According to a second aspect of an embodiment of the present application, a database access device is provided, the device is applied to a proxy service, the proxy service and the database are deployed on the same backbone network, the device comprising:

[0011] a scheduling module, configured to receive a first operation request for the database sent by a client, wherein the first operation request is a request based on the Hypertext Transfer Protocol (HTTP), and the first operation request includes a database operation statement, wherein the communication connection between the client and the proxy service is an HTTP connection;

[0012] A connection cache module, used for creating a first session between the client and the proxy service, and establishing a first transmission control protocol TCP connection between the proxy service and the database when the first condition is not met, storing the correspondence between the session identifier of the first session and the connection identifier of the first TCP connection in a first mapping relationship; using the first TCP connection as a target TCP connection; wherein the session information of any session includes the session identifier of any session; the first mapping relationship includes the correspondence between the session identifier of at least one created session and the connection identifier of the corresponding TCP connection; the failure to meet the first condition includes that the first operation request does not include session information;

[0013] The connection cache module is further configured to, if the first operation request includes session information, use the session information as second session information, determine a connection identifier corresponding to the session identifier in the second session information based on the stored first mapping relationship, and use a second TCP connection corresponding to the connection identifier as a target TCP connection;

[0014] An execution module, used for communicating with the database through the target TCP connection, and executing the database operation statement through the database;

[0015] The data processing module is used to send the first session information of the first session to the client; and is also used to obtain an execution result and send the execution result to the client.

[0016] According to a third aspect of an embodiment of the present application, an electronic device is provided, which includes a memory, a processor, and a computer program stored in the memory, and when the processor executes the program, the steps of the method provided in the first aspect are implemented.

[0017] According to a fourth aspect of an embodiment of the present application, a computer-readable storage medium is provided, on which a computer program is stored. When the computer program is executed by a processor, the steps of the method provided in the first aspect are implemented.

[0018] According to the fifth aspect of the embodiment of the present application, a computer program product is provided, which includes computer instructions, and the computer instructions are stored in a computer-readable storage medium. When a processor of a computer device reads the computer instructions from the computer-readable storage medium, the processor executes the computer instructions, so that the computer device executes the steps of implementing the method provided in the first aspect.

[0019] The beneficial effect of the technical solution provided by the embodiment of the present application is: after receiving the first operation request sent by the client through HTTP, according to whether the first operation request includes session information, it is determined whether the first operation request has a corresponding TCP connection, and when there is no corresponding TCP connection, a TCP connection is established, and when there is a corresponding TCP connection, the database operation statement in the first operation request is executed through the TCP connection, the execution result is obtained, and the execution result is returned to the client, thereby realizing access to the database based on HTTP, solving the problem that the TCP connection cannot be established and the database cannot be accessed in some scenarios. In addition, in the embodiment of the present application, when the first operation request does not include session information, a session between the client and the proxy service is established, session information is generated, and a corresponding relationship between the session representation of the session and the connection identifier of the TCP connection is established, so that the first operation request corresponding to the same session can be executed through the same TCP connection, so that the database access method provided by the embodiment of the present application can support transactional database requests. Further, in the embodiment of the present application, the proxy service and the database are deployed on the same backbone network, which reduces the distance between the proxy service and the database, shortens the data transmission time between the database and the proxy service, and improves the speed of connecting to the database compared to the method of accessing the database based on the TCP connection, solving the delay problem caused by the introduction of the middle layer. BRIEF DESCRIPTION OF THE DRAWINGS

[0020] In order to more clearly illustrate the technical solutions in the embodiments of the present application, the drawings required for use in describing the embodiments of the present application are briefly introduced below.

[0021] Figure 1 A schematic diagram of a system architecture for implementing database access provided in an embodiment of the present application;

[0022] Figure 2 A flowchart of a database access method provided in an embodiment of the present application;

[0023] Figure 3 A schematic diagram of another system architecture for database access provided in an embodiment of the present application;

[0024] Figure 4 A schematic diagram of a non-transactional operation interface and a transactional operation interface of a driver provided in an embodiment of the present application;

[0025] Figure 5 A schematic diagram of another system architecture for database access provided in an embodiment of the present application;

[0026] Figure 6 A schematic diagram of a flow chart for executing a database operation statement provided in an embodiment of the present application;

[0027] Figure 7 Another schematic diagram of a database access process provided in an embodiment of the present application;

[0028] Figure 8 Provides a schematic diagram of the response format of the execution results of different database operation statements;

[0029] Fig. 9 A schematic diagram of a data processing flow provided in an embodiment of the present application;

[0030] Fig.10 A schematic diagram of a process of accessing a database by a driver program provided in an embodiment of the present application;

[0031] Fig.11 Another system architecture diagram for database access provided by an embodiment of the present application;

[0032] Fig.12 A comparison chart of execution time of database operation statements under different drivers provided in an embodiment of the present application;

[0033] Fig.13 A schematic diagram of the structure of a database access device provided in an embodiment of the present application;

[0034] Fig.14 A schematic diagram of the structure of an electronic device for accessing a database provided in an embodiment of the present application. DETAILED DESCRIPTION

[0035] The embodiments of the present application are described below in conjunction with the drawings in the present application. It should be understood that the implementation methods described below in conjunction with the drawings are exemplary descriptions for explaining the technical solutions of the embodiments of the present application and do not constitute a limitation on the technical solutions of the embodiments of the present application.

[0036] It will be understood by those skilled in the art that, unless specifically stated, the singular forms "one", "said", and "the" used herein may also include plural forms. It should be further understood that the terms "including" and "comprising" used in the embodiments of the present application refer to that the corresponding features can be implemented as the presented features, information, data, steps, operations, elements and / or components, but do not exclude the implementation as other features, information, data, steps, operations, elements, components and / or combinations thereof supported by the technical field. It should be understood that when we say that an element is "connected" or "coupled" to another element, the one element may be directly connected or coupled to the other element, or it may refer to that the one element and the other element establish a connection relationship through an intermediate element. In addition, the "connection" or "coupling" used herein may include wireless connection or wireless coupling. The term "and / or" used herein indicates at least one of the items defined by the term, for example, "A and / or B" may be implemented as "A", or as "B", or as "A and B".

[0037] In order to make the objectives, technical solutions and advantages of the present application clearer, the implementation methods of the present application will be further described in detail below with reference to the accompanying drawings.

[0038] First, several terms involved in this application are introduced and explained:

[0039] Transmission Control Protocol (TCP) is a connection-oriented, reliable, byte-stream-based communication protocol. TCP uses connection as the most basic abstract unit. Each TCP connection has two endpoints, which are sockets.

[0040] Hypertext Transfer Protocol (HTTP) is one of the most widely used protocols on the Internet. It is a standard protocol for transmitting hypertext from a server to a local browser.

[0041] Hypertext Transfer Protocol Secure (HTTPS) is a secure version of HTTP, which adds the TLS protocol to HTTP to make communication between the client and the server more secure. HTTPS encrypts data at the transport layer to protect the data from eavesdropping or tampering, and also verifies the identity of the server to prevent man-in-the-middle attacks.

[0042] Transport Layer Security (TLS) is a security protocol used to provide encrypted communications and data integrity protection on computer networks.

[0043] Kubernetes: A platform for automatically deploying, expanding, and managing containerized applications. Many database services choose to be deployed on Kubernetes to achieve elastic scaling.

[0044] Edge function: A serverless computing service (Faas). It can provide users with serverless computing services. It runs close to users and can respond to user requests quickly. Edge functions are very suitable as the backend part of front-end and back-end integrated development, but due to the limitations of its operating environment, it is usually impossible to directly access the database based on the TCP protocol.

[0045] Transactional operation: An operation in a database management system that ensures data integrity and consistency. Transactional operations usually include the following characteristics: Atomicity: A transaction is an indivisible minimum unit of work. The operations in a transaction are either completed or not done at all, and will not end at a certain point in the middle; Consistency: A transaction must cause the database to transition from one consistent state to another. Isolation: The results of a transaction cannot be visible to other transactions until the transaction is completed; Persistence: Once a transaction is committed, its impact on the system is permanent, and the results of the transaction will not be lost even if the system fails.

[0046] Transactional operations are usually used in scenarios where multiple steps need to be performed, and all of these steps must succeed to ensure data consistency. For example, in a banking system, to transfer money from one account to another, the following operations need to be performed: deduct the corresponding amount from the transfer account; add the corresponding amount to the receiving account; and update the account balance.

[0047] These steps must all be completed to ensure the correctness of the account balance. If any step fails, the entire operation should be undone to keep the data consistent.

[0048] Streaming is a data transmission method that allows the server to respond to requests without sending all the data at once, but to send it in multiple parts step by step. This is very useful for large file transfers, real-time data transmission (such as video streaming, real-time log transmission, etc.).

[0049] The database access method, device, electronic device, computer-readable storage medium and computer program product provided in the present application are intended to solve the above technical problems in the prior art.

[0050] The following describes several exemplary embodiments to illustrate the technical solutions of the embodiments of the present application and the technical effects produced by the technical solutions of the present application. It should be noted that the following embodiments can refer to, draw on or combine with each other, and the same terms, similar features and similar implementation steps in different embodiments will not be described repeatedly.

[0051] Figure 1 A schematic diagram of the system architecture for implementing database access provided in an embodiment of the present application, wherein the client 101 communicates with the proxy service 102 via HTTP, the proxy service 102 communicates with the database 103 via TCP, the proxy service 102 and the database 103 are deployed in the same backbone network, and the proxy service 102 can be deployed in the same Kubernetes cluster or the same rack as the database 103. The database 103 is a database server for storing data and being able to execute database operation statements on the data, the proxy service 102 is a proxy server, the database server and the proxy server can be physical servers or cloud servers, and can be composed of four functional modules, namely a scheduling module, a connection cache module, an execution module, and a data processing module.

[0052] The client 101 is used to send a first operation request to the proxy service 102. The first operation request can be transmitted via HTTP, and the first operation request includes a database operation statement. The proxy service 102 determines whether a TCP connection has been established for the first operation request based on the received first operation request and whether the first operation request includes session information.

[0053] If the first operation request does not include session information, indicating that no TCP connection for the first operation request has been established, the proxy service will establish a TCP connection, execute the database operation statement in the first request through the TCP connection, and return the execution result to the client;

[0054] If the first operation request includes session information, it means that a TCP connection for the first operation request has been established in advance, and the TCP connection corresponds to the session information in the first operation request. The proxy service can find the TCP connection based on the session information, and then execute the database operation statement in the first operation request through the TCP connection, and return the execution result to the client.

[0055] In some embodiments, the proxy service 102 is an independent physical server, or a server cluster or distributed system composed of multiple physical servers, or a cloud server that provides basic cloud computing services such as cloud services, cloud databases, cloud computing, cloud functions, cloud storage, network services, cloud communications, middleware services, domain name services, security services, content delivery networks (CDNs), and big data and artificial intelligence platforms. The client 101 is a smart phone, tablet computer, laptop computer, desktop computer, smart speaker, smart watch, smart voice interaction device, smart home appliance, car client, etc., but is not limited to this. On this basis, the client 101 in the embodiment of the present application can be a mobile device that does not support access to the database through the TCP protocol, or it can be a terminal device with an application and a browser installed, or it can be an edge function service. By setting up a proxy service, the present application can enable the above-mentioned client that cannot access the database through the TCP protocol to access the database through the HTTP protocol.

[0056] In an embodiment of the present application, a database access method is provided, which is executed by a proxy service, and the proxy service and the database are deployed on the same backbone network, such as Figure 2 As shown, the method includes steps S201, S202 (not shown in the figure) and S203, wherein S202 includes S2021 and S2022.

[0057] S201. Receive a first operation request for a database sent by a client, where the first operation request is a request based on the Hypertext Transfer Protocol (HTTP), and includes a database operation statement, wherein the communication connection between the client and the proxy service is an HTTP connection.

[0058] In the embodiment of the present application, the proxy service and the database are deployed in the same backbone network to reduce the traffic cost of data transmission and reduce access delay. The prior art accesses the database through TCP. To ensure the security of data transmission, TCP with TSL needs to be used, and the speed of establishing the connection is slow. In the present application, the proxy service and the database are in the same backbone network, which has ensured the security of data transmission. Then, only the TCP protocol can be used, reducing the use of the database protocol with a slower connection. Therefore, the connection speed of the embodiment of the present application is better than the database connection of the traditional TCP with TLS.

[0059] The proxy service can be written in Go (Goland). The proxy service is used for protocol conversion, and the number of proxy services can be one or more. As an optional embodiment, the proxy service and the database can be deployed in the same cluster or the same rack, such as a Kubernetes cluster. If you need to deploy multiple instances in the cluster, you can use StatefulSet to deploy. StatefulSet can run a group of proxy service instances and generate a corresponding proxy service identifier for each instance.

[0060] In an embodiment of the present application, a driver can be installed in the client, and the database operation statement input by the user is converted into a first operation request through the driver. The first operation request can be transmitted to the proxy service through the HTTP protocol, that is, the first operation request is a request based on HTTP, and the communication connection between the client and the proxy service is an HTTP connection. The proxy service includes a scheduling module, and the scheduling module can receive the first operation request sent by the client.

[0061] The proxy service includes an HTTP interface that supports HTTP transmission, allowing the client to execute database operation statements through HTTP-based requests. The HTTP interface definition is shown in Table 1. A set of rules are defined through the HTTP protocol so that the client can communicate with the proxy service. The rules include the request method, request path, parameters, authentication, and the format of the database statement.

[0062] Table 1 HTTP interface definition table

[0063]

[0064] The HTTP interface may be provided in a scheduling module, and the proxy service receives the first operation request for the database sent by the client through the scheduling module.

[0065] In an embodiment of the present application, the database operation statement can be any SQL statement type, such as a query statement, a create, delete, or modify statement, a start transaction statement, a commit transaction statement, a rollback transaction statement, and a setting statement.

[0066] S2021. When the first condition is not met, create a first session between the client and the proxy service, establish a first Transmission Control Protocol TCP connection between the proxy service and the database, store the correspondence between the session identifier of the first session and the connection identifier of the first TCP connection in a first mapping relationship; use the first TCP connection as the target TCP connection; send first session information of the first session to the client; wherein the session information of any session includes the session identifier of any session; the first mapping relationship includes the correspondence between the session identifier of at least one created session and the connection identifier of the corresponding TCP connection; not meeting the first condition includes that the first operation request does not include the session information.

[0067] In an embodiment of the present application, the scheduling module is also used to determine whether the first condition is met, wherein one situation in which the first condition is not met is that the first operation request does not include session information. Session information is information generated after the client and the proxy service establish a session. If the first operation request includes session information, it means that a session has been established between the client and the proxy service before the client sends the first operation request; if the first operation request does not include session information, it means that no session has been established between the client and the proxy service, and at this time the connection cache module will create a first session between the client and the proxy service.

[0068] The connection cache module establishes a first session with the client, and generates first session information corresponding to the first session, wherein the session information includes a session identifier of the first session, and the session identifier may be represented by SessionID.

[0069] At the same time, the connection cache module will also establish a first TCP connection between the proxy service and the database, use the first TCP connection as the target TCP connection, and correspond the session identifier of the first session with the first connection identifier of the first TCP connection, and store the correspondence in the first mapping relationship.

[0070] In the embodiment of the present application, the connection cache module may store the generated first TCP connection in the cache of the proxy service, and obtain the first TCP connection from the cache when the first TCP connection is needed later.

[0071] In the embodiment of the present application, the data processing module in the proxy service is further configured to send the generated first session information of the first session to the client.

[0072] S2022: If the first operation request includes session information, use the session information as the second session information, determine the connection identifier corresponding to the session identifier in the second session information based on the stored first mapping relationship, and use the second TCP connection corresponding to the connection identifier as the target TCP connection.

[0073] In an embodiment of the present application, when the first operation request includes session information, it indicates that a session has been established between the client and the proxy service, and the session information is used as the second session information. The session corresponding to the second session information is the second session. It should be understood that when the proxy service generates the second session, a second TCP connection between the proxy service and the database is also established, and the correspondence between the second session identifier of the second session information and the connection identifier of the second TCP connection is stored in the first mapping relationship.

[0074] Therefore, when the first operation request includes the second session information, the connection cache module is further used to determine the connection identifier corresponding to the session identifier based on the first mapping relationship and the session identifier in the second session information, thereby obtaining the second TCP connection corresponding to the connection identifier and using the second TCP connection as the target TCP connection. The connection cache module can obtain the second TCP connection from the cache of the proxy service based on the connection identifier.

[0075] S203, communicating with the database through the target TCP connection, executing the database operation statement through the database, obtaining the execution result, and sending the execution result to the client.

[0076] In an embodiment of the present application, the proxy service also includes an execution module, which can parse the database operation statement in the first operation request to identify the database operation statement, and then communicate with the database through the target TCP connection, initiate a request to the database, and execute the database operation statement through the database. It should be understood that the database can be understood as a database server, and the proxy service is a proxy server.

[0077] The target TCP connection is a first TCP connection newly created by the connection cache module or a second TCP connection determined by the connection cache module according to the connection identifier.

[0078] In an embodiment of the present application, the data processing module is also used to perform data processing on the execution results and return the execution results to the client. As an optional embodiment, the client receives the execution results through a driver and performs data processing on the execution results through the driver so that the client can communicate with the proxy service through the driver.

[0079] It should be understood that operations for accessing a database can be divided into transactional operations and non-transactional operations. When a client processes a transactional operation or a non-transactional operation, it may generate multiple first operation requests corresponding to the transactional operation, or it may generate multiple first operation requests corresponding to the non-transactional operation. When the first operation request is a request corresponding to a transactional operation, the request type of the first operation request is a transactional request, and when the first operation request is a request in a non-transactional operation, the request type of the first operation request is a non-transactional request.

[0080] The HTTP protocol is stateless, that is, the requests corresponding to the states of a transactional operation such as Begin, In Progress (including add, delete, check, modify), Commit or Rollback are all independent, so accessing the database through the HTTP protocol does not support transactional operations. In the embodiment of the present application, by setting session information in the information transmission between the client and the proxy service, the state of the transactional operation during execution can be maintained, so that the database access method provided in the embodiment of the present application supports transactional operations.

[0081] In an embodiment of the present application, regardless of whether the first operation request is a transactional request or a non-transactional request, if the first operation request does not include session information, a session can be created between the client and the proxy service, and a TCP connection can be established between the proxy service and the database to improve the versatility of the database access process; as an optional embodiment, in order to improve the processing efficiency of non-transactional requests, session information may not be set for non-transactional requests, and when the proxy service receives the first operation request of the non-transactional request, the database operation statement in the first operation request may be executed.

[0082] The embodiment of the present application, the beneficial effect of the technical solution provided by the embodiment of the present application is: after receiving the first operation request sent by the client through HTTP, according to whether the first operation request includes session information, it is determined whether the first operation request has a corresponding TCP connection, and when there is no corresponding TCP connection, a TCP connection is established, and when there is a corresponding TCP connection, the database operation statement in the first operation request is executed through the TCP connection, the execution result is obtained, and the execution result is returned to the client, thereby realizing HTTP-based access to the database, solving the problem that a TCP connection cannot be established and the database cannot be accessed in some scenarios. In addition, in the embodiment of the present application, when the first operation request does not include session information, a session between the client and the proxy service is established, session information is generated, and a corresponding relationship between the session representation of the session and the connection identifier of the TCP connection is established, so that the first operation request corresponding to the same session can be executed through the same TCP connection, so that the database access method provided by the embodiment of the present application can support transactional database requests. Furthermore, in an embodiment of the present application, the proxy service and the database are deployed on the same backbone network, which reduces the distance between the proxy service and the database and shortens the data transmission time between the database and the proxy service. Compared with the method of accessing the database based on TCP connection, the speed of connecting to the database is improved and the delay problem caused by introducing the middle layer is solved.

[0083] As an optional embodiment of the present application, the client is installed with at least one driver;

[0084] The first operation request is generated by the client in the following way:

[0085] Receive an operation instruction for a database, the operation instruction including a driver identification and a database operation statement, wherein a target driver corresponding to the driver identification matches a programming language of the database operation statement;

[0086] determining a target driver from at least one driver according to the driver identifier;

[0087] According to the database operation statement, a first operation request is generated through a target driver.

[0088] In an embodiment of the present application, multiple drivers are provided for the client, each driver is written based on a programming language, encapsulates the code for converting the database operation statement of the corresponding programming language into the first operation request, and provides a simple and easy-to-use interface to the user.

[0089] The programming language corresponding to the database operation statement can be JavaScript, Go or Java. When the user enters the database operation statement in the client, he needs to enter the operation instruction including the driver identification and the database operation statement to indicate the driver to be used, wherein the driver identification can be the installation address of the driver in the client. It should be noted that the database operation statement is in the operation instruction, so the programming language corresponding to the operation instruction is also the programming language corresponding to the database operation statement.

[0090] like Figure 3 As shown, Figure 3 A schematic diagram of another system architecture for database access provided in an embodiment of the present application. Figure 3 Some clients in the embodiments of the present application are listed in the specification, including terminal devices with browsers installed, terminal devices with applications installed, the terminal devices can be mobile devices, and the clients can directly serve some virtual edge functions. Each client provides users with an environment for inputting operation instructions, and operation instructions can be input through applications, browsers, and edge function services. Taking the browser as an example, the user inputs the operation instructions of the corresponding programming language in the browser according to the programming language of the browser, and specifies the driver identifier of the driver corresponding to the programming language in the operation instructions. Figure 3 In the example, if the programming language corresponding to the browser is JavaScript, the programming language of the operation instruction is also JavaScript. Furthermore, the operation instruction includes the driver identification of the driver corresponding to JavaScript. The driver is connected to the proxy service through an HTTP connection. That is, the driver corresponding to the programming language can be found according to the programming language corresponding to the application scenario input by the user. When the application is in Go language, the driver corresponding to Go language can be used. When the application is in Java language, the driver corresponding to Java language can be used.

[0091] In the embodiment of the present application, the driver provides a simple request interface, and the driver is similar in design to the existing TCP driver, following the same design principles and usage. When using the driver, the user does not need to change the operation method that he is already familiar with, and can use it like using a traditional TCP driver.

[0092] The driver program requests the proxy service internally, encapsulates the complex processing details for the user, and is used to process the execution results sent by the proxy service. In an embodiment of the present application, the client may be a terminal device with an application and a browser installed, or it may be an edge function service. The user may enter an operation instruction in the application program, browser, or edge function service. The operation instruction may include an interface identifier and parameter information to be called, wherein the interface corresponding to the interface identifier may be an interface provided by the driver program for processing database operation statements, and the parameter information may include database operation statements, as well as information such as the access address, user name, and user name password. It should be understood that the user will determine the corresponding driver program based on the programming language used, thereby adding a driver program identifier to the operation instruction to specify the driver program, so that the client program can call the corresponding target driver program based on the driver program identifier.

[0093] As an optional embodiment, the interface corresponding to the interface identifier in the operation instruction may be an interface provided by the driver for processing transactional operations or non-transactional operations. The driver processes the database operation statement according to the interface corresponding to the interface identifier in the operation instruction. Figure 4 As shown, Figure 4 A schematic diagram of a non-transactional operation interface and a transactional operation interface of a driver provided in an embodiment of the present application. Among them, the Connect interface uses the execute method to process non-transactional operations, converts non-transactional database operation statements into corresponding first operation requests, and can be upgraded to the Tx interface through the begin method. The Tx interface uses the execute method to process transactional operations, converts transactional operations into corresponding first operation requests, and can also use the commit and rollback methods to commit and rollback transactional operations.

[0094] In an embodiment of the present application, the client determines the corresponding target driver by receiving an operation instruction, converts the database operation statement into a corresponding first operation request through the target driver, and sends the first operation request to the proxy service. Through the cooperation between the driver and the proxy service, the client accesses the database based on the HTTP protocol.

[0095] As an optional embodiment of the present application, any session information further includes a proxy service identifier;

[0096] Determining, based on the stored first mapping relationship, a connection identifier corresponding to the session identifier in the second session information, includes:

[0097] If the proxy service identifier in the second session information is a proxy service identifier of a proxy service, determining a connection identifier corresponding to the second session identifier in the second session information based on the stored first mapping relationship;

[0098] The method also includes:

[0099] If the proxy service identifier in the second session information is not the proxy service identifier of the proxy service, the first operation request is sent to the target proxy service corresponding to the proxy service identifier in the second session information.

[0100] like Figure 5 As shown, Figure 5 A schematic diagram of another system architecture for database access provided for an embodiment of the present application. In an embodiment of the present application, the number of proxy services may be multiple, and different proxy services may be connected to each other through a scheduling module. When there is at least one proxy service, the connection cache module of the proxy service includes the proxy service identifier of the proxy service in the generated session information, and the proxy service identifier may be represented by {instance ID}, which is used to indicate which proxy service the two parties of the session corresponding to the session information are the client and. The client sends the first operation request to the proxy service through a content delivery network (CDN) or a load balancer to shorten the access delay.

[0101] In an embodiment of the present application, after the scheduling module of the proxy service receives the first operation request, if there is session information in the first operation request, that is, the second session information, the second session information is parsed, and the proxy service identifier is determined from the second session information to determine whether the second session corresponding to the second session information corresponds to the present proxy service.

[0102] If the proxy service identifier in the second session information is the proxy service identifier of the present proxy service, the first operation request will continue to be processed in an embodiment of the present application; if the proxy service identifier in the session information is not the proxy service identifier of the present proxy service, the scheduling module in the present proxy service will forward the first operation request to the target proxy service corresponding to the proxy service identifier in the second session information, so that the scheduling module of the target proxy service receives the first operation request, and based on the target proxy service, the target proxy service processes the first operation request.

[0103] In the embodiment of the present application, by setting a proxy service identifier in the session information, the proxy service can determine whether the session corresponding to the first operation request is related to itself, so that when there are multiple proxy services, no additional components are required to determine the proxy service corresponding to the first operation request, and the proxy service corresponding to the first operation request can be determined. Therefore, the corresponding proxy service can be found for the first operation request in the transactional operation, thereby achieving the state maintenance of the transactional operation when there are multiple proxy services.

[0104] As an optional embodiment of the present application, the first operation request includes indication information, where the indication information is used to indicate a request type corresponding to the first operation request, where the request type is a transactional request or a non-transactional request, and the database access method further includes:

[0105] If sending the first operation request to the target proxy service fails, determining a request type corresponding to the first operation request based on the indication information;

[0106] If the request type is a transactional request, a request failure is returned to the client;

[0107] Among them, not meeting the first condition includes:

[0108] The request type is a non-transactional request and sending the first operation request to the target proxy service fails.

[0109] In an embodiment of the present application, the first operation request includes indication information, where the indication information is used to indicate whether the request type corresponding to the first operation request is a transactional request or a non-transactional request.

[0110] In an embodiment of the present application, if the proxy service identifier in the session information is not the proxy service identifier of the present proxy service, the scheduling module of the proxy service forwards the first operation request to the target proxy service corresponding to the proxy service identifier in the session information. During the forwarding process, if the forwarding fails due to a failure of the target proxy service, a connection failure between the proxy service and the target proxy service, or other reasons, the proxy service determines whether the request type of the first operation request is a transactional request or a non-transactional request based on the indication information in the first operation request.

[0111] It should be understood that transactional operations need to meet consistency, that is, the states of different transactional operations are maintained. Therefore, if the request type of the first operation request is a transactional request, the request result of the first operation request returned to the client is a request failure.

[0112] In the embodiment of the present application, the situation that the first condition is not met may also be that the request type of the first operation request is a non-transactional request, and the first operation request fails to be sent to the target proxy service. That is, when the sending to the target proxy service fails and the first operation request type is a non-transactional request, step S2021 is also performed. It should be understood that non-transactional operations do not require state retention, so if the first operation request is a non-transactional request, a new TCP connection can be established and the first operation request can continue to be processed in this proxy service.

[0113] In an embodiment of the present application, by setting indication information in the first operation request, the proxy service can determine the request type corresponding to the first operation request. When forwarding the first operation request to the target proxy service fails, the subsequent operation is determined according to the request type. The first operation requests corresponding to transactional operations and non-transactional operations can be processed separately. On the basis of supporting transactional operations, the processing efficiency of non-transactional operations can also be improved.

[0114] In an embodiment of the present application, the indication information may be to determine the request type corresponding to the first operation request by determining whether the first character or the second character exists in the first operation request. If the first character or the second character exists in the indication information, the request type of the first operation request is a transactional request; if the first character or the second character does not exist in the indication information, the request type of the first operation request is a non-transactional request.

[0115] In the embodiment of the present application, the first character may be a character in a database operation statement, and the second character may be a character in session information.

[0116] It should be understood that, for the first operation request corresponding to a transactional operation or a non-transactional operation, the first operation request does not include session information, and the indication information may be whether the database operation statement in the first operation request includes the first character, such as the "begin" character. That is, if the first operation request does not include session information but includes the first character, the proxy service determines that the first operation is a transactional operation; if the first operation request does not include a session identifier and does not include the first character, the proxy service determines that the first operation is a non-transactional request.

[0117] In an embodiment of the present application, for a non-first first operation request corresponding to a transactional operation or a non-transactional operation, the proxy service can determine whether the first operation request is a transactional request or a non-transactional request based on the second character. After receiving the first first operation request of a transactional operation or a non-transactional operation, the proxy service generates session information including the second character, and after receiving the first first operation request of a non-transactional operation, generates session information not including the second character, and the second character can be "tx". For example, the session information of a transactional request can be tx_${SessionID}_${Instance ID}, and the session information of a non-transactional request can be ${SessionID}_${Instance ID}, where "SessionID" represents a session identifier and "Instance ID" represents a proxy service identifier. Therefore, when the first operation request includes session information and there is "tx" in the session information, it indicates that the first operation request is a transactional request. When the first operation request includes session information and there is no "tx" in the session information, it indicates that the first operation request is a non-transactional request.

[0118] The first character may also be "rollback" or "commit". It should be understood that the methods corresponding to "rollback" and "commit" are instructions used in transactional operations. Therefore, when the database operation statement includes the first character, it can also be determined that the first operation request is a transactional request.

[0119] As an optional embodiment of the present application, each TCP connection has a corresponding timeliness status, and the timeliness status is used to characterize whether the TCP connection is valid; the first operator request includes indication information, and the indication information is used to indicate a request type corresponding to the first operation request, and the request type is a transactional request or a non-transactional request;

[0120] Communicate with the database through the target TCP connection and execute database operation statements through the database, which also includes:

[0121] Determine the aging status of the target TCP connection;

[0122] If the time validity status of the target TCP connection is valid, a keep-alive task is performed on the target TCP connection to make the target TCP connection valid when executing database operation statements;

[0123] If the time validity state of the target TCP connection is invalid, determining the request type corresponding to the first operation request based on the indication information; if the first operation request is a transaction request, returning a request failure to the client;

[0124] The first condition not being met includes: the first operation request is a non-transactional request and the timeliness status of the target TCP connection is invalid.

[0125] In an embodiment of the present application, in order to support transactional operations, it is necessary to maintain a TCP connection in the proxy service. However, maintaining a connection for a long time will cause the number of database connections to continue to grow, resulting in a waste of resources and affecting database performance. To this end, an embodiment of the present application proposes to establish a survival time (Time To Live, TTL) mechanism for TCP connections. The TTL mechanism can refresh the survival time during the use of the connection and clean up expired connections after the connection has been idle for more than a certain period of time. If the connection has not expired, a Ping operation is performed to prevent the connection from being disconnected by the server. If the connection expires, the connection will be actively closed.

[0126] Specifically, in the embodiment of the present application, each TCP connection has the attribute of an expiration state, and the expiration state includes two states: valid and invalid. An invalid TCP connection is also called an expired TCP connection. The connection cache module of the proxy service can determine the TCP connection based on the connection identifier, and the execution module executes the database operation statement through the TCP connection, and any TCP connection that executes the database operation statement is used as the target TCP connection.

[0127] In the embodiment of the present application, before executing the database operation statement, the validity state of the target TCP connection is determined. If the validity state of the target TCP connection is valid, the connection cache module performs a keep-alive task on the target TCP connection. During the process of the connection cache module performing the keep-alive task, the execution module executes the database operation statement through the TCP connection, and the target TCP connection remains valid, thereby ensuring the smooth execution of the database operation statement in the first operation request.

[0128] like Figure 6 As shown, Figure 6 A flow chart of executing database operation statements provided for an embodiment of the present application. After the client sends an HTTP request to the proxy service, the scheduling module of the proxy service receives the HTTP request, parses the session information, sends the session information to the connection cache module, and initiates a session check to the connection cache module. The connection cache module obtains the session identifier from the session information, and determines the TCP connection corresponding to the session identifier from the first mapping relationship, thereby determining whether the TCP connection is expired, and returns the check result to another thread of the connection cache module of the proxy service. The return result here is that the TCP connection is valid, that is, it has not expired. The connection cache module of the proxy service will register a keep-alive task, and then update the TTL. The effective length of the TCP connection can be refreshed at a preset time interval. During the process of updating the TTL of the connection cache module, the execution module can execute the database operation statement. After the execution is completed, the connection cache module cancels the keep-alive task. If the TCP connection fails afterwards, the connection cache module will clean up the TCP connection.

[0129] In an embodiment of the present application, if the time validity status of the target TCP connection is invalid, the indication information in the first operation request is obtained, and the request type of the first operation request is determined. If the request type of the first operation request is a transactional request, the request result of the first operation request is returned to the client as a request failure.

[0130] In the embodiment of the present application, the situation where the first condition is not met may also be that the first operation request is a non-transactional request and the time-limit status of the target TCP connection is invalid. That is, when the time-limit status of the target TCP connection is invalid and the request type of the first operation request is a non-transactional request, step S2021 needs to be executed. It should be understood that non-transactional operations do not require state maintenance, so if the first operation request is a non-transactional request, a new TCP connection can be established, and the first operation request can continue to be processed in this proxy service.

[0131] To more clearly explain how this application accesses the database according to the request type of the first operation request, please refer to Figure 7 , Figure 7 Another database access process diagram provided for an embodiment of the present application. After receiving an HTTP request, the proxy service parses the Session information in the HTTP request, and determines whether the HTTP request needs to be forwarded based on the proxy service identifier in the Session information. If forwarding is not required, the request is processed by the proxy service; if the HTTP request needs to be forwarded and the forwarding is unsuccessful, the request type corresponding to the request is determined. If it is a transactional request, a request failure is returned to the client. If it is a non-transactional request, the request can continue to be processed.

[0132] The proxy service then parses the database operation statement in the request, determines the operation type of the database operation statement, and obtains a TCP connection from the corresponding cache based on whether the HTTP request is a transactional request or a non-transactional request. If the obtained TCP connection is valid, the database is accessed through the TCP connection to execute the parsed database operation statement. If the obtained TCP connection is invalid and the request is a transactional request, a request failure is returned to the client. If the obtained TCP connection is invalid and the request is a non-transactional request, a new connection can be established and placed in the cache, and the database is accessed through the newly created TCP connection to execute the parsed database operation statement.

[0133] In the embodiment of the present application, by setting the time-limit status of the TCP connection, the connection is closed and the cache is cleared after the TCP connection is idle for a certain period of time, and the resources of the proxy service and the database are released in time to prevent the problem of inaccessibility of the database and increased costs caused by too many connections. After the TCP connection fails, the subsequent operation is determined according to the request type of the first operation request, which can support transactional operations and improve the processing efficiency of non-transactional operations.

[0134] As an optional embodiment of the embodiment of the present application, determining the timeliness state of the target TCP connection includes:

[0135] Obtain the effective duration of the target TCP connection, and compare the effective duration of the target TCP connection with the preset effective duration;

[0136] If the effective duration of the target TCP connection is less than or equal to the effective duration, the time validity status of the target TCP connection is valid;

[0137] If the effective duration of the target TCP connection is greater than the effective duration, the validity status of the target TCP connection is invalid;

[0138] If the target TCP connection is valid, the keep-alive task is performed on the target TCP connection, including:

[0139] The effective duration of the target TCP connection is updated to 0 at a preset time interval, where the time interval is less than the effective duration.

[0140] In the embodiment of the present application, the timeliness status of the TCP connection is determined according to the effective duration of the TCP connection and the preset effective duration. For example, if the effective duration is 10 minutes, if the effective duration of the TCP connection is 5 minutes, the timeliness status of the TCP connection is effective, and if the effective duration of the TCP connection is 14 minutes, the timeliness status of the TCP connection is invalid.

[0141] When a keep-alive task is executed for a TCP connection, a new goroutine can be started to execute the keep-alive task. The keep-alive task will immediately refresh the effective duration of the TCP connection, and after a preset time interval, the effective duration of the TCP connection will be set to 0. It should be understood that the duration of the preset time interval is less than the effective duration. For example, the effective duration is 10 minutes, and the preset time interval can be 1 minute, that is, the survival time of the TCP connection, that is, the effective duration, is refreshed every one minute to ensure that the TCP connection will not expire, that is, become invalid, during the duration of the first operation request.

[0142] In the embodiment of the present application, after the database operation statement is executed, the proxy service cancels the keep-alive task, that is, the effective time of the TCP connection is no longer set to 0 at preset time intervals.

[0143] The embodiment of the present application proposes a method for determining the timeliness status of a TCP connection by presetting a valid time length, so that according to the timeliness status of the TCP connection, when the first operation request is not received, the invalid TCP connection can be cleaned up in time to reduce the waste of resources. When the first operation request is received, the keep-alive task is performed on the valid TCP connection to ensure the smooth execution of the first operation request.

[0144] As an optional embodiment, the connection cache module may store the created TCP connection in different caches according to the request type of the first operation request.

[0145] If the request type of the first operation request is a transactional request, the first established TCP connection is stored in the transactional cache, and if the type of the first operation request is a non-transactional request, the first established TCP connection is stored in the non-transactional cache. Validity periods are set for transactional requests and non-transactional requests respectively. As an optional embodiment, the validity period of transactional requests is greater than that of non-transactional requests, so that transactional requests can maintain a longer state.

[0146] The connection cache of the proxy service can obtain a TCP connection from a corresponding cache according to the session identifier in the session information and the type corresponding to the first operation request, thereby improving the efficiency of obtaining a TCP connection.

[0147] As an optional embodiment of the present application, sending the execution result to the client includes:

[0148] Convert the execution result into a first data format supporting HTTP transmission;

[0149] According to the data volume of the execution result, determine the transmission mode of sending the execution result to the client, wherein the transmission mode includes streaming transmission and batch transmission;

[0150] The execution result in the first data format is compressed, and the compressed execution result is sent to the client via the transmission method, so that the client decompresses the compressed execution result and converts the data format of the decompressed execution result into a second data format corresponding to the programming language of the database operation statement.

[0151] In the embodiment of the present application, different database operation statements will have different return information. DQL operations return data types and data, and DML operations return the number of rows affected by the operation and the last inserted primary key or row identifier (ID). Converting the execution result into a first data format includes parsing the execution result, the parsed data format is a data format supported by the proxy service, and assembling the parsed execution result into a corresponding response format, and finally encoding the encapsulated execution result into a first data format that supports HTTP transmission.

[0152] For example, if the programming language of the proxy service is Goland, the format of the parsed data can be in string format. As an optional embodiment, the method for parsing the execution result can be determined according to the data type of the execution result, and the parsing methods include Hex and UTF8. Take the database as MySQL as an example: for Blob, Tinyblob, Mediumblob, Longblob, Binary, Varbinary, Bit type data, since these types can store binary data, they are not necessarily legal UTF8 binary arrays. Directly using UTF8 for parsing will cause data loss or errors. Therefore, for this type of data, Hex is used to parse the data; since Hex will increase the data size, UTF8 is used for data parsing for other types of data.

[0153] In the embodiment of the present application, when assembling the parsed execution results, the execution results can be assembled according to the predefined response formats of different database operation statements. Figure 8 As shown, Figure 8 Provides a schematic diagram of the response format of the execution results of different database operation statements, including the response format of the DQL operation execution result and the response format of the DML execution result. QueryResponse is the response format of the DQL operation, and ExecuteResponse is the application format of the DML operation. When the database operation statement is a DQL operation, the execution result includes the queried data and the data type, where FieldType is the data type corresponding to the data.

[0154] In an embodiment of the present application, Json can be used to encode the assembled execution result, and the execution result can be encoded into a first data format that supports HTTP transmission. The return information including session information and execution results can be encoded as a whole to improve the efficiency of return information transmission.

[0155] In an embodiment of the present application, the transmission mode of sending the execution result to the client can be determined according to the data volume of the execution result. The transmission mode can include streaming transmission and batch transmission. When selecting the transmission mode, a data volume threshold can be set, and the transmission mode is determined according to the relationship between the data volume of the execution result and the data volume threshold.

[0156] As an optional embodiment, if the data volume of the execution result is less than or equal to a preset data volume threshold, batch transmission is selected, and if the data volume of the execution result is greater than the preset data volume threshold, streaming transmission is selected. Further, when selecting streaming transmission, whether the client supports streaming transmission can also be considered. If the client does not support streaming transmission, batch transmission is also used when the data volume of the execution result is greater than the preset data volume threshold. The data volume can be the number of rows of data in the execution result.

[0157] Streaming can reduce memory consumption and improve data processing efficiency. When the transmission mode is streaming, the HTTP keep-alive mode can be enabled to keep the connection between the client and the proxy service alive, allowing the HTTP connection to remain open after sending and receiving data, rather than closing it immediately, to reduce the overhead of frequent establishment and disconnection of connections. At the same time, streaming can also enable chunked transfer encoding (Transfer-Encoding: chunked), and the server will divide the data into a series of chunks for sending, and the size of each chunk will be marked before it. In this way, the client can know the beginning and end of each chunk, thus avoiding the problem of data sticking. Streaming can send the data type when sending the first chunk, and then send a chunk for every 10,000 lines of data.

[0158] like Fig. 9 As shown, Fig. 9 A flow chart of data processing provided for an embodiment of the present application. After the proxy service obtains the execution result, it determines the transmission method according to the amount of data in the execution result obtained and whether the client prohibits streaming transmission, and then obtains the type of data. According to whether the data type can store binary data, it determines the method of parsing the data, including UTF8 and HEX parsing methods. After parsing the data, the data is assembled and encoded based on Json. If the subsequent transmission uses streaming transmission, the keep-alive mode in HTTP is turned on, and the data is divided into a series of blocks, and each block is encoded and transmitted.

[0159] In the embodiment of the present application, the execution result of the first data format may also be compressed using a file compression program (GNUzip, gzip) to reduce the amount of communication data and reduce data transmission delay.

[0160] In the embodiment of the present application, the data processing module of the proxy service can encapsulate the execution result and the corresponding session information into a return result, where the execution result can be an execution result in the first data format or a compressed execution result. When encapsulating, the return header information of the return result can be generated according to the session information, and the return body information of the return result can be generated according to the execution result. For example:

[0161] Return header: Session: ${session}

[0162] Successful return body:

[0163] {

[0164] "types":[ ]object(FiledType), / * DQL return* /

[0165] "rows":[ ][ ]"string" / * DQL returns* /

[0166] "RowsAffected": int, / * DML returns* /

[0167] "LastInsertID": "string" / * DML returns * /

[0168] }

[0169] / / FiledType

[0170] {

[0171] "name": "string",

[0172] "type": "string",

[0173] "nullable": bool

[0174] }

[0175] Failure return body

[0176] {

[0177] "code": int,

[0178] "message": "string"

[0179] }

[0180] Return to example

[0181] DQL returns

[0182] {

[0183] "types":

[0184] {

[0185] "name": "id",

[0186] "type": "INT",

[0187] "nullable": false

[0188] },

[0189] {

[0190] "name": "name",

[0191] "type": "VARCHAR",

[0192] "nullable": true

[0193] }

[0194] ,

[0195] "rows":

[0197] "1",

[0198] "a"

[0199] ,

[0201] "2",

[0202] "b"

[0204] ,

[0205] "rowsAffected": 0,

[0206] "lastInsertID": 0

[0207] }

[0208] DML Return

[0209] {

[0210] "types": null,

[0211] "rows": null,

[0212] "rowsAffected": 1,

[0213] "lastInsertID":​​​

[0214] }

[0215] Error Response

[0216] {

[0217] "code": 61100002,

[0218] "message": "Query fail: Error 1146 (42S02): Table 'test.t2' doesn'texist"

[0219] }

[0220] In an embodiment of the present application, after the client obtains the execution result, it can decompress the compressed execution result and convert the data format of the decompressed execution result into a second data format corresponding to the programming language of the database operation statement.

[0221] As an optional embodiment, the driver installed on the client is used to receive the return result sent by the proxy service. If the execution result is a compressed execution result, the client can decompress the compressed execution result through the driver, and can convert the data format of the execution result into a second data format corresponding to the programming language corresponding to the operation instruction and the database operation statement according to the data type of the data in the execution result. For example, the JavaScript language correspondence is shown in Table 2. The driver can convert the data into the corresponding data type in the JavaScript language according to the data type.

[0222] Table 2 JavaScript language and database data type correspondence table

[0223]

[0224] like Fig.10 As shown, Fig.10 A flowchart of a driver program for accessing a database provided in an embodiment of the present application. The user makes an SQL request in the client application and passes in configuration information including connection information, including database path information, user name and password information, and database operation statements. The driver program assembles HTTP request parameters based on the configuration information and Session information, where the Session is empty for the first request. The driver program reads and returns information based on JSON decoding, which includes Session, data, and type information. The driver program converts the data into the corresponding type of its implementation language based on the database type.

[0225] In the embodiment of the present application, the execution results are parsed, assembled, encoded and compressed to convert the execution results transmitted via TCP into HTTP transmission, thereby realizing the conversion of the two protocols, so that user environments such as mobile devices that do not support TCP access to the database can access the database through HTTP, and the transmission speed is fast, reducing the access delay.

[0226] The following are specific examples of transactional and non-transactional requests:

[0227] The specific process of transactional requests includes:

[0228] S1. The user uses the driver connect method to obtain a Connect object instance, and then calls the begin method of the Connect object instance to start a transaction request;

[0229] S2. The driver constructs an HTTP request server proxy service, where the request contains a begin statement; the request is accelerated by the CDN or forwarded to a specific proxy service instance by nginx or other load balancers;

[0230] S3, the proxy service scheduling module receives the request, but the request does not carry the Session and is therefore not forwarded;

[0231] S4, the proxy service execution module parses the SQL as a Begin request;

[0232] S5. The proxy service connection cache module creates a new connection, generates a Session, and caches the corresponding relationship between the Session and the TCP connection;

[0233] S6, the proxy service execution module uses the newly created connection to execute the begin statement;

[0234] S7, the proxy service data processing module parses the database return result and encapsulates the HTTP return result, which includes the Session information;

[0235] S8. The driver receives the HTTP response, generates a Tx object instance containing the Session, and returns it to the user.

[0236] S9. The user executes the begin interface successfully and obtains a Tx object instance;

[0237] S10, the user uses the driver to call the execute method of the Tx object instance, and the method parameter includes the SQL statement;

[0238] S11. The driver constructs an HTTP request server proxy service, where the request includes the SQL statement and Session information passed in by the user; the request is accelerated by CDN or forwarded to a specific proxy service instance by nginx or other load balancers;

[0239] S12, the proxy service scheduling module receives the request, parses the session to obtain instance information, and forwards it to the correct instance;

[0240] S13, the proxy service execution module parses the SQL, and the result may be DQL, DML or Execute;

[0241] S14. The proxy service connection cache module obtains the cached TCP connection according to the Session; at the same time, a keep-alive task is started to refresh the connection expiration time every minute to ensure that the connection will not expire during use;

[0242] S15, the proxy service execution module uses the acquired connection to execute the SQL statement;

[0243] S16, the proxy service data processing module parses and encodes the result returned by the database, compresses it and encapsulates it as an HTTP return result;

[0244] S17, the proxy service connection cache module closes the keep-alive task;

[0245] S18, the driver receives the HTTP return result, decompresses and decodes the data, then converts the data according to the data type, and finally returns it to the user;

[0246] S19. The user successfully executes the execute interface and obtains the execution result;

[0247] S20, the user uses the driver to call the commit method of the Tx object instance to end a transaction request;

[0248] S21, the driver constructs an HTTP request server proxy service, wherein the request includes a Commit statement; the request is accelerated by the CDN or forwarded to a specific proxy service instance by nginx or other load balancers;

[0249] S22, the proxy service scheduling module receives the request, parses the session to obtain instance information, and forwards it to the correct instance;

[0250] S23, the proxy service execution module parses the SQL into a Commit request;

[0251] S24, the proxy service connection cache module obtains the cached TCP connection according to the Session;

[0252] S25, the proxy service execution module uses the newly created connection to execute the commit statement;

[0253] S26, the proxy service data processing module parses the database return result and encapsulates the HTTP return result;

[0254] S27, the driver receives the HTTP response result and returns it to the user;

[0255] S28. The user executes the commit interface successfully and the transaction process ends.

[0256] Take the JavaScript API interface of the driver as an example:

[0257] A specific implementation example of a transactional request is to transfer money through the driver program. User 1 transfers 10 to user 2:

[0258]

[0259] The above process is to construct a Connect object instance through the connect method and connection parameters; upgrade to a transaction connection through the begin method of the Connect object instance, and execute in the same transaction connection afterwards; execute SQL through the execute method of the Connect object instance: reduce the account of user 1 by 10; execute SQL through the execute method of the Connect object instance: increase the account of user 1 by 10; commit the transaction through the commit method of the Connect object instance; when an exception occurs, roll back the transaction through the rollback method of the Connect object instance. Among them, @database / driver is the installation address of the target driver, which is used as the driver identifier in the embodiment of this application.

[0260] It should be understood that in the above embodiment, the user inputs the above information at one time, and the driver generates multiple first operation requests in sequence according to the input information, and needs to obtain the return result of the previous first operation request before generating the next first operation request.

[0261] Example of non-transactional request flow:

[0262] S1. The user uses the driver connect method to obtain a Connect object instance, and then calls the execute method of the Connect object instance to make a non-transaction request; the method parameter contains a SQL statement;

[0263] S2. The driver builds an HTTP request server proxy service, where the request contains the SQL statement passed in by the user; the request is accelerated by the CDN or forwarded to a specific proxy service instance through nginx or other load balancers;

[0264] S3, the proxy service scheduling module receives the request. The first request does not carry the Session and is therefore not forwarded;

[0265] S4, the proxy service execution module parses the SQL;

[0266] S5. The proxy service connection cache module creates a new connection, generates a session, and caches the correspondence between the session and the TCP connection. At the same time, a keep-alive task is started to refresh the connection expiration time every minute to ensure that the connection will not expire during use.

[0267] S6, the proxy service execution module uses the newly created connection to execute the SQL statement;

[0268] S7, the proxy service data processing module parses and encodes the result returned by the database, compresses it and encapsulates it as an HTTP return result;

[0269] S8, the proxy service connection cache module closes the keep-alive task;

[0270] S9. The driver receives the HTTP response, decompresses and decodes the data, converts the data according to the data type, and finally returns it to the user; at the same time, it updates the Session information in the Connect object instance;

[0271] S10. The user successfully executes the execute interface and obtains the execution result;

[0272] S11. The user uses the Connect object instance (which already contains the Session) in the first request in the driver program and calls its execute method to make a non-transactional request; the method parameters contain SQL statements;

[0273] S12, the driver builds an HTTP request server proxy service, where the request includes the SQL statement passed in by the user; the request is accelerated by the CDN, or the request is forwarded to a specific proxy service instance through nginx or other load balancers;

[0274] S13, the proxy service scheduling module receives the request, which is not the first request carrying the Session, so it is forwarded to the correct instance;

[0275] S14, the proxy service execution module parses the SQL;

[0276] S15. The proxy service connection cache module finds the connection according to the Session and determines whether the connection is expired; if it is not expired, the connection is used; if it is expired, a new connection is created and a new Session is generated, and the corresponding relationship between the new Session and the TCP connection is cached; at the same time, a keep-alive task is started to refresh the connection expiration time every one minute to ensure that the connection will not expire during use;

[0277] S16, the proxy service execution module uses the newly created connection to execute the SQL statement;

[0278] S17, the proxy service data processing module parses and encodes the result returned by the database, compresses it and encapsulates it as an HTTP return result;

[0279] S18, the proxy service connection cache module closes the keep-alive task;

[0280] S19, the driver receives the HTTP return result, decompresses and decodes the data, then converts the data according to the data type, and finally returns it to the user; if it is a new session established after the forwarding fails, the Session information in the Connect object instance also needs to be updated;

[0281] S20. The user executes the execute interface successfully and obtains the execution result.

[0282] Non-transactional requests create, insert, and query tables through the driver:

[0283]

[0284] The above process includes constructing a Connect object instance through the connect method and connection parameters, and creating a table through the execute method of the Connect object instance. The first request to the proxy service will return a Session, and the underlying layer of subsequent requests will carry this Session request; insert a data; and query the data.

[0285] Similar to transactional operations, in the above embodiment, the user inputs the above operation instruction at one time, and the driver generates multiple first operation requests in sequence according to the operation instruction, and needs to obtain the return result of the previous first operation request before generating the next first operation request.

[0286] In the embodiment of the present application, HTTPS can be used instead of HTTP, that is, the client communicates with the proxy service through HTTPS. HTTPS is a more secure transmission protocol than HTTP.

[0287] like Fig.11 As shown, Fig.11Another system architecture diagram for database access provided by the embodiment of the present application. Among them, CDN, HTTP proxy service and database are deployed in the same backbone network, HTTP proxy service and database are deployed in the same Kubernetes cluster, or in the same rack, and the driver is deployed in the user operating environment, which can be a browser, application and edge function service. The driver can convert the information input by the user through the browser, application and edge function service into an HTTPS request, which is based on TLS1.3. The HTTPS request first reaches the CDN and is accelerated to the HTTP proxy service through the CDN. The connection cache module in the HTTP proxy service can cache the TCP connection and access the database through the TCP connection. At this time, the TCP connection does not need to be based on TLS to obtain the execution result. There is data in the execution result. The proxy service can compress the data and send it to the driver through HTTPS. After the driver decompresses the returned result, it sends it to the browser, application or edge function service.

[0288] Compared to TCP+TLS, HTTP+TLS (HTTPS) in the embodiment of the present application takes less time in the connection establishment phase. Compared to TLS1.2, TLS1.3 can further reduce the connection establishment from 3 round-trip communications to 2 round-trip communications, further shortening the connection delay. TCP+TLS requires 5 round-trip communications, while HTTPS only requires 3 round-trip communications. The strategy of deploying close to the database is used to shorten the TCP connection communication distance. If deployed in the same network backbone, data security can be guaranteed, and the TCP connection can choose not to enable TLS, which can greatly reduce the connection delay.

[0289] like Fig.12 As shown, Fig.12 A comparison chart of the execution time of database operation statements under different drivers provided in the embodiment of the present application, using the driver under the complete embodiment of the present application as an HTTP driver, requesting the database based on the HTTP driver and the traditional TCP driver and executing a simple show databases statement. In 10 tests, the average time used for operation using the HTTP driver of the embodiment of the present application was 13ms, while the average time used for operation using the TCP driver in the prior art was 21ms. Therefore, the database access method provided in the embodiment of the present application has a greatly improved access speed compared to the traditional TCP access method.

[0290] The present application embodiment provides a database access device, such as Fig.13As shown, the database access device is applied to the proxy service, and the proxy service and the database are deployed in the same backbone network. The device may include: a scheduling module 1301, a connection cache module 1302, an execution module 1303 and a data processing module 1304, wherein:

[0291] The scheduling module 1301 is used to receive a first operation request for the database sent by the client, where the first operation request is a request based on the Hypertext Transfer Protocol (HTTP), and the first operation request includes a database operation statement, wherein the communication connection between the client and the proxy service is an HTTP connection;

[0292] The connection cache module 1302 is used to create a first session between the client and the proxy service, and establish a first transmission control protocol TCP connection between the proxy service and the database when the first condition is not met, and store the corresponding relationship between the session identifier of the first session and the connection identifier of the first TCP connection in a first mapping relationship; the first TCP connection is used as a target TCP connection; wherein the session information of any session includes the session identifier of any session; the first mapping relationship includes the corresponding relationship between the session identifier of at least one created session and the connection identifier of the corresponding TCP connection; the failure to meet the first condition includes that the first operation request does not include the session information;

[0293] The connection cache module is further configured to, if the first operation request includes session information, use the session information as the second session information, and determine, based on the stored first mapping relationship, a connection identifier corresponding to the session identifier in the second session information, and use the second TCP connection corresponding to the connection identifier as the target TCP connection;

[0294] An execution module 1303 is used to communicate with the database through the target TCP connection and execute the database operation statement through the database;

[0295] The data processing module 1304 is used to send the first session information of the first session to the client; and is also used to obtain the execution result and send the execution result to the client.

[0296] In the embodiment of the present application, the HTTP request is first routed to the proxy service scheduling module by a general routing component (such as nginx). The scheduling module forwards the HTTP request based on the Session information. If the forwarding fails, it will also determine whether it can fall back to the current instance for execution based on whether the request type is a transaction. The scheduling module does not need to deploy other components and forwards between instances as part of the proxy service.

[0297] Execution module: includes two functions: SQL parsing and SQL execution. SQL parsing classifies SQL into several categories based on the syntax tree: DQL, DML, Begin, Commit, Rollback, Execute, and Unsupported. SQL execution obtains or creates a new TCP connection from the connection cache module and makes a request to the database based on the SQL category.

[0298] Connection cache module: responsible for creating and caching TCP connections, maintaining transactional connection cache and non-transactional connection cache. The connection cache module will establish a TCP connection with the database and cache it when the user makes the first request, and then manage the life cycle of the connection based on the TTL mechanism and scheduled cleanup tasks: all TCP connections have a survival time of 10 minutes, which will be refreshed when the connection is used. When the survival time is reached, the connection is considered expired, and the cleanup task will close the connection and clean up the connection cache. When the transaction connection is cleaned up, subsequent requests will return an error.

[0299] Data processing module: For the data returned by the database, it obtains the type information and data information respectively, and accurately decodes it according to the type information, and finally encapsulates it into a return body and transmits it to the client driver through the HTTP protocol. Since the amount of data that can be transmitted by the HTTP protocol is limited, the data processing module will also choose whether to use streaming transmission based on the amount of data.

[0300] The device of the embodiments of the present application can execute the method provided by the embodiments of the present application, and the implementation principles are similar. The actions performed by each module in the device of each embodiment of the present application correspond to the steps in the method of each embodiment of the present application. For the detailed functional description of each module of the device, please refer to the description in the corresponding method shown in the previous text, which will not be repeated here.

[0301] In an embodiment of the present application, an electronic device is provided, including a memory, a processor, and a computer program stored in the memory, and the processor executes the above-mentioned computer program to implement the steps of the database access method. Compared with the related art, it can be implemented as follows: after receiving a first operation request sent by a client via HTTP, according to whether the first operation request includes session information, it is determined whether the first operation request has a corresponding TCP connection, and when there is no corresponding TCP connection, a TCP connection is established, and when there is a corresponding TCP connection, the database operation statement in the first operation request is executed through the TCP connection, the execution result is obtained, and the execution result is returned to the client, thereby implementing HTTP-based access to the database, solving the problem that a TCP connection cannot be established in some scenarios and thus the database cannot be accessed. In addition, in an embodiment of the present application, when the first operation request does not include session information, a session between the client and the proxy service is established, session information is generated, and a corresponding relationship between the session representation of the session and the connection identifier of the TCP connection is established, so that the first operation request corresponding to the same session can be executed through the same TCP connection, so that the database access method provided by the embodiment of the present application can support transactional database requests. Furthermore, in an embodiment of the present application, the proxy service and the database are deployed on the same backbone network, which reduces the distance between the proxy service and the database and shortens the data transmission time between the database and the proxy service. Compared with the method of accessing the database based on TCP connection, the speed of connecting to the database is improved and the delay problem caused by introducing the middle layer is solved.

[0302] In an alternative embodiment, an electronic device is provided, such as Fig.14 As shown, Fig.14 The electronic device 4000 shown includes: a processor 4001 and a memory 4003. The processor 4001 and the memory 4003 are connected, such as through a bus 4002. Optionally, the electronic device 4000 may also include a transceiver 4004, which may be used for data interaction between the electronic device and other electronic devices, such as data transmission and / or data reception. It should be noted that in actual applications, the transceiver 4004 is not limited to one, and the structure of the electronic device 4000 does not constitute a limitation on the embodiments of the present application.

[0303] Processor 4001 may be a CPU (Central Processing Unit), a general-purpose processor, a DSP (Digital Signal Processor), an ASIC (Application Specific Integrated Circuit), an FPGA (Field Programmable Gate Array) or other programmable logic devices, transistor logic devices, hardware components or any combination thereof. It may implement or execute various exemplary logic blocks, modules and circuits described in conjunction with the disclosure of this application. Processor 4001 may also be a combination that implements computing functions, such as a combination of one or more microprocessors, a combination of a DSP and a microprocessor, etc.

[0304] The bus 4002 may include a path to transmit information between the above components. The bus 4002 may be a PCI (Peripheral Component Interconnect) bus or an EISA (Extended Industry Standard Architecture) bus. The bus 4002 may be divided into an address bus, a data bus, a control bus, etc. For ease of representation, Fig.14 Only one thick line is used in the diagram, but this does not mean that there is only one bus or only one type of bus.

[0305] The memory 4003 may be a ROM (Read Only Memory) or other types of static storage devices that can store static information and instructions, a RAM (Random Access Memory) or other types of dynamic storage devices that can store information and instructions, or an EEPROM (Electrically Erasable Programmable Read Only Memory), a CD-ROM (Compact Disc Read Only Memory) or other optical disk storage, optical disk storage (including compressed optical disk, laser disk, optical disk, digital versatile disk, Blu-ray disk, etc.), magnetic disk storage media, other magnetic storage devices, or any other medium that can be used to carry or store computer programs and can be read by a computer, without limitation herein.

[0306] The memory 4003 is used to store the computer program for executing the embodiment of the present application, and the execution is controlled by the processor 4001. The processor 4001 is used to execute the computer program stored in the memory 4003 to implement the steps shown in the above method embodiment.

[0307] Among them, electronic devices may include but are not limited to mobile terminals such as mobile phones, laptops, digital broadcast receivers, PDAs (personal digital assistants), PADs (tablet computers), PMPs (portable multimedia players), vehicle-mounted terminals (such as vehicle-mounted navigation terminals), etc., and fixed terminals such as digital TVs, desktop computers, etc. Fig.14 The electronic device shown is only an example and should not bring any limitation to the functions and scope of use of the embodiments of the present disclosure.

[0308] The embodiment of the present application provides a computer-readable storage medium, on which a computer program is stored, and when the computer program is executed by a processor, the steps and corresponding contents of the aforementioned method embodiment can be implemented. Compared with the prior art, it can be implemented as follows: after receiving a first operation request sent by a client via HTTP, according to whether the first operation request includes session information, it is determined whether the first operation request has a corresponding TCP connection, and when there is no corresponding TCP connection, a TCP connection is established, and when there is a corresponding TCP connection, the database operation statement in the first operation request is executed through the TCP connection, the execution result is obtained, and the execution result is returned to the client, thereby implementing HTTP-based access to the database, solving the problem that a TCP connection cannot be established in some scenarios and thus the database cannot be accessed. In addition, in the embodiment of the present application, when the first operation request does not include session information, a session between the client and the proxy service is established, session information is generated, and a corresponding relationship between the session representation of the session and the connection identifier of the TCP connection is established, so that the first operation request corresponding to the same session can be executed through the same TCP connection, so that the database access method provided by the embodiment of the present application can support transactional database requests. Furthermore, in an embodiment of the present application, the proxy service and the database are deployed on the same backbone network, which reduces the distance between the proxy service and the database and shortens the data transmission time between the database and the proxy service. Compared with the method of accessing the database based on TCP connection, the speed of connecting to the database is improved and the delay problem caused by introducing the middle layer is solved.

[0309] It should be noted that the computer-readable medium mentioned above in the present disclosure may be a computer-readable signal medium or a computer-readable medium or any combination of the above two. The computer-readable storage medium may be, for example, but not limited to, an electrical, magnetic, optical, electromagnetic, infrared, or semiconductor system, device or device, or any combination of the above. More specific examples of computer-readable storage media may include, but are not limited to: an electrical connection with one or more wires, a portable computer disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the above. In the present disclosure, a computer-readable storage medium may be any tangible medium containing or storing a program that can be used by or in combination with an instruction execution system, device or device. In the present disclosure, a computer-readable signal medium may include a data signal propagated in a baseband or as part of a carrier wave, which carries a computer-readable program code. This propagated data signal may take a variety of forms, including but not limited to electromagnetic signals, optical signals, or any suitable combination of the above. Computer readable signal media may also be any computer readable medium other than computer readable storage media, which may send, propagate or transmit a program for use by or in conjunction with an instruction execution system, apparatus or device. The program code contained on the computer readable medium may be transmitted using any appropriate medium, including but not limited to: wires, optical cables, RF (radio frequency), etc., or any suitable combination of the above.

[0310] The embodiment of the present application also provides a computer program product, including a computer program, which can implement the steps and corresponding contents of the aforementioned method embodiment when executed by a processor. Compared with the prior art, it can be achieved that: after receiving a first operation request sent by a client via HTTP, according to whether the first operation request includes session information, it is determined whether the first operation request has a corresponding TCP connection, and when there is no corresponding TCP connection, a TCP connection is established, and when there is a corresponding TCP connection, the database operation statement in the first operation request is executed through the TCP connection, the execution result is obtained, and the execution result is returned to the client, thereby realizing HTTP-based access to the database, solving the problem that a TCP connection cannot be established in some scenarios and thus the database cannot be accessed. In addition, in the embodiment of the present application, when the first operation request does not include session information, a session between the client and the proxy service is established, session information is generated, and a corresponding relationship between the session representation of the session and the connection identifier of the TCP connection is established, so that the first operation request corresponding to the same session can be executed through the same TCP connection, so that the database access method provided by the embodiment of the present application can support transactional database requests. Furthermore, in an embodiment of the present application, the proxy service and the database are deployed on the same backbone network, which reduces the distance between the proxy service and the database and shortens the data transmission time between the database and the proxy service. Compared with the method of accessing the database based on TCP connection, the speed of connecting to the database is improved and the delay problem caused by introducing the middle layer is solved.

[0311] The terms "first", "second", "third", "fourth", "1", "2", etc. (if any) in the specification and claims of this application and the above-mentioned drawings are used to distinguish similar objects, and are not necessarily used to describe a specific order or sequence. It should be understood that the numbers used in this way can be interchanged where appropriate, so that the embodiments of the present application described herein can be implemented in an order other than that shown or described in the drawings.

[0312] It should be understood that, although each operation step is indicated by arrows in the flowchart of the embodiment of the present application, the implementation order of these steps is not limited to the order indicated by the arrows. Unless clearly stated herein, in some implementation scenarios of the embodiment of the present application, the implementation steps in each flowchart can be performed in other orders according to demand. In addition, some or all of the steps in each flowchart may include multiple sub-steps or multiple stages based on actual implementation scenarios. Some or all of these sub-steps or stages may be executed at the same time, and each sub-step or stage in these sub-steps or stages may also be executed at different times respectively. In different scenarios of execution time, the execution order of these sub-steps or stages may be flexibly configured according to demand, and the embodiment of the present application does not limit this.

[0313] The above is only an optional implementation method for some implementation scenarios of the present application. It should be pointed out that for ordinary technicians in this technical field, without departing from the technical concept of the solution of the present application, other similar implementation methods based on the technical ideas of the present application are also within the protection scope of the embodiments of the present application.

Claims

1. A database access method, characterized in that: The method is executed by a proxy service, wherein the proxy service and the database are deployed on the same backbone network, and the method comprises: receiving a first operation request for the database sent by a client, wherein the first operation request is a request based on the Hypertext Transfer Protocol (HTTP), and the first operation request includes a database operation statement, wherein the communication connection between the client and the proxy service is an HTTP connection; In the case where the first condition is not met, a first session is created between the client and the proxy service, and a first Transmission Control Protocol TCP connection is established between the proxy service and the database, and a correspondence between a session identifier of the first session and a connection identifier of the first TCP connection is stored in a first mapping relationship; the first TCP connection is used as a target TCP connection; and first session information of the first session is sent to the client; wherein the session information of any session includes the session identifier of any session; the first mapping relationship includes a correspondence between a session identifier of at least one created session and a connection identifier of a corresponding TCP connection; the failure to meet the first condition includes that the first operation request does not include session information; If the first operation request includes session information, use the session information as second session information, determine a connection identifier corresponding to the session identifier in the second session information based on the stored first mapping relationship, and use a second TCP connection corresponding to the connection identifier as the target TCP connection; Communicate with the database through the target TCP connection, execute the database operation statement through the database, obtain the execution result, and send the execution result to the client.

2. The method according to claim 1, characterized in that The client is installed with multiple drivers, each driver corresponding to a programming language; The first operation request is generated by the client in the following manner: receiving an operation instruction for the database, the operation instruction including the database operation statement and a driver identification of a target driver corresponding to the database operation statement; Determining a target driver from the plurality of drivers according to the driver identifier; According to the database operation statement, a first operation request based on HTTP is generated through the target driver.

3. The method according to claim 1, characterized in that The session information of any session also includes the proxy service identifier; The determining, based on the stored first mapping relationship, a connection identifier corresponding to the session identifier in the second session information includes: If the proxy service identifier in the second session information is the proxy service identifier of the proxy service, determining, based on the stored first mapping relationship, a connection identifier corresponding to the second session identifier in the second session information; The method further comprises: If the proxy service identifier in the second session information is not the proxy service identifier of the proxy service, sending the first operation request to the target proxy service corresponding to the proxy service identifier in the second session information.

4. The method according to claim 3, characterized in that The first operation request includes indication information, where the indication information is used to indicate a request type corresponding to the first operation request, where the request type is a transactional request or a non-transactional request, and the method further includes: If sending the first operation request to the target proxy service fails, determining a request type corresponding to the first operation request based on the indication information; If the request type is a transactional request, returning a request failure to the client; Wherein, not satisfying the first condition includes: The request type is a non-transactional request and sending the first operation request to the target proxy service fails.

5. The method according to any one of claims 1 to 4, characterized in that: Each TCP connection has a corresponding timeliness status, and the timeliness status is used to indicate whether the corresponding TCP connection is valid; the first operation request includes indication information, and the indication information is used to indicate the request type corresponding to the first operation request, and the request type is a transactional request or a non-transactional request; Communicating with the database through the target TCP connection and executing the database operation statement through the database, the method also includes: Determine the timeliness status of the target TCP connection; If the time validity state of the target TCP connection is valid, performing a keep-alive task on the target TCP connection so that the target TCP connection is valid when executing the database operation statement; If the time validity state of the target TCP connection is invalid, determining the request type corresponding to the first operation request based on the indication information; if the first operation request is a transaction request, returning a request failure to the client; The failure to meet the first condition includes: the first operation request is a non-transactional request and the timeliness status of the target TCP connection is invalid.

6. The method according to claim 5, characterized in that Determining the timeliness status of the target TCP connection includes: Obtaining the effective duration of the target TCP connection, and comparing the effective duration of the target TCP connection with a preset effective duration; If the effective duration of the target TCP connection is less than or equal to the effective duration, the time validity state of the target TCP connection is valid; If the effective duration of the target TCP connection is greater than the effective duration, the validity status of the target TCP connection is invalid; If the target TCP connection is valid, performing a keep-alive task on the target TCP connection includes: The effective duration of the target TCP connection is updated to 0 according to a preset time interval, and the time interval is less than the effective duration.

7. The method according to claim 1, characterized in that The sending the execution result to the client comprises: Converting the execution result into a first data format supporting HTTP transmission; According to the data volume of the execution result, determine the transmission mode of sending the execution result to the client, wherein the transmission mode includes streaming transmission and batch transmission; The execution result in the first data format is compressed, and the compressed execution result is sent to the client via the transmission method, so that the client decompresses the compressed execution result and converts the data format of the decompressed execution result into a second data format corresponding to the programming language of the database operation statement.

8. A database access device, characterized in that: Applied to a proxy service, the proxy service and the database are deployed on the same backbone network, and the device comprises: a scheduling module, configured to receive a first operation request for the database sent by a client, wherein the first operation request is a request based on the Hypertext Transfer Protocol (HTTP), and the first operation request includes a database operation statement, wherein the communication connection between the client and the proxy service is an HTTP connection; A connection cache module, used for creating a first session between the client and the proxy service, and establishing a first transmission control protocol TCP connection between the proxy service and the database when the first condition is not met, storing the correspondence between the session identifier of the first session and the connection identifier of the first TCP connection in a first mapping relationship; using the first TCP connection as a target TCP connection; wherein the session information of any session includes the session identifier of any session; the first mapping relationship includes the correspondence between the session identifier of at least one created session and the connection identifier of the corresponding TCP connection; the failure to meet the first condition includes that the first operation request does not include session information; The connection cache module is further configured to, if the first operation request includes session information, use the session information as second session information, determine a connection identifier corresponding to the session identifier in the second session information based on the stored first mapping relationship, and use a second TCP connection corresponding to the connection identifier as a target TCP connection; An execution module, used for communicating with the database through the target TCP connection, and executing the database operation statement through the database; a data processing module, configured to send the first session information of the first session to the client; The data processing module is also used to obtain the execution result and send the execution result to the client.

9. An electronic device comprising a memory, a processor and a computer program stored in the memory, characterized in that: The processor executes the computer program to implement the steps of the method according to any one of claims 1 to 7.

10. A computer-readable storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, the steps of the method according to any one of claims 1 to 7 are implemented.

11. A computer program product, comprising a computer program, characterized in that When the computer program is executed by a processor, the steps of the method according to any one of claims 1 to 7 are implemented.

Citation Information

Patent Citations

  • Database access permission control method and device and electronic equipment

    CN111756752A

  • Database security control method and device, computer equipment and storage medium

    CN117278241A