Multi-data source switching method and related equipment based on TDSQL database
By intercepting requests in the AOP section and using pre-configured files to match the TDSQL database data source connection information, and cached institutional encoding, the problem of carrying institutional encoding in the existing technology is solved, and data source switching without carrying institutional encoding is achieved, improving user experience.
Patent Information
- Application Number
- CN202211332659.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-10-28
- Publication Date
- 2025-08-26
- Estimated Expiration
- 2042-10-28
AI Technical Summary
The data source access scheme based on Spring Boot in the prior art requires carrying institutional code in each service request, resulting in the inability to find the corresponding TDSQL database without carrying institutional code, affecting user usage.
By intercepting user requests in the AOP section, using pre-configured files to match the user information, a mapping relationship is established when the user logs in, and the institution code is cached to the browser, and the institution code is directly obtained from the browser for data source switching during business requests.
This enables users to not have to carry institutional codes at each request, simplifying user operations and improving system availability and user experience.
Smart Images

Figure CN115599864B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of financial management technology, and in particular to a multi-data source switching method based on a TDSQL database and related equipment. Background Art
[0002] The TDSQL database is a distributed database compatible with the MySQL protocol. Business systems using the TDSQL database can store huge amounts of business data.
[0003] A certain business system adopts the B / S model and is provided to different institutions. When users from different institutions use this business system, the business data of different institutions need to be stored in different TDSQL databases, while not affecting the users' normal use of the business system.
[0004] The prior art provides a data source access solution based on Spring Boot in different environments. This solution loads and starts the corresponding data access object configuration component according to the type of configuration file and environment variables, and then uses the base class and implementation class of the service layer to obtain the required data source, and then access the database connected to the data source.
[0005] After research, the applicant found that the data source access solution based on Spring Boot in different environments needs to carry the organization code of the user's organization in each business request except the login request. When the organization code is not carried in the business request, the corresponding TDSQL database cannot be found, and the data source cannot be switched, which affects user use. Summary of the Invention
[0006] In view of this, an embodiment of the present invention provides a multi-data source switching method and related equipment based on the TDSQL database, so that users do not need to carry the organization code every time they send a request, which is convenient for users to use.
[0007] To achieve the above objectives, the embodiments of the present invention provide the following technical solutions:
[0008] A multi-data source switching method based on a TDSQL database, comprising:
[0009] Intercept user requests in AOP aspects;
[0010] When the user request is a login request, directly matching and extracting the TDSQL database data source connection information specifically storing user information in the pre-configuration file from the login request;
[0011] Writing the TDSQL database data source connection information into the request thread of the user login request and releasing the user request;
[0012] Initiate a database request based on the TDSQL database data source connection information in the request thread and establish a database connection;
[0013] Use the forwarding route configured by the load balancer to forward the user login request to the SQL engine of the TDSQL database used to store user information;
[0014] Forwarding the user login request to the data node through the SQL engine;
[0015] extracting user information based on the user login request;
[0016] Feed the extracted user information back to the application;
[0017] The application authenticates the user information;
[0018] When the authentication is successful, the user information is cached and a successful login prompt is fed back to the browser, wherein the successful login prompt includes at least the organization code; so that the browser caches the organization code in the browser after obtaining the successful login prompt;
[0019] When the user request intercepted in the AOP aspect is a business request, the organization code is obtained from the request header of the request and the business request is executed. The organization code in the request header is extracted from the browser cache.
[0020] Optionally, in the above-mentioned multi-data source switching method based on the TDSQL database, the TDSQL database data source connection information includes:
[0021] The address and port of the load balancer responsible for forwarding database requests. Different TDSQL databases are distinguished by the different ports of the load balancer. The corresponding port of the load balancer is used to forward database requests to the SQL engine of the corresponding TDSQL database, and then the SQL engine forwards the requests to the data node.
[0022] Optionally, in the above-mentioned multi-data source switching method based on the TDSQL database, executing the service request includes:
[0023] According to the correspondence between the organization code and the TDSQL database data source defined in the preset configuration file, the TDSQL database data source connection information of the organization code is obtained, and the data source connection information is written to the request thread corresponding to the business request, and the business request is released;
[0024] Initiate a database request according to the data source connection information in the request thread and establish a database connection;
[0025] Using the forwarding route configured by the load balancer, the service request is forwarded to the SQL engine of the TDSQL database that matches the organization code;
[0026] The TDSQL database SQL engine forwards the service request to the data node, obtains the service data corresponding to the service request, and feeds it back to the user terminal.
[0027] Optionally, in the above-mentioned multi-data source switching method based on the TDSQL database, the forwarding route configured by the load balancer is used to forward the user login request to the SQL engine of the TDSQL database for storing user information, and the user login request is forwarded to the data node by the SQL engine, including:
[0028] A forwarding route configured by one load balancer is selected from at least one load balancer to forward the user login request to the SQL engine of the TDSQL database for storing user information, and the user login request is forwarded to the data node through the SQL engine, wherein, when the number of the load balancers is greater than one, the port numbers of the multiple load balancers are the same or different, and when the number of the load balancer is one, the port numbers of the load balancers are different.
[0029] A multi-data source switching device based on a TDSQL database, comprising:
[0030] User request acquisition unit, used to intercept user requests in AOP aspects;
[0031] A login request processing unit is configured to establish a request thread corresponding to the user login request when the user request is a user login request; extract TDSQL database data source connection information specifically for storing user information by directly matching in a pre-configuration file from the login request; write the TDSQL database data source connection information into the request thread of the user login request and release the user request; initiate a database request based on the TDSQL database data source connection information in the request thread and establish a database connection; forward the user login request to the SQL engine of the TDSQL database for storing user information using a forwarding route configured by a load balancer; forward the user login request to a data node through the SQL engine; extract user information based on the user login request; feed back the extracted user information to an application; the application authenticates the user information; when the authentication is successful, caches the user information and feeds back a successful login prompt to the browser, wherein the successful login prompt includes at least an institution code;
[0032] A cache unit, configured to cache the organization code in the browser after the browser obtains the login success prompt information;
[0033] The business processing unit is used to obtain the organization code from the request header of the request and execute the business request when the user request intercepted in the AOP aspect is a business request. The organization code in the request header is extracted from the user information cached by the browser. When executing the business request, the load balancer is used to forward the business request to the SQL engine of the TDSQL database for storing user information according to the configured forwarding route, and the business request is forwarded to the data node through the SQL engine.
[0034] Optionally, in the above-mentioned multi-data source switching device based on the TDSQL database, the TDSQL database data source connection information includes:
[0035] The address and port of the load balancer responsible for forwarding database requests. Different TDSQL databases are distinguished by the different ports of the load balancer. The corresponding port of the load balancer is used to forward database requests to the SQL engine of the corresponding TDSQL database, and then the SQL engine forwards the requests to the data node.
[0036] Optionally, in the above-mentioned multi-data source switching device based on the TDSQL database, when executing the service request, the service processing unit is specifically configured to:
[0037] According to the correspondence between the organization code and the TDSQL database data source defined in the preset configuration file, the TDSQL database data source connection information of the organization code is obtained, and the data source connection information is written to the request thread corresponding to the business request, and the business request is released;
[0038] Initiate a database request according to the data source connection information in the request thread and establish a database connection;
[0039] Using the forwarding route configured by the load balancer, the service request is forwarded to the SQL engine of the TDSQL database that matches the organization code;
[0040] The TDSQL database SQL engine forwards the service request to the data node, obtains the service data corresponding to the service request, and feeds it back to the user terminal.
[0041] Optionally, in the above-mentioned multi-data source switching device based on the TDSQL database, the login request processing unit, when using the forwarding route configured by the load balancer to forward the user login request to the SQL engine of the TDSQL database for storing user information, and forwarding the user login request to the data node through the SQL engine, is specifically used to:
[0042] A forwarding route configured by one load balancer is selected from at least one load balancer to forward the user login request to the SQL engine of the TDSQL database for storing user information, and the user login request is forwarded to the data node through the SQL engine, wherein, when the number of the load balancers is greater than one, the port numbers of the multiple load balancers are the same or different, and when the number of the load balancer is one, the port numbers of the load balancers are different.
[0043] A readable storage medium stores a computer program thereon, which, when executed by a processor, implements the various steps of the multi-data source switching method based on the TDSQL database as described in any one of the above.
[0044] A multi-data source switching device includes a memory and a processor;
[0045] The memory is used to store programs;
[0046] The processor is used to execute the program to implement each step of the multi-data source switching method based on the TDSQL database described above.
[0047] Based on the above technical solution, the above solution provided by the embodiment of the present invention pre-establishes a mapping relationship between user information, organization code and TDSQL database data source connection information on the server side. When the user logs in, the organization code and target database are determined based on the login information, and the logged-in user is authenticated. When the authentication is passed, the organization code is sent to the browser side so that the browser caches the organization code. When the logged-in user initiates a service request, the organization code can be directly extracted from the browser side, thereby realizing that the user does not need to send and know the organization code during the login process, which is convenient for user use. BRIEF DESCRIPTION OF THE DRAWINGS
[0048] In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the following briefly introduces the drawings required for use in the embodiments or the description of the prior art. Obviously, the drawings described below are merely embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on the provided drawings without paying any creative work.
[0049] Figure 1 A flowchart of a multi-data source switching method based on a TDSQL database disclosed in an embodiment of the present application;
[0050] Figure 2 This is a flowchart of a multi-data source switching method based on a TDSQL database disclosed in another embodiment of the present application;
[0051] Figure 3 This is a schematic diagram of the structure of a multi-data source switching device based on a TDSQL database disclosed in an embodiment of the present application;
[0052] Figure 4 This is a schematic diagram of the structure of the multi-data source switching device disclosed in an embodiment of the present application. DETAILED DESCRIPTION
[0053] The following will clearly and completely describe the technical solutions in the embodiments of the present invention in conjunction with the accompanying drawings. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without making creative efforts are within the scope of protection of the present invention.
[0054] First, some of the professional terms used in this application are explained:
[0055] TDSQL database: A distributed database compatible with the MySQL protocol, suitable for high-concurrency, high-performance, and large-capacity OLTP scenarios. It is not suitable for OLAP scenarios and adopts a master-slave high-availability architecture.
[0056] SQL engine: Computing node, responsible for routing forwarding, SQL analysis, read-write separation and other functions.
[0057] Data nodes: connected into several groups based on the MySQL database master-slave protocol.
[0058] F5: A load balancer that evenly distributes requests to different servers.
[0059] Java: Java is an object-oriented high-level programming language.
[0060] AOP: Aspect-oriented programming.
[0061] B / S: Brower / Server or browser / server mode. When users use a system in B / S mode, they can access the system directly through the browser web page without installing client software.
[0062] HTTP request: refers to the request information from the client to the server. In this article, the request initiated by the browser is an HTTP request.
[0063] Redis: is a high-performance non-relational database commonly used for caching data.
[0064] The main purpose of the present invention is to realize the requirement that the business data of different institutions in a certain business system need to be stored in different TDSQL databases. In this solution, the organization code of each institution is determined in advance, and the organization code of each institution needs to be different, that is, the organization code of each institution needs to be unique. In the program configuration file, the configuration is mainly divided into two parts. The first part is to specify different data sources for different institutions, and the second part is to configure the database connection information of different data sources. There is a preset mapping relationship between the data source and database connection information corresponding to the same institution.
[0065] In the first part, a TDSQL database is designated as a data source specifically for storing user information. This user information includes the institution code of each user's organization. This data source is specified in the preset configuration file using the correspondence 000000001 = mainds. 000000001 can be considered the identification code for the data source specifically for storing user information, and mainds can be considered the name of the data source. A one-to-one correspondence is then established between each institution's institution code and different TDSQL databases, from institution 1 to institution n. As many correspondences as there are institutions, multiple data sources are formed. In the second part, database connection information for different data sources is configured. The database connection information URL contains the F5 address and port responsible for forwarding database requests. Different TDSQL databases are distinguished by different F5 ports. The corresponding F5 port forwards the request to the SQL engine corresponding to the TDSQL database, which then forwards the request to the data node.
[0066] In the AOP aspect, the HTTP request initiated by the browser is intercepted, the organization code in the request header of the HTTP request is obtained, and it is matched with the organization code in the configuration file to determine the corresponding data source.
[0067] See also Figure 1 , the embodiment of the present application discloses a multi-data source switching method based on a TDSQL database, which may include:
[0068] Step S101: intercepting user requests in the AOP aspect.
[0069] In this step, the user may initiate a user request to the application through a browser or other client terminal. When Aspect Oriented Programming (AOP) detects the request, it will intercept the user request.
[0070] Step S102: When the user request is a login request, directly matching and extracting TDSQL database data source connection information specifically storing user information from the pre-configuration file in the login request;
[0071] When AOP intercepts the user request, it first analyzes the type of user request to determine whether it is a user login request or a business request. When the request type is different, the processing flow initiated is different. When it is detected that the user request is a user login request, a request thread corresponding to the user login request is established.
[0072] When the request initiated by the user is a user login request, the login request is loaded with a user identifier corresponding to the user. When the AOP intercepts the user login request, the user identifier can be directly extracted from the request.
[0073] In the system applying this solution, a pre-configuration file is pre-stored. The pre-configuration file refers to the program configuration file mentioned above. After obtaining the user identifier, the configuration file can be matched to the organization code, and then the TDSQL database data source connection information corresponding to the organization code can be further determined, thereby realizing the confirmation of the database address.
[0074] Step S103: writing the TDSQL database data source connection information into the request thread of the user login request, and releasing the user request;
[0075] After the TDSQL database data source connection information is determined, the data source connection information is set in the current request thread (the thread corresponding to the user login request). After the setting is completed, the AOP aspect releases the user login request and executes the subsequent login processing logic.
[0076] In this step, after the TDSQL database data source connection information is determined, the customized DynamicDataSource class can be used to set the matched data source for the HTTP request thread by inheriting the AbstractRoutingDataSource abstract class.
[0077] Step S104: initiating a database request based on the TDSQL database data source connection information in the request thread and establishing a database connection;
[0078] After the request thread configuration is completed, a database request is initiated based on the data source connection information in the request thread, thereby establishing a database connection between the application and the database.
[0079] Step S105: using the forwarding route configured by the load balancer, forwarding the user login request to the SQL engine of the TDSQL database for storing user information, and forwarding the user login request to the data node through the SQL engine;
[0080] In this article, the load balancer uses F5. F5 forwards the route according to the configuration, that is, different ports correspond to different TDSQL database SQL engines. F5 forwards the user login request to the SQL engine of the TDSQL database that stores user information according to the balancing principle. The SQL engine then forwards it to the data node to complete the establishment of the database.
[0081] In this solution, the data node stores user information. Therefore, when the SQL engine obtains a user login request, it needs to forward it to the data node for subsequent authentication processing.
[0082] Step S106: extracting user information based on the user login request, feeding the extracted user information back to the application, and the application authenticating the user information;
[0083] In this step, the user login request needs to be authenticated. At the beginning of authentication, the data node needs to extract the user information reserved by the user based on the login request. Based on the user information, the corresponding application for authentication can be used to authenticate the user login request, thereby obtaining the corresponding authentication result.
[0084] Step S107: When the authentication is successful, the user information is cached, and the user information and a successful login prompt are fed back to the browser; so that the browser caches the organization code in the browser after obtaining the successful login prompt;
[0085] When the user login request is authenticated, the server caches the user information, including the organization code, for example, in Redis on the server. After the application completes the entire login request, it returns a successful login message to the browser, which includes at least the user information, including the organization code.
[0086] After the browser receives the successful login prompt, it indicates that the user has successfully logged in. To facilitate subsequent request operations, the user information, including the organization code, can be cached in the browser cache. When the user subsequently initiates an HTTP request through the browser, the organization code can be directly obtained from the browser cache and carried in the request header (Request Headers). The HTTP request can be understood as a business request initiated by the user. After a successful login, any business request initiated by the browser will carry the organization code in the browser cache in the request header, which is used by the application server to find a matching data source.
[0087] Step S108: When the user request intercepted in the AOP aspect is a business request, the organization code is obtained from the browser cache, the organization code is obtained from the request header of the request, and the business request is executed. The organization code in the request header is extracted from the browser cache when executing the business request.
[0088] It can be seen from the above scheme that in this scheme, by pre-establishing the mapping relationship between user information and organization code and TDSQL database data source connection information on the server side, when the user logs in, the organization code and target database are determined based on the login information, and the logged-in user is authenticated. When the authentication is passed, the organization code is sent to the browser side so that the browser caches the organization code. When the logged-in user initiates a business request, the organization code can be directly extracted from the browser side, thereby realizing that the user does not need to send and know the organization code during the login process, which is convenient for user use.
[0089] Furthermore, in the technical solution disclosed in the above embodiment of the present application, the above solution can use Java as the development language, adopt AOP programming method to intercept different requests to obtain the organization code, use TDSQL database as storage, each TDSQL database as an independent data source, and use F5 as a load balancer to forward different database requests, realize multi-data source switching, and ensure the use requirements of business data of different organizations when stored in different TDSQL databases.
[0090] In the technical solution disclosed in another embodiment of the present application, the specific type of the TDSQL database data source connection information can be set according to user needs, as long as it can ensure that the TDSQL database data source corresponding to the institution code can be determined. For example, in this solution, the TDSQL database data source connection information may include: the address and port of the load balancer responsible for forwarding database requests, and different TDSQL databases are distinguished by different ports of the load balancer. The corresponding port of the load balancer is used to forward user requests to the SQL engine of the corresponding TDSQL database, and then the SQL engine forwards the request to the data node. In this solution, the number of load balancers can be 1 or greater than 1. When the load balancer is used to forward the user login request to the SQL engine of the TDSQL database for storing user information according to the configured forwarding route, specifically: one load balancer is selected from at least 1 load balancer to forward the user login request to the SQL engine of the TDSQL database for storing user information according to the configured forwarding route. When the number of the load balancers is greater than 1, the port numbers of the multiple load balancers are the same or different. When the port numbers of the multiple load balancers are different, it indicates that the SQL engines they are responsible for are different. At this time, it is necessary to determine the corresponding load balancer according to the TDSQL database data source connection information, and forward the user login request to the SQL engine of the TDSQL database for storing user information through the load balancer. When the number of the load balancer is 1, the port numbers of the load balancers are different, and the multiple port numbers of the load balancer correspond one-to-one to the TDSQL database.
[0091] In the technical solution disclosed in another embodiment of the present application, when the user request is a service request, the output transmission method of the request is similar to the transmission method of the user login request, except that the specific details of the execution of some steps are different. Figure 2 In the technical solution disclosed in the above embodiment, the execution of the service request specifically includes:
[0092] Step S201: According to the correspondence between the organization code and the TDSQL database data source defined in the preset configuration file, the TDSQL database data source connection information of the organization code is obtained, and the data source connection information is written into the request thread corresponding to the service request, thereby releasing the user request;
[0093] This step can be summarized as follows: extracting the organization code from the request header in the service request, determining the TDSQL database data source connection information adapted to the organization code based on a preset configuration file, writing the TDSQL database data source connection information to the request thread, and releasing the service request;
[0094] In this step, after the TDSQL database data source connection information is determined, the customized DynamicDataSource class can be used to set the matched data source for the HTTP request thread by inheriting the AbstractRoutingDataSource abstract class.
[0095] Step S202: Initiate a database request according to the data source connection information in the request thread and establish a database connection;
[0096] Step S203: When the database connection is successful, the load balancer is used to forward the service request to the SQL engine of the TDSQL database that matches the organization code according to the configured forwarding route;
[0097] Step S204: The TDSQL database SQL engine forwards the service request to the data node, obtains service data corresponding to the service request, and feeds back to the user terminal.
[0098] The business data is the target data corresponding to the business request. After the target data is determined, the target data is fed back to the user terminal, which may be a browser or an APP with corresponding functions.
[0099] In summary, the technical solutions disclosed in the embodiments of this application have the following technical effects:
[0100] Use TDSQL database to store data. It is compatible with MySQL protocol and can adapt to MySQL database very easily. Business systems using MySQL database can be easily migrated from MySQL to TDSQL.
[0101] Using F5 as routing forwarding can reduce the coupling between the application and the TDSQL database. When adding or reducing the TDSQL database, the F5 routing forwarding rules can be modified without modifying the application.
[0102] The solution can be designed and implemented using Java language, which is flexible in programming, supports cross-platform and is easy to implement.
[0103] It uses AOP to intercept requests and has good code scalability.
[0104] This embodiment discloses a multi-data source switching device based on a TDSQL database. For the specific working content of each unit in the device, please refer to the content of the above method embodiment.
[0105] The following describes a multi-data source switching device based on a TDSQL database provided in an embodiment of the present invention. The multi-data source switching device based on a TDSQL database described below and the multi-data source switching method based on a TDSQL database described above can be referenced to each other.
[0106] For details, see Figure 3 The multi-data source switching device based on the TDSQL database includes:
[0107] User request acquisition unit A is used to intercept user requests in the AOP aspect;
[0108] The login request processing unit B is used to establish a request thread corresponding to the user login request when the user request is a user login request; extract a user identifier from the user login request; extract TDSQL database data source connection information matching the user identifier from a preset configuration file based on the user identifier; write the TDSQL database data source connection information into the request thread of the user login request and release the user request; initiate a database request based on the TDSQL database data source connection information in the request thread and establish a database connection; adopt a load balancer to forward the user login request to the SQL engine of the TDSQL database for storing user information according to the configured forwarding route; forward the user login request to the data node through the SQL engine; extract user information based on the user login request; feed back the extracted user information to the application; the application authenticates the user information; when the authentication is passed, caches the user information and feeds back a login success prompt message to the browser, so that the browser caches the organization code in the browser after obtaining the login success prompt message, and the login success prompt message includes at least the organization code;
[0109] Business processing unit C is used to obtain the organization code from the request header of the request and execute the business request when the user request intercepted in the AOP aspect is a business request. The organization code in the request header is extracted from the user information cached by the browser. When executing the business request, the load balancer is used to forward the business request to the SQL engine of the TDSQL database used to store user information according to the configured forwarding route, and then the SQL engine forwards the business request to the data node.
[0110] Corresponding to the above method, when executing the service request, the service processing unit is specifically configured to:
[0111] According to the correspondence between the organization code and the TDSQL database data source defined in the preset configuration file, the TDSQL database data source connection information of the organization code is obtained, and the data source connection information is written to the request thread corresponding to the business request, and the business request is released;
[0112] Initiate a database request according to the data source connection information in the request thread and establish a database connection;
[0113] Use a load balancer to forward the service request to the SQL engine of the TDSQL database that matches the organization code according to the configured forwarding route;
[0114] The TDSQL database SQL engine forwards the service request to the data node, obtains the service data corresponding to the service request, and feeds it back to the user terminal.
[0115] A readable storage medium having a computer program stored thereon, characterized in that when the computer program is executed by a processor, the computer program implements the various steps of the multi-data source switching method based on the TDSQL database as described in any one of the above embodiments.
[0116] Figure 4 For a hardware structure diagram of a multi-data source switching device provided by an embodiment of the present invention, see Figure 4 As shown, it may include: at least one processor 100, at least one communication interface 200, at least one memory 300 and at least one communication bus 400;
[0117] In the embodiment of the present invention, the number of the processor 100, the communication interface 200, the memory 300, and the communication bus 400 is at least one, and the processor 100, the communication interface 200, and the memory 300 communicate with each other through the communication bus 400; obviously, Figure 4 The communication connections shown for the processor 100, communication interface 200, memory 300, and communication bus 400 are merely optional;
[0118] Optionally, the communication interface 200 may be an interface of a communication module, such as an interface of a GSM module;
[0119] The processor 100 may be a central processing unit (CPU), or an application-specific integrated circuit (ASIC), or one or more integrated circuits configured to implement the embodiments of the present invention.
[0120] The memory 300 may include a high-speed RAM memory, and may also include a non-volatile memory (non-volatile memory), such as at least one disk memory.
[0121] The processor 100 is specifically configured to:
[0122] Intercept user requests in AOP aspects;
[0123] When the user request is a user login request, the TDSQL database data source connection information specifically storing user information is directly extracted from the preset configuration file in the login request;
[0124] Writing the TDSQL database data source connection information into the request thread of the user login request and releasing the user request;
[0125] Initiate a database request based on the TDSQL database data source connection information in the request thread and establish a database connection;
[0126] Use the load balancer to forward user login requests to the SQL engine of the TDSQL database used to store user information based on the configured forwarding route;
[0127] Forwarding the user login request to the data node through the SQL engine;
[0128] extracting user information based on the user login request;
[0129] Feed the extracted user information back to the application;
[0130] The application authenticates the user information;
[0131] When the authentication is successful, the user information is cached and a successful login prompt is fed back to the browser, wherein the successful login prompt includes at least the organization code; so that the browser caches the organization code in the browser after obtaining the successful login prompt;
[0132] When the user request intercepted in the AOP aspect is a business request, the organization code is obtained from the request header of the request and the business request is executed. The organization code in the request header is extracted from the browser cache.
[0133] A readable storage medium having a computer program stored thereon, characterized in that when the computer program is executed by a processor, each step of any one of the above-mentioned methods for switching multiple data sources based on a TDSQL database is implemented.
[0134] For the convenience of description, the above system is described as being divided into various modules according to their functions. Of course, when implementing the present invention, the functions of each module can be implemented in the same or multiple software and / or hardware.
[0135] Each embodiment in this specification is described in a progressive manner. The same or similar parts between the embodiments can be referred to each other. Each embodiment focuses on the differences from other embodiments. In particular, for system or system embodiments, since they are basically similar to method embodiments, the description is relatively simple. For relevant parts, refer to the partial description of the method embodiment. The system and system embodiments described above are merely schematic, wherein the units described as separate components may or may not be physically separated, and the components displayed as units may or may not be physical units, that is, they may be located in one place, or they may be distributed on multiple network units. Some or all of the modules can be selected according to actual needs to achieve the purpose of the solution of this embodiment. A person of ordinary skill in the art can understand and implement it without expending creative work.
[0136] Professionals may further appreciate that the units and algorithm steps of each example described in conjunction with the embodiments disclosed herein can be implemented in electronic hardware, computer software, or a combination of the two. In order to clearly illustrate the interchangeability of hardware and software, the above description has generally described the components and steps of each example according to their functions. Whether these functions are performed in hardware or software depends on the specific application and design constraints of the technical solution. Professionals and technicians may use different methods to implement the described functions for each specific application, but such implementation should not be considered beyond the scope of the present invention.
[0137] The steps of the methods or algorithms described in conjunction with the embodiments disclosed herein may be implemented directly using hardware, a software module executed by a processor, or a combination of the two. The software module may be placed in a random access memory (RAM), internal memory, read-only memory (ROM), electrically programmable ROM, electrically erasable programmable ROM, registers, a hard disk, a removable disk, a CD-ROM, or any other form of storage medium known in the art.
[0138] It should also be noted that, in this document, relational terms such as first and second, etc., are used only to distinguish one entity or operation from another entity or operation, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Moreover, the terms "comprises," "comprising," or any other variations thereof are intended to cover non-exclusive inclusion, such that a process, method, article, or device comprising a series of elements includes not only those elements, but also other elements not explicitly listed, or elements inherent to such process, method, article, or device. In the absence of further limitations, an element defined by the phrase "comprising a ..." does not exclude the presence of additional identical elements in the process, method, article, or device comprising the element.
[0139] The above description of the disclosed embodiments is intended to enable one skilled in the art to implement or use the present invention. Various modifications to these embodiments will be readily apparent to one skilled in the art, and the general principles defined herein may be implemented in other embodiments without departing from the spirit or scope of the present invention. Therefore, the present invention is not limited to the embodiments shown herein but is intended to conform to the widest scope consistent with the principles and novel features disclosed herein.
Claims
1. A multi-data source switching method based on TDSQL database, characterized in that: include: Intercept user requests in AOP aspects; When the user request is a login request, directly matching and extracting the TDSQL database data source connection information specifically storing user information in the pre-configuration file from the login request; Writing the TDSQL database data source connection information into the request thread of the user login request and releasing the user request; Initiate a database request based on the TDSQL database data source connection information in the request thread and establish a database connection; Use the forwarding route configured by the load balancer to forward the user login request to the SQL engine of the TDSQL database used to store user information; Forwarding the user login request to the data node through the SQL engine; extracting user information based on the user login request; Feed the extracted user information back to the application; The application authenticates the user information; When the authentication is successful, the user information is cached and a login success prompt message is fed back to the browser, wherein the login success prompt message includes at least the organization code; So that after the browser obtains the login success prompt information, it caches the organization code in the browser; When the user request intercepted in the AOP aspect is a business request, the organization code is obtained from the request header of the request and the business request is executed. The organization code in the request header is extracted from the browser cache.
2. The multi-data source switching method based on TDSQL database according to claim 1, characterized in that: The TDSQL database data source connection information includes: The address and port of the load balancer responsible for forwarding database requests. Different TDSQL databases are distinguished by the different ports of the load balancer. The corresponding port of the load balancer is used to forward database requests to the SQL engine of the corresponding TDSQL database, and then the SQL engine forwards the requests to the data node.
3. The multi-data source switching method based on TDSQL database according to claim 1, characterized in that: Executing the service request includes: According to the correspondence between the organization code and the TDSQL database data source defined in the preset configuration file, the TDSQL database data source connection information of the organization code is obtained, and the data source connection information is written to the request thread corresponding to the business request, and the business request is released; Initiate a database request according to the data source connection information in the request thread and establish a database connection; Using the forwarding route configured by the load balancer, the service request is forwarded to the SQL engine of the TDSQL database that matches the organization code; The TDSQL database SQL engine forwards the service request to the data node, obtains the service data corresponding to the service request, and feeds it back to the user terminal.
4. The multi-data source switching method based on TDSQL database according to claim 1, characterized in that: Using the forwarding route configured by the load balancer, forwarding the user login request to the SQL engine of the TDSQL database for storing user information, and forwarding the user login request to the data node through the SQL engine, including: A forwarding route configured by one load balancer is selected from at least one load balancer to forward the user login request to the SQL engine of the TDSQL database for storing user information, and the user login request is forwarded to the data node through the SQL engine, wherein, when the number of the load balancers is greater than one, the port numbers of the multiple load balancers are the same or different, and when the number of the load balancer is one, the port numbers of the load balancers are different.
5. A multi-data source switching device based on TDSQL database, characterized in that: include: User request acquisition unit, used to intercept user requests in AOP aspects; A login request processing unit is configured to, when the user request is a user login request, establish a request thread corresponding to the user login request; directly match and extract TDSQL database data source connection information specifically for storing user information from a pre-configuration file in the login request; write the TDSQL database data source connection information to the request thread of the user login request and release the user request; initiate a database request based on the TDSQL database data source connection information in the request thread and establish a database connection; and forward the user login request to the SQL engine of the TDSQL database for storing user information using a forwarding route configured by a load balancer; forwarding the user login request to a data node via the SQL engine; extracting user information based on the user login request; feeding the extracted user information back to the application; the application authenticating the user information; when the authentication is successful, caching the user information and feeding back a successful login prompt to the browser, the successful login prompt including at least an institution code; A cache unit, configured to cache the organization code in the browser after the browser obtains the login success prompt information; The business processing unit is used to obtain the organization code from the request header of the request and execute the business request when the user request intercepted in the AOP aspect is a business request. The organization code in the request header is extracted from the user information cached by the browser. When executing the business request, the load balancer is used to forward the business request to the SQL engine of the TDSQL database for storing user information according to the configured forwarding route, and the business request is forwarded to the data node through the SQL engine.
6. The multi-data source switching device based on TDSQL database according to claim 5, characterized in that: The TDSQL database data source connection information includes: The address and port of the load balancer responsible for forwarding database requests. Different TDSQL databases are distinguished by the different ports of the load balancer. The corresponding port of the load balancer is used to forward database requests to the SQL engine of the corresponding TDSQL database, and then the SQL engine forwards the requests to the data node.
7. The multi-data source switching device based on TDSQL database according to claim 5, characterized in that: When executing the service request, the service processing unit is specifically configured to: According to the correspondence between the organization code and the TDSQL database data source defined in the preset configuration file, the TDSQL database data source connection information of the organization code is obtained, and the data source connection information is written to the request thread corresponding to the business request, and the business request is released; Initiate a database request according to the data source connection information in the request thread and establish a database connection; Using the forwarding route configured by the load balancer, the service request is forwarded to the SQL engine of the TDSQL database that matches the organization code; The TDSQL database SQL engine forwards the service request to the data node, obtains the service data corresponding to the service request, and feeds it back to the user terminal.
8. The multi-data source switching device based on TDSQL database according to claim 5, characterized in that: The login request processing unit, when using the forwarding route configured by the load balancer to forward the user login request to the SQL engine of the TDSQL database for storing user information, and forwarding the user login request to the data node through the SQL engine, is specifically configured to: A forwarding route configured by one load balancer is selected from at least one load balancer to forward the user login request to the SQL engine of the TDSQL database for storing user information, and the user login request is forwarded to the data node through the SQL engine, wherein, when the number of the load balancers is greater than one, the port numbers of the multiple load balancers are the same or different, and when the number of the load balancer is one, the port numbers of the load balancers are different.
9. A readable storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, each step of the multi-data source switching method based on the TDSQL database as claimed in any one of claims 1 to 4 is implemented.
10. A multi-data source switching device, characterized in that: including memory and processor; The memory is used to store programs; The processor is configured to execute the program to implement the various steps of the multi-data source switching method based on the TDSQL database as described in any one of claims 1 to 4.
Citation Information
Patent Citations
Multi-tenant data isolation scheme applied to PaaS (Platform-as-a-Service) platform
CN106529331A
RAC multi-node database query method, device and system
CN111581234A