Database proxy method based on plug-in

By using WebAssembly technology to implement the plug-in system in the database proxy, the problem that existing database proxy is difficult to meet the diverse needs of applications is solved, and the flexible expansion and high security of the database proxy are achieved.

CN119513175APending Publication Date: 2025-02-25HANGZHOU YUNYUANSHENG DATA CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202411582524.6
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-11-07
Publication Date
2025-02-25

AI Technical Summary

Technical Problem

Existing database agents are difficult to meet the diverse needs of applications, and lack standardized implementation methods, so they cannot effectively handle the general needs of applications.

Method used

The WebAssembly-based plug-in system allows users to write plug-ins in multiple programming languages, compile them into Wasm programs, install them in the database proxy, and pattern matching through pre-configured Filters, modify SQL requests and return results.

Benefits of technology

It realizes the flexible expansion capabilities of database agents, can dynamically load and run plug-ins without restarting database agents, improves the security of the system and cross-platform capabilities, and meets the diverse needs of applications.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119513175A_ABST
    Figure CN119513175A_ABST
Patent Text Reader

Abstract

The invention discloses a plug-in-based database proxy method, which comprises the following steps that: a database proxy receives SQL (Structured Query Language) request information, and performs pattern matching on the SQL request information and a pre-configured Filter to obtain a plurality of plug-ins through matching; modifying the SQL request information through a plurality of matched plug-ins and then sending the SQL request information to a database; receiving an SQL return result executed by the database; and modifying an SQL return result through the plurality of matched plug-ins. According to the database agent method based on the plug-in, a user is allowed to use various programming languages to write the plug-in, compile the plug-in into a Wasm program and load and run the Wasm program in a database agent layer.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention specifically relates to a database proxy method based on plug-in. Background Art

[0002] The job of the database proxy is to receive the SQL request of the application and forward it to the database. In this process, some common requirements for the application will be implemented in the database proxy layer, such as audit logs, authentication, permission verification, current limiting, etc. However, since the above requirements are generally functions required by the application side, there is a lack of standards, and the implementation of these functions by the database proxy layer may be difficult to meet the requirements. In addition, the requirements of the application cannot be predicted and enumerated. Summary of the invention

[0003] The present invention provides a plug-in-based database proxy method to solve the above-mentioned technical problems, and specifically adopts the following technical solutions:

[0004] A plug-in-based database proxy method, comprising:

[0005] The database proxy receives SQL request information, matches the SQL request information with the pre-configured Filter pattern, and matches it to several plug-ins;

[0006] Modify the SQL request information through several matched plug-ins and send it to the database;

[0007] Receive the SQL return result after the database is executed;

[0008] Modify the SQL return results through several matched plug-ins.

[0009] Furthermore, the database proxy implements a plug-in system based on WebAssembly technology.

[0010] Furthermore, before the database proxy receives the SQL request information, the plug-in-based database proxy method further comprises:

[0011] Write the code for several plug-ins and compile the code of each plug-in into a corresponding Wasm plug-in program that can run on the database proxy;

[0012] Install several Wasm plug-ins on the database agent;

[0013] Set the effective scope of each plug-in in the database proxy to form several filters.

[0014] Furthermore, the plug-in-based database proxy method further comprises:

[0015] Defines a set of ABI interfaces for database agents and Wasm plugins.

[0016] Furthermore, the Wasm plug-in program written by the user runs in the sandbox environment provided by the database agent.

[0017] Furthermore, each Wasm plug-in has independent linear memory, and Wasm plug-ins cannot access the memory of other Wasm plug-ins or database agents.

[0018] Furthermore, Wasm plugins cannot directly access the database proxy's file system.

[0019] Furthermore, the database agent allows the Wasm plug-in to access the set file path by mounting.

[0020] Furthermore, Wasm plugins cannot directly access the network.

[0021] The benefit of the present invention lies in that the provided plug-in-based database proxy method implements a plug-in system based on WebAssembly technology, allowing users to write plug-ins in multiple programming languages, compile them into wasm programs, and load and run them in the database proxy layer. At the same time, the database proxy layer also uses the sandbox capability provided by WebAssembly to provide isolation capabilities for plug-ins to improve the security of the system. Due to the cross-platform nature of WebAssembly, plug-ins written by users can be compiled once and run across platforms. BRIEF DESCRIPTION OF THE DRAWINGS

[0022] In order to more clearly illustrate the embodiments of the present application or the technical solutions in the prior art, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present application. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative labor.

[0023] Figure 1 It is a schematic diagram of a plug-in-based database proxy method of the present invention. DETAILED DESCRIPTION

[0024] The embodiments of the present application are described in detail below, and examples of the embodiments are shown in the accompanying drawings, wherein the same or similar reference numerals throughout represent the same or similar elements or elements having the same or similar functions. The embodiments described below with reference to the accompanying drawings are exemplary and are intended to be used to explain the present application, and should not be construed as limiting the present application.

[0025] like Figure 1A plug-in-based database proxy method of the present application is shown, comprising:

[0026] S1: The database proxy receives SQL request information, performs pattern matching on the SQL request information and the pre-configured Filter, and matches it to several plug-ins.

[0027] The aforementioned filters are all configured in advance. Specifically, before the database proxy receives SQL request information, the plug-in-based database proxy method also includes:

[0028] The user writes the code of several plug-ins, compiles the code of each plug-in into a corresponding Wasm plug-in program that can be run on the database proxy. Install several Wasm plug-in programs on the database proxy. Set the effective scope of each plug-in in the database proxy to form several filters.

[0029] Specifically, when the database agent receives a SQL request, it does several things:

[0030] 1. Parse the MySQL protocol, from which you can obtain some information, such as the client Host, IP, SQL request type, SQL statement, User currently executing SQL, comments, etc.

[0031] 2. Use SQL Parser to parse SQL statements so that you can know which databases and tables this SQL will operate on.

[0032] 3.Then the database agent can start pattern matching. If the above information matches the "dimension defined by the filter", it means that this SQL hits this filter. Before / after the SQL is executed, it will be intercepted by the filter and the filter-related code will be executed.

[0033] The above steps are to create a Filter. A Filter is equivalent to a plug-in and its effective scope.

[0034] In the implementation of the present application, the database proxy implements the plug-in system based on WebAssembly technology. WebAssembly can provide relatively good dynamic loading and running capabilities, cross-platform capabilities, and security sandbox capabilities.

[0035] Users can extend the capabilities of the database proxy by writing Wasm plug-ins. The database proxy can load and run plug-ins without recompiling or restarting. This means that the user's business application will not be interrupted because the database proxy needs to be restarted. This greatly enhances the dynamic loading and running capabilities.

[0036] In the implementation of the present application, the plug-in-based database proxy method further includes: defining a set of ABI interfaces for the database proxy and the Wasm plug-in program. Our main program (that is, the database proxy) and the wasm plug-in program define a set of ABI interfaces respectively. As long as any program that implements this set of ABI interfaces can call each other, it improves the cross-platform capability.

[0037] The security sandbox capability is reflected in the following aspects: we can configure the resources that each wasm plug-in can access, such as limiting the directories and files it can access, and the memory between it and the "database proxy" is isolated from each other.

[0038] In the implementation mode of the present application, the Wasm plug-in program written by the user runs in the sandbox environment provided by the database proxy. In this way, the memory between each Wasm plug-in program and the memory between the database proxy are isolated from each other.

[0039] In the implementation of the present application, each Wasm plug-in has independent linear memory, and the Wasm plug-in cannot access the memory of other Wasm plug-ins or database agents. This prevents buffer overflows and other memory security vulnerabilities through boundary checking and memory segmentation.

[0040] In the implementation of the present application, the Wasm plug-in cannot directly access the file system of the database proxy. The database proxy allows the Wasm plug-in to access the set file path by mounting.

[0041] In the implementation of the present application, the Wasm plug-in cannot directly access the network. The database agent is required to provide a dedicated function so that Wasm can access the network through the dedicated function.

[0042] The following is a complete wasm plugin example. The user wrote a plugin in Go programming language. Its function is to check all Delete and Update statements. If there is no where condition in the SQL, the SQL execution is directly rejected to avoid misoperation that causes all data in the database to be modified by one SQL.

[0043] SQL

[0044] package main

[0045] import(

[0046]

[0047] if stmt.Where == nil{

[0048] return fmt.Errorf("no where clause")

[0049] }

[0050] default:

[0051] }

[0052] return nil

[0053] }

[0054] / / The ABI interface that the wasm program needs to implement is used to modify the SQL result after SQL is executed

[0055] func(a*ParserWasmPlugin)RunAfterExecution(queryResult*query.QueryResult,errBefore error)(*query.QueryResult,error){

[0056] return queryResult,errBefore

[0057] }

[0058] The following are examples of functions that the host environment needs to define, implement, and export to the Wasm plugin:

[0059] Go

[0060] / / The ABI interface that the host environment needs to implement is to allow the wasm program to obtain the value according to the key in the host environment func getValueByKeyOnHost(scope uint32,hostModulePtr uint64,keyPtr,keySize uint32,returnValuePtr,returnValueSize*uint32)Status

[0061] / / The ABI interface that the host environment needs to implement is to allow the wasm program to set a key-value in the host environment func setValueByKeyOnHost(scope uint32, hostModulePtr uint64, keyPtr, keySize, valuePtr, valueSize uint32) Status

[0062] / / The ABI interface that the host environment needs to implement is to allow the wasm program to acquire the lock in the host environment

[0063] / / The ABI interface that the host environment needs to implement is to allow the wasm program to release the lock in the host environment

[0064] func unlockOnHost(scope uint32,hostModulePtr uint64)

[0065] / / The ABI interface that the host environment needs to implement is to allow the wasm program to obtain SQL requests in the host environment func getQueryOnHost(hostInstancePtr uint64,returnValueData*uint32,returnValueSize

[0066] *uint32)Status

[0067] / / The ABI interface that the host environment needs to implement is to allow the wasm program to modify the SQL request in the host environment func setQueryOnHost(hostInstancePtr uint64, queryValuePtr uint32, queryValueSize uint32)

[0068] Status

[0069] / / The ABI interface that the host environment needs to implement is used to allow the wasm program to obtain the current ABI version in the host environment

[0070] func getAbiVersionOnHost(returnValuePtr*uint32,returnValueSize*uint32)Status

[0071] / / The ABI interface that the host environment needs to implement is to allow the wasm program to obtain the type of the current wasmruntime in the host environment

[0072] func getRuntimeTypeOnHost(returnValuePtr*uint32,returnValueSize*uint32)Status

[0073] / / The ABI interface that the host environment needs to implement is to allow the wasm program to print the INFO log in the host environment func infoLogOnHost(ptr uint32,size uint32)Status

[0074] / / The ABI interface that the host environment needs to implement is to allow the wasm program to print the ERROR log in the host environment

[0075] func errorLogOnHost(ptr uint32,size uint32)Status

[0076] / / The ABI interface that the host environment needs to implement is used to allow the wasm program to set SQL execution error information in the host environment

[0077] func setErrorMessageOnHost(hostInstancePtr uint64,errMessagePtruint32,errMessageSize uint32)Status

[0078] / / The ABI interface that the host environment needs to implement is used to allow the wasm program to obtain SQL execution error information in the host environment

[0079] func getErrorMessageOnHost(hostInstancePtr uint64,returnErrMessagePtr*uint32,returnErrMessageSize*uint32)Status

[0080] / / The ABI interface that the host environment needs to implement is used to allow the wasm program to obtain the results of SQL execution in the host environment

[0081] func getQueryResultOnHost(hostInstancePtr uint64,returnQueryRstBytesPtr*uint32,returnQueryRstBytesSize*uint32)Status

[0082] / / The ABI interface that the host environment needs to implement is used to allow the wasm program to modify the results of SQL execution in the host environment

[0083] func setQueryResultOnHost(hostInstancePtr uint64,returnQueryRstBytesPtr uint32,returnQueryRstBytesSize uint32)Status

[0084] The following are examples of functions that a Wasm plugin needs to define, implement, and export to the host environment:

[0085] Go

[0086] / / The ABI interface that the wasm program needs to implement is used to modify the SQL request before SQL execution

[0087] func RunBeforeExecutionOnGuest(hostInstancePtr,hostModulePtr uint64)

[0088] / / The ABI interface that the wasm program needs to implement is used to modify the SQL result after SQL is executed

[0089] func RunAfterExecutionOnGuest()

[0090] S2: Modify the SQL request information through several matched plug-ins and send it to the database.

[0091] Before the SQL request information is executed, the SQL request information is first processed by several matched plug-ins.

[0092] S3: Receive the SQL result returned by the database after execution.

[0093] After the modified SQL request information is sent to the database, the database executes the SQL and returns the SQL return result to the database agent.

[0094] S4: Modify the SQL return results through several matched plug-ins.

[0095] The database proxy then modifies the SQL return result through the previously matched Wasm plug-in program, and finally returns it to the application.

[0096] The above shows and describes the basic principles, main features and advantages of the present invention. Those skilled in the art should understand that the above embodiments do not limit the present invention in any form, and any technical solution obtained by equivalent replacement or equivalent transformation falls within the protection scope of the present invention.

Claims

1. A plug-in-based database proxy method, characterized in that: Include: The database proxy receives SQL request information, matches the SQL request information with the pre-configured Filter pattern, and matches it to several plug-ins; Modify the SQL request information through several matched plug-ins and send it to the database; Receive the SQL return result after the database is executed; Modify the SQL return results through several matched plug-ins.

2. The plug-in-based database proxy method according to claim 1, characterized in that: The database proxy implements a plug-in system based on WebAssembly technology.

3. The plug-in-based database proxy method according to claim 2, characterized in that: Before the database proxy receives the SQL request information, the plug-in-based database proxy method further includes: Write the code for several plug-ins and compile the code of each plug-in into a corresponding Wasm plug-in program that can run on the database proxy; Install several Wasm plug-ins on the database agent; Set the effective scope of each plug-in in the database proxy to form several filters.

4. The plug-in-based database proxy method according to claim 3, characterized in that: The plug-in-based database proxy method further comprises: Defines a set of ABI interfaces for database agents and Wasm plugins.

5. The plug-in-based database proxy method according to claim 3, characterized in that: User-written Wasm plug-in programs run in the sandbox environment provided by the database agent.

6. The plug-in-based database proxy method according to claim 5, characterized in that: Each Wasm plug-in has independent linear memory, and Wasm plug-ins cannot access the memory of other Wasm plug-ins or database agents.

7. The plug-in-based database proxy method according to claim 5, characterized in that: The Wasm plugin cannot directly access the database agent's file system.

8. The plug-in-based database proxy method according to claim 7, characterized in that: The database proxy allows the Wasm plug-in to access the set file path by mounting.

9. The plug-in-based database proxy method according to claim 5, characterized in that: Wasm plugins do not have direct access to the network.