Tenant data processing method and device, storage medium and electronic equipment
By loading tenant agent classes in a multi-tenant environment and using tenant plug-ins to determine the target tenant, the problem of high intrusion and time-consuming business for the determination of tenants in the existing technology is solved, and zero-invasion and efficient data source management is achieved.
Patent Information
- Application Number
- CN202510185848.4
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-02-19
- Publication Date
- 2025-06-10
AI Technical Summary
In the prior art, the method of determining the dynamic data source of tenants has too many transformations of the original business, which is highly invasive, and the transformation process takes too long.
By starting the target application and loading the tenant agent class, using the tenant agent class to call the tenant interception class to determine the pending data source, deploying the tenant plug-in and target application within the service container, using the tenant plug-in to determine the target tenant corresponding to the front-end request, and storing its identity data into the request context.
It realizes tenant data isolation and dynamic data source configuration without modifying business code, reduces the time consumption of data source configuration and switching, and improves the flexibility, security and response speed of multi-tenant applications.
Smart Images

Figure CN120122947A_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of computers, and in particular, to a method and device for processing tenant data, a storage medium, and an electronic device. Background Art
[0002] In software applications with a multi-tenant architecture, implementing dynamic data source switching to ensure data isolation and improve resource utilization is a core requirement. Existing technical solutions mainly involve modifying application code to introduce data source selection logic or relying on external components for tenant identification and data routing.
[0003] However, code modification not only increases the complexity and maintenance cost of business code but also increases the invasiveness of the application, that is, the business logic is mixed with the tenant management logic, affecting the readability and maintainability of the code. In addition, although relying on external components can reduce the workload of code modification, it may introduce additional system latency and stability risks.
[0004] Therefore, there are technical problems in the existing methods for determining dynamic data sources for tenants, such as excessive modification of the original business, large invasiveness, and overly long modification processes.
[0005] To address the above problems, no effective solutions have been proposed yet. Summary of the Invention
[0006] Embodiments of this application provide a method and device for processing tenant data, a storage medium, and an electronic device, so as to at least solve the technical problems of excessive modification of the original business, large invasiveness, and overly long modification processes in the existing methods for determining dynamic data sources for tenants.
[0007] According to one aspect of the embodiments of this application, a method for processing tenant data is provided, including: starting a target application and loading a tenant proxy class, where the tenant proxy class is used to call a tenant interceptor class during the running of the target application to determine a data source to be processed; when the target application receives a front-end request, using a tenant plugin to determine a target tenant corresponding to the front-end request and storing identity data of the target tenant in a request context, where the request context is used to identify the target tenant during the processing of the front-end request, and both the target application and the tenant plugin are deployed in a service container; when the target application needs to call a data source interface, using the tenant interceptor class to perform a read operation on the request context to determine the data source to be processed, where the data source to be processed is a data source associated with the target tenant; processing data in the data source to be processed according to the front-end request to generate a response message, where the response message is used to indicate an operation result of the target application for the front-end request.
[0008] According to another aspect of the embodiments of the present application, there is also provided a processing device for tenant data, including: a loading module, configured to start a target application and load a tenant proxy class, where the tenant proxy class is used to call a tenant interception class during the running of the target application to determine a data source to be processed; a determination module, configured to, when the target application receives a front-end request, use a tenant plug-in to determine a target tenant corresponding to the front-end request, and store identity data of the target tenant in a request context, where the request context is used to identify the target tenant during the processing of the front-end request, and both the target application and the tenant plug-in are deployed in a service container; a reading module, configured to, when the target application needs to call the data source interface, use the tenant interception class to perform a reading operation on the request context to determine the data source to be processed, where the data source to be processed is a data source associated with the target tenant; a generation module, configured to process data in the data source to be processed according to the front-end request to generate a response message, where the response message is used to indicate an operation result of the target application for the front-end request.
[0009] Optionally, the device is further configured to: before starting the target application and loading the tenant proxy class, call a target interface of the tenant proxy class to obtain data source configuration information, where the data source configuration information is used to update a data source associated with the target tenant; save the data source configuration information to a proxy data source object in the tenant interception class, where the proxy data source object is used to store data source configuration information corresponding to each tenant, and the target application provides business services for each tenant.
[0010] Optionally, the device is used to obtain data source configuration information by calling a target interface of the tenant agent class in the following manner, including at least one of the following: calling the target interface of the tenant agent class to obtain new data source configuration information, where the data source configuration information includes the new data source configuration information, and the new data source configuration information includes a database address, a database login key pair, and a tenant number of the target tenant, and the new data source configuration information is used to add a first data source associated with the target tenant; calling the target interface of the tenant agent class to obtain deleted data source configuration information, where the data source configuration information includes the deleted data source configuration information, and the deleted data source configuration information includes a database address, a database login key pair, and a tenant number of the target tenant, and the deleted data source configuration information is used to delete a second data source associated with the target tenant; calling the target interface of the tenant agent class to obtain updated data source configuration information, where the data source configuration information includes the updated data source configuration information, and the updated data source configuration information includes a database address, a database login key pair, and a tenant number of the target tenant, and the updated data source configuration information is used to update a third data source associated with the target tenant.
[0011] Optionally, the device is further used to: when the target application receives a front-end request, use a tenant plugin to determine the target tenant corresponding to the front-end request, and after storing the identity data of the target tenant in the request context, when the target application has completed a pre-service operation and needs to call the data source interface, use the tenant interceptor class to perform the read operation on the request context to determine the data source to be processed, where the pre-service operation represents a service operation that does not depend on the data source to be processed; when the data source to be processed is determined, perform a post-service operation on the data in the data source to be processed according to the front-end request to generate the response message, where the post-service operation represents a service operation that depends on the data source to be processed.
[0012] Optionally, when the target application receives a front-end request, the device is used to use a tenant plugin to determine the target tenant corresponding to the front-end request and store the identity data of the target tenant in the request context in the following manner: determine the target tenant that has a unique mapping relationship with the tenant number according to the tenant number of the target tenant; use an implementation class based on thread local variables to store the identity data to obtain the request context.
[0013] Optionally, the device is used to start the target application and load the tenant agent class in the following manner: use a bytecode manipulation library and a Java virtual machine tool interface to perform bytecode enhancement on the data source interface.
[0014] Optionally, the device is further configured to: before starting the target application and loading the tenant agent class, add configuration parameters of the tenant plug-in to a configuration file of the service container, and add configuration parameters of the tenant agent class to a startup script of the service container; and restart the service container.
[0015] According to another aspect of the embodiments of the present application, there is also provided a computer-readable storage medium storing a computer program, wherein the computer program is configured to execute the above-mentioned processing method for tenant data when running.
[0016] According to another aspect of the embodiments of the present application, there is provided a computer program product or a computer program, which includes computer instructions stored in a computer-readable storage medium. A processor of a computer device reads the computer instructions from the computer-readable storage medium, and the processor executes the computer instructions, so that the computer device executes the processing method for tenant data as described above.
[0017] According to another aspect of the embodiments of the present application, there is also provided an electronic device including a memory and a processor, wherein a computer program is stored in the memory, and the processor is configured to execute the above-mentioned processing method for tenant data through the computer program.
[0018] In the embodiments of the present application, by starting the target application and loading the tenant agent class, the mechanism of the tenant interception class is automatically triggered during the loading of the tenant agent class, and the dynamic configuration of the data source in a multi-tenant environment can be processed in a more lightweight and transparent manner. Specifically, when the target application receives a front-end request, the tenant plug-in can immediately identify the tenant to which the request belongs and store this information in the request context, marking the tenant identity of the request. Subsequently, when the application needs to access the database, the tenant interception class will read the tenant identifier in the request context, dynamically determine the data source associated with the tenant, and then perform corresponding data operations.
[0019] That is to say, by non-invasively enhancing the target application in the service container, the purpose of realizing tenant data isolation and dynamic data source configuration without modifying the business code is achieved, thereby realizing zero invasiveness and high efficiency in data source management in multi-tenant applications. Furthermore, the technical problems in the prior art that the method for determining the tenant dynamic data source has a large business invasiveness and takes too long are solved, and the flexibility, security and response speed of multi-tenant applications are improved. Especially in a high-concurrency environment, the time consumption of data source configuration and switching is reduced, and the stable operation of the application and the correct processing of tenant data are ensured. BRIEF DESCRIPTION OF THE DRAWINGS
[0020] The accompanying drawings described herein are used to provide a further understanding of the present application and form a part of the present application. The illustrative embodiments of the present application and their descriptions are used to explain the present application and do not constitute an improper limitation of the present application. In the drawings:
[0021] Figure 1 It is a schematic diagram of an application environment of an optional method for processing tenant data according to an embodiment of the present application;
[0022] Figure 2 It is a schematic flowchart of an optional method for processing tenant data according to an embodiment of the present application;
[0023] Figure 3 It is a schematic diagram of an optional method for processing tenant data according to an embodiment of the present application;
[0024] Figure 4 It is a schematic diagram of another optional method for processing tenant data according to an embodiment of the present application;
[0025] Figure 5 It is a schematic structural diagram of an optional device for processing tenant data according to an embodiment of the present application;
[0026] Figure 6 It is a schematic structural diagram of an optional product for processing tenant data according to an embodiment of the present application;
[0027] Figure 7 It is a schematic structural diagram of an optional electronic device according to an embodiment of the present application. Detailed implementation manners
[0028] In order to enable those skilled in the art to better understand the solution of the present application, the technical solutions in the embodiments of the present application will be clearly and completely described below with reference to the accompanying drawings in the embodiments of the present application. Obviously, the described embodiments are only a part of the embodiments of the present application, rather than all the embodiments. Based on the embodiments in the present application, all other embodiments obtained by those of ordinary skill in the art without creative efforts shall fall within the protection scope of the present application.
[0029] It should be noted that the terms "first", "second", etc. in the description, claims and above-mentioned drawings of this application are used to distinguish similar objects, and do not necessarily have to be used to describe a specific order or sequence. It should be understood that the data used in this way can be interchanged under appropriate circumstances, so that the embodiments of the present application described here can be implemented in an order other than those illustrated or described here. In addition, the terms "comprising" and "having" and any variations thereof are intended to cover non-exclusive inclusion. For example, a process, method, system, product or device that includes a series of steps or units does not necessarily have to be limited to those steps or units clearly listed, but may include other steps or units not clearly listed or inherent to these processes, methods, products or devices.
[0030] The present application will be described below in conjunction with embodiments:
[0031] According to one aspect of the embodiments of the present application, a method for processing tenant data is provided. Optionally, in this embodiment, the above-mentioned method for processing tenant data can be applied to a hardware environment composed of a server 101 and a terminal device 103 as shown in Figure 1 the figure. As shown in Figure 1 the figure, the server 101 is connected to the terminal device 103 through a network, and can be used to provide services for the terminal device or an application 107 installed on the terminal device. The application can be a video application, an instant messaging application, a browser application, an educational application, a game application, etc. A database 105 can be set on the server or independently of the server, and is used to provide data storage services for the server 101. For example, a game data storage server. The above-mentioned network can include, but is not limited to: a wired network, a wireless network. Among them, the wired network includes: a local area network, a metropolitan area network and a wide area network, and the wireless network includes: Bluetooth, WIFI and other networks that implement wireless communication. The terminal device 103 can be a terminal configured with an application, and can include, but is not limited to, at least one of the following: a mobile phone (such as an Android mobile phone, an iOS mobile phone, etc.), a laptop computer, a tablet computer, a handheld computer, a MID (Mobile Internet Devices, mobile Internet device), a PAD, a desktop computer, a smart TV, a smart voice interaction device, a smart home appliance, a vehicle-mounted terminal, an aircraft, a virtual reality (Virtual Reality, VR for short) terminal, an augmented reality (Augmented Reality, AR for short) terminal, a mixed reality (Mixed Reality, MR for short) terminal and other computer devices. The above-mentioned server can be a single server, or a server cluster composed of multiple servers, or a cloud server.
[0032] In combination with Figure 1As shown, the above method for processing tenant data can be executed by an electronic device, which can be a terminal device or a server. The above method for processing tenant data can be implemented separately by the terminal device or the server, or jointly implemented by the terminal device and the server.
[0033] The above is only an example, and this embodiment does not make specific limitations.
[0034] Optionally, as an alternative implementation, as Figure 2 shown, the above method for processing tenant data includes:
[0035] S202, start the target application and load the tenant proxy class, where the tenant proxy class is used to call the tenant interceptor class during the running of the target application to determine the data source to be processed;
[0036] Optionally, in the embodiments of the present application, the above target application refers to an application running on a Servlet container, including but not limited to application programs developed by popular frameworks such as Spring MVC and Struts. The above tenant proxy class refers to a Java Agent that can enhance the bytecode of the target application when the JVM (Java Virtual Machine) starts. The implementation technologies include but are not limited to bytecode operation libraries such as Byte Buddy and ASM. For example, in the embodiments of the present application, TenantAgent is used to refer to this tenant proxy class. The above tenant interceptor class refers to a component that intervenes before data access and parses tenant information from the request context. The implementation methods include but are not limited to AOP (Aspect-Oriented Programming), bytecode enhancement technology, etc. For example, DataSourceInterceptor is used to refer to this tenant interceptor class. The above data source to be processed refers to a database instance or connection pool dynamically selected according to the target tenant information stored in the request context, which can be a database on a specific database server, an instance of a cloud database service, or other forms of data storage services.
[0037] For example, the above tenant proxy class TenantAgent implements the premain method through the Java Instrumentation API and is loaded through the -javaagent parameter when the JVM (service container) starts. The premain method will be called before the main method of the target application to implement bytecode operation without modifying the application source code (that is, dynamically obtain the target data source DataSource according to the tenant ID in the request context).
[0038] It should be noted that the selection of the service container, the framework of the target application, the technology used by the tenant proxy class, and the specific implementation form of the tenant interceptor class can all be adjusted according to the differences in the actual deployment environment and system architecture. This application does not make specific limitations on this, aiming to provide a general and non-invasive multi-tenant dynamic data source configuration solution.
[0039] S204. When the target application receives a front-end request, use the tenant plugin to determine the target tenant corresponding to the front-end request, and store the identity data of the target tenant in the request context, where the request context is used to identify the target tenant during the processing of the front-end request. Both the target application and the tenant plugin are deployed in the service container.
[0040] Optionally, in the embodiments of this application, the above-mentioned target tenant refers to a specific user or organization using the system in a multi-tenant architecture, and the above-mentioned identity data refers to information that can uniquely identify the target tenant, including but not limited to tenant ID, tenant name, unique encoding of the tenant, etc.; the above-mentioned request context refers to a data structure used by the server to store and transmit data associated with the request when processing the front-end request, which can ensure that key information such as the identity data of the tenant can be accessed by each processing component throughout the entire life cycle of the request processing; the above-mentioned front-end requests include but are not limited to HTTP requests, WebSocket connection requests, etc., which are the main ways for users to interact with the system; the above-mentioned tenant plugin refers to a component that runs in the service container and is used to identify and determine the tenant to which the request belongs when the target application receives a request, and its implementation can be based on different technologies, such as the Valve of Tomcat, the Lua script processing of Nginx, etc.
[0041] For example, use DataSourceInterceptor to refer to this tenant interceptor class, implement the invoke method of the org.apache.catalina.Valve class of Apache Tomcat, work at the container level of Tomcat, and be used to intercept requests entering the container and perform specific operations when the request reaches the target application (that is: obtain the tenant identity information ID of the user and store it in the request context).
[0042] For example, the above-mentioned request context includes all data and states related to this request during the entire process from the client initiating an HTTP request to the server returning a response. It contains detailed information about the request, the processing logic of the server, the generation process of the response, etc. In this case, Java ThreadLocal is used to implement the access and storage of request context information.
[0043] Optionally, in the embodiments of the present application, the above-mentioned ThreadLocal is a mechanism in Java used to provide an independent variable copy for each thread in a multi-threaded environment, thereby avoiding data competition and sharing problems between threads. Each thread can independently operate its own variable copy without affecting the copies of other threads.
[0044] It should be noted that in the embodiments of the present application, the selection of the service container, the type of the front-end request, the identification method of the target tenant, the storage format of the identity data, and the specific implementation of the tenant plug-in can all be adjusted according to the actual deployment environment and business requirements.
[0045] For example, the service container can be Tomcat, Jetty, Undertow, etc.; the front-end request can be a RESTful API call, a SOAP service request, etc.; the identification method of the target tenant can be based on the HTTP header, request parameters, user session, etc.; the identity data can be stored in JSON format, XML format or other custom formats; the implementation of the tenant plug-in can utilize the characteristics of the service container, such as using the Lua plug-in in Nginx to process tenant information. The present application does not make any limitations in this regard.
[0046] Exemplarily, Figure 3 is a schematic diagram of an optional method for processing tenant data according to the embodiments of the present application. Taking the above-mentioned target application and tenant plug-in running in a Tomcat Servle service container as an example, its hierarchy is as Figure 3 shown.
[0047] S206, in the case where the target application needs to call the data source interface, use the tenant interceptor class to perform a read operation on the request context to determine the data source to be processed, where the data source to be processed is the data source associated with the target tenant;
[0048] Optionally, in the embodiments of the present application, the above-mentioned data source interface refers to the standard interface for the application program to interact with the database, mainly used to obtain a database connection, including but not limited to the getConnection method in javax.sql.DataSource, etc.; the data source to be processed refers to the database instance or connection pool dynamically selected according to the target tenant information stored in the request context, which can be a database on a specific database server, an instance of a cloud database service, or other forms of data storage services.
[0049] It should be noted that in the embodiments of the present application, the specific implementation of the data source interface, the type and configuration method of the data source to be processed can all be adjusted according to the database management and access technology adopted by the target application.
[0050] For example, the data source interface can be the DataSource interface of JDBC, the data source configuration identified by the @DataSource annotation in Spring Boot, or the data source access interfaces in other database frameworks such as MyBatis and Hibernate. The data source to be processed above can be a local database server, a remote database server, a cloud database service, or other database cluster resources, and its configuration information can be stored in a local file, a database table, a configuration center, or other accessible data storage for quickly obtaining and establishing a database connection when needed. This application does not make specific limitations on such details
[0051] S208. Process the data in the data source to be processed according to the front-end request, and generate a response message, where the response message is used to indicate the operation result of the target application for the front-end request
[0052] Optionally, in the embodiments of this application, the above response message refers to the feedback information returned by the target application to the requester after completing operations such as reading, writing, or other operations on the data, including but not limited to JSON responses, XML documents, status codes, error messages, etc
[0053] It should be noted that in practical applications, the format of the above response message can be customized according to API specifications or communication protocols, such as using RESTful-style HTTP responses, SOAP-based XML responses, or custom binary data transfer formats. This application does not make limitations on this, aiming to provide a unified processing flow for various possible front-end requests, data source types, and response formats, ensuring the accuracy, security, and efficiency of data operations, while maintaining the clarity of business logic and the scalability of the application
[0054] In an exemplary embodiment Figure 4 is a schematic diagram of another optional method for processing tenant data according to the embodiments of this application. The tenant request processing flow is as follows Figure 4 shown
[0055] S1. Create a TenantValve (the above tenant plugin), obtain the tenant identity from the request context, and use the implementation class based on ThreadLocal to save the tenant ID (the above identity data)
[0056] S2. Create a DataSourceInterceptor class (the above target interceptor class) to implement the data source routing logic, that is, based on the tenant ID in S1, obtain the corresponding tenant data source and return a Connention
[0057] S3. Create TenantAgent (the above tenant agent class) and enhance the javax.sql.DataSource#getConnection method (the above data source interface) in the premain manner.
[0058] S4. Configure the TenantValve and the JVM startup parameter javaagent of TomcatWebApp (the above target application), and restart the Tomcat instance.
[0059] S5. Call the HTTP API of TenanAgent, submit the data source configuration information of the specific tenant, and save it in the static variable TenantDataSourceMap in the DataSourceInterceptor class.
[0060] S6. Complete the transformation of the multi-tenant dynamic data source for this WebApp.
[0061] It should be noted that the designs of the above TenantValve (tenant plugin), TenantAgent (tenant agent class), and DataSourceInterceptor (target interceptor class) have high reusability and flexibility. They are not limited to being used in specific applications or scenarios, but can be applied across multiple projects and frameworks. Specifically:
[0062] As a tenant identity acquisition component at the request level, TenantValve (tenant plugin) can ensure the secure and accurate transmission of tenant information throughout the entire lifecycle of request processing based on its ThreadLocal implementation. This implementation is not only applicable to Servlet containers such as Tomcat, but can also be applied to other Web containers or servers, such as Jetty and Undertow, through corresponding adaptation adjustments, as well as in microservice architectures that are not Servlet containers.
[0063] TenantAgent (tenant agent class) enhances the bytecode before the application starts through the JVM Instrumentation API. This mechanism enables TenantAgent to be seamlessly integrated into any Java-based environment without modifying the application code. Additionally, by selecting different bytecode manipulation libraries, such as ASM and Byte Buddy, TenantAgent can further optimize its performance or adapt to different JVM environments.
[0064] The logic of the DataSourceInterceptor (the target interceptor class) is not limited to the getConnection method of javax.sql.DataSource. Its data source routing and selection mechanism can be extended to support other types of database access interfaces, such as data source configurations in frameworks like Spring Data JPA and MyBatis.
[0065] Through the embodiments of this application, the target application is started and the tenant proxy class is loaded. The loading of the tenant proxy class automatically triggers the mechanism of the tenant interceptor class, which can handle the dynamic configuration of data sources in a multi-tenant environment in a more lightweight and transparent manner. Specifically, when the target application receives a front-end request, the tenant plugin can immediately identify the tenant to which the request belongs and store this information in the request context, marking the tenant identity of the request. Subsequently, when the application needs to access the database, the tenant interceptor class will read the tenant identifier in the request context, dynamically determine the data source associated with the tenant, and then perform the corresponding data operations.
[0066] That is to say, by non-invasively enhancing the target application within the service container, the purpose of achieving tenant data isolation and dynamic data source configuration without modifying the business code is achieved, thus realizing zero invasiveness and high efficiency in data source management in multi-tenant applications. Furthermore, it solves the technical problems in the prior art that the method for determining dynamic data sources for tenants has a large impact on the business and takes too long, improving the flexibility, security, and response speed of multi-tenant applications. Especially in a high-concurrency environment, it reduces the time consumption of data source configuration and switching, ensuring the stable operation of the application and the correct processing of tenant data.
[0067] As an optional solution, before starting the target application and loading the tenant proxy class, the method further includes: calling the target interface of the tenant proxy class to obtain data source configuration information, where the data source configuration information is used to update the data source associated with the target tenant; saving the data source configuration information to the proxy data source object in the tenant interceptor class, where the proxy data source object is used to store the data source configuration information corresponding to each tenant, and the target application provides business services for each tenant.
[0068] Optionally, in the embodiments of the present application, the above-mentioned target interface refers to the interface provided in the tenant proxy class for receiving and processing data source configuration information, including but not limited to HTTP API, gRPC service, message queue service, etc.; the data source configuration information refers to the detailed parameters describing the data sources associated with each tenant, including but not limited to database URL, username, password, JDBC driver, etc.; the proxy data source object refers to the data structure used in the tenant interceptor class to uniformly manage the data source configuration information of multiple tenants, and can be any container supporting key-value pair storage, such as HashMap, ConcurrentHashMap, etc.
[0069] It should be noted that in the embodiments of the present application, the specific implementation of the target interface, the format of the data source configuration information, and the type of the proxy data source object can all be adjusted according to the actual deployment environment and business requirements.
[0070] For example, the target interface can be a RESTful-based HTTP API that receives data source configuration information in JSON format through a POST request; the data source configuration information can include the connection string of the database, pooling parameters, security configuration, etc.; the proxy data source object can be a thread-safe ConcurrentHashMap to ensure the accuracy and consistency of the data source configuration information in a high-concurrency scenario.
[0071] In an exemplary embodiment, the tenant proxy class receives data source configuration information from an external management system through an HTTP API interface. When a new tenant data source needs to be added or an existing data source needs to update its configuration, the external management system sends a request to this API, carrying the tenant ID and the corresponding data source configuration parameters. After the tenant proxy class processes the request, it updates the data source configuration information into the proxy data source object. After associating it with a specific tenant ID, each time the target application processes a tenant request, the tenant interceptor class dynamically obtains the data source configuration information associated with this tenant from the proxy data source object according to the tenant ID saved in the request context, thereby realizing the dynamic selection and update of the data source.
[0072] Through the embodiments of the present application, by using the target interface of the tenant proxy class and the proxy data source object in the tenant interceptor class, the technical effects of dynamic and flexible data source configuration management and multi-tenant isolation are achieved, the purpose of improving the security, isolation, and scalability of system data processing is achieved, while reducing the intrusion into the business code and accelerating the efficiency of service deployment and tenant switching.
[0073] As an alternative, the obtaining of the data source configuration information by invoking the target interface of the tenant proxy class includes at least one of the following: invoking the target interface of the tenant proxy class to obtain new data source configuration information, where the data source configuration information includes the new data source configuration information, the new data source configuration information includes the database address, the database login key pair, and the tenant number of the target tenant, and the new data source configuration information is used to add a first data source associated with the target tenant; invoking the target interface of the tenant proxy class to obtain deleted data source configuration information, where the data source configuration information includes the deleted data source configuration information, the deleted data source configuration information includes the database address, the database login key pair, and the tenant number of the target tenant, and the deleted data source configuration information is used to delete a second data source associated with the target tenant; invoking the target interface of the tenant proxy class to obtain updated data source configuration information, where the data source configuration information includes the updated data source configuration information, the updated data source configuration information includes the database address, the database login key pair, and the tenant number of the target tenant, and the updated data source configuration information is used to update a third data source associated with the target tenant.
[0074] As an alternative, the obtaining of the data source configuration information by invoking the target interface of the tenant proxy class includes at least one of the following: invoking the target interface of the tenant proxy class to obtain new data source configuration information, where the data source configuration information includes the new data source configuration information, the new data source configuration information includes the database address, the database login key pair, and the tenant number of the target tenant, and the new data source configuration information is used to add a first data source associated with the target tenant; invoking the target interface of the tenant proxy class to obtain deleted data source configuration information, where the data source configuration information includes the deleted data source configuration information, the deleted data source configuration information includes the database address, the database login key pair, and the tenant number of the target tenant, and the deleted data source configuration information is used to delete a second data source associated with the target tenant; invoking the target interface of the tenant proxy class to obtain updated data source configuration information, where the data source configuration information includes the updated data source configuration information, the updated data source configuration information includes the database address, the database login key pair, and the tenant number of the target tenant, and the updated data source configuration information is used to update a third data source associated with the target tenant.
[0075] Optionally, in the embodiments of the present application, the above-mentioned newly added data source configuration information refers to the information used to create a new data source instance, which may be the database URL, login username and password, tenant ID, etc.; the deleted data source configuration information refers to the information used to identify the data source that needs to be removed from the system, and also includes the database URL, login credentials, tenant ID, etc.; the updated data source configuration information refers to the information used to modify the configuration of the existing data source instance, and also includes the database URL, login credentials, tenant ID, etc., as well as the relevant data to be modified.
[0076] It should be noted that, in the embodiments of the present application, the data source configuration information may include, in addition to the basic database connection parameters, the database version, connection pool settings, security policies, etc.; the management of the data source can adopt a centralized or distributed configuration center, local configuration file or other customized data source management strategies to achieve dynamic adjustment and management of the data source.
[0077] In an exemplary embodiment, the external management system provides a data source configuration update instruction to the target application by calling the HTTP API interface of the tenant proxy class. When a new data source needs to be added for a certain tenant, the external management system sends a POST request to the target interface, carrying information such as the tenant ID, database address, login username and password, etc.; after receiving the request, the tenant proxy class creates a first data source using this information, associates it with the specified tenant, and stores it in the proxy data source object.
[0078] Similarly, when the second data source needs to be deleted or the third data source needs to be updated, the external management system sends DELETE or PUT requests to the target interface respectively, carrying the corresponding tenant ID and data source identification information. The tenant proxy class performs the deletion or update operation of the data source according to the request type and content to ensure the accuracy and timeliness of the data source information in the proxy data source object.
[0079] Through the embodiments of the present application, by adopting the target interface of the tenant proxy class and the dynamic management of the data source configuration information, the technical effects of flexible, efficient, and non-invasive data source configuration update and tenant isolation are achieved, the purpose of enhancing the system's data processing ability and adapting to the changes in tenant requirements is achieved, and a practical solution for the dynamic configuration and management of data sources in a multi-tenant environment is provided.
[0080] As an alternative solution, after the target application receives the front-end request, determines the target tenant corresponding to the front-end request using the tenant plugin, and stores the identity data of the target tenant in the request context, the method further includes: when the target application has completed the pre-business operation and needs to call the data source interface, performing the reading operation on the request context using the tenant interceptor class to determine the data source to be processed, where the pre-business operation refers to a business operation that does not depend on the data source to be processed; when the data source to be processed is determined, performing a post-business operation on the data in the data source to be processed according to the front-end request to generate the response message, where the post-business operation refers to a business operation that depends on the data source to be processed.
[0081] Optionally, in the embodiments of the present application, the above-mentioned pre-business operation refers to the business logic processing performed after the target application starts and before accessing the database, including but not limited to identity authentication, permission check, request parameter verification, etc.; the above-mentioned post-business operation refers to performing specific data reading and writing operations based on the determined data source, such as querying user information, updating order status, etc.; the above-mentioned reading operation refers to the tenant interceptor class reading the identity data of the target tenant from the request context stored in ThreadLocal to dynamically select the corresponding data source.
[0082] It should be noted that in the embodiments of the present application, the specific content of the pre-business operation and the post-business operation, the selection logic of the data source to be processed, and the calling method of the data source interface can all be adjusted according to the differences in the application architecture, business requirements, and database access technology.
[0083] For example, the pre-business operation can be request authentication through the API gateway or business rule check at the application layer; the post-business operation can be database operations performed through JDBC, ORM framework, or other database access APIs; the selection logic of the data source can flexibly allocate the most suitable data source instance for different tenants in combination with the tenant ID, business scenario, and load balancing strategy.
[0084] In an exemplary embodiment, the target application is a SaaS platform that provides customized services for different tenants. After receiving the front-end request, the tenant plugin parses the tenant identifier in the request and stores the tenant information in the request context of ThreadLocal. After performing pre-business operations such as user login verification and permission check, the target application reads the target tenant information stored in the request context through the tenant interceptor class and dynamically selects the corresponding data source.
[0085] For example, a front-end request may involve querying order data for a specific tenant. After authentication is completed, the tenant interceptor class reads the tenant ID in the ThreadLocal and selects the data source instance associated with the tenant from the configured multiple data sources based on this ID. Then, the target application uses the selected data source to perform subsequent business operations, such as querying order information in the database, and packages the results into a response message and returns it to the front end.
[0086] Through the embodiments of the present application, by adopting the phased processing mechanism of the tenant plugin and the tenant interceptor class, the decoupling of business operations and data source selection is achieved, ensuring the security and isolation of data access in a multi-tenant environment. At the same time, the response efficiency and resource utilization rate of the system are improved, achieving the purpose of efficient, secure, and flexible data source management and business processing.
[0087] As an alternative solution, when the target application receives a front-end request, using the tenant plugin to determine the target tenant corresponding to the front-end request and storing the identity data of the target tenant in the request context includes: determining the target tenant that has a unique mapping relationship with the tenant number according to the tenant number of the target tenant; using an implementation class based on thread-local variables to store the identity data to obtain the request context.
[0088] As an alternative solution, when the target application receives a front-end request, using the tenant plugin to determine the target tenant corresponding to the front-end request and storing the identity data of the target tenant in the request context includes: when the target application receives a front-end request, using the tenant plugin to parse the front-end request to obtain the tenant number; determining the target tenant that has a unique mapping relationship with the tenant number according to the tenant number; using an implementation class based on thread-local variables to store the identity data to obtain the request context.
[0089] Optionally, in the embodiments of the present application, the above-mentioned tenant number refers to an identifier used to uniquely identify each tenant, which can be a number, a string, a UUID, etc., and is used to locate and distinguish different tenants within the system.
[0090] It should be noted that the way the tenant plugin parses the front-end request, the specific form of the tenant number, and the implementation details of the request context can all be adjusted according to the actual application environment and business requirements. For example, the tenant plugin can parse the X-Tenant-ID in the HTTP header or the parameter tenantId in the URL; the tenant number can be an enterprise customer ID, a user group ID, or other custom identifiers; in addition to storing tenant information, the request context can also include other states or data related to request processing, such as user permissions, request sequence numbers, etc., and any thread-safe data structure can be used for the specific implementation.
[0091] In an exemplary embodiment, the target application is a multi-tenant enterprise-level service system that receives requests from the front end through HTTP interfaces. When a request with tenant information arrives, the tenant plugin TenantValve first parses the X-Tenant-ID field in the request header to obtain the tenant number. Then, by querying the internally maintained tenant mapping table, it determines the tenant information uniquely corresponding to this tenant number, and the target tenant here may be a specific company or user group. Next, TenantValve uses the implementation class TenantThreadContextHolder of ThreadLocal to store the tenant information and form a request context. Furthermore, in subsequent stages of request processing, such as the data access layer, the tenant interceptor DataSourceInterceptor can read the tenant number from ThreadLocal to determine which data source to use for operations.
[0092] Through the embodiments of this application, by adopting the mechanism of using a tenant plugin to parse front-end requests, determining the target tenant based on the tenant number, and using ThreadLocal to store identity data, the accurate parsing of multi-tenant requests and the lossless transmission of tenant information are achieved, ensuring that the tenant can be correctly identified in each request processing flow, and then dynamically selecting the associated data source, thus achieving the purpose of improving the multi-tenant support ability of the system, enhancing data security and isolation.
[0093] As an alternative solution, starting the target application and loading the tenant proxy class includes: using a bytecode manipulation library and the Java Virtual Machine Tool Interface to perform bytecode enhancement on the data source interface.
[0094] Optionally, in the embodiments of this application, the above-mentioned bytecode manipulation library refers to a software library that provides bytecode generation and modification functions, including but not limited to Byte Buddy, ASM, Javassist, etc.; the above-mentioned Java Virtual Machine Tool Interface (Java Virtual Machine Tool Interface, JVM TI) refers to a set of native interfaces provided by the Java virtual machine for monitoring and modifying the virtual machine state at runtime, including but not limited to loading a Java Agent when the JVM starts to achieve bytecode enhancement of classes.
[0095] It should be noted that in the embodiments of this application, the selection of the bytecode manipulation library, the usage method of the Java Virtual Machine Tool Interface, and the specific type of the data source interface can be adjusted according to the architecture, performance requirements, and compatibility requirements of the target application.
[0096] For example, considering that Byte Buddy has good compatibility with Spring and other modern Java frameworks, Byte Buddy can be used if the Spring framework is used in the target application; if the target application has extremely demanding performance requirements, ASM can be selected, which provides more low-level control in bytecode manipulation; the data source interface can be any interface that conforms to the JDBC specification, and the specific implementation can be selected according to the database type and connection pool management strategy.
[0097] In an exemplary embodiment, the target application is a microservice system based on Spring Boot, and the system uses HikariCP as the database connection pool. During the startup phase, by configuring the Java Agent parameters, the system loads the TenantAgent, and the TenantAgent uses the Byte Buddy library to perform bytecode enhancement on all classes that implement the javax.sql.DataSource interface. Specifically:
[0098] TenantAgent enhances the getConnection method of DataSource and weaves in the data source routing logic, which dynamically selects the correct data source according to the tenant ID carried in the request context. When the microservice system processes any front-end request, it can transparently access the database associated with the requesting tenant through the enhanced data source interface, without hard-coding the data source configuration information in the business code.
[0099] Through the embodiments of the present application, the strategy of using a bytecode manipulation library and the Java Virtual Machine Tool Interface to perform bytecode enhancement on the data source interface achieves the technical effects of dynamic data source management and multi-tenant support. This method avoids invasive modifications to the existing business code, reduces the complexity of development and deployment, and at the same time ensures the security and isolation of data access, achieving the purpose of improving the flexibility of the system and enhancing the data management ability in a multi-tenant environment.
[0100] As an alternative solution, before starting the target application and loading the tenant agent class, the method further includes: adding configuration parameters of the tenant plugin to the configuration file of the service container, and adding configuration parameters of the tenant agent class to the startup script of the service container; restarting the service container.
[0101] Optionally, in the embodiments of the present application, the above service container refers to a software environment for hosting and running applications, including but not limited to Tomcat, Jetty, WildFly, Spring Boot applications, etc.; the configuration parameters of the above tenant plugin refer to the settings added to the service container configuration file for starting and configuring the tenant plugin, including but not limited to the class name of the plugin, initialization parameters, listened URL patterns, etc.; the configuration parameters of the above tenant proxy class refer to the parameters added to the service container startup script for ensuring that the tenant proxy class is loaded by the JVM when starting, such as the -javaagent option, including but not limited to the path of the proxy class, version number, configuration file path, etc.
[0102] It should be noted that in the embodiments of the present application, the type of the service container, the format of the configuration file, and the specific implementation of the startup script can all be adjusted according to the application architecture and deployment environment. For example, the service container can be a Java-based web server such as Tomcat or Jetty, or it can be a self-contained application based on Spring Boot; the configuration file can be in formats such as XML, JSON, YAML, etc., depending on the configuration mechanism of the service container; the modification method of the startup script can be to directly modify the script file, such as catalina.sh or boot.sh, or it can be to pass parameters through environment variables, configuration files, or custom scripts.
[0103] In an exemplary embodiment, the target application is deployed on a Tomcat service container. To implement the support for multi-tenant dynamic data sources, first, the configuration parameters of the tenant plugin TenantValve are added to the Tomcat configuration file server.xml. For example, the class name and initialization parameters of TenantValve are added to <valve>Among the elements, ensure that each WebApp can identify the tenant information in the request. Next, in the Tomcat startup script catalina.sh, add the configuration of the tenant agent class TenantAgent through the -javaagent parameter, such as specifying the path of TenantAgent.jar, to ensure that the data source can be bytecode enhanced when the JVM starts. After completing the above configuration, restart the Tomcat service container to load the new configuration information. At this time, the target application already has the ability to dynamically switch data sources for tenant plugins and tenant agent classes.
[0104] More specifically, in the Tomcat catalina_base directory, for the Tomcat configuration file config / server.xml <host>Add <Valve className="com.demo.tenant.valve.TenantValve" / > inside the block to add the configuration parameters of the tenant plugin in the configuration file of the service container; under the Tomcat Catalina_base directory, add "export CATALINA_OPTS="$CATALINA_OPTS -javaagent:tenant-agent.jar"" in the Tomcat startup script bin / catalina.sh to add the configuration parameters of the tenant proxy class in the startup script of the service container. After the configuration parameters of both are modified, restart the service container.
[0105] Through the embodiments of this application, by adopting the strategy of adding the configuration parameters of the tenant plugin and the tenant proxy class in the service container and restarting the service container, non-invasive transformation of the application environment is achieved, ensuring that the application can correctly identify and process multi-tenant requests. There is no need to modify the source code or business logic of the application, reducing the complexity and risk of implementing a multi-tenant architecture, and achieving the purpose of improving the scalability of the application and adapting to a multi-tenant environment.
[0106] In another exemplary embodiment, the above method for processing tenant data can be applied to the scenario of dynamic switching of multi-tenant multi-data sources, with the characteristics of zero intrusion, zero dependence, and strong generality. There is no need to transform the original application code and deployment architecture. Dynamic switching of multi-tenant data sources is achieved through application container plugins, and only the application needs to be restarted; there is no need to introduce additional third-party components, and dynamic addition of tenant data sources can be realized, which is pluggable and easy to roll back, meeting the requirements for rapid online deployment. Specifically:
[0107] Multi-tenancy is an architectural pattern in the SaaS (Software as a Service) cloud platform. In this pattern, a single instance or application can serve multiple tenants, where "tenant" refers to different users or customer organizations on the SaaS platform. The core idea of the multi-tenant architecture lies in resource sharing and isolation. It allows different tenants to use the same set of infrastructure, platform, and application programs, while ensuring data security and privacy between tenants. Resource isolation and data routing are the keys to multi-tenant technology. The implementation methods of the multi-tenant architecture include database-level isolation, application-level isolation, physical isolation, etc. And database-level isolation is one of the most common methods, among which fully independent database isolation has great advantages in terms of security, isolation, and scalability. Especially for large enterprise customers in the B2B category, there are strong requirements in terms of data security, disaster recovery isolation, and application stability.
[0108] At present, there are three multi-tenant and multi-data source technologies in use. The first is to intercept user requests, identify tenant identities, and store them in the request context. The second is to select the independent database corresponding to the tenant through the tenant routing logic when obtaining data, and return the data of the corresponding tenant users. The third is to dynamically manage the data source to realize the activation of tenants. All of them require code transformation of existing applications and introduce third-party components. They are highly invasive to the business and cannot meet the needs of rapid business launch.
[0109] For example, Tomcat is used as the Servlet container of the target application to be transformed by the tenant. It is not limited to this type of container. The application to be transformed by the tenant is WebApp (referred to as WebApp). TenantValve is a tenant plug-in developed based on the Tomcat Valve mechanism, which is used to store the tenant identity in the user request into the request context; TenanAgent is a Java Agent, which is loaded when the JVM starts and implements the aspect logic of obtaining the data source interface (i.e. javax.sql.DataSource#getConnection). The specific implementation methods include but are not limited to:
[0110] S1, create TenantValve (the above tenant plug-in), obtain the tenant identity from the request context, and use the ThreadLocal-based implementation class to save the tenant ID (the above identity data).
[0111] S2, create the DataSourceInterceptor class (the above target interception class) to implement the data source routing logic, that is, based on the tenant ID in S1, obtain the corresponding tenant data source and return Conention.
[0112] S3, create TenantAgent (the above tenant agent class), and enhance the javax.sql.DataSource#getConnection method (the above data source interface) in premain mode.
[0113] S4, configure the TenantValve and JVM startup parameter javaagent of TomcatWebApp (the above target application), and restart the Tomcat instance.
[0114] S5, call the HTTPAPI of TenanAgent, submit the data source configuration information of the specific tenant, and save it in the static variable TenantDataSourceMap of the DataSourceInterceptor class.
[0115] S6, complete the multi-tenant dynamic data source transformation of the WebApp.
[0116] Specifically, when creating the TenantValue plugin, it can include, but is not limited to, obtaining the tenant ID in the login state token (login token) in the Cookie by logging in to the system, or pre - defining it through an independent tenant sub - domain name; creating the TenantThreadContextHolder class to store the tenant ID in the passed - in request context; creating the TenantAgent, and implementing the data source enhancement logic acquisition in the premain method. Here, the Java Agent and byte - code enhancement technology refer to the technology of expanding or modifying the program behavior by operating on or modifying the compiled Java class file (i.e., the.class file) without changing the source code. For example, it can be the Byte Buddy tool implemented based on the JVM Instrumentation API. The Byte Buddy is a modern byte - code generation library, designed with compatibility for Java 8 and later versions in mind and having good performance.
[0117] Furthermore, implement the premain method during JVM initialization. Specifically:
[0118] Implement the DataSourceInterceptor class to weave in the tenant data source routing logic, and the getTenantId method implements obtaining the tenant ID from the current request context;
[0119] Create the DataSourceRepository class to implement the default data source and dynamically add data sources, including:
[0120] Initialize the default data source and save it to the class static variable tenantDataSources, including but not limited to using the jetty server to create an http server and adding a data source addition API. Among them, MyServlet inherits HttpServlet and implements the API method for adding data sources, receives request parameters, initializes the DataSource instance, and saves it to the static variable tenantDataSources in the DataSourceRepository class;
[0121] Encapsulate the initialization of the data source and the jetty server in the initDataSource method, and place the initDataSource method at TenantAgent#premain to complete the initialization and dynamic loading capabilities of the data source;
[0122] Modify the Tomcat startup configuration: Modify the server.xml to add TenantValue, and modify the catalina.sh to add the javaagent parameter.
[0123] Through the embodiments of the present application, bytecode enhancement is adopted to weave in the routing logic for dynamically selecting a data source according to the tenant ID. The aspect extends the application. The customized Valve plugin can transmit the tenant ID from the request context to the method of obtaining the data source enhanced by the Java Agent, ensuring that the correct tenant data source is obtained during the request, without invading the application and business logic code, being completely transparent to it, and the overall implementation is very lightweight.
[0124] It can be understood that in the specific implementation manner of the present application, data related to user information, etc. is involved. When the above embodiments of the present application are applied to specific products or technologies, user permission or consent needs to be obtained, and the collection, use, and processing of relevant data need to comply with the relevant laws, regulations, and standards of relevant countries and regions.
[0125] It should be noted that for the foregoing method embodiments, for the sake of simple description, they are all expressed as a series of action combinations. However, those skilled in the art should know that the present application is not limited by the described action sequence, because according to the present application, certain steps can be performed in other sequences or simultaneously. Secondly, those skilled in the art should also know that the embodiments described in the specification are all preferred embodiments, and the actions and modules involved are not necessarily essential to the present application.
[0126] According to another aspect of the embodiments of the present application, there is also provided a processing device for tenant data for implementing the above-mentioned processing method of tenant data. As Figure 5 shown, the device includes:
[0127] A loading module 502, configured to start a target application and load a tenant proxy class, where the tenant proxy class is used to call a tenant interception class to determine a data source to be processed during the running process of the target application;
[0128] A determination module 504, configured to, when the target application receives a front-end request, use a tenant plugin to determine a target tenant corresponding to the front-end request, and store the identity data of the target tenant in the request context, where the request context is used to identify the target tenant during the processing of the front-end request, and both the target application and the tenant plugin are deployed in a service container;
[0129] A reading module 506, configured to, when the target application needs to call a data source interface, use the tenant interception class to perform a reading operation on the request context to determine a data source to be processed, where the data source to be processed is a data source associated with the target tenant;
[0130] A generation module 508, configured to process data in a data source to be processed according to a front-end request and generate a response message, where the response message is used to indicate an operation result of a target application for the front-end request.
[0131] As an optional solution, the above device is further configured to: before starting the target application and loading the tenant proxy class, call a target interface of the tenant proxy class to obtain data source configuration information, where the data source configuration information is used to update the data source associated with the target tenant; save the data source configuration information to a proxy data source object in the tenant interception class, where the proxy data source object is used to store data source configuration information corresponding to each tenant, and the target application provides business services for each tenant.
[0132] As an optional solution, the above device is configured to call a target interface of the tenant proxy class to obtain data source configuration information in the following manner, including at least one of the following: call a target interface of the tenant proxy class to obtain new data source configuration information, where the data source configuration information includes the new data source configuration information, the new data source configuration information includes a database address, a database login key pair, and a tenant number of the target tenant, and the new data source configuration information is used to add a first data source associated with the target tenant; call a target interface of the tenant proxy class to obtain deleted data source configuration information, where the data source configuration information includes the deleted data source configuration information, the deleted data source configuration information includes a database address, a database login key pair, and a tenant number of the target tenant, and the deleted data source configuration information is used to delete a second data source associated with the target tenant; call a target interface of the tenant proxy class to obtain updated data source configuration information, where the data source configuration information includes the updated data source configuration information, the updated data source configuration information includes a database address, a database login key pair, and a tenant number of the target tenant, and the updated data source configuration information is used to update a third data source associated with the target tenant.
[0133] As an optional solution, the above device is further configured to: when the target application receives a front-end request, use a tenant plugin to determine the target tenant corresponding to the front-end request, and after storing the identity data of the target tenant in the request context, when the target application has completed a pre-service operation and needs to call a data source interface, use a tenant interception class to perform a read operation on the request context to determine the data source to be processed, where the pre-service operation represents a business operation that does not depend on the data source to be processed; when the data source to be processed is determined, perform a post-service operation on the data in the data source to be processed according to the front-end request to generate a response message, where the post-service operation represents a business operation that depends on the data source to be processed.
[0134] As an alternative solution, the above device is used to determine the target tenant corresponding to the front-end request using the tenant plug-in and store the identity data of the target tenant in the request context when the target application receives the front-end request in the following manner: determine the target tenant that has a unique mapping relationship with the tenant number according to the tenant number of the target tenant; use an implementation class based on thread-local variables to store the identity data to obtain the request context.
[0135] As an alternative solution, the above device is used to start the target application and load the tenant proxy class in the following manner: perform bytecode enhancement on the data source interface using a bytecode manipulation library and the Java Virtual Machine Tool Interface.
[0136] As an alternative solution, the above device is further used to: before starting the target application and loading the tenant proxy class, add configuration parameters of the tenant plug-in to the configuration file of the service container, and add configuration parameters of the tenant proxy class to the startup script of the service container; restart the service container.
[0137] In the embodiments of the present application, the term "module" or "unit" refers to a computer program or a part of a computer program with a predetermined function, which works together with other related parts to achieve a predetermined goal, and can be fully or partially implemented by using software, hardware (such as a processing circuit or a memory), or a combination thereof. Similarly, a processor (or multiple processors or memories) can be used to implement one or more modules or units. In addition, each module or unit can be a part of the overall module or unit that includes the function of the module or unit.
[0138] Regarding the device in the above embodiments, the specific manner in which each module performs operations has been described in detail in the embodiments related to the method, and will not be elaborated here.
[0139] According to one aspect of the present application, there is provided a computer program product, which includes a computer program.
[0140] The serial numbers of the embodiments of the present application above are only for description and do not represent the advantages or disadvantages of the embodiments.
[0141] Figure 6 Schematically shown is a block diagram of a computer system of an electronic device for implementing the embodiments of the present application.
[0142] It should be noted that Figure 6 The computer system 600 of the electronic device shown is only an example and should not impose any limitation on the functions and usage scope of the embodiments of the present application.
[0143] Such as Figure 6 As shown, the computer system 600 includes a central processing unit 601 (CPU), which can perform various appropriate actions and processes according to a program stored in a read-only memory 602 (ROM) or a program loaded from a storage section 608 into a random access memory 603 (RAM). In the random access memory 603, various programs and data required for system operations are also stored. The central processing unit 601, the read-only memory 602, and the random access memory 603 are connected to each other via a bus 604. An input / output interface 605 (Input / Output interface, i.e., I / O interface) is also connected to the bus 604.
[0144] The following components are connected to the input / output interface 605: an input section 606 including a keyboard, a mouse, etc.; an output section 607 including, for example, a cathode ray tube (CRT), a liquid crystal display (LCD), etc., and a speaker, etc.; a storage section 608 including a hard disk, etc.; and a communication section 609 including a network interface card such as a local area network card, a modem, etc. The communication section 609 performs communication processing via a network such as the Internet. A drive 610 is also connected to the input / output interface 605 as needed. A removable medium 611, such as a magnetic disk, an optical disk, a magneto-optical disk, a semiconductor memory, etc., is installed on the drive 610 as needed so that a computer program read from it can be installed into the storage section 608 as needed.
[0145] In particular, according to an embodiment of the present application, the processes described in each method flowchart can be implemented as computer software programs. For example, an embodiment of the present application includes a computer program product, which includes a computer program carried on a computer-readable medium, and the computer program contains program codes for performing the methods shown in the flowcharts. In such an embodiment, the computer program can be downloaded and installed from a network via the communication section 609, and / or installed from the removable medium 611. When the computer program is executed by the central processing unit 601, various functions defined in the system of the present application are executed.
[0146] In such an embodiment, the computer program can be downloaded and installed from a network via the communication section 609, and / or installed from the removable medium 611. When the computer program is executed by the central processing unit 601, various functions provided by the embodiments of the present application are executed.
[0147] According to another aspect of the embodiments of the present application, an electronic device for implementing the above-mentioned processing method of tenant data is further provided. The electronic device can be Figure 1 The terminal device or server shown. In this embodiment, the electronic device is taken as an example of the terminal device for illustration. As Figure 7 shown, the electronic device includes a memory 702 and a processor 704. A computer program is stored in the memory 702, and the processor 704 is configured to execute the steps in any of the above method embodiments through the computer program.
[0148] Optionally, in this embodiment, the above electronic device may be at least one network device among multiple network devices of a computer network.
[0149] Optionally, in this embodiment, the above processor may be configured to execute the methods in the embodiments of the present application through a computer program.
[0150] Optionally, those of ordinary skill in the art can understand that Figure 7 the structure shown is only schematic, Figure 7 and it does not limit the structure of the above electronic device. For example, the electronic device may further include more or fewer components (such as a network interface, etc.) than those shown in Figure 7 , or have a different configuration from that shown in Figure 7 .
[0151] Among them, the memory 702 can be used to store software programs and modules, such as the program instructions / modules corresponding to the processing method and device of tenant data in the embodiments of the present application. The processor 704 executes various functional applications and data processing by running the software programs and modules stored in the memory 702, that is, to implement the above-mentioned processing method of tenant data. The memory 702 may include a high-speed random access memory, and may also include a non-volatile memory, such as one or more magnetic storage devices, flash memories, or other non-volatile solid-state memories. In some instances, the memory 702 may further include a memory remotely provided with respect to the processor 704, and these remote memories can be connected to the terminal through a network. Examples of the above network include but are not limited to the Internet, an enterprise intranet, a local area network, a mobile communication network, and combinations thereof. Among them, the memory 702 can specifically but not limitedly be used to store information related to the data source to be processed. As an example, as Figure 7 shown, the above memory 702 may but not limitedly include a loading module 502, a determination module 504, a reading module 506, and a generation module 508 in the above processing device of tenant data. In addition, it may also include but not limited to other module units in the above processing device of tenant data, which are not described in detail in this example.
[0152] Optionally, the above-mentioned transmission device 706 is used to receive or send data via a network. Specific examples of the above-mentioned network may include a wired network and a wireless network. In one example, the transmission device 706 includes a network adapter (Network Interface Controller, NIC), which can be connected to other network devices and routers through a network cable, so as to communicate with the Internet or a local area network. In one example, the transmission device 706 is a radio frequency (RF) module, which is used to communicate with the Internet wirelessly.
[0153] In addition, the above-mentioned electronic device further includes: a display 708, which is used to display the above-mentioned response message; and a connection bus 710, which is used to connect each module component in the above-mentioned electronic device.
[0154] In other embodiments, the above-mentioned terminal device or server can be a node in a distributed system. Among them, the distributed system can be a blockchain system, and the blockchain system can be a distributed system formed by connecting the multiple nodes through network communication. Among them, the nodes can form a peer-to-peer network, and any form of computing device, such as electronic devices like servers and terminals, can become a node in the blockchain system by joining the peer-to-peer network.
[0155] According to one aspect of the present application, there is provided a computer-readable storage medium. The processor of the electronic device reads the computer instructions from the computer-readable storage medium, and the processor executes the computer instructions, so that the electronic device executes the tenant data processing method provided in various optional implementation manners of the above-mentioned tenant data processing.
[0156] Optionally, in this embodiment, the above-mentioned computer-readable storage medium can be set to store the methods for executing the embodiments of the present application.
[0157] Optionally, in this embodiment, those of ordinary skill in the art can understand that all or part of the steps in the above-mentioned various methods can be completed by instructing the relevant hardware of the terminal device through a program, and the program can be stored in a computer-readable storage medium. The storage medium may include: a flash drive, a read-only memory (ROM), a random access memory (RAM), a magnetic disk or an optical disc, etc.
[0158] The serial numbers of the above-mentioned embodiments of the present application are only for description and do not represent the advantages or disadvantages of the embodiments.
[0159] If the integrated units in the above embodiments are implemented in the form of software functional units and sold or used as independent products, they can be stored in the above computer-readable storage media. Based on such an understanding, the technical solution of this application, in essence, or the part that contributes to the prior art, or all or part of this technical solution, can be embodied in the form of a software product. This computer software product is stored in a storage medium and includes several instructions for causing one or more electronic devices to execute all or part of the steps of the methods described in the various embodiments of this application.
[0160] In the above embodiments of this application, the descriptions of the various embodiments have their own emphases. For the parts not detailed in a certain embodiment, reference can be made to the relevant descriptions of other embodiments.
[0161] In the several embodiments provided by this application, it should be understood that the disclosed application program can be implemented in other ways. Among them, the device embodiments described above are only illustrative. For example, the division of the units is only a logical function division. In actual implementation, there may be other division methods. For example, multiple units or components can be combined or integrated into another system, or some features can be ignored or not executed. Another point is that the displayed or discussed coupling or direct coupling or communication connection between each other can be through some interfaces. The indirect coupling or communication connection of units or modules can be in an electrical or other form.
[0162] The units described as separate components may or may not be physically separated. The components displayed as units may or may not be physical units, that is, they can be located in one place, or they can be distributed to multiple network units. Some or all of the units can be selected according to actual needs to achieve the purpose of the solution of this embodiment.
[0163] In addition, the functional units in the various embodiments of this application can be integrated in a processing unit, or each unit can exist physically alone, or two or more units can be integrated in one unit. The above integrated units can be implemented in the form of hardware or in the form of software functional units.
[0164] The above are only the preferred embodiments of this application. It should be noted that for those of ordinary skill in the art, without departing from the principle of this application, several improvements and refinements can still be made, and these improvements and refinements should also be regarded as the protection scope of this application.< / host> < / valve>
Claims
1. A method for processing tenant data, characterized in that: include: Starting the target application and loading the tenant proxy class, wherein the tenant proxy class is used to call the tenant interception class to determine the data source to be processed during the operation of the target application; When the target application receives a front-end request, the target tenant corresponding to the front-end request is determined using the tenant plug-in, and the identity data of the target tenant is stored in the request context, wherein the request context is used to identify the target tenant during the processing of the front-end request, and the target application and the tenant plug-in are both deployed in a service container; In the case where the target application needs to call a data source interface, use the tenant interception class to perform a read operation on the request context to determine the data source to be processed, wherein the data source to be processed is a data source associated with the target tenant; The data in the to-be-processed data source is processed according to the front-end request to generate a response message, wherein the response message is used to indicate the operation result of the target application with respect to the front-end request.
2. The method according to claim 1, characterized in that Before starting the target application and loading the tenant proxy class, the method further includes: Calling the target interface of the tenant proxy class to obtain data source configuration information, wherein the data source configuration information is used to update the data source associated with the target tenant; The data source configuration information is saved in the proxy data source object in the tenant interception class, wherein the proxy data source object is used to store the data source configuration information corresponding to each tenant, and the target application provides business services for each tenant.
3. The method according to claim 2, characterized in that The calling of the target interface of the tenant proxy class to obtain the data source configuration information includes at least one of the following: Calling the target interface of the tenant proxy class to obtain the newly added data source configuration information, wherein the data source configuration information includes the newly added data source configuration information, the newly added data source configuration information includes a database address, a database login key pair, and a tenant number of the target tenant, and the newly added data source configuration information is used to add a first data source associated with the target tenant; Calling the target interface of the tenant proxy class to obtain the data source deletion configuration information, wherein the data source configuration information includes the data source deletion configuration information, the data source deletion configuration information includes a database address, a database login key pair, and a tenant number of the target tenant, and the data source deletion configuration information is used to delete a second data source associated with the target tenant; The target interface of the tenant proxy class is called to obtain updated data source configuration information, wherein the data source configuration information includes the updated data source configuration information, the updated data source configuration information includes a database address, a database login key pair, and a tenant number of the target tenant, and the updated data source configuration information is used to update a third data source associated with the target tenant.
4. The method according to claim 1, characterized in that: When the target application receives the front-end request, after using the tenant plug-in to determine the target tenant corresponding to the front-end request and storing the identity data of the target tenant in the request context, the method further includes: When the target application has completed the pre-service operation and needs to call the data source interface, the tenant interception class is used to perform the read operation on the request context to determine the data source to be processed, wherein the pre-service operation represents a business operation that does not depend on the data source to be processed; When the data source to be processed is determined, a post-business operation is performed on the data in the data source to be processed according to the front-end request to generate the response message, wherein the post-business operation represents a business operation that needs to be performed depending on the data source to be processed.
5. The method according to claim 1, characterized in that When the target application receives the front-end request, using the tenant plug-in to determine the target tenant corresponding to the front-end request, and storing the identity data of the target tenant in the request context, includes: Determine, according to the tenant number of the target tenant, the target tenant having a unique mapping relationship with the tenant number; The identity data is stored using an implementation class based on thread local variables to obtain the request context.
6. The method according to claim 1, characterized in that The starting of the target application and loading of the tenant proxy class includes: The bytecode of the data source interface is enhanced using a bytecode operation library and a Java virtual machine tool interface.
7. The method according to claim 1, characterized in that Before starting the target application and loading the tenant proxy class, the method further includes: Add the configuration parameters of the tenant plug-in to the configuration file of the service container, and add the configuration parameters of the tenant proxy class to the startup script of the service container; Restart the service container.
8. A tenant data processing device, characterized in that: include: A loading module, used to start the target application and load the tenant proxy class, wherein the tenant proxy class is used to call the tenant interception class to determine the data source to be processed during the operation of the target application; a determination module, configured to determine, when the target application receives a front-end request, a target tenant corresponding to the front-end request using a tenant plug-in, and store the identity data of the target tenant in a request context, wherein the request context is used to identify the target tenant during the processing of the front-end request, and the target application and the tenant plug-in are both deployed in a service container; A reading module, configured to use the tenant interception class to perform a read operation on the request context and determine the data source to be processed when the target application needs to call a data source interface, wherein the data source to be processed is a data source associated with the target tenant; A generation module is used to process the data in the to-be-processed data source according to the front-end request and generate a response message, wherein the response message is used to indicate the operation result of the target application for the front-end request.
9. A computer-readable storage medium, characterized in that: The computer-readable storage medium includes a stored computer program, wherein the computer program can be executed by an electronic device to perform the method described in any one of claims 1 to 7.
10. 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 described in any one of claims 1 to 7 are implemented.
11. An electronic device comprising a memory and a processor, characterized in that: A computer program is stored in the memory, and the processor is configured to execute the method according to any one of claims 1 to 7 through the computer program.